Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- SemaOpenMP.cpp - Semantic Analysis for OpenMP constructs ---------===// |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements semantic analysis for OpenMP directives and |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 11 | /// clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 15 | #include "TreeTransform.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTMutationListener.h" |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 18 | #include "clang/AST/CXXInheritance.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 19 | #include "clang/AST/Decl.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 20 | #include "clang/AST/DeclCXX.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclOpenMP.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtCXX.h" |
| 23 | #include "clang/AST/StmtOpenMP.h" |
| 24 | #include "clang/AST/StmtVisitor.h" |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 25 | #include "clang/AST/TypeOrdering.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 26 | #include "clang/Basic/OpenMPKinds.h" |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 27 | #include "clang/Basic/TargetInfo.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 28 | #include "clang/Lex/Preprocessor.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 29 | #include "clang/Sema/Initialization.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 30 | #include "clang/Sema/Lookup.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 31 | #include "clang/Sema/Scope.h" |
| 32 | #include "clang/Sema/ScopeInfo.h" |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 33 | #include "clang/Sema/SemaInternal.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 34 | using namespace clang; |
| 35 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 36 | //===----------------------------------------------------------------------===// |
| 37 | // Stack of data-sharing attributes for variables |
| 38 | //===----------------------------------------------------------------------===// |
| 39 | |
| 40 | namespace { |
| 41 | /// \brief Default data sharing attributes, which can be applied to directive. |
| 42 | enum DefaultDataSharingAttributes { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 43 | DSA_unspecified = 0, /// \brief Data sharing attribute not specified. |
| 44 | DSA_none = 1 << 0, /// \brief Default data sharing attribute 'none'. |
| 45 | DSA_shared = 1 << 1 /// \brief Default data sharing attribute 'shared'. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 46 | }; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 47 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 48 | /// \brief Stack for tracking declarations used in OpenMP directives and |
| 49 | /// clauses and their data-sharing attributes. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 50 | class DSAStackTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 51 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 52 | struct DSAVarData final { |
| 53 | OpenMPDirectiveKind DKind = OMPD_unknown; |
| 54 | OpenMPClauseKind CKind = OMPC_unknown; |
| 55 | Expr *RefExpr = nullptr; |
| 56 | DeclRefExpr *PrivateCopy = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 57 | SourceLocation ImplicitDSALoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 58 | DSAVarData() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 59 | }; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 60 | typedef llvm::SmallVector<std::pair<Expr *, OverloadedOperatorKind>, 4> |
| 61 | OperatorOffsetTy; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 62 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 63 | private: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 64 | struct DSAInfo final { |
| 65 | OpenMPClauseKind Attributes = OMPC_unknown; |
| 66 | /// Pointer to a reference expression and a flag which shows that the |
| 67 | /// variable is marked as lastprivate(true) or not (false). |
| 68 | llvm::PointerIntPair<Expr *, 1, bool> RefExpr; |
| 69 | DeclRefExpr *PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 70 | }; |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 71 | typedef llvm::DenseMap<ValueDecl *, DSAInfo> DeclSAMapTy; |
| 72 | typedef llvm::DenseMap<ValueDecl *, Expr *> AlignedMapTy; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 73 | typedef std::pair<unsigned, VarDecl *> LCDeclInfo; |
| 74 | typedef llvm::DenseMap<ValueDecl *, LCDeclInfo> LoopControlVariablesMapTy; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 75 | typedef llvm::DenseMap< |
| 76 | ValueDecl *, OMPClauseMappableExprCommon::MappableExprComponentLists> |
| 77 | MappedExprComponentsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 78 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 79 | CriticalsWithHintsTy; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 80 | typedef llvm::DenseMap<OMPDependClause *, OperatorOffsetTy> |
| 81 | DoacrossDependMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 82 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 83 | struct SharingMapTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 84 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 85 | AlignedMapTy AlignedMap; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 86 | MappedExprComponentsTy MappedExprComponents; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 87 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 88 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 89 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 90 | OpenMPDirectiveKind Directive = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 91 | DeclarationNameInfo DirectiveName; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 92 | Scope *CurScope = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 93 | SourceLocation ConstructLoc; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 94 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 95 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 96 | /// This data is required during codegen. |
| 97 | DoacrossDependMapTy DoacrossDepends; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 98 | /// \brief first argument (Expr *) contains optional argument of the |
| 99 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 100 | /// clause, false otherwise. |
| 101 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 102 | bool NowaitRegion = false; |
| 103 | bool CancelRegion = false; |
| 104 | unsigned AssociatedLoops = 1; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 105 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 106 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 107 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 108 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 109 | ConstructLoc(Loc) {} |
| 110 | SharingMapTy() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 111 | }; |
| 112 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 113 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 114 | |
| 115 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 116 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 117 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 118 | /// from current directive. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 119 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 120 | Sema &SemaRef; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 121 | bool ForceCapturing = false; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 122 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 123 | |
| 124 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 125 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 126 | DSAVarData getDSA(StackTy::reverse_iterator& Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 127 | |
| 128 | /// \brief Checks if the variable is a local for OpenMP region. |
| 129 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 130 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 131 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 132 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 133 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 134 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 135 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 137 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 138 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 139 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 140 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 141 | Scope *CurScope, SourceLocation Loc) { |
| 142 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 143 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void pop() { |
| 147 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 148 | Stack.pop_back(); |
| 149 | } |
| 150 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 151 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 152 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 153 | } |
| 154 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 155 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 156 | auto I = Criticals.find(Name.getAsString()); |
| 157 | if (I != Criticals.end()) |
| 158 | return I->second; |
| 159 | return std::make_pair(nullptr, llvm::APSInt()); |
| 160 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 161 | /// \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] | 162 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 163 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 164 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 165 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 166 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 167 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 168 | /// \brief Check if the specified variable is a loop control variable for |
| 169 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 170 | /// \return The index of the loop control variable in the list of associated |
| 171 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 172 | LCDeclInfo isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 173 | /// \brief Check if the specified variable is a loop control variable for |
| 174 | /// parent region. |
| 175 | /// \return The index of the loop control variable in the list of associated |
| 176 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 177 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 178 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 179 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 180 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 181 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 182 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 183 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 184 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 185 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 186 | /// \brief Returns data sharing attributes from top of the stack for the |
| 187 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 188 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 189 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 190 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 191 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 192 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 193 | /// predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 194 | DSAVarData hasDSA(ValueDecl *D, |
| 195 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 196 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 197 | bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 198 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 199 | /// match specified \a CPred predicate in any innermost directive which |
| 200 | /// matches \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 201 | DSAVarData |
| 202 | hasInnermostDSA(ValueDecl *D, |
| 203 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 204 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 205 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 206 | /// \brief Checks if the specified variables has explicit data-sharing |
| 207 | /// attributes which match specified \a CPred predicate at the specified |
| 208 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 209 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 210 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 211 | unsigned Level, bool NotLastprivate = false); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 212 | |
| 213 | /// \brief Returns true if the directive at level \Level matches in the |
| 214 | /// specified \a DPred predicate. |
| 215 | bool hasExplicitDirective( |
| 216 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 217 | unsigned Level); |
| 218 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 219 | /// \brief Finds a directive which matches specified \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 220 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 221 | const DeclarationNameInfo &, |
| 222 | SourceLocation)> &DPred, |
| 223 | bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 224 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 225 | /// \brief Returns currently analyzed directive. |
| 226 | OpenMPDirectiveKind getCurrentDirective() const { |
| 227 | return Stack.back().Directive; |
| 228 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 229 | /// \brief Returns parent directive. |
| 230 | OpenMPDirectiveKind getParentDirective() const { |
| 231 | if (Stack.size() > 2) |
| 232 | return Stack[Stack.size() - 2].Directive; |
| 233 | return OMPD_unknown; |
| 234 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 235 | |
| 236 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 237 | void setDefaultDSANone(SourceLocation Loc) { |
| 238 | Stack.back().DefaultAttr = DSA_none; |
| 239 | Stack.back().DefaultAttrLoc = Loc; |
| 240 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 241 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 242 | void setDefaultDSAShared(SourceLocation Loc) { |
| 243 | Stack.back().DefaultAttr = DSA_shared; |
| 244 | Stack.back().DefaultAttrLoc = Loc; |
| 245 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 246 | |
| 247 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 248 | return Stack.back().DefaultAttr; |
| 249 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 250 | SourceLocation getDefaultDSALocation() const { |
| 251 | return Stack.back().DefaultAttrLoc; |
| 252 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 253 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 254 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 255 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 256 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 257 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 260 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 261 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 262 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 263 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 264 | } |
| 265 | /// \brief Returns true, if parent region is ordered (has associated |
| 266 | /// 'ordered' clause), false - otherwise. |
| 267 | bool isParentOrderedRegion() const { |
| 268 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 269 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 270 | return false; |
| 271 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 272 | /// \brief Returns optional parameter for the ordered region. |
| 273 | Expr *getParentOrderedRegionParam() const { |
| 274 | if (Stack.size() > 2) |
| 275 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 276 | return nullptr; |
| 277 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 278 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 279 | void setNowaitRegion(bool IsNowait = true) { |
| 280 | Stack.back().NowaitRegion = IsNowait; |
| 281 | } |
| 282 | /// \brief Returns true, if parent region is nowait (has associated |
| 283 | /// 'nowait' clause), false - otherwise. |
| 284 | bool isParentNowaitRegion() const { |
| 285 | if (Stack.size() > 2) |
| 286 | return Stack[Stack.size() - 2].NowaitRegion; |
| 287 | return false; |
| 288 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 289 | /// \brief Marks parent region as cancel region. |
| 290 | void setParentCancelRegion(bool Cancel = true) { |
| 291 | if (Stack.size() > 2) |
| 292 | Stack[Stack.size() - 2].CancelRegion = |
| 293 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 294 | } |
| 295 | /// \brief Return true if current region has inner cancel construct. |
| 296 | bool isCancelRegion() const { |
| 297 | return Stack.back().CancelRegion; |
| 298 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 299 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 300 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 301 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 302 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 303 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 304 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 305 | /// \brief Marks current target region as one with closely nested teams |
| 306 | /// region. |
| 307 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 308 | if (Stack.size() > 2) |
| 309 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 310 | } |
| 311 | /// \brief Returns true, if current region has closely nested teams region. |
| 312 | bool hasInnerTeamsRegion() const { |
| 313 | return getInnerTeamsRegionLoc().isValid(); |
| 314 | } |
| 315 | /// \brief Returns location of the nested teams region (if any). |
| 316 | SourceLocation getInnerTeamsRegionLoc() const { |
| 317 | if (Stack.size() > 1) |
| 318 | return Stack.back().InnerTeamsRegionLoc; |
| 319 | return SourceLocation(); |
| 320 | } |
| 321 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 322 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 323 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 324 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 325 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 326 | // Do the check specified in \a Check to all component lists and return true |
| 327 | // if any issue is found. |
| 328 | bool checkMappableExprComponentListsForDecl( |
| 329 | ValueDecl *VD, bool CurrentRegionOnly, |
| 330 | const llvm::function_ref<bool( |
| 331 | OMPClauseMappableExprCommon::MappableExprComponentListRef)> &Check) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 332 | auto SI = Stack.rbegin(); |
| 333 | auto SE = Stack.rend(); |
| 334 | |
| 335 | if (SI == SE) |
| 336 | return false; |
| 337 | |
| 338 | if (CurrentRegionOnly) { |
| 339 | SE = std::next(SI); |
| 340 | } else { |
| 341 | ++SI; |
| 342 | } |
| 343 | |
| 344 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 345 | auto MI = SI->MappedExprComponents.find(VD); |
| 346 | if (MI != SI->MappedExprComponents.end()) |
| 347 | for (auto &L : MI->second) |
| 348 | if (Check(L)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 349 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 350 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 351 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 354 | // Create a new mappable expression component list associated with a given |
| 355 | // declaration and initialize it with the provided list of components. |
| 356 | void addMappableExpressionComponents( |
| 357 | ValueDecl *VD, |
| 358 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components) { |
| 359 | assert(Stack.size() > 1 && |
| 360 | "Not expecting to retrieve components from a empty stack!"); |
| 361 | auto &MEC = Stack.back().MappedExprComponents[VD]; |
| 362 | // Create new entry and append the new components there. |
| 363 | MEC.resize(MEC.size() + 1); |
| 364 | MEC.back().append(Components.begin(), Components.end()); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 365 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 366 | |
| 367 | unsigned getNestingLevel() const { |
| 368 | assert(Stack.size() > 1); |
| 369 | return Stack.size() - 2; |
| 370 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 371 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { |
| 372 | assert(Stack.size() > 2); |
| 373 | assert(isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive)); |
| 374 | Stack[Stack.size() - 2].DoacrossDepends.insert({C, OpsOffs}); |
| 375 | } |
| 376 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 377 | getDoacrossDependClauses() const { |
| 378 | assert(Stack.size() > 1); |
| 379 | if (isOpenMPWorksharingDirective(Stack[Stack.size() - 1].Directive)) { |
| 380 | auto &Ref = Stack[Stack.size() - 1].DoacrossDepends; |
| 381 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 382 | } |
| 383 | return llvm::make_range(Stack[0].DoacrossDepends.end(), |
| 384 | Stack[0].DoacrossDepends.end()); |
| 385 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 386 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 387 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 388 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 389 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 390 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 391 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 393 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 394 | auto *VD = dyn_cast<VarDecl>(D); |
| 395 | auto *FD = dyn_cast<FieldDecl>(D); |
| 396 | if (VD != nullptr) { |
| 397 | VD = VD->getCanonicalDecl(); |
| 398 | D = VD; |
| 399 | } else { |
| 400 | assert(FD); |
| 401 | FD = FD->getCanonicalDecl(); |
| 402 | D = FD; |
| 403 | } |
| 404 | return D; |
| 405 | } |
| 406 | |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 407 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator& Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 408 | ValueDecl *D) { |
| 409 | D = getCanonicalDecl(D); |
| 410 | auto *VD = dyn_cast<VarDecl>(D); |
| 411 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 412 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 413 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 414 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 415 | // in a region but not in construct] |
| 416 | // File-scope or namespace-scope variables referenced in called routines |
| 417 | // in the region are shared unless they appear in a threadprivate |
| 418 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 419 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 420 | DVar.CKind = OMPC_shared; |
| 421 | |
| 422 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 423 | // in a region but not in construct] |
| 424 | // Variables with static storage duration that are declared in called |
| 425 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 426 | if (VD && VD->hasGlobalStorage()) |
| 427 | DVar.CKind = OMPC_shared; |
| 428 | |
| 429 | // Non-static data members are shared by default. |
| 430 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 431 | DVar.CKind = OMPC_shared; |
| 432 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 433 | return DVar; |
| 434 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 435 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 436 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 437 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 438 | // in a Construct, C/C++, predetermined, p.1] |
| 439 | // Variables with automatic storage duration that are declared in a scope |
| 440 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 441 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 442 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 443 | DVar.CKind = OMPC_private; |
| 444 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 445 | } |
| 446 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 447 | // Explicitly specified attributes and local variables with predetermined |
| 448 | // attributes. |
| 449 | if (Iter->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 450 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 451 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 452 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 453 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 454 | return DVar; |
| 455 | } |
| 456 | |
| 457 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 458 | // in a Construct, C/C++, implicitly determined, p.1] |
| 459 | // In a parallel or task construct, the data-sharing attributes of these |
| 460 | // variables are determined by the default clause, if present. |
| 461 | switch (Iter->DefaultAttr) { |
| 462 | case DSA_shared: |
| 463 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 464 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 465 | return DVar; |
| 466 | case DSA_none: |
| 467 | return DVar; |
| 468 | case DSA_unspecified: |
| 469 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 470 | // in a Construct, implicitly determined, p.2] |
| 471 | // In a parallel construct, if no default clause is present, these |
| 472 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 473 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 474 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 475 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 476 | DVar.CKind = OMPC_shared; |
| 477 | return DVar; |
| 478 | } |
| 479 | |
| 480 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 481 | // in a Construct, implicitly determined, p.4] |
| 482 | // In a task construct, if no default clause is present, a variable that in |
| 483 | // the enclosing context is determined to be shared by all implicit tasks |
| 484 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 485 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 486 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 487 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 488 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 489 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 490 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 491 | // In a task construct, if no default clause is present, a variable |
| 492 | // whose data-sharing attribute is not determined by the rules above is |
| 493 | // firstprivate. |
| 494 | DVarTemp = getDSA(I, D); |
| 495 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 496 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 497 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 498 | return DVar; |
| 499 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 500 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 501 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 502 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 503 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 504 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 505 | return DVar; |
| 506 | } |
| 507 | } |
| 508 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 509 | // in a Construct, implicitly determined, p.3] |
| 510 | // For constructs other than task, if no default clause is present, these |
| 511 | // variables inherit their data-sharing attributes from the enclosing |
| 512 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 513 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 516 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 517 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 518 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 519 | auto It = Stack.back().AlignedMap.find(D); |
| 520 | if (It == Stack.back().AlignedMap.end()) { |
| 521 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 522 | Stack.back().AlignedMap[D] = NewDE; |
| 523 | return nullptr; |
| 524 | } else { |
| 525 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 526 | return It->second; |
| 527 | } |
| 528 | return nullptr; |
| 529 | } |
| 530 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 531 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 532 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 533 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 534 | Stack.back().LCVMap.insert( |
| 535 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 538 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 539 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 540 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 541 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 542 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 543 | } |
| 544 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 545 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 546 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 547 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 548 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 549 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 550 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 551 | } |
| 552 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 553 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 554 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 555 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 556 | return nullptr; |
| 557 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 558 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 559 | return Pair.first; |
| 560 | } |
| 561 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 564 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 565 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 566 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 567 | if (A == OMPC_threadprivate) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 568 | auto &Data = Stack[0].SharingMap[D]; |
| 569 | Data.Attributes = A; |
| 570 | Data.RefExpr.setPointer(E); |
| 571 | Data.PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 572 | } else { |
| 573 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 574 | auto &Data = Stack.back().SharingMap[D]; |
| 575 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 576 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 577 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 578 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 579 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 580 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 581 | return; |
| 582 | } |
| 583 | const bool IsLastprivate = |
| 584 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 585 | Data.Attributes = A; |
| 586 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 587 | Data.PrivateCopy = PrivateCopy; |
| 588 | if (PrivateCopy) { |
| 589 | auto &Data = Stack.back().SharingMap[PrivateCopy->getDecl()]; |
| 590 | Data.Attributes = A; |
| 591 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 592 | Data.PrivateCopy = nullptr; |
| 593 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 597 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 598 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 599 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 600 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 601 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 602 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 603 | ++I; |
| 604 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 605 | if (I == E) |
| 606 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 607 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 608 | Scope *CurScope = getCurScope(); |
| 609 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 610 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 611 | } |
| 612 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 613 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 614 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 617 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 618 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 619 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 620 | DeclContext *DC = SemaRef.CurContext; |
| 621 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 622 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 623 | VarDecl *Decl = |
| 624 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 625 | if (Attrs) { |
| 626 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 627 | I != E; ++I) |
| 628 | Decl->addAttr(*I); |
| 629 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 630 | Decl->setImplicit(); |
| 631 | return Decl; |
| 632 | } |
| 633 | |
| 634 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 635 | SourceLocation Loc, |
| 636 | bool RefersToCapture = false) { |
| 637 | D->setReferenced(); |
| 638 | D->markUsed(S.Context); |
| 639 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 640 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 641 | VK_LValue); |
| 642 | } |
| 643 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 644 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 645 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 646 | DSAVarData DVar; |
| 647 | |
| 648 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 649 | // in a Construct, C/C++, predetermined, p.1] |
| 650 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 651 | auto *VD = dyn_cast<VarDecl>(D); |
| 652 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 653 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 654 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 655 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 656 | (VD && VD->getStorageClass() == SC_Register && |
| 657 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 658 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 659 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 660 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 661 | } |
| 662 | if (Stack[0].SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 663 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 664 | DVar.CKind = OMPC_threadprivate; |
| 665 | return DVar; |
| 666 | } |
| 667 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 668 | if (Stack.size() == 1) { |
| 669 | // Not in OpenMP execution region and top scope was already checked. |
| 670 | return DVar; |
| 671 | } |
| 672 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 673 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 674 | // in a Construct, C/C++, predetermined, p.4] |
| 675 | // Static data members are shared. |
| 676 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 677 | // in a Construct, C/C++, predetermined, p.7] |
| 678 | // Variables with static storage duration that are declared in a scope |
| 679 | // inside the construct are shared. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 680 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 681 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 682 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 683 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 684 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 685 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 686 | DVar.CKind = OMPC_shared; |
| 687 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 691 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 692 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 693 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 694 | // in a Construct, C/C++, predetermined, p.6] |
| 695 | // Variables with const qualified type having no mutable member are |
| 696 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 697 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 698 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 699 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 700 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 701 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 702 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 703 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 704 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 705 | // Variables with const-qualified type having no mutable member may be |
| 706 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 707 | DSAVarData DVarTemp = hasDSA( |
| 708 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, |
| 709 | MatchesAlways, FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 710 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 711 | return DVar; |
| 712 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 713 | DVar.CKind = OMPC_shared; |
| 714 | return DVar; |
| 715 | } |
| 716 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 717 | // Explicitly specified attributes and local variables with predetermined |
| 718 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 719 | auto StartI = std::next(Stack.rbegin()); |
| 720 | auto EndI = std::prev(Stack.rend()); |
| 721 | if (FromParent && StartI != EndI) { |
| 722 | StartI = std::next(StartI); |
| 723 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 724 | auto I = std::prev(StartI); |
| 725 | if (I->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 726 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 727 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 728 | DVar.CKind = I->SharingMap[D].Attributes; |
| 729 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | return DVar; |
| 733 | } |
| 734 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 735 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 736 | bool FromParent) { |
| 737 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 738 | auto StartI = Stack.rbegin(); |
| 739 | auto EndI = std::prev(Stack.rend()); |
| 740 | if (FromParent && StartI != EndI) { |
| 741 | StartI = std::next(StartI); |
| 742 | } |
| 743 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 746 | DSAStackTy::DSAVarData |
| 747 | DSAStackTy::hasDSA(ValueDecl *D, |
| 748 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 749 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 750 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 751 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 752 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 753 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 754 | if (FromParent && StartI != EndI) { |
| 755 | StartI = std::next(StartI); |
| 756 | } |
| 757 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 758 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 759 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 760 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 761 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 762 | return DVar; |
| 763 | } |
| 764 | return DSAVarData(); |
| 765 | } |
| 766 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 767 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| 768 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 769 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 770 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 771 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 772 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 773 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 774 | if (FromParent && StartI != EndI) { |
| 775 | StartI = std::next(StartI); |
| 776 | } |
| 777 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 778 | if (!DPred(I->Directive)) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 779 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 780 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 781 | if (CPred(DVar.CKind)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 782 | return DVar; |
| 783 | return DSAVarData(); |
| 784 | } |
| 785 | return DSAVarData(); |
| 786 | } |
| 787 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 788 | bool DSAStackTy::hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 789 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 790 | unsigned Level, bool NotLastprivate) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 791 | if (CPred(ClauseKindMode)) |
| 792 | return true; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 793 | D = getCanonicalDecl(D); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 794 | auto StartI = std::next(Stack.begin()); |
| 795 | auto EndI = Stack.end(); |
NAKAMURA Takumi | 0332eda | 2015-06-23 10:01:20 +0000 | [diff] [blame] | 796 | if (std::distance(StartI, EndI) <= (int)Level) |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 797 | return false; |
| 798 | std::advance(StartI, Level); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 799 | return (StartI->SharingMap.count(D) > 0) && |
| 800 | StartI->SharingMap[D].RefExpr.getPointer() && |
| 801 | CPred(StartI->SharingMap[D].Attributes) && |
| 802 | (!NotLastprivate || !StartI->SharingMap[D].RefExpr.getInt()); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 805 | bool DSAStackTy::hasExplicitDirective( |
| 806 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 807 | unsigned Level) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 808 | auto StartI = std::next(Stack.begin()); |
| 809 | auto EndI = Stack.end(); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 810 | if (std::distance(StartI, EndI) <= (int)Level) |
| 811 | return false; |
| 812 | std::advance(StartI, Level); |
| 813 | return DPred(StartI->Directive); |
| 814 | } |
| 815 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 816 | bool DSAStackTy::hasDirective( |
| 817 | const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 818 | const DeclarationNameInfo &, SourceLocation)> |
| 819 | &DPred, |
| 820 | bool FromParent) { |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 821 | // We look only in the enclosing region. |
| 822 | if (Stack.size() < 2) |
| 823 | return false; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 824 | auto StartI = std::next(Stack.rbegin()); |
| 825 | auto EndI = std::prev(Stack.rend()); |
| 826 | if (FromParent && StartI != EndI) { |
| 827 | StartI = std::next(StartI); |
| 828 | } |
| 829 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 830 | if (DPred(I->Directive, I->DirectiveName, I->ConstructLoc)) |
| 831 | return true; |
| 832 | } |
| 833 | return false; |
| 834 | } |
| 835 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 836 | void Sema::InitDataSharingAttributesStack() { |
| 837 | VarDataSharingAttributesStack = new DSAStackTy(*this); |
| 838 | } |
| 839 | |
| 840 | #define DSAStack static_cast<DSAStackTy *>(VarDataSharingAttributesStack) |
| 841 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 842 | bool Sema::IsOpenMPCapturedByRef(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 843 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 844 | |
| 845 | auto &Ctx = getASTContext(); |
| 846 | bool IsByRef = true; |
| 847 | |
| 848 | // Find the directive that is associated with the provided scope. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 849 | auto Ty = D->getType(); |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 850 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 851 | if (DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, Level)) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 852 | // This table summarizes how a given variable should be passed to the device |
| 853 | // given its type and the clauses where it appears. This table is based on |
| 854 | // the description in OpenMP 4.5 [2.10.4, target Construct] and |
| 855 | // OpenMP 4.5 [2.15.5, Data-mapping Attribute Rules and Clauses]. |
| 856 | // |
| 857 | // ========================================================================= |
| 858 | // | type | defaultmap | pvt | first | is_device_ptr | map | res. | |
| 859 | // | |(tofrom:scalar)| | pvt | | | | |
| 860 | // ========================================================================= |
| 861 | // | scl | | | | - | | bycopy| |
| 862 | // | scl | | - | x | - | - | bycopy| |
| 863 | // | scl | | x | - | - | - | null | |
| 864 | // | scl | x | | | - | | byref | |
| 865 | // | scl | x | - | x | - | - | bycopy| |
| 866 | // | scl | x | x | - | - | - | null | |
| 867 | // | scl | | - | - | - | x | byref | |
| 868 | // | scl | x | - | - | - | x | byref | |
| 869 | // |
| 870 | // | agg | n.a. | | | - | | byref | |
| 871 | // | agg | n.a. | - | x | - | - | byref | |
| 872 | // | agg | n.a. | x | - | - | - | null | |
| 873 | // | agg | n.a. | - | - | - | x | byref | |
| 874 | // | agg | n.a. | - | - | - | x[] | byref | |
| 875 | // |
| 876 | // | ptr | n.a. | | | - | | bycopy| |
| 877 | // | ptr | n.a. | - | x | - | - | bycopy| |
| 878 | // | ptr | n.a. | x | - | - | - | null | |
| 879 | // | ptr | n.a. | - | - | - | x | byref | |
| 880 | // | ptr | n.a. | - | - | - | x[] | bycopy| |
| 881 | // | ptr | n.a. | - | - | x | | bycopy| |
| 882 | // | ptr | n.a. | - | - | x | x | bycopy| |
| 883 | // | ptr | n.a. | - | - | x | x[] | bycopy| |
| 884 | // ========================================================================= |
| 885 | // Legend: |
| 886 | // scl - scalar |
| 887 | // ptr - pointer |
| 888 | // agg - aggregate |
| 889 | // x - applies |
| 890 | // - - invalid in this combination |
| 891 | // [] - mapped with an array section |
| 892 | // byref - should be mapped by reference |
| 893 | // byval - should be mapped by value |
| 894 | // null - initialize a local variable to null on the device |
| 895 | // |
| 896 | // Observations: |
| 897 | // - All scalar declarations that show up in a map clause have to be passed |
| 898 | // by reference, because they may have been mapped in the enclosing data |
| 899 | // environment. |
| 900 | // - If the scalar value does not fit the size of uintptr, it has to be |
| 901 | // passed by reference, regardless the result in the table above. |
| 902 | // - For pointers mapped by value that have either an implicit map or an |
| 903 | // array section, the runtime library may pass the NULL value to the |
| 904 | // device instead of the value passed to it by the compiler. |
| 905 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 906 | |
| 907 | if (Ty->isReferenceType()) |
| 908 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 909 | |
| 910 | // Locate map clauses and see if the variable being captured is referred to |
| 911 | // in any of those clauses. Here we only care about variables, not fields, |
| 912 | // because fields are part of aggregates. |
| 913 | bool IsVariableUsedInMapClause = false; |
| 914 | bool IsVariableAssociatedWithSection = false; |
| 915 | |
| 916 | DSAStack->checkMappableExprComponentListsForDecl( |
| 917 | D, /*CurrentRegionOnly=*/true, |
| 918 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 919 | MapExprComponents) { |
| 920 | |
| 921 | auto EI = MapExprComponents.rbegin(); |
| 922 | auto EE = MapExprComponents.rend(); |
| 923 | |
| 924 | assert(EI != EE && "Invalid map expression!"); |
| 925 | |
| 926 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 927 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 928 | |
| 929 | ++EI; |
| 930 | if (EI == EE) |
| 931 | return false; |
| 932 | |
| 933 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 934 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 935 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 936 | IsVariableAssociatedWithSection = true; |
| 937 | // There is nothing more we need to know about this variable. |
| 938 | return true; |
| 939 | } |
| 940 | |
| 941 | // Keep looking for more map info. |
| 942 | return false; |
| 943 | }); |
| 944 | |
| 945 | if (IsVariableUsedInMapClause) { |
| 946 | // If variable is identified in a map clause it is always captured by |
| 947 | // reference except if it is a pointer that is dereferenced somehow. |
| 948 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 949 | } else { |
| 950 | // By default, all the data that has a scalar type is mapped by copy. |
| 951 | IsByRef = !Ty->isScalarType(); |
| 952 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 955 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| 956 | IsByRef = !DSAStack->hasExplicitDSA( |
| 957 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 958 | Level, /*NotLastprivate=*/true); |
| 959 | } |
| 960 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 961 | // When passing data by copy, we need to make sure it fits the uintptr size |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 962 | // and alignment, because the runtime library only deals with uintptr types. |
| 963 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 964 | // instead. |
| 965 | if (!IsByRef && |
| 966 | (Ctx.getTypeSizeInChars(Ty) > |
| 967 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 968 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 969 | IsByRef = true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 970 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 971 | |
| 972 | return IsByRef; |
| 973 | } |
| 974 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 975 | unsigned Sema::getOpenMPNestingLevel() const { |
| 976 | assert(getLangOpts().OpenMP); |
| 977 | return DSAStack->getNestingLevel(); |
| 978 | } |
| 979 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 980 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 981 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 982 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 983 | |
| 984 | // If we are attempting to capture a global variable in a directive with |
| 985 | // 'target' we return true so that this global is also mapped to the device. |
| 986 | // |
| 987 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 988 | // then it should not be captured. Therefore, an extra check has to be |
| 989 | // inserted here once support for 'declare target' is added. |
| 990 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 991 | auto *VD = dyn_cast<VarDecl>(D); |
| 992 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 993 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 994 | !DSAStack->isClauseParsingMode()) |
| 995 | return VD; |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 996 | if (DSAStack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 997 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 998 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 999 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1000 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1001 | false)) |
| 1002 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1003 | } |
| 1004 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1005 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1006 | (!DSAStack->isClauseParsingMode() || |
| 1007 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1008 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1009 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1010 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1011 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1012 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1013 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1014 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1015 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1016 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1017 | DVarPrivate = DSAStack->hasDSA( |
| 1018 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 1019 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1020 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1021 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1022 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1023 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1024 | } |
| 1025 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1026 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1027 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1028 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1029 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1030 | } |
| 1031 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1032 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1033 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1034 | // Return true if the current level is no longer enclosed in a target region. |
| 1035 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1036 | auto *VD = dyn_cast<VarDecl>(D); |
| 1037 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1038 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1039 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1042 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1043 | |
| 1044 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1045 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1046 | Scope *CurScope, SourceLocation Loc) { |
| 1047 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1048 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 1049 | } |
| 1050 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1051 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1052 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1055 | void Sema::EndOpenMPClause() { |
| 1056 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1059 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1060 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1061 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1062 | // clause requires an accessible, unambiguous default constructor for the |
| 1063 | // class type, unless the list item is also specified in a firstprivate |
| 1064 | // clause. |
| 1065 | if (auto D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1066 | for (auto *C : D->clauses()) { |
| 1067 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1068 | SmallVector<Expr *, 8> PrivateCopies; |
| 1069 | for (auto *DE : Clause->varlists()) { |
| 1070 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1071 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1072 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1073 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1074 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1075 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1076 | QualType Type = VD->getType().getNonReferenceType(); |
| 1077 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1078 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1079 | // Generate helper private variable and initialize it with the |
| 1080 | // default value. The address of the original variable is replaced |
| 1081 | // by the address of the new private variable in CodeGen. This new |
| 1082 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1083 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1084 | auto *VDPrivate = buildVarDecl( |
| 1085 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1086 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1087 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1088 | if (VDPrivate->isInvalidDecl()) |
| 1089 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1090 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1091 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1092 | } else { |
| 1093 | // The variable is also a firstprivate, so initialization sequence |
| 1094 | // for private copy is generated already. |
| 1095 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1096 | } |
| 1097 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1098 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1099 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1100 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | } |
| 1104 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1105 | DSAStack->pop(); |
| 1106 | DiscardCleanupsInEvaluationContext(); |
| 1107 | PopExpressionEvaluationContext(); |
| 1108 | } |
| 1109 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1110 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1111 | Expr *NumIterations, Sema &SemaRef, |
| 1112 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1113 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1114 | namespace { |
| 1115 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1116 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1117 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1118 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1119 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1120 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1121 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1122 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1123 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1124 | if (VarDecl *VD = dyn_cast_or_null<VarDecl>(ND)) { |
| 1125 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1126 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1127 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1128 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1129 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1130 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1131 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1132 | |
| 1133 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1134 | private: |
| 1135 | Sema &SemaRef; |
| 1136 | |
| 1137 | public: |
| 1138 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1139 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1140 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1141 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1142 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1143 | SemaRef.getCurScope()); |
| 1144 | } |
| 1145 | return false; |
| 1146 | } |
| 1147 | }; |
| 1148 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1149 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1150 | |
| 1151 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1152 | CXXScopeSpec &ScopeSpec, |
| 1153 | const DeclarationNameInfo &Id) { |
| 1154 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1155 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1156 | |
| 1157 | if (Lookup.isAmbiguous()) |
| 1158 | return ExprError(); |
| 1159 | |
| 1160 | VarDecl *VD; |
| 1161 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1162 | if (TypoCorrection Corrected = CorrectTypo( |
| 1163 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1164 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1165 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1166 | PDiag(Lookup.empty() |
| 1167 | ? diag::err_undeclared_var_use_suggest |
| 1168 | : diag::err_omp_expected_var_arg_suggest) |
| 1169 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1170 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1171 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1172 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1173 | : diag::err_omp_expected_var_arg) |
| 1174 | << Id.getName(); |
| 1175 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1176 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1177 | } else { |
| 1178 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1179 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1180 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1181 | return ExprError(); |
| 1182 | } |
| 1183 | } |
| 1184 | Lookup.suppressDiagnostics(); |
| 1185 | |
| 1186 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1187 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1188 | if (!VD->hasGlobalStorage()) { |
| 1189 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1190 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1191 | bool IsDecl = |
| 1192 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1193 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1194 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1195 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1196 | return ExprError(); |
| 1197 | } |
| 1198 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1199 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1200 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1201 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1202 | // A threadprivate directive for file-scope variables must appear outside |
| 1203 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1204 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1205 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1206 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1207 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1208 | bool IsDecl = |
| 1209 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1210 | Diag(VD->getLocation(), |
| 1211 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1212 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1213 | return ExprError(); |
| 1214 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1215 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1216 | // A threadprivate directive for static class member variables must appear |
| 1217 | // in the class definition, in the same scope in which the member |
| 1218 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1219 | if (CanonicalVD->isStaticDataMember() && |
| 1220 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1221 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1222 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1223 | bool IsDecl = |
| 1224 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1225 | Diag(VD->getLocation(), |
| 1226 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1227 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1228 | return ExprError(); |
| 1229 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1230 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1231 | // A threadprivate directive for namespace-scope variables must appear |
| 1232 | // outside any definition or declaration other than the namespace |
| 1233 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1234 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1235 | (!getCurLexicalContext()->isFileContext() || |
| 1236 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1237 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1238 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1239 | bool IsDecl = |
| 1240 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1241 | Diag(VD->getLocation(), |
| 1242 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1243 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1244 | return ExprError(); |
| 1245 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1246 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1247 | // A threadprivate directive for static block-scope variables must appear |
| 1248 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1249 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1250 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1251 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1252 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1253 | bool IsDecl = |
| 1254 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1255 | Diag(VD->getLocation(), |
| 1256 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1257 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1258 | return ExprError(); |
| 1259 | } |
| 1260 | |
| 1261 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1262 | // A threadprivate directive must lexically precede all references to any |
| 1263 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1264 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1265 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1266 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1267 | return ExprError(); |
| 1268 | } |
| 1269 | |
| 1270 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1271 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1272 | SourceLocation(), VD, |
| 1273 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1274 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1277 | Sema::DeclGroupPtrTy |
| 1278 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1279 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1280 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1281 | CurContext->addDecl(D); |
| 1282 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1283 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1284 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1287 | namespace { |
| 1288 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1289 | Sema &SemaRef; |
| 1290 | |
| 1291 | public: |
| 1292 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
| 1293 | if (auto VD = dyn_cast<VarDecl>(E->getDecl())) { |
| 1294 | if (VD->hasLocalStorage()) { |
| 1295 | SemaRef.Diag(E->getLocStart(), |
| 1296 | diag::err_omp_local_var_in_threadprivate_init) |
| 1297 | << E->getSourceRange(); |
| 1298 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1299 | << VD << VD->getSourceRange(); |
| 1300 | return true; |
| 1301 | } |
| 1302 | } |
| 1303 | return false; |
| 1304 | } |
| 1305 | bool VisitStmt(const Stmt *S) { |
| 1306 | for (auto Child : S->children()) { |
| 1307 | if (Child && Visit(Child)) |
| 1308 | return true; |
| 1309 | } |
| 1310 | return false; |
| 1311 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1312 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1313 | }; |
| 1314 | } // namespace |
| 1315 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1316 | OMPThreadPrivateDecl * |
| 1317 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1318 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1319 | for (auto &RefExpr : VarList) { |
| 1320 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1321 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1322 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1323 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1324 | // Mark variable as used. |
| 1325 | VD->setReferenced(); |
| 1326 | VD->markUsed(Context); |
| 1327 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1328 | QualType QType = VD->getType(); |
| 1329 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1330 | // It will be analyzed later. |
| 1331 | Vars.push_back(DE); |
| 1332 | continue; |
| 1333 | } |
| 1334 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1335 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1336 | // A threadprivate variable must not have an incomplete type. |
| 1337 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1338 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1339 | continue; |
| 1340 | } |
| 1341 | |
| 1342 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1343 | // A threadprivate variable must not have a reference type. |
| 1344 | if (VD->getType()->isReferenceType()) { |
| 1345 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1346 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1347 | bool IsDecl = |
| 1348 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1349 | Diag(VD->getLocation(), |
| 1350 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1351 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1352 | continue; |
| 1353 | } |
| 1354 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1355 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1356 | // the corresponding diagnostic. |
| 1357 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1358 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1359 | getLangOpts().OpenMPUseTLS && |
| 1360 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1361 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1362 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1363 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1364 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1365 | bool IsDecl = |
| 1366 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1367 | Diag(VD->getLocation(), |
| 1368 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1369 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1370 | continue; |
| 1371 | } |
| 1372 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1373 | // Check if initial value of threadprivate variable reference variable with |
| 1374 | // local storage (it is not supported by runtime). |
| 1375 | if (auto Init = VD->getAnyInitializer()) { |
| 1376 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1377 | if (Checker.Visit(Init)) |
| 1378 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1379 | } |
| 1380 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1381 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1382 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1383 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1384 | Context, SourceRange(Loc, Loc))); |
| 1385 | if (auto *ML = Context.getASTMutationListener()) |
| 1386 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1387 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1388 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1389 | if (!Vars.empty()) { |
| 1390 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1391 | Vars); |
| 1392 | D->setAccess(AS_public); |
| 1393 | } |
| 1394 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1395 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1396 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1397 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1398 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1399 | bool IsLoopIterVar = false) { |
| 1400 | if (DVar.RefExpr) { |
| 1401 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1402 | << getOpenMPClauseName(DVar.CKind); |
| 1403 | return; |
| 1404 | } |
| 1405 | enum { |
| 1406 | PDSA_StaticMemberShared, |
| 1407 | PDSA_StaticLocalVarShared, |
| 1408 | PDSA_LoopIterVarPrivate, |
| 1409 | PDSA_LoopIterVarLinear, |
| 1410 | PDSA_LoopIterVarLastprivate, |
| 1411 | PDSA_ConstVarShared, |
| 1412 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1413 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1414 | PDSA_LocalVarPrivate, |
| 1415 | PDSA_Implicit |
| 1416 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1417 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1418 | auto ReportLoc = D->getLocation(); |
| 1419 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1420 | if (IsLoopIterVar) { |
| 1421 | if (DVar.CKind == OMPC_private) |
| 1422 | Reason = PDSA_LoopIterVarPrivate; |
| 1423 | else if (DVar.CKind == OMPC_lastprivate) |
| 1424 | Reason = PDSA_LoopIterVarLastprivate; |
| 1425 | else |
| 1426 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1427 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1428 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1429 | Reason = PDSA_TaskVarFirstprivate; |
| 1430 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1431 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1432 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1433 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1434 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1435 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1436 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1437 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1438 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1439 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1440 | ReportHint = true; |
| 1441 | Reason = PDSA_LocalVarPrivate; |
| 1442 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1443 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1444 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1445 | << Reason << ReportHint |
| 1446 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1447 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1448 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1449 | << getOpenMPClauseName(DVar.CKind); |
| 1450 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1453 | namespace { |
| 1454 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1455 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1456 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1457 | bool ErrorFound; |
| 1458 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1459 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1460 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1461 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1462 | public: |
| 1463 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1464 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1465 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1466 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1467 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1468 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1469 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1470 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1471 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1472 | auto DVar = Stack->getTopDSA(VD, false); |
| 1473 | // Check if the variable has explicit DSA set and stop analysis if it so. |
| 1474 | if (DVar.RefExpr) return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1475 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1476 | auto ELoc = E->getExprLoc(); |
| 1477 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1478 | // The default(none) clause requires that each variable that is referenced |
| 1479 | // in the construct, and does not have a predetermined data-sharing |
| 1480 | // attribute, must have its data-sharing attribute explicitly determined |
| 1481 | // by being listed in a data-sharing attribute clause. |
| 1482 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1483 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1484 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1485 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1486 | return; |
| 1487 | } |
| 1488 | |
| 1489 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1490 | // A list item that appears in a reduction clause of the innermost |
| 1491 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1492 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1493 | DVar = Stack->hasInnermostDSA( |
| 1494 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1495 | [](OpenMPDirectiveKind K) -> bool { |
| 1496 | return isOpenMPParallelDirective(K) || |
| 1497 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1498 | }, |
| 1499 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1500 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1501 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1502 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1503 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1504 | return; |
| 1505 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1506 | |
| 1507 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1508 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1509 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1510 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1511 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1512 | } |
| 1513 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1514 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1515 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1516 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1517 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1518 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1519 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1520 | auto DVar = Stack->getTopDSA(FD, false); |
| 1521 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1522 | // so. |
| 1523 | if (DVar.RefExpr) |
| 1524 | return; |
| 1525 | |
| 1526 | auto ELoc = E->getExprLoc(); |
| 1527 | auto DKind = Stack->getCurrentDirective(); |
| 1528 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1529 | // A list item that appears in a reduction clause of the innermost |
| 1530 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1531 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1532 | DVar = Stack->hasInnermostDSA( |
| 1533 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1534 | [](OpenMPDirectiveKind K) -> bool { |
| 1535 | return isOpenMPParallelDirective(K) || |
| 1536 | isOpenMPWorksharingDirective(K) || |
| 1537 | isOpenMPTeamsDirective(K); |
| 1538 | }, |
| 1539 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1540 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1541 | ErrorFound = true; |
| 1542 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1543 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1544 | return; |
| 1545 | } |
| 1546 | |
| 1547 | // Define implicit data-sharing attributes for task. |
| 1548 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1549 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1550 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1551 | ImplicitFirstprivate.push_back(E); |
| 1552 | } |
| 1553 | } |
| 1554 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1555 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1556 | for (auto *C : S->clauses()) { |
| 1557 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1558 | // for task directives. |
| 1559 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1560 | for (auto *CC : C->children()) { |
| 1561 | if (CC) |
| 1562 | Visit(CC); |
| 1563 | } |
| 1564 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1565 | } |
| 1566 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1567 | for (auto *C : S->children()) { |
| 1568 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1569 | Visit(C); |
| 1570 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1571 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1572 | |
| 1573 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1574 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1575 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1576 | return VarsWithInheritedDSA; |
| 1577 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1578 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1579 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1580 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1581 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1582 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1583 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1584 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1585 | switch (DKind) { |
| 1586 | case OMPD_parallel: { |
| 1587 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1588 | QualType KmpInt32PtrTy = |
| 1589 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1590 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1591 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1592 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1593 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1594 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1595 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1596 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1597 | break; |
| 1598 | } |
| 1599 | case OMPD_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1600 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1601 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1602 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1603 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1604 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1605 | break; |
| 1606 | } |
| 1607 | case OMPD_for: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1608 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1609 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1610 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1611 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1612 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | } |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1615 | case OMPD_for_simd: { |
| 1616 | Sema::CapturedParamNameType Params[] = { |
| 1617 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1618 | }; |
| 1619 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1620 | Params); |
| 1621 | break; |
| 1622 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1623 | case OMPD_sections: { |
| 1624 | Sema::CapturedParamNameType Params[] = { |
| 1625 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1626 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1627 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1628 | Params); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1629 | break; |
| 1630 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1631 | case OMPD_section: { |
| 1632 | Sema::CapturedParamNameType Params[] = { |
| 1633 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1634 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1635 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1636 | Params); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1637 | break; |
| 1638 | } |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1639 | case OMPD_single: { |
| 1640 | Sema::CapturedParamNameType Params[] = { |
| 1641 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1642 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1643 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1644 | Params); |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1645 | break; |
| 1646 | } |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1647 | case OMPD_master: { |
| 1648 | Sema::CapturedParamNameType Params[] = { |
| 1649 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1650 | }; |
| 1651 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1652 | Params); |
| 1653 | break; |
| 1654 | } |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1655 | case OMPD_critical: { |
| 1656 | Sema::CapturedParamNameType Params[] = { |
| 1657 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1658 | }; |
| 1659 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1660 | Params); |
| 1661 | break; |
| 1662 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1663 | case OMPD_parallel_for: { |
| 1664 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1665 | QualType KmpInt32PtrTy = |
| 1666 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1667 | Sema::CapturedParamNameType Params[] = { |
| 1668 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1669 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1670 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1671 | }; |
| 1672 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1673 | Params); |
| 1674 | break; |
| 1675 | } |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1676 | case OMPD_parallel_for_simd: { |
| 1677 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1678 | QualType KmpInt32PtrTy = |
| 1679 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1680 | Sema::CapturedParamNameType Params[] = { |
| 1681 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1682 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1683 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1684 | }; |
| 1685 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1686 | Params); |
| 1687 | break; |
| 1688 | } |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1689 | case OMPD_parallel_sections: { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1690 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1691 | QualType KmpInt32PtrTy = |
| 1692 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1693 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 68adb7d | 2015-04-14 03:29:22 +0000 | [diff] [blame] | 1694 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1695 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1696 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1697 | }; |
| 1698 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1699 | Params); |
| 1700 | break; |
| 1701 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1702 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1703 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1704 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1705 | FunctionProtoType::ExtProtoInfo EPI; |
| 1706 | EPI.Variadic = true; |
| 1707 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1708 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1709 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1710 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1711 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1712 | std::make_pair(".copy_fn.", |
| 1713 | Context.getPointerType(CopyFnType).withConst()), |
| 1714 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1715 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1716 | }; |
| 1717 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1718 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1719 | // Mark this captured region as inlined, because we don't use outlined |
| 1720 | // function directly. |
| 1721 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1722 | AlwaysInlineAttr::CreateImplicit( |
| 1723 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1724 | break; |
| 1725 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1726 | case OMPD_ordered: { |
| 1727 | Sema::CapturedParamNameType Params[] = { |
| 1728 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1729 | }; |
| 1730 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1731 | Params); |
| 1732 | break; |
| 1733 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1734 | case OMPD_atomic: { |
| 1735 | Sema::CapturedParamNameType Params[] = { |
| 1736 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1737 | }; |
| 1738 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1739 | Params); |
| 1740 | break; |
| 1741 | } |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1742 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1743 | case OMPD_target: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1744 | case OMPD_target_parallel: |
| 1745 | case OMPD_target_parallel_for: { |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1746 | Sema::CapturedParamNameType Params[] = { |
| 1747 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1748 | }; |
| 1749 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1750 | Params); |
| 1751 | break; |
| 1752 | } |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1753 | case OMPD_teams: { |
| 1754 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1755 | QualType KmpInt32PtrTy = |
| 1756 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1757 | Sema::CapturedParamNameType Params[] = { |
| 1758 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1759 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1760 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1761 | }; |
| 1762 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1763 | Params); |
| 1764 | break; |
| 1765 | } |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1766 | case OMPD_taskgroup: { |
| 1767 | Sema::CapturedParamNameType Params[] = { |
| 1768 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1769 | }; |
| 1770 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1771 | Params); |
| 1772 | break; |
| 1773 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1774 | case OMPD_taskloop: |
| 1775 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1776 | QualType KmpInt32Ty = |
| 1777 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1778 | QualType KmpUInt64Ty = |
| 1779 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1780 | QualType KmpInt64Ty = |
| 1781 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1782 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1783 | FunctionProtoType::ExtProtoInfo EPI; |
| 1784 | EPI.Variadic = true; |
| 1785 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1786 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1787 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1788 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1789 | std::make_pair(".privates.", |
| 1790 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1791 | std::make_pair( |
| 1792 | ".copy_fn.", |
| 1793 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1794 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1795 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1796 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1797 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1798 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1799 | }; |
| 1800 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1801 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1802 | // Mark this captured region as inlined, because we don't use outlined |
| 1803 | // function directly. |
| 1804 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1805 | AlwaysInlineAttr::CreateImplicit( |
| 1806 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1807 | break; |
| 1808 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1809 | case OMPD_distribute: { |
| 1810 | Sema::CapturedParamNameType Params[] = { |
| 1811 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1812 | }; |
| 1813 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1814 | Params); |
| 1815 | break; |
| 1816 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1817 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 1818 | case OMPD_distribute_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1819 | case OMPD_distribute_parallel_for: { |
| 1820 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1821 | QualType KmpInt32PtrTy = |
| 1822 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1823 | Sema::CapturedParamNameType Params[] = { |
| 1824 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1825 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1826 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1827 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1828 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1829 | }; |
| 1830 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1831 | Params); |
| 1832 | break; |
| 1833 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1834 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1835 | case OMPD_taskyield: |
| 1836 | case OMPD_barrier: |
| 1837 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1838 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1839 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1840 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1841 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1842 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1843 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1844 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1845 | case OMPD_declare_target: |
| 1846 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1847 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1848 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1849 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1850 | llvm_unreachable("Unknown OpenMP directive"); |
| 1851 | } |
| 1852 | } |
| 1853 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1854 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1855 | Expr *CaptureExpr, bool WithInit, |
| 1856 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1857 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1858 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1859 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1860 | QualType Ty = Init->getType(); |
| 1861 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1862 | if (S.getLangOpts().CPlusPlus) |
| 1863 | Ty = C.getLValueReferenceType(Ty); |
| 1864 | else { |
| 1865 | Ty = C.getPointerType(Ty); |
| 1866 | ExprResult Res = |
| 1867 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1868 | if (!Res.isUsable()) |
| 1869 | return nullptr; |
| 1870 | Init = Res.get(); |
| 1871 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1872 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1873 | } |
| 1874 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1875 | if (!WithInit) |
| 1876 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1877 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1878 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1879 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1880 | return CED; |
| 1881 | } |
| 1882 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1883 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1884 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1885 | OMPCapturedExprDecl *CD; |
| 1886 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1887 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1888 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1889 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1890 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1891 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1892 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1895 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1896 | if (!Ref) { |
| 1897 | auto *CD = |
| 1898 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1899 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1900 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1901 | CaptureExpr->getExprLoc()); |
| 1902 | } |
| 1903 | ExprResult Res = Ref; |
| 1904 | if (!S.getLangOpts().CPlusPlus && |
| 1905 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1906 | Ref->getType()->isPointerType()) |
| 1907 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1908 | if (!Res.isUsable()) |
| 1909 | return ExprError(); |
| 1910 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1911 | } |
| 1912 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1913 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1914 | ArrayRef<OMPClause *> Clauses) { |
| 1915 | if (!S.isUsable()) { |
| 1916 | ActOnCapturedRegionError(); |
| 1917 | return StmtError(); |
| 1918 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1919 | |
| 1920 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1921 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1922 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1923 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1924 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1925 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1926 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1927 | (getLangOpts().OpenMPUseTLS && |
| 1928 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1929 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1930 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1931 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1932 | for (auto *VarRef : Clause->children()) { |
| 1933 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1934 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1935 | } |
| 1936 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1937 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1938 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1939 | // Mark all variables in private list clauses as used in inner region. |
| 1940 | // Required for proper codegen of combined directives. |
| 1941 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1942 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1943 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1944 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1945 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1946 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1947 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1948 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1949 | if (auto *E = C->getPostUpdateExpr()) |
| 1950 | MarkDeclarationsReferencedInExpr(E); |
| 1951 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1952 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1953 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1954 | SC = cast<OMPScheduleClause>(Clause); |
| 1955 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1956 | OC = cast<OMPOrderedClause>(Clause); |
| 1957 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1958 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1959 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1960 | bool ErrorFound = false; |
| 1961 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1962 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1963 | // specified. |
| 1964 | if (SC && |
| 1965 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1966 | SC->getSecondScheduleModifier() == |
| 1967 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1968 | OC) { |
| 1969 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1970 | ? SC->getFirstScheduleModifierLoc() |
| 1971 | : SC->getSecondScheduleModifierLoc(), |
| 1972 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1973 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1974 | ErrorFound = true; |
| 1975 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1976 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1977 | for (auto *C : LCs) { |
| 1978 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1979 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1980 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1981 | ErrorFound = true; |
| 1982 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1983 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1984 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1985 | OC->getNumForLoops()) { |
| 1986 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1987 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1988 | ErrorFound = true; |
| 1989 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1990 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1991 | ActOnCapturedRegionError(); |
| 1992 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1993 | } |
| 1994 | return ActOnCapturedRegionEnd(S.get()); |
| 1995 | } |
| 1996 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1997 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1998 | OpenMPDirectiveKind CurrentRegion, |
| 1999 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2000 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2001 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2002 | // Allowed nesting of constructs |
| 2003 | // +------------------+-----------------+------------------------------------+ |
| 2004 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 2005 | // +------------------+-----------------+------------------------------------+ |
| 2006 | // | parallel | parallel | * | |
| 2007 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2008 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2009 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2010 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2011 | // | parallel | simd | * | |
| 2012 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2013 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2014 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2015 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2016 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2017 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2018 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2019 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2020 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2021 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2022 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2023 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2024 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2025 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2026 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2027 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2028 | // | parallel | target parallel | * | |
| 2029 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2030 | // | parallel | target enter | * | |
| 2031 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2032 | // | parallel | target exit | * | |
| 2033 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2034 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2035 | // | parallel | cancellation | | |
| 2036 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2037 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2038 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2039 | // | parallel | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2040 | // | parallel | distribute | + | |
| 2041 | // | parallel | distribute | + | |
| 2042 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2043 | // | parallel | distribute | + | |
| 2044 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2045 | // | parallel | distribute simd | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2046 | // +------------------+-----------------+------------------------------------+ |
| 2047 | // | for | parallel | * | |
| 2048 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2049 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2050 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2051 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2052 | // | for | simd | * | |
| 2053 | // | for | sections | + | |
| 2054 | // | for | section | + | |
| 2055 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2056 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2057 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2058 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2059 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2060 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2061 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2062 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2063 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2064 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2065 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2066 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2067 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2068 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2069 | // | for | target parallel | * | |
| 2070 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2071 | // | for | target enter | * | |
| 2072 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2073 | // | for | target exit | * | |
| 2074 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2075 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2076 | // | for | cancellation | | |
| 2077 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2078 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2079 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2080 | // | for | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2081 | // | for | distribute | + | |
| 2082 | // | for | distribute | + | |
| 2083 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2084 | // | for | distribute | + | |
| 2085 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2086 | // | for | distribute simd | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2087 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2088 | // | master | parallel | * | |
| 2089 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2090 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2091 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2092 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2093 | // | master | simd | * | |
| 2094 | // | master | sections | + | |
| 2095 | // | master | section | + | |
| 2096 | // | master | single | + | |
| 2097 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2098 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2099 | // | master |parallel sections| * | |
| 2100 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2101 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2102 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2103 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2104 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2105 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2106 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2107 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2108 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2109 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2110 | // | master | target parallel | * | |
| 2111 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2112 | // | master | target enter | * | |
| 2113 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2114 | // | master | target exit | * | |
| 2115 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2116 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2117 | // | master | cancellation | | |
| 2118 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2119 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2120 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2121 | // | master | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2122 | // | master | distribute | + | |
| 2123 | // | master | distribute | + | |
| 2124 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2125 | // | master | distribute | + | |
| 2126 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2127 | // | master | distribute simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2128 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2129 | // | critical | parallel | * | |
| 2130 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2131 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2132 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2133 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2134 | // | critical | simd | * | |
| 2135 | // | critical | sections | + | |
| 2136 | // | critical | section | + | |
| 2137 | // | critical | single | + | |
| 2138 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2139 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2140 | // | critical |parallel sections| * | |
| 2141 | // | critical | task | * | |
| 2142 | // | critical | taskyield | * | |
| 2143 | // | critical | barrier | + | |
| 2144 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2145 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2146 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2147 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2148 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2149 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2150 | // | critical | target parallel | * | |
| 2151 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2152 | // | critical | target enter | * | |
| 2153 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2154 | // | critical | target exit | * | |
| 2155 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2156 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2157 | // | critical | cancellation | | |
| 2158 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2159 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2160 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2161 | // | critical | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2162 | // | critical | distribute | + | |
| 2163 | // | critical | distribute | + | |
| 2164 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2165 | // | critical | distribute | + | |
| 2166 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2167 | // | critical | distribute simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2168 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2169 | // | simd | parallel | | |
| 2170 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2171 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2172 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2173 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2174 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2175 | // | simd | sections | | |
| 2176 | // | simd | section | | |
| 2177 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2178 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2179 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2180 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2181 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2182 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2183 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2184 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2185 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2186 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2187 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2188 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2189 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2190 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2191 | // | simd | target parallel | | |
| 2192 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2193 | // | simd | target enter | | |
| 2194 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2195 | // | simd | target exit | | |
| 2196 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2197 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2198 | // | simd | cancellation | | |
| 2199 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2200 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2201 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2202 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2203 | // | simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2204 | // | simd | distribute | | |
| 2205 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2206 | // | simd | distribute | | |
| 2207 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2208 | // | simd | distribute simd | | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2209 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2210 | // | for simd | parallel | | |
| 2211 | // | for simd | for | | |
| 2212 | // | for simd | for simd | | |
| 2213 | // | for simd | master | | |
| 2214 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2215 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2216 | // | for simd | sections | | |
| 2217 | // | for simd | section | | |
| 2218 | // | for simd | single | | |
| 2219 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2220 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2221 | // | for simd |parallel sections| | |
| 2222 | // | for simd | task | | |
| 2223 | // | for simd | taskyield | | |
| 2224 | // | for simd | barrier | | |
| 2225 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2226 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2227 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2228 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2229 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2230 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2231 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2232 | // | for simd | target parallel | | |
| 2233 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2234 | // | for simd | target enter | | |
| 2235 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2236 | // | for simd | target exit | | |
| 2237 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2238 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2239 | // | for simd | cancellation | | |
| 2240 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2241 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2242 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2243 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2244 | // | for simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2245 | // | for simd | distribute | | |
| 2246 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2247 | // | for simd | distribute | | |
| 2248 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2249 | // | for simd | distribute simd | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2250 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2251 | // | parallel for simd| parallel | | |
| 2252 | // | parallel for simd| for | | |
| 2253 | // | parallel for simd| for simd | | |
| 2254 | // | parallel for simd| master | | |
| 2255 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2256 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2257 | // | parallel for simd| sections | | |
| 2258 | // | parallel for simd| section | | |
| 2259 | // | parallel for simd| single | | |
| 2260 | // | parallel for simd| parallel for | | |
| 2261 | // | parallel for simd|parallel for simd| | |
| 2262 | // | parallel for simd|parallel sections| | |
| 2263 | // | parallel for simd| task | | |
| 2264 | // | parallel for simd| taskyield | | |
| 2265 | // | parallel for simd| barrier | | |
| 2266 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2267 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2268 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2269 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2270 | // | parallel for simd| atomic | | |
| 2271 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2272 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2273 | // | parallel for simd| target parallel | | |
| 2274 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2275 | // | parallel for simd| target enter | | |
| 2276 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2277 | // | parallel for simd| target exit | | |
| 2278 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2279 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2280 | // | parallel for simd| cancellation | | |
| 2281 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2282 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2283 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2284 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2285 | // | parallel for simd| distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2286 | // | parallel for simd| distribute | | |
| 2287 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2288 | // | parallel for simd| distribute | | |
| 2289 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2290 | // | parallel for simd| distribute simd | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2291 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2292 | // | sections | parallel | * | |
| 2293 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2294 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2295 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2296 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2297 | // | sections | simd | * | |
| 2298 | // | sections | sections | + | |
| 2299 | // | sections | section | * | |
| 2300 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2301 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2302 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2303 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2304 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2305 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2306 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2307 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2308 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2309 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2310 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2311 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2312 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2313 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2314 | // | sections | target parallel | * | |
| 2315 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2316 | // | sections | target enter | * | |
| 2317 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2318 | // | sections | target exit | * | |
| 2319 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2320 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2321 | // | sections | cancellation | | |
| 2322 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2323 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2324 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2325 | // | sections | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2326 | // | sections | distribute | + | |
| 2327 | // | sections | distribute | + | |
| 2328 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2329 | // | sections | distribute | + | |
| 2330 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2331 | // | sections | distribute simd | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2332 | // +------------------+-----------------+------------------------------------+ |
| 2333 | // | section | parallel | * | |
| 2334 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2335 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2336 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2337 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2338 | // | section | simd | * | |
| 2339 | // | section | sections | + | |
| 2340 | // | section | section | + | |
| 2341 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2342 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2343 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2344 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2345 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2346 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2347 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2348 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2349 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2350 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2351 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2352 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2353 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2354 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2355 | // | section | target parallel | * | |
| 2356 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2357 | // | section | target enter | * | |
| 2358 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2359 | // | section | target exit | * | |
| 2360 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2361 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2362 | // | section | cancellation | | |
| 2363 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2364 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2365 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2366 | // | section | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2367 | // | section | distribute | + | |
| 2368 | // | section | distribute | + | |
| 2369 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2370 | // | section | distribute | + | |
| 2371 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2372 | // | section | distribute simd | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2373 | // +------------------+-----------------+------------------------------------+ |
| 2374 | // | single | parallel | * | |
| 2375 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2376 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2377 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2378 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2379 | // | single | simd | * | |
| 2380 | // | single | sections | + | |
| 2381 | // | single | section | + | |
| 2382 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2383 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2384 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2385 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2386 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2387 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2388 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2389 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2390 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2391 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2392 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2393 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2394 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2395 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2396 | // | single | target parallel | * | |
| 2397 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2398 | // | single | target enter | * | |
| 2399 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2400 | // | single | target exit | * | |
| 2401 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2402 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2403 | // | single | cancellation | | |
| 2404 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2405 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2406 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2407 | // | single | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2408 | // | single | distribute | + | |
| 2409 | // | single | distribute | + | |
| 2410 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2411 | // | single | distribute | + | |
| 2412 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2413 | // | single | distribute simd | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2414 | // +------------------+-----------------+------------------------------------+ |
| 2415 | // | parallel for | parallel | * | |
| 2416 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2417 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2418 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2419 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2420 | // | parallel for | simd | * | |
| 2421 | // | parallel for | sections | + | |
| 2422 | // | parallel for | section | + | |
| 2423 | // | parallel for | single | + | |
| 2424 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2425 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2426 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2427 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2428 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2429 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2430 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2431 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2432 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2433 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2434 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2435 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2436 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2437 | // | parallel for | target parallel | * | |
| 2438 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2439 | // | parallel for | target enter | * | |
| 2440 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2441 | // | parallel for | target exit | * | |
| 2442 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2443 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2444 | // | parallel for | cancellation | | |
| 2445 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2446 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2447 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2448 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2449 | // | parallel for | distribute | + | |
| 2450 | // | parallel for | distribute | + | |
| 2451 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2452 | // | parallel for | distribute | + | |
| 2453 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2454 | // | parallel for | distribute simd | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2455 | // +------------------+-----------------+------------------------------------+ |
| 2456 | // | parallel sections| parallel | * | |
| 2457 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2458 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2459 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2460 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2461 | // | parallel sections| simd | * | |
| 2462 | // | parallel sections| sections | + | |
| 2463 | // | parallel sections| section | * | |
| 2464 | // | parallel sections| single | + | |
| 2465 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2466 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2467 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2468 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2469 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2470 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2471 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2472 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2473 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2474 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2475 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2476 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2477 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2478 | // | parallel sections| target parallel | * | |
| 2479 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2480 | // | parallel sections| target enter | * | |
| 2481 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2482 | // | parallel sections| target exit | * | |
| 2483 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2484 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2485 | // | parallel sections| cancellation | | |
| 2486 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2487 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2488 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2489 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2490 | // | parallel sections| distribute | + | |
| 2491 | // | parallel sections| distribute | + | |
| 2492 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2493 | // | parallel sections| distribute | + | |
| 2494 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2495 | // | parallel sections| distribute simd | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2496 | // +------------------+-----------------+------------------------------------+ |
| 2497 | // | task | parallel | * | |
| 2498 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2499 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2500 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2501 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2502 | // | task | simd | * | |
| 2503 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2504 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2505 | // | task | single | + | |
| 2506 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2507 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2508 | // | task |parallel sections| * | |
| 2509 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2510 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2511 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2512 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2513 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2514 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2515 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2516 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2517 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2518 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2519 | // | task | target parallel | * | |
| 2520 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2521 | // | task | target enter | * | |
| 2522 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2523 | // | task | target exit | * | |
| 2524 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2525 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2526 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2527 | // | | point | ! | |
| 2528 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2529 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2530 | // | task | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2531 | // | task | distribute | + | |
| 2532 | // | task | distribute | + | |
| 2533 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2534 | // | task | distribute | + | |
| 2535 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2536 | // | task | distribute simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2537 | // +------------------+-----------------+------------------------------------+ |
| 2538 | // | ordered | parallel | * | |
| 2539 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2540 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2541 | // | ordered | master | * | |
| 2542 | // | ordered | critical | * | |
| 2543 | // | ordered | simd | * | |
| 2544 | // | ordered | sections | + | |
| 2545 | // | ordered | section | + | |
| 2546 | // | ordered | single | + | |
| 2547 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2548 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2549 | // | ordered |parallel sections| * | |
| 2550 | // | ordered | task | * | |
| 2551 | // | ordered | taskyield | * | |
| 2552 | // | ordered | barrier | + | |
| 2553 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2554 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2555 | // | ordered | flush | * | |
| 2556 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2557 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2558 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2559 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2560 | // | ordered | target parallel | * | |
| 2561 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2562 | // | ordered | target enter | * | |
| 2563 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2564 | // | ordered | target exit | * | |
| 2565 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2566 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2567 | // | ordered | cancellation | | |
| 2568 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2569 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2570 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2571 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2572 | // | ordered | distribute | + | |
| 2573 | // | ordered | distribute | + | |
| 2574 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2575 | // | ordered | distribute | + | |
| 2576 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2577 | // | ordered | distribute simd | + | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2578 | // +------------------+-----------------+------------------------------------+ |
| 2579 | // | atomic | parallel | | |
| 2580 | // | atomic | for | | |
| 2581 | // | atomic | for simd | | |
| 2582 | // | atomic | master | | |
| 2583 | // | atomic | critical | | |
| 2584 | // | atomic | simd | | |
| 2585 | // | atomic | sections | | |
| 2586 | // | atomic | section | | |
| 2587 | // | atomic | single | | |
| 2588 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2589 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2590 | // | atomic |parallel sections| | |
| 2591 | // | atomic | task | | |
| 2592 | // | atomic | taskyield | | |
| 2593 | // | atomic | barrier | | |
| 2594 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2595 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2596 | // | atomic | flush | | |
| 2597 | // | atomic | ordered | | |
| 2598 | // | atomic | atomic | | |
| 2599 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2600 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2601 | // | atomic | target parallel | | |
| 2602 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2603 | // | atomic | target enter | | |
| 2604 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2605 | // | atomic | target exit | | |
| 2606 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2607 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2608 | // | atomic | cancellation | | |
| 2609 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2610 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2611 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2612 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2613 | // | atomic | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2614 | // | atomic | distribute | | |
| 2615 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2616 | // | atomic | distribute | | |
| 2617 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2618 | // | atomic | distribute simd | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2619 | // +------------------+-----------------+------------------------------------+ |
| 2620 | // | target | parallel | * | |
| 2621 | // | target | for | * | |
| 2622 | // | target | for simd | * | |
| 2623 | // | target | master | * | |
| 2624 | // | target | critical | * | |
| 2625 | // | target | simd | * | |
| 2626 | // | target | sections | * | |
| 2627 | // | target | section | * | |
| 2628 | // | target | single | * | |
| 2629 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2630 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2631 | // | target |parallel sections| * | |
| 2632 | // | target | task | * | |
| 2633 | // | target | taskyield | * | |
| 2634 | // | target | barrier | * | |
| 2635 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2636 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2637 | // | target | flush | * | |
| 2638 | // | target | ordered | * | |
| 2639 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2640 | // | target | target | | |
| 2641 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2642 | // | target | target parallel | | |
| 2643 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2644 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2645 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2646 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2647 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2648 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2649 | // | target | cancellation | | |
| 2650 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2651 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2652 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2653 | // | target | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2654 | // | target | distribute | + | |
| 2655 | // | target | distribute | + | |
| 2656 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2657 | // | target | distribute | + | |
| 2658 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2659 | // | target | distribute simd | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2660 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2661 | // | target parallel | parallel | * | |
| 2662 | // | target parallel | for | * | |
| 2663 | // | target parallel | for simd | * | |
| 2664 | // | target parallel | master | * | |
| 2665 | // | target parallel | critical | * | |
| 2666 | // | target parallel | simd | * | |
| 2667 | // | target parallel | sections | * | |
| 2668 | // | target parallel | section | * | |
| 2669 | // | target parallel | single | * | |
| 2670 | // | target parallel | parallel for | * | |
| 2671 | // | target parallel |parallel for simd| * | |
| 2672 | // | target parallel |parallel sections| * | |
| 2673 | // | target parallel | task | * | |
| 2674 | // | target parallel | taskyield | * | |
| 2675 | // | target parallel | barrier | * | |
| 2676 | // | target parallel | taskwait | * | |
| 2677 | // | target parallel | taskgroup | * | |
| 2678 | // | target parallel | flush | * | |
| 2679 | // | target parallel | ordered | * | |
| 2680 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2681 | // | target parallel | target | | |
| 2682 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2683 | // | target parallel | target parallel | | |
| 2684 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2685 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2686 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2687 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2688 | // | | data | | |
| 2689 | // | target parallel | teams | | |
| 2690 | // | target parallel | cancellation | | |
| 2691 | // | | point | ! | |
| 2692 | // | target parallel | cancel | ! | |
| 2693 | // | target parallel | taskloop | * | |
| 2694 | // | target parallel | taskloop simd | * | |
| 2695 | // | target parallel | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2696 | // | target parallel | distribute | | |
| 2697 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2698 | // | target parallel | distribute | | |
| 2699 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2700 | // | target parallel | distribute simd | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2701 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2702 | // | target parallel | parallel | * | |
| 2703 | // | for | | | |
| 2704 | // | target parallel | for | * | |
| 2705 | // | for | | | |
| 2706 | // | target parallel | for simd | * | |
| 2707 | // | for | | | |
| 2708 | // | target parallel | master | * | |
| 2709 | // | for | | | |
| 2710 | // | target parallel | critical | * | |
| 2711 | // | for | | | |
| 2712 | // | target parallel | simd | * | |
| 2713 | // | for | | | |
| 2714 | // | target parallel | sections | * | |
| 2715 | // | for | | | |
| 2716 | // | target parallel | section | * | |
| 2717 | // | for | | | |
| 2718 | // | target parallel | single | * | |
| 2719 | // | for | | | |
| 2720 | // | target parallel | parallel for | * | |
| 2721 | // | for | | | |
| 2722 | // | target parallel |parallel for simd| * | |
| 2723 | // | for | | | |
| 2724 | // | target parallel |parallel sections| * | |
| 2725 | // | for | | | |
| 2726 | // | target parallel | task | * | |
| 2727 | // | for | | | |
| 2728 | // | target parallel | taskyield | * | |
| 2729 | // | for | | | |
| 2730 | // | target parallel | barrier | * | |
| 2731 | // | for | | | |
| 2732 | // | target parallel | taskwait | * | |
| 2733 | // | for | | | |
| 2734 | // | target parallel | taskgroup | * | |
| 2735 | // | for | | | |
| 2736 | // | target parallel | flush | * | |
| 2737 | // | for | | | |
| 2738 | // | target parallel | ordered | * | |
| 2739 | // | for | | | |
| 2740 | // | target parallel | atomic | * | |
| 2741 | // | for | | | |
| 2742 | // | target parallel | target | | |
| 2743 | // | for | | | |
| 2744 | // | target parallel | target parallel | | |
| 2745 | // | for | | | |
| 2746 | // | target parallel | target parallel | | |
| 2747 | // | for | for | | |
| 2748 | // | target parallel | target enter | | |
| 2749 | // | for | data | | |
| 2750 | // | target parallel | target exit | | |
| 2751 | // | for | data | | |
| 2752 | // | target parallel | teams | | |
| 2753 | // | for | | | |
| 2754 | // | target parallel | cancellation | | |
| 2755 | // | for | point | ! | |
| 2756 | // | target parallel | cancel | ! | |
| 2757 | // | for | | | |
| 2758 | // | target parallel | taskloop | * | |
| 2759 | // | for | | | |
| 2760 | // | target parallel | taskloop simd | * | |
| 2761 | // | for | | | |
| 2762 | // | target parallel | distribute | | |
| 2763 | // | for | | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2764 | // | target parallel | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2765 | // | for | parallel for | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2766 | // | target parallel | distribute | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2767 | // | for |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2768 | // | target parallel | distribute simd | | |
| 2769 | // | for | | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2770 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2771 | // | teams | parallel | * | |
| 2772 | // | teams | for | + | |
| 2773 | // | teams | for simd | + | |
| 2774 | // | teams | master | + | |
| 2775 | // | teams | critical | + | |
| 2776 | // | teams | simd | + | |
| 2777 | // | teams | sections | + | |
| 2778 | // | teams | section | + | |
| 2779 | // | teams | single | + | |
| 2780 | // | teams | parallel for | * | |
| 2781 | // | teams |parallel for simd| * | |
| 2782 | // | teams |parallel sections| * | |
| 2783 | // | teams | task | + | |
| 2784 | // | teams | taskyield | + | |
| 2785 | // | teams | barrier | + | |
| 2786 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2787 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2788 | // | teams | flush | + | |
| 2789 | // | teams | ordered | + | |
| 2790 | // | teams | atomic | + | |
| 2791 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2792 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2793 | // | teams | target parallel | + | |
| 2794 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2795 | // | teams | target enter | + | |
| 2796 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2797 | // | teams | target exit | + | |
| 2798 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2799 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2800 | // | teams | cancellation | | |
| 2801 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2802 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2803 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2804 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2805 | // | teams | distribute | ! | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2806 | // | teams | distribute | ! | |
| 2807 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2808 | // | teams | distribute | ! | |
| 2809 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2810 | // | teams | distribute simd | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2811 | // +------------------+-----------------+------------------------------------+ |
| 2812 | // | taskloop | parallel | * | |
| 2813 | // | taskloop | for | + | |
| 2814 | // | taskloop | for simd | + | |
| 2815 | // | taskloop | master | + | |
| 2816 | // | taskloop | critical | * | |
| 2817 | // | taskloop | simd | * | |
| 2818 | // | taskloop | sections | + | |
| 2819 | // | taskloop | section | + | |
| 2820 | // | taskloop | single | + | |
| 2821 | // | taskloop | parallel for | * | |
| 2822 | // | taskloop |parallel for simd| * | |
| 2823 | // | taskloop |parallel sections| * | |
| 2824 | // | taskloop | task | * | |
| 2825 | // | taskloop | taskyield | * | |
| 2826 | // | taskloop | barrier | + | |
| 2827 | // | taskloop | taskwait | * | |
| 2828 | // | taskloop | taskgroup | * | |
| 2829 | // | taskloop | flush | * | |
| 2830 | // | taskloop | ordered | + | |
| 2831 | // | taskloop | atomic | * | |
| 2832 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2833 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2834 | // | taskloop | target parallel | * | |
| 2835 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2836 | // | taskloop | target enter | * | |
| 2837 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2838 | // | taskloop | target exit | * | |
| 2839 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2840 | // | taskloop | teams | + | |
| 2841 | // | taskloop | cancellation | | |
| 2842 | // | | point | | |
| 2843 | // | taskloop | cancel | | |
| 2844 | // | taskloop | taskloop | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2845 | // | taskloop | distribute | + | |
| 2846 | // | taskloop | distribute | + | |
| 2847 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2848 | // | taskloop | distribute | + | |
| 2849 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2850 | // | taskloop | distribute simd | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2851 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2852 | // | taskloop simd | parallel | | |
| 2853 | // | taskloop simd | for | | |
| 2854 | // | taskloop simd | for simd | | |
| 2855 | // | taskloop simd | master | | |
| 2856 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2857 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2858 | // | taskloop simd | sections | | |
| 2859 | // | taskloop simd | section | | |
| 2860 | // | taskloop simd | single | | |
| 2861 | // | taskloop simd | parallel for | | |
| 2862 | // | taskloop simd |parallel for simd| | |
| 2863 | // | taskloop simd |parallel sections| | |
| 2864 | // | taskloop simd | task | | |
| 2865 | // | taskloop simd | taskyield | | |
| 2866 | // | taskloop simd | barrier | | |
| 2867 | // | taskloop simd | taskwait | | |
| 2868 | // | taskloop simd | taskgroup | | |
| 2869 | // | taskloop simd | flush | | |
| 2870 | // | taskloop simd | ordered | + (with simd clause) | |
| 2871 | // | taskloop simd | atomic | | |
| 2872 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2873 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2874 | // | taskloop simd | target parallel | | |
| 2875 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2876 | // | taskloop simd | target enter | | |
| 2877 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2878 | // | taskloop simd | target exit | | |
| 2879 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2880 | // | taskloop simd | teams | | |
| 2881 | // | taskloop simd | cancellation | | |
| 2882 | // | | point | | |
| 2883 | // | taskloop simd | cancel | | |
| 2884 | // | taskloop simd | taskloop | | |
| 2885 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2886 | // | taskloop simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2887 | // | taskloop simd | distribute | | |
| 2888 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2889 | // | taskloop simd | distribute | | |
| 2890 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2891 | // | taskloop simd | distribute simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2892 | // +------------------+-----------------+------------------------------------+ |
| 2893 | // | distribute | parallel | * | |
| 2894 | // | distribute | for | * | |
| 2895 | // | distribute | for simd | * | |
| 2896 | // | distribute | master | * | |
| 2897 | // | distribute | critical | * | |
| 2898 | // | distribute | simd | * | |
| 2899 | // | distribute | sections | * | |
| 2900 | // | distribute | section | * | |
| 2901 | // | distribute | single | * | |
| 2902 | // | distribute | parallel for | * | |
| 2903 | // | distribute |parallel for simd| * | |
| 2904 | // | distribute |parallel sections| * | |
| 2905 | // | distribute | task | * | |
| 2906 | // | distribute | taskyield | * | |
| 2907 | // | distribute | barrier | * | |
| 2908 | // | distribute | taskwait | * | |
| 2909 | // | distribute | taskgroup | * | |
| 2910 | // | distribute | flush | * | |
| 2911 | // | distribute | ordered | + | |
| 2912 | // | distribute | atomic | * | |
| 2913 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2914 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2915 | // | distribute | target parallel | | |
| 2916 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2917 | // | distribute | target enter | | |
| 2918 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2919 | // | distribute | target exit | | |
| 2920 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2921 | // | distribute | teams | | |
| 2922 | // | distribute | cancellation | + | |
| 2923 | // | | point | | |
| 2924 | // | distribute | cancel | + | |
| 2925 | // | distribute | taskloop | * | |
| 2926 | // | distribute | taskloop simd | * | |
| 2927 | // | distribute | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2928 | // | distribute | distribute | | |
| 2929 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2930 | // | distribute | distribute | | |
| 2931 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 2932 | // | distribute | distribute simd | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2933 | // +------------------+-----------------+------------------------------------+ |
| 2934 | // | distribute | parallel | * | |
| 2935 | // | parallel for | | | |
| 2936 | // | distribute | for | * | |
| 2937 | // | parallel for | | | |
| 2938 | // | distribute | for simd | * | |
| 2939 | // | parallel for | | | |
| 2940 | // | distribute | master | * | |
| 2941 | // | parallel for | | | |
| 2942 | // | distribute | critical | * | |
| 2943 | // | parallel for | | | |
| 2944 | // | distribute | simd | * | |
| 2945 | // | parallel for | | | |
| 2946 | // | distribute | sections | * | |
| 2947 | // | parallel for | | | |
| 2948 | // | distribute | section | * | |
| 2949 | // | parallel for | | | |
| 2950 | // | distribute | single | * | |
| 2951 | // | parallel for | | | |
| 2952 | // | distribute | parallel for | * | |
| 2953 | // | parallel for | | | |
| 2954 | // | distribute |parallel for simd| * | |
| 2955 | // | parallel for | | | |
| 2956 | // | distribute |parallel sections| * | |
| 2957 | // | parallel for | | | |
| 2958 | // | distribute | task | * | |
| 2959 | // | parallel for | | | |
| 2960 | // | parallel for | | | |
| 2961 | // | distribute | taskyield | * | |
| 2962 | // | parallel for | | | |
| 2963 | // | distribute | barrier | * | |
| 2964 | // | parallel for | | | |
| 2965 | // | distribute | taskwait | * | |
| 2966 | // | parallel for | | | |
| 2967 | // | distribute | taskgroup | * | |
| 2968 | // | parallel for | | | |
| 2969 | // | distribute | flush | * | |
| 2970 | // | parallel for | | | |
| 2971 | // | distribute | ordered | + | |
| 2972 | // | parallel for | | | |
| 2973 | // | distribute | atomic | * | |
| 2974 | // | parallel for | | | |
| 2975 | // | distribute | target | | |
| 2976 | // | parallel for | | | |
| 2977 | // | distribute | target parallel | | |
| 2978 | // | parallel for | | | |
| 2979 | // | distribute | target parallel | | |
| 2980 | // | parallel for | for | | |
| 2981 | // | distribute | target enter | | |
| 2982 | // | parallel for | data | | |
| 2983 | // | distribute | target exit | | |
| 2984 | // | parallel for | data | | |
| 2985 | // | distribute | teams | | |
| 2986 | // | parallel for | | | |
| 2987 | // | distribute | cancellation | + | |
| 2988 | // | parallel for | point | | |
| 2989 | // | distribute | cancel | + | |
| 2990 | // | parallel for | | | |
| 2991 | // | distribute | taskloop | * | |
| 2992 | // | parallel for | | | |
| 2993 | // | distribute | taskloop simd | * | |
| 2994 | // | parallel for | | | |
| 2995 | // | distribute | distribute | | |
| 2996 | // | parallel for | | | |
| 2997 | // | distribute | distribute | | |
| 2998 | // | parallel for | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2999 | // | distribute | distribute | | |
| 3000 | // | parallel for |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 3001 | // | distribute | distribute simd | | |
| 3002 | // | parallel for | | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3003 | // +------------------+-----------------+------------------------------------+ |
| 3004 | // | distribute | parallel | * | |
| 3005 | // | parallel for simd| | | |
| 3006 | // | distribute | for | * | |
| 3007 | // | parallel for simd| | | |
| 3008 | // | distribute | for simd | * | |
| 3009 | // | parallel for simd| | | |
| 3010 | // | distribute | master | * | |
| 3011 | // | parallel for simd| | | |
| 3012 | // | distribute | critical | * | |
| 3013 | // | parallel for simd| | | |
| 3014 | // | distribute | simd | * | |
| 3015 | // | parallel for simd| | | |
| 3016 | // | distribute | sections | * | |
| 3017 | // | parallel for simd| | | |
| 3018 | // | distribute | section | * | |
| 3019 | // | parallel for simd| | | |
| 3020 | // | distribute | single | * | |
| 3021 | // | parallel for simd| | | |
| 3022 | // | distribute | parallel for | * | |
| 3023 | // | parallel for simd| | | |
| 3024 | // | distribute |parallel for simd| * | |
| 3025 | // | parallel for simd| | | |
| 3026 | // | distribute |parallel sections| * | |
| 3027 | // | parallel for simd| | | |
| 3028 | // | distribute | task | * | |
| 3029 | // | parallel for simd| | | |
| 3030 | // | distribute | taskyield | * | |
| 3031 | // | parallel for simd| | | |
| 3032 | // | distribute | barrier | * | |
| 3033 | // | parallel for simd| | | |
| 3034 | // | distribute | taskwait | * | |
| 3035 | // | parallel for simd| | | |
| 3036 | // | distribute | taskgroup | * | |
| 3037 | // | parallel for simd| | | |
| 3038 | // | distribute | flush | * | |
| 3039 | // | parallel for simd| | | |
| 3040 | // | distribute | ordered | + | |
| 3041 | // | parallel for simd| | | |
| 3042 | // | distribute | atomic | * | |
| 3043 | // | parallel for simd| | | |
| 3044 | // | distribute | target | | |
| 3045 | // | parallel for simd| | | |
| 3046 | // | distribute | target parallel | | |
| 3047 | // | parallel for simd| | | |
| 3048 | // | distribute | target parallel | | |
| 3049 | // | parallel for simd| for | | |
| 3050 | // | distribute | target enter | | |
| 3051 | // | parallel for simd| data | | |
| 3052 | // | distribute | target exit | | |
| 3053 | // | parallel for simd| data | | |
| 3054 | // | distribute | teams | | |
| 3055 | // | parallel for simd| | | |
| 3056 | // | distribute | cancellation | + | |
| 3057 | // | parallel for simd| point | | |
| 3058 | // | distribute | cancel | + | |
| 3059 | // | parallel for simd| | | |
| 3060 | // | distribute | taskloop | * | |
| 3061 | // | parallel for simd| | | |
| 3062 | // | distribute | taskloop simd | * | |
| 3063 | // | parallel for simd| | | |
| 3064 | // | distribute | distribute | | |
| 3065 | // | parallel for simd| | | |
| 3066 | // | distribute | distribute | * | |
| 3067 | // | parallel for simd| parallel for | | |
| 3068 | // | distribute | distribute | * | |
| 3069 | // | parallel for simd|parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 3070 | // | distribute | distribute simd | * | |
| 3071 | // | parallel for simd| | | |
| 3072 | // +------------------+-----------------+------------------------------------+ |
| 3073 | // | distribute simd | parallel | * | |
| 3074 | // | distribute simd | for | * | |
| 3075 | // | distribute simd | for simd | * | |
| 3076 | // | distribute simd | master | * | |
| 3077 | // | distribute simd | critical | * | |
| 3078 | // | distribute simd | simd | * | |
| 3079 | // | distribute simd | sections | * | |
| 3080 | // | distribute simd | section | * | |
| 3081 | // | distribute simd | single | * | |
| 3082 | // | distribute simd | parallel for | * | |
| 3083 | // | distribute simd |parallel for simd| * | |
| 3084 | // | distribute simd |parallel sections| * | |
| 3085 | // | distribute simd | task | * | |
| 3086 | // | distribute simd | taskyield | * | |
| 3087 | // | distribute simd | barrier | * | |
| 3088 | // | distribute simd | taskwait | * | |
| 3089 | // | distribute simd | taskgroup | * | |
| 3090 | // | distribute simd | flush | * | |
| 3091 | // | distribute simd | ordered | + | |
| 3092 | // | distribute simd | atomic | * | |
| 3093 | // | distribute simd | target | * | |
| 3094 | // | distribute simd | target parallel | * | |
| 3095 | // | distribute simd | target parallel | * | |
| 3096 | // | | for | | |
| 3097 | // | distribute simd | target enter | * | |
| 3098 | // | | data | | |
| 3099 | // | distribute simd | target exit | * | |
| 3100 | // | | data | | |
| 3101 | // | distribute simd | teams | * | |
| 3102 | // | distribute simd | cancellation | + | |
| 3103 | // | | point | | |
| 3104 | // | distribute simd | cancel | + | |
| 3105 | // | distribute simd | taskloop | * | |
| 3106 | // | distribute simd | taskloop simd | * | |
| 3107 | // | distribute simd | distribute | | |
| 3108 | // | distribute simd | distribute | * | |
| 3109 | // | | parallel for | | |
| 3110 | // | distribute simd | distribute | * | |
| 3111 | // | |parallel for simd| | |
| 3112 | // | distribute simd | distribute simd | * | |
| 3113 | // | | | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3114 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3115 | if (Stack->getCurScope()) { |
| 3116 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3117 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3118 | bool NestingProhibited = false; |
| 3119 | bool CloseNesting = true; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3120 | enum { |
| 3121 | NoRecommend, |
| 3122 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3123 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3124 | ShouldBeInTargetRegion, |
| 3125 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3126 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3127 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3128 | // OpenMP [2.16, Nesting of Regions] |
| 3129 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3130 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3131 | // An ordered construct with the simd clause is the only OpenMP |
| 3132 | // construct that can appear in the simd region. |
| 3133 | // Allowing a SIMD consruct nested in another SIMD construct is an |
| 3134 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 3135 | // message. |
| 3136 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 3137 | ? diag::err_omp_prohibited_region_simd |
| 3138 | : diag::warn_omp_nesting_simd); |
| 3139 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3140 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3141 | if (ParentRegion == OMPD_atomic) { |
| 3142 | // OpenMP [2.16, Nesting of Regions] |
| 3143 | // OpenMP constructs may not be nested inside an atomic region. |
| 3144 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 3145 | return true; |
| 3146 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3147 | if (CurrentRegion == OMPD_section) { |
| 3148 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 3149 | // Orphaned section directives are prohibited. That is, the section |
| 3150 | // directives must appear within the sections construct and must not be |
| 3151 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3152 | if (ParentRegion != OMPD_sections && |
| 3153 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3154 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 3155 | << (ParentRegion != OMPD_unknown) |
| 3156 | << getOpenMPDirectiveName(ParentRegion); |
| 3157 | return true; |
| 3158 | } |
| 3159 | return false; |
| 3160 | } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3161 | // Allow some constructs to be orphaned (they could be used in functions, |
| 3162 | // called from OpenMP regions with the required preconditions). |
| 3163 | if (ParentRegion == OMPD_unknown) |
| 3164 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3165 | if (CurrentRegion == OMPD_cancellation_point || |
| 3166 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3167 | // OpenMP [2.16, Nesting of Regions] |
| 3168 | // A cancellation point construct for which construct-type-clause is |
| 3169 | // taskgroup must be nested inside a task construct. A cancellation |
| 3170 | // point construct for which construct-type-clause is not taskgroup must |
| 3171 | // be closely nested inside an OpenMP construct that matches the type |
| 3172 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3173 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 3174 | // nested inside a task construct. A cancel construct for which |
| 3175 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 3176 | // OpenMP construct that matches the type specified in |
| 3177 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3178 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3179 | !((CancelRegion == OMPD_parallel && |
| 3180 | (ParentRegion == OMPD_parallel || |
| 3181 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3182 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3183 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 3184 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3185 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 3186 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3187 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 3188 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3189 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3190 | // OpenMP [2.16, Nesting of Regions] |
| 3191 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3192 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3193 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3194 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3195 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 3196 | // OpenMP [2.16, Nesting of Regions] |
| 3197 | // A critical region may not be nested (closely or otherwise) inside a |
| 3198 | // critical region with the same name. Note that this restriction is not |
| 3199 | // sufficient to prevent deadlock. |
| 3200 | SourceLocation PreviousCriticalLoc; |
| 3201 | bool DeadLock = |
| 3202 | Stack->hasDirective([CurrentName, &PreviousCriticalLoc]( |
| 3203 | OpenMPDirectiveKind K, |
| 3204 | const DeclarationNameInfo &DNI, |
| 3205 | SourceLocation Loc) |
| 3206 | ->bool { |
| 3207 | if (K == OMPD_critical && |
| 3208 | DNI.getName() == CurrentName.getName()) { |
| 3209 | PreviousCriticalLoc = Loc; |
| 3210 | return true; |
| 3211 | } else |
| 3212 | return false; |
| 3213 | }, |
| 3214 | false /* skip top directive */); |
| 3215 | if (DeadLock) { |
| 3216 | SemaRef.Diag(StartLoc, |
| 3217 | diag::err_omp_prohibited_region_critical_same_name) |
| 3218 | << CurrentName.getName(); |
| 3219 | if (PreviousCriticalLoc.isValid()) |
| 3220 | SemaRef.Diag(PreviousCriticalLoc, |
| 3221 | diag::note_omp_previous_critical_region); |
| 3222 | return true; |
| 3223 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3224 | } else if (CurrentRegion == OMPD_barrier) { |
| 3225 | // OpenMP [2.16, Nesting of Regions] |
| 3226 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3227 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3228 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3229 | isOpenMPTaskingDirective(ParentRegion) || |
| 3230 | ParentRegion == OMPD_master || |
| 3231 | ParentRegion == OMPD_critical || |
| 3232 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3233 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3234 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3235 | // OpenMP [2.16, Nesting of Regions] |
| 3236 | // A worksharing region may not be closely nested inside a worksharing, |
| 3237 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3238 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3239 | isOpenMPTaskingDirective(ParentRegion) || |
| 3240 | ParentRegion == OMPD_master || |
| 3241 | ParentRegion == OMPD_critical || |
| 3242 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3243 | Recommend = ShouldBeInParallelRegion; |
| 3244 | } else if (CurrentRegion == OMPD_ordered) { |
| 3245 | // OpenMP [2.16, Nesting of Regions] |
| 3246 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3247 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3248 | // An ordered region must be closely nested inside a loop region (or |
| 3249 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3250 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 3251 | // An ordered construct with the simd clause is the only OpenMP construct |
| 3252 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3253 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3254 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3255 | !(isOpenMPSimdDirective(ParentRegion) || |
| 3256 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3257 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3258 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 3259 | // OpenMP [2.16, Nesting of Regions] |
| 3260 | // If specified, a teams construct must be contained within a target |
| 3261 | // construct. |
| 3262 | NestingProhibited = ParentRegion != OMPD_target; |
| 3263 | Recommend = ShouldBeInTargetRegion; |
| 3264 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 3265 | } |
| 3266 | if (!NestingProhibited && isOpenMPTeamsDirective(ParentRegion)) { |
| 3267 | // OpenMP [2.16, Nesting of Regions] |
| 3268 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 3269 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 3270 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3271 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 3272 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3273 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3274 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3275 | if (!NestingProhibited && isOpenMPDistributeDirective(CurrentRegion)) { |
| 3276 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3277 | // The region associated with the distribute construct must be strictly |
| 3278 | // nested inside a teams region |
| 3279 | NestingProhibited = !isOpenMPTeamsDirective(ParentRegion); |
| 3280 | Recommend = ShouldBeInTeamsRegion; |
| 3281 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3282 | if (!NestingProhibited && |
| 3283 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 3284 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 3285 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3286 | // If a target, target update, target data, target enter data, or |
| 3287 | // target exit data construct is encountered during execution of a |
| 3288 | // target region, the behavior is unspecified. |
| 3289 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3290 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 3291 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3292 | if (isOpenMPTargetExecutionDirective(K)) { |
| 3293 | OffendingRegion = K; |
| 3294 | return true; |
| 3295 | } else |
| 3296 | return false; |
| 3297 | }, |
| 3298 | false /* don't skip top directive */); |
| 3299 | CloseNesting = false; |
| 3300 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3301 | if (NestingProhibited) { |
| 3302 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3303 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 3304 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3305 | return true; |
| 3306 | } |
| 3307 | } |
| 3308 | return false; |
| 3309 | } |
| 3310 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3311 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 3312 | ArrayRef<OMPClause *> Clauses, |
| 3313 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 3314 | bool ErrorFound = false; |
| 3315 | unsigned NamedModifiersNumber = 0; |
| 3316 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 3317 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3318 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3319 | for (const auto *C : Clauses) { |
| 3320 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 3321 | // At most one if clause without a directive-name-modifier can appear on |
| 3322 | // the directive. |
| 3323 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 3324 | if (FoundNameModifiers[CurNM]) { |
| 3325 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 3326 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 3327 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 3328 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3329 | } else if (CurNM != OMPD_unknown) { |
| 3330 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3331 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3332 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3333 | FoundNameModifiers[CurNM] = IC; |
| 3334 | if (CurNM == OMPD_unknown) |
| 3335 | continue; |
| 3336 | // Check if the specified name modifier is allowed for the current |
| 3337 | // directive. |
| 3338 | // At most one if clause with the particular directive-name-modifier can |
| 3339 | // appear on the directive. |
| 3340 | bool MatchFound = false; |
| 3341 | for (auto NM : AllowedNameModifiers) { |
| 3342 | if (CurNM == NM) { |
| 3343 | MatchFound = true; |
| 3344 | break; |
| 3345 | } |
| 3346 | } |
| 3347 | if (!MatchFound) { |
| 3348 | S.Diag(IC->getNameModifierLoc(), |
| 3349 | diag::err_omp_wrong_if_directive_name_modifier) |
| 3350 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 3351 | ErrorFound = true; |
| 3352 | } |
| 3353 | } |
| 3354 | } |
| 3355 | // If any if clause on the directive includes a directive-name-modifier then |
| 3356 | // all if clauses on the directive must include a directive-name-modifier. |
| 3357 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 3358 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 3359 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 3360 | diag::err_omp_no_more_if_clause); |
| 3361 | } else { |
| 3362 | std::string Values; |
| 3363 | std::string Sep(", "); |
| 3364 | unsigned AllowedCnt = 0; |
| 3365 | unsigned TotalAllowedNum = |
| 3366 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 3367 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 3368 | ++Cnt) { |
| 3369 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 3370 | if (!FoundNameModifiers[NM]) { |
| 3371 | Values += "'"; |
| 3372 | Values += getOpenMPDirectiveName(NM); |
| 3373 | Values += "'"; |
| 3374 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 3375 | Values += " or "; |
| 3376 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 3377 | Values += Sep; |
| 3378 | ++AllowedCnt; |
| 3379 | } |
| 3380 | } |
| 3381 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 3382 | diag::err_omp_unnamed_if_clause) |
| 3383 | << (TotalAllowedNum > 1) << Values; |
| 3384 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3385 | for (auto Loc : NameModifierLoc) { |
| 3386 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 3387 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3388 | ErrorFound = true; |
| 3389 | } |
| 3390 | return ErrorFound; |
| 3391 | } |
| 3392 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3393 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 3394 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 3395 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 3396 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3397 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3398 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 3399 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3400 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3401 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3402 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3403 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3404 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3405 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3406 | if (AStmt) { |
| 3407 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3408 | |
| 3409 | // Check default data sharing attributes for referenced variables. |
| 3410 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 3411 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 3412 | if (DSAChecker.isErrorFound()) |
| 3413 | return StmtError(); |
| 3414 | // Generate list of implicitly defined firstprivate variables. |
| 3415 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3416 | |
| 3417 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 3418 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 3419 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 3420 | SourceLocation(), SourceLocation())) { |
| 3421 | ClausesWithImplicit.push_back(Implicit); |
| 3422 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 3423 | DSAChecker.getImplicitFirstprivate().size(); |
| 3424 | } else |
| 3425 | ErrorFound = true; |
| 3426 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3427 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3428 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3429 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3430 | switch (Kind) { |
| 3431 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3432 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3433 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3434 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3435 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3436 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3437 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3438 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3439 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3440 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3441 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3442 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3443 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3444 | case OMPD_for_simd: |
| 3445 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3446 | EndLoc, VarsWithInheritedDSA); |
| 3447 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3448 | case OMPD_sections: |
| 3449 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3450 | EndLoc); |
| 3451 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3452 | case OMPD_section: |
| 3453 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3454 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3455 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3456 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3457 | case OMPD_single: |
| 3458 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3459 | EndLoc); |
| 3460 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3461 | case OMPD_master: |
| 3462 | assert(ClausesWithImplicit.empty() && |
| 3463 | "No clauses are allowed for 'omp master' directive"); |
| 3464 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3465 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3466 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3467 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3468 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3469 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3470 | case OMPD_parallel_for: |
| 3471 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3472 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3473 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3474 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3475 | case OMPD_parallel_for_simd: |
| 3476 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3477 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3478 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3479 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3480 | case OMPD_parallel_sections: |
| 3481 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3482 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3483 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3484 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3485 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3486 | Res = |
| 3487 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3488 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3489 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3490 | case OMPD_taskyield: |
| 3491 | assert(ClausesWithImplicit.empty() && |
| 3492 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3493 | assert(AStmt == nullptr && |
| 3494 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3495 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3496 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3497 | case OMPD_barrier: |
| 3498 | assert(ClausesWithImplicit.empty() && |
| 3499 | "No clauses are allowed for 'omp barrier' directive"); |
| 3500 | assert(AStmt == nullptr && |
| 3501 | "No associated statement allowed for 'omp barrier' directive"); |
| 3502 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3503 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3504 | case OMPD_taskwait: |
| 3505 | assert(ClausesWithImplicit.empty() && |
| 3506 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3507 | assert(AStmt == nullptr && |
| 3508 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3509 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3510 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3511 | case OMPD_taskgroup: |
| 3512 | assert(ClausesWithImplicit.empty() && |
| 3513 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3514 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3515 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3516 | case OMPD_flush: |
| 3517 | assert(AStmt == nullptr && |
| 3518 | "No associated statement allowed for 'omp flush' directive"); |
| 3519 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3520 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3521 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3522 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3523 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3524 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3525 | case OMPD_atomic: |
| 3526 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3527 | EndLoc); |
| 3528 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3529 | case OMPD_teams: |
| 3530 | Res = |
| 3531 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3532 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3533 | case OMPD_target: |
| 3534 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3535 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3536 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3537 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3538 | case OMPD_target_parallel: |
| 3539 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3540 | StartLoc, EndLoc); |
| 3541 | AllowedNameModifiers.push_back(OMPD_target); |
| 3542 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3543 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3544 | case OMPD_target_parallel_for: |
| 3545 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3546 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3547 | AllowedNameModifiers.push_back(OMPD_target); |
| 3548 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3549 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3550 | case OMPD_cancellation_point: |
| 3551 | assert(ClausesWithImplicit.empty() && |
| 3552 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3553 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3554 | "cancellation point' directive"); |
| 3555 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3556 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3557 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3558 | assert(AStmt == nullptr && |
| 3559 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3560 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3561 | CancelRegion); |
| 3562 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3563 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3564 | case OMPD_target_data: |
| 3565 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3566 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3567 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3568 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3569 | case OMPD_target_enter_data: |
| 3570 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3571 | EndLoc); |
| 3572 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3573 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3574 | case OMPD_target_exit_data: |
| 3575 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3576 | EndLoc); |
| 3577 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3578 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3579 | case OMPD_taskloop: |
| 3580 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3581 | EndLoc, VarsWithInheritedDSA); |
| 3582 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3583 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3584 | case OMPD_taskloop_simd: |
| 3585 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3586 | EndLoc, VarsWithInheritedDSA); |
| 3587 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3588 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3589 | case OMPD_distribute: |
| 3590 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3591 | EndLoc, VarsWithInheritedDSA); |
| 3592 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3593 | case OMPD_target_update: |
| 3594 | assert(!AStmt && "Statement is not allowed for target update"); |
| 3595 | Res = |
| 3596 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3597 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 3598 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3599 | case OMPD_distribute_parallel_for: |
| 3600 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 3601 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3602 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3603 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3604 | case OMPD_distribute_parallel_for_simd: |
| 3605 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 3606 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3607 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3608 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 3609 | case OMPD_distribute_simd: |
| 3610 | Res = ActOnOpenMPDistributeSimdDirective( |
| 3611 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3612 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3613 | case OMPD_declare_target: |
| 3614 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3615 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3616 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3617 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3618 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3619 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3620 | llvm_unreachable("Unknown OpenMP directive"); |
| 3621 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3622 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3623 | for (auto P : VarsWithInheritedDSA) { |
| 3624 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3625 | << P.first << P.second->getSourceRange(); |
| 3626 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3627 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3628 | |
| 3629 | if (!AllowedNameModifiers.empty()) |
| 3630 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3631 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3632 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3633 | if (ErrorFound) |
| 3634 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3635 | return Res; |
| 3636 | } |
| 3637 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3638 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 3639 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3640 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3641 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 3642 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3643 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3644 | assert(Linears.size() == LinModifiers.size()); |
| 3645 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3646 | if (!DG || DG.get().isNull()) |
| 3647 | return DeclGroupPtrTy(); |
| 3648 | |
| 3649 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 3650 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3651 | return DG; |
| 3652 | } |
| 3653 | auto *ADecl = DG.get().getSingleDecl(); |
| 3654 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3655 | ADecl = FTD->getTemplatedDecl(); |
| 3656 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3657 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 3658 | if (!FD) { |
| 3659 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3660 | return DeclGroupPtrTy(); |
| 3661 | } |
| 3662 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3663 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3664 | // The parameter of the simdlen clause must be a constant positive integer |
| 3665 | // expression. |
| 3666 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3667 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3668 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3669 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3670 | // The special this pointer can be used as if was one of the arguments to the |
| 3671 | // function in any of the linear, aligned, or uniform clauses. |
| 3672 | // The uniform clause declares one or more arguments to have an invariant |
| 3673 | // value for all concurrent invocations of the function in the execution of a |
| 3674 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3675 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 3676 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3677 | for (auto *E : Uniforms) { |
| 3678 | E = E->IgnoreParenImpCasts(); |
| 3679 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3680 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 3681 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3682 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3683 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 3684 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3685 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3686 | } |
| 3687 | if (isa<CXXThisExpr>(E)) { |
| 3688 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3689 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3690 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3691 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3692 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3693 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3694 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3695 | // The aligned clause declares that the object to which each list item points |
| 3696 | // is aligned to the number of bytes expressed in the optional parameter of |
| 3697 | // the aligned clause. |
| 3698 | // The special this pointer can be used as if was one of the arguments to the |
| 3699 | // function in any of the linear, aligned, or uniform clauses. |
| 3700 | // The type of list items appearing in the aligned clause must be array, |
| 3701 | // pointer, reference to array, or reference to pointer. |
| 3702 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 3703 | Expr *AlignedThis = nullptr; |
| 3704 | for (auto *E : Aligneds) { |
| 3705 | E = E->IgnoreParenImpCasts(); |
| 3706 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3707 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3708 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3709 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3710 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3711 | ->getCanonicalDecl() == CanonPVD) { |
| 3712 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3713 | // A list-item cannot appear in more than one aligned clause. |
| 3714 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 3715 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3716 | << 1 << E->getSourceRange(); |
| 3717 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 3718 | diag::note_omp_explicit_dsa) |
| 3719 | << getOpenMPClauseName(OMPC_aligned); |
| 3720 | continue; |
| 3721 | } |
| 3722 | AlignedArgs[CanonPVD] = E; |
| 3723 | QualType QTy = PVD->getType() |
| 3724 | .getNonReferenceType() |
| 3725 | .getUnqualifiedType() |
| 3726 | .getCanonicalType(); |
| 3727 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 3728 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 3729 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 3730 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 3731 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 3732 | } |
| 3733 | continue; |
| 3734 | } |
| 3735 | } |
| 3736 | if (isa<CXXThisExpr>(E)) { |
| 3737 | if (AlignedThis) { |
| 3738 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3739 | << 2 << E->getSourceRange(); |
| 3740 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3741 | << getOpenMPClauseName(OMPC_aligned); |
| 3742 | } |
| 3743 | AlignedThis = E; |
| 3744 | continue; |
| 3745 | } |
| 3746 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3747 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3748 | } |
| 3749 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 3750 | // positive integer expression. If no optional parameter is specified, |
| 3751 | // implementation-defined default alignments for SIMD instructions on the |
| 3752 | // target platforms are assumed. |
| 3753 | SmallVector<Expr *, 4> NewAligns; |
| 3754 | for (auto *E : Alignments) { |
| 3755 | ExprResult Align; |
| 3756 | if (E) |
| 3757 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 3758 | NewAligns.push_back(Align.get()); |
| 3759 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3760 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3761 | // The linear clause declares one or more list items to be private to a SIMD |
| 3762 | // lane and to have a linear relationship with respect to the iteration space |
| 3763 | // of a loop. |
| 3764 | // The special this pointer can be used as if was one of the arguments to the |
| 3765 | // function in any of the linear, aligned, or uniform clauses. |
| 3766 | // When a linear-step expression is specified in a linear clause it must be |
| 3767 | // either a constant integer expression or an integer-typed parameter that is |
| 3768 | // specified in a uniform clause on the directive. |
| 3769 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 3770 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 3771 | auto MI = LinModifiers.begin(); |
| 3772 | for (auto *E : Linears) { |
| 3773 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 3774 | ++MI; |
| 3775 | E = E->IgnoreParenImpCasts(); |
| 3776 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3777 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3778 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3779 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3780 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3781 | ->getCanonicalDecl() == CanonPVD) { |
| 3782 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 3783 | // A list-item cannot appear in more than one linear clause. |
| 3784 | if (LinearArgs.count(CanonPVD) > 0) { |
| 3785 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3786 | << getOpenMPClauseName(OMPC_linear) |
| 3787 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 3788 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 3789 | diag::note_omp_explicit_dsa) |
| 3790 | << getOpenMPClauseName(OMPC_linear); |
| 3791 | continue; |
| 3792 | } |
| 3793 | // Each argument can appear in at most one uniform or linear clause. |
| 3794 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 3795 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3796 | << getOpenMPClauseName(OMPC_linear) |
| 3797 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 3798 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 3799 | diag::note_omp_explicit_dsa) |
| 3800 | << getOpenMPClauseName(OMPC_uniform); |
| 3801 | continue; |
| 3802 | } |
| 3803 | LinearArgs[CanonPVD] = E; |
| 3804 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3805 | E->isInstantiationDependent() || |
| 3806 | E->containsUnexpandedParameterPack()) |
| 3807 | continue; |
| 3808 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 3809 | PVD->getOriginalType()); |
| 3810 | continue; |
| 3811 | } |
| 3812 | } |
| 3813 | if (isa<CXXThisExpr>(E)) { |
| 3814 | if (UniformedLinearThis) { |
| 3815 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3816 | << getOpenMPClauseName(OMPC_linear) |
| 3817 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 3818 | << E->getSourceRange(); |
| 3819 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3820 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 3821 | : OMPC_linear); |
| 3822 | continue; |
| 3823 | } |
| 3824 | UniformedLinearThis = E; |
| 3825 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3826 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3827 | continue; |
| 3828 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3829 | E->getType()); |
| 3830 | continue; |
| 3831 | } |
| 3832 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3833 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3834 | } |
| 3835 | Expr *Step = nullptr; |
| 3836 | Expr *NewStep = nullptr; |
| 3837 | SmallVector<Expr *, 4> NewSteps; |
| 3838 | for (auto *E : Steps) { |
| 3839 | // Skip the same step expression, it was checked already. |
| 3840 | if (Step == E || !E) { |
| 3841 | NewSteps.push_back(E ? NewStep : nullptr); |
| 3842 | continue; |
| 3843 | } |
| 3844 | Step = E; |
| 3845 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 3846 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3847 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3848 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 3849 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 3850 | << Step->getSourceRange(); |
| 3851 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 3852 | E->isInstantiationDependent() || |
| 3853 | E->containsUnexpandedParameterPack() || |
| 3854 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 3855 | NewSteps.push_back(Step); |
| 3856 | else { |
| 3857 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 3858 | << Step->getSourceRange(); |
| 3859 | } |
| 3860 | continue; |
| 3861 | } |
| 3862 | NewStep = Step; |
| 3863 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 3864 | !Step->isInstantiationDependent() && |
| 3865 | !Step->containsUnexpandedParameterPack()) { |
| 3866 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 3867 | .get(); |
| 3868 | if (NewStep) |
| 3869 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 3870 | } |
| 3871 | NewSteps.push_back(NewStep); |
| 3872 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3873 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 3874 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3875 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3876 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 3877 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 3878 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 3879 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3880 | ADecl->addAttr(NewAttr); |
| 3881 | return ConvertDeclToDeclGroup(ADecl); |
| 3882 | } |
| 3883 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3884 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 3885 | Stmt *AStmt, |
| 3886 | SourceLocation StartLoc, |
| 3887 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3888 | if (!AStmt) |
| 3889 | return StmtError(); |
| 3890 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 3891 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 3892 | // 1.2.2 OpenMP Language Terminology |
| 3893 | // Structured block - An executable statement with a single entry at the |
| 3894 | // top and a single exit at the bottom. |
| 3895 | // The point of exit cannot be a branch out of the structured block. |
| 3896 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 3897 | CS->getCapturedDecl()->setNothrow(); |
| 3898 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3899 | getCurFunction()->setHasBranchProtectedScope(); |
| 3900 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3901 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 3902 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3905 | namespace { |
| 3906 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 3907 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 3908 | /// for IR generation. |
| 3909 | class OpenMPIterationSpaceChecker { |
| 3910 | /// \brief Reference to Sema. |
| 3911 | Sema &SemaRef; |
| 3912 | /// \brief A location for diagnostics (when there is no some better location). |
| 3913 | SourceLocation DefaultLoc; |
| 3914 | /// \brief A location for diagnostics (when increment is not compatible). |
| 3915 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3916 | /// \brief A source location for referring to loop init later. |
| 3917 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3918 | /// \brief A source location for referring to condition later. |
| 3919 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3920 | /// \brief A source location for referring to increment later. |
| 3921 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3922 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3923 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3924 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3925 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3926 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3927 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3928 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3929 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3930 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3931 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3932 | /// \brief This flag is true when condition is one of: |
| 3933 | /// Var < UB |
| 3934 | /// Var <= UB |
| 3935 | /// UB > Var |
| 3936 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3937 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3938 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3939 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3940 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3941 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3942 | |
| 3943 | public: |
| 3944 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3945 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3946 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 3947 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3948 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3949 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 3950 | /// for less/greater and for strict/non-strict comparison. |
| 3951 | bool CheckCond(Expr *S); |
| 3952 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 3953 | /// does not conform, otherwise save loop step (#Step). |
| 3954 | bool CheckInc(Expr *S); |
| 3955 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3956 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 3957 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3958 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3959 | /// \brief Source range of the loop init. |
| 3960 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 3961 | /// \brief Source range of the loop condition. |
| 3962 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 3963 | /// \brief Source range of the loop increment. |
| 3964 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 3965 | /// \brief True if the step should be subtracted. |
| 3966 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 3967 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3968 | Expr * |
| 3969 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 3970 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3971 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3972 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 3973 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3974 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3975 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 3976 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3977 | /// \brief Build reference expression to the private counter be used for |
| 3978 | /// codegen. |
| 3979 | Expr *BuildPrivateCounterVar() const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3980 | /// \brief Build initization of the counter be used for codegen. |
| 3981 | Expr *BuildCounterInit() const; |
| 3982 | /// \brief Build step of the counter be used for codegen. |
| 3983 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3984 | /// \brief Return true if any expression is dependent. |
| 3985 | bool Dependent() const; |
| 3986 | |
| 3987 | private: |
| 3988 | /// \brief Check the right-hand side of an assignment in the increment |
| 3989 | /// expression. |
| 3990 | bool CheckIncRHS(Expr *RHS); |
| 3991 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3992 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3993 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 3994 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 3995 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3996 | /// \brief Helper to set loop increment. |
| 3997 | bool SetStep(Expr *NewStep, bool Subtract); |
| 3998 | }; |
| 3999 | |
| 4000 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4001 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4002 | assert(!LB && !UB && !Step); |
| 4003 | return false; |
| 4004 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4005 | return LCDecl->getType()->isDependentType() || |
| 4006 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 4007 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4008 | } |
| 4009 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4010 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4011 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 4012 | E = ExprTemp->getSubExpr(); |
| 4013 | |
| 4014 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 4015 | E = MTE->GetTemporaryExpr(); |
| 4016 | |
| 4017 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 4018 | E = Binder->getSubExpr(); |
| 4019 | |
| 4020 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 4021 | E = ICE->getSubExprAsWritten(); |
| 4022 | return E->IgnoreParens(); |
| 4023 | } |
| 4024 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4025 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 4026 | Expr *NewLCRefExpr, |
| 4027 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4028 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4029 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4030 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4031 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4032 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4033 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 4034 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4035 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 4036 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4037 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4038 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4039 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4040 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4041 | LB = NewLB; |
| 4042 | return false; |
| 4043 | } |
| 4044 | |
| 4045 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 4046 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4047 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4048 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 4049 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4050 | if (!NewUB) |
| 4051 | return true; |
| 4052 | UB = NewUB; |
| 4053 | TestIsLessOp = LessOp; |
| 4054 | TestIsStrictOp = StrictOp; |
| 4055 | ConditionSrcRange = SR; |
| 4056 | ConditionLoc = SL; |
| 4057 | return false; |
| 4058 | } |
| 4059 | |
| 4060 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 4061 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4062 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4063 | if (!NewStep) |
| 4064 | return true; |
| 4065 | if (!NewStep->isValueDependent()) { |
| 4066 | // Check that the step is integer expression. |
| 4067 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 4068 | ExprResult Val = |
| 4069 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 4070 | if (Val.isInvalid()) |
| 4071 | return true; |
| 4072 | NewStep = Val.get(); |
| 4073 | |
| 4074 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 4075 | // If test-expr is of form var relational-op b and relational-op is < or |
| 4076 | // <= then incr-expr must cause var to increase on each iteration of the |
| 4077 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 4078 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 4079 | // the loop. |
| 4080 | // If test-expr is of form b relational-op var and relational-op is < or |
| 4081 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 4082 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 4083 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 4084 | // the loop. |
| 4085 | llvm::APSInt Result; |
| 4086 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4087 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 4088 | bool IsConstNeg = |
| 4089 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4090 | bool IsConstPos = |
| 4091 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4092 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 4093 | if (UB && (IsConstZero || |
| 4094 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4095 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4096 | SemaRef.Diag(NewStep->getExprLoc(), |
| 4097 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4098 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4099 | SemaRef.Diag(ConditionLoc, |
| 4100 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 4101 | << TestIsLessOp << ConditionSrcRange; |
| 4102 | return true; |
| 4103 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4104 | if (TestIsLessOp == Subtract) { |
| 4105 | NewStep = SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, |
| 4106 | NewStep).get(); |
| 4107 | Subtract = !Subtract; |
| 4108 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4109 | } |
| 4110 | |
| 4111 | Step = NewStep; |
| 4112 | SubtractStep = Subtract; |
| 4113 | return false; |
| 4114 | } |
| 4115 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4116 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4117 | // Check init-expr for canonical loop form and save loop counter |
| 4118 | // variable - #Var and its initialization value - #LB. |
| 4119 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 4120 | // var = lb |
| 4121 | // integer-type var = lb |
| 4122 | // random-access-iterator-type var = lb |
| 4123 | // pointer-type var = lb |
| 4124 | // |
| 4125 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4126 | if (EmitDiags) { |
| 4127 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 4128 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4129 | return true; |
| 4130 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4131 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4132 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4133 | S = ExprTemp->getSubExpr(); |
| 4134 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4135 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4136 | if (Expr *E = dyn_cast<Expr>(S)) |
| 4137 | S = E->IgnoreParens(); |
| 4138 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4139 | if (BO->getOpcode() == BO_Assign) { |
| 4140 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 4141 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 4142 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4143 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4144 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4145 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 4146 | } |
| 4147 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4148 | if (ME->isArrow() && |
| 4149 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4150 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4151 | } |
| 4152 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4153 | } else if (auto DS = dyn_cast<DeclStmt>(S)) { |
| 4154 | if (DS->isSingleDecl()) { |
| 4155 | if (auto Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4156 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4157 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4158 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4159 | SemaRef.Diag(S->getLocStart(), |
| 4160 | diag::ext_omp_loop_not_canonical_init) |
| 4161 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4162 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4163 | } |
| 4164 | } |
| 4165 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4166 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 4167 | if (CE->getOperator() == OO_Equal) { |
| 4168 | auto *LHS = CE->getArg(0); |
| 4169 | if (auto DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 4170 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4171 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4172 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4173 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 4174 | } |
| 4175 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4176 | if (ME->isArrow() && |
| 4177 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4178 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4179 | } |
| 4180 | } |
| 4181 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4182 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4183 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4184 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4185 | if (EmitDiags) { |
| 4186 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 4187 | << S->getSourceRange(); |
| 4188 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4189 | return true; |
| 4190 | } |
| 4191 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4192 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4193 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4194 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4195 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 4196 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4197 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4198 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 4199 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4200 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4201 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4202 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4203 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4204 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 4205 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 4206 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 4207 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4208 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4209 | return getCanonicalDecl(VD); |
| 4210 | } |
| 4211 | } |
| 4212 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 4213 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4214 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4215 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 4219 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 4220 | // less/greater and for strict/non-strict comparison. |
| 4221 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4222 | // var relational-op b |
| 4223 | // b relational-op var |
| 4224 | // |
| 4225 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4226 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4227 | return true; |
| 4228 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4229 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4230 | SourceLocation CondLoc = S->getLocStart(); |
| 4231 | if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 4232 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4233 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4234 | return SetUB(BO->getRHS(), |
| 4235 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 4236 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4237 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4238 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4239 | return SetUB(BO->getLHS(), |
| 4240 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 4241 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4242 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 4243 | } |
| 4244 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 4245 | if (CE->getNumArgs() == 2) { |
| 4246 | auto Op = CE->getOperator(); |
| 4247 | switch (Op) { |
| 4248 | case OO_Greater: |
| 4249 | case OO_GreaterEqual: |
| 4250 | case OO_Less: |
| 4251 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4252 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4253 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 4254 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4255 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4256 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4257 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 4258 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4259 | CE->getOperatorLoc()); |
| 4260 | break; |
| 4261 | default: |
| 4262 | break; |
| 4263 | } |
| 4264 | } |
| 4265 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4266 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4267 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4268 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4269 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4270 | return true; |
| 4271 | } |
| 4272 | |
| 4273 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 4274 | // RHS of canonical loop form increment can be: |
| 4275 | // var + incr |
| 4276 | // incr + var |
| 4277 | // var - incr |
| 4278 | // |
| 4279 | RHS = RHS->IgnoreParenImpCasts(); |
| 4280 | if (auto BO = dyn_cast<BinaryOperator>(RHS)) { |
| 4281 | if (BO->isAdditiveOp()) { |
| 4282 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4283 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4284 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4285 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4286 | return SetStep(BO->getLHS(), false); |
| 4287 | } |
| 4288 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
| 4289 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 4290 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4291 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4292 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4293 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4294 | return SetStep(CE->getArg(0), false); |
| 4295 | } |
| 4296 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4297 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4298 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4299 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4300 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4301 | return true; |
| 4302 | } |
| 4303 | |
| 4304 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 4305 | // Check incr-expr for canonical loop form and return true if it |
| 4306 | // does not conform. |
| 4307 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4308 | // ++var |
| 4309 | // var++ |
| 4310 | // --var |
| 4311 | // var-- |
| 4312 | // var += incr |
| 4313 | // var -= incr |
| 4314 | // var = var + incr |
| 4315 | // var = incr + var |
| 4316 | // var = var - incr |
| 4317 | // |
| 4318 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4319 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4320 | return true; |
| 4321 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4322 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4323 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4324 | S = ExprTemp->getSubExpr(); |
| 4325 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4326 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4327 | S = S->IgnoreParens(); |
| 4328 | if (auto UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4329 | if (UO->isIncrementDecrementOp() && |
| 4330 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4331 | return SetStep( |
| 4332 | SemaRef.ActOnIntegerConstant(UO->getLocStart(), |
| 4333 | (UO->isDecrementOp() ? -1 : 1)).get(), |
| 4334 | false); |
| 4335 | } else if (auto BO = dyn_cast<BinaryOperator>(S)) { |
| 4336 | switch (BO->getOpcode()) { |
| 4337 | case BO_AddAssign: |
| 4338 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4339 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4340 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 4341 | break; |
| 4342 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4343 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4344 | return CheckIncRHS(BO->getRHS()); |
| 4345 | break; |
| 4346 | default: |
| 4347 | break; |
| 4348 | } |
| 4349 | } else if (auto CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
| 4350 | switch (CE->getOperator()) { |
| 4351 | case OO_PlusPlus: |
| 4352 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4353 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4354 | return SetStep( |
| 4355 | SemaRef.ActOnIntegerConstant( |
| 4356 | CE->getLocStart(), |
| 4357 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)).get(), |
| 4358 | false); |
| 4359 | break; |
| 4360 | case OO_PlusEqual: |
| 4361 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4362 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4363 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 4364 | break; |
| 4365 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4366 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4367 | return CheckIncRHS(CE->getArg(1)); |
| 4368 | break; |
| 4369 | default: |
| 4370 | break; |
| 4371 | } |
| 4372 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4373 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4374 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4375 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4376 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4377 | return true; |
| 4378 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4379 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4380 | static ExprResult |
| 4381 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 4382 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4383 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 4384 | return SemaRef.PerformImplicitConversion( |
| 4385 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 4386 | /*AllowExplicit=*/true); |
| 4387 | auto I = Captures.find(Capture); |
| 4388 | if (I != Captures.end()) |
| 4389 | return buildCapture(SemaRef, Capture, I->second); |
| 4390 | DeclRefExpr *Ref = nullptr; |
| 4391 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 4392 | Captures[Capture] = Ref; |
| 4393 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4394 | } |
| 4395 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4396 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4397 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 4398 | Scope *S, const bool LimitedType, |
| 4399 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4400 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4401 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4402 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4403 | SemaRef.getLangOpts().CPlusPlus) { |
| 4404 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4405 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 4406 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4407 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 4408 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4409 | if (!Upper || !Lower) |
| 4410 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4411 | |
| 4412 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4413 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4414 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4415 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4416 | // and lower bound, and to tell what is passed to 'operator-'. |
| 4417 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 4418 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4419 | return nullptr; |
| 4420 | } |
| 4421 | } |
| 4422 | |
| 4423 | if (!Diff.isUsable()) |
| 4424 | return nullptr; |
| 4425 | |
| 4426 | // Upper - Lower [- 1] |
| 4427 | if (TestIsStrictOp) |
| 4428 | Diff = SemaRef.BuildBinOp( |
| 4429 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 4430 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4431 | if (!Diff.isUsable()) |
| 4432 | return nullptr; |
| 4433 | |
| 4434 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4435 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 4436 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4437 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4438 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4439 | if (!Diff.isUsable()) |
| 4440 | return nullptr; |
| 4441 | |
| 4442 | // Parentheses (for dumping/debugging purposes only). |
| 4443 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4444 | if (!Diff.isUsable()) |
| 4445 | return nullptr; |
| 4446 | |
| 4447 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4448 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4449 | if (!Diff.isUsable()) |
| 4450 | return nullptr; |
| 4451 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4452 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4453 | QualType Type = Diff.get()->getType(); |
| 4454 | auto &C = SemaRef.Context; |
| 4455 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 4456 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 4457 | if (!Type->isIntegerType() || UseVarType) { |
| 4458 | unsigned NewSize = |
| 4459 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 4460 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 4461 | : Type->hasSignedIntegerRepresentation(); |
| 4462 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4463 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 4464 | Diff = SemaRef.PerformImplicitConversion( |
| 4465 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 4466 | if (!Diff.isUsable()) |
| 4467 | return nullptr; |
| 4468 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4469 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4470 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4471 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 4472 | if (NewSize != C.getTypeSize(Type)) { |
| 4473 | if (NewSize < C.getTypeSize(Type)) { |
| 4474 | assert(NewSize == 64 && "incorrect loop var size"); |
| 4475 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 4476 | << InitSrcRange << ConditionSrcRange; |
| 4477 | } |
| 4478 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4479 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 4480 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4481 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 4482 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 4483 | Sema::AA_Converting, true); |
| 4484 | if (!Diff.isUsable()) |
| 4485 | return nullptr; |
| 4486 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4487 | } |
| 4488 | } |
| 4489 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4490 | return Diff.get(); |
| 4491 | } |
| 4492 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4493 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 4494 | Scope *S, Expr *Cond, |
| 4495 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4496 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 4497 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4498 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4499 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4500 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 4501 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 4502 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 4503 | return nullptr; |
| 4504 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4505 | auto CondExpr = SemaRef.BuildBinOp( |
| 4506 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 4507 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4508 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4509 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4510 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 4511 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4512 | CondExpr = SemaRef.PerformImplicitConversion( |
| 4513 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 4514 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4515 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4516 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4517 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 4518 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 4519 | } |
| 4520 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4521 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4522 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4523 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4524 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 4525 | if (!VD) { |
| 4526 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 4527 | auto *Ref = buildDeclRefExpr( |
| 4528 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4529 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 4530 | // If the loop control decl is explicitly marked as private, do not mark it |
| 4531 | // as captured again. |
| 4532 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 4533 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4534 | return Ref; |
| 4535 | } |
| 4536 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4537 | DefaultLoc); |
| 4538 | } |
| 4539 | |
| 4540 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4541 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 4542 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 4543 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4544 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 4545 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4546 | if (PrivateVar->isInvalidDecl()) |
| 4547 | return nullptr; |
| 4548 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 4549 | } |
| 4550 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4551 | } |
| 4552 | |
| 4553 | /// \brief Build initization of the counter be used for codegen. |
| 4554 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 4555 | |
| 4556 | /// \brief Build step of the counter be used for codegen. |
| 4557 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 4558 | |
| 4559 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4560 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4561 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4562 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4563 | /// \brief This expression calculates the number of iterations in the loop. |
| 4564 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4565 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4566 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4567 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4568 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4569 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4570 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4571 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4572 | /// \brief This is step for the #CounterVar used to generate its update: |
| 4573 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4574 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4575 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4576 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4577 | /// \brief Source range of the loop init. |
| 4578 | SourceRange InitSrcRange; |
| 4579 | /// \brief Source range of the loop condition. |
| 4580 | SourceRange CondSrcRange; |
| 4581 | /// \brief Source range of the loop increment. |
| 4582 | SourceRange IncSrcRange; |
| 4583 | }; |
| 4584 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4585 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4586 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4587 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 4588 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 4589 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4590 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 4591 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4592 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 4593 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4594 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 4595 | if (auto *D = ISC.GetLoopDecl()) { |
| 4596 | auto *VD = dyn_cast<VarDecl>(D); |
| 4597 | if (!VD) { |
| 4598 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 4599 | VD = Private; |
| 4600 | else { |
| 4601 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 4602 | /*WithInit=*/false); |
| 4603 | VD = cast<VarDecl>(Ref->getDecl()); |
| 4604 | } |
| 4605 | } |
| 4606 | DSAStack->addLoopControlVariable(D, VD); |
| 4607 | } |
| 4608 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4609 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4610 | } |
| 4611 | } |
| 4612 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4613 | /// \brief Called on a for stmt to check and extract its iteration space |
| 4614 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4615 | static bool CheckOpenMPIterationSpace( |
| 4616 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 4617 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4618 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4619 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4620 | LoopIterationSpace &ResultIterSpace, |
| 4621 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4622 | // OpenMP [2.6, Canonical Loop Form] |
| 4623 | // for (init-expr; test-expr; incr-expr) structured-block |
| 4624 | auto For = dyn_cast_or_null<ForStmt>(S); |
| 4625 | if (!For) { |
| 4626 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4627 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 4628 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 4629 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 4630 | if (NestedLoopCount > 1) { |
| 4631 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 4632 | SemaRef.Diag(DSA.getConstructLoc(), |
| 4633 | diag::note_omp_collapse_ordered_expr) |
| 4634 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 4635 | << OrderedLoopCountExpr->getSourceRange(); |
| 4636 | else if (CollapseLoopCountExpr) |
| 4637 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4638 | diag::note_omp_collapse_ordered_expr) |
| 4639 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 4640 | else |
| 4641 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4642 | diag::note_omp_collapse_ordered_expr) |
| 4643 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 4644 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4645 | return true; |
| 4646 | } |
| 4647 | assert(For->getBody()); |
| 4648 | |
| 4649 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 4650 | |
| 4651 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 4652 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4653 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4654 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4655 | |
| 4656 | bool HasErrors = false; |
| 4657 | |
| 4658 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4659 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 4660 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4661 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4662 | // OpenMP [2.6, Canonical Loop Form] |
| 4663 | // Var is one of the following: |
| 4664 | // A variable of signed or unsigned integer type. |
| 4665 | // For C++, a variable of a random access iterator type. |
| 4666 | // For C, a variable of a pointer type. |
| 4667 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 4668 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 4669 | !VarType->isPointerType() && |
| 4670 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 4671 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 4672 | << SemaRef.getLangOpts().CPlusPlus; |
| 4673 | HasErrors = true; |
| 4674 | } |
| 4675 | |
| 4676 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 4677 | // a Construct |
| 4678 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4679 | // parallel for construct is (are) private. |
| 4680 | // The loop iteration variable in the associated for-loop of a simd |
| 4681 | // construct with just one associated for-loop is linear with a |
| 4682 | // constant-linear-step that is the increment of the associated for-loop. |
| 4683 | // Exclude loop var from the list of variables with implicitly defined data |
| 4684 | // sharing attributes. |
| 4685 | VarsWithImplicitDSA.erase(LCDecl); |
| 4686 | |
| 4687 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4688 | // in a Construct, C/C++]. |
| 4689 | // The loop iteration variable in the associated for-loop of a simd |
| 4690 | // construct with just one associated for-loop may be listed in a linear |
| 4691 | // clause with a constant-linear-step that is the increment of the |
| 4692 | // associated for-loop. |
| 4693 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4694 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4695 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4696 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4697 | // declared in the loop and it is predetermined as a private. |
| 4698 | auto PredeterminedCKind = |
| 4699 | isOpenMPSimdDirective(DKind) |
| 4700 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4701 | : OMPC_private; |
| 4702 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4703 | DVar.CKind != PredeterminedCKind) || |
| 4704 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4705 | isOpenMPDistributeDirective(DKind)) && |
| 4706 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4707 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4708 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 4709 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 4710 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4711 | << getOpenMPClauseName(PredeterminedCKind); |
| 4712 | if (DVar.RefExpr == nullptr) |
| 4713 | DVar.CKind = PredeterminedCKind; |
| 4714 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 4715 | HasErrors = true; |
| 4716 | } else if (LoopDeclRefExpr != nullptr) { |
| 4717 | // Make the loop iteration variable private (for worksharing constructs), |
| 4718 | // linear (for simd directives with the only one associated loop) or |
| 4719 | // lastprivate (for simd directives with several collapsed or ordered |
| 4720 | // loops). |
| 4721 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 4722 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 4723 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4724 | /*FromParent=*/false); |
| 4725 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 4726 | } |
| 4727 | |
| 4728 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4729 | |
| 4730 | // Check test-expr. |
| 4731 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4732 | |
| 4733 | // Check incr-expr. |
| 4734 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4735 | } |
| 4736 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4737 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4738 | return HasErrors; |
| 4739 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4740 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4741 | ResultIterSpace.PreCond = |
| 4742 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4743 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4744 | DSA.getCurScope(), |
| 4745 | (isOpenMPWorksharingDirective(DKind) || |
| 4746 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4747 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4748 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4749 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4750 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4751 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4752 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4753 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4754 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4755 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4756 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4757 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4758 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4759 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4760 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4761 | ResultIterSpace.CounterInit == nullptr || |
| 4762 | ResultIterSpace.CounterStep == nullptr); |
| 4763 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4764 | return HasErrors; |
| 4765 | } |
| 4766 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4767 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4768 | static ExprResult |
| 4769 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 4770 | ExprResult Start, |
| 4771 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4772 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4773 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 4774 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4775 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4776 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4777 | VarRef.get()->getType())) { |
| 4778 | NewStart = SemaRef.PerformImplicitConversion( |
| 4779 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4780 | /*AllowExplicit=*/true); |
| 4781 | if (!NewStart.isUsable()) |
| 4782 | return ExprError(); |
| 4783 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4784 | |
| 4785 | auto Init = |
| 4786 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4787 | return Init; |
| 4788 | } |
| 4789 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4790 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4791 | static ExprResult |
| 4792 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4793 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 4794 | ExprResult Step, bool Subtract, |
| 4795 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4796 | // Add parentheses (for debugging purposes only). |
| 4797 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4798 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4799 | !Step.isUsable()) |
| 4800 | return ExprError(); |
| 4801 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4802 | ExprResult NewStep = Step; |
| 4803 | if (Captures) |
| 4804 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4805 | if (NewStep.isInvalid()) |
| 4806 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4807 | ExprResult Update = |
| 4808 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4809 | if (!Update.isUsable()) |
| 4810 | return ExprError(); |
| 4811 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4812 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4813 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4814 | ExprResult NewStart = Start; |
| 4815 | if (Captures) |
| 4816 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4817 | if (NewStart.isInvalid()) |
| 4818 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4819 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4820 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4821 | ExprResult SavedUpdate = Update; |
| 4822 | ExprResult UpdateVal; |
| 4823 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4824 | NewStart.get()->getType()->isOverloadableType() || |
| 4825 | Update.get()->getType()->isOverloadableType()) { |
| 4826 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4827 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4828 | Update = |
| 4829 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4830 | if (Update.isUsable()) { |
| 4831 | UpdateVal = |
| 4832 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 4833 | VarRef.get(), SavedUpdate.get()); |
| 4834 | if (UpdateVal.isUsable()) { |
| 4835 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 4836 | UpdateVal.get()); |
| 4837 | } |
| 4838 | } |
| 4839 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4840 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4841 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4842 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 4843 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 4844 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 4845 | NewStart.get(), SavedUpdate.get()); |
| 4846 | if (!Update.isUsable()) |
| 4847 | return ExprError(); |
| 4848 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4849 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 4850 | VarRef.get()->getType())) { |
| 4851 | Update = SemaRef.PerformImplicitConversion( |
| 4852 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 4853 | if (!Update.isUsable()) |
| 4854 | return ExprError(); |
| 4855 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4856 | |
| 4857 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 4858 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4859 | return Update; |
| 4860 | } |
| 4861 | |
| 4862 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 4863 | /// bits. |
| 4864 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, |
| 4865 | Sema &SemaRef) { |
| 4866 | if (E == nullptr) |
| 4867 | return ExprError(); |
| 4868 | auto &C = SemaRef.Context; |
| 4869 | QualType OldType = E->getType(); |
| 4870 | unsigned HasBits = C.getTypeSize(OldType); |
| 4871 | if (HasBits >= Bits) |
| 4872 | return ExprResult(E); |
| 4873 | // OK to convert to signed, because new type has more bits than old. |
| 4874 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 4875 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 4876 | true); |
| 4877 | } |
| 4878 | |
| 4879 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 4880 | /// into \a Bits bits. |
| 4881 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 4882 | if (E == nullptr) |
| 4883 | return false; |
| 4884 | llvm::APSInt Result; |
| 4885 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 4886 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 4887 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4888 | } |
| 4889 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4890 | /// Build preinits statement for the given declarations. |
| 4891 | static Stmt *buildPreInits(ASTContext &Context, |
| 4892 | SmallVectorImpl<Decl *> &PreInits) { |
| 4893 | if (!PreInits.empty()) { |
| 4894 | return new (Context) DeclStmt( |
| 4895 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 4896 | SourceLocation(), SourceLocation()); |
| 4897 | } |
| 4898 | return nullptr; |
| 4899 | } |
| 4900 | |
| 4901 | /// Build preinits statement for the given declarations. |
| 4902 | static Stmt *buildPreInits(ASTContext &Context, |
| 4903 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 4904 | if (!Captures.empty()) { |
| 4905 | SmallVector<Decl *, 16> PreInits; |
| 4906 | for (auto &Pair : Captures) |
| 4907 | PreInits.push_back(Pair.second->getDecl()); |
| 4908 | return buildPreInits(Context, PreInits); |
| 4909 | } |
| 4910 | return nullptr; |
| 4911 | } |
| 4912 | |
| 4913 | /// Build postupdate expression for the given list of postupdates expressions. |
| 4914 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 4915 | Expr *PostUpdate = nullptr; |
| 4916 | if (!PostUpdates.empty()) { |
| 4917 | for (auto *E : PostUpdates) { |
| 4918 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 4919 | E->getExprLoc(), |
| 4920 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 4921 | E->getExprLoc(), E) |
| 4922 | .get(); |
| 4923 | PostUpdate = PostUpdate |
| 4924 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 4925 | PostUpdate, ConvE) |
| 4926 | .get() |
| 4927 | : ConvE; |
| 4928 | } |
| 4929 | } |
| 4930 | return PostUpdate; |
| 4931 | } |
| 4932 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4933 | /// \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] | 4934 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 4935 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4936 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4937 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 4938 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 4939 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4940 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4941 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4942 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4943 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4944 | // Found 'collapse' clause - calculate collapse number. |
| 4945 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4946 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4947 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4948 | } |
| 4949 | if (OrderedLoopCountExpr) { |
| 4950 | // Found 'ordered' clause - calculate collapse number. |
| 4951 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 4952 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 4953 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 4954 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4955 | diag::err_omp_wrong_ordered_loop_count) |
| 4956 | << OrderedLoopCountExpr->getSourceRange(); |
| 4957 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4958 | diag::note_collapse_loop_count) |
| 4959 | << CollapseLoopCountExpr->getSourceRange(); |
| 4960 | } |
| 4961 | NestedLoopCount = Result.getLimitedValue(); |
| 4962 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4963 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4964 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 4965 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4966 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4967 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 4968 | IterSpaces.resize(NestedLoopCount); |
| 4969 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4970 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4971 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4972 | NestedLoopCount, CollapseLoopCountExpr, |
| 4973 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4974 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4975 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4976 | // 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] | 4977 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 4978 | // All loops associated with the construct must be perfectly nested; that |
| 4979 | // is, there must be no intervening code nor any OpenMP directive between |
| 4980 | // any two loops. |
| 4981 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4982 | } |
| 4983 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4984 | Built.clear(/* size */ NestedLoopCount); |
| 4985 | |
| 4986 | if (SemaRef.CurContext->isDependentContext()) |
| 4987 | return NestedLoopCount; |
| 4988 | |
| 4989 | // An example of what is generated for the following code: |
| 4990 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4991 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4992 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4993 | // for (k = 0; k < NK; ++k) |
| 4994 | // for (j = J0; j < NJ; j+=2) { |
| 4995 | // <loop body> |
| 4996 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4997 | // |
| 4998 | // We generate the code below. |
| 4999 | // Note: the loop body may be outlined in CodeGen. |
| 5000 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 5001 | // iterations and operator+= to calculate counter value. |
| 5002 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 5003 | // or i64 is currently supported). |
| 5004 | // |
| 5005 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 5006 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 5007 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 5008 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 5009 | // // similar updates for vars in clauses (e.g. 'linear') |
| 5010 | // <loop body (using local i and j)> |
| 5011 | // } |
| 5012 | // i = NI; // assign final values of counters |
| 5013 | // j = NJ; |
| 5014 | // |
| 5015 | |
| 5016 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 5017 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5018 | // Precondition tests if there is at least one iteration (all conditions are |
| 5019 | // true). |
| 5020 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5021 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5022 | ExprResult LastIteration32 = WidenIterationCount( |
| 5023 | 32 /* Bits */, SemaRef.PerformImplicitConversion( |
| 5024 | N0->IgnoreImpCasts(), N0->getType(), |
| 5025 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 5026 | .get(), |
| 5027 | SemaRef); |
| 5028 | ExprResult LastIteration64 = WidenIterationCount( |
| 5029 | 64 /* Bits */, SemaRef.PerformImplicitConversion( |
| 5030 | N0->IgnoreImpCasts(), N0->getType(), |
| 5031 | Sema::AA_Converting, /*AllowExplicit=*/true) |
| 5032 | .get(), |
| 5033 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5034 | |
| 5035 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 5036 | return NestedLoopCount; |
| 5037 | |
| 5038 | auto &C = SemaRef.Context; |
| 5039 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 5040 | |
| 5041 | Scope *CurScope = DSA.getCurScope(); |
| 5042 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5043 | if (PreCond.isUsable()) { |
| 5044 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 5045 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 5046 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5047 | auto N = IterSpaces[Cnt].NumIterations; |
| 5048 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 5049 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5050 | LastIteration32 = SemaRef.BuildBinOp( |
| 5051 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
| 5052 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5053 | Sema::AA_Converting, |
| 5054 | /*AllowExplicit=*/true) |
| 5055 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5056 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5057 | LastIteration64 = SemaRef.BuildBinOp( |
| 5058 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
| 5059 | SemaRef.PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5060 | Sema::AA_Converting, |
| 5061 | /*AllowExplicit=*/true) |
| 5062 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | // Choose either the 32-bit or 64-bit version. |
| 5066 | ExprResult LastIteration = LastIteration64; |
| 5067 | if (LastIteration32.isUsable() && |
| 5068 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 5069 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 5070 | FitsInto( |
| 5071 | 32 /* Bits */, |
| 5072 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 5073 | LastIteration64.get(), SemaRef))) |
| 5074 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5075 | QualType VType = LastIteration.get()->getType(); |
| 5076 | QualType RealVType = VType; |
| 5077 | QualType StrideVType = VType; |
| 5078 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 5079 | VType = |
| 5080 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 5081 | StrideVType = |
| 5082 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 5083 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5084 | |
| 5085 | if (!LastIteration.isUsable()) |
| 5086 | return 0; |
| 5087 | |
| 5088 | // Save the number of iterations. |
| 5089 | ExprResult NumIterations = LastIteration; |
| 5090 | { |
| 5091 | LastIteration = SemaRef.BuildBinOp( |
| 5092 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 5093 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5094 | if (!LastIteration.isUsable()) |
| 5095 | return 0; |
| 5096 | } |
| 5097 | |
| 5098 | // Calculate the last iteration number beforehand instead of doing this on |
| 5099 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 5100 | llvm::APSInt Result; |
| 5101 | bool IsConstant = |
| 5102 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 5103 | ExprResult CalcLastIteration; |
| 5104 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5105 | ExprResult SaveRef = |
| 5106 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5107 | LastIteration = SaveRef; |
| 5108 | |
| 5109 | // Prepare SaveRef + 1. |
| 5110 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5111 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5112 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5113 | if (!NumIterations.isUsable()) |
| 5114 | return 0; |
| 5115 | } |
| 5116 | |
| 5117 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 5118 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5119 | // Build variables passed into runtime, nesessary for worksharing directives. |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5120 | ExprResult LB, UB, IL, ST, EUB, PrevLB, PrevUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5121 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5122 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5123 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5124 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 5125 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5126 | SemaRef.AddInitializerToDecl( |
| 5127 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5128 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5129 | |
| 5130 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5131 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 5132 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5133 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 5134 | /*DirectInit*/ false, |
| 5135 | /*TypeMayContainAuto*/ false); |
| 5136 | |
| 5137 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 5138 | // This will be used to implement clause 'lastprivate'. |
| 5139 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5140 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 5141 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5142 | SemaRef.AddInitializerToDecl( |
| 5143 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5144 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5145 | |
| 5146 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5147 | VarDecl *STDecl = |
| 5148 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 5149 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5150 | SemaRef.AddInitializerToDecl( |
| 5151 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 5152 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5153 | |
| 5154 | // Build expression: UB = min(UB, LastIteration) |
| 5155 | // It is nesessary for CodeGen of directives with static scheduling. |
| 5156 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 5157 | UB.get(), LastIteration.get()); |
| 5158 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 5159 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 5160 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 5161 | CondOp.get()); |
| 5162 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5163 | |
| 5164 | // If we have a combined directive that combines 'distribute', 'for' or |
| 5165 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 5166 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 5167 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 5168 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5169 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| 5170 | |
| 5171 | // We expect to have at least 2 more parameters than the 'parallel' |
| 5172 | // directive does - the lower and upper bounds of the previous schedule. |
| 5173 | assert(CD->getNumParams() >= 4 && |
| 5174 | "Unexpected number of parameters in loop combined directive"); |
| 5175 | |
| 5176 | // Set the proper type for the bounds given what we learned from the |
| 5177 | // enclosed loops. |
| 5178 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 5179 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 5180 | |
| 5181 | // Previous lower and upper bounds are obtained from the region |
| 5182 | // parameters. |
| 5183 | PrevLB = |
| 5184 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 5185 | PrevUB = |
| 5186 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 5187 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5191 | ExprResult IV; |
| 5192 | ExprResult Init; |
| 5193 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5194 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 5195 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5196 | Expr *RHS = (isOpenMPWorksharingDirective(DKind) || |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5197 | isOpenMPTaskLoopDirective(DKind) || |
| 5198 | isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5199 | ? LB.get() |
| 5200 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 5201 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 5202 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5203 | } |
| 5204 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5205 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5206 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5207 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5208 | (isOpenMPWorksharingDirective(DKind) || |
| 5209 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5210 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 5211 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 5212 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5213 | |
| 5214 | // Loop increment (IV = IV + 1) |
| 5215 | SourceLocation IncLoc; |
| 5216 | ExprResult Inc = |
| 5217 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 5218 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 5219 | if (!Inc.isUsable()) |
| 5220 | return 0; |
| 5221 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5222 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 5223 | if (!Inc.isUsable()) |
| 5224 | return 0; |
| 5225 | |
| 5226 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 5227 | // Used for directives with static scheduling. |
| 5228 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5229 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5230 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5231 | // LB + ST |
| 5232 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 5233 | if (!NextLB.isUsable()) |
| 5234 | return 0; |
| 5235 | // LB = LB + ST |
| 5236 | NextLB = |
| 5237 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 5238 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 5239 | if (!NextLB.isUsable()) |
| 5240 | return 0; |
| 5241 | // UB + ST |
| 5242 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 5243 | if (!NextUB.isUsable()) |
| 5244 | return 0; |
| 5245 | // UB = UB + ST |
| 5246 | NextUB = |
| 5247 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 5248 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 5249 | if (!NextUB.isUsable()) |
| 5250 | return 0; |
| 5251 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5252 | |
| 5253 | // Build updates and final values of the loop counters. |
| 5254 | bool HasErrors = false; |
| 5255 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5256 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5257 | Built.Updates.resize(NestedLoopCount); |
| 5258 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5259 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5260 | { |
| 5261 | ExprResult Div; |
| 5262 | // Go from inner nested loop to outer. |
| 5263 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5264 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 5265 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 5266 | // Build: Iter = (IV / Div) % IS.NumIters |
| 5267 | // where Div is product of previous iterations' IS.NumIters. |
| 5268 | ExprResult Iter; |
| 5269 | if (Div.isUsable()) { |
| 5270 | Iter = |
| 5271 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 5272 | } else { |
| 5273 | Iter = IV; |
| 5274 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 5275 | "unusable div expected on first iteration only"); |
| 5276 | } |
| 5277 | |
| 5278 | if (Cnt != 0 && Iter.isUsable()) |
| 5279 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 5280 | IS.NumIterations); |
| 5281 | if (!Iter.isUsable()) { |
| 5282 | HasErrors = true; |
| 5283 | break; |
| 5284 | } |
| 5285 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5286 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5287 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 5288 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 5289 | IS.CounterVar->getExprLoc(), |
| 5290 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5291 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5292 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5293 | if (!Init.isUsable()) { |
| 5294 | HasErrors = true; |
| 5295 | break; |
| 5296 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5297 | ExprResult Update = BuildCounterUpdate( |
| 5298 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 5299 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5300 | if (!Update.isUsable()) { |
| 5301 | HasErrors = true; |
| 5302 | break; |
| 5303 | } |
| 5304 | |
| 5305 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 5306 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5307 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5308 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5309 | if (!Final.isUsable()) { |
| 5310 | HasErrors = true; |
| 5311 | break; |
| 5312 | } |
| 5313 | |
| 5314 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 5315 | if (Cnt != 0) { |
| 5316 | if (Div.isUnset()) |
| 5317 | Div = IS.NumIterations; |
| 5318 | else |
| 5319 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 5320 | IS.NumIterations); |
| 5321 | |
| 5322 | // Add parentheses (for debugging purposes only). |
| 5323 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5324 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5325 | if (!Div.isUsable()) { |
| 5326 | HasErrors = true; |
| 5327 | break; |
| 5328 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5329 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5330 | } |
| 5331 | if (!Update.isUsable() || !Final.isUsable()) { |
| 5332 | HasErrors = true; |
| 5333 | break; |
| 5334 | } |
| 5335 | // Save results |
| 5336 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5337 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5338 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5339 | Built.Updates[Cnt] = Update.get(); |
| 5340 | Built.Finals[Cnt] = Final.get(); |
| 5341 | } |
| 5342 | } |
| 5343 | |
| 5344 | if (HasErrors) |
| 5345 | return 0; |
| 5346 | |
| 5347 | // Save results |
| 5348 | Built.IterationVarRef = IV.get(); |
| 5349 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5350 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5351 | Built.CalcLastIteration = |
| 5352 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5353 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5354 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5355 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5356 | Built.Init = Init.get(); |
| 5357 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5358 | Built.LB = LB.get(); |
| 5359 | Built.UB = UB.get(); |
| 5360 | Built.IL = IL.get(); |
| 5361 | Built.ST = ST.get(); |
| 5362 | Built.EUB = EUB.get(); |
| 5363 | Built.NLB = NextLB.get(); |
| 5364 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5365 | Built.PrevLB = PrevLB.get(); |
| 5366 | Built.PrevUB = PrevUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5367 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5368 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 5369 | // Fill data for doacross depend clauses. |
| 5370 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 5371 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 5372 | Pair.first->setCounterValue(CounterVal); |
| 5373 | else { |
| 5374 | if (NestedLoopCount != Pair.second.size() || |
| 5375 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 5376 | // Erroneous case - clause has some problems. |
| 5377 | Pair.first->setCounterValue(CounterVal); |
| 5378 | continue; |
| 5379 | } |
| 5380 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 5381 | auto I = Pair.second.rbegin(); |
| 5382 | auto IS = IterSpaces.rbegin(); |
| 5383 | auto ILM = LoopMultipliers.rbegin(); |
| 5384 | Expr *UpCounterVal = CounterVal; |
| 5385 | Expr *Multiplier = nullptr; |
| 5386 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5387 | if (I->first) { |
| 5388 | assert(IS->CounterStep); |
| 5389 | Expr *NormalizedOffset = |
| 5390 | SemaRef |
| 5391 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 5392 | I->first, IS->CounterStep) |
| 5393 | .get(); |
| 5394 | if (Multiplier) { |
| 5395 | NormalizedOffset = |
| 5396 | SemaRef |
| 5397 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 5398 | NormalizedOffset, Multiplier) |
| 5399 | .get(); |
| 5400 | } |
| 5401 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 5402 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
| 5403 | UpCounterVal = |
| 5404 | SemaRef.BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 5405 | UpCounterVal, NormalizedOffset).get(); |
| 5406 | } |
| 5407 | Multiplier = *ILM; |
| 5408 | ++I; |
| 5409 | ++IS; |
| 5410 | ++ILM; |
| 5411 | } |
| 5412 | Pair.first->setCounterValue(UpCounterVal); |
| 5413 | } |
| 5414 | } |
| 5415 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5416 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5417 | } |
| 5418 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5419 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5420 | auto CollapseClauses = |
| 5421 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 5422 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 5423 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5424 | return nullptr; |
| 5425 | } |
| 5426 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5427 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5428 | auto OrderedClauses = |
| 5429 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 5430 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 5431 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5432 | return nullptr; |
| 5433 | } |
| 5434 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5435 | static bool checkSimdlenSafelenValues(Sema &S, const Expr *Simdlen, |
| 5436 | const Expr *Safelen) { |
| 5437 | llvm::APSInt SimdlenRes, SafelenRes; |
| 5438 | if (Simdlen->isValueDependent() || Simdlen->isTypeDependent() || |
| 5439 | Simdlen->isInstantiationDependent() || |
| 5440 | Simdlen->containsUnexpandedParameterPack()) |
| 5441 | return false; |
| 5442 | if (Safelen->isValueDependent() || Safelen->isTypeDependent() || |
| 5443 | Safelen->isInstantiationDependent() || |
| 5444 | Safelen->containsUnexpandedParameterPack()) |
| 5445 | return false; |
| 5446 | Simdlen->EvaluateAsInt(SimdlenRes, S.Context); |
| 5447 | Safelen->EvaluateAsInt(SafelenRes, S.Context); |
| 5448 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5449 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5450 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5451 | if (SimdlenRes > SafelenRes) { |
| 5452 | S.Diag(Simdlen->getExprLoc(), diag::err_omp_wrong_simdlen_safelen_values) |
| 5453 | << Simdlen->getSourceRange() << Safelen->getSourceRange(); |
| 5454 | return true; |
| 5455 | } |
| 5456 | return false; |
| 5457 | } |
| 5458 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5459 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 5460 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5461 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5462 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5463 | if (!AStmt) |
| 5464 | return StmtError(); |
| 5465 | |
| 5466 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5467 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5468 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5469 | // define the nested loops number. |
| 5470 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5471 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5472 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5473 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5474 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5475 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5476 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5477 | "omp simd loop exprs were not built"); |
| 5478 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5479 | if (!CurContext->isDependentContext()) { |
| 5480 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5481 | for (auto C : Clauses) { |
| 5482 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5483 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5484 | B.NumIterations, *this, CurScope, |
| 5485 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5486 | return StmtError(); |
| 5487 | } |
| 5488 | } |
| 5489 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5490 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5491 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5492 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5493 | OMPSafelenClause *Safelen = nullptr; |
| 5494 | OMPSimdlenClause *Simdlen = nullptr; |
| 5495 | for (auto *Clause : Clauses) { |
| 5496 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5497 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5498 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5499 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5500 | if (Safelen && Simdlen) |
| 5501 | break; |
| 5502 | } |
| 5503 | if (Simdlen && Safelen && |
| 5504 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5505 | Safelen->getSafelen())) |
| 5506 | return StmtError(); |
| 5507 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5508 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5509 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5510 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5511 | } |
| 5512 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5513 | StmtResult Sema::ActOnOpenMPForDirective( |
| 5514 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5515 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5516 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5517 | if (!AStmt) |
| 5518 | return StmtError(); |
| 5519 | |
| 5520 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5521 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5522 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5523 | // define the nested loops number. |
| 5524 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5525 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5526 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5527 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5528 | return StmtError(); |
| 5529 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5530 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5531 | "omp for loop exprs were not built"); |
| 5532 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5533 | if (!CurContext->isDependentContext()) { |
| 5534 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5535 | for (auto C : Clauses) { |
| 5536 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5537 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5538 | B.NumIterations, *this, CurScope, |
| 5539 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5540 | return StmtError(); |
| 5541 | } |
| 5542 | } |
| 5543 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5544 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5545 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5546 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5547 | } |
| 5548 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5549 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 5550 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5551 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5552 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5553 | if (!AStmt) |
| 5554 | return StmtError(); |
| 5555 | |
| 5556 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5557 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5558 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5559 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5560 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5561 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 5562 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5563 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5564 | if (NestedLoopCount == 0) |
| 5565 | return StmtError(); |
| 5566 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5567 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5568 | "omp for simd loop exprs were not built"); |
| 5569 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5570 | if (!CurContext->isDependentContext()) { |
| 5571 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5572 | for (auto C : Clauses) { |
| 5573 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5574 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5575 | B.NumIterations, *this, CurScope, |
| 5576 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5577 | return StmtError(); |
| 5578 | } |
| 5579 | } |
| 5580 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5581 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5582 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5583 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5584 | OMPSafelenClause *Safelen = nullptr; |
| 5585 | OMPSimdlenClause *Simdlen = nullptr; |
| 5586 | for (auto *Clause : Clauses) { |
| 5587 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5588 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5589 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5590 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5591 | if (Safelen && Simdlen) |
| 5592 | break; |
| 5593 | } |
| 5594 | if (Simdlen && Safelen && |
| 5595 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5596 | Safelen->getSafelen())) |
| 5597 | return StmtError(); |
| 5598 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5599 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5600 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5601 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5602 | } |
| 5603 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5604 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5605 | Stmt *AStmt, |
| 5606 | SourceLocation StartLoc, |
| 5607 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5608 | if (!AStmt) |
| 5609 | return StmtError(); |
| 5610 | |
| 5611 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5612 | auto BaseStmt = AStmt; |
| 5613 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5614 | BaseStmt = CS->getCapturedStmt(); |
| 5615 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5616 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5617 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5618 | return StmtError(); |
| 5619 | // All associated statements must be '#pragma omp section' except for |
| 5620 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5621 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5622 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5623 | if (SectionStmt) |
| 5624 | Diag(SectionStmt->getLocStart(), |
| 5625 | diag::err_omp_sections_substmt_not_section); |
| 5626 | return StmtError(); |
| 5627 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5628 | cast<OMPSectionDirective>(SectionStmt) |
| 5629 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5630 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5631 | } else { |
| 5632 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 5633 | return StmtError(); |
| 5634 | } |
| 5635 | |
| 5636 | getCurFunction()->setHasBranchProtectedScope(); |
| 5637 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5638 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5639 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5640 | } |
| 5641 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5642 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 5643 | SourceLocation StartLoc, |
| 5644 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5645 | if (!AStmt) |
| 5646 | return StmtError(); |
| 5647 | |
| 5648 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5649 | |
| 5650 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5651 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5652 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5653 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 5654 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5655 | } |
| 5656 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5657 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 5658 | Stmt *AStmt, |
| 5659 | SourceLocation StartLoc, |
| 5660 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5661 | if (!AStmt) |
| 5662 | return StmtError(); |
| 5663 | |
| 5664 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5665 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5666 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5667 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5668 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 5669 | // The copyprivate clause must not be used with the nowait clause. |
| 5670 | OMPClause *Nowait = nullptr; |
| 5671 | OMPClause *Copyprivate = nullptr; |
| 5672 | for (auto *Clause : Clauses) { |
| 5673 | if (Clause->getClauseKind() == OMPC_nowait) |
| 5674 | Nowait = Clause; |
| 5675 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 5676 | Copyprivate = Clause; |
| 5677 | if (Copyprivate && Nowait) { |
| 5678 | Diag(Copyprivate->getLocStart(), |
| 5679 | diag::err_omp_single_copyprivate_with_nowait); |
| 5680 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 5681 | return StmtError(); |
| 5682 | } |
| 5683 | } |
| 5684 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5685 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5686 | } |
| 5687 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5688 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 5689 | SourceLocation StartLoc, |
| 5690 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5691 | if (!AStmt) |
| 5692 | return StmtError(); |
| 5693 | |
| 5694 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5695 | |
| 5696 | getCurFunction()->setHasBranchProtectedScope(); |
| 5697 | |
| 5698 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5699 | } |
| 5700 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5701 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 5702 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 5703 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5704 | if (!AStmt) |
| 5705 | return StmtError(); |
| 5706 | |
| 5707 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5708 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5709 | bool ErrorFound = false; |
| 5710 | llvm::APSInt Hint; |
| 5711 | SourceLocation HintLoc; |
| 5712 | bool DependentHint = false; |
| 5713 | for (auto *C : Clauses) { |
| 5714 | if (C->getClauseKind() == OMPC_hint) { |
| 5715 | if (!DirName.getName()) { |
| 5716 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 5717 | ErrorFound = true; |
| 5718 | } |
| 5719 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 5720 | if (E->isTypeDependent() || E->isValueDependent() || |
| 5721 | E->isInstantiationDependent()) |
| 5722 | DependentHint = true; |
| 5723 | else { |
| 5724 | Hint = E->EvaluateKnownConstInt(Context); |
| 5725 | HintLoc = C->getLocStart(); |
| 5726 | } |
| 5727 | } |
| 5728 | } |
| 5729 | if (ErrorFound) |
| 5730 | return StmtError(); |
| 5731 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 5732 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 5733 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 5734 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 5735 | if (HintLoc.isValid()) { |
| 5736 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 5737 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 5738 | } else |
| 5739 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 5740 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 5741 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 5742 | << 1 |
| 5743 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 5744 | /*Radix=*/10, /*Signed=*/false); |
| 5745 | } else |
| 5746 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 5747 | } |
| 5748 | } |
| 5749 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5750 | getCurFunction()->setHasBranchProtectedScope(); |
| 5751 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5752 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 5753 | Clauses, AStmt); |
| 5754 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 5755 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 5756 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5757 | } |
| 5758 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5759 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 5760 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5761 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5762 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5763 | if (!AStmt) |
| 5764 | return StmtError(); |
| 5765 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5766 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5767 | // 1.2.2 OpenMP Language Terminology |
| 5768 | // Structured block - An executable statement with a single entry at the |
| 5769 | // top and a single exit at the bottom. |
| 5770 | // The point of exit cannot be a branch out of the structured block. |
| 5771 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5772 | CS->getCapturedDecl()->setNothrow(); |
| 5773 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5774 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5775 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5776 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5777 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5778 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 5779 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5780 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5781 | if (NestedLoopCount == 0) |
| 5782 | return StmtError(); |
| 5783 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5784 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5785 | "omp parallel for loop exprs were not built"); |
| 5786 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5787 | if (!CurContext->isDependentContext()) { |
| 5788 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5789 | for (auto C : Clauses) { |
| 5790 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5791 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5792 | B.NumIterations, *this, CurScope, |
| 5793 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5794 | return StmtError(); |
| 5795 | } |
| 5796 | } |
| 5797 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5798 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5799 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5800 | NestedLoopCount, Clauses, AStmt, B, |
| 5801 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5802 | } |
| 5803 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5804 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5805 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5806 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5807 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5808 | if (!AStmt) |
| 5809 | return StmtError(); |
| 5810 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5811 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5812 | // 1.2.2 OpenMP Language Terminology |
| 5813 | // Structured block - An executable statement with a single entry at the |
| 5814 | // top and a single exit at the bottom. |
| 5815 | // The point of exit cannot be a branch out of the structured block. |
| 5816 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5817 | CS->getCapturedDecl()->setNothrow(); |
| 5818 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5819 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5820 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5821 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5822 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5823 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5824 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5825 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5826 | if (NestedLoopCount == 0) |
| 5827 | return StmtError(); |
| 5828 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5829 | if (!CurContext->isDependentContext()) { |
| 5830 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5831 | for (auto C : Clauses) { |
| 5832 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 5833 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5834 | B.NumIterations, *this, CurScope, |
| 5835 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5836 | return StmtError(); |
| 5837 | } |
| 5838 | } |
| 5839 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5840 | // OpenMP 4.1 [2.8.1, simd Construct, Restrictions] |
| 5841 | // If both simdlen and safelen clauses are specified, the value of the simdlen |
| 5842 | // parameter must be less than or equal to the value of the safelen parameter. |
| 5843 | OMPSafelenClause *Safelen = nullptr; |
| 5844 | OMPSimdlenClause *Simdlen = nullptr; |
| 5845 | for (auto *Clause : Clauses) { |
| 5846 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5847 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5848 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5849 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5850 | if (Safelen && Simdlen) |
| 5851 | break; |
| 5852 | } |
| 5853 | if (Simdlen && Safelen && |
| 5854 | checkSimdlenSafelenValues(*this, Simdlen->getSimdlen(), |
| 5855 | Safelen->getSafelen())) |
| 5856 | return StmtError(); |
| 5857 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5858 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5859 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5860 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5863 | StmtResult |
| 5864 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5865 | Stmt *AStmt, SourceLocation StartLoc, |
| 5866 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5867 | if (!AStmt) |
| 5868 | return StmtError(); |
| 5869 | |
| 5870 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5871 | auto BaseStmt = AStmt; |
| 5872 | while (CapturedStmt *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
| 5873 | BaseStmt = CS->getCapturedStmt(); |
| 5874 | if (auto C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
| 5875 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5876 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5877 | return StmtError(); |
| 5878 | // All associated statements must be '#pragma omp section' except for |
| 5879 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5880 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5881 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5882 | if (SectionStmt) |
| 5883 | Diag(SectionStmt->getLocStart(), |
| 5884 | diag::err_omp_parallel_sections_substmt_not_section); |
| 5885 | return StmtError(); |
| 5886 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5887 | cast<OMPSectionDirective>(SectionStmt) |
| 5888 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5889 | } |
| 5890 | } else { |
| 5891 | Diag(AStmt->getLocStart(), |
| 5892 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 5893 | return StmtError(); |
| 5894 | } |
| 5895 | |
| 5896 | getCurFunction()->setHasBranchProtectedScope(); |
| 5897 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5898 | return OMPParallelSectionsDirective::Create( |
| 5899 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 5900 | } |
| 5901 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5902 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 5903 | Stmt *AStmt, SourceLocation StartLoc, |
| 5904 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5905 | if (!AStmt) |
| 5906 | return StmtError(); |
| 5907 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5908 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5909 | // 1.2.2 OpenMP Language Terminology |
| 5910 | // Structured block - An executable statement with a single entry at the |
| 5911 | // top and a single exit at the bottom. |
| 5912 | // The point of exit cannot be a branch out of the structured block. |
| 5913 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5914 | CS->getCapturedDecl()->setNothrow(); |
| 5915 | |
| 5916 | getCurFunction()->setHasBranchProtectedScope(); |
| 5917 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5918 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5919 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 5920 | } |
| 5921 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 5922 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 5923 | SourceLocation EndLoc) { |
| 5924 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 5925 | } |
| 5926 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 5927 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 5928 | SourceLocation EndLoc) { |
| 5929 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 5930 | } |
| 5931 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 5932 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 5933 | SourceLocation EndLoc) { |
| 5934 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 5935 | } |
| 5936 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5937 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 5938 | SourceLocation StartLoc, |
| 5939 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5940 | if (!AStmt) |
| 5941 | return StmtError(); |
| 5942 | |
| 5943 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 5944 | |
| 5945 | getCurFunction()->setHasBranchProtectedScope(); |
| 5946 | |
| 5947 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5948 | } |
| 5949 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 5950 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 5951 | SourceLocation StartLoc, |
| 5952 | SourceLocation EndLoc) { |
| 5953 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 5954 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5955 | } |
| 5956 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5957 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 5958 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5959 | SourceLocation StartLoc, |
| 5960 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5961 | OMPClause *DependFound = nullptr; |
| 5962 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5963 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5964 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5965 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5966 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5967 | for (auto *C : Clauses) { |
| 5968 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 5969 | DependFound = C; |
| 5970 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 5971 | if (DependSourceClause) { |
| 5972 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5973 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5974 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5975 | ErrorFound = true; |
| 5976 | } else |
| 5977 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5978 | if (DependSinkClause) { |
| 5979 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5980 | << 0; |
| 5981 | ErrorFound = true; |
| 5982 | } |
| 5983 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5984 | if (DependSourceClause) { |
| 5985 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5986 | << 1; |
| 5987 | ErrorFound = true; |
| 5988 | } |
| 5989 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5990 | } |
| 5991 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5992 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5993 | else if (C->getClauseKind() == OMPC_simd) |
| 5994 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5995 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5996 | if (!ErrorFound && !SC && |
| 5997 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5998 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5999 | // An ordered construct with the simd clause is the only OpenMP construct |
| 6000 | // that can appear in the simd region. |
| 6001 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6002 | ErrorFound = true; |
| 6003 | } else if (DependFound && (TC || SC)) { |
| 6004 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 6005 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 6006 | ErrorFound = true; |
| 6007 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 6008 | Diag(DependFound->getLocStart(), |
| 6009 | diag::err_omp_ordered_directive_without_param); |
| 6010 | ErrorFound = true; |
| 6011 | } else if (TC || Clauses.empty()) { |
| 6012 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 6013 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 6014 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 6015 | << (TC != nullptr); |
| 6016 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 6017 | ErrorFound = true; |
| 6018 | } |
| 6019 | } |
| 6020 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6021 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6022 | |
| 6023 | if (AStmt) { |
| 6024 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6025 | |
| 6026 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6027 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6028 | |
| 6029 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6030 | } |
| 6031 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6032 | namespace { |
| 6033 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 6034 | /// construct. |
| 6035 | class OpenMPAtomicUpdateChecker { |
| 6036 | /// \brief Error results for atomic update expressions. |
| 6037 | enum ExprAnalysisErrorCode { |
| 6038 | /// \brief A statement is not an expression statement. |
| 6039 | NotAnExpression, |
| 6040 | /// \brief Expression is not builtin binary or unary operation. |
| 6041 | NotABinaryOrUnaryExpression, |
| 6042 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 6043 | NotAnUnaryIncDecExpression, |
| 6044 | /// \brief An expression is not of scalar type. |
| 6045 | NotAScalarType, |
| 6046 | /// \brief A binary operation is not an assignment operation. |
| 6047 | NotAnAssignmentOp, |
| 6048 | /// \brief RHS part of the binary operation is not a binary expression. |
| 6049 | NotABinaryExpression, |
| 6050 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 6051 | /// expression. |
| 6052 | NotABinaryOperator, |
| 6053 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 6054 | /// part. |
| 6055 | NotAnUpdateExpression, |
| 6056 | /// \brief No errors is found. |
| 6057 | NoError |
| 6058 | }; |
| 6059 | /// \brief Reference to Sema. |
| 6060 | Sema &SemaRef; |
| 6061 | /// \brief A location for note diagnostics (when error is found). |
| 6062 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6063 | /// \brief 'x' lvalue part of the source atomic expression. |
| 6064 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6065 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 6066 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6067 | /// \brief Helper expression of the form |
| 6068 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6069 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6070 | Expr *UpdateExpr; |
| 6071 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 6072 | /// important for non-associative operations. |
| 6073 | bool IsXLHSInRHSPart; |
| 6074 | BinaryOperatorKind Op; |
| 6075 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6076 | /// \brief true if the source expression is a postfix unary operation, false |
| 6077 | /// if it is a prefix unary operation. |
| 6078 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6079 | |
| 6080 | public: |
| 6081 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6082 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6083 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6084 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 6085 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6086 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 6087 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6088 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 6089 | /// \param NoteId Diagnostic note for the main error message. |
| 6090 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6091 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6092 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 6093 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6094 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 6095 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6096 | /// \brief Return the update expression used in calculation of the updated |
| 6097 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6098 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6099 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 6100 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 6101 | /// false otherwise. |
| 6102 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 6103 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6104 | /// \brief true if the source expression is a postfix unary operation, false |
| 6105 | /// if it is a prefix unary operation. |
| 6106 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 6107 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6108 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6109 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 6110 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6111 | }; |
| 6112 | } // namespace |
| 6113 | |
| 6114 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 6115 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 6116 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6117 | SourceLocation ErrorLoc, NoteLoc; |
| 6118 | SourceRange ErrorRange, NoteRange; |
| 6119 | // Allowed constructs are: |
| 6120 | // x = x binop expr; |
| 6121 | // x = expr binop x; |
| 6122 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 6123 | X = AtomicBinOp->getLHS(); |
| 6124 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 6125 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 6126 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 6127 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 6128 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6129 | Op = AtomicInnerBinOp->getOpcode(); |
| 6130 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6131 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 6132 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 6133 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 6134 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 6135 | /*Canonical=*/true); |
| 6136 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 6137 | /*Canonical=*/true); |
| 6138 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 6139 | /*Canonical=*/true); |
| 6140 | if (XId == LHSId) { |
| 6141 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6142 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6143 | } else if (XId == RHSId) { |
| 6144 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6145 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6146 | } else { |
| 6147 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6148 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6149 | NoteLoc = X->getExprLoc(); |
| 6150 | NoteRange = X->getSourceRange(); |
| 6151 | ErrorFound = NotAnUpdateExpression; |
| 6152 | } |
| 6153 | } else { |
| 6154 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6155 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6156 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 6157 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6158 | ErrorFound = NotABinaryOperator; |
| 6159 | } |
| 6160 | } else { |
| 6161 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 6162 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 6163 | ErrorFound = NotABinaryExpression; |
| 6164 | } |
| 6165 | } else { |
| 6166 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6167 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6168 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 6169 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6170 | ErrorFound = NotAnAssignmentOp; |
| 6171 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6172 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6173 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6174 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6175 | return true; |
| 6176 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6177 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6178 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 6182 | unsigned NoteId) { |
| 6183 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6184 | SourceLocation ErrorLoc, NoteLoc; |
| 6185 | SourceRange ErrorRange, NoteRange; |
| 6186 | // Allowed constructs are: |
| 6187 | // x++; |
| 6188 | // x--; |
| 6189 | // ++x; |
| 6190 | // --x; |
| 6191 | // x binop= expr; |
| 6192 | // x = x binop expr; |
| 6193 | // x = expr binop x; |
| 6194 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 6195 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 6196 | if (AtomicBody->getType()->isScalarType() || |
| 6197 | AtomicBody->isInstantiationDependent()) { |
| 6198 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 6199 | AtomicBody->IgnoreParenImpCasts())) { |
| 6200 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6201 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6202 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6203 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6204 | E = AtomicCompAssignOp->getRHS(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6205 | X = AtomicCompAssignOp->getLHS(); |
| 6206 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6207 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 6208 | AtomicBody->IgnoreParenImpCasts())) { |
| 6209 | // Check for Binary Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6210 | if(checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
| 6211 | return true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6212 | } else if (auto *AtomicUnaryOp = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6213 | dyn_cast<UnaryOperator>(AtomicBody->IgnoreParenImpCasts())) { |
| 6214 | // Check for Unary Operation |
| 6215 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6216 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6217 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 6218 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
| 6219 | X = AtomicUnaryOp->getSubExpr(); |
| 6220 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 6221 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6222 | } else { |
| 6223 | ErrorFound = NotAnUnaryIncDecExpression; |
| 6224 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 6225 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 6226 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 6227 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6228 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6229 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6230 | ErrorFound = NotABinaryOrUnaryExpression; |
| 6231 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 6232 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 6233 | } |
| 6234 | } else { |
| 6235 | ErrorFound = NotAScalarType; |
| 6236 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 6237 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6238 | } |
| 6239 | } else { |
| 6240 | ErrorFound = NotAnExpression; |
| 6241 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 6242 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6243 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6244 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6245 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6246 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6247 | return true; |
| 6248 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6249 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6250 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6251 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 6252 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 6253 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 6254 | auto *OVEX = new (SemaRef.getASTContext()) |
| 6255 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 6256 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 6257 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 6258 | auto Update = |
| 6259 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 6260 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 6261 | if (Update.isInvalid()) |
| 6262 | return true; |
| 6263 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 6264 | Sema::AA_Casting); |
| 6265 | if (Update.isInvalid()) |
| 6266 | return true; |
| 6267 | UpdateExpr = Update.get(); |
| 6268 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6269 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6270 | } |
| 6271 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6272 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 6273 | Stmt *AStmt, |
| 6274 | SourceLocation StartLoc, |
| 6275 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6276 | if (!AStmt) |
| 6277 | return StmtError(); |
| 6278 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6279 | auto CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6280 | // 1.2.2 OpenMP Language Terminology |
| 6281 | // Structured block - An executable statement with a single entry at the |
| 6282 | // top and a single exit at the bottom. |
| 6283 | // The point of exit cannot be a branch out of the structured block. |
| 6284 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6285 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 6286 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6287 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6288 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6289 | C->getClauseKind() == OMPC_update || |
| 6290 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6291 | if (AtomicKind != OMPC_unknown) { |
| 6292 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 6293 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 6294 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 6295 | << getOpenMPClauseName(AtomicKind); |
| 6296 | } else { |
| 6297 | AtomicKind = C->getClauseKind(); |
| 6298 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6299 | } |
| 6300 | } |
| 6301 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6302 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6303 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 6304 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 6305 | Body = EWC->getSubExpr(); |
| 6306 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6307 | Expr *X = nullptr; |
| 6308 | Expr *V = nullptr; |
| 6309 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6310 | Expr *UE = nullptr; |
| 6311 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6312 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6313 | // OpenMP [2.12.6, atomic Construct] |
| 6314 | // In the next expressions: |
| 6315 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 6316 | // * During the execution of an atomic region, multiple syntactic |
| 6317 | // occurrences of x must designate the same storage location. |
| 6318 | // * Neither of v and expr (as applicable) may access the storage location |
| 6319 | // designated by x. |
| 6320 | // * Neither of x and expr (as applicable) may access the storage location |
| 6321 | // designated by v. |
| 6322 | // * expr is an expression with scalar type. |
| 6323 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 6324 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 6325 | // * The expression x binop expr must be numerically equivalent to x binop |
| 6326 | // (expr). This requirement is satisfied if the operators in expr have |
| 6327 | // precedence greater than binop, or by using parentheses around expr or |
| 6328 | // subexpressions of expr. |
| 6329 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 6330 | // binop x. This requirement is satisfied if the operators in expr have |
| 6331 | // precedence equal to or greater than binop, or by using parentheses around |
| 6332 | // expr or subexpressions of expr. |
| 6333 | // * For forms that allow multiple occurrences of x, the number of times |
| 6334 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6335 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6336 | enum { |
| 6337 | NotAnExpression, |
| 6338 | NotAnAssignmentOp, |
| 6339 | NotAScalarType, |
| 6340 | NotAnLValue, |
| 6341 | NoError |
| 6342 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6343 | SourceLocation ErrorLoc, NoteLoc; |
| 6344 | SourceRange ErrorRange, NoteRange; |
| 6345 | // If clause is read: |
| 6346 | // v = x; |
| 6347 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 6348 | auto AtomicBinOp = |
| 6349 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6350 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6351 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6352 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6353 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6354 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 6355 | if (!X->isLValue() || !V->isLValue()) { |
| 6356 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 6357 | ErrorFound = NotAnLValue; |
| 6358 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6359 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6360 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 6361 | NoteRange = NotLValueExpr->getSourceRange(); |
| 6362 | } |
| 6363 | } else if (!X->isInstantiationDependent() || |
| 6364 | !V->isInstantiationDependent()) { |
| 6365 | auto NotScalarExpr = |
| 6366 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6367 | ? V |
| 6368 | : X; |
| 6369 | ErrorFound = NotAScalarType; |
| 6370 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6371 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6372 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6373 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6374 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6375 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6376 | ErrorFound = NotAnAssignmentOp; |
| 6377 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6378 | ErrorRange = AtomicBody->getSourceRange(); |
| 6379 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6380 | : AtomicBody->getExprLoc(); |
| 6381 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6382 | : AtomicBody->getSourceRange(); |
| 6383 | } |
| 6384 | } else { |
| 6385 | ErrorFound = NotAnExpression; |
| 6386 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6387 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6388 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6389 | if (ErrorFound != NoError) { |
| 6390 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 6391 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6392 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6393 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6394 | return StmtError(); |
| 6395 | } else if (CurContext->isDependentContext()) |
| 6396 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6397 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6398 | enum { |
| 6399 | NotAnExpression, |
| 6400 | NotAnAssignmentOp, |
| 6401 | NotAScalarType, |
| 6402 | NotAnLValue, |
| 6403 | NoError |
| 6404 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6405 | SourceLocation ErrorLoc, NoteLoc; |
| 6406 | SourceRange ErrorRange, NoteRange; |
| 6407 | // If clause is write: |
| 6408 | // x = expr; |
| 6409 | if (auto AtomicBody = dyn_cast<Expr>(Body)) { |
| 6410 | auto AtomicBinOp = |
| 6411 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6412 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 6413 | X = AtomicBinOp->getLHS(); |
| 6414 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6415 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6416 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 6417 | if (!X->isLValue()) { |
| 6418 | ErrorFound = NotAnLValue; |
| 6419 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6420 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6421 | NoteLoc = X->getExprLoc(); |
| 6422 | NoteRange = X->getSourceRange(); |
| 6423 | } |
| 6424 | } else if (!X->isInstantiationDependent() || |
| 6425 | !E->isInstantiationDependent()) { |
| 6426 | auto NotScalarExpr = |
| 6427 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6428 | ? E |
| 6429 | : X; |
| 6430 | ErrorFound = NotAScalarType; |
| 6431 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6432 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6433 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6434 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6435 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6436 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6437 | ErrorFound = NotAnAssignmentOp; |
| 6438 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6439 | ErrorRange = AtomicBody->getSourceRange(); |
| 6440 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6441 | : AtomicBody->getExprLoc(); |
| 6442 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6443 | : AtomicBody->getSourceRange(); |
| 6444 | } |
| 6445 | } else { |
| 6446 | ErrorFound = NotAnExpression; |
| 6447 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6448 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6449 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6450 | if (ErrorFound != NoError) { |
| 6451 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 6452 | << ErrorRange; |
| 6453 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6454 | << NoteRange; |
| 6455 | return StmtError(); |
| 6456 | } else if (CurContext->isDependentContext()) |
| 6457 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6458 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6459 | // If clause is update: |
| 6460 | // x++; |
| 6461 | // x--; |
| 6462 | // ++x; |
| 6463 | // --x; |
| 6464 | // x binop= expr; |
| 6465 | // x = x binop expr; |
| 6466 | // x = expr binop x; |
| 6467 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6468 | if (Checker.checkStatement( |
| 6469 | Body, (AtomicKind == OMPC_update) |
| 6470 | ? diag::err_omp_atomic_update_not_expression_statement |
| 6471 | : diag::err_omp_atomic_not_expression_statement, |
| 6472 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6473 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6474 | if (!CurContext->isDependentContext()) { |
| 6475 | E = Checker.getExpr(); |
| 6476 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6477 | UE = Checker.getUpdateExpr(); |
| 6478 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6479 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6480 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6481 | enum { |
| 6482 | NotAnAssignmentOp, |
| 6483 | NotACompoundStatement, |
| 6484 | NotTwoSubstatements, |
| 6485 | NotASpecificExpression, |
| 6486 | NoError |
| 6487 | } ErrorFound = NoError; |
| 6488 | SourceLocation ErrorLoc, NoteLoc; |
| 6489 | SourceRange ErrorRange, NoteRange; |
| 6490 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6491 | // If clause is a capture: |
| 6492 | // v = x++; |
| 6493 | // v = x--; |
| 6494 | // v = ++x; |
| 6495 | // v = --x; |
| 6496 | // v = x binop= expr; |
| 6497 | // v = x = x binop expr; |
| 6498 | // v = x = expr binop x; |
| 6499 | auto *AtomicBinOp = |
| 6500 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6501 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6502 | V = AtomicBinOp->getLHS(); |
| 6503 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6504 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6505 | if (Checker.checkStatement( |
| 6506 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 6507 | diag::note_omp_atomic_update)) |
| 6508 | return StmtError(); |
| 6509 | E = Checker.getExpr(); |
| 6510 | X = Checker.getX(); |
| 6511 | UE = Checker.getUpdateExpr(); |
| 6512 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 6513 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6514 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6515 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6516 | ErrorRange = AtomicBody->getSourceRange(); |
| 6517 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6518 | : AtomicBody->getExprLoc(); |
| 6519 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6520 | : AtomicBody->getSourceRange(); |
| 6521 | ErrorFound = NotAnAssignmentOp; |
| 6522 | } |
| 6523 | if (ErrorFound != NoError) { |
| 6524 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 6525 | << ErrorRange; |
| 6526 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6527 | return StmtError(); |
| 6528 | } else if (CurContext->isDependentContext()) { |
| 6529 | UE = V = E = X = nullptr; |
| 6530 | } |
| 6531 | } else { |
| 6532 | // If clause is a capture: |
| 6533 | // { v = x; x = expr; } |
| 6534 | // { v = x; x++; } |
| 6535 | // { v = x; x--; } |
| 6536 | // { v = x; ++x; } |
| 6537 | // { v = x; --x; } |
| 6538 | // { v = x; x binop= expr; } |
| 6539 | // { v = x; x = x binop expr; } |
| 6540 | // { v = x; x = expr binop x; } |
| 6541 | // { x++; v = x; } |
| 6542 | // { x--; v = x; } |
| 6543 | // { ++x; v = x; } |
| 6544 | // { --x; v = x; } |
| 6545 | // { x binop= expr; v = x; } |
| 6546 | // { x = x binop expr; v = x; } |
| 6547 | // { x = expr binop x; v = x; } |
| 6548 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 6549 | // Check that this is { expr1; expr2; } |
| 6550 | if (CS->size() == 2) { |
| 6551 | auto *First = CS->body_front(); |
| 6552 | auto *Second = CS->body_back(); |
| 6553 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 6554 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6555 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 6556 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6557 | // Need to find what subexpression is 'v' and what is 'x'. |
| 6558 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6559 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 6560 | BinaryOperator *BinOp = nullptr; |
| 6561 | if (IsUpdateExprFound) { |
| 6562 | BinOp = dyn_cast<BinaryOperator>(First); |
| 6563 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6564 | } |
| 6565 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6566 | // { v = x; x++; } |
| 6567 | // { v = x; x--; } |
| 6568 | // { v = x; ++x; } |
| 6569 | // { v = x; --x; } |
| 6570 | // { v = x; x binop= expr; } |
| 6571 | // { v = x; x = x binop expr; } |
| 6572 | // { v = x; x = expr binop x; } |
| 6573 | // Check that the first expression has form v = x. |
| 6574 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6575 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6576 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6577 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6578 | IsUpdateExprFound = XId == PossibleXId; |
| 6579 | if (IsUpdateExprFound) { |
| 6580 | V = BinOp->getLHS(); |
| 6581 | X = Checker.getX(); |
| 6582 | E = Checker.getExpr(); |
| 6583 | UE = Checker.getUpdateExpr(); |
| 6584 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6585 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6586 | } |
| 6587 | } |
| 6588 | if (!IsUpdateExprFound) { |
| 6589 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 6590 | BinOp = nullptr; |
| 6591 | if (IsUpdateExprFound) { |
| 6592 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 6593 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6594 | } |
| 6595 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6596 | // { x++; v = x; } |
| 6597 | // { x--; v = x; } |
| 6598 | // { ++x; v = x; } |
| 6599 | // { --x; v = x; } |
| 6600 | // { x binop= expr; v = x; } |
| 6601 | // { x = x binop expr; v = x; } |
| 6602 | // { x = expr binop x; v = x; } |
| 6603 | // Check that the second expression has form v = x. |
| 6604 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6605 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6606 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6607 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6608 | IsUpdateExprFound = XId == PossibleXId; |
| 6609 | if (IsUpdateExprFound) { |
| 6610 | V = BinOp->getLHS(); |
| 6611 | X = Checker.getX(); |
| 6612 | E = Checker.getExpr(); |
| 6613 | UE = Checker.getUpdateExpr(); |
| 6614 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6615 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6616 | } |
| 6617 | } |
| 6618 | } |
| 6619 | if (!IsUpdateExprFound) { |
| 6620 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6621 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 6622 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 6623 | if (!FirstExpr || !SecondExpr || |
| 6624 | !(FirstExpr->isInstantiationDependent() || |
| 6625 | SecondExpr->isInstantiationDependent())) { |
| 6626 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 6627 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6628 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6629 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 6630 | : First->getLocStart(); |
| 6631 | NoteRange = ErrorRange = FirstBinOp |
| 6632 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6633 | : SourceRange(ErrorLoc, ErrorLoc); |
| 6634 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6635 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 6636 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 6637 | ErrorFound = NotAnAssignmentOp; |
| 6638 | NoteLoc = ErrorLoc = SecondBinOp |
| 6639 | ? SecondBinOp->getOperatorLoc() |
| 6640 | : Second->getLocStart(); |
| 6641 | NoteRange = ErrorRange = |
| 6642 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 6643 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6644 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6645 | auto *PossibleXRHSInFirst = |
| 6646 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6647 | auto *PossibleXLHSInSecond = |
| 6648 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6649 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 6650 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 6651 | /*Canonical=*/true); |
| 6652 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 6653 | /*Canonical=*/true); |
| 6654 | IsUpdateExprFound = X1Id == X2Id; |
| 6655 | if (IsUpdateExprFound) { |
| 6656 | V = FirstBinOp->getLHS(); |
| 6657 | X = SecondBinOp->getLHS(); |
| 6658 | E = SecondBinOp->getRHS(); |
| 6659 | UE = nullptr; |
| 6660 | IsXLHSInRHSPart = false; |
| 6661 | IsPostfixUpdate = true; |
| 6662 | } else { |
| 6663 | ErrorFound = NotASpecificExpression; |
| 6664 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 6665 | ErrorRange = FirstBinOp->getSourceRange(); |
| 6666 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 6667 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 6668 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6669 | } |
| 6670 | } |
| 6671 | } |
| 6672 | } |
| 6673 | } else { |
| 6674 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6675 | NoteRange = ErrorRange = |
| 6676 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6677 | ErrorFound = NotTwoSubstatements; |
| 6678 | } |
| 6679 | } else { |
| 6680 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6681 | NoteRange = ErrorRange = |
| 6682 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6683 | ErrorFound = NotACompoundStatement; |
| 6684 | } |
| 6685 | if (ErrorFound != NoError) { |
| 6686 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 6687 | << ErrorRange; |
| 6688 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6689 | return StmtError(); |
| 6690 | } else if (CurContext->isDependentContext()) { |
| 6691 | UE = V = E = X = nullptr; |
| 6692 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6693 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6694 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6695 | |
| 6696 | getCurFunction()->setHasBranchProtectedScope(); |
| 6697 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6698 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6699 | X, V, E, UE, IsXLHSInRHSPart, |
| 6700 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6701 | } |
| 6702 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6703 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 6704 | Stmt *AStmt, |
| 6705 | SourceLocation StartLoc, |
| 6706 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6707 | if (!AStmt) |
| 6708 | return StmtError(); |
| 6709 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 6710 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6711 | // 1.2.2 OpenMP Language Terminology |
| 6712 | // Structured block - An executable statement with a single entry at the |
| 6713 | // top and a single exit at the bottom. |
| 6714 | // The point of exit cannot be a branch out of the structured block. |
| 6715 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6716 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6717 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6718 | // OpenMP [2.16, Nesting of Regions] |
| 6719 | // If specified, a teams construct must be contained within a target |
| 6720 | // construct. That target construct must contain no statements or directives |
| 6721 | // outside of the teams construct. |
| 6722 | if (DSAStack->hasInnerTeamsRegion()) { |
| 6723 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 6724 | bool OMPTeamsFound = true; |
| 6725 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 6726 | auto I = CS->body_begin(); |
| 6727 | while (I != CS->body_end()) { |
| 6728 | auto OED = dyn_cast<OMPExecutableDirective>(*I); |
| 6729 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 6730 | OMPTeamsFound = false; |
| 6731 | break; |
| 6732 | } |
| 6733 | ++I; |
| 6734 | } |
| 6735 | assert(I != CS->body_end() && "Not found statement"); |
| 6736 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 6737 | } else { |
| 6738 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 6739 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6740 | } |
| 6741 | if (!OMPTeamsFound) { |
| 6742 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 6743 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 6744 | diag::note_omp_nested_teams_construct_here); |
| 6745 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 6746 | << isa<OMPExecutableDirective>(S); |
| 6747 | return StmtError(); |
| 6748 | } |
| 6749 | } |
| 6750 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6751 | getCurFunction()->setHasBranchProtectedScope(); |
| 6752 | |
| 6753 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6754 | } |
| 6755 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6756 | StmtResult |
| 6757 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 6758 | Stmt *AStmt, SourceLocation StartLoc, |
| 6759 | SourceLocation EndLoc) { |
| 6760 | if (!AStmt) |
| 6761 | return StmtError(); |
| 6762 | |
| 6763 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6764 | // 1.2.2 OpenMP Language Terminology |
| 6765 | // Structured block - An executable statement with a single entry at the |
| 6766 | // top and a single exit at the bottom. |
| 6767 | // The point of exit cannot be a branch out of the structured block. |
| 6768 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6769 | CS->getCapturedDecl()->setNothrow(); |
| 6770 | |
| 6771 | getCurFunction()->setHasBranchProtectedScope(); |
| 6772 | |
| 6773 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6774 | AStmt); |
| 6775 | } |
| 6776 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6777 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 6778 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6779 | SourceLocation EndLoc, |
| 6780 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6781 | if (!AStmt) |
| 6782 | return StmtError(); |
| 6783 | |
| 6784 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6785 | // 1.2.2 OpenMP Language Terminology |
| 6786 | // Structured block - An executable statement with a single entry at the |
| 6787 | // top and a single exit at the bottom. |
| 6788 | // The point of exit cannot be a branch out of the structured block. |
| 6789 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6790 | CS->getCapturedDecl()->setNothrow(); |
| 6791 | |
| 6792 | OMPLoopDirective::HelperExprs B; |
| 6793 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6794 | // define the nested loops number. |
| 6795 | unsigned NestedLoopCount = |
| 6796 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 6797 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6798 | VarsWithImplicitDSA, B); |
| 6799 | if (NestedLoopCount == 0) |
| 6800 | return StmtError(); |
| 6801 | |
| 6802 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6803 | "omp target parallel for loop exprs were not built"); |
| 6804 | |
| 6805 | if (!CurContext->isDependentContext()) { |
| 6806 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6807 | for (auto C : Clauses) { |
| 6808 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 6809 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6810 | B.NumIterations, *this, CurScope, |
| 6811 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6812 | return StmtError(); |
| 6813 | } |
| 6814 | } |
| 6815 | |
| 6816 | getCurFunction()->setHasBranchProtectedScope(); |
| 6817 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6818 | NestedLoopCount, Clauses, AStmt, |
| 6819 | B, DSAStack->isCancelRegion()); |
| 6820 | } |
| 6821 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6822 | /// \brief Check for existence of a map clause in the list of clauses. |
| 6823 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 6824 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6825 | I != E; ++I) { |
| 6826 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6827 | return true; |
| 6828 | } |
| 6829 | } |
| 6830 | |
| 6831 | return false; |
| 6832 | } |
| 6833 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6834 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6835 | Stmt *AStmt, |
| 6836 | SourceLocation StartLoc, |
| 6837 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6838 | if (!AStmt) |
| 6839 | return StmtError(); |
| 6840 | |
| 6841 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6842 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6843 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6844 | // At least one map clause must appear on the directive. |
| 6845 | if (!HasMapClause(Clauses)) { |
| 6846 | Diag(StartLoc, diag::err_omp_no_map_for_directive) << |
| 6847 | getOpenMPDirectiveName(OMPD_target_data); |
| 6848 | return StmtError(); |
| 6849 | } |
| 6850 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6851 | getCurFunction()->setHasBranchProtectedScope(); |
| 6852 | |
| 6853 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6854 | AStmt); |
| 6855 | } |
| 6856 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6857 | StmtResult |
| 6858 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6859 | SourceLocation StartLoc, |
| 6860 | SourceLocation EndLoc) { |
| 6861 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 6862 | // At least one map clause must appear on the directive. |
| 6863 | if (!HasMapClause(Clauses)) { |
| 6864 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6865 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 6866 | return StmtError(); |
| 6867 | } |
| 6868 | |
| 6869 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 6870 | Clauses); |
| 6871 | } |
| 6872 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 6873 | StmtResult |
| 6874 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6875 | SourceLocation StartLoc, |
| 6876 | SourceLocation EndLoc) { |
| 6877 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 6878 | // At least one map clause must appear on the directive. |
| 6879 | if (!HasMapClause(Clauses)) { |
| 6880 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6881 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 6882 | return StmtError(); |
| 6883 | } |
| 6884 | |
| 6885 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6886 | } |
| 6887 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6888 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 6889 | SourceLocation StartLoc, |
| 6890 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6891 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6892 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6893 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6894 | seenMotionClause = true; |
| 6895 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 6896 | if (!seenMotionClause) { |
| 6897 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 6898 | return StmtError(); |
| 6899 | } |
| 6900 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6901 | } |
| 6902 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6903 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6904 | Stmt *AStmt, SourceLocation StartLoc, |
| 6905 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6906 | if (!AStmt) |
| 6907 | return StmtError(); |
| 6908 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6909 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6910 | // 1.2.2 OpenMP Language Terminology |
| 6911 | // Structured block - An executable statement with a single entry at the |
| 6912 | // top and a single exit at the bottom. |
| 6913 | // The point of exit cannot be a branch out of the structured block. |
| 6914 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6915 | CS->getCapturedDecl()->setNothrow(); |
| 6916 | |
| 6917 | getCurFunction()->setHasBranchProtectedScope(); |
| 6918 | |
| 6919 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6920 | } |
| 6921 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 6922 | StmtResult |
| 6923 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 6924 | SourceLocation EndLoc, |
| 6925 | OpenMPDirectiveKind CancelRegion) { |
| 6926 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6927 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6928 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6929 | << getOpenMPDirectiveName(CancelRegion); |
| 6930 | return StmtError(); |
| 6931 | } |
| 6932 | if (DSAStack->isParentNowaitRegion()) { |
| 6933 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 6934 | return StmtError(); |
| 6935 | } |
| 6936 | if (DSAStack->isParentOrderedRegion()) { |
| 6937 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 6938 | return StmtError(); |
| 6939 | } |
| 6940 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 6941 | CancelRegion); |
| 6942 | } |
| 6943 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6944 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 6945 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6946 | SourceLocation EndLoc, |
| 6947 | OpenMPDirectiveKind CancelRegion) { |
| 6948 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 6949 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 6950 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 6951 | << getOpenMPDirectiveName(CancelRegion); |
| 6952 | return StmtError(); |
| 6953 | } |
| 6954 | if (DSAStack->isParentNowaitRegion()) { |
| 6955 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 6956 | return StmtError(); |
| 6957 | } |
| 6958 | if (DSAStack->isParentOrderedRegion()) { |
| 6959 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 6960 | return StmtError(); |
| 6961 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6962 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 6963 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6964 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 6965 | } |
| 6966 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6967 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 6968 | ArrayRef<OMPClause *> Clauses) { |
| 6969 | OMPClause *PrevClause = nullptr; |
| 6970 | bool ErrorFound = false; |
| 6971 | for (auto *C : Clauses) { |
| 6972 | if (C->getClauseKind() == OMPC_grainsize || |
| 6973 | C->getClauseKind() == OMPC_num_tasks) { |
| 6974 | if (!PrevClause) |
| 6975 | PrevClause = C; |
| 6976 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 6977 | S.Diag(C->getLocStart(), |
| 6978 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 6979 | << getOpenMPClauseName(C->getClauseKind()) |
| 6980 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6981 | S.Diag(PrevClause->getLocStart(), |
| 6982 | diag::note_omp_previous_grainsize_num_tasks) |
| 6983 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6984 | ErrorFound = true; |
| 6985 | } |
| 6986 | } |
| 6987 | } |
| 6988 | return ErrorFound; |
| 6989 | } |
| 6990 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6991 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6992 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6993 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6994 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6995 | if (!AStmt) |
| 6996 | return StmtError(); |
| 6997 | |
| 6998 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6999 | OMPLoopDirective::HelperExprs B; |
| 7000 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7001 | // define the nested loops number. |
| 7002 | unsigned NestedLoopCount = |
| 7003 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7004 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7005 | VarsWithImplicitDSA, B); |
| 7006 | if (NestedLoopCount == 0) |
| 7007 | return StmtError(); |
| 7008 | |
| 7009 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7010 | "omp for loop exprs were not built"); |
| 7011 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7012 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7013 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7014 | // not appear on the same taskloop directive. |
| 7015 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7016 | return StmtError(); |
| 7017 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7018 | getCurFunction()->setHasBranchProtectedScope(); |
| 7019 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 7020 | NestedLoopCount, Clauses, AStmt, B); |
| 7021 | } |
| 7022 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7023 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 7024 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7025 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7026 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7027 | if (!AStmt) |
| 7028 | return StmtError(); |
| 7029 | |
| 7030 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7031 | OMPLoopDirective::HelperExprs B; |
| 7032 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7033 | // define the nested loops number. |
| 7034 | unsigned NestedLoopCount = |
| 7035 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 7036 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 7037 | VarsWithImplicitDSA, B); |
| 7038 | if (NestedLoopCount == 0) |
| 7039 | return StmtError(); |
| 7040 | |
| 7041 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7042 | "omp for loop exprs were not built"); |
| 7043 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7044 | if (!CurContext->isDependentContext()) { |
| 7045 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7046 | for (auto C : Clauses) { |
| 7047 | if (auto LC = dyn_cast<OMPLinearClause>(C)) |
| 7048 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7049 | B.NumIterations, *this, CurScope, |
| 7050 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7051 | return StmtError(); |
| 7052 | } |
| 7053 | } |
| 7054 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7055 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7056 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7057 | // not appear on the same taskloop directive. |
| 7058 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7059 | return StmtError(); |
| 7060 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7061 | getCurFunction()->setHasBranchProtectedScope(); |
| 7062 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7063 | NestedLoopCount, Clauses, AStmt, B); |
| 7064 | } |
| 7065 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7066 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 7067 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7068 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7069 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7070 | if (!AStmt) |
| 7071 | return StmtError(); |
| 7072 | |
| 7073 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7074 | OMPLoopDirective::HelperExprs B; |
| 7075 | // In presence of clause 'collapse' with number of loops, it will |
| 7076 | // define the nested loops number. |
| 7077 | unsigned NestedLoopCount = |
| 7078 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 7079 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7080 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7081 | if (NestedLoopCount == 0) |
| 7082 | return StmtError(); |
| 7083 | |
| 7084 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7085 | "omp for loop exprs were not built"); |
| 7086 | |
| 7087 | getCurFunction()->setHasBranchProtectedScope(); |
| 7088 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 7089 | NestedLoopCount, Clauses, AStmt, B); |
| 7090 | } |
| 7091 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7092 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 7093 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7094 | SourceLocation EndLoc, |
| 7095 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7096 | if (!AStmt) |
| 7097 | return StmtError(); |
| 7098 | |
| 7099 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7100 | // 1.2.2 OpenMP Language Terminology |
| 7101 | // Structured block - An executable statement with a single entry at the |
| 7102 | // top and a single exit at the bottom. |
| 7103 | // The point of exit cannot be a branch out of the structured block. |
| 7104 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7105 | CS->getCapturedDecl()->setNothrow(); |
| 7106 | |
| 7107 | OMPLoopDirective::HelperExprs B; |
| 7108 | // In presence of clause 'collapse' with number of loops, it will |
| 7109 | // define the nested loops number. |
| 7110 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7111 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 7112 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 7113 | VarsWithImplicitDSA, B); |
| 7114 | if (NestedLoopCount == 0) |
| 7115 | return StmtError(); |
| 7116 | |
| 7117 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7118 | "omp for loop exprs were not built"); |
| 7119 | |
| 7120 | getCurFunction()->setHasBranchProtectedScope(); |
| 7121 | return OMPDistributeParallelForDirective::Create( |
| 7122 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7123 | } |
| 7124 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7125 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 7126 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7127 | SourceLocation EndLoc, |
| 7128 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7129 | if (!AStmt) |
| 7130 | return StmtError(); |
| 7131 | |
| 7132 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7133 | // 1.2.2 OpenMP Language Terminology |
| 7134 | // Structured block - An executable statement with a single entry at the |
| 7135 | // top and a single exit at the bottom. |
| 7136 | // The point of exit cannot be a branch out of the structured block. |
| 7137 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7138 | CS->getCapturedDecl()->setNothrow(); |
| 7139 | |
| 7140 | OMPLoopDirective::HelperExprs B; |
| 7141 | // In presence of clause 'collapse' with number of loops, it will |
| 7142 | // define the nested loops number. |
| 7143 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7144 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 7145 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 7146 | VarsWithImplicitDSA, B); |
| 7147 | if (NestedLoopCount == 0) |
| 7148 | return StmtError(); |
| 7149 | |
| 7150 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7151 | "omp for loop exprs were not built"); |
| 7152 | |
| 7153 | getCurFunction()->setHasBranchProtectedScope(); |
| 7154 | return OMPDistributeParallelForSimdDirective::Create( |
| 7155 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7156 | } |
| 7157 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame^] | 7158 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 7159 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7160 | SourceLocation EndLoc, |
| 7161 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7162 | if (!AStmt) |
| 7163 | return StmtError(); |
| 7164 | |
| 7165 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7166 | // 1.2.2 OpenMP Language Terminology |
| 7167 | // Structured block - An executable statement with a single entry at the |
| 7168 | // top and a single exit at the bottom. |
| 7169 | // The point of exit cannot be a branch out of the structured block. |
| 7170 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7171 | CS->getCapturedDecl()->setNothrow(); |
| 7172 | |
| 7173 | OMPLoopDirective::HelperExprs B; |
| 7174 | // In presence of clause 'collapse' with number of loops, it will |
| 7175 | // define the nested loops number. |
| 7176 | unsigned NestedLoopCount = |
| 7177 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 7178 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7179 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7180 | if (NestedLoopCount == 0) |
| 7181 | return StmtError(); |
| 7182 | |
| 7183 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7184 | "omp for loop exprs were not built"); |
| 7185 | |
| 7186 | getCurFunction()->setHasBranchProtectedScope(); |
| 7187 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7188 | NestedLoopCount, Clauses, AStmt, B); |
| 7189 | } |
| 7190 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7191 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7192 | SourceLocation StartLoc, |
| 7193 | SourceLocation LParenLoc, |
| 7194 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7195 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7196 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7197 | case OMPC_final: |
| 7198 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7199 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7200 | case OMPC_num_threads: |
| 7201 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7202 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7203 | case OMPC_safelen: |
| 7204 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7205 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7206 | case OMPC_simdlen: |
| 7207 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7208 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7209 | case OMPC_collapse: |
| 7210 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7211 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7212 | case OMPC_ordered: |
| 7213 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 7214 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7215 | case OMPC_device: |
| 7216 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7217 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7218 | case OMPC_num_teams: |
| 7219 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7220 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7221 | case OMPC_thread_limit: |
| 7222 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7223 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7224 | case OMPC_priority: |
| 7225 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7226 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7227 | case OMPC_grainsize: |
| 7228 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7229 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7230 | case OMPC_num_tasks: |
| 7231 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7232 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7233 | case OMPC_hint: |
| 7234 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7235 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7236 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7237 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7238 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7239 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7240 | case OMPC_private: |
| 7241 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7242 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7243 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7244 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7245 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7246 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7247 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7248 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7249 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7250 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7251 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7252 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7253 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7254 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7255 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7256 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7257 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7258 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7259 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7260 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7261 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7262 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7263 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7264 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7265 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7266 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7267 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7268 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7269 | case OMPC_from: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7270 | llvm_unreachable("Clause is not allowed."); |
| 7271 | } |
| 7272 | return Res; |
| 7273 | } |
| 7274 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7275 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 7276 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7277 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7278 | SourceLocation NameModifierLoc, |
| 7279 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7280 | SourceLocation EndLoc) { |
| 7281 | Expr *ValExpr = Condition; |
| 7282 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7283 | !Condition->isInstantiationDependent() && |
| 7284 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7285 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7286 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7287 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7288 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7289 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7290 | } |
| 7291 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7292 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 7293 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7294 | } |
| 7295 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7296 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 7297 | SourceLocation StartLoc, |
| 7298 | SourceLocation LParenLoc, |
| 7299 | SourceLocation EndLoc) { |
| 7300 | Expr *ValExpr = Condition; |
| 7301 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7302 | !Condition->isInstantiationDependent() && |
| 7303 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7304 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7305 | if (Val.isInvalid()) |
| 7306 | return nullptr; |
| 7307 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7308 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7309 | } |
| 7310 | |
| 7311 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7312 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7313 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 7314 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7315 | if (!Op) |
| 7316 | return ExprError(); |
| 7317 | |
| 7318 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 7319 | public: |
| 7320 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7321 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 7322 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 7323 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7324 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 7325 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7326 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 7327 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7328 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 7329 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7330 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 7331 | QualType T, |
| 7332 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7333 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 7334 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7335 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 7336 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7337 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7338 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7339 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7340 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 7341 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7342 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 7343 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7344 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 7345 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7346 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7347 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7348 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7349 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 7350 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7351 | llvm_unreachable("conversion functions are permitted"); |
| 7352 | } |
| 7353 | } ConvertDiagnoser; |
| 7354 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 7355 | } |
| 7356 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7357 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7358 | OpenMPClauseKind CKind, |
| 7359 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7360 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7361 | !ValExpr->isInstantiationDependent()) { |
| 7362 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7363 | ExprResult Value = |
| 7364 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7365 | if (Value.isInvalid()) |
| 7366 | return false; |
| 7367 | |
| 7368 | ValExpr = Value.get(); |
| 7369 | // The expression must evaluate to a non-negative integer value. |
| 7370 | llvm::APSInt Result; |
| 7371 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7372 | Result.isSigned() && |
| 7373 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 7374 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7375 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7376 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7377 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7378 | return false; |
| 7379 | } |
| 7380 | } |
| 7381 | return true; |
| 7382 | } |
| 7383 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7384 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 7385 | SourceLocation StartLoc, |
| 7386 | SourceLocation LParenLoc, |
| 7387 | SourceLocation EndLoc) { |
| 7388 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7389 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7390 | // OpenMP [2.5, Restrictions] |
| 7391 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7392 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 7393 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7394 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7395 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7396 | return new (Context) |
| 7397 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7398 | } |
| 7399 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7400 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7401 | OpenMPClauseKind CKind, |
| 7402 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7403 | if (!E) |
| 7404 | return ExprError(); |
| 7405 | if (E->isValueDependent() || E->isTypeDependent() || |
| 7406 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7407 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7408 | llvm::APSInt Result; |
| 7409 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 7410 | if (ICE.isInvalid()) |
| 7411 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7412 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 7413 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7414 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7415 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7416 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7417 | return ExprError(); |
| 7418 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 7419 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 7420 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 7421 | << E->getSourceRange(); |
| 7422 | return ExprError(); |
| 7423 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7424 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 7425 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7426 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7427 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7428 | return ICE; |
| 7429 | } |
| 7430 | |
| 7431 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 7432 | SourceLocation LParenLoc, |
| 7433 | SourceLocation EndLoc) { |
| 7434 | // OpenMP [2.8.1, simd construct, Description] |
| 7435 | // The parameter of the safelen clause must be a constant |
| 7436 | // positive integer expression. |
| 7437 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 7438 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7439 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7440 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7441 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7442 | } |
| 7443 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7444 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 7445 | SourceLocation LParenLoc, |
| 7446 | SourceLocation EndLoc) { |
| 7447 | // OpenMP [2.8.1, simd construct, Description] |
| 7448 | // The parameter of the simdlen clause must be a constant |
| 7449 | // positive integer expression. |
| 7450 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 7451 | if (Simdlen.isInvalid()) |
| 7452 | return nullptr; |
| 7453 | return new (Context) |
| 7454 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 7455 | } |
| 7456 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7457 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 7458 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7459 | SourceLocation LParenLoc, |
| 7460 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7461 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7462 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7463 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7464 | // The parameter of the collapse clause must be a constant |
| 7465 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7466 | ExprResult NumForLoopsResult = |
| 7467 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 7468 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7469 | return nullptr; |
| 7470 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7471 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7472 | } |
| 7473 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7474 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 7475 | SourceLocation EndLoc, |
| 7476 | SourceLocation LParenLoc, |
| 7477 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7478 | // OpenMP [2.7.1, loop construct, Description] |
| 7479 | // OpenMP [2.8.1, simd construct, Description] |
| 7480 | // OpenMP [2.9.6, distribute construct, Description] |
| 7481 | // The parameter of the ordered clause must be a constant |
| 7482 | // positive integer expression if any. |
| 7483 | if (NumForLoops && LParenLoc.isValid()) { |
| 7484 | ExprResult NumForLoopsResult = |
| 7485 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 7486 | if (NumForLoopsResult.isInvalid()) |
| 7487 | return nullptr; |
| 7488 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7489 | } else |
| 7490 | NumForLoops = nullptr; |
| 7491 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7492 | return new (Context) |
| 7493 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 7494 | } |
| 7495 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7496 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 7497 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 7498 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7499 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7500 | switch (Kind) { |
| 7501 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7502 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7503 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 7504 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7505 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7506 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7507 | Res = ActOnOpenMPProcBindClause( |
| 7508 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 7509 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7510 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7511 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7512 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7513 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7514 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7515 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7516 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7517 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7518 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7519 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7520 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7521 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7522 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7523 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7524 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7525 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7526 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7527 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7528 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7529 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7530 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7531 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7532 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7533 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7534 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7535 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7536 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7537 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7538 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7539 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7540 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7541 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7542 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7543 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7544 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7545 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7546 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7547 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7548 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7549 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7550 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7551 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7552 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7553 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7554 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7555 | case OMPC_from: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7556 | llvm_unreachable("Clause is not allowed."); |
| 7557 | } |
| 7558 | return Res; |
| 7559 | } |
| 7560 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7561 | static std::string |
| 7562 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 7563 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 7564 | std::string Values; |
| 7565 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 7566 | unsigned Skipped = Exclude.size(); |
| 7567 | auto S = Exclude.begin(), E = Exclude.end(); |
| 7568 | for (unsigned i = First; i < Last; ++i) { |
| 7569 | if (std::find(S, E, i) != E) { |
| 7570 | --Skipped; |
| 7571 | continue; |
| 7572 | } |
| 7573 | Values += "'"; |
| 7574 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 7575 | Values += "'"; |
| 7576 | if (i == Bound - Skipped) |
| 7577 | Values += " or "; |
| 7578 | else if (i != Bound + 1 - Skipped) |
| 7579 | Values += ", "; |
| 7580 | } |
| 7581 | return Values; |
| 7582 | } |
| 7583 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7584 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7585 | SourceLocation KindKwLoc, |
| 7586 | SourceLocation StartLoc, |
| 7587 | SourceLocation LParenLoc, |
| 7588 | SourceLocation EndLoc) { |
| 7589 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7590 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7591 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7592 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7593 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7594 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7595 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7596 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7597 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7598 | switch (Kind) { |
| 7599 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7600 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7601 | break; |
| 7602 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7603 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7604 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7605 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7606 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7607 | break; |
| 7608 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7609 | return new (Context) |
| 7610 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7611 | } |
| 7612 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7613 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7614 | SourceLocation KindKwLoc, |
| 7615 | SourceLocation StartLoc, |
| 7616 | SourceLocation LParenLoc, |
| 7617 | SourceLocation EndLoc) { |
| 7618 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7619 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7620 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7621 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7622 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7623 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7624 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7625 | return new (Context) |
| 7626 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7627 | } |
| 7628 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7629 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7630 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7631 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7632 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7633 | SourceLocation EndLoc) { |
| 7634 | OMPClause *Res = nullptr; |
| 7635 | switch (Kind) { |
| 7636 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7637 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7638 | assert(Argument.size() == NumberOfElements && |
| 7639 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7640 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7641 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7642 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7643 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7644 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7645 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7646 | break; |
| 7647 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7648 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7649 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7650 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7651 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7652 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7653 | case OMPC_dist_schedule: |
| 7654 | Res = ActOnOpenMPDistScheduleClause( |
| 7655 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7656 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7657 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7658 | case OMPC_defaultmap: |
| 7659 | enum { Modifier, DefaultmapKind }; |
| 7660 | Res = ActOnOpenMPDefaultmapClause( |
| 7661 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7662 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
| 7663 | StartLoc, LParenLoc, ArgumentLoc[Modifier], |
| 7664 | ArgumentLoc[DefaultmapKind], EndLoc); |
| 7665 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7666 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7667 | case OMPC_num_threads: |
| 7668 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7669 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7670 | case OMPC_collapse: |
| 7671 | case OMPC_default: |
| 7672 | case OMPC_proc_bind: |
| 7673 | case OMPC_private: |
| 7674 | case OMPC_firstprivate: |
| 7675 | case OMPC_lastprivate: |
| 7676 | case OMPC_shared: |
| 7677 | case OMPC_reduction: |
| 7678 | case OMPC_linear: |
| 7679 | case OMPC_aligned: |
| 7680 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7681 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7682 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7683 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7684 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7685 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7686 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7687 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7688 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7689 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7690 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7691 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7692 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7693 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7694 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7695 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7696 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7697 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7698 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7699 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7700 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7701 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7702 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7703 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7704 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7705 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7706 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7707 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7708 | case OMPC_from: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7709 | llvm_unreachable("Clause is not allowed."); |
| 7710 | } |
| 7711 | return Res; |
| 7712 | } |
| 7713 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7714 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7715 | OpenMPScheduleClauseModifier M2, |
| 7716 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7717 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7718 | SmallVector<unsigned, 2> Excluded; |
| 7719 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7720 | Excluded.push_back(M2); |
| 7721 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7722 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7723 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7724 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7725 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7726 | << getListOfPossibleValues(OMPC_schedule, |
| 7727 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7728 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7729 | Excluded) |
| 7730 | << getOpenMPClauseName(OMPC_schedule); |
| 7731 | return true; |
| 7732 | } |
| 7733 | return false; |
| 7734 | } |
| 7735 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7736 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7737 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7738 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7739 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7740 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7741 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7742 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7743 | return nullptr; |
| 7744 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7745 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7746 | // but not both. |
| 7747 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7748 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7749 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7750 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7751 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7752 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7753 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7754 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7755 | return nullptr; |
| 7756 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7757 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7758 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7759 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7760 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7761 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7762 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7763 | Exclude); |
| 7764 | } else { |
| 7765 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7766 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7767 | } |
| 7768 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7769 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7770 | return nullptr; |
| 7771 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7772 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7773 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7774 | // schedule(guided). |
| 7775 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7776 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7777 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7778 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7779 | diag::err_omp_schedule_nonmonotonic_static); |
| 7780 | return nullptr; |
| 7781 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7782 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7783 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7784 | if (ChunkSize) { |
| 7785 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7786 | !ChunkSize->isInstantiationDependent() && |
| 7787 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7788 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7789 | ExprResult Val = |
| 7790 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7791 | if (Val.isInvalid()) |
| 7792 | return nullptr; |
| 7793 | |
| 7794 | ValExpr = Val.get(); |
| 7795 | |
| 7796 | // OpenMP [2.7.1, Restrictions] |
| 7797 | // chunk_size must be a loop invariant integer expression with a positive |
| 7798 | // value. |
| 7799 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7800 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7801 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7802 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7803 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7804 | return nullptr; |
| 7805 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7806 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7807 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7808 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7809 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7810 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7811 | } |
| 7812 | } |
| 7813 | } |
| 7814 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7815 | return new (Context) |
| 7816 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7817 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7818 | } |
| 7819 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7820 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7821 | SourceLocation StartLoc, |
| 7822 | SourceLocation EndLoc) { |
| 7823 | OMPClause *Res = nullptr; |
| 7824 | switch (Kind) { |
| 7825 | case OMPC_ordered: |
| 7826 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7827 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7828 | case OMPC_nowait: |
| 7829 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7830 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7831 | case OMPC_untied: |
| 7832 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7833 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7834 | case OMPC_mergeable: |
| 7835 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7836 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7837 | case OMPC_read: |
| 7838 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7839 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7840 | case OMPC_write: |
| 7841 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7842 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7843 | case OMPC_update: |
| 7844 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7845 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7846 | case OMPC_capture: |
| 7847 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7848 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7849 | case OMPC_seq_cst: |
| 7850 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7851 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7852 | case OMPC_threads: |
| 7853 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7854 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7855 | case OMPC_simd: |
| 7856 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7857 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7858 | case OMPC_nogroup: |
| 7859 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7860 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7861 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7862 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7863 | case OMPC_num_threads: |
| 7864 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7865 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7866 | case OMPC_collapse: |
| 7867 | case OMPC_schedule: |
| 7868 | case OMPC_private: |
| 7869 | case OMPC_firstprivate: |
| 7870 | case OMPC_lastprivate: |
| 7871 | case OMPC_shared: |
| 7872 | case OMPC_reduction: |
| 7873 | case OMPC_linear: |
| 7874 | case OMPC_aligned: |
| 7875 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7876 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7877 | case OMPC_default: |
| 7878 | case OMPC_proc_bind: |
| 7879 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7880 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7881 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7882 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7883 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7884 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7885 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7886 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7887 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7888 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7889 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7890 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7891 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7892 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7893 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7894 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7895 | case OMPC_from: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7896 | llvm_unreachable("Clause is not allowed."); |
| 7897 | } |
| 7898 | return Res; |
| 7899 | } |
| 7900 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7901 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7902 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7903 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7904 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7905 | } |
| 7906 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7907 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7908 | SourceLocation EndLoc) { |
| 7909 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7910 | } |
| 7911 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7912 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7913 | SourceLocation EndLoc) { |
| 7914 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7915 | } |
| 7916 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7917 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7918 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7919 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7920 | } |
| 7921 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7922 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7923 | SourceLocation EndLoc) { |
| 7924 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7925 | } |
| 7926 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7927 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7928 | SourceLocation EndLoc) { |
| 7929 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7930 | } |
| 7931 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7932 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7933 | SourceLocation EndLoc) { |
| 7934 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7935 | } |
| 7936 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7937 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7938 | SourceLocation EndLoc) { |
| 7939 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7940 | } |
| 7941 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7942 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7943 | SourceLocation EndLoc) { |
| 7944 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7945 | } |
| 7946 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7947 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7948 | SourceLocation EndLoc) { |
| 7949 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7950 | } |
| 7951 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7952 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7953 | SourceLocation EndLoc) { |
| 7954 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7955 | } |
| 7956 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7957 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7958 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7959 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7960 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7961 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7962 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7963 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7964 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7965 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7966 | switch (Kind) { |
| 7967 | case OMPC_private: |
| 7968 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7969 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7970 | case OMPC_firstprivate: |
| 7971 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7972 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7973 | case OMPC_lastprivate: |
| 7974 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7975 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7976 | case OMPC_shared: |
| 7977 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7978 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7979 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7980 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7981 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7982 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7983 | case OMPC_linear: |
| 7984 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7985 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7986 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7987 | case OMPC_aligned: |
| 7988 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7989 | ColonLoc, EndLoc); |
| 7990 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7991 | case OMPC_copyin: |
| 7992 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7993 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7994 | case OMPC_copyprivate: |
| 7995 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7996 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7997 | case OMPC_flush: |
| 7998 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7999 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8000 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8001 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
| 8002 | StartLoc, LParenLoc, EndLoc); |
| 8003 | break; |
| 8004 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8005 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 8006 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 8007 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8008 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8009 | case OMPC_to: |
| 8010 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8011 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8012 | case OMPC_from: |
| 8013 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8014 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8015 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8016 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8017 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8018 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8019 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8020 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8021 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8022 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8023 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8024 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8025 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8026 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8027 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8028 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8029 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8030 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8031 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8032 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8033 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8034 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8035 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8036 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8037 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8038 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8039 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8040 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8041 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8042 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8043 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8044 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8045 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8046 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8047 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8048 | llvm_unreachable("Clause is not allowed."); |
| 8049 | } |
| 8050 | return Res; |
| 8051 | } |
| 8052 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8053 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8054 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8055 | ExprResult Res = BuildDeclRefExpr( |
| 8056 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 8057 | if (!Res.isUsable()) |
| 8058 | return ExprError(); |
| 8059 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 8060 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 8061 | if (!Res.isUsable()) |
| 8062 | return ExprError(); |
| 8063 | } |
| 8064 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 8065 | Res = DefaultLvalueConversion(Res.get()); |
| 8066 | if (!Res.isUsable()) |
| 8067 | return ExprError(); |
| 8068 | } |
| 8069 | return Res; |
| 8070 | } |
| 8071 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8072 | static std::pair<ValueDecl *, bool> |
| 8073 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 8074 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8075 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 8076 | RefExpr->containsUnexpandedParameterPack()) |
| 8077 | return std::make_pair(nullptr, true); |
| 8078 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8079 | // OpenMP [3.1, C/C++] |
| 8080 | // A list item is a variable name. |
| 8081 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 8082 | // A variable that is part of another variable (as an array or |
| 8083 | // structure element) cannot appear in a private clause. |
| 8084 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8085 | enum { |
| 8086 | NoArrayExpr = -1, |
| 8087 | ArraySubscript = 0, |
| 8088 | OMPArraySection = 1 |
| 8089 | } IsArrayExpr = NoArrayExpr; |
| 8090 | if (AllowArraySection) { |
| 8091 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 8092 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 8093 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8094 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8095 | RefExpr = Base; |
| 8096 | IsArrayExpr = ArraySubscript; |
| 8097 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 8098 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 8099 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 8100 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 8101 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8102 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8103 | RefExpr = Base; |
| 8104 | IsArrayExpr = OMPArraySection; |
| 8105 | } |
| 8106 | } |
| 8107 | ELoc = RefExpr->getExprLoc(); |
| 8108 | ERange = RefExpr->getSourceRange(); |
| 8109 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8110 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 8111 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 8112 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 8113 | (S.getCurrentThisType().isNull() || !ME || |
| 8114 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 8115 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8116 | if (IsArrayExpr != NoArrayExpr) |
| 8117 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 8118 | << ERange; |
| 8119 | else { |
| 8120 | S.Diag(ELoc, |
| 8121 | AllowArraySection |
| 8122 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 8123 | : diag::err_omp_expected_var_name_member_expr) |
| 8124 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 8125 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8126 | return std::make_pair(nullptr, false); |
| 8127 | } |
| 8128 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 8129 | } |
| 8130 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8131 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 8132 | SourceLocation StartLoc, |
| 8133 | SourceLocation LParenLoc, |
| 8134 | SourceLocation EndLoc) { |
| 8135 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8136 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8137 | for (auto &RefExpr : VarList) { |
| 8138 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8139 | SourceLocation ELoc; |
| 8140 | SourceRange ERange; |
| 8141 | Expr *SimpleRefExpr = RefExpr; |
| 8142 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8143 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8144 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8145 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8146 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8147 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8148 | ValueDecl *D = Res.first; |
| 8149 | if (!D) |
| 8150 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8151 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8152 | QualType Type = D->getType(); |
| 8153 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8154 | |
| 8155 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8156 | // A variable that appears in a private clause must not have an incomplete |
| 8157 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8158 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8159 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8160 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8161 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8162 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8163 | // in a Construct] |
| 8164 | // Variables with the predetermined data-sharing attributes may not be |
| 8165 | // listed in data-sharing attributes clauses, except for the cases |
| 8166 | // listed below. For these exceptions only, listing a predetermined |
| 8167 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8168 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8169 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8170 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8171 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8172 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8173 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8174 | continue; |
| 8175 | } |
| 8176 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8177 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8178 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8179 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8180 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8181 | << getOpenMPClauseName(OMPC_private) << Type |
| 8182 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8183 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8184 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8185 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8186 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8187 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8188 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8189 | continue; |
| 8190 | } |
| 8191 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8192 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8193 | // A list item cannot appear in both a map clause and a data-sharing |
| 8194 | // attribute clause on the same construct |
| 8195 | if (DSAStack->getCurrentDirective() == OMPD_target) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8196 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| 8197 | VD, /* CurrentRegionOnly = */ true, |
| 8198 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) |
| 8199 | -> bool { return true; })) { |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8200 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 8201 | << getOpenMPClauseName(OMPC_private) |
| 8202 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8203 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8204 | continue; |
| 8205 | } |
| 8206 | } |
| 8207 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8208 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 8209 | // A variable of class type (or array thereof) that appears in a private |
| 8210 | // clause requires an accessible, unambiguous default constructor for the |
| 8211 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8212 | // Generate helper private variable and initialize it with the default |
| 8213 | // value. The address of the original variable is replaced by the address of |
| 8214 | // the new private variable in CodeGen. This new variable is not added to |
| 8215 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 8216 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8217 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8218 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8219 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8220 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8221 | if (VDPrivate->isInvalidDecl()) |
| 8222 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8223 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8224 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8225 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8226 | DeclRefExpr *Ref = nullptr; |
| 8227 | if (!VD) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8228 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8229 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
| 8230 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8231 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8232 | } |
| 8233 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8234 | if (Vars.empty()) |
| 8235 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8236 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8237 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8238 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8239 | } |
| 8240 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8241 | namespace { |
| 8242 | class DiagsUninitializedSeveretyRAII { |
| 8243 | private: |
| 8244 | DiagnosticsEngine &Diags; |
| 8245 | SourceLocation SavedLoc; |
| 8246 | bool IsIgnored; |
| 8247 | |
| 8248 | public: |
| 8249 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 8250 | bool IsIgnored) |
| 8251 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 8252 | if (!IsIgnored) { |
| 8253 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 8254 | /*Map*/ diag::Severity::Ignored, Loc); |
| 8255 | } |
| 8256 | } |
| 8257 | ~DiagsUninitializedSeveretyRAII() { |
| 8258 | if (!IsIgnored) |
| 8259 | Diags.popMappings(SavedLoc); |
| 8260 | } |
| 8261 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 8262 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8263 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8264 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 8265 | SourceLocation StartLoc, |
| 8266 | SourceLocation LParenLoc, |
| 8267 | SourceLocation EndLoc) { |
| 8268 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8269 | SmallVector<Expr *, 8> PrivateCopies; |
| 8270 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8271 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8272 | bool IsImplicitClause = |
| 8273 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 8274 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 8275 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8276 | for (auto &RefExpr : VarList) { |
| 8277 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8278 | SourceLocation ELoc; |
| 8279 | SourceRange ERange; |
| 8280 | Expr *SimpleRefExpr = RefExpr; |
| 8281 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8282 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8283 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8284 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8285 | PrivateCopies.push_back(nullptr); |
| 8286 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8287 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8288 | ValueDecl *D = Res.first; |
| 8289 | if (!D) |
| 8290 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8291 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8292 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8293 | QualType Type = D->getType(); |
| 8294 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8295 | |
| 8296 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8297 | // A variable that appears in a private clause must not have an incomplete |
| 8298 | // type or a reference type. |
| 8299 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8300 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8301 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8302 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8303 | |
| 8304 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 8305 | // 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] | 8306 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8307 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8308 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8309 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8310 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8311 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8312 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8313 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8314 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8315 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8316 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 8317 | // A list item that specifies a given variable may not appear in more |
| 8318 | // than one clause on the same directive, except that a variable may be |
| 8319 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8320 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8321 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8322 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8323 | << getOpenMPClauseName(DVar.CKind) |
| 8324 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8325 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8326 | continue; |
| 8327 | } |
| 8328 | |
| 8329 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8330 | // in a Construct] |
| 8331 | // Variables with the predetermined data-sharing attributes may not be |
| 8332 | // listed in data-sharing attributes clauses, except for the cases |
| 8333 | // listed below. For these exceptions only, listing a predetermined |
| 8334 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8335 | // the variable's predetermined data-sharing attributes. |
| 8336 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8337 | // in a Construct, C/C++, p.2] |
| 8338 | // Variables with const-qualified type having no mutable member may be |
| 8339 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8340 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8341 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 8342 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8343 | << getOpenMPClauseName(DVar.CKind) |
| 8344 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8345 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8346 | continue; |
| 8347 | } |
| 8348 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8349 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8350 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 8351 | // A list item that is private within a parallel region must not appear |
| 8352 | // in a firstprivate clause on a worksharing construct if any of the |
| 8353 | // worksharing regions arising from the worksharing construct ever bind |
| 8354 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8355 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8356 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8357 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8358 | if (DVar.CKind != OMPC_shared && |
| 8359 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8360 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8361 | Diag(ELoc, diag::err_omp_required_access) |
| 8362 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8363 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8364 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8365 | continue; |
| 8366 | } |
| 8367 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8368 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 8369 | // A list item that appears in a reduction clause of a parallel construct |
| 8370 | // must not appear in a firstprivate clause on a worksharing or task |
| 8371 | // construct if any of the worksharing or task regions arising from the |
| 8372 | // worksharing or task construct ever bind to any of the parallel regions |
| 8373 | // arising from the parallel construct. |
| 8374 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 8375 | // A list item that appears in a reduction clause in worksharing |
| 8376 | // construct must not appear in a firstprivate clause in a task construct |
| 8377 | // encountered during execution of any of the worksharing regions arising |
| 8378 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8379 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8380 | DVar = DSAStack->hasInnermostDSA( |
| 8381 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8382 | [](OpenMPDirectiveKind K) -> bool { |
| 8383 | return isOpenMPParallelDirective(K) || |
| 8384 | isOpenMPWorksharingDirective(K); |
| 8385 | }, |
| 8386 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8387 | if (DVar.CKind == OMPC_reduction && |
| 8388 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8389 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 8390 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 8391 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8392 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8393 | continue; |
| 8394 | } |
| 8395 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8396 | |
| 8397 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8398 | // A list item that is private within a teams region must not appear in a |
| 8399 | // firstprivate clause on a distribute construct if any of the distribute |
| 8400 | // regions arising from the distribute construct ever bind to any of the |
| 8401 | // teams regions arising from the teams construct. |
| 8402 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8403 | // A list item that appears in a reduction clause of a teams construct |
| 8404 | // must not appear in a firstprivate clause on a distribute construct if |
| 8405 | // any of the distribute regions arising from the distribute construct |
| 8406 | // ever bind to any of the teams regions arising from the teams construct. |
| 8407 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8408 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8409 | // both. |
| 8410 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8411 | DVar = DSAStack->hasInnermostDSA( |
| 8412 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 8413 | [](OpenMPDirectiveKind K) -> bool { |
| 8414 | return isOpenMPTeamsDirective(K); |
| 8415 | }, |
| 8416 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8417 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 8418 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8419 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8420 | continue; |
| 8421 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8422 | DVar = DSAStack->hasInnermostDSA( |
| 8423 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8424 | [](OpenMPDirectiveKind K) -> bool { |
| 8425 | return isOpenMPTeamsDirective(K); |
| 8426 | }, |
| 8427 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8428 | if (DVar.CKind == OMPC_reduction && |
| 8429 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 8430 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8431 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8432 | continue; |
| 8433 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8434 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8435 | if (DVar.CKind == OMPC_lastprivate) { |
| 8436 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8437 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8438 | continue; |
| 8439 | } |
| 8440 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8441 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8442 | // A list item cannot appear in both a map clause and a data-sharing |
| 8443 | // attribute clause on the same construct |
| 8444 | if (CurrDir == OMPD_target) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8445 | if (DSAStack->checkMappableExprComponentListsForDecl( |
| 8446 | VD, /* CurrentRegionOnly = */ true, |
| 8447 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef) |
| 8448 | -> bool { return true; })) { |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8449 | Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 8450 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8451 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8452 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8453 | continue; |
| 8454 | } |
| 8455 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8456 | } |
| 8457 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8458 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8459 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8460 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8461 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8462 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 8463 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8464 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8465 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8466 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8467 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8468 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8469 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8470 | continue; |
| 8471 | } |
| 8472 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8473 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8474 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8475 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8476 | // Generate helper private variable and initialize it with the value of the |
| 8477 | // original variable. The address of the original variable is replaced by |
| 8478 | // the address of the new private variable in the CodeGen. This new variable |
| 8479 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 8480 | // original variable for proper diagnostics and variable capturing. |
| 8481 | Expr *VDInitRefExpr = nullptr; |
| 8482 | // For arrays generate initializer for single element and replace it by the |
| 8483 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8484 | if (Type->isArrayType()) { |
| 8485 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8486 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8487 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8488 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8489 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8490 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8491 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8492 | InitializedEntity Entity = |
| 8493 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8494 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 8495 | |
| 8496 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 8497 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 8498 | if (Result.isInvalid()) |
| 8499 | VDPrivate->setInvalidDecl(); |
| 8500 | else |
| 8501 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8502 | // Remove temp variable declaration. |
| 8503 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8504 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8505 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 8506 | ".firstprivate.temp"); |
| 8507 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 8508 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8509 | AddInitializerToDecl(VDPrivate, |
| 8510 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 8511 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8512 | } |
| 8513 | if (VDPrivate->isInvalidDecl()) { |
| 8514 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8515 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8516 | diag::note_omp_task_predetermined_firstprivate_here); |
| 8517 | } |
| 8518 | continue; |
| 8519 | } |
| 8520 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8521 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8522 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 8523 | RefExpr->getExprLoc()); |
| 8524 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8525 | if (!VD) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8526 | if (TopDVar.CKind == OMPC_lastprivate) |
| 8527 | Ref = TopDVar.PrivateCopy; |
| 8528 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8529 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8530 | if (!IsOpenMPCapturedDecl(D)) |
| 8531 | ExprCaptures.push_back(Ref->getDecl()); |
| 8532 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8533 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8534 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 8535 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8536 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 8537 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8538 | } |
| 8539 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8540 | if (Vars.empty()) |
| 8541 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8542 | |
| 8543 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8544 | Vars, PrivateCopies, Inits, |
| 8545 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8546 | } |
| 8547 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8548 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 8549 | SourceLocation StartLoc, |
| 8550 | SourceLocation LParenLoc, |
| 8551 | SourceLocation EndLoc) { |
| 8552 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8553 | SmallVector<Expr *, 8> SrcExprs; |
| 8554 | SmallVector<Expr *, 8> DstExprs; |
| 8555 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8556 | SmallVector<Decl *, 4> ExprCaptures; |
| 8557 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8558 | for (auto &RefExpr : VarList) { |
| 8559 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8560 | SourceLocation ELoc; |
| 8561 | SourceRange ERange; |
| 8562 | Expr *SimpleRefExpr = RefExpr; |
| 8563 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8564 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8565 | // It will be analyzed later. |
| 8566 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8567 | SrcExprs.push_back(nullptr); |
| 8568 | DstExprs.push_back(nullptr); |
| 8569 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8570 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8571 | ValueDecl *D = Res.first; |
| 8572 | if (!D) |
| 8573 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8574 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8575 | QualType Type = D->getType(); |
| 8576 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8577 | |
| 8578 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 8579 | // A variable that appears in a lastprivate clause must not have an |
| 8580 | // incomplete type or a reference type. |
| 8581 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8582 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8583 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8584 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8585 | |
| 8586 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8587 | // in a Construct] |
| 8588 | // Variables with the predetermined data-sharing attributes may not be |
| 8589 | // listed in data-sharing attributes clauses, except for the cases |
| 8590 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8591 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8592 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 8593 | DVar.CKind != OMPC_firstprivate && |
| 8594 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 8595 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8596 | << getOpenMPClauseName(DVar.CKind) |
| 8597 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8598 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8599 | continue; |
| 8600 | } |
| 8601 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8602 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8603 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8604 | // A list item that is private within a parallel region, or that appears in |
| 8605 | // the reduction clause of a parallel construct, must not appear in a |
| 8606 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8607 | // worksharing regions ever binds to any of the corresponding parallel |
| 8608 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8609 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8610 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8611 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8612 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8613 | if (DVar.CKind != OMPC_shared) { |
| 8614 | Diag(ELoc, diag::err_omp_required_access) |
| 8615 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8616 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8617 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8618 | continue; |
| 8619 | } |
| 8620 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8621 | |
| 8622 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8623 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8624 | // both. |
| 8625 | if (CurrDir == OMPD_distribute) { |
| 8626 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8627 | if (DVar.CKind == OMPC_firstprivate) { |
| 8628 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8629 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8630 | continue; |
| 8631 | } |
| 8632 | } |
| 8633 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8634 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8635 | // A variable of class type (or array thereof) that appears in a |
| 8636 | // lastprivate clause requires an accessible, unambiguous default |
| 8637 | // constructor for the class type, unless the list item is also specified |
| 8638 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8639 | // A variable of class type (or array thereof) that appears in a |
| 8640 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8641 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8642 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8643 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8644 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8645 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8646 | auto *PseudoSrcExpr = |
| 8647 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8648 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8649 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8650 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8651 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8652 | // For arrays generate assignment operation for single element and replace |
| 8653 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8654 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8655 | PseudoDstExpr, PseudoSrcExpr); |
| 8656 | if (AssignmentOp.isInvalid()) |
| 8657 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8658 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8659 | /*DiscardedValue=*/true); |
| 8660 | if (AssignmentOp.isInvalid()) |
| 8661 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8662 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8663 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8664 | if (!VD) { |
| 8665 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8666 | Ref = TopDVar.PrivateCopy; |
| 8667 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8668 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8669 | if (!IsOpenMPCapturedDecl(D)) |
| 8670 | ExprCaptures.push_back(Ref->getDecl()); |
| 8671 | } |
| 8672 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8673 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8674 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8675 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8676 | if (!RefRes.isUsable()) |
| 8677 | continue; |
| 8678 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8679 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8680 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8681 | if (!PostUpdateRes.isUsable()) |
| 8682 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8683 | ExprPostUpdates.push_back( |
| 8684 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8685 | } |
| 8686 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8687 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8688 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8689 | SrcExprs.push_back(PseudoSrcExpr); |
| 8690 | DstExprs.push_back(PseudoDstExpr); |
| 8691 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8692 | } |
| 8693 | |
| 8694 | if (Vars.empty()) |
| 8695 | return nullptr; |
| 8696 | |
| 8697 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8698 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8699 | buildPreInits(Context, ExprCaptures), |
| 8700 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8701 | } |
| 8702 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8703 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8704 | SourceLocation StartLoc, |
| 8705 | SourceLocation LParenLoc, |
| 8706 | SourceLocation EndLoc) { |
| 8707 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8708 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8709 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8710 | SourceLocation ELoc; |
| 8711 | SourceRange ERange; |
| 8712 | Expr *SimpleRefExpr = RefExpr; |
| 8713 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8714 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8715 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8716 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8717 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8718 | ValueDecl *D = Res.first; |
| 8719 | if (!D) |
| 8720 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8721 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8722 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8723 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8724 | // in a Construct] |
| 8725 | // Variables with the predetermined data-sharing attributes may not be |
| 8726 | // listed in data-sharing attributes clauses, except for the cases |
| 8727 | // listed below. For these exceptions only, listing a predetermined |
| 8728 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8729 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8730 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8731 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8732 | DVar.RefExpr) { |
| 8733 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8734 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8735 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8736 | continue; |
| 8737 | } |
| 8738 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8739 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8740 | if (!VD && IsOpenMPCapturedDecl(D)) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8741 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8742 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 8743 | Vars.push_back((VD || !Ref) ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8744 | } |
| 8745 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8746 | if (Vars.empty()) |
| 8747 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8748 | |
| 8749 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8750 | } |
| 8751 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8752 | namespace { |
| 8753 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8754 | DSAStackTy *Stack; |
| 8755 | |
| 8756 | public: |
| 8757 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8758 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8759 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8760 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8761 | return false; |
| 8762 | if (DVar.CKind != OMPC_unknown) |
| 8763 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8764 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8765 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 8766 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8767 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8768 | return true; |
| 8769 | return false; |
| 8770 | } |
| 8771 | return false; |
| 8772 | } |
| 8773 | bool VisitStmt(Stmt *S) { |
| 8774 | for (auto Child : S->children()) { |
| 8775 | if (Child && Visit(Child)) |
| 8776 | return true; |
| 8777 | } |
| 8778 | return false; |
| 8779 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8780 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8781 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8782 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8783 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8784 | namespace { |
| 8785 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8786 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8787 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8788 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8789 | ValueDecl *Field; |
| 8790 | DeclRefExpr *CapturedExpr; |
| 8791 | |
| 8792 | public: |
| 8793 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8794 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8795 | |
| 8796 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8797 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8798 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8799 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8800 | return CapturedExpr; |
| 8801 | } |
| 8802 | return BaseTransform::TransformMemberExpr(E); |
| 8803 | } |
| 8804 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8805 | }; |
| 8806 | } // namespace |
| 8807 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8808 | template <typename T> |
| 8809 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8810 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8811 | for (auto &Set : Lookups) { |
| 8812 | for (auto *D : Set) { |
| 8813 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8814 | return Res; |
| 8815 | } |
| 8816 | } |
| 8817 | return T(); |
| 8818 | } |
| 8819 | |
| 8820 | static ExprResult |
| 8821 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8822 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8823 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8824 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8825 | if (ReductionIdScopeSpec.isInvalid()) |
| 8826 | return ExprError(); |
| 8827 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8828 | if (S) { |
| 8829 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8830 | Lookup.suppressDiagnostics(); |
| 8831 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8832 | auto *D = Lookup.getRepresentativeDecl(); |
| 8833 | do { |
| 8834 | S = S->getParent(); |
| 8835 | } while (S && !S->isDeclScope(D)); |
| 8836 | if (S) |
| 8837 | S = S->getParent(); |
| 8838 | Lookups.push_back(UnresolvedSet<8>()); |
| 8839 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8840 | Lookup.clear(); |
| 8841 | } |
| 8842 | } else if (auto *ULE = |
| 8843 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8844 | Lookups.push_back(UnresolvedSet<8>()); |
| 8845 | Decl *PrevD = nullptr; |
| 8846 | for(auto *D : ULE->decls()) { |
| 8847 | if (D == PrevD) |
| 8848 | Lookups.push_back(UnresolvedSet<8>()); |
| 8849 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8850 | Lookups.back().addDecl(DRD); |
| 8851 | PrevD = D; |
| 8852 | } |
| 8853 | } |
| 8854 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8855 | Ty->containsUnexpandedParameterPack() || |
| 8856 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8857 | return !D->isInvalidDecl() && |
| 8858 | (D->getType()->isDependentType() || |
| 8859 | D->getType()->isInstantiationDependentType() || |
| 8860 | D->getType()->containsUnexpandedParameterPack()); |
| 8861 | })) { |
| 8862 | UnresolvedSet<8> ResSet; |
| 8863 | for (auto &Set : Lookups) { |
| 8864 | ResSet.append(Set.begin(), Set.end()); |
| 8865 | // The last item marks the end of all declarations at the specified scope. |
| 8866 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8867 | } |
| 8868 | return UnresolvedLookupExpr::Create( |
| 8869 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8870 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8871 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8872 | } |
| 8873 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8874 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8875 | if (!D->isInvalidDecl() && |
| 8876 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8877 | return D; |
| 8878 | return nullptr; |
| 8879 | })) |
| 8880 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8881 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8882 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8883 | if (!D->isInvalidDecl() && |
| 8884 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8885 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8886 | return D; |
| 8887 | return nullptr; |
| 8888 | })) { |
| 8889 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8890 | /*DetectVirtual=*/false); |
| 8891 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8892 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8893 | VD->getType().getUnqualifiedType()))) { |
| 8894 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8895 | /*DiagID=*/0) != |
| 8896 | Sema::AR_inaccessible) { |
| 8897 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8898 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8899 | } |
| 8900 | } |
| 8901 | } |
| 8902 | } |
| 8903 | if (ReductionIdScopeSpec.isSet()) { |
| 8904 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8905 | return ExprError(); |
| 8906 | } |
| 8907 | return ExprEmpty(); |
| 8908 | } |
| 8909 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8910 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 8911 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 8912 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8913 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 8914 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8915 | auto DN = ReductionId.getName(); |
| 8916 | auto OOK = DN.getCXXOverloadedOperator(); |
| 8917 | BinaryOperatorKind BOK = BO_Comma; |
| 8918 | |
| 8919 | // OpenMP [2.14.3.6, reduction clause] |
| 8920 | // C |
| 8921 | // reduction-identifier is either an identifier or one of the following |
| 8922 | // operators: +, -, *, &, |, ^, && and || |
| 8923 | // C++ |
| 8924 | // reduction-identifier is either an id-expression or one of the following |
| 8925 | // operators: +, -, *, &, |, ^, && and || |
| 8926 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8927 | switch (OOK) { |
| 8928 | case OO_Plus: |
| 8929 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8930 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8931 | break; |
| 8932 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8933 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8934 | break; |
| 8935 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8936 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8937 | break; |
| 8938 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8939 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8940 | break; |
| 8941 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8942 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8943 | break; |
| 8944 | case OO_AmpAmp: |
| 8945 | BOK = BO_LAnd; |
| 8946 | break; |
| 8947 | case OO_PipePipe: |
| 8948 | BOK = BO_LOr; |
| 8949 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8950 | case OO_New: |
| 8951 | case OO_Delete: |
| 8952 | case OO_Array_New: |
| 8953 | case OO_Array_Delete: |
| 8954 | case OO_Slash: |
| 8955 | case OO_Percent: |
| 8956 | case OO_Tilde: |
| 8957 | case OO_Exclaim: |
| 8958 | case OO_Equal: |
| 8959 | case OO_Less: |
| 8960 | case OO_Greater: |
| 8961 | case OO_LessEqual: |
| 8962 | case OO_GreaterEqual: |
| 8963 | case OO_PlusEqual: |
| 8964 | case OO_MinusEqual: |
| 8965 | case OO_StarEqual: |
| 8966 | case OO_SlashEqual: |
| 8967 | case OO_PercentEqual: |
| 8968 | case OO_CaretEqual: |
| 8969 | case OO_AmpEqual: |
| 8970 | case OO_PipeEqual: |
| 8971 | case OO_LessLess: |
| 8972 | case OO_GreaterGreater: |
| 8973 | case OO_LessLessEqual: |
| 8974 | case OO_GreaterGreaterEqual: |
| 8975 | case OO_EqualEqual: |
| 8976 | case OO_ExclaimEqual: |
| 8977 | case OO_PlusPlus: |
| 8978 | case OO_MinusMinus: |
| 8979 | case OO_Comma: |
| 8980 | case OO_ArrowStar: |
| 8981 | case OO_Arrow: |
| 8982 | case OO_Call: |
| 8983 | case OO_Subscript: |
| 8984 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8985 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8986 | case NUM_OVERLOADED_OPERATORS: |
| 8987 | llvm_unreachable("Unexpected reduction identifier"); |
| 8988 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8989 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8990 | if (II->isStr("max")) |
| 8991 | BOK = BO_GT; |
| 8992 | else if (II->isStr("min")) |
| 8993 | BOK = BO_LT; |
| 8994 | } |
| 8995 | break; |
| 8996 | } |
| 8997 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8998 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8999 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9000 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9001 | |
| 9002 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9003 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9004 | SmallVector<Expr *, 8> LHSs; |
| 9005 | SmallVector<Expr *, 8> RHSs; |
| 9006 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9007 | SmallVector<Decl *, 4> ExprCaptures; |
| 9008 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9009 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 9010 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9011 | for (auto RefExpr : VarList) { |
| 9012 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9013 | // OpenMP [2.1, C/C++] |
| 9014 | // A list item is a variable or array section, subject to the restrictions |
| 9015 | // specified in Section 2.4 on page 42 and in each of the sections |
| 9016 | // describing clauses and directives for which a list appears. |
| 9017 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 9018 | // A variable that is part of another variable (as an array or |
| 9019 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9020 | if (!FirstIter && IR != ER) |
| 9021 | ++IR; |
| 9022 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9023 | SourceLocation ELoc; |
| 9024 | SourceRange ERange; |
| 9025 | Expr *SimpleRefExpr = RefExpr; |
| 9026 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9027 | /*AllowArraySection=*/true); |
| 9028 | if (Res.second) { |
| 9029 | // It will be analyzed later. |
| 9030 | Vars.push_back(RefExpr); |
| 9031 | Privates.push_back(nullptr); |
| 9032 | LHSs.push_back(nullptr); |
| 9033 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9034 | // Try to find 'declare reduction' corresponding construct before using |
| 9035 | // builtin/overloaded operators. |
| 9036 | QualType Type = Context.DependentTy; |
| 9037 | CXXCastPath BasePath; |
| 9038 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9039 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9040 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9041 | if (CurContext->isDependentContext() && |
| 9042 | (DeclareReductionRef.isUnset() || |
| 9043 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 9044 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9045 | else |
| 9046 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9047 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9048 | ValueDecl *D = Res.first; |
| 9049 | if (!D) |
| 9050 | continue; |
| 9051 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9052 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9053 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 9054 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 9055 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9056 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9057 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9058 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 9059 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 9060 | Type = ATy->getElementType(); |
| 9061 | else |
| 9062 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9063 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9064 | } else |
| 9065 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 9066 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9067 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9068 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9069 | // A variable that appears in a private clause must not have an incomplete |
| 9070 | // type or a reference type. |
| 9071 | if (RequireCompleteType(ELoc, Type, |
| 9072 | diag::err_omp_reduction_incomplete_type)) |
| 9073 | continue; |
| 9074 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9075 | // A list item that appears in a reduction clause must not be |
| 9076 | // const-qualified. |
| 9077 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9078 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9079 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9080 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9081 | bool IsDecl = !VD || |
| 9082 | VD->isThisDeclarationADefinition(Context) == |
| 9083 | VarDecl::DeclarationOnly; |
| 9084 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9085 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9086 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9087 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9088 | continue; |
| 9089 | } |
| 9090 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 9091 | // If a list-item is a reference type then it must bind to the same object |
| 9092 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9093 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9094 | VarDecl *VDDef = VD->getDefinition(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9095 | if (VD->getType()->isReferenceType() && VDDef) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9096 | DSARefChecker Check(DSAStack); |
| 9097 | if (Check.Visit(VDDef->getInit())) { |
| 9098 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 9099 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 9100 | continue; |
| 9101 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9102 | } |
| 9103 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9104 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9105 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9106 | // in a Construct] |
| 9107 | // Variables with the predetermined data-sharing attributes may not be |
| 9108 | // listed in data-sharing attributes clauses, except for the cases |
| 9109 | // listed below. For these exceptions only, listing a predetermined |
| 9110 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9111 | // the variable's predetermined data-sharing attributes. |
| 9112 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 9113 | // Any number of reduction clauses can be specified on the directive, |
| 9114 | // but a list item can appear only once in the reduction clauses for that |
| 9115 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9116 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9117 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9118 | if (DVar.CKind == OMPC_reduction) { |
| 9119 | Diag(ELoc, diag::err_omp_once_referenced) |
| 9120 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9121 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9122 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9123 | } else if (DVar.CKind != OMPC_unknown) { |
| 9124 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9125 | << getOpenMPClauseName(DVar.CKind) |
| 9126 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9127 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9128 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9129 | } |
| 9130 | |
| 9131 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 9132 | // A list item that appears in a reduction clause of a worksharing |
| 9133 | // construct must be shared in the parallel regions to which any of the |
| 9134 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9135 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 9136 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 9137 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9138 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9139 | if (DVar.CKind != OMPC_shared) { |
| 9140 | Diag(ELoc, diag::err_omp_required_access) |
| 9141 | << getOpenMPClauseName(OMPC_reduction) |
| 9142 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9143 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9144 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9145 | } |
| 9146 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9147 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9148 | // Try to find 'declare reduction' corresponding construct before using |
| 9149 | // builtin/overloaded operators. |
| 9150 | CXXCastPath BasePath; |
| 9151 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9152 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9153 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9154 | if (DeclareReductionRef.isInvalid()) |
| 9155 | continue; |
| 9156 | if (CurContext->isDependentContext() && |
| 9157 | (DeclareReductionRef.isUnset() || |
| 9158 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 9159 | Vars.push_back(RefExpr); |
| 9160 | Privates.push_back(nullptr); |
| 9161 | LHSs.push_back(nullptr); |
| 9162 | RHSs.push_back(nullptr); |
| 9163 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9164 | continue; |
| 9165 | } |
| 9166 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 9167 | // Not allowed reduction identifier is found. |
| 9168 | Diag(ReductionId.getLocStart(), |
| 9169 | diag::err_omp_unknown_reduction_identifier) |
| 9170 | << Type << ReductionIdRange; |
| 9171 | continue; |
| 9172 | } |
| 9173 | |
| 9174 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 9175 | // The type of a list item that appears in a reduction clause must be valid |
| 9176 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 9177 | // of the list item must be an allowed arithmetic data type: char, int, |
| 9178 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 9179 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 9180 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 9181 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 9182 | if (DeclareReductionRef.isUnset()) { |
| 9183 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 9184 | !(Type->isScalarType() || |
| 9185 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 9186 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 9187 | << getLangOpts().CPlusPlus; |
| 9188 | if (!ASE && !OASE) { |
| 9189 | bool IsDecl = !VD || |
| 9190 | VD->isThisDeclarationADefinition(Context) == |
| 9191 | VarDecl::DeclarationOnly; |
| 9192 | Diag(D->getLocation(), |
| 9193 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9194 | << D; |
| 9195 | } |
| 9196 | continue; |
| 9197 | } |
| 9198 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 9199 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 9200 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 9201 | if (!ASE && !OASE) { |
| 9202 | bool IsDecl = !VD || |
| 9203 | VD->isThisDeclarationADefinition(Context) == |
| 9204 | VarDecl::DeclarationOnly; |
| 9205 | Diag(D->getLocation(), |
| 9206 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9207 | << D; |
| 9208 | } |
| 9209 | continue; |
| 9210 | } |
| 9211 | } |
| 9212 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9213 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9214 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9215 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9216 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9217 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9218 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9219 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9220 | (!ASE && |
| 9221 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9222 | // For arays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9223 | // Create pseudo array type for private copy. The size for this array will |
| 9224 | // be generated during codegen. |
| 9225 | // For array subscripts or single variables Private Ty is the same as Type |
| 9226 | // (type of the variable or single array element). |
| 9227 | PrivateTy = Context.getVariableArrayType( |
| 9228 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 9229 | Context.getSizeType(), VK_RValue), |
| 9230 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9231 | } else if (!ASE && !OASE && |
| 9232 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 9233 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9234 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9235 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 9236 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9237 | // Add initializer for private variable. |
| 9238 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9239 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 9240 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 9241 | if (DeclareReductionRef.isUsable()) { |
| 9242 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 9243 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 9244 | if (DRD->getInitializer()) { |
| 9245 | Init = DRDRef; |
| 9246 | RHSVD->setInit(DRDRef); |
| 9247 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9248 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9249 | } else { |
| 9250 | switch (BOK) { |
| 9251 | case BO_Add: |
| 9252 | case BO_Xor: |
| 9253 | case BO_Or: |
| 9254 | case BO_LOr: |
| 9255 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 9256 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 9257 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 9258 | break; |
| 9259 | case BO_Mul: |
| 9260 | case BO_LAnd: |
| 9261 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 9262 | // '*' and '&&' reduction ops - initializer is '1'. |
| 9263 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9264 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9265 | break; |
| 9266 | case BO_And: { |
| 9267 | // '&' reduction op - initializer is '~0'. |
| 9268 | QualType OrigType = Type; |
| 9269 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 9270 | Type = ComplexTy->getElementType(); |
| 9271 | if (Type->isRealFloatingType()) { |
| 9272 | llvm::APFloat InitValue = |
| 9273 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 9274 | /*isIEEE=*/true); |
| 9275 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9276 | Type, ELoc); |
| 9277 | } else if (Type->isScalarType()) { |
| 9278 | auto Size = Context.getTypeSize(Type); |
| 9279 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 9280 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 9281 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9282 | } |
| 9283 | if (Init && OrigType->isAnyComplexType()) { |
| 9284 | // Init = 0xFFFF + 0xFFFFi; |
| 9285 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 9286 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 9287 | } |
| 9288 | Type = OrigType; |
| 9289 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9290 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9291 | case BO_LT: |
| 9292 | case BO_GT: { |
| 9293 | // 'min' reduction op - initializer is 'Largest representable number in |
| 9294 | // the reduction list item type'. |
| 9295 | // 'max' reduction op - initializer is 'Least representable number in |
| 9296 | // the reduction list item type'. |
| 9297 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 9298 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 9299 | auto Size = Context.getTypeSize(Type); |
| 9300 | QualType IntTy = |
| 9301 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 9302 | llvm::APInt InitValue = |
| 9303 | (BOK != BO_LT) |
| 9304 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 9305 | : llvm::APInt::getMinValue(Size) |
| 9306 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 9307 | : llvm::APInt::getMaxValue(Size); |
| 9308 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9309 | if (Type->isPointerType()) { |
| 9310 | // Cast to pointer type. |
| 9311 | auto CastExpr = BuildCStyleCastExpr( |
| 9312 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 9313 | SourceLocation(), Init); |
| 9314 | if (CastExpr.isInvalid()) |
| 9315 | continue; |
| 9316 | Init = CastExpr.get(); |
| 9317 | } |
| 9318 | } else if (Type->isRealFloatingType()) { |
| 9319 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 9320 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 9321 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9322 | Type, ELoc); |
| 9323 | } |
| 9324 | break; |
| 9325 | } |
| 9326 | case BO_PtrMemD: |
| 9327 | case BO_PtrMemI: |
| 9328 | case BO_MulAssign: |
| 9329 | case BO_Div: |
| 9330 | case BO_Rem: |
| 9331 | case BO_Sub: |
| 9332 | case BO_Shl: |
| 9333 | case BO_Shr: |
| 9334 | case BO_LE: |
| 9335 | case BO_GE: |
| 9336 | case BO_EQ: |
| 9337 | case BO_NE: |
| 9338 | case BO_AndAssign: |
| 9339 | case BO_XorAssign: |
| 9340 | case BO_OrAssign: |
| 9341 | case BO_Assign: |
| 9342 | case BO_AddAssign: |
| 9343 | case BO_SubAssign: |
| 9344 | case BO_DivAssign: |
| 9345 | case BO_RemAssign: |
| 9346 | case BO_ShlAssign: |
| 9347 | case BO_ShrAssign: |
| 9348 | case BO_Comma: |
| 9349 | llvm_unreachable("Unexpected reduction operation"); |
| 9350 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9351 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9352 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9353 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 9354 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9355 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9356 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9357 | if (RHSVD->isInvalidDecl()) |
| 9358 | continue; |
| 9359 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9360 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 9361 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9362 | bool IsDecl = |
| 9363 | !VD || |
| 9364 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9365 | Diag(D->getLocation(), |
| 9366 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9367 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9368 | continue; |
| 9369 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9370 | // Store initializer for single element in private copy. Will be used during |
| 9371 | // codegen. |
| 9372 | PrivateVD->setInit(RHSVD->getInit()); |
| 9373 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9374 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9375 | ExprResult ReductionOp; |
| 9376 | if (DeclareReductionRef.isUsable()) { |
| 9377 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 9378 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 9379 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 9380 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 9381 | if (!BasePath.empty()) { |
| 9382 | LHS = DefaultLvalueConversion(LHS.get()); |
| 9383 | RHS = DefaultLvalueConversion(RHS.get()); |
| 9384 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9385 | CK_UncheckedDerivedToBase, LHS.get(), |
| 9386 | &BasePath, LHS.get()->getValueKind()); |
| 9387 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9388 | CK_UncheckedDerivedToBase, RHS.get(), |
| 9389 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9390 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9391 | FunctionProtoType::ExtProtoInfo EPI; |
| 9392 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 9393 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 9394 | auto *OVE = new (Context) OpaqueValueExpr( |
| 9395 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 9396 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 9397 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 9398 | ReductionOp = new (Context) |
| 9399 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 9400 | } else { |
| 9401 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 9402 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 9403 | if (ReductionOp.isUsable()) { |
| 9404 | if (BOK != BO_LT && BOK != BO_GT) { |
| 9405 | ReductionOp = |
| 9406 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9407 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 9408 | } else { |
| 9409 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 9410 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 9411 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 9412 | ReductionOp = |
| 9413 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9414 | BO_Assign, LHSDRE, ConditionalOp); |
| 9415 | } |
| 9416 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 9417 | } |
| 9418 | if (ReductionOp.isInvalid()) |
| 9419 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9420 | } |
| 9421 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9422 | DeclRefExpr *Ref = nullptr; |
| 9423 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
| 9424 | if (!VD) { |
| 9425 | if (ASE || OASE) { |
| 9426 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 9427 | VarsExpr = |
| 9428 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 9429 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9430 | } else { |
| 9431 | VarsExpr = Ref = |
| 9432 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9433 | } |
| 9434 | if (!IsOpenMPCapturedDecl(D)) { |
| 9435 | ExprCaptures.push_back(Ref->getDecl()); |
| 9436 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9437 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9438 | if (!RefRes.isUsable()) |
| 9439 | continue; |
| 9440 | ExprResult PostUpdateRes = |
| 9441 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9442 | SimpleRefExpr, RefRes.get()); |
| 9443 | if (!PostUpdateRes.isUsable()) |
| 9444 | continue; |
| 9445 | ExprPostUpdates.push_back( |
| 9446 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9447 | } |
| 9448 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9449 | } |
| 9450 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 9451 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9452 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9453 | LHSs.push_back(LHSDRE); |
| 9454 | RHSs.push_back(RHSDRE); |
| 9455 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9456 | } |
| 9457 | |
| 9458 | if (Vars.empty()) |
| 9459 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9460 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9461 | return OMPReductionClause::Create( |
| 9462 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9463 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9464 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 9465 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9466 | } |
| 9467 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9468 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 9469 | SourceLocation LinLoc) { |
| 9470 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 9471 | LinKind == OMPC_LINEAR_unknown) { |
| 9472 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 9473 | return true; |
| 9474 | } |
| 9475 | return false; |
| 9476 | } |
| 9477 | |
| 9478 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 9479 | OpenMPLinearClauseKind LinKind, |
| 9480 | QualType Type) { |
| 9481 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 9482 | // A variable must not have an incomplete type or a reference type. |
| 9483 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 9484 | return true; |
| 9485 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 9486 | !Type->isReferenceType()) { |
| 9487 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 9488 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 9489 | return true; |
| 9490 | } |
| 9491 | Type = Type.getNonReferenceType(); |
| 9492 | |
| 9493 | // A list item must not be const-qualified. |
| 9494 | if (Type.isConstant(Context)) { |
| 9495 | Diag(ELoc, diag::err_omp_const_variable) |
| 9496 | << getOpenMPClauseName(OMPC_linear); |
| 9497 | if (D) { |
| 9498 | bool IsDecl = |
| 9499 | !VD || |
| 9500 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9501 | Diag(D->getLocation(), |
| 9502 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9503 | << D; |
| 9504 | } |
| 9505 | return true; |
| 9506 | } |
| 9507 | |
| 9508 | // A list item must be of integral or pointer type. |
| 9509 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 9510 | const auto *Ty = Type.getTypePtrOrNull(); |
| 9511 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 9512 | !Ty->isPointerType())) { |
| 9513 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 9514 | if (D) { |
| 9515 | bool IsDecl = |
| 9516 | !VD || |
| 9517 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9518 | Diag(D->getLocation(), |
| 9519 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9520 | << D; |
| 9521 | } |
| 9522 | return true; |
| 9523 | } |
| 9524 | return false; |
| 9525 | } |
| 9526 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9527 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 9528 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 9529 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 9530 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9531 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9532 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9533 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9534 | SmallVector<Decl *, 4> ExprCaptures; |
| 9535 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9536 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9537 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9538 | for (auto &RefExpr : VarList) { |
| 9539 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9540 | SourceLocation ELoc; |
| 9541 | SourceRange ERange; |
| 9542 | Expr *SimpleRefExpr = RefExpr; |
| 9543 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9544 | /*AllowArraySection=*/false); |
| 9545 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9546 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9547 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9548 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9549 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9550 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9551 | ValueDecl *D = Res.first; |
| 9552 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9553 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9554 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9555 | QualType Type = D->getType(); |
| 9556 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9557 | |
| 9558 | // OpenMP [2.14.3.7, linear clause] |
| 9559 | // A list-item cannot appear in more than one linear clause. |
| 9560 | // A list-item that appears in a linear clause cannot appear in any |
| 9561 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9562 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9563 | if (DVar.RefExpr) { |
| 9564 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9565 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9566 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9567 | continue; |
| 9568 | } |
| 9569 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9570 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9571 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9572 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9573 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9574 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9575 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9576 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9577 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9578 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9579 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9580 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9581 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9582 | if (!VD) { |
| 9583 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 9584 | if (!IsOpenMPCapturedDecl(D)) { |
| 9585 | ExprCaptures.push_back(Ref->getDecl()); |
| 9586 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9587 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9588 | if (!RefRes.isUsable()) |
| 9589 | continue; |
| 9590 | ExprResult PostUpdateRes = |
| 9591 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9592 | SimpleRefExpr, RefRes.get()); |
| 9593 | if (!PostUpdateRes.isUsable()) |
| 9594 | continue; |
| 9595 | ExprPostUpdates.push_back( |
| 9596 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9597 | } |
| 9598 | } |
| 9599 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9600 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9601 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9602 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9603 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9604 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9605 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 9606 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9607 | |
| 9608 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
| 9609 | Vars.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9610 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9611 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9612 | } |
| 9613 | |
| 9614 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9615 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9616 | |
| 9617 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9618 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9619 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9620 | !Step->isInstantiationDependent() && |
| 9621 | !Step->containsUnexpandedParameterPack()) { |
| 9622 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9623 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9624 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9625 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9626 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9627 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9628 | // Build var to save the step value. |
| 9629 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9630 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9631 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9632 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9633 | ExprResult CalcStep = |
| 9634 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9635 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9636 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9637 | // Warn about zero linear step (it would be probably better specified as |
| 9638 | // making corresponding variables 'const'). |
| 9639 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9640 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9641 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9642 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9643 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9644 | if (!IsConstant && CalcStep.isUsable()) { |
| 9645 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9646 | // (This is not used if the number of iterations may be kfold-ed). |
| 9647 | CalcStepExpr = CalcStep.get(); |
| 9648 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9649 | } |
| 9650 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9651 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9652 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9653 | StepExpr, CalcStepExpr, |
| 9654 | buildPreInits(Context, ExprCaptures), |
| 9655 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9656 | } |
| 9657 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9658 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9659 | Expr *NumIterations, Sema &SemaRef, |
| 9660 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9661 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9662 | SmallVector<Expr *, 8> Updates; |
| 9663 | SmallVector<Expr *, 8> Finals; |
| 9664 | Expr *Step = Clause.getStep(); |
| 9665 | Expr *CalcStep = Clause.getCalcStep(); |
| 9666 | // OpenMP [2.14.3.7, linear clause] |
| 9667 | // If linear-step is not specified it is assumed to be 1. |
| 9668 | if (Step == nullptr) |
| 9669 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9670 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9671 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9672 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9673 | bool HasErrors = false; |
| 9674 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9675 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9676 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9677 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9678 | SourceLocation ELoc; |
| 9679 | SourceRange ERange; |
| 9680 | Expr *SimpleRefExpr = RefExpr; |
| 9681 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9682 | /*AllowArraySection=*/false); |
| 9683 | ValueDecl *D = Res.first; |
| 9684 | if (Res.second || !D) { |
| 9685 | Updates.push_back(nullptr); |
| 9686 | Finals.push_back(nullptr); |
| 9687 | HasErrors = true; |
| 9688 | continue; |
| 9689 | } |
| 9690 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9691 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9692 | ->getMemberDecl(); |
| 9693 | } |
| 9694 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9695 | Expr *InitExpr = *CurInit; |
| 9696 | |
| 9697 | // Build privatized reference to the current linear var. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9698 | auto DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9699 | Expr *CapturedRef; |
| 9700 | if (LinKind == OMPC_LINEAR_uval) |
| 9701 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9702 | else |
| 9703 | CapturedRef = |
| 9704 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9705 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9706 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9707 | |
| 9708 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9709 | ExprResult Update; |
| 9710 | if (!Info.first) { |
| 9711 | Update = |
| 9712 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9713 | InitExpr, IV, Step, /* Subtract */ false); |
| 9714 | } else |
| 9715 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9716 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9717 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9718 | |
| 9719 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9720 | ExprResult Final; |
| 9721 | if (!Info.first) { |
| 9722 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9723 | InitExpr, NumIterations, Step, |
| 9724 | /* Subtract */ false); |
| 9725 | } else |
| 9726 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9727 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9728 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9729 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9730 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9731 | Updates.push_back(nullptr); |
| 9732 | Finals.push_back(nullptr); |
| 9733 | HasErrors = true; |
| 9734 | } else { |
| 9735 | Updates.push_back(Update.get()); |
| 9736 | Finals.push_back(Final.get()); |
| 9737 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9738 | ++CurInit; |
| 9739 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9740 | } |
| 9741 | Clause.setUpdates(Updates); |
| 9742 | Clause.setFinals(Finals); |
| 9743 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9744 | } |
| 9745 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9746 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9747 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9748 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9749 | |
| 9750 | SmallVector<Expr *, 8> Vars; |
| 9751 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9752 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9753 | SourceLocation ELoc; |
| 9754 | SourceRange ERange; |
| 9755 | Expr *SimpleRefExpr = RefExpr; |
| 9756 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9757 | /*AllowArraySection=*/false); |
| 9758 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9759 | // It will be analyzed later. |
| 9760 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9761 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9762 | ValueDecl *D = Res.first; |
| 9763 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9764 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9765 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9766 | QualType QType = D->getType(); |
| 9767 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9768 | |
| 9769 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9770 | // The type of list items appearing in the aligned clause must be |
| 9771 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9772 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9773 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9774 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9775 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9776 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9777 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9778 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9779 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9780 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9781 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9782 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9783 | continue; |
| 9784 | } |
| 9785 | |
| 9786 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9787 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9788 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9789 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9790 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9791 | << getOpenMPClauseName(OMPC_aligned); |
| 9792 | continue; |
| 9793 | } |
| 9794 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9795 | DeclRefExpr *Ref = nullptr; |
| 9796 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9797 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9798 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9799 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9800 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9801 | } |
| 9802 | |
| 9803 | // OpenMP [2.8.1, simd construct, Description] |
| 9804 | // The parameter of the aligned clause, alignment, must be a constant |
| 9805 | // positive integer expression. |
| 9806 | // If no optional parameter is specified, implementation-defined default |
| 9807 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9808 | if (Alignment != nullptr) { |
| 9809 | ExprResult AlignResult = |
| 9810 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9811 | if (AlignResult.isInvalid()) |
| 9812 | return nullptr; |
| 9813 | Alignment = AlignResult.get(); |
| 9814 | } |
| 9815 | if (Vars.empty()) |
| 9816 | return nullptr; |
| 9817 | |
| 9818 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9819 | EndLoc, Vars, Alignment); |
| 9820 | } |
| 9821 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9822 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9823 | SourceLocation StartLoc, |
| 9824 | SourceLocation LParenLoc, |
| 9825 | SourceLocation EndLoc) { |
| 9826 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9827 | SmallVector<Expr *, 8> SrcExprs; |
| 9828 | SmallVector<Expr *, 8> DstExprs; |
| 9829 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9830 | for (auto &RefExpr : VarList) { |
| 9831 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 9832 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9833 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9834 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9835 | SrcExprs.push_back(nullptr); |
| 9836 | DstExprs.push_back(nullptr); |
| 9837 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9838 | continue; |
| 9839 | } |
| 9840 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9841 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9842 | // OpenMP [2.1, C/C++] |
| 9843 | // A list item is a variable name. |
| 9844 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 9845 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9846 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9847 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9848 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 9849 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9850 | continue; |
| 9851 | } |
| 9852 | |
| 9853 | Decl *D = DE->getDecl(); |
| 9854 | VarDecl *VD = cast<VarDecl>(D); |
| 9855 | |
| 9856 | QualType Type = VD->getType(); |
| 9857 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 9858 | // It will be analyzed later. |
| 9859 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9860 | SrcExprs.push_back(nullptr); |
| 9861 | DstExprs.push_back(nullptr); |
| 9862 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9863 | continue; |
| 9864 | } |
| 9865 | |
| 9866 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 9867 | // A list item that appears in a copyin clause must be threadprivate. |
| 9868 | if (!DSAStack->isThreadPrivate(VD)) { |
| 9869 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9870 | << getOpenMPClauseName(OMPC_copyin) |
| 9871 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9872 | continue; |
| 9873 | } |
| 9874 | |
| 9875 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9876 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9877 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9878 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9879 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9880 | auto *SrcVD = |
| 9881 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 9882 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9883 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9884 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 9885 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9886 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 9887 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9888 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9889 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9890 | // For arrays generate assignment operation for single element and replace |
| 9891 | // it by the original array element in CodeGen. |
| 9892 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 9893 | PseudoDstExpr, PseudoSrcExpr); |
| 9894 | if (AssignmentOp.isInvalid()) |
| 9895 | continue; |
| 9896 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 9897 | /*DiscardedValue=*/true); |
| 9898 | if (AssignmentOp.isInvalid()) |
| 9899 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9900 | |
| 9901 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 9902 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9903 | SrcExprs.push_back(PseudoSrcExpr); |
| 9904 | DstExprs.push_back(PseudoDstExpr); |
| 9905 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9906 | } |
| 9907 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9908 | if (Vars.empty()) |
| 9909 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9910 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9911 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9912 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9913 | } |
| 9914 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9915 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 9916 | SourceLocation StartLoc, |
| 9917 | SourceLocation LParenLoc, |
| 9918 | SourceLocation EndLoc) { |
| 9919 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9920 | SmallVector<Expr *, 8> SrcExprs; |
| 9921 | SmallVector<Expr *, 8> DstExprs; |
| 9922 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9923 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9924 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9925 | SourceLocation ELoc; |
| 9926 | SourceRange ERange; |
| 9927 | Expr *SimpleRefExpr = RefExpr; |
| 9928 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9929 | /*AllowArraySection=*/false); |
| 9930 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9931 | // It will be analyzed later. |
| 9932 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9933 | SrcExprs.push_back(nullptr); |
| 9934 | DstExprs.push_back(nullptr); |
| 9935 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9936 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9937 | ValueDecl *D = Res.first; |
| 9938 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9939 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9940 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9941 | QualType Type = D->getType(); |
| 9942 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9943 | |
| 9944 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 9945 | // A list item that appears in a copyprivate clause may not appear in a |
| 9946 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9947 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 9948 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9949 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 9950 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9951 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9952 | << getOpenMPClauseName(DVar.CKind) |
| 9953 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9954 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9955 | continue; |
| 9956 | } |
| 9957 | |
| 9958 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 9959 | // All list items that appear in a copyprivate clause must be either |
| 9960 | // threadprivate or private in the enclosing context. |
| 9961 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9962 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9963 | if (DVar.CKind == OMPC_shared) { |
| 9964 | Diag(ELoc, diag::err_omp_required_access) |
| 9965 | << getOpenMPClauseName(OMPC_copyprivate) |
| 9966 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9967 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9968 | continue; |
| 9969 | } |
| 9970 | } |
| 9971 | } |
| 9972 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9973 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9974 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9975 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9976 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9977 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9978 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9979 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9980 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9981 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9982 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9983 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9984 | continue; |
| 9985 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9986 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9987 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9988 | // A variable of class type (or array thereof) that appears in a |
| 9989 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9990 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9991 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9992 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9993 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9994 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9995 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9996 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9997 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9998 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9999 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10000 | auto *PseudoDstExpr = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10001 | buildDeclRefExpr(*this, DstVD, Type, ELoc); |
| 10002 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10003 | PseudoDstExpr, PseudoSrcExpr); |
| 10004 | if (AssignmentOp.isInvalid()) |
| 10005 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10006 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10007 | /*DiscardedValue=*/true); |
| 10008 | if (AssignmentOp.isInvalid()) |
| 10009 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10010 | |
| 10011 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 10012 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10013 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 10014 | Vars.push_back( |
| 10015 | VD ? RefExpr->IgnoreParens() |
| 10016 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10017 | SrcExprs.push_back(PseudoSrcExpr); |
| 10018 | DstExprs.push_back(PseudoDstExpr); |
| 10019 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10020 | } |
| 10021 | |
| 10022 | if (Vars.empty()) |
| 10023 | return nullptr; |
| 10024 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10025 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10026 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10027 | } |
| 10028 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 10029 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 10030 | SourceLocation StartLoc, |
| 10031 | SourceLocation LParenLoc, |
| 10032 | SourceLocation EndLoc) { |
| 10033 | if (VarList.empty()) |
| 10034 | return nullptr; |
| 10035 | |
| 10036 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 10037 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 10038 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10039 | OMPClause * |
| 10040 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 10041 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 10042 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10043 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10044 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10045 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10046 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10047 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10048 | return nullptr; |
| 10049 | } |
| 10050 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10051 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 10052 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10053 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10054 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10055 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 10056 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 10057 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10058 | return nullptr; |
| 10059 | } |
| 10060 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10061 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10062 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 10063 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 10064 | if (DepKind == OMPC_DEPEND_sink) { |
| 10065 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 10066 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 10067 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10068 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10069 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10070 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 10071 | DSAStack->getParentOrderedRegionParam()) { |
| 10072 | for (auto &RefExpr : VarList) { |
| 10073 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10074 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10075 | // It will be analyzed later. |
| 10076 | Vars.push_back(RefExpr); |
| 10077 | continue; |
| 10078 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10079 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10080 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 10081 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 10082 | if (DepKind == OMPC_DEPEND_sink) { |
| 10083 | if (DepCounter >= TotalDepCount) { |
| 10084 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 10085 | continue; |
| 10086 | } |
| 10087 | ++DepCounter; |
| 10088 | // OpenMP [2.13.9, Summary] |
| 10089 | // depend(dependence-type : vec), where dependence-type is: |
| 10090 | // 'sink' and where vec is the iteration vector, which has the form: |
| 10091 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 10092 | // where n is the value specified by the ordered clause in the loop |
| 10093 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 10094 | // loop associated with the loop directive, and di is a constant |
| 10095 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10096 | if (CurContext->isDependentContext()) { |
| 10097 | // It will be analyzed later. |
| 10098 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10099 | continue; |
| 10100 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10101 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 10102 | OverloadedOperatorKind OOK = OO_None; |
| 10103 | SourceLocation OOLoc; |
| 10104 | Expr *LHS = SimpleExpr; |
| 10105 | Expr *RHS = nullptr; |
| 10106 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 10107 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 10108 | OOLoc = BO->getOperatorLoc(); |
| 10109 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 10110 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 10111 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 10112 | OOK = OCE->getOperator(); |
| 10113 | OOLoc = OCE->getOperatorLoc(); |
| 10114 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10115 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 10116 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 10117 | OOK = MCE->getMethodDecl() |
| 10118 | ->getNameInfo() |
| 10119 | .getName() |
| 10120 | .getCXXOverloadedOperator(); |
| 10121 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 10122 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 10123 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10124 | } |
| 10125 | SourceLocation ELoc; |
| 10126 | SourceRange ERange; |
| 10127 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 10128 | /*AllowArraySection=*/false); |
| 10129 | if (Res.second) { |
| 10130 | // It will be analyzed later. |
| 10131 | Vars.push_back(RefExpr); |
| 10132 | } |
| 10133 | ValueDecl *D = Res.first; |
| 10134 | if (!D) |
| 10135 | continue; |
| 10136 | |
| 10137 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 10138 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 10139 | continue; |
| 10140 | } |
| 10141 | if (RHS) { |
| 10142 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 10143 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 10144 | if (RHSRes.isInvalid()) |
| 10145 | continue; |
| 10146 | } |
| 10147 | if (!CurContext->isDependentContext() && |
| 10148 | DSAStack->getParentOrderedRegionParam() && |
| 10149 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 10150 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10151 | << DSAStack->getParentLoopControlVariable( |
| 10152 | DepCounter.getZExtValue()); |
| 10153 | continue; |
| 10154 | } |
| 10155 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10156 | } else { |
| 10157 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 10158 | // A variable that is part of another variable (such as a field of a |
| 10159 | // structure) but is not an array element or an array section cannot |
| 10160 | // appear in a depend clause. |
| 10161 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 10162 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 10163 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 10164 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 10165 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10166 | (ASE && |
| 10167 | !ASE->getBase() |
| 10168 | ->getType() |
| 10169 | .getNonReferenceType() |
| 10170 | ->isPointerType() && |
| 10171 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10172 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 10173 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10174 | continue; |
| 10175 | } |
| 10176 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10177 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 10178 | } |
| 10179 | |
| 10180 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 10181 | TotalDepCount > VarList.size() && |
| 10182 | DSAStack->getParentOrderedRegionParam()) { |
| 10183 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10184 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 10185 | } |
| 10186 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 10187 | Vars.empty()) |
| 10188 | return nullptr; |
| 10189 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10190 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10191 | DepKind, DepLoc, ColonLoc, Vars); |
| 10192 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 10193 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 10194 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10195 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10196 | |
| 10197 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 10198 | SourceLocation LParenLoc, |
| 10199 | SourceLocation EndLoc) { |
| 10200 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10201 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10202 | // OpenMP [2.9.1, Restrictions] |
| 10203 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10204 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 10205 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10206 | return nullptr; |
| 10207 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10208 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10209 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10210 | |
| 10211 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 10212 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 10213 | if (!RD || RD->isInvalidDecl()) |
| 10214 | return true; |
| 10215 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 10216 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 10217 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 10218 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10219 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 10220 | if (RD->isDynamicClass()) { |
| 10221 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10222 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 10223 | return false; |
| 10224 | } |
| 10225 | auto *DC = RD; |
| 10226 | bool IsCorrect = true; |
| 10227 | for (auto *I : DC->decls()) { |
| 10228 | if (I) { |
| 10229 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 10230 | if (MD->isStatic()) { |
| 10231 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10232 | SemaRef.Diag(MD->getLocation(), |
| 10233 | diag::note_omp_static_member_in_target); |
| 10234 | IsCorrect = false; |
| 10235 | } |
| 10236 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 10237 | if (VD->isStaticDataMember()) { |
| 10238 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10239 | SemaRef.Diag(VD->getLocation(), |
| 10240 | diag::note_omp_static_member_in_target); |
| 10241 | IsCorrect = false; |
| 10242 | } |
| 10243 | } |
| 10244 | } |
| 10245 | } |
| 10246 | |
| 10247 | for (auto &I : RD->bases()) { |
| 10248 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 10249 | I.getType()->getAsCXXRecordDecl())) |
| 10250 | IsCorrect = false; |
| 10251 | } |
| 10252 | return IsCorrect; |
| 10253 | } |
| 10254 | |
| 10255 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 10256 | DSAStackTy *Stack, QualType QTy) { |
| 10257 | NamedDecl *ND; |
| 10258 | if (QTy->isIncompleteType(&ND)) { |
| 10259 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 10260 | return false; |
| 10261 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
| 10262 | if (!RD->isInvalidDecl() && |
| 10263 | !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
| 10264 | return false; |
| 10265 | } |
| 10266 | return true; |
| 10267 | } |
| 10268 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10269 | /// \brief Return true if it can be proven that the provided array expression |
| 10270 | /// (array section or array subscript) does NOT specify the whole size of the |
| 10271 | /// array whose base type is \a BaseQTy. |
| 10272 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 10273 | const Expr *E, |
| 10274 | QualType BaseQTy) { |
| 10275 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10276 | |
| 10277 | // If this is an array subscript, it refers to the whole size if the size of |
| 10278 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 10279 | // format of an array subscript if no colon is used. |
| 10280 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 10281 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10282 | return ATy->getSize().getSExtValue() != 1; |
| 10283 | // Size can't be evaluated statically. |
| 10284 | return false; |
| 10285 | } |
| 10286 | |
| 10287 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10288 | auto *LowerBound = OASE->getLowerBound(); |
| 10289 | auto *Length = OASE->getLength(); |
| 10290 | |
| 10291 | // If there is a lower bound that does not evaluates to zero, we are not |
| 10292 | // convering the whole dimension. |
| 10293 | if (LowerBound) { |
| 10294 | llvm::APSInt ConstLowerBound; |
| 10295 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 10296 | return false; // Can't get the integer value as a constant. |
| 10297 | if (ConstLowerBound.getSExtValue()) |
| 10298 | return true; |
| 10299 | } |
| 10300 | |
| 10301 | // If we don't have a length we covering the whole dimension. |
| 10302 | if (!Length) |
| 10303 | return false; |
| 10304 | |
| 10305 | // If the base is a pointer, we don't have a way to get the size of the |
| 10306 | // pointee. |
| 10307 | if (BaseQTy->isPointerType()) |
| 10308 | return false; |
| 10309 | |
| 10310 | // We can only check if the length is the same as the size of the dimension |
| 10311 | // if we have a constant array. |
| 10312 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 10313 | if (!CATy) |
| 10314 | return false; |
| 10315 | |
| 10316 | llvm::APSInt ConstLength; |
| 10317 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10318 | return false; // Can't get the integer value as a constant. |
| 10319 | |
| 10320 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 10321 | } |
| 10322 | |
| 10323 | // Return true if it can be proven that the provided array expression (array |
| 10324 | // section or array subscript) does NOT specify a single element of the array |
| 10325 | // whose base type is \a BaseQTy. |
| 10326 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
| 10327 | const Expr *E, |
| 10328 | QualType BaseQTy) { |
| 10329 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10330 | |
| 10331 | // An array subscript always refer to a single element. Also, an array section |
| 10332 | // assumes the format of an array subscript if no colon is used. |
| 10333 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 10334 | return false; |
| 10335 | |
| 10336 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10337 | auto *Length = OASE->getLength(); |
| 10338 | |
| 10339 | // If we don't have a length we have to check if the array has unitary size |
| 10340 | // for this dimension. Also, we should always expect a length if the base type |
| 10341 | // is pointer. |
| 10342 | if (!Length) { |
| 10343 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10344 | return ATy->getSize().getSExtValue() != 1; |
| 10345 | // We cannot assume anything. |
| 10346 | return false; |
| 10347 | } |
| 10348 | |
| 10349 | // Check if the length evaluates to 1. |
| 10350 | llvm::APSInt ConstLength; |
| 10351 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10352 | return false; // Can't get the integer value as a constant. |
| 10353 | |
| 10354 | return ConstLength.getSExtValue() != 1; |
| 10355 | } |
| 10356 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10357 | // Return the expression of the base of the mappable expression or null if it |
| 10358 | // cannot be determined and do all the necessary checks to see if the expression |
| 10359 | // is valid as a standalone mappable expression. In the process, record all the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10360 | // components of the expression. |
| 10361 | static Expr *CheckMapClauseExpressionBase( |
| 10362 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10363 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 10364 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10365 | SourceLocation ELoc = E->getExprLoc(); |
| 10366 | SourceRange ERange = E->getSourceRange(); |
| 10367 | |
| 10368 | // The base of elements of list in a map clause have to be either: |
| 10369 | // - a reference to variable or field. |
| 10370 | // - a member expression. |
| 10371 | // - an array expression. |
| 10372 | // |
| 10373 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 10374 | // reference to 'r'. |
| 10375 | // |
| 10376 | // If we have: |
| 10377 | // |
| 10378 | // struct SS { |
| 10379 | // Bla S; |
| 10380 | // foo() { |
| 10381 | // #pragma omp target map (S.Arr[:12]); |
| 10382 | // } |
| 10383 | // } |
| 10384 | // |
| 10385 | // We want to retrieve the member expression 'this->S'; |
| 10386 | |
| 10387 | Expr *RelevantExpr = nullptr; |
| 10388 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10389 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 10390 | // If a list item is an array section, it must specify contiguous storage. |
| 10391 | // |
| 10392 | // For this restriction it is sufficient that we make sure only references |
| 10393 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10394 | // exist except in the rightmost expression (unless they cover the whole |
| 10395 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10396 | // |
| 10397 | // r.ArrS[3:5].Arr[6:7] |
| 10398 | // |
| 10399 | // r.ArrS[3:5].x |
| 10400 | // |
| 10401 | // but these would be valid: |
| 10402 | // r.ArrS[3].Arr[6:7] |
| 10403 | // |
| 10404 | // r.ArrS[3].x |
| 10405 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10406 | bool AllowUnitySizeArraySection = true; |
| 10407 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10408 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 10409 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10410 | E = E->IgnoreParenImpCasts(); |
| 10411 | |
| 10412 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 10413 | if (!isa<VarDecl>(CurE->getDecl())) |
| 10414 | break; |
| 10415 | |
| 10416 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10417 | |
| 10418 | // If we got a reference to a declaration, we should not expect any array |
| 10419 | // section before that. |
| 10420 | AllowUnitySizeArraySection = false; |
| 10421 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10422 | |
| 10423 | // Record the component. |
| 10424 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 10425 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10426 | continue; |
| 10427 | } |
| 10428 | |
| 10429 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 10430 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 10431 | |
| 10432 | if (isa<CXXThisExpr>(BaseE)) |
| 10433 | // We found a base expression: this->Val. |
| 10434 | RelevantExpr = CurE; |
| 10435 | else |
| 10436 | E = BaseE; |
| 10437 | |
| 10438 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 10439 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 10440 | << CurE->getSourceRange(); |
| 10441 | break; |
| 10442 | } |
| 10443 | |
| 10444 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 10445 | |
| 10446 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 10447 | // A bit-field cannot appear in a map clause. |
| 10448 | // |
| 10449 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10450 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 10451 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10452 | break; |
| 10453 | } |
| 10454 | |
| 10455 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10456 | // If the type of a list item is a reference to a type T then the type |
| 10457 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10458 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10459 | |
| 10460 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 10461 | // A list item cannot be a variable that is a member of a structure with |
| 10462 | // a union type. |
| 10463 | // |
| 10464 | if (auto *RT = CurType->getAs<RecordType>()) |
| 10465 | if (RT->isUnionType()) { |
| 10466 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 10467 | << CurE->getSourceRange(); |
| 10468 | break; |
| 10469 | } |
| 10470 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10471 | // If we got a member expression, we should not expect any array section |
| 10472 | // before that: |
| 10473 | // |
| 10474 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 10475 | // If a list item is an element of a structure, only the rightmost symbol |
| 10476 | // of the variable reference can be an array section. |
| 10477 | // |
| 10478 | AllowUnitySizeArraySection = false; |
| 10479 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10480 | |
| 10481 | // Record the component. |
| 10482 | CurComponents.push_back( |
| 10483 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10484 | continue; |
| 10485 | } |
| 10486 | |
| 10487 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 10488 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10489 | |
| 10490 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 10491 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10492 | << 0 << CurE->getSourceRange(); |
| 10493 | break; |
| 10494 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10495 | |
| 10496 | // If we got an array subscript that express the whole dimension we |
| 10497 | // can have any array expressions before. If it only expressing part of |
| 10498 | // the dimension, we can only have unitary-size array expressions. |
| 10499 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 10500 | E->getType())) |
| 10501 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10502 | |
| 10503 | // Record the component - we don't have any declaration associated. |
| 10504 | CurComponents.push_back( |
| 10505 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10506 | continue; |
| 10507 | } |
| 10508 | |
| 10509 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10510 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10511 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10512 | auto CurType = |
| 10513 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10514 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10515 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10516 | // If the type of a list item is a reference to a type T then the type |
| 10517 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10518 | if (CurType->isReferenceType()) |
| 10519 | CurType = CurType->getPointeeType(); |
| 10520 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10521 | bool IsPointer = CurType->isAnyPointerType(); |
| 10522 | |
| 10523 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10524 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10525 | << 0 << CurE->getSourceRange(); |
| 10526 | break; |
| 10527 | } |
| 10528 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10529 | bool NotWhole = |
| 10530 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 10531 | bool NotUnity = |
| 10532 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 10533 | |
| 10534 | if (AllowWholeSizeArraySection && AllowUnitySizeArraySection) { |
| 10535 | // Any array section is currently allowed. |
| 10536 | // |
| 10537 | // If this array section refers to the whole dimension we can still |
| 10538 | // accept other array sections before this one, except if the base is a |
| 10539 | // pointer. Otherwise, only unitary sections are accepted. |
| 10540 | if (NotWhole || IsPointer) |
| 10541 | AllowWholeSizeArraySection = false; |
| 10542 | } else if ((AllowUnitySizeArraySection && NotUnity) || |
| 10543 | (AllowWholeSizeArraySection && NotWhole)) { |
| 10544 | // A unity or whole array section is not allowed and that is not |
| 10545 | // compatible with the properties of the current array section. |
| 10546 | SemaRef.Diag( |
| 10547 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 10548 | << CurE->getSourceRange(); |
| 10549 | break; |
| 10550 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10551 | |
| 10552 | // Record the component - we don't have any declaration associated. |
| 10553 | CurComponents.push_back( |
| 10554 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10555 | continue; |
| 10556 | } |
| 10557 | |
| 10558 | // If nothing else worked, this is not a valid map clause expression. |
| 10559 | SemaRef.Diag(ELoc, |
| 10560 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 10561 | << ERange; |
| 10562 | break; |
| 10563 | } |
| 10564 | |
| 10565 | return RelevantExpr; |
| 10566 | } |
| 10567 | |
| 10568 | // Return true if expression E associated with value VD has conflicts with other |
| 10569 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10570 | static bool CheckMapConflicts( |
| 10571 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 10572 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10573 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 10574 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10575 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10576 | SourceLocation ELoc = E->getExprLoc(); |
| 10577 | SourceRange ERange = E->getSourceRange(); |
| 10578 | |
| 10579 | // In order to easily check the conflicts we need to match each component of |
| 10580 | // the expression under test with the components of the expressions that are |
| 10581 | // already in the stack. |
| 10582 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10583 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10584 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10585 | "Map clause expression with unexpected base!"); |
| 10586 | |
| 10587 | // Variables to help detecting enclosing problems in data environment nests. |
| 10588 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10589 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10590 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10591 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 10592 | VD, CurrentRegionOnly, |
| 10593 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
| 10594 | StackComponents) -> bool { |
| 10595 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10596 | assert(!StackComponents.empty() && |
| 10597 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10598 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10599 | "Map clause expression with unexpected base!"); |
| 10600 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10601 | // The whole expression in the stack. |
| 10602 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10603 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10604 | // Expressions must start from the same base. Here we detect at which |
| 10605 | // point both expressions diverge from each other and see if we can |
| 10606 | // detect if the memory referred to both expressions is contiguous and |
| 10607 | // do not overlap. |
| 10608 | auto CI = CurComponents.rbegin(); |
| 10609 | auto CE = CurComponents.rend(); |
| 10610 | auto SI = StackComponents.rbegin(); |
| 10611 | auto SE = StackComponents.rend(); |
| 10612 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10613 | |
| 10614 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10615 | // At most one list item can be an array item derived from a given |
| 10616 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10617 | if (CurrentRegionOnly && |
| 10618 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10619 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10620 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10621 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10622 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10623 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10624 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10625 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10626 | diag::note_used_here) |
| 10627 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10628 | return true; |
| 10629 | } |
| 10630 | |
| 10631 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10632 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10633 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10634 | break; |
| 10635 | |
| 10636 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10637 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10638 | break; |
| 10639 | } |
| 10640 | |
| 10641 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10642 | // List items of map clauses in the same construct must not share |
| 10643 | // original storage. |
| 10644 | // |
| 10645 | // If the expressions are exactly the same or one is a subset of the |
| 10646 | // other, it means they are sharing storage. |
| 10647 | if (CI == CE && SI == SE) { |
| 10648 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10649 | if (CKind == OMPC_map) |
| 10650 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10651 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10652 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10653 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10654 | << ERange; |
| 10655 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10656 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10657 | << RE->getSourceRange(); |
| 10658 | return true; |
| 10659 | } else { |
| 10660 | // If we find the same expression in the enclosing data environment, |
| 10661 | // that is legal. |
| 10662 | IsEnclosedByDataEnvironmentExpr = true; |
| 10663 | return false; |
| 10664 | } |
| 10665 | } |
| 10666 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10667 | QualType DerivedType = |
| 10668 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10669 | SourceLocation DerivedLoc = |
| 10670 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10671 | |
| 10672 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10673 | // If the type of a list item is a reference to a type T then the type |
| 10674 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10675 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10676 | |
| 10677 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10678 | // A variable for which the type is pointer and an array section |
| 10679 | // derived from that variable must not appear as list items of map |
| 10680 | // clauses of the same construct. |
| 10681 | // |
| 10682 | // Also, cover one of the cases in: |
| 10683 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10684 | // If any part of the original storage of a list item has corresponding |
| 10685 | // storage in the device data environment, all of the original storage |
| 10686 | // must have corresponding storage in the device data environment. |
| 10687 | // |
| 10688 | if (DerivedType->isAnyPointerType()) { |
| 10689 | if (CI == CE || SI == SE) { |
| 10690 | SemaRef.Diag( |
| 10691 | DerivedLoc, |
| 10692 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10693 | << DerivedLoc; |
| 10694 | } else { |
| 10695 | assert(CI != CE && SI != SE); |
| 10696 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10697 | << DerivedLoc; |
| 10698 | } |
| 10699 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10700 | << RE->getSourceRange(); |
| 10701 | return true; |
| 10702 | } |
| 10703 | |
| 10704 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10705 | // List items of map clauses in the same construct must not share |
| 10706 | // original storage. |
| 10707 | // |
| 10708 | // An expression is a subset of the other. |
| 10709 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10710 | if (CKind == OMPC_map) |
| 10711 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10712 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10713 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10714 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10715 | << ERange; |
| 10716 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10717 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10718 | << RE->getSourceRange(); |
| 10719 | return true; |
| 10720 | } |
| 10721 | |
| 10722 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10723 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10724 | if (!CurrentRegionOnly && SI != SE) |
| 10725 | EnclosingExpr = RE; |
| 10726 | |
| 10727 | // The current expression is a subset of the expression in the data |
| 10728 | // environment. |
| 10729 | IsEnclosedByDataEnvironmentExpr |= |
| 10730 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10731 | |
| 10732 | return false; |
| 10733 | }); |
| 10734 | |
| 10735 | if (CurrentRegionOnly) |
| 10736 | return FoundError; |
| 10737 | |
| 10738 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10739 | // If any part of the original storage of a list item has corresponding |
| 10740 | // storage in the device data environment, all of the original storage must |
| 10741 | // have corresponding storage in the device data environment. |
| 10742 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10743 | // If a list item is an element of a structure, and a different element of |
| 10744 | // the structure has a corresponding list item in the device data environment |
| 10745 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10746 | // then the list item must also have a corresponding list item in the device |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10747 | // data environment prior to the task encountering the construct. |
| 10748 | // |
| 10749 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10750 | SemaRef.Diag(ELoc, |
| 10751 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10752 | << ERange; |
| 10753 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10754 | << EnclosingExpr->getSourceRange(); |
| 10755 | return true; |
| 10756 | } |
| 10757 | |
| 10758 | return FoundError; |
| 10759 | } |
| 10760 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10761 | namespace { |
| 10762 | // Utility struct that gathers all the related lists associated with a mappable |
| 10763 | // expression. |
| 10764 | struct MappableVarListInfo final { |
| 10765 | // The list of expressions. |
| 10766 | ArrayRef<Expr *> VarList; |
| 10767 | // The list of processed expressions. |
| 10768 | SmallVector<Expr *, 16> ProcessedVarList; |
| 10769 | // The mappble components for each expression. |
| 10770 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 10771 | // The base declaration of the variable. |
| 10772 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 10773 | |
| 10774 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 10775 | // We have a list of components and base declarations for each entry in the |
| 10776 | // variable list. |
| 10777 | VarComponents.reserve(VarList.size()); |
| 10778 | VarBaseDeclarations.reserve(VarList.size()); |
| 10779 | } |
| 10780 | }; |
| 10781 | } |
| 10782 | |
| 10783 | // Check the validity of the provided variable list for the provided clause kind |
| 10784 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 10785 | // components and variables are extracted and used to fill \a Vars, |
| 10786 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 10787 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 10788 | static void |
| 10789 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 10790 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 10791 | SourceLocation StartLoc, |
| 10792 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 10793 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10794 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 10795 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10796 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10797 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10798 | // Keep track of the mappable components and base declarations in this clause. |
| 10799 | // Each entry in the list is going to have a list of components associated. We |
| 10800 | // record each set of the components so that we can build the clause later on. |
| 10801 | // In the end we should have the same amount of declarations and component |
| 10802 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10803 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10804 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10805 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10806 | SourceLocation ELoc = RE->getExprLoc(); |
| 10807 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10808 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 10809 | |
| 10810 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 10811 | VE->isInstantiationDependent() || |
| 10812 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10813 | // We can only analyze this information once the missing information is |
| 10814 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10815 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10816 | continue; |
| 10817 | } |
| 10818 | |
| 10819 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10820 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10821 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10822 | SemaRef.Diag(ELoc, |
| 10823 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10824 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10825 | continue; |
| 10826 | } |
| 10827 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10828 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 10829 | ValueDecl *CurDeclaration = nullptr; |
| 10830 | |
| 10831 | // Obtain the array or member expression bases if required. Also, fill the |
| 10832 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10833 | auto *BE = |
| 10834 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10835 | if (!BE) |
| 10836 | continue; |
| 10837 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10838 | assert(!CurComponents.empty() && |
| 10839 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10840 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10841 | // For the following checks, we rely on the base declaration which is |
| 10842 | // expected to be associated with the last component. The declaration is |
| 10843 | // expected to be a variable or a field (if 'this' is being mapped). |
| 10844 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 10845 | assert(CurDeclaration && "Null decl on map clause."); |
| 10846 | assert( |
| 10847 | CurDeclaration->isCanonicalDecl() && |
| 10848 | "Expecting components to have associated only canonical declarations."); |
| 10849 | |
| 10850 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 10851 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10852 | |
| 10853 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 10854 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10855 | |
| 10856 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10857 | // threadprivate variables cannot appear in a map clause. |
| 10858 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 10859 | // threadprivate variables cannot appear in a from clause. |
| 10860 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 10861 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10862 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 10863 | << getOpenMPClauseName(CKind); |
| 10864 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10865 | continue; |
| 10866 | } |
| 10867 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10868 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 10869 | // A list item cannot appear in both a map clause and a data-sharing |
| 10870 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10871 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10872 | // Check conflicts with other map clause expressions. We check the conflicts |
| 10873 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10874 | // environment, because the restrictions are different. We only have to |
| 10875 | // check conflicts across regions for the map clauses. |
| 10876 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10877 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10878 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10879 | if (CKind == OMPC_map && |
| 10880 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10881 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10882 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10883 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10884 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10885 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10886 | // If the type of a list item is a reference to a type T then the type will |
| 10887 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10888 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10889 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10890 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 10891 | // A list item in a to or from clause must have a mappable type. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10892 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10893 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10894 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 10895 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10896 | continue; |
| 10897 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10898 | if (CKind == OMPC_map) { |
| 10899 | // target enter data |
| 10900 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 10901 | // A map-type must be specified in all map clauses and must be either |
| 10902 | // to or alloc. |
| 10903 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 10904 | if (DKind == OMPD_target_enter_data && |
| 10905 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 10906 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10907 | << (IsMapTypeImplicit ? 1 : 0) |
| 10908 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10909 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10910 | continue; |
| 10911 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10912 | |
| 10913 | // target exit_data |
| 10914 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 10915 | // A map-type must be specified in all map clauses and must be either |
| 10916 | // from, release, or delete. |
| 10917 | if (DKind == OMPD_target_exit_data && |
| 10918 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 10919 | MapType == OMPC_MAP_delete)) { |
| 10920 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10921 | << (IsMapTypeImplicit ? 1 : 0) |
| 10922 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10923 | << getOpenMPDirectiveName(DKind); |
| 10924 | continue; |
| 10925 | } |
| 10926 | |
| 10927 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10928 | // A list item cannot appear in both a map clause and a data-sharing |
| 10929 | // attribute clause on the same construct |
| 10930 | if (DKind == OMPD_target && VD) { |
| 10931 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10932 | if (isOpenMPPrivate(DVar.CKind)) { |
| 10933 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_map_and_dsa) |
| 10934 | << getOpenMPClauseName(DVar.CKind) |
| 10935 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 10936 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 10937 | continue; |
| 10938 | } |
| 10939 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10940 | } |
| 10941 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10942 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10943 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10944 | |
| 10945 | // Store the components in the stack so that they can be used to check |
| 10946 | // against other clauses later on. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10947 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10948 | |
| 10949 | // Save the components and declaration to create the clause. For purposes of |
| 10950 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 10951 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10952 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 10953 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 10954 | CurComponents.end()); |
| 10955 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 10956 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10957 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10958 | } |
| 10959 | |
| 10960 | OMPClause * |
| 10961 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 10962 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 10963 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 10964 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10965 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 10966 | MappableVarListInfo MVLI(VarList); |
| 10967 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 10968 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10969 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10970 | // We need to produce a map clause even if we don't have variables so that |
| 10971 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10972 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10973 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10974 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 10975 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10976 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10977 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10978 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 10979 | TypeResult ParsedType) { |
| 10980 | assert(ParsedType.isUsable()); |
| 10981 | |
| 10982 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 10983 | if (ReductionType.isNull()) |
| 10984 | return QualType(); |
| 10985 | |
| 10986 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 10987 | // A type name in a declare reduction directive cannot be a function type, an |
| 10988 | // array type, a reference type, or a type qualified with const, volatile or |
| 10989 | // restrict. |
| 10990 | if (ReductionType.hasQualifiers()) { |
| 10991 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 10992 | return QualType(); |
| 10993 | } |
| 10994 | |
| 10995 | if (ReductionType->isFunctionType()) { |
| 10996 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 10997 | return QualType(); |
| 10998 | } |
| 10999 | if (ReductionType->isReferenceType()) { |
| 11000 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 11001 | return QualType(); |
| 11002 | } |
| 11003 | if (ReductionType->isArrayType()) { |
| 11004 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 11005 | return QualType(); |
| 11006 | } |
| 11007 | return ReductionType; |
| 11008 | } |
| 11009 | |
| 11010 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 11011 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 11012 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 11013 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 11014 | SmallVector<Decl *, 8> Decls; |
| 11015 | Decls.reserve(ReductionTypes.size()); |
| 11016 | |
| 11017 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 11018 | ForRedeclaration); |
| 11019 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 11020 | // A reduction-identifier may not be re-declared in the current scope for the |
| 11021 | // same type or for a type that is compatible according to the base language |
| 11022 | // rules. |
| 11023 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 11024 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 11025 | bool InCompoundScope = true; |
| 11026 | if (S != nullptr) { |
| 11027 | // Find previous declaration with the same name not referenced in other |
| 11028 | // declarations. |
| 11029 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 11030 | InCompoundScope = |
| 11031 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 11032 | LookupName(Lookup, S); |
| 11033 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 11034 | /*AllowInlineNamespace=*/false); |
| 11035 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 11036 | auto Filter = Lookup.makeFilter(); |
| 11037 | while (Filter.hasNext()) { |
| 11038 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 11039 | if (InCompoundScope) { |
| 11040 | auto I = UsedAsPrevious.find(PrevDecl); |
| 11041 | if (I == UsedAsPrevious.end()) |
| 11042 | UsedAsPrevious[PrevDecl] = false; |
| 11043 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 11044 | UsedAsPrevious[D] = true; |
| 11045 | } |
| 11046 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 11047 | PrevDecl->getLocation(); |
| 11048 | } |
| 11049 | Filter.done(); |
| 11050 | if (InCompoundScope) { |
| 11051 | for (auto &PrevData : UsedAsPrevious) { |
| 11052 | if (!PrevData.second) { |
| 11053 | PrevDRD = PrevData.first; |
| 11054 | break; |
| 11055 | } |
| 11056 | } |
| 11057 | } |
| 11058 | } else if (PrevDeclInScope != nullptr) { |
| 11059 | auto *PrevDRDInScope = PrevDRD = |
| 11060 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 11061 | do { |
| 11062 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 11063 | PrevDRDInScope->getLocation(); |
| 11064 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 11065 | } while (PrevDRDInScope != nullptr); |
| 11066 | } |
| 11067 | for (auto &TyData : ReductionTypes) { |
| 11068 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 11069 | bool Invalid = false; |
| 11070 | if (I != PreviousRedeclTypes.end()) { |
| 11071 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 11072 | << TyData.first; |
| 11073 | Diag(I->second, diag::note_previous_definition); |
| 11074 | Invalid = true; |
| 11075 | } |
| 11076 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 11077 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 11078 | Name, TyData.first, PrevDRD); |
| 11079 | DC->addDecl(DRD); |
| 11080 | DRD->setAccess(AS); |
| 11081 | Decls.push_back(DRD); |
| 11082 | if (Invalid) |
| 11083 | DRD->setInvalidDecl(); |
| 11084 | else |
| 11085 | PrevDRD = DRD; |
| 11086 | } |
| 11087 | |
| 11088 | return DeclGroupPtrTy::make( |
| 11089 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 11090 | } |
| 11091 | |
| 11092 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 11093 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11094 | |
| 11095 | // Enter new function scope. |
| 11096 | PushFunctionScope(); |
| 11097 | getCurFunction()->setHasBranchProtectedScope(); |
| 11098 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 11099 | |
| 11100 | if (S != nullptr) |
| 11101 | PushDeclContext(S, DRD); |
| 11102 | else |
| 11103 | CurContext = DRD; |
| 11104 | |
| 11105 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 11106 | |
| 11107 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11108 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 11109 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 11110 | // uses semantics of argument handles by value, but it should be passed by |
| 11111 | // reference. C lang does not support references, so pass all parameters as |
| 11112 | // pointers. |
| 11113 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11114 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11115 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11116 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 11117 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 11118 | // uses semantics of argument handles by value, but it should be passed by |
| 11119 | // reference. C lang does not support references, so pass all parameters as |
| 11120 | // pointers. |
| 11121 | // Create 'T omp_out;' variable. |
| 11122 | auto *OmpOutParm = |
| 11123 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 11124 | if (S != nullptr) { |
| 11125 | PushOnScopeChains(OmpInParm, S); |
| 11126 | PushOnScopeChains(OmpOutParm, S); |
| 11127 | } else { |
| 11128 | DRD->addDecl(OmpInParm); |
| 11129 | DRD->addDecl(OmpOutParm); |
| 11130 | } |
| 11131 | } |
| 11132 | |
| 11133 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 11134 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11135 | DiscardCleanupsInEvaluationContext(); |
| 11136 | PopExpressionEvaluationContext(); |
| 11137 | |
| 11138 | PopDeclContext(); |
| 11139 | PopFunctionScopeInfo(); |
| 11140 | |
| 11141 | if (Combiner != nullptr) |
| 11142 | DRD->setCombiner(Combiner); |
| 11143 | else |
| 11144 | DRD->setInvalidDecl(); |
| 11145 | } |
| 11146 | |
| 11147 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 11148 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11149 | |
| 11150 | // Enter new function scope. |
| 11151 | PushFunctionScope(); |
| 11152 | getCurFunction()->setHasBranchProtectedScope(); |
| 11153 | |
| 11154 | if (S != nullptr) |
| 11155 | PushDeclContext(S, DRD); |
| 11156 | else |
| 11157 | CurContext = DRD; |
| 11158 | |
| 11159 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 11160 | |
| 11161 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11162 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 11163 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 11164 | // uses semantics of argument handles by value, but it should be passed by |
| 11165 | // reference. C lang does not support references, so pass all parameters as |
| 11166 | // pointers. |
| 11167 | // Create 'T omp_priv;' variable. |
| 11168 | auto *OmpPrivParm = |
| 11169 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11170 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 11171 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 11172 | // uses semantics of argument handles by value, but it should be passed by |
| 11173 | // reference. C lang does not support references, so pass all parameters as |
| 11174 | // pointers. |
| 11175 | // Create 'T omp_orig;' variable. |
| 11176 | auto *OmpOrigParm = |
| 11177 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11178 | if (S != nullptr) { |
| 11179 | PushOnScopeChains(OmpPrivParm, S); |
| 11180 | PushOnScopeChains(OmpOrigParm, S); |
| 11181 | } else { |
| 11182 | DRD->addDecl(OmpPrivParm); |
| 11183 | DRD->addDecl(OmpOrigParm); |
| 11184 | } |
| 11185 | } |
| 11186 | |
| 11187 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 11188 | Expr *Initializer) { |
| 11189 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11190 | DiscardCleanupsInEvaluationContext(); |
| 11191 | PopExpressionEvaluationContext(); |
| 11192 | |
| 11193 | PopDeclContext(); |
| 11194 | PopFunctionScopeInfo(); |
| 11195 | |
| 11196 | if (Initializer != nullptr) |
| 11197 | DRD->setInitializer(Initializer); |
| 11198 | else |
| 11199 | DRD->setInvalidDecl(); |
| 11200 | } |
| 11201 | |
| 11202 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11203 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 11204 | for (auto *D : DeclReductions.get()) { |
| 11205 | if (IsValid) { |
| 11206 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11207 | if (S != nullptr) |
| 11208 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 11209 | } else |
| 11210 | D->setInvalidDecl(); |
| 11211 | } |
| 11212 | return DeclReductions; |
| 11213 | } |
| 11214 | |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11215 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
| 11216 | SourceLocation StartLoc, |
| 11217 | SourceLocation LParenLoc, |
| 11218 | SourceLocation EndLoc) { |
| 11219 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11220 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11221 | // OpenMP [teams Constrcut, Restrictions] |
| 11222 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11223 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 11224 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11225 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11226 | |
| 11227 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11228 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11229 | |
| 11230 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 11231 | SourceLocation StartLoc, |
| 11232 | SourceLocation LParenLoc, |
| 11233 | SourceLocation EndLoc) { |
| 11234 | Expr *ValExpr = ThreadLimit; |
| 11235 | |
| 11236 | // OpenMP [teams Constrcut, Restrictions] |
| 11237 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11238 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 11239 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11240 | return nullptr; |
| 11241 | |
| 11242 | return new (Context) OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, |
| 11243 | EndLoc); |
| 11244 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11245 | |
| 11246 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 11247 | SourceLocation StartLoc, |
| 11248 | SourceLocation LParenLoc, |
| 11249 | SourceLocation EndLoc) { |
| 11250 | Expr *ValExpr = Priority; |
| 11251 | |
| 11252 | // OpenMP [2.9.1, task Constrcut] |
| 11253 | // The priority-value is a non-negative numerical scalar expression. |
| 11254 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 11255 | /*StrictlyPositive=*/false)) |
| 11256 | return nullptr; |
| 11257 | |
| 11258 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11259 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11260 | |
| 11261 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 11262 | SourceLocation StartLoc, |
| 11263 | SourceLocation LParenLoc, |
| 11264 | SourceLocation EndLoc) { |
| 11265 | Expr *ValExpr = Grainsize; |
| 11266 | |
| 11267 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11268 | // The parameter of the grainsize clause must be a positive integer |
| 11269 | // expression. |
| 11270 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 11271 | /*StrictlyPositive=*/true)) |
| 11272 | return nullptr; |
| 11273 | |
| 11274 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11275 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11276 | |
| 11277 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 11278 | SourceLocation StartLoc, |
| 11279 | SourceLocation LParenLoc, |
| 11280 | SourceLocation EndLoc) { |
| 11281 | Expr *ValExpr = NumTasks; |
| 11282 | |
| 11283 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11284 | // The parameter of the num_tasks clause must be a positive integer |
| 11285 | // expression. |
| 11286 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 11287 | /*StrictlyPositive=*/true)) |
| 11288 | return nullptr; |
| 11289 | |
| 11290 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11291 | } |
| 11292 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11293 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11294 | SourceLocation LParenLoc, |
| 11295 | SourceLocation EndLoc) { |
| 11296 | // OpenMP [2.13.2, critical construct, Description] |
| 11297 | // ... where hint-expression is an integer constant expression that evaluates |
| 11298 | // to a valid lock hint. |
| 11299 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 11300 | if (HintExpr.isInvalid()) |
| 11301 | return nullptr; |
| 11302 | return new (Context) |
| 11303 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 11304 | } |
| 11305 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11306 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 11307 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11308 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 11309 | SourceLocation EndLoc) { |
| 11310 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 11311 | std::string Values; |
| 11312 | Values += "'"; |
| 11313 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 11314 | Values += "'"; |
| 11315 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11316 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 11317 | return nullptr; |
| 11318 | } |
| 11319 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11320 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11321 | if (ChunkSize) { |
| 11322 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 11323 | !ChunkSize->isInstantiationDependent() && |
| 11324 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 11325 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 11326 | ExprResult Val = |
| 11327 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 11328 | if (Val.isInvalid()) |
| 11329 | return nullptr; |
| 11330 | |
| 11331 | ValExpr = Val.get(); |
| 11332 | |
| 11333 | // OpenMP [2.7.1, Restrictions] |
| 11334 | // chunk_size must be a loop invariant integer expression with a positive |
| 11335 | // value. |
| 11336 | llvm::APSInt Result; |
| 11337 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 11338 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 11339 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 11340 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 11341 | return nullptr; |
| 11342 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 11343 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 11344 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11345 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11346 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11347 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11348 | } |
| 11349 | } |
| 11350 | } |
| 11351 | |
| 11352 | return new (Context) |
| 11353 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11354 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11355 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11356 | |
| 11357 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 11358 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 11359 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 11360 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 11361 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
| 11362 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || |
| 11363 | Kind != OMPC_DEFAULTMAP_scalar) { |
| 11364 | std::string Value; |
| 11365 | SourceLocation Loc; |
| 11366 | Value += "'"; |
| 11367 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 11368 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 11369 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
| 11370 | Loc = MLoc; |
| 11371 | } else { |
| 11372 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
| 11373 | OMPC_DEFAULTMAP_scalar); |
| 11374 | Loc = KindLoc; |
| 11375 | } |
| 11376 | Value += "'"; |
| 11377 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 11378 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 11379 | return nullptr; |
| 11380 | } |
| 11381 | |
| 11382 | return new (Context) |
| 11383 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 11384 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11385 | |
| 11386 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 11387 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 11388 | if (!CurLexicalContext->isFileContext() && |
| 11389 | !CurLexicalContext->isExternCContext() && |
| 11390 | !CurLexicalContext->isExternCXXContext()) { |
| 11391 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 11392 | return false; |
| 11393 | } |
| 11394 | if (IsInOpenMPDeclareTargetContext) { |
| 11395 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 11396 | return false; |
| 11397 | } |
| 11398 | |
| 11399 | IsInOpenMPDeclareTargetContext = true; |
| 11400 | return true; |
| 11401 | } |
| 11402 | |
| 11403 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 11404 | assert(IsInOpenMPDeclareTargetContext && |
| 11405 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 11406 | |
| 11407 | IsInOpenMPDeclareTargetContext = false; |
| 11408 | } |
| 11409 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11410 | void |
| 11411 | Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
| 11412 | const DeclarationNameInfo &Id, |
| 11413 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11414 | NamedDeclSetType &SameDirectiveDecls) { |
| 11415 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 11416 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 11417 | |
| 11418 | if (Lookup.isAmbiguous()) |
| 11419 | return; |
| 11420 | Lookup.suppressDiagnostics(); |
| 11421 | |
| 11422 | if (!Lookup.isSingleResult()) { |
| 11423 | if (TypoCorrection Corrected = |
| 11424 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 11425 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 11426 | CTK_ErrorRecovery)) { |
| 11427 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 11428 | << Id.getName()); |
| 11429 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 11430 | return; |
| 11431 | } |
| 11432 | |
| 11433 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 11434 | return; |
| 11435 | } |
| 11436 | |
| 11437 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 11438 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 11439 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 11440 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 11441 | |
| 11442 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 11443 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 11444 | ND->addAttr(A); |
| 11445 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 11446 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 11447 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 11448 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 11449 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 11450 | << Id.getName(); |
| 11451 | } |
| 11452 | } else |
| 11453 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 11454 | } |
| 11455 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11456 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 11457 | Sema &SemaRef, Decl *D) { |
| 11458 | if (!D) |
| 11459 | return; |
| 11460 | Decl *LD = nullptr; |
| 11461 | if (isa<TagDecl>(D)) { |
| 11462 | LD = cast<TagDecl>(D)->getDefinition(); |
| 11463 | } else if (isa<VarDecl>(D)) { |
| 11464 | LD = cast<VarDecl>(D)->getDefinition(); |
| 11465 | |
| 11466 | // If this is an implicit variable that is legal and we do not need to do |
| 11467 | // anything. |
| 11468 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11469 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11470 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11471 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11472 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11473 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11474 | return; |
| 11475 | } |
| 11476 | |
| 11477 | } else if (isa<FunctionDecl>(D)) { |
| 11478 | const FunctionDecl *FD = nullptr; |
| 11479 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 11480 | LD = const_cast<FunctionDecl *>(FD); |
| 11481 | |
| 11482 | // If the definition is associated with the current declaration in the |
| 11483 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 11484 | // to do anything else. |
| 11485 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11486 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11487 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11488 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11489 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11490 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11491 | return; |
| 11492 | } |
| 11493 | } |
| 11494 | if (!LD) |
| 11495 | LD = D; |
| 11496 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11497 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 11498 | // Outlined declaration is not declared target. |
| 11499 | if (LD->isOutOfLine()) { |
| 11500 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11501 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11502 | } else { |
| 11503 | DeclContext *DC = LD->getDeclContext(); |
| 11504 | while (DC) { |
| 11505 | if (isa<FunctionDecl>(DC) && |
| 11506 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11507 | break; |
| 11508 | DC = DC->getParent(); |
| 11509 | } |
| 11510 | if (DC) |
| 11511 | return; |
| 11512 | |
| 11513 | // Is not declared in target context. |
| 11514 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11515 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11516 | } |
| 11517 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11518 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11519 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11520 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11521 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11522 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11523 | } |
| 11524 | } |
| 11525 | |
| 11526 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 11527 | Sema &SemaRef, DSAStackTy *Stack, |
| 11528 | ValueDecl *VD) { |
| 11529 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11530 | return true; |
| 11531 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 11532 | return false; |
| 11533 | return true; |
| 11534 | } |
| 11535 | |
| 11536 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 11537 | if (!D || D->isInvalidDecl()) |
| 11538 | return; |
| 11539 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 11540 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 11541 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 11542 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 11543 | if (DSAStack->isThreadPrivate(VD)) { |
| 11544 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 11545 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 11546 | return; |
| 11547 | } |
| 11548 | } |
| 11549 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 11550 | // Problem if any with var declared with incomplete type will be reported |
| 11551 | // as normal, so no need to check it here. |
| 11552 | if ((E || !VD->getType()->isIncompleteType()) && |
| 11553 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 11554 | // Mark decl as declared target to prevent further diagnostic. |
| 11555 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11556 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11557 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11558 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11559 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11560 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11561 | } |
| 11562 | return; |
| 11563 | } |
| 11564 | } |
| 11565 | if (!E) { |
| 11566 | // Checking declaration inside declare target region. |
| 11567 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11568 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11569 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11570 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11571 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11572 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11573 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11574 | } |
| 11575 | return; |
| 11576 | } |
| 11577 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 11578 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11579 | |
| 11580 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 11581 | SourceLocation StartLoc, |
| 11582 | SourceLocation LParenLoc, |
| 11583 | SourceLocation EndLoc) { |
| 11584 | MappableVarListInfo MVLI(VarList); |
| 11585 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 11586 | if (MVLI.ProcessedVarList.empty()) |
| 11587 | return nullptr; |
| 11588 | |
| 11589 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11590 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11591 | MVLI.VarComponents); |
| 11592 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11593 | |
| 11594 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11595 | SourceLocation StartLoc, |
| 11596 | SourceLocation LParenLoc, |
| 11597 | SourceLocation EndLoc) { |
| 11598 | MappableVarListInfo MVLI(VarList); |
| 11599 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11600 | if (MVLI.ProcessedVarList.empty()) |
| 11601 | return nullptr; |
| 11602 | |
| 11603 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11604 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11605 | MVLI.VarComponents); |
| 11606 | } |