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 | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 75 | /// Struct that associates a component with the clause kind where they are |
| 76 | /// found. |
| 77 | struct MappedExprComponentTy { |
| 78 | OMPClauseMappableExprCommon::MappableExprComponentLists Components; |
| 79 | OpenMPClauseKind Kind = OMPC_unknown; |
| 80 | }; |
| 81 | typedef llvm::DenseMap<ValueDecl *, MappedExprComponentTy> |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 82 | MappedExprComponentsTy; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 83 | typedef llvm::StringMap<std::pair<OMPCriticalDirective *, llvm::APSInt>> |
| 84 | CriticalsWithHintsTy; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 85 | typedef llvm::DenseMap<OMPDependClause *, OperatorOffsetTy> |
| 86 | DoacrossDependMapTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 87 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 88 | struct SharingMapTy final { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 89 | DeclSAMapTy SharingMap; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 90 | AlignedMapTy AlignedMap; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 91 | MappedExprComponentsTy MappedExprComponents; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 92 | LoopControlVariablesMapTy LCVMap; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 93 | DefaultDataSharingAttributes DefaultAttr = DSA_unspecified; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 94 | SourceLocation DefaultAttrLoc; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 95 | OpenMPDirectiveKind Directive = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 96 | DeclarationNameInfo DirectiveName; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 97 | Scope *CurScope = nullptr; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 98 | SourceLocation ConstructLoc; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 99 | /// Set of 'depend' clauses with 'sink|source' dependence kind. Required to |
| 100 | /// get the data (loop counters etc.) about enclosing loop-based construct. |
| 101 | /// This data is required during codegen. |
| 102 | DoacrossDependMapTy DoacrossDepends; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 103 | /// \brief first argument (Expr *) contains optional argument of the |
| 104 | /// 'ordered' clause, the second one is true if the regions has 'ordered' |
| 105 | /// clause, false otherwise. |
| 106 | llvm::PointerIntPair<Expr *, 1, bool> OrderedRegion; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 107 | bool NowaitRegion = false; |
| 108 | bool CancelRegion = false; |
| 109 | unsigned AssociatedLoops = 1; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 110 | SourceLocation InnerTeamsRegionLoc; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 111 | SharingMapTy(OpenMPDirectiveKind DKind, DeclarationNameInfo Name, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 112 | Scope *CurScope, SourceLocation Loc) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 113 | : Directive(DKind), DirectiveName(Name), CurScope(CurScope), |
| 114 | ConstructLoc(Loc) {} |
| 115 | SharingMapTy() {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 116 | }; |
| 117 | |
Axel Naumann | 323862e | 2016-02-03 10:45:22 +0000 | [diff] [blame] | 118 | typedef SmallVector<SharingMapTy, 4> StackTy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 119 | |
| 120 | /// \brief Stack of used declaration and their data-sharing attributes. |
| 121 | StackTy Stack; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 122 | /// \brief true, if check for DSA must be from parent directive, false, if |
| 123 | /// from current directive. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 124 | OpenMPClauseKind ClauseKindMode = OMPC_unknown; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 125 | Sema &SemaRef; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 126 | bool ForceCapturing = false; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 127 | CriticalsWithHintsTy Criticals; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 128 | |
| 129 | typedef SmallVector<SharingMapTy, 8>::reverse_iterator reverse_iterator; |
| 130 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 131 | DSAVarData getDSA(StackTy::reverse_iterator &Iter, ValueDecl *D); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 132 | |
| 133 | /// \brief Checks if the variable is a local for OpenMP region. |
| 134 | bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 135 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 136 | public: |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 137 | explicit DSAStackTy(Sema &S) : Stack(1), SemaRef(S) {} |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 138 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 139 | bool isClauseParsingMode() const { return ClauseKindMode != OMPC_unknown; } |
| 140 | void setClauseParsingMode(OpenMPClauseKind K) { ClauseKindMode = K; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 141 | |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 142 | bool isForceVarCapturing() const { return ForceCapturing; } |
| 143 | void setForceVarCapturing(bool V) { ForceCapturing = V; } |
| 144 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 145 | void push(OpenMPDirectiveKind DKind, const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 146 | Scope *CurScope, SourceLocation Loc) { |
| 147 | Stack.push_back(SharingMapTy(DKind, DirName, CurScope, Loc)); |
| 148 | Stack.back().DefaultAttrLoc = Loc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | void pop() { |
| 152 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty!"); |
| 153 | Stack.pop_back(); |
| 154 | } |
| 155 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 156 | void addCriticalWithHint(OMPCriticalDirective *D, llvm::APSInt Hint) { |
| 157 | Criticals[D->getDirectiveName().getAsString()] = std::make_pair(D, Hint); |
| 158 | } |
| 159 | const std::pair<OMPCriticalDirective *, llvm::APSInt> |
| 160 | getCriticalWithHint(const DeclarationNameInfo &Name) const { |
| 161 | auto I = Criticals.find(Name.getAsString()); |
| 162 | if (I != Criticals.end()) |
| 163 | return I->second; |
| 164 | return std::make_pair(nullptr, llvm::APSInt()); |
| 165 | } |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 166 | /// \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] | 167 | /// add it and return NULL; otherwise return previous occurrence's expression |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 168 | /// for diagnostics. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 169 | Expr *addUniqueAligned(ValueDecl *D, Expr *NewDE); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 170 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 171 | /// \brief Register specified variable as loop control variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 172 | void addLoopControlVariable(ValueDecl *D, VarDecl *Capture); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 173 | /// \brief Check if the specified variable is a loop control variable for |
| 174 | /// current region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 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 isLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 178 | /// \brief Check if the specified variable is a loop control variable for |
| 179 | /// parent region. |
| 180 | /// \return The index of the loop control variable in the list of associated |
| 181 | /// for-loops (from outer to inner). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 182 | LCDeclInfo isParentLoopControlVariable(ValueDecl *D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 183 | /// \brief Get the loop control variable for the I-th loop (or nullptr) in |
| 184 | /// parent directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 185 | ValueDecl *getParentLoopControlVariable(unsigned I); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 186 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 187 | /// \brief Adds explicit data sharing attribute to the specified declaration. |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 188 | void addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 189 | DeclRefExpr *PrivateCopy = nullptr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 190 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 191 | /// \brief Returns data sharing attributes from top of the stack for the |
| 192 | /// specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 193 | DSAVarData getTopDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 194 | /// \brief Returns data-sharing attributes for the specified declaration. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 195 | DSAVarData getImplicitDSA(ValueDecl *D, bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 196 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 197 | /// match specified \a CPred predicate in any directive which matches \a DPred |
| 198 | /// predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 199 | DSAVarData hasDSA(ValueDecl *D, |
| 200 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 201 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 202 | bool FromParent); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 203 | /// \brief Checks if the specified variables has data-sharing attributes which |
| 204 | /// match specified \a CPred predicate in any innermost directive which |
| 205 | /// matches \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 206 | DSAVarData |
| 207 | hasInnermostDSA(ValueDecl *D, |
| 208 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 209 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 210 | bool FromParent); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 211 | /// \brief Checks if the specified variables has explicit data-sharing |
| 212 | /// attributes which match specified \a CPred predicate at the specified |
| 213 | /// OpenMP region. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 214 | bool hasExplicitDSA(ValueDecl *D, |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 215 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 216 | unsigned Level, bool NotLastprivate = false); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 217 | |
| 218 | /// \brief Returns true if the directive at level \Level matches in the |
| 219 | /// specified \a DPred predicate. |
| 220 | bool hasExplicitDirective( |
| 221 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 222 | unsigned Level); |
| 223 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 224 | /// \brief Finds a directive which matches specified \a DPred predicate. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 225 | bool hasDirective(const llvm::function_ref<bool(OpenMPDirectiveKind, |
| 226 | const DeclarationNameInfo &, |
| 227 | SourceLocation)> &DPred, |
| 228 | bool FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 229 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 230 | /// \brief Returns currently analyzed directive. |
| 231 | OpenMPDirectiveKind getCurrentDirective() const { |
| 232 | return Stack.back().Directive; |
| 233 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 234 | /// \brief Returns parent directive. |
| 235 | OpenMPDirectiveKind getParentDirective() const { |
| 236 | if (Stack.size() > 2) |
| 237 | return Stack[Stack.size() - 2].Directive; |
| 238 | return OMPD_unknown; |
| 239 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 240 | |
| 241 | /// \brief Set default data sharing attribute to none. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 242 | void setDefaultDSANone(SourceLocation Loc) { |
| 243 | Stack.back().DefaultAttr = DSA_none; |
| 244 | Stack.back().DefaultAttrLoc = Loc; |
| 245 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 246 | /// \brief Set default data sharing attribute to shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 247 | void setDefaultDSAShared(SourceLocation Loc) { |
| 248 | Stack.back().DefaultAttr = DSA_shared; |
| 249 | Stack.back().DefaultAttrLoc = Loc; |
| 250 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 251 | |
| 252 | DefaultDataSharingAttributes getDefaultDSA() const { |
| 253 | return Stack.back().DefaultAttr; |
| 254 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 255 | SourceLocation getDefaultDSALocation() const { |
| 256 | return Stack.back().DefaultAttrLoc; |
| 257 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 258 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 259 | /// \brief Checks if the specified variable is a threadprivate. |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 260 | bool isThreadPrivate(VarDecl *D) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 261 | DSAVarData DVar = getTopDSA(D, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 262 | return isOpenMPThreadPrivate(DVar.CKind); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 265 | /// \brief Marks current region as ordered (it has an 'ordered' clause). |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 266 | void setOrderedRegion(bool IsOrdered, Expr *Param) { |
| 267 | Stack.back().OrderedRegion.setInt(IsOrdered); |
| 268 | Stack.back().OrderedRegion.setPointer(Param); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 269 | } |
| 270 | /// \brief Returns true, if parent region is ordered (has associated |
| 271 | /// 'ordered' clause), false - otherwise. |
| 272 | bool isParentOrderedRegion() const { |
| 273 | if (Stack.size() > 2) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 274 | return Stack[Stack.size() - 2].OrderedRegion.getInt(); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 275 | return false; |
| 276 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 277 | /// \brief Returns optional parameter for the ordered region. |
| 278 | Expr *getParentOrderedRegionParam() const { |
| 279 | if (Stack.size() > 2) |
| 280 | return Stack[Stack.size() - 2].OrderedRegion.getPointer(); |
| 281 | return nullptr; |
| 282 | } |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 283 | /// \brief Marks current region as nowait (it has a 'nowait' clause). |
| 284 | void setNowaitRegion(bool IsNowait = true) { |
| 285 | Stack.back().NowaitRegion = IsNowait; |
| 286 | } |
| 287 | /// \brief Returns true, if parent region is nowait (has associated |
| 288 | /// 'nowait' clause), false - otherwise. |
| 289 | bool isParentNowaitRegion() const { |
| 290 | if (Stack.size() > 2) |
| 291 | return Stack[Stack.size() - 2].NowaitRegion; |
| 292 | return false; |
| 293 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 294 | /// \brief Marks parent region as cancel region. |
| 295 | void setParentCancelRegion(bool Cancel = true) { |
| 296 | if (Stack.size() > 2) |
| 297 | Stack[Stack.size() - 2].CancelRegion = |
| 298 | Stack[Stack.size() - 2].CancelRegion || Cancel; |
| 299 | } |
| 300 | /// \brief Return true if current region has inner cancel construct. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 301 | bool isCancelRegion() const { return Stack.back().CancelRegion; } |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 302 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 303 | /// \brief Set collapse value for the region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 304 | void setAssociatedLoops(unsigned Val) { Stack.back().AssociatedLoops = Val; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 305 | /// \brief Return collapse value for region. |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 306 | unsigned getAssociatedLoops() const { return Stack.back().AssociatedLoops; } |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 307 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 308 | /// \brief Marks current target region as one with closely nested teams |
| 309 | /// region. |
| 310 | void setParentTeamsRegionLoc(SourceLocation TeamsRegionLoc) { |
| 311 | if (Stack.size() > 2) |
| 312 | Stack[Stack.size() - 2].InnerTeamsRegionLoc = TeamsRegionLoc; |
| 313 | } |
| 314 | /// \brief Returns true, if current region has closely nested teams region. |
| 315 | bool hasInnerTeamsRegion() const { |
| 316 | return getInnerTeamsRegionLoc().isValid(); |
| 317 | } |
| 318 | /// \brief Returns location of the nested teams region (if any). |
| 319 | SourceLocation getInnerTeamsRegionLoc() const { |
| 320 | if (Stack.size() > 1) |
| 321 | return Stack.back().InnerTeamsRegionLoc; |
| 322 | return SourceLocation(); |
| 323 | } |
| 324 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 325 | Scope *getCurScope() const { return Stack.back().CurScope; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 326 | Scope *getCurScope() { return Stack.back().CurScope; } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 327 | SourceLocation getConstructLoc() { return Stack.back().ConstructLoc; } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 328 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 329 | // Do the check specified in \a Check to all component lists and return true |
| 330 | // if any issue is found. |
| 331 | bool checkMappableExprComponentListsForDecl( |
| 332 | ValueDecl *VD, bool CurrentRegionOnly, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 333 | const llvm::function_ref< |
| 334 | bool(OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 335 | OpenMPClauseKind)> &Check) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 336 | auto SI = Stack.rbegin(); |
| 337 | auto SE = Stack.rend(); |
| 338 | |
| 339 | if (SI == SE) |
| 340 | return false; |
| 341 | |
| 342 | if (CurrentRegionOnly) { |
| 343 | SE = std::next(SI); |
| 344 | } else { |
| 345 | ++SI; |
| 346 | } |
| 347 | |
| 348 | for (; SI != SE; ++SI) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 349 | auto MI = SI->MappedExprComponents.find(VD); |
| 350 | if (MI != SI->MappedExprComponents.end()) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 351 | for (auto &L : MI->second.Components) |
| 352 | if (Check(L, MI->second.Kind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 353 | return true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 354 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 355 | return false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 356 | } |
| 357 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 358 | // Create a new mappable expression component list associated with a given |
| 359 | // declaration and initialize it with the provided list of components. |
| 360 | void addMappableExpressionComponents( |
| 361 | ValueDecl *VD, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 362 | OMPClauseMappableExprCommon::MappableExprComponentListRef Components, |
| 363 | OpenMPClauseKind WhereFoundClauseKind) { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 364 | assert(Stack.size() > 1 && |
| 365 | "Not expecting to retrieve components from a empty stack!"); |
| 366 | auto &MEC = Stack.back().MappedExprComponents[VD]; |
| 367 | // Create new entry and append the new components there. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 368 | MEC.Components.resize(MEC.Components.size() + 1); |
| 369 | MEC.Components.back().append(Components.begin(), Components.end()); |
| 370 | MEC.Kind = WhereFoundClauseKind; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 371 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 372 | |
| 373 | unsigned getNestingLevel() const { |
| 374 | assert(Stack.size() > 1); |
| 375 | return Stack.size() - 2; |
| 376 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 377 | void addDoacrossDependClause(OMPDependClause *C, OperatorOffsetTy &OpsOffs) { |
| 378 | assert(Stack.size() > 2); |
| 379 | assert(isOpenMPWorksharingDirective(Stack[Stack.size() - 2].Directive)); |
| 380 | Stack[Stack.size() - 2].DoacrossDepends.insert({C, OpsOffs}); |
| 381 | } |
| 382 | llvm::iterator_range<DoacrossDependMapTy::const_iterator> |
| 383 | getDoacrossDependClauses() const { |
| 384 | assert(Stack.size() > 1); |
| 385 | if (isOpenMPWorksharingDirective(Stack[Stack.size() - 1].Directive)) { |
| 386 | auto &Ref = Stack[Stack.size() - 1].DoacrossDepends; |
| 387 | return llvm::make_range(Ref.begin(), Ref.end()); |
| 388 | } |
| 389 | return llvm::make_range(Stack[0].DoacrossDepends.end(), |
| 390 | Stack[0].DoacrossDepends.end()); |
| 391 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 392 | }; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 393 | bool isParallelOrTaskRegion(OpenMPDirectiveKind DKind) { |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 394 | return isOpenMPParallelDirective(DKind) || isOpenMPTaskingDirective(DKind) || |
| 395 | isOpenMPTeamsDirective(DKind) || DKind == OMPD_unknown; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 396 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 397 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 398 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 399 | static ValueDecl *getCanonicalDecl(ValueDecl *D) { |
| 400 | auto *VD = dyn_cast<VarDecl>(D); |
| 401 | auto *FD = dyn_cast<FieldDecl>(D); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 402 | if (VD != nullptr) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 403 | VD = VD->getCanonicalDecl(); |
| 404 | D = VD; |
| 405 | } else { |
| 406 | assert(FD); |
| 407 | FD = FD->getCanonicalDecl(); |
| 408 | D = FD; |
| 409 | } |
| 410 | return D; |
| 411 | } |
| 412 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 413 | DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator &Iter, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 414 | ValueDecl *D) { |
| 415 | D = getCanonicalDecl(D); |
| 416 | auto *VD = dyn_cast<VarDecl>(D); |
| 417 | auto *FD = dyn_cast<FieldDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 418 | DSAVarData DVar; |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 419 | if (Iter == std::prev(Stack.rend())) { |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 420 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 421 | // in a region but not in construct] |
| 422 | // File-scope or namespace-scope variables referenced in called routines |
| 423 | // in the region are shared unless they appear in a threadprivate |
| 424 | // directive. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 425 | if (VD && !VD->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D)) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 426 | DVar.CKind = OMPC_shared; |
| 427 | |
| 428 | // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced |
| 429 | // in a region but not in construct] |
| 430 | // Variables with static storage duration that are declared in called |
| 431 | // routines in the region are shared. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 432 | if (VD && VD->hasGlobalStorage()) |
| 433 | DVar.CKind = OMPC_shared; |
| 434 | |
| 435 | // Non-static data members are shared by default. |
| 436 | if (FD) |
Alexey Bataev | 750a58b | 2014-03-18 12:19:12 +0000 | [diff] [blame] | 437 | DVar.CKind = OMPC_shared; |
| 438 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 439 | return DVar; |
| 440 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 441 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 442 | DVar.DKind = Iter->Directive; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 443 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 444 | // in a Construct, C/C++, predetermined, p.1] |
| 445 | // Variables with automatic storage duration that are declared in a scope |
| 446 | // inside the construct are private. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 447 | if (VD && isOpenMPLocal(VD, Iter) && VD->isLocalVarDecl() && |
| 448 | (VD->getStorageClass() == SC_Auto || VD->getStorageClass() == SC_None)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 449 | DVar.CKind = OMPC_private; |
| 450 | return DVar; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 451 | } |
| 452 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 453 | // Explicitly specified attributes and local variables with predetermined |
| 454 | // attributes. |
| 455 | if (Iter->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 456 | DVar.RefExpr = Iter->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 457 | DVar.PrivateCopy = Iter->SharingMap[D].PrivateCopy; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 458 | DVar.CKind = Iter->SharingMap[D].Attributes; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 459 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 460 | return DVar; |
| 461 | } |
| 462 | |
| 463 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 464 | // in a Construct, C/C++, implicitly determined, p.1] |
| 465 | // In a parallel or task construct, the data-sharing attributes of these |
| 466 | // variables are determined by the default clause, if present. |
| 467 | switch (Iter->DefaultAttr) { |
| 468 | case DSA_shared: |
| 469 | DVar.CKind = OMPC_shared; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 470 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 471 | return DVar; |
| 472 | case DSA_none: |
| 473 | return DVar; |
| 474 | case DSA_unspecified: |
| 475 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 476 | // in a Construct, implicitly determined, p.2] |
| 477 | // In a parallel construct, if no default clause is present, these |
| 478 | // variables are shared. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 479 | DVar.ImplicitDSALoc = Iter->DefaultAttrLoc; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 480 | if (isOpenMPParallelDirective(DVar.DKind) || |
| 481 | isOpenMPTeamsDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 482 | DVar.CKind = OMPC_shared; |
| 483 | return DVar; |
| 484 | } |
| 485 | |
| 486 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 487 | // in a Construct, implicitly determined, p.4] |
| 488 | // In a task construct, if no default clause is present, a variable that in |
| 489 | // the enclosing context is determined to be shared by all implicit tasks |
| 490 | // bound to the current team is shared. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 491 | if (isOpenMPTaskingDirective(DVar.DKind)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 492 | DSAVarData DVarTemp; |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 493 | for (StackTy::reverse_iterator I = std::next(Iter), EE = Stack.rend(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 494 | I != EE; ++I) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 495 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 496 | // Referenced in a Construct, implicitly determined, p.6] |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 497 | // In a task construct, if no default clause is present, a variable |
| 498 | // whose data-sharing attribute is not determined by the rules above is |
| 499 | // firstprivate. |
| 500 | DVarTemp = getDSA(I, D); |
| 501 | if (DVarTemp.CKind != OMPC_shared) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 502 | DVar.RefExpr = nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 503 | DVar.CKind = OMPC_firstprivate; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 504 | return DVar; |
| 505 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 506 | if (isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 507 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 508 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 509 | DVar.CKind = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 510 | (DVarTemp.CKind == OMPC_unknown) ? OMPC_firstprivate : OMPC_shared; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 511 | return DVar; |
| 512 | } |
| 513 | } |
| 514 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 515 | // in a Construct, implicitly determined, p.3] |
| 516 | // For constructs other than task, if no default clause is present, these |
| 517 | // variables inherit their data-sharing attributes from the enclosing |
| 518 | // context. |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 519 | return getDSA(++Iter, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 522 | Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 523 | assert(Stack.size() > 1 && "Data sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 524 | D = getCanonicalDecl(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 525 | auto It = Stack.back().AlignedMap.find(D); |
| 526 | if (It == Stack.back().AlignedMap.end()) { |
| 527 | assert(NewDE && "Unexpected nullptr expr to be added into aligned map"); |
| 528 | Stack.back().AlignedMap[D] = NewDE; |
| 529 | return nullptr; |
| 530 | } else { |
| 531 | assert(It->second && "Unexpected nullptr expr in the aligned map"); |
| 532 | return It->second; |
| 533 | } |
| 534 | return nullptr; |
| 535 | } |
| 536 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 537 | void DSAStackTy::addLoopControlVariable(ValueDecl *D, VarDecl *Capture) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 538 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 539 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 540 | Stack.back().LCVMap.insert( |
| 541 | std::make_pair(D, LCDeclInfo(Stack.back().LCVMap.size() + 1, Capture))); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 544 | DSAStackTy::LCDeclInfo DSAStackTy::isLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 545 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 546 | D = getCanonicalDecl(D); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 547 | return Stack.back().LCVMap.count(D) > 0 ? Stack.back().LCVMap[D] |
| 548 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 551 | DSAStackTy::LCDeclInfo DSAStackTy::isParentLoopControlVariable(ValueDecl *D) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 552 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 553 | D = getCanonicalDecl(D); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 554 | return Stack[Stack.size() - 2].LCVMap.count(D) > 0 |
| 555 | ? Stack[Stack.size() - 2].LCVMap[D] |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 556 | : LCDeclInfo(0, nullptr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 557 | } |
| 558 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 559 | ValueDecl *DSAStackTy::getParentLoopControlVariable(unsigned I) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 560 | assert(Stack.size() > 2 && "Data-sharing attributes stack is empty"); |
| 561 | if (Stack[Stack.size() - 2].LCVMap.size() < I) |
| 562 | return nullptr; |
| 563 | for (auto &Pair : Stack[Stack.size() - 2].LCVMap) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 564 | if (Pair.second.first == I) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 565 | return Pair.first; |
| 566 | } |
| 567 | return nullptr; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 568 | } |
| 569 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 570 | void DSAStackTy::addDSA(ValueDecl *D, Expr *E, OpenMPClauseKind A, |
| 571 | DeclRefExpr *PrivateCopy) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 572 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 573 | if (A == OMPC_threadprivate) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 574 | auto &Data = Stack[0].SharingMap[D]; |
| 575 | Data.Attributes = A; |
| 576 | Data.RefExpr.setPointer(E); |
| 577 | Data.PrivateCopy = nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 578 | } else { |
| 579 | assert(Stack.size() > 1 && "Data-sharing attributes stack is empty"); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 580 | auto &Data = Stack.back().SharingMap[D]; |
| 581 | assert(Data.Attributes == OMPC_unknown || (A == Data.Attributes) || |
| 582 | (A == OMPC_firstprivate && Data.Attributes == OMPC_lastprivate) || |
| 583 | (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) || |
| 584 | (isLoopControlVariable(D).first && A == OMPC_private)); |
| 585 | if (A == OMPC_lastprivate && Data.Attributes == OMPC_firstprivate) { |
| 586 | Data.RefExpr.setInt(/*IntVal=*/true); |
| 587 | return; |
| 588 | } |
| 589 | const bool IsLastprivate = |
| 590 | A == OMPC_lastprivate || Data.Attributes == OMPC_lastprivate; |
| 591 | Data.Attributes = A; |
| 592 | Data.RefExpr.setPointerAndInt(E, IsLastprivate); |
| 593 | Data.PrivateCopy = PrivateCopy; |
| 594 | if (PrivateCopy) { |
| 595 | auto &Data = Stack.back().SharingMap[PrivateCopy->getDecl()]; |
| 596 | Data.Attributes = A; |
| 597 | Data.RefExpr.setPointerAndInt(PrivateCopy, IsLastprivate); |
| 598 | Data.PrivateCopy = nullptr; |
| 599 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 603 | bool DSAStackTy::isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter) { |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 604 | D = D->getCanonicalDecl(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 605 | if (Stack.size() > 2) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 606 | reverse_iterator I = Iter, E = std::prev(Stack.rend()); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 607 | Scope *TopScope = nullptr; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 608 | while (I != E && !isParallelOrTaskRegion(I->Directive)) { |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 609 | ++I; |
| 610 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 611 | if (I == E) |
| 612 | return false; |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 613 | TopScope = I->CurScope ? I->CurScope->getParent() : nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 614 | Scope *CurScope = getCurScope(); |
| 615 | while (CurScope != TopScope && !CurScope->isDeclScope(D)) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | CurScope = CurScope->getParent(); |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 617 | } |
| 618 | return CurScope != TopScope; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 619 | } |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 620 | return false; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 623 | /// \brief Build a variable declaration for OpenMP loop iteration variable. |
| 624 | static VarDecl *buildVarDecl(Sema &SemaRef, SourceLocation Loc, QualType Type, |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 625 | StringRef Name, const AttrVec *Attrs = nullptr) { |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 626 | DeclContext *DC = SemaRef.CurContext; |
| 627 | IdentifierInfo *II = &SemaRef.PP.getIdentifierTable().get(Name); |
| 628 | TypeSourceInfo *TInfo = SemaRef.Context.getTrivialTypeSourceInfo(Type, Loc); |
| 629 | VarDecl *Decl = |
| 630 | VarDecl::Create(SemaRef.Context, DC, Loc, Loc, II, Type, TInfo, SC_None); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 631 | if (Attrs) { |
| 632 | for (specific_attr_iterator<AlignedAttr> I(Attrs->begin()), E(Attrs->end()); |
| 633 | I != E; ++I) |
| 634 | Decl->addAttr(*I); |
| 635 | } |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 636 | Decl->setImplicit(); |
| 637 | return Decl; |
| 638 | } |
| 639 | |
| 640 | static DeclRefExpr *buildDeclRefExpr(Sema &S, VarDecl *D, QualType Ty, |
| 641 | SourceLocation Loc, |
| 642 | bool RefersToCapture = false) { |
| 643 | D->setReferenced(); |
| 644 | D->markUsed(S.Context); |
| 645 | return DeclRefExpr::Create(S.getASTContext(), NestedNameSpecifierLoc(), |
| 646 | SourceLocation(), D, RefersToCapture, Loc, Ty, |
| 647 | VK_LValue); |
| 648 | } |
| 649 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 650 | DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) { |
| 651 | D = getCanonicalDecl(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 652 | DSAVarData DVar; |
| 653 | |
| 654 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 655 | // in a Construct, C/C++, predetermined, p.1] |
| 656 | // Variables appearing in threadprivate directives are threadprivate. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 657 | auto *VD = dyn_cast<VarDecl>(D); |
| 658 | if ((VD && VD->getTLSKind() != VarDecl::TLS_None && |
| 659 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 660 | SemaRef.getLangOpts().OpenMPUseTLS && |
| 661 | SemaRef.getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 662 | (VD && VD->getStorageClass() == SC_Register && |
| 663 | VD->hasAttr<AsmLabelAttr>() && !VD->isLocalVarDecl())) { |
| 664 | addDSA(D, buildDeclRefExpr(SemaRef, VD, D->getType().getNonReferenceType(), |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 665 | D->getLocation()), |
Alexey Bataev | f2453a0 | 2015-05-06 07:25:08 +0000 | [diff] [blame] | 666 | OMPC_threadprivate); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 667 | } |
| 668 | if (Stack[0].SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 669 | DVar.RefExpr = Stack[0].SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 670 | DVar.CKind = OMPC_threadprivate; |
| 671 | return DVar; |
| 672 | } |
| 673 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 674 | if (Stack.size() == 1) { |
| 675 | // Not in OpenMP execution region and top scope was already checked. |
| 676 | return DVar; |
| 677 | } |
| 678 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 679 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 680 | // in a Construct, C/C++, predetermined, p.4] |
| 681 | // Static data members are shared. |
| 682 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 683 | // in a Construct, C/C++, predetermined, p.7] |
| 684 | // Variables with static storage duration that are declared in a scope |
| 685 | // inside the construct are shared. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 686 | auto &&MatchesAlways = [](OpenMPDirectiveKind) -> bool { return true; }; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 687 | if (VD && VD->isStaticDataMember()) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 688 | DSAVarData DVarTemp = hasDSA(D, isOpenMPPrivate, MatchesAlways, FromParent); |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 689 | if (DVarTemp.CKind != OMPC_unknown && DVarTemp.RefExpr) |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 690 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 691 | |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 692 | DVar.CKind = OMPC_shared; |
| 693 | return DVar; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | QualType Type = D->getType().getNonReferenceType().getCanonicalType(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 697 | bool IsConstant = Type.isConstant(SemaRef.getASTContext()); |
| 698 | Type = SemaRef.getASTContext().getBaseElementType(Type); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 699 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 700 | // in a Construct, C/C++, predetermined, p.6] |
| 701 | // Variables with const qualified type having no mutable member are |
| 702 | // shared. |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 703 | CXXRecordDecl *RD = |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 704 | SemaRef.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : nullptr; |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 705 | if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RD)) |
| 706 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 707 | RD = CTD->getTemplatedDecl(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 708 | if (IsConstant && |
Alexey Bataev | 4bcad7f | 2016-02-10 10:50:12 +0000 | [diff] [blame] | 709 | !(SemaRef.getLangOpts().CPlusPlus && RD && RD->hasDefinition() && |
| 710 | RD->hasMutableFields())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 711 | // Variables with const-qualified type having no mutable member may be |
| 712 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 713 | DSAVarData DVarTemp = hasDSA( |
| 714 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; }, |
| 715 | MatchesAlways, FromParent); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 716 | if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) |
| 717 | return DVar; |
| 718 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 719 | DVar.CKind = OMPC_shared; |
| 720 | return DVar; |
| 721 | } |
| 722 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 723 | // Explicitly specified attributes and local variables with predetermined |
| 724 | // attributes. |
Alexey Bataev | dffa93a | 2015-12-10 08:20:58 +0000 | [diff] [blame] | 725 | auto StartI = std::next(Stack.rbegin()); |
| 726 | auto EndI = std::prev(Stack.rend()); |
| 727 | if (FromParent && StartI != EndI) { |
| 728 | StartI = std::next(StartI); |
| 729 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 730 | auto I = std::prev(StartI); |
| 731 | if (I->SharingMap.count(D)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 732 | DVar.RefExpr = I->SharingMap[D].RefExpr.getPointer(); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 733 | DVar.PrivateCopy = I->SharingMap[D].PrivateCopy; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 734 | DVar.CKind = I->SharingMap[D].Attributes; |
| 735 | DVar.ImplicitDSALoc = I->DefaultAttrLoc; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | return DVar; |
| 739 | } |
| 740 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 741 | DSAStackTy::DSAVarData DSAStackTy::getImplicitDSA(ValueDecl *D, |
| 742 | bool FromParent) { |
| 743 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 744 | auto StartI = Stack.rbegin(); |
| 745 | auto EndI = std::prev(Stack.rend()); |
| 746 | if (FromParent && StartI != EndI) { |
| 747 | StartI = std::next(StartI); |
| 748 | } |
| 749 | return getDSA(StartI, D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 750 | } |
| 751 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 752 | DSAStackTy::DSAVarData |
| 753 | DSAStackTy::hasDSA(ValueDecl *D, |
| 754 | const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 755 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 756 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 757 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 758 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 759 | auto EndI = Stack.rend(); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 760 | if (FromParent && StartI != EndI) { |
| 761 | StartI = std::next(StartI); |
| 762 | } |
| 763 | for (auto I = StartI, EE = EndI; I != EE; ++I) { |
| 764 | if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive)) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 765 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 766 | DSAVarData DVar = getDSA(I, D); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 767 | if (CPred(DVar.CKind)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 768 | return DVar; |
| 769 | } |
| 770 | return DSAVarData(); |
| 771 | } |
| 772 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 773 | DSAStackTy::DSAVarData DSAStackTy::hasInnermostDSA( |
| 774 | ValueDecl *D, const llvm::function_ref<bool(OpenMPClauseKind)> &CPred, |
| 775 | const llvm::function_ref<bool(OpenMPDirectiveKind)> &DPred, |
| 776 | bool FromParent) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 777 | D = getCanonicalDecl(D); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 778 | auto StartI = std::next(Stack.rbegin()); |
Dmitry Polukhin | dc78bc82 | 2016-04-01 09:52:30 +0000 | [diff] [blame] | 779 | auto EndI = Stack.rend(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 780 | if (FromParent && StartI != EndI) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 781 | StartI = std::next(StartI); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 782 | if (StartI == EndI || !DPred(StartI->Directive)) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 783 | return DSAVarData(); |
Alexey Bataev | e397812 | 2016-07-19 05:06:39 +0000 | [diff] [blame] | 784 | DSAVarData DVar = getDSA(StartI, D); |
| 785 | return CPred(DVar.CKind) ? DVar : DSAVarData(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 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 | if (Ty->isReferenceType()) |
| 907 | Ty = Ty->castAs<ReferenceType>()->getPointeeType(); |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 908 | |
| 909 | // Locate map clauses and see if the variable being captured is referred to |
| 910 | // in any of those clauses. Here we only care about variables, not fields, |
| 911 | // because fields are part of aggregates. |
| 912 | bool IsVariableUsedInMapClause = false; |
| 913 | bool IsVariableAssociatedWithSection = false; |
| 914 | |
| 915 | DSAStack->checkMappableExprComponentListsForDecl( |
| 916 | D, /*CurrentRegionOnly=*/true, |
| 917 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 918 | MapExprComponents, |
| 919 | OpenMPClauseKind WhereFoundClauseKind) { |
| 920 | // Only the map clause information influences how a variable is |
| 921 | // captured. E.g. is_device_ptr does not require changing the default |
| 922 | // behaviour. |
| 923 | if (WhereFoundClauseKind != OMPC_map) |
| 924 | return false; |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 925 | |
| 926 | auto EI = MapExprComponents.rbegin(); |
| 927 | auto EE = MapExprComponents.rend(); |
| 928 | |
| 929 | assert(EI != EE && "Invalid map expression!"); |
| 930 | |
| 931 | if (isa<DeclRefExpr>(EI->getAssociatedExpression())) |
| 932 | IsVariableUsedInMapClause |= EI->getAssociatedDeclaration() == D; |
| 933 | |
| 934 | ++EI; |
| 935 | if (EI == EE) |
| 936 | return false; |
| 937 | |
| 938 | if (isa<ArraySubscriptExpr>(EI->getAssociatedExpression()) || |
| 939 | isa<OMPArraySectionExpr>(EI->getAssociatedExpression()) || |
| 940 | isa<MemberExpr>(EI->getAssociatedExpression())) { |
| 941 | IsVariableAssociatedWithSection = true; |
| 942 | // There is nothing more we need to know about this variable. |
| 943 | return true; |
| 944 | } |
| 945 | |
| 946 | // Keep looking for more map info. |
| 947 | return false; |
| 948 | }); |
| 949 | |
| 950 | if (IsVariableUsedInMapClause) { |
| 951 | // If variable is identified in a map clause it is always captured by |
| 952 | // reference except if it is a pointer that is dereferenced somehow. |
| 953 | IsByRef = !(Ty->isPointerType() && IsVariableAssociatedWithSection); |
| 954 | } else { |
| 955 | // By default, all the data that has a scalar type is mapped by copy. |
| 956 | IsByRef = !Ty->isScalarType(); |
| 957 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 958 | } |
| 959 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 960 | if (IsByRef && Ty.getNonReferenceType()->isScalarType()) { |
| 961 | IsByRef = !DSAStack->hasExplicitDSA( |
| 962 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_firstprivate; }, |
| 963 | Level, /*NotLastprivate=*/true); |
| 964 | } |
| 965 | |
Samuel Antao | 86ace55 | 2016-04-27 22:40:57 +0000 | [diff] [blame] | 966 | // 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] | 967 | // and alignment, because the runtime library only deals with uintptr types. |
| 968 | // If it does not fit the uintptr size, we need to pass the data by reference |
| 969 | // instead. |
| 970 | if (!IsByRef && |
| 971 | (Ctx.getTypeSizeInChars(Ty) > |
| 972 | Ctx.getTypeSizeInChars(Ctx.getUIntPtrType()) || |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 973 | Ctx.getDeclAlign(D) > Ctx.getTypeAlignInChars(Ctx.getUIntPtrType()))) { |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 974 | IsByRef = true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 975 | } |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 976 | |
| 977 | return IsByRef; |
| 978 | } |
| 979 | |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 980 | unsigned Sema::getOpenMPNestingLevel() const { |
| 981 | assert(getLangOpts().OpenMP); |
| 982 | return DSAStack->getNestingLevel(); |
| 983 | } |
| 984 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 985 | VarDecl *Sema::IsOpenMPCapturedDecl(ValueDecl *D) { |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 986 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 987 | D = getCanonicalDecl(D); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 988 | |
| 989 | // If we are attempting to capture a global variable in a directive with |
| 990 | // 'target' we return true so that this global is also mapped to the device. |
| 991 | // |
| 992 | // FIXME: If the declaration is enclosed in a 'declare target' directive, |
| 993 | // then it should not be captured. Therefore, an extra check has to be |
| 994 | // inserted here once support for 'declare target' is added. |
| 995 | // |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 996 | auto *VD = dyn_cast<VarDecl>(D); |
| 997 | if (VD && !VD->hasLocalStorage()) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 998 | if (DSAStack->getCurrentDirective() == OMPD_target && |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 999 | !DSAStack->isClauseParsingMode()) |
| 1000 | return VD; |
Samuel Antao | f0d7975 | 2016-05-27 15:21:27 +0000 | [diff] [blame] | 1001 | if (DSAStack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1002 | [](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 1003 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1004 | return isOpenMPTargetExecutionDirective(K); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1005 | }, |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1006 | false)) |
| 1007 | return VD; |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
Alexey Bataev | 48977c3 | 2015-08-04 08:10:48 +0000 | [diff] [blame] | 1010 | if (DSAStack->getCurrentDirective() != OMPD_unknown && |
| 1011 | (!DSAStack->isClauseParsingMode() || |
| 1012 | DSAStack->getParentDirective() != OMPD_unknown)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1013 | auto &&Info = DSAStack->isLoopControlVariable(D); |
| 1014 | if (Info.first || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1015 | (VD && VD->hasLocalStorage() && |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1016 | isParallelOrTaskRegion(DSAStack->getCurrentDirective())) || |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1017 | (VD && DSAStack->isForceVarCapturing())) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 1018 | return VD ? VD : Info.second; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1019 | auto DVarPrivate = DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1020 | if (DVarPrivate.CKind != OMPC_unknown && isOpenMPPrivate(DVarPrivate.CKind)) |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1021 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1022 | DVarPrivate = DSAStack->hasDSA( |
| 1023 | D, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 1024 | DSAStack->isClauseParsingMode()); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1025 | if (DVarPrivate.CKind != OMPC_unknown) |
| 1026 | return VD ? VD : cast<VarDecl>(DVarPrivate.PrivateCopy->getDecl()); |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1027 | } |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 1028 | return nullptr; |
Alexey Bataev | f841bd9 | 2014-12-16 07:00:22 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1031 | bool Sema::isOpenMPPrivateDecl(ValueDecl *D, unsigned Level) { |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1032 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1033 | return DSAStack->hasExplicitDSA( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1034 | D, [](OpenMPClauseKind K) -> bool { return K == OMPC_private; }, Level); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1037 | bool Sema::isOpenMPTargetCapturedDecl(ValueDecl *D, unsigned Level) { |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1038 | assert(LangOpts.OpenMP && "OpenMP is not allowed"); |
| 1039 | // Return true if the current level is no longer enclosed in a target region. |
| 1040 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1041 | auto *VD = dyn_cast<VarDecl>(D); |
| 1042 | return VD && !VD->hasLocalStorage() && |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1043 | DSAStack->hasExplicitDirective(isOpenMPTargetExecutionDirective, |
| 1044 | Level); |
Samuel Antao | 4be30e9 | 2015-10-02 17:14:03 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1047 | void Sema::DestroyDataSharingAttributesStack() { delete DSAStack; } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1048 | |
| 1049 | void Sema::StartOpenMPDSABlock(OpenMPDirectiveKind DKind, |
| 1050 | const DeclarationNameInfo &DirName, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1051 | Scope *CurScope, SourceLocation Loc) { |
| 1052 | DSAStack->push(DKind, DirName, CurScope, Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1053 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 1054 | } |
| 1055 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1056 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1057 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1060 | void Sema::EndOpenMPClause() { |
| 1061 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1064 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1065 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1066 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1067 | // clause requires an accessible, unambiguous default constructor for the |
| 1068 | // class type, unless the list item is also specified in a firstprivate |
| 1069 | // clause. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1070 | if (auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1071 | for (auto *C : D->clauses()) { |
| 1072 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1073 | SmallVector<Expr *, 8> PrivateCopies; |
| 1074 | for (auto *DE : Clause->varlists()) { |
| 1075 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1076 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1077 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1078 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1079 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1080 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1081 | QualType Type = VD->getType().getNonReferenceType(); |
| 1082 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1083 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1084 | // Generate helper private variable and initialize it with the |
| 1085 | // default value. The address of the original variable is replaced |
| 1086 | // by the address of the new private variable in CodeGen. This new |
| 1087 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1088 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1089 | auto *VDPrivate = buildVarDecl( |
| 1090 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1091 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1092 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
| 1093 | if (VDPrivate->isInvalidDecl()) |
| 1094 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1095 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1096 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1097 | } else { |
| 1098 | // The variable is also a firstprivate, so initialization sequence |
| 1099 | // for private copy is generated already. |
| 1100 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1103 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1104 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1105 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1110 | DSAStack->pop(); |
| 1111 | DiscardCleanupsInEvaluationContext(); |
| 1112 | PopExpressionEvaluationContext(); |
| 1113 | } |
| 1114 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1115 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1116 | Expr *NumIterations, Sema &SemaRef, |
| 1117 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1118 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1119 | namespace { |
| 1120 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1121 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1122 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1123 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1124 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1125 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1126 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1127 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1128 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1129 | if (auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1130 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1131 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1132 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1133 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1135 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1136 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1137 | |
| 1138 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1139 | private: |
| 1140 | Sema &SemaRef; |
| 1141 | |
| 1142 | public: |
| 1143 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1144 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1145 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1146 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1147 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1148 | SemaRef.getCurScope()); |
| 1149 | } |
| 1150 | return false; |
| 1151 | } |
| 1152 | }; |
| 1153 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1154 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1155 | |
| 1156 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1157 | CXXScopeSpec &ScopeSpec, |
| 1158 | const DeclarationNameInfo &Id) { |
| 1159 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1160 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1161 | |
| 1162 | if (Lookup.isAmbiguous()) |
| 1163 | return ExprError(); |
| 1164 | |
| 1165 | VarDecl *VD; |
| 1166 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1167 | if (TypoCorrection Corrected = CorrectTypo( |
| 1168 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1169 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1170 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1171 | PDiag(Lookup.empty() |
| 1172 | ? diag::err_undeclared_var_use_suggest |
| 1173 | : diag::err_omp_expected_var_arg_suggest) |
| 1174 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1175 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1176 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1177 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1178 | : diag::err_omp_expected_var_arg) |
| 1179 | << Id.getName(); |
| 1180 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1181 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1182 | } else { |
| 1183 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1184 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1185 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1186 | return ExprError(); |
| 1187 | } |
| 1188 | } |
| 1189 | Lookup.suppressDiagnostics(); |
| 1190 | |
| 1191 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1192 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1193 | if (!VD->hasGlobalStorage()) { |
| 1194 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1195 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1196 | bool IsDecl = |
| 1197 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1198 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1199 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1200 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1201 | return ExprError(); |
| 1202 | } |
| 1203 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1204 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1205 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1206 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1207 | // A threadprivate directive for file-scope variables must appear outside |
| 1208 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1209 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1210 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1211 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1212 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1213 | bool IsDecl = |
| 1214 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1215 | Diag(VD->getLocation(), |
| 1216 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1217 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1218 | return ExprError(); |
| 1219 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1220 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1221 | // A threadprivate directive for static class member variables must appear |
| 1222 | // in the class definition, in the same scope in which the member |
| 1223 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1224 | if (CanonicalVD->isStaticDataMember() && |
| 1225 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1226 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1227 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1228 | bool IsDecl = |
| 1229 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1230 | Diag(VD->getLocation(), |
| 1231 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1232 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1233 | return ExprError(); |
| 1234 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1235 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1236 | // A threadprivate directive for namespace-scope variables must appear |
| 1237 | // outside any definition or declaration other than the namespace |
| 1238 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1239 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1240 | (!getCurLexicalContext()->isFileContext() || |
| 1241 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1242 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1243 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1244 | bool IsDecl = |
| 1245 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1246 | Diag(VD->getLocation(), |
| 1247 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1248 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1249 | return ExprError(); |
| 1250 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1251 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1252 | // A threadprivate directive for static block-scope variables must appear |
| 1253 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1254 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1255 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1256 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1257 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1258 | bool IsDecl = |
| 1259 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1260 | Diag(VD->getLocation(), |
| 1261 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1262 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1263 | return ExprError(); |
| 1264 | } |
| 1265 | |
| 1266 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1267 | // A threadprivate directive must lexically precede all references to any |
| 1268 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1269 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1270 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1271 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1272 | return ExprError(); |
| 1273 | } |
| 1274 | |
| 1275 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1276 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1277 | SourceLocation(), VD, |
| 1278 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1279 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1282 | Sema::DeclGroupPtrTy |
| 1283 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1284 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1285 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1286 | CurContext->addDecl(D); |
| 1287 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1288 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1289 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1292 | namespace { |
| 1293 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1294 | Sema &SemaRef; |
| 1295 | |
| 1296 | public: |
| 1297 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1298 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1299 | if (VD->hasLocalStorage()) { |
| 1300 | SemaRef.Diag(E->getLocStart(), |
| 1301 | diag::err_omp_local_var_in_threadprivate_init) |
| 1302 | << E->getSourceRange(); |
| 1303 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1304 | << VD << VD->getSourceRange(); |
| 1305 | return true; |
| 1306 | } |
| 1307 | } |
| 1308 | return false; |
| 1309 | } |
| 1310 | bool VisitStmt(const Stmt *S) { |
| 1311 | for (auto Child : S->children()) { |
| 1312 | if (Child && Visit(Child)) |
| 1313 | return true; |
| 1314 | } |
| 1315 | return false; |
| 1316 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1317 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1318 | }; |
| 1319 | } // namespace |
| 1320 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1321 | OMPThreadPrivateDecl * |
| 1322 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1323 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1324 | for (auto &RefExpr : VarList) { |
| 1325 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1326 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1327 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1328 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1329 | // Mark variable as used. |
| 1330 | VD->setReferenced(); |
| 1331 | VD->markUsed(Context); |
| 1332 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1333 | QualType QType = VD->getType(); |
| 1334 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1335 | // It will be analyzed later. |
| 1336 | Vars.push_back(DE); |
| 1337 | continue; |
| 1338 | } |
| 1339 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1340 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1341 | // A threadprivate variable must not have an incomplete type. |
| 1342 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1343 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1344 | continue; |
| 1345 | } |
| 1346 | |
| 1347 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1348 | // A threadprivate variable must not have a reference type. |
| 1349 | if (VD->getType()->isReferenceType()) { |
| 1350 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1351 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1352 | bool IsDecl = |
| 1353 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1354 | Diag(VD->getLocation(), |
| 1355 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1356 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1357 | continue; |
| 1358 | } |
| 1359 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1360 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1361 | // the corresponding diagnostic. |
| 1362 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1363 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1364 | getLangOpts().OpenMPUseTLS && |
| 1365 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1366 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1367 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1368 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1369 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1370 | bool IsDecl = |
| 1371 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1372 | Diag(VD->getLocation(), |
| 1373 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1374 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1375 | continue; |
| 1376 | } |
| 1377 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1378 | // Check if initial value of threadprivate variable reference variable with |
| 1379 | // local storage (it is not supported by runtime). |
| 1380 | if (auto Init = VD->getAnyInitializer()) { |
| 1381 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1382 | if (Checker.Visit(Init)) |
| 1383 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1386 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1387 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1388 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1389 | Context, SourceRange(Loc, Loc))); |
| 1390 | if (auto *ML = Context.getASTMutationListener()) |
| 1391 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1392 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1393 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1394 | if (!Vars.empty()) { |
| 1395 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1396 | Vars); |
| 1397 | D->setAccess(AS_public); |
| 1398 | } |
| 1399 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1400 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1401 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1402 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1403 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1404 | bool IsLoopIterVar = false) { |
| 1405 | if (DVar.RefExpr) { |
| 1406 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1407 | << getOpenMPClauseName(DVar.CKind); |
| 1408 | return; |
| 1409 | } |
| 1410 | enum { |
| 1411 | PDSA_StaticMemberShared, |
| 1412 | PDSA_StaticLocalVarShared, |
| 1413 | PDSA_LoopIterVarPrivate, |
| 1414 | PDSA_LoopIterVarLinear, |
| 1415 | PDSA_LoopIterVarLastprivate, |
| 1416 | PDSA_ConstVarShared, |
| 1417 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1418 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1419 | PDSA_LocalVarPrivate, |
| 1420 | PDSA_Implicit |
| 1421 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1422 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1423 | auto ReportLoc = D->getLocation(); |
| 1424 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1425 | if (IsLoopIterVar) { |
| 1426 | if (DVar.CKind == OMPC_private) |
| 1427 | Reason = PDSA_LoopIterVarPrivate; |
| 1428 | else if (DVar.CKind == OMPC_lastprivate) |
| 1429 | Reason = PDSA_LoopIterVarLastprivate; |
| 1430 | else |
| 1431 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1432 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1433 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1434 | Reason = PDSA_TaskVarFirstprivate; |
| 1435 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1436 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1437 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1438 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1439 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1440 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1441 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1442 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1443 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1444 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1445 | ReportHint = true; |
| 1446 | Reason = PDSA_LocalVarPrivate; |
| 1447 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1448 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1449 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1450 | << Reason << ReportHint |
| 1451 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1452 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1453 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1454 | << getOpenMPClauseName(DVar.CKind); |
| 1455 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1458 | namespace { |
| 1459 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1460 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1461 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1462 | bool ErrorFound; |
| 1463 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1464 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1465 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1466 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1467 | public: |
| 1468 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1469 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1470 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1471 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1472 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1473 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1474 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1475 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1477 | auto DVar = Stack->getTopDSA(VD, false); |
| 1478 | // Check if the variable has explicit DSA set and stop analysis if it so. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1479 | if (DVar.RefExpr) |
| 1480 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1481 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1482 | auto ELoc = E->getExprLoc(); |
| 1483 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1484 | // The default(none) clause requires that each variable that is referenced |
| 1485 | // in the construct, and does not have a predetermined data-sharing |
| 1486 | // attribute, must have its data-sharing attribute explicitly determined |
| 1487 | // by being listed in a data-sharing attribute clause. |
| 1488 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1489 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1490 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1491 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1496 | // A list item that appears in a reduction clause of the innermost |
| 1497 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1498 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1499 | DVar = Stack->hasInnermostDSA( |
| 1500 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1501 | [](OpenMPDirectiveKind K) -> bool { |
| 1502 | return isOpenMPParallelDirective(K) || |
| 1503 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1504 | }, |
| 1505 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1506 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1507 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1508 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1509 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1510 | return; |
| 1511 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1512 | |
| 1513 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1514 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1515 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1516 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1517 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1518 | } |
| 1519 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1520 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1521 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1522 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1523 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1524 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1525 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1526 | auto DVar = Stack->getTopDSA(FD, false); |
| 1527 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1528 | // so. |
| 1529 | if (DVar.RefExpr) |
| 1530 | return; |
| 1531 | |
| 1532 | auto ELoc = E->getExprLoc(); |
| 1533 | auto DKind = Stack->getCurrentDirective(); |
| 1534 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1535 | // A list item that appears in a reduction clause of the innermost |
| 1536 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1537 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1538 | DVar = Stack->hasInnermostDSA( |
| 1539 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1540 | [](OpenMPDirectiveKind K) -> bool { |
| 1541 | return isOpenMPParallelDirective(K) || |
| 1542 | isOpenMPWorksharingDirective(K) || |
| 1543 | isOpenMPTeamsDirective(K); |
| 1544 | }, |
| 1545 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1546 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1547 | ErrorFound = true; |
| 1548 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1549 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | // Define implicit data-sharing attributes for task. |
| 1554 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1555 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1556 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1557 | ImplicitFirstprivate.push_back(E); |
| 1558 | } |
| 1559 | } |
| 1560 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1561 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1562 | for (auto *C : S->clauses()) { |
| 1563 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1564 | // for task directives. |
| 1565 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1566 | for (auto *CC : C->children()) { |
| 1567 | if (CC) |
| 1568 | Visit(CC); |
| 1569 | } |
| 1570 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1571 | } |
| 1572 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1573 | for (auto *C : S->children()) { |
| 1574 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1575 | Visit(C); |
| 1576 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1577 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1578 | |
| 1579 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1580 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1581 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1582 | return VarsWithInheritedDSA; |
| 1583 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1584 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1585 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1586 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1587 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1588 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1589 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1590 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1591 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1592 | case OMPD_parallel: |
| 1593 | case OMPD_parallel_for: |
| 1594 | case OMPD_parallel_for_simd: |
| 1595 | case OMPD_parallel_sections: |
| 1596 | case OMPD_teams: { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1597 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1598 | QualType KmpInt32PtrTy = |
| 1599 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
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(".global_tid.", KmpInt32PtrTy), |
| 1602 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1603 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1604 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1605 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1606 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1607 | break; |
| 1608 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1609 | case OMPD_simd: |
| 1610 | case OMPD_for: |
| 1611 | case OMPD_for_simd: |
| 1612 | case OMPD_sections: |
| 1613 | case OMPD_section: |
| 1614 | case OMPD_single: |
| 1615 | case OMPD_master: |
| 1616 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1617 | case OMPD_taskgroup: |
| 1618 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1619 | case OMPD_ordered: |
| 1620 | case OMPD_atomic: |
| 1621 | case OMPD_target_data: |
| 1622 | case OMPD_target: |
| 1623 | case OMPD_target_parallel: |
| 1624 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1625 | case OMPD_target_parallel_for_simd: |
| 1626 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1627 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1628 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1629 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1630 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1631 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1632 | break; |
| 1633 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1634 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1635 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1636 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1637 | FunctionProtoType::ExtProtoInfo EPI; |
| 1638 | EPI.Variadic = true; |
| 1639 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1640 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1641 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1642 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1643 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1644 | std::make_pair(".copy_fn.", |
| 1645 | Context.getPointerType(CopyFnType).withConst()), |
| 1646 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1647 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1648 | }; |
| 1649 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1650 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1651 | // Mark this captured region as inlined, because we don't use outlined |
| 1652 | // function directly. |
| 1653 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1654 | AlwaysInlineAttr::CreateImplicit( |
| 1655 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1656 | break; |
| 1657 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1658 | case OMPD_taskloop: |
| 1659 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1660 | QualType KmpInt32Ty = |
| 1661 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1662 | QualType KmpUInt64Ty = |
| 1663 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1664 | QualType KmpInt64Ty = |
| 1665 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1666 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1667 | FunctionProtoType::ExtProtoInfo EPI; |
| 1668 | EPI.Variadic = true; |
| 1669 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1670 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1671 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1672 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1673 | std::make_pair(".privates.", |
| 1674 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1675 | std::make_pair( |
| 1676 | ".copy_fn.", |
| 1677 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1678 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1679 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1680 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1681 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1682 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1683 | }; |
| 1684 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1685 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1686 | // Mark this captured region as inlined, because we don't use outlined |
| 1687 | // function directly. |
| 1688 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1689 | AlwaysInlineAttr::CreateImplicit( |
| 1690 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1691 | break; |
| 1692 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1693 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1694 | case OMPD_distribute_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1695 | case OMPD_distribute_parallel_for: |
Diana Picus | 8b44bbc | 2016-08-18 09:25:07 +0000 | [diff] [blame] | 1696 | case OMPD_teams_distribute: { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1697 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1698 | QualType KmpInt32PtrTy = |
| 1699 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1700 | Sema::CapturedParamNameType Params[] = { |
| 1701 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1702 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1703 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1704 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1705 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1706 | }; |
| 1707 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1708 | Params); |
| 1709 | break; |
| 1710 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1711 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1712 | case OMPD_taskyield: |
| 1713 | case OMPD_barrier: |
| 1714 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1715 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1716 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1717 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1718 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1719 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1720 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1721 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1722 | case OMPD_declare_target: |
| 1723 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1724 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1725 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1726 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1727 | llvm_unreachable("Unknown OpenMP directive"); |
| 1728 | } |
| 1729 | } |
| 1730 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1731 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1732 | Expr *CaptureExpr, bool WithInit, |
| 1733 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1734 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1735 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1736 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1737 | QualType Ty = Init->getType(); |
| 1738 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1739 | if (S.getLangOpts().CPlusPlus) |
| 1740 | Ty = C.getLValueReferenceType(Ty); |
| 1741 | else { |
| 1742 | Ty = C.getPointerType(Ty); |
| 1743 | ExprResult Res = |
| 1744 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1745 | if (!Res.isUsable()) |
| 1746 | return nullptr; |
| 1747 | Init = Res.get(); |
| 1748 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1749 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1750 | } |
| 1751 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1752 | if (!WithInit) |
| 1753 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1754 | S.CurContext->addHiddenDecl(CED); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1755 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false, |
| 1756 | /*TypeMayContainAuto=*/true); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1757 | return CED; |
| 1758 | } |
| 1759 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1760 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1761 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1762 | OMPCapturedExprDecl *CD; |
| 1763 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1764 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1765 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1766 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1767 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1768 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1769 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1772 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1773 | if (!Ref) { |
| 1774 | auto *CD = |
| 1775 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1776 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1777 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1778 | CaptureExpr->getExprLoc()); |
| 1779 | } |
| 1780 | ExprResult Res = Ref; |
| 1781 | if (!S.getLangOpts().CPlusPlus && |
| 1782 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1783 | Ref->getType()->isPointerType()) |
| 1784 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1785 | if (!Res.isUsable()) |
| 1786 | return ExprError(); |
| 1787 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1790 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1791 | ArrayRef<OMPClause *> Clauses) { |
| 1792 | if (!S.isUsable()) { |
| 1793 | ActOnCapturedRegionError(); |
| 1794 | return StmtError(); |
| 1795 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1796 | |
| 1797 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1798 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1799 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1800 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1801 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1802 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1803 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1804 | (getLangOpts().OpenMPUseTLS && |
| 1805 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1806 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1807 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1808 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1809 | for (auto *VarRef : Clause->children()) { |
| 1810 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1811 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1812 | } |
| 1813 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1814 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1815 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1816 | // Mark all variables in private list clauses as used in inner region. |
| 1817 | // Required for proper codegen of combined directives. |
| 1818 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1819 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1820 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1821 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1822 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1823 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1824 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1825 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1826 | if (auto *E = C->getPostUpdateExpr()) |
| 1827 | MarkDeclarationsReferencedInExpr(E); |
| 1828 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1829 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1830 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1831 | SC = cast<OMPScheduleClause>(Clause); |
| 1832 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1833 | OC = cast<OMPOrderedClause>(Clause); |
| 1834 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1835 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1836 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1837 | bool ErrorFound = false; |
| 1838 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1839 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1840 | // specified. |
| 1841 | if (SC && |
| 1842 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1843 | SC->getSecondScheduleModifier() == |
| 1844 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1845 | OC) { |
| 1846 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1847 | ? SC->getFirstScheduleModifierLoc() |
| 1848 | : SC->getSecondScheduleModifierLoc(), |
| 1849 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1850 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1851 | ErrorFound = true; |
| 1852 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1853 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1854 | for (auto *C : LCs) { |
| 1855 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1856 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1857 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1858 | ErrorFound = true; |
| 1859 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1860 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1861 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1862 | OC->getNumForLoops()) { |
| 1863 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1864 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1865 | ErrorFound = true; |
| 1866 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1867 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1868 | ActOnCapturedRegionError(); |
| 1869 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1870 | } |
| 1871 | return ActOnCapturedRegionEnd(S.get()); |
| 1872 | } |
| 1873 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1874 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1875 | OpenMPDirectiveKind CurrentRegion, |
| 1876 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1877 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1878 | SourceLocation StartLoc) { |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1879 | // Allowed nesting of constructs |
| 1880 | // +------------------+-----------------+------------------------------------+ |
| 1881 | // | Parent directive | Child directive | Closely (!), No-Closely(+), Both(*)| |
| 1882 | // +------------------+-----------------+------------------------------------+ |
| 1883 | // | parallel | parallel | * | |
| 1884 | // | parallel | for | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1885 | // | parallel | for simd | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1886 | // | parallel | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1887 | // | parallel | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1888 | // | parallel | simd | * | |
| 1889 | // | parallel | sections | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1890 | // | parallel | section | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1891 | // | parallel | single | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1892 | // | parallel | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1893 | // | parallel |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1894 | // | parallel |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1895 | // | parallel | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1896 | // | parallel | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1897 | // | parallel | barrier | * | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1898 | // | parallel | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1899 | // | parallel | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1900 | // | parallel | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1901 | // | parallel | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1902 | // | parallel | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1903 | // | parallel | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1904 | // | parallel | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1905 | // | parallel | target parallel | * | |
| 1906 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1907 | // | parallel | target enter | * | |
| 1908 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1909 | // | parallel | target exit | * | |
| 1910 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1911 | // | parallel | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1912 | // | parallel | cancellation | | |
| 1913 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1914 | // | parallel | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1915 | // | parallel | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1916 | // | parallel | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1917 | // | parallel | distribute | + | |
| 1918 | // | parallel | distribute | + | |
| 1919 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1920 | // | parallel | distribute | + | |
| 1921 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1922 | // | parallel | distribute simd | + | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1923 | // | parallel | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1924 | // | parallel | teams distribute| + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1925 | // +------------------+-----------------+------------------------------------+ |
| 1926 | // | for | parallel | * | |
| 1927 | // | for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1928 | // | for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1929 | // | for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1930 | // | for | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1931 | // | for | simd | * | |
| 1932 | // | for | sections | + | |
| 1933 | // | for | section | + | |
| 1934 | // | for | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1935 | // | for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1936 | // | for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1937 | // | for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1938 | // | for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1939 | // | for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1940 | // | for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1941 | // | for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1942 | // | for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1943 | // | for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1944 | // | for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1945 | // | for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1946 | // | for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1947 | // | for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1948 | // | for | target parallel | * | |
| 1949 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1950 | // | for | target enter | * | |
| 1951 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1952 | // | for | target exit | * | |
| 1953 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1954 | // | for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1955 | // | for | cancellation | | |
| 1956 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1957 | // | for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1958 | // | for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1959 | // | for | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1960 | // | for | distribute | + | |
| 1961 | // | for | distribute | + | |
| 1962 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1963 | // | for | distribute | + | |
| 1964 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1965 | // | for | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1966 | // | for | target parallel | + | |
| 1967 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1968 | // | for | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1969 | // | for | teams distribute| + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 1970 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1971 | // | master | parallel | * | |
| 1972 | // | master | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1973 | // | master | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1974 | // | master | master | * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1975 | // | master | critical | * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1976 | // | master | simd | * | |
| 1977 | // | master | sections | + | |
| 1978 | // | master | section | + | |
| 1979 | // | master | single | + | |
| 1980 | // | master | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1981 | // | master |parallel for simd| * | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1982 | // | master |parallel sections| * | |
| 1983 | // | master | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1984 | // | master | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1985 | // | master | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1986 | // | master | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1987 | // | master | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1988 | // | master | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1989 | // | master | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1990 | // | master | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1991 | // | master | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1992 | // | master | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1993 | // | master | target parallel | * | |
| 1994 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1995 | // | master | target enter | * | |
| 1996 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1997 | // | master | target exit | * | |
| 1998 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1999 | // | master | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2000 | // | master | cancellation | | |
| 2001 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2002 | // | master | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2003 | // | master | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2004 | // | master | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2005 | // | master | distribute | + | |
| 2006 | // | master | distribute | + | |
| 2007 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2008 | // | master | distribute | + | |
| 2009 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2010 | // | master | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2011 | // | master | target parallel | + | |
| 2012 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2013 | // | master | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2014 | // | master | teams distribute| + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2015 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2016 | // | critical | parallel | * | |
| 2017 | // | critical | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2018 | // | critical | for simd | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2019 | // | critical | master | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2020 | // | critical | critical | * (should have different names) | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2021 | // | critical | simd | * | |
| 2022 | // | critical | sections | + | |
| 2023 | // | critical | section | + | |
| 2024 | // | critical | single | + | |
| 2025 | // | critical | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2026 | // | critical |parallel for simd| * | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2027 | // | critical |parallel sections| * | |
| 2028 | // | critical | task | * | |
| 2029 | // | critical | taskyield | * | |
| 2030 | // | critical | barrier | + | |
| 2031 | // | critical | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2032 | // | critical | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2033 | // | critical | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2034 | // | critical | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2035 | // | critical | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2036 | // | critical | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2037 | // | critical | target parallel | * | |
| 2038 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2039 | // | critical | target enter | * | |
| 2040 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2041 | // | critical | target exit | * | |
| 2042 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2043 | // | critical | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2044 | // | critical | cancellation | | |
| 2045 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2046 | // | critical | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2047 | // | critical | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2048 | // | critical | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2049 | // | critical | distribute | + | |
| 2050 | // | critical | distribute | + | |
| 2051 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2052 | // | critical | distribute | + | |
| 2053 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2054 | // | critical | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2055 | // | critical | target parallel | + | |
| 2056 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2057 | // | critical | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2058 | // | critical | teams distribute| + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2059 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2060 | // | simd | parallel | | |
| 2061 | // | simd | for | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2062 | // | simd | for simd | | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2063 | // | simd | master | | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2064 | // | simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2065 | // | simd | simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2066 | // | simd | sections | | |
| 2067 | // | simd | section | | |
| 2068 | // | simd | single | | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2069 | // | simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2070 | // | simd |parallel for simd| | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2071 | // | simd |parallel sections| | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2072 | // | simd | task | | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2073 | // | simd | taskyield | | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2074 | // | simd | barrier | | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2075 | // | simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2076 | // | simd | taskgroup | | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2077 | // | simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2078 | // | simd | ordered | + (with simd clause) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2079 | // | simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2080 | // | simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2081 | // | simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2082 | // | simd | target parallel | | |
| 2083 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2084 | // | simd | target enter | | |
| 2085 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2086 | // | simd | target exit | | |
| 2087 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2088 | // | simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2089 | // | simd | cancellation | | |
| 2090 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2091 | // | simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2092 | // | simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2093 | // | simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2094 | // | simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2095 | // | simd | distribute | | |
| 2096 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2097 | // | simd | distribute | | |
| 2098 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2099 | // | simd | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2100 | // | simd | target parallel | | |
| 2101 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2102 | // | simd | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2103 | // | simd | teams distribute| | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2104 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2105 | // | for simd | parallel | | |
| 2106 | // | for simd | for | | |
| 2107 | // | for simd | for simd | | |
| 2108 | // | for simd | master | | |
| 2109 | // | for simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2110 | // | for simd | simd | * | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2111 | // | for simd | sections | | |
| 2112 | // | for simd | section | | |
| 2113 | // | for simd | single | | |
| 2114 | // | for simd | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2115 | // | for simd |parallel for simd| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2116 | // | for simd |parallel sections| | |
| 2117 | // | for simd | task | | |
| 2118 | // | for simd | taskyield | | |
| 2119 | // | for simd | barrier | | |
| 2120 | // | for simd | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2121 | // | for simd | taskgroup | | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2122 | // | for simd | flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2123 | // | for simd | ordered | + (with simd clause) | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2124 | // | for simd | atomic | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2125 | // | for simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2126 | // | for simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2127 | // | for simd | target parallel | | |
| 2128 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2129 | // | for simd | target enter | | |
| 2130 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2131 | // | for simd | target exit | | |
| 2132 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2133 | // | for simd | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2134 | // | for simd | cancellation | | |
| 2135 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2136 | // | for simd | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2137 | // | for simd | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2138 | // | for simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2139 | // | for simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2140 | // | for simd | distribute | | |
| 2141 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2142 | // | for simd | distribute | | |
| 2143 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2144 | // | for simd | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2145 | // | for simd | target parallel | | |
| 2146 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2147 | // | for simd | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2148 | // | for simd | teams distribute| | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2149 | // +------------------+-----------------+------------------------------------+ |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2150 | // | parallel for simd| parallel | | |
| 2151 | // | parallel for simd| for | | |
| 2152 | // | parallel for simd| for simd | | |
| 2153 | // | parallel for simd| master | | |
| 2154 | // | parallel for simd| critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2155 | // | parallel for simd| simd | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2156 | // | parallel for simd| sections | | |
| 2157 | // | parallel for simd| section | | |
| 2158 | // | parallel for simd| single | | |
| 2159 | // | parallel for simd| parallel for | | |
| 2160 | // | parallel for simd|parallel for simd| | |
| 2161 | // | parallel for simd|parallel sections| | |
| 2162 | // | parallel for simd| task | | |
| 2163 | // | parallel for simd| taskyield | | |
| 2164 | // | parallel for simd| barrier | | |
| 2165 | // | parallel for simd| taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2166 | // | parallel for simd| taskgroup | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2167 | // | parallel for simd| flush | | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2168 | // | parallel for simd| ordered | + (with simd clause) | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2169 | // | parallel for simd| atomic | | |
| 2170 | // | parallel for simd| target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2171 | // | parallel for simd| target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2172 | // | parallel for simd| target parallel | | |
| 2173 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2174 | // | parallel for simd| target enter | | |
| 2175 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2176 | // | parallel for simd| target exit | | |
| 2177 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2178 | // | parallel for simd| teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2179 | // | parallel for simd| cancellation | | |
| 2180 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2181 | // | parallel for simd| cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2182 | // | parallel for simd| taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2183 | // | parallel for simd| taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2184 | // | parallel for simd| distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2185 | // | parallel for simd| distribute | | |
| 2186 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2187 | // | parallel for simd| distribute | | |
| 2188 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2189 | // | parallel for simd| distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2190 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2191 | // | parallel for simd| target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2192 | // | parallel for simd| teams distribute| | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2193 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2194 | // | sections | parallel | * | |
| 2195 | // | sections | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2196 | // | sections | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2197 | // | sections | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2198 | // | sections | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2199 | // | sections | simd | * | |
| 2200 | // | sections | sections | + | |
| 2201 | // | sections | section | * | |
| 2202 | // | sections | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2203 | // | sections | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2204 | // | sections |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2205 | // | sections |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2206 | // | sections | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2207 | // | sections | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2208 | // | sections | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2209 | // | sections | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2210 | // | sections | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2211 | // | sections | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2212 | // | sections | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2213 | // | sections | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2214 | // | sections | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2215 | // | sections | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2216 | // | sections | target parallel | * | |
| 2217 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2218 | // | sections | target enter | * | |
| 2219 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2220 | // | sections | target exit | * | |
| 2221 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2222 | // | sections | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2223 | // | sections | cancellation | | |
| 2224 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2225 | // | sections | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2226 | // | sections | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2227 | // | sections | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2228 | // | sections | distribute | + | |
| 2229 | // | sections | distribute | + | |
| 2230 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2231 | // | sections | distribute | + | |
| 2232 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2233 | // | sections | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2234 | // | sections | target parallel | + | |
| 2235 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2236 | // | sections | target simd | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2237 | // +------------------+-----------------+------------------------------------+ |
| 2238 | // | section | parallel | * | |
| 2239 | // | section | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2240 | // | section | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2241 | // | section | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2242 | // | section | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2243 | // | section | simd | * | |
| 2244 | // | section | sections | + | |
| 2245 | // | section | section | + | |
| 2246 | // | section | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2247 | // | section | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2248 | // | section |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2249 | // | section |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2250 | // | section | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2251 | // | section | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2252 | // | section | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2253 | // | section | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2254 | // | section | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2255 | // | section | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2256 | // | section | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2257 | // | section | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2258 | // | section | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2259 | // | section | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2260 | // | section | target parallel | * | |
| 2261 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2262 | // | section | target enter | * | |
| 2263 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2264 | // | section | target exit | * | |
| 2265 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2266 | // | section | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2267 | // | section | cancellation | | |
| 2268 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2269 | // | section | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2270 | // | section | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2271 | // | section | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2272 | // | section | distribute | + | |
| 2273 | // | section | distribute | + | |
| 2274 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2275 | // | section | distribute | + | |
| 2276 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2277 | // | section | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2278 | // | section | target parallel | + | |
| 2279 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2280 | // | section | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2281 | // | section | teams distrubte | + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2282 | // +------------------+-----------------+------------------------------------+ |
| 2283 | // | single | parallel | * | |
| 2284 | // | single | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2285 | // | single | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2286 | // | single | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2287 | // | single | critical | * | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2288 | // | single | simd | * | |
| 2289 | // | single | sections | + | |
| 2290 | // | single | section | + | |
| 2291 | // | single | single | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2292 | // | single | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2293 | // | single |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2294 | // | single |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2295 | // | single | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2296 | // | single | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2297 | // | single | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2298 | // | single | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2299 | // | single | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2300 | // | single | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2301 | // | single | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2302 | // | single | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2303 | // | single | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2304 | // | single | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2305 | // | single | target parallel | * | |
| 2306 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2307 | // | single | target enter | * | |
| 2308 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2309 | // | single | target exit | * | |
| 2310 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2311 | // | single | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2312 | // | single | cancellation | | |
| 2313 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2314 | // | single | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2315 | // | single | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2316 | // | single | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2317 | // | single | distribute | + | |
| 2318 | // | single | distribute | + | |
| 2319 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2320 | // | single | distribute | + | |
| 2321 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2322 | // | single | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2323 | // | single | target parallel | + | |
| 2324 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2325 | // | single | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2326 | // | single | teams distrubte | + | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2327 | // +------------------+-----------------+------------------------------------+ |
| 2328 | // | parallel for | parallel | * | |
| 2329 | // | parallel for | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2330 | // | parallel for | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2331 | // | parallel for | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2332 | // | parallel for | critical | * | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2333 | // | parallel for | simd | * | |
| 2334 | // | parallel for | sections | + | |
| 2335 | // | parallel for | section | + | |
| 2336 | // | parallel for | single | + | |
| 2337 | // | parallel for | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2338 | // | parallel for |parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2339 | // | parallel for |parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2340 | // | parallel for | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2341 | // | parallel for | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2342 | // | parallel for | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2343 | // | parallel for | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2344 | // | parallel for | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2345 | // | parallel for | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2346 | // | parallel for | ordered | * (if construct is ordered) | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2347 | // | parallel for | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2348 | // | parallel for | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2349 | // | parallel for | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2350 | // | parallel for | target parallel | * | |
| 2351 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2352 | // | parallel for | target enter | * | |
| 2353 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2354 | // | parallel for | target exit | * | |
| 2355 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2356 | // | parallel for | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2357 | // | parallel for | cancellation | | |
| 2358 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2359 | // | parallel for | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2360 | // | parallel for | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2361 | // | parallel for | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2362 | // | parallel for | distribute | + | |
| 2363 | // | parallel for | distribute | + | |
| 2364 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2365 | // | parallel for | distribute | + | |
| 2366 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2367 | // | parallel for | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2368 | // | parallel for | target parallel | + | |
| 2369 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2370 | // | parallel for | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2371 | // | parallel for | teams distribute| + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2372 | // +------------------+-----------------+------------------------------------+ |
| 2373 | // | parallel sections| parallel | * | |
| 2374 | // | parallel sections| for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2375 | // | parallel sections| for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2376 | // | parallel sections| master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2377 | // | parallel sections| critical | + | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2378 | // | parallel sections| simd | * | |
| 2379 | // | parallel sections| sections | + | |
| 2380 | // | parallel sections| section | * | |
| 2381 | // | parallel sections| single | + | |
| 2382 | // | parallel sections| parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2383 | // | parallel sections|parallel for simd| * | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2384 | // | parallel sections|parallel sections| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2385 | // | parallel sections| task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2386 | // | parallel sections| taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2387 | // | parallel sections| barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2388 | // | parallel sections| taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2389 | // | parallel sections| taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2390 | // | parallel sections| flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2391 | // | parallel sections| ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2392 | // | parallel sections| atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2393 | // | parallel sections| target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2394 | // | parallel sections| target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2395 | // | parallel sections| target parallel | * | |
| 2396 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2397 | // | parallel sections| target enter | * | |
| 2398 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2399 | // | parallel sections| target exit | * | |
| 2400 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2401 | // | parallel sections| teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2402 | // | parallel sections| cancellation | | |
| 2403 | // | | point | ! | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2404 | // | parallel sections| cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2405 | // | parallel sections| taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2406 | // | parallel sections| taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2407 | // | parallel sections| distribute | + | |
| 2408 | // | parallel sections| distribute | + | |
| 2409 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2410 | // | parallel sections| distribute | + | |
| 2411 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2412 | // | parallel sections| distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2413 | // | parallel sections| target parallel | + | |
| 2414 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2415 | // | parallel sections| target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2416 | // | parallel sections| teams distribute| + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2417 | // +------------------+-----------------+------------------------------------+ |
| 2418 | // | task | parallel | * | |
| 2419 | // | task | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2420 | // | task | for simd | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2421 | // | task | master | + | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2422 | // | task | critical | * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2423 | // | task | simd | * | |
| 2424 | // | task | sections | + | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2425 | // | task | section | + | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2426 | // | task | single | + | |
| 2427 | // | task | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2428 | // | task |parallel for simd| * | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2429 | // | task |parallel sections| * | |
| 2430 | // | task | task | * | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2431 | // | task | taskyield | * | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2432 | // | task | barrier | + | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2433 | // | task | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2434 | // | task | taskgroup | * | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2435 | // | task | flush | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2436 | // | task | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2437 | // | task | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2438 | // | task | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2439 | // | task | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2440 | // | task | target parallel | * | |
| 2441 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2442 | // | task | target enter | * | |
| 2443 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2444 | // | task | target exit | * | |
| 2445 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2446 | // | task | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2447 | // | task | cancellation | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2448 | // | | point | ! | |
| 2449 | // | task | cancel | ! | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2450 | // | task | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2451 | // | task | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2452 | // | task | distribute | + | |
| 2453 | // | task | distribute | + | |
| 2454 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2455 | // | task | distribute | + | |
| 2456 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2457 | // | task | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2458 | // | task | target parallel | + | |
| 2459 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2460 | // | task | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2461 | // | task | teams distribute| + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2462 | // +------------------+-----------------+------------------------------------+ |
| 2463 | // | ordered | parallel | * | |
| 2464 | // | ordered | for | + | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2465 | // | ordered | for simd | + | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2466 | // | ordered | master | * | |
| 2467 | // | ordered | critical | * | |
| 2468 | // | ordered | simd | * | |
| 2469 | // | ordered | sections | + | |
| 2470 | // | ordered | section | + | |
| 2471 | // | ordered | single | + | |
| 2472 | // | ordered | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2473 | // | ordered |parallel for simd| * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2474 | // | ordered |parallel sections| * | |
| 2475 | // | ordered | task | * | |
| 2476 | // | ordered | taskyield | * | |
| 2477 | // | ordered | barrier | + | |
| 2478 | // | ordered | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2479 | // | ordered | taskgroup | * | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2480 | // | ordered | flush | * | |
| 2481 | // | ordered | ordered | + | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2482 | // | ordered | atomic | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2483 | // | ordered | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2484 | // | ordered | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2485 | // | ordered | target parallel | * | |
| 2486 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2487 | // | ordered | target enter | * | |
| 2488 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2489 | // | ordered | target exit | * | |
| 2490 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2491 | // | ordered | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2492 | // | ordered | cancellation | | |
| 2493 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2494 | // | ordered | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2495 | // | ordered | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2496 | // | ordered | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2497 | // | ordered | distribute | + | |
| 2498 | // | ordered | distribute | + | |
| 2499 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2500 | // | ordered | distribute | + | |
| 2501 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2502 | // | ordered | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2503 | // | ordered | target parallel | + | |
| 2504 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2505 | // | ordered | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2506 | // | ordered | teams distribute| + | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2507 | // +------------------+-----------------+------------------------------------+ |
| 2508 | // | atomic | parallel | | |
| 2509 | // | atomic | for | | |
| 2510 | // | atomic | for simd | | |
| 2511 | // | atomic | master | | |
| 2512 | // | atomic | critical | | |
| 2513 | // | atomic | simd | | |
| 2514 | // | atomic | sections | | |
| 2515 | // | atomic | section | | |
| 2516 | // | atomic | single | | |
| 2517 | // | atomic | parallel for | | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2518 | // | atomic |parallel for simd| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2519 | // | atomic |parallel sections| | |
| 2520 | // | atomic | task | | |
| 2521 | // | atomic | taskyield | | |
| 2522 | // | atomic | barrier | | |
| 2523 | // | atomic | taskwait | | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2524 | // | atomic | taskgroup | | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2525 | // | atomic | flush | | |
| 2526 | // | atomic | ordered | | |
| 2527 | // | atomic | atomic | | |
| 2528 | // | atomic | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2529 | // | atomic | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2530 | // | atomic | target parallel | | |
| 2531 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2532 | // | atomic | target enter | | |
| 2533 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2534 | // | atomic | target exit | | |
| 2535 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2536 | // | atomic | teams | | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2537 | // | atomic | cancellation | | |
| 2538 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2539 | // | atomic | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2540 | // | atomic | taskloop | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2541 | // | atomic | taskloop simd | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2542 | // | atomic | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2543 | // | atomic | distribute | | |
| 2544 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2545 | // | atomic | distribute | | |
| 2546 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2547 | // | atomic | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2548 | // | atomic | target parallel | | |
| 2549 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2550 | // | atomic | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2551 | // | atomic | teams distribute| | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2552 | // +------------------+-----------------+------------------------------------+ |
| 2553 | // | target | parallel | * | |
| 2554 | // | target | for | * | |
| 2555 | // | target | for simd | * | |
| 2556 | // | target | master | * | |
| 2557 | // | target | critical | * | |
| 2558 | // | target | simd | * | |
| 2559 | // | target | sections | * | |
| 2560 | // | target | section | * | |
| 2561 | // | target | single | * | |
| 2562 | // | target | parallel for | * | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2563 | // | target |parallel for simd| * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2564 | // | target |parallel sections| * | |
| 2565 | // | target | task | * | |
| 2566 | // | target | taskyield | * | |
| 2567 | // | target | barrier | * | |
| 2568 | // | target | taskwait | * | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2569 | // | target | taskgroup | * | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2570 | // | target | flush | * | |
| 2571 | // | target | ordered | * | |
| 2572 | // | target | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2573 | // | target | target | | |
| 2574 | // | target | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2575 | // | target | target parallel | | |
| 2576 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2577 | // | target | target enter | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2578 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2579 | // | target | target exit | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2580 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2581 | // | target | teams | * | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2582 | // | target | cancellation | | |
| 2583 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2584 | // | target | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2585 | // | target | taskloop | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2586 | // | target | taskloop simd | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2587 | // | target | distribute | + | |
| 2588 | // | target | distribute | + | |
| 2589 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2590 | // | target | distribute | + | |
| 2591 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2592 | // | target | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2593 | // | target | target parallel | | |
| 2594 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2595 | // | target | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2596 | // | target | teams distribute| | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2597 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2598 | // | target parallel | parallel | * | |
| 2599 | // | target parallel | for | * | |
| 2600 | // | target parallel | for simd | * | |
| 2601 | // | target parallel | master | * | |
| 2602 | // | target parallel | critical | * | |
| 2603 | // | target parallel | simd | * | |
| 2604 | // | target parallel | sections | * | |
| 2605 | // | target parallel | section | * | |
| 2606 | // | target parallel | single | * | |
| 2607 | // | target parallel | parallel for | * | |
| 2608 | // | target parallel |parallel for simd| * | |
| 2609 | // | target parallel |parallel sections| * | |
| 2610 | // | target parallel | task | * | |
| 2611 | // | target parallel | taskyield | * | |
| 2612 | // | target parallel | barrier | * | |
| 2613 | // | target parallel | taskwait | * | |
| 2614 | // | target parallel | taskgroup | * | |
| 2615 | // | target parallel | flush | * | |
| 2616 | // | target parallel | ordered | * | |
| 2617 | // | target parallel | atomic | * | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2618 | // | target parallel | target | | |
| 2619 | // | target parallel | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2620 | // | target parallel | target parallel | | |
| 2621 | // | | for | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2622 | // | target parallel | target enter | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2623 | // | | data | | |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2624 | // | target parallel | target exit | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2625 | // | | data | | |
| 2626 | // | target parallel | teams | | |
| 2627 | // | target parallel | cancellation | | |
| 2628 | // | | point | ! | |
| 2629 | // | target parallel | cancel | ! | |
| 2630 | // | target parallel | taskloop | * | |
| 2631 | // | target parallel | taskloop simd | * | |
| 2632 | // | target parallel | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2633 | // | target parallel | distribute | | |
| 2634 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2635 | // | target parallel | distribute | | |
| 2636 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2637 | // | target parallel | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2638 | // | target parallel | target parallel | | |
| 2639 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2640 | // | target parallel | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2641 | // | target parallel | teams distribute| + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2642 | // +------------------+-----------------+------------------------------------+ |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2643 | // | target parallel | parallel | * | |
| 2644 | // | for | | | |
| 2645 | // | target parallel | for | * | |
| 2646 | // | for | | | |
| 2647 | // | target parallel | for simd | * | |
| 2648 | // | for | | | |
| 2649 | // | target parallel | master | * | |
| 2650 | // | for | | | |
| 2651 | // | target parallel | critical | * | |
| 2652 | // | for | | | |
| 2653 | // | target parallel | simd | * | |
| 2654 | // | for | | | |
| 2655 | // | target parallel | sections | * | |
| 2656 | // | for | | | |
| 2657 | // | target parallel | section | * | |
| 2658 | // | for | | | |
| 2659 | // | target parallel | single | * | |
| 2660 | // | for | | | |
| 2661 | // | target parallel | parallel for | * | |
| 2662 | // | for | | | |
| 2663 | // | target parallel |parallel for simd| * | |
| 2664 | // | for | | | |
| 2665 | // | target parallel |parallel sections| * | |
| 2666 | // | for | | | |
| 2667 | // | target parallel | task | * | |
| 2668 | // | for | | | |
| 2669 | // | target parallel | taskyield | * | |
| 2670 | // | for | | | |
| 2671 | // | target parallel | barrier | * | |
| 2672 | // | for | | | |
| 2673 | // | target parallel | taskwait | * | |
| 2674 | // | for | | | |
| 2675 | // | target parallel | taskgroup | * | |
| 2676 | // | for | | | |
| 2677 | // | target parallel | flush | * | |
| 2678 | // | for | | | |
| 2679 | // | target parallel | ordered | * | |
| 2680 | // | for | | | |
| 2681 | // | target parallel | atomic | * | |
| 2682 | // | for | | | |
| 2683 | // | target parallel | target | | |
| 2684 | // | for | | | |
| 2685 | // | target parallel | target parallel | | |
| 2686 | // | for | | | |
| 2687 | // | target parallel | target parallel | | |
| 2688 | // | for | for | | |
| 2689 | // | target parallel | target enter | | |
| 2690 | // | for | data | | |
| 2691 | // | target parallel | target exit | | |
| 2692 | // | for | data | | |
| 2693 | // | target parallel | teams | | |
| 2694 | // | for | | | |
| 2695 | // | target parallel | cancellation | | |
| 2696 | // | for | point | ! | |
| 2697 | // | target parallel | cancel | ! | |
| 2698 | // | for | | | |
| 2699 | // | target parallel | taskloop | * | |
| 2700 | // | for | | | |
| 2701 | // | target parallel | taskloop simd | * | |
| 2702 | // | for | | | |
| 2703 | // | target parallel | distribute | | |
| 2704 | // | for | | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2705 | // | target parallel | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2706 | // | for | parallel for | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2707 | // | target parallel | distribute | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2708 | // | for |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2709 | // | target parallel | distribute simd | | |
| 2710 | // | for | | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2711 | // | target parallel | target parallel | | |
| 2712 | // | for | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2713 | // | target parallel | target simd | | |
| 2714 | // | for | | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2715 | // | target parallel | teams distribute| | |
| 2716 | // | for | | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2717 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2718 | // | teams | parallel | * | |
| 2719 | // | teams | for | + | |
| 2720 | // | teams | for simd | + | |
| 2721 | // | teams | master | + | |
| 2722 | // | teams | critical | + | |
| 2723 | // | teams | simd | + | |
| 2724 | // | teams | sections | + | |
| 2725 | // | teams | section | + | |
| 2726 | // | teams | single | + | |
| 2727 | // | teams | parallel for | * | |
| 2728 | // | teams |parallel for simd| * | |
| 2729 | // | teams |parallel sections| * | |
| 2730 | // | teams | task | + | |
| 2731 | // | teams | taskyield | + | |
| 2732 | // | teams | barrier | + | |
| 2733 | // | teams | taskwait | + | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2734 | // | teams | taskgroup | + | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2735 | // | teams | flush | + | |
| 2736 | // | teams | ordered | + | |
| 2737 | // | teams | atomic | + | |
| 2738 | // | teams | target | + | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2739 | // | teams | target parallel | + | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2740 | // | teams | target parallel | + | |
| 2741 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2742 | // | teams | target enter | + | |
| 2743 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2744 | // | teams | target exit | + | |
| 2745 | // | | data | | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2746 | // | teams | teams | + | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2747 | // | teams | cancellation | | |
| 2748 | // | | point | | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2749 | // | teams | cancel | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2750 | // | teams | taskloop | + | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2751 | // | teams | taskloop simd | + | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2752 | // | teams | distribute | ! | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2753 | // | teams | distribute | ! | |
| 2754 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2755 | // | teams | distribute | ! | |
| 2756 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2757 | // | teams | distribute simd | ! | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2758 | // | teams | target parallel | + | |
| 2759 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2760 | // | teams | target simd | + | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2761 | // | teams | teams distribute| + | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2762 | // +------------------+-----------------+------------------------------------+ |
| 2763 | // | taskloop | parallel | * | |
| 2764 | // | taskloop | for | + | |
| 2765 | // | taskloop | for simd | + | |
| 2766 | // | taskloop | master | + | |
| 2767 | // | taskloop | critical | * | |
| 2768 | // | taskloop | simd | * | |
| 2769 | // | taskloop | sections | + | |
| 2770 | // | taskloop | section | + | |
| 2771 | // | taskloop | single | + | |
| 2772 | // | taskloop | parallel for | * | |
| 2773 | // | taskloop |parallel for simd| * | |
| 2774 | // | taskloop |parallel sections| * | |
| 2775 | // | taskloop | task | * | |
| 2776 | // | taskloop | taskyield | * | |
| 2777 | // | taskloop | barrier | + | |
| 2778 | // | taskloop | taskwait | * | |
| 2779 | // | taskloop | taskgroup | * | |
| 2780 | // | taskloop | flush | * | |
| 2781 | // | taskloop | ordered | + | |
| 2782 | // | taskloop | atomic | * | |
| 2783 | // | taskloop | target | * | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2784 | // | taskloop | target parallel | * | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2785 | // | taskloop | target parallel | * | |
| 2786 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2787 | // | taskloop | target enter | * | |
| 2788 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2789 | // | taskloop | target exit | * | |
| 2790 | // | | data | | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2791 | // | taskloop | teams | + | |
| 2792 | // | taskloop | cancellation | | |
| 2793 | // | | point | | |
| 2794 | // | taskloop | cancel | | |
| 2795 | // | taskloop | taskloop | * | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2796 | // | taskloop | distribute | + | |
| 2797 | // | taskloop | distribute | + | |
| 2798 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2799 | // | taskloop | distribute | + | |
| 2800 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2801 | // | taskloop | distribute simd | + | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2802 | // | taskloop | target parallel | * | |
| 2803 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2804 | // | taskloop | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2805 | // | taskloop | teams distribute| + | |
Alexey Bataev | 18eb25e | 2014-06-30 10:22:46 +0000 | [diff] [blame] | 2806 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2807 | // | taskloop simd | parallel | | |
| 2808 | // | taskloop simd | for | | |
| 2809 | // | taskloop simd | for simd | | |
| 2810 | // | taskloop simd | master | | |
| 2811 | // | taskloop simd | critical | | |
Alexey Bataev | 1f09221 | 2016-02-02 04:59:52 +0000 | [diff] [blame] | 2812 | // | taskloop simd | simd | * | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2813 | // | taskloop simd | sections | | |
| 2814 | // | taskloop simd | section | | |
| 2815 | // | taskloop simd | single | | |
| 2816 | // | taskloop simd | parallel for | | |
| 2817 | // | taskloop simd |parallel for simd| | |
| 2818 | // | taskloop simd |parallel sections| | |
| 2819 | // | taskloop simd | task | | |
| 2820 | // | taskloop simd | taskyield | | |
| 2821 | // | taskloop simd | barrier | | |
| 2822 | // | taskloop simd | taskwait | | |
| 2823 | // | taskloop simd | taskgroup | | |
| 2824 | // | taskloop simd | flush | | |
| 2825 | // | taskloop simd | ordered | + (with simd clause) | |
| 2826 | // | taskloop simd | atomic | | |
| 2827 | // | taskloop simd | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2828 | // | taskloop simd | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2829 | // | taskloop simd | target parallel | | |
| 2830 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2831 | // | taskloop simd | target enter | | |
| 2832 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2833 | // | taskloop simd | target exit | | |
| 2834 | // | | data | | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2835 | // | taskloop simd | teams | | |
| 2836 | // | taskloop simd | cancellation | | |
| 2837 | // | | point | | |
| 2838 | // | taskloop simd | cancel | | |
| 2839 | // | taskloop simd | taskloop | | |
| 2840 | // | taskloop simd | taskloop simd | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2841 | // | taskloop simd | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2842 | // | taskloop simd | distribute | | |
| 2843 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2844 | // | taskloop simd | distribute | | |
| 2845 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2846 | // | taskloop simd | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2847 | // | taskloop simd | target parallel | | |
| 2848 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2849 | // | taskloop simd | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2850 | // | taskloop simd | teams distribute| | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2851 | // +------------------+-----------------+------------------------------------+ |
| 2852 | // | distribute | parallel | * | |
| 2853 | // | distribute | for | * | |
| 2854 | // | distribute | for simd | * | |
| 2855 | // | distribute | master | * | |
| 2856 | // | distribute | critical | * | |
| 2857 | // | distribute | simd | * | |
| 2858 | // | distribute | sections | * | |
| 2859 | // | distribute | section | * | |
| 2860 | // | distribute | single | * | |
| 2861 | // | distribute | parallel for | * | |
| 2862 | // | distribute |parallel for simd| * | |
| 2863 | // | distribute |parallel sections| * | |
| 2864 | // | distribute | task | * | |
| 2865 | // | distribute | taskyield | * | |
| 2866 | // | distribute | barrier | * | |
| 2867 | // | distribute | taskwait | * | |
| 2868 | // | distribute | taskgroup | * | |
| 2869 | // | distribute | flush | * | |
| 2870 | // | distribute | ordered | + | |
| 2871 | // | distribute | atomic | * | |
| 2872 | // | distribute | target | | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2873 | // | distribute | target parallel | | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2874 | // | distribute | target parallel | | |
| 2875 | // | | for | | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2876 | // | distribute | target enter | | |
| 2877 | // | | data | | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2878 | // | distribute | target exit | | |
| 2879 | // | | data | | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2880 | // | distribute | teams | | |
| 2881 | // | distribute | cancellation | + | |
| 2882 | // | | point | | |
| 2883 | // | distribute | cancel | + | |
| 2884 | // | distribute | taskloop | * | |
| 2885 | // | distribute | taskloop simd | * | |
| 2886 | // | distribute | distribute | | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2887 | // | distribute | distribute | | |
| 2888 | // | | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2889 | // | distribute | distribute | | |
| 2890 | // | |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2891 | // | distribute | distribute simd | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2892 | // | distribute | target parallel | | |
| 2893 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2894 | // | distribute | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2895 | // | distribute | teams distribute| | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2896 | // +------------------+-----------------+------------------------------------+ |
| 2897 | // | distribute | parallel | * | |
| 2898 | // | parallel for | | | |
| 2899 | // | distribute | for | * | |
| 2900 | // | parallel for | | | |
| 2901 | // | distribute | for simd | * | |
| 2902 | // | parallel for | | | |
| 2903 | // | distribute | master | * | |
| 2904 | // | parallel for | | | |
| 2905 | // | distribute | critical | * | |
| 2906 | // | parallel for | | | |
| 2907 | // | distribute | simd | * | |
| 2908 | // | parallel for | | | |
| 2909 | // | distribute | sections | * | |
| 2910 | // | parallel for | | | |
| 2911 | // | distribute | section | * | |
| 2912 | // | parallel for | | | |
| 2913 | // | distribute | single | * | |
| 2914 | // | parallel for | | | |
| 2915 | // | distribute | parallel for | * | |
| 2916 | // | parallel for | | | |
| 2917 | // | distribute |parallel for simd| * | |
| 2918 | // | parallel for | | | |
| 2919 | // | distribute |parallel sections| * | |
| 2920 | // | parallel for | | | |
| 2921 | // | distribute | task | * | |
| 2922 | // | parallel for | | | |
| 2923 | // | parallel for | | | |
| 2924 | // | distribute | taskyield | * | |
| 2925 | // | parallel for | | | |
| 2926 | // | distribute | barrier | * | |
| 2927 | // | parallel for | | | |
| 2928 | // | distribute | taskwait | * | |
| 2929 | // | parallel for | | | |
| 2930 | // | distribute | taskgroup | * | |
| 2931 | // | parallel for | | | |
| 2932 | // | distribute | flush | * | |
| 2933 | // | parallel for | | | |
| 2934 | // | distribute | ordered | + | |
| 2935 | // | parallel for | | | |
| 2936 | // | distribute | atomic | * | |
| 2937 | // | parallel for | | | |
| 2938 | // | distribute | target | | |
| 2939 | // | parallel for | | | |
| 2940 | // | distribute | target parallel | | |
| 2941 | // | parallel for | | | |
| 2942 | // | distribute | target parallel | | |
| 2943 | // | parallel for | for | | |
| 2944 | // | distribute | target enter | | |
| 2945 | // | parallel for | data | | |
| 2946 | // | distribute | target exit | | |
| 2947 | // | parallel for | data | | |
| 2948 | // | distribute | teams | | |
| 2949 | // | parallel for | | | |
| 2950 | // | distribute | cancellation | + | |
| 2951 | // | parallel for | point | | |
| 2952 | // | distribute | cancel | + | |
| 2953 | // | parallel for | | | |
| 2954 | // | distribute | taskloop | * | |
| 2955 | // | parallel for | | | |
| 2956 | // | distribute | taskloop simd | * | |
| 2957 | // | parallel for | | | |
| 2958 | // | distribute | distribute | | |
| 2959 | // | parallel for | | | |
| 2960 | // | distribute | distribute | | |
| 2961 | // | parallel for | parallel for | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2962 | // | distribute | distribute | | |
| 2963 | // | parallel for |parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2964 | // | distribute | distribute simd | | |
| 2965 | // | parallel for | | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2966 | // | distribute | target parallel | | |
| 2967 | // | parallel for | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2968 | // | distribute | target simd | | |
| 2969 | // | parallel for | | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2970 | // | distribute | teams distribute| | |
| 2971 | // | parallel for | | | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2972 | // +------------------+-----------------+------------------------------------+ |
| 2973 | // | distribute | parallel | * | |
| 2974 | // | parallel for simd| | | |
| 2975 | // | distribute | for | * | |
| 2976 | // | parallel for simd| | | |
| 2977 | // | distribute | for simd | * | |
| 2978 | // | parallel for simd| | | |
| 2979 | // | distribute | master | * | |
| 2980 | // | parallel for simd| | | |
| 2981 | // | distribute | critical | * | |
| 2982 | // | parallel for simd| | | |
| 2983 | // | distribute | simd | * | |
| 2984 | // | parallel for simd| | | |
| 2985 | // | distribute | sections | * | |
| 2986 | // | parallel for simd| | | |
| 2987 | // | distribute | section | * | |
| 2988 | // | parallel for simd| | | |
| 2989 | // | distribute | single | * | |
| 2990 | // | parallel for simd| | | |
| 2991 | // | distribute | parallel for | * | |
| 2992 | // | parallel for simd| | | |
| 2993 | // | distribute |parallel for simd| * | |
| 2994 | // | parallel for simd| | | |
| 2995 | // | distribute |parallel sections| * | |
| 2996 | // | parallel for simd| | | |
| 2997 | // | distribute | task | * | |
| 2998 | // | parallel for simd| | | |
| 2999 | // | distribute | taskyield | * | |
| 3000 | // | parallel for simd| | | |
| 3001 | // | distribute | barrier | * | |
| 3002 | // | parallel for simd| | | |
| 3003 | // | distribute | taskwait | * | |
| 3004 | // | parallel for simd| | | |
| 3005 | // | distribute | taskgroup | * | |
| 3006 | // | parallel for simd| | | |
| 3007 | // | distribute | flush | * | |
| 3008 | // | parallel for simd| | | |
| 3009 | // | distribute | ordered | + | |
| 3010 | // | parallel for simd| | | |
| 3011 | // | distribute | atomic | * | |
| 3012 | // | parallel for simd| | | |
| 3013 | // | distribute | target | | |
| 3014 | // | parallel for simd| | | |
| 3015 | // | distribute | target parallel | | |
| 3016 | // | parallel for simd| | | |
| 3017 | // | distribute | target parallel | | |
| 3018 | // | parallel for simd| for | | |
| 3019 | // | distribute | target enter | | |
| 3020 | // | parallel for simd| data | | |
| 3021 | // | distribute | target exit | | |
| 3022 | // | parallel for simd| data | | |
| 3023 | // | distribute | teams | | |
| 3024 | // | parallel for simd| | | |
| 3025 | // | distribute | cancellation | + | |
| 3026 | // | parallel for simd| point | | |
| 3027 | // | distribute | cancel | + | |
| 3028 | // | parallel for simd| | | |
| 3029 | // | distribute | taskloop | * | |
| 3030 | // | parallel for simd| | | |
| 3031 | // | distribute | taskloop simd | * | |
| 3032 | // | parallel for simd| | | |
| 3033 | // | distribute | distribute | | |
| 3034 | // | parallel for simd| | | |
| 3035 | // | distribute | distribute | * | |
| 3036 | // | parallel for simd| parallel for | | |
| 3037 | // | distribute | distribute | * | |
| 3038 | // | parallel for simd|parallel for simd| | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3039 | // | distribute | distribute simd | * | |
| 3040 | // | parallel for simd| | | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3041 | // | distribute | target parallel | | |
| 3042 | // | parallel for simd| for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3043 | // | distribute | target simd | | |
| 3044 | // | parallel for simd| | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3045 | // | distribute | teams distribute| | |
| 3046 | // | parallel for simd| | | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3047 | // +------------------+-----------------+------------------------------------+ |
| 3048 | // | distribute simd | parallel | * | |
| 3049 | // | distribute simd | for | * | |
| 3050 | // | distribute simd | for simd | * | |
| 3051 | // | distribute simd | master | * | |
| 3052 | // | distribute simd | critical | * | |
| 3053 | // | distribute simd | simd | * | |
| 3054 | // | distribute simd | sections | * | |
| 3055 | // | distribute simd | section | * | |
| 3056 | // | distribute simd | single | * | |
| 3057 | // | distribute simd | parallel for | * | |
| 3058 | // | distribute simd |parallel for simd| * | |
| 3059 | // | distribute simd |parallel sections| * | |
| 3060 | // | distribute simd | task | * | |
| 3061 | // | distribute simd | taskyield | * | |
| 3062 | // | distribute simd | barrier | * | |
| 3063 | // | distribute simd | taskwait | * | |
| 3064 | // | distribute simd | taskgroup | * | |
| 3065 | // | distribute simd | flush | * | |
| 3066 | // | distribute simd | ordered | + | |
| 3067 | // | distribute simd | atomic | * | |
| 3068 | // | distribute simd | target | * | |
| 3069 | // | distribute simd | target parallel | * | |
| 3070 | // | distribute simd | target parallel | * | |
| 3071 | // | | for | | |
| 3072 | // | distribute simd | target enter | * | |
| 3073 | // | | data | | |
| 3074 | // | distribute simd | target exit | * | |
| 3075 | // | | data | | |
| 3076 | // | distribute simd | teams | * | |
| 3077 | // | distribute simd | cancellation | + | |
| 3078 | // | | point | | |
| 3079 | // | distribute simd | cancel | + | |
| 3080 | // | distribute simd | taskloop | * | |
| 3081 | // | distribute simd | taskloop simd | * | |
| 3082 | // | distribute simd | distribute | | |
| 3083 | // | distribute simd | distribute | * | |
| 3084 | // | | parallel for | | |
| 3085 | // | distribute simd | distribute | * | |
| 3086 | // | |parallel for simd| | |
| 3087 | // | distribute simd | distribute simd | * | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3088 | // | distribute simd | target parallel | * | |
| 3089 | // | | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3090 | // | distribute simd | target simd | * | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3091 | // | distribute simd | teams distribute| * | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3092 | // +------------------+-----------------+------------------------------------+ |
| 3093 | // | target parallel | parallel | * | |
| 3094 | // | for simd | | | |
| 3095 | // | target parallel | for | * | |
| 3096 | // | for simd | | | |
| 3097 | // | target parallel | for simd | * | |
| 3098 | // | for simd | | | |
| 3099 | // | target parallel | master | * | |
| 3100 | // | for simd | | | |
| 3101 | // | target parallel | critical | * | |
| 3102 | // | for simd | | | |
| 3103 | // | target parallel | simd | ! | |
| 3104 | // | for simd | | | |
| 3105 | // | target parallel | sections | * | |
| 3106 | // | for simd | | | |
| 3107 | // | target parallel | section | * | |
| 3108 | // | for simd | | | |
| 3109 | // | target parallel | single | * | |
| 3110 | // | for simd | | | |
| 3111 | // | target parallel | parallel for | * | |
| 3112 | // | for simd | | | |
| 3113 | // | target parallel |parallel for simd| * | |
| 3114 | // | for simd | | | |
| 3115 | // | target parallel |parallel sections| * | |
| 3116 | // | for simd | | | |
| 3117 | // | target parallel | task | * | |
| 3118 | // | for simd | | | |
| 3119 | // | target parallel | taskyield | * | |
| 3120 | // | for simd | | | |
| 3121 | // | target parallel | barrier | * | |
| 3122 | // | for simd | | | |
| 3123 | // | target parallel | taskwait | * | |
| 3124 | // | for simd | | | |
| 3125 | // | target parallel | taskgroup | * | |
| 3126 | // | for simd | | | |
| 3127 | // | target parallel | flush | * | |
| 3128 | // | for simd | | | |
| 3129 | // | target parallel | ordered | + (with simd clause) | |
| 3130 | // | for simd | | | |
| 3131 | // | target parallel | atomic | * | |
| 3132 | // | for simd | | | |
| 3133 | // | target parallel | target | * | |
| 3134 | // | for simd | | | |
| 3135 | // | target parallel | target parallel | * | |
| 3136 | // | for simd | | | |
| 3137 | // | target parallel | target parallel | * | |
| 3138 | // | for simd | for | | |
| 3139 | // | target parallel | target enter | * | |
| 3140 | // | for simd | data | | |
| 3141 | // | target parallel | target exit | * | |
| 3142 | // | for simd | data | | |
| 3143 | // | target parallel | teams | * | |
| 3144 | // | for simd | | | |
| 3145 | // | target parallel | cancellation | * | |
| 3146 | // | for simd | point | | |
| 3147 | // | target parallel | cancel | * | |
| 3148 | // | for simd | | | |
| 3149 | // | target parallel | taskloop | * | |
| 3150 | // | for simd | | | |
| 3151 | // | target parallel | taskloop simd | * | |
| 3152 | // | for simd | | | |
| 3153 | // | target parallel | distribute | * | |
| 3154 | // | for simd | | | |
| 3155 | // | target parallel | distribute | * | |
| 3156 | // | for simd | parallel for | | |
| 3157 | // | target parallel | distribute | * | |
| 3158 | // | for simd |parallel for simd| | |
| 3159 | // | target parallel | distribute simd | * | |
| 3160 | // | for simd | | | |
| 3161 | // | target parallel | target parallel | * | |
| 3162 | // | for simd | for simd | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3163 | // | target parallel | target simd | * | |
| 3164 | // | for simd | | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3165 | // | target parallel | teams distribute| * | |
| 3166 | // | for simd | | | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3167 | // +------------------+-----------------+------------------------------------+ |
| 3168 | // | target simd | parallel | | |
| 3169 | // | target simd | for | | |
| 3170 | // | target simd | for simd | | |
| 3171 | // | target simd | master | | |
| 3172 | // | target simd | critical | | |
| 3173 | // | target simd | simd | | |
| 3174 | // | target simd | sections | | |
| 3175 | // | target simd | section | | |
| 3176 | // | target simd | single | | |
| 3177 | // | target simd | parallel for | | |
| 3178 | // | target simd |parallel for simd| | |
| 3179 | // | target simd |parallel sections| | |
| 3180 | // | target simd | task | | |
| 3181 | // | target simd | taskyield | | |
| 3182 | // | target simd | barrier | | |
| 3183 | // | target simd | taskwait | | |
| 3184 | // | target simd | taskgroup | | |
| 3185 | // | target simd | flush | | |
| 3186 | // | target simd | ordered | + (with simd clause) | |
| 3187 | // | target simd | atomic | | |
| 3188 | // | target simd | target | | |
| 3189 | // | target simd | target parallel | | |
| 3190 | // | target simd | target parallel | | |
| 3191 | // | | for | | |
| 3192 | // | target simd | target enter | | |
| 3193 | // | | data | | |
| 3194 | // | target simd | target exit | | |
| 3195 | // | | data | | |
| 3196 | // | target simd | teams | | |
| 3197 | // | target simd | cancellation | | |
| 3198 | // | | point | | |
| 3199 | // | target simd | cancel | | |
| 3200 | // | target simd | taskloop | | |
| 3201 | // | target simd | taskloop simd | | |
| 3202 | // | target simd | distribute | | |
| 3203 | // | target simd | distribute | | |
| 3204 | // | | parallel for | | |
| 3205 | // | target simd | distribute | | |
| 3206 | // | |parallel for simd| | |
| 3207 | // | target simd | distribute simd | | |
| 3208 | // | target simd | target parallel | | |
| 3209 | // | | for simd | | |
| 3210 | // | target simd | target simd | | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3211 | // | target simd | teams distribute| | |
| 3212 | // +------------------+-----------------+------------------------------------+ |
| 3213 | // | teams distribute | parallel | | |
| 3214 | // | teams distribute | for | | |
| 3215 | // | teams distribute | for simd | | |
| 3216 | // | teams distribute | master | | |
| 3217 | // | teams distribute | critical | | |
| 3218 | // | teams distribute | simd | | |
| 3219 | // | teams distribute | sections | | |
| 3220 | // | teams distribute | section | | |
| 3221 | // | teams distribute | single | | |
| 3222 | // | teams distribute | parallel for | | |
| 3223 | // | teams distribute |parallel for simd| | |
| 3224 | // | teams distribute |parallel sections| | |
| 3225 | // | teams distribute | task | | |
| 3226 | // | teams distribute | taskyield | | |
| 3227 | // | teams distribute | barrier | | |
| 3228 | // | teams distribute | taskwait | | |
| 3229 | // | teams distribute | taskgroup | | |
| 3230 | // | teams distribute | flush | | |
| 3231 | // | teams distribute | ordered | + (with simd clause) | |
| 3232 | // | teams distribute | atomic | | |
| 3233 | // | teams distribute | target | | |
| 3234 | // | teams distribute | target parallel | | |
| 3235 | // | teams distribute | target parallel | | |
| 3236 | // | | for | | |
| 3237 | // | teams distribute | target enter | | |
| 3238 | // | | data | | |
| 3239 | // | teams distribute | target exit | | |
| 3240 | // | | data | | |
| 3241 | // | teams distribute | teams | | |
| 3242 | // | teams distribute | cancellation | | |
| 3243 | // | | point | | |
| 3244 | // | teams distribute | cancel | | |
| 3245 | // | teams distribute | taskloop | | |
| 3246 | // | teams distribute | taskloop simd | | |
| 3247 | // | teams distribute | distribute | | |
| 3248 | // | teams distribute | distribute | | |
| 3249 | // | | parallel for | | |
| 3250 | // | teams distribute | distribute | | |
| 3251 | // | |parallel for simd| | |
| 3252 | // | teams distribute | distribute simd | | |
| 3253 | // | teams distribute | target parallel | | |
| 3254 | // | | for simd | | |
| 3255 | // | teams distribute | teams distribute| | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3256 | // +------------------+-----------------+------------------------------------+ |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3257 | if (Stack->getCurScope()) { |
| 3258 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3259 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3260 | bool NestingProhibited = false; |
| 3261 | bool CloseNesting = true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3262 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3263 | enum { |
| 3264 | NoRecommend, |
| 3265 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3266 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3267 | ShouldBeInTargetRegion, |
| 3268 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3269 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3270 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3271 | // OpenMP [2.16, Nesting of Regions] |
| 3272 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3273 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3274 | // An ordered construct with the simd clause is the only OpenMP |
| 3275 | // construct that can appear in the simd region. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3276 | // Allowing a SIMD construct nested in another SIMD construct is an |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 3277 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 3278 | // message. |
| 3279 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 3280 | ? diag::err_omp_prohibited_region_simd |
| 3281 | : diag::warn_omp_nesting_simd); |
| 3282 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3283 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3284 | if (ParentRegion == OMPD_atomic) { |
| 3285 | // OpenMP [2.16, Nesting of Regions] |
| 3286 | // OpenMP constructs may not be nested inside an atomic region. |
| 3287 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 3288 | return true; |
| 3289 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3290 | if (CurrentRegion == OMPD_section) { |
| 3291 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 3292 | // Orphaned section directives are prohibited. That is, the section |
| 3293 | // directives must appear within the sections construct and must not be |
| 3294 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3295 | if (ParentRegion != OMPD_sections && |
| 3296 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3297 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 3298 | << (ParentRegion != OMPD_unknown) |
| 3299 | << getOpenMPDirectiveName(ParentRegion); |
| 3300 | return true; |
| 3301 | } |
| 3302 | return false; |
| 3303 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3304 | // Allow some constructs (except teams) to be orphaned (they could be |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3305 | // used in functions, called from OpenMP regions with the required |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3306 | // preconditions). |
| 3307 | if (ParentRegion == OMPD_unknown && !isOpenMPTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3308 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3309 | if (CurrentRegion == OMPD_cancellation_point || |
| 3310 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3311 | // OpenMP [2.16, Nesting of Regions] |
| 3312 | // A cancellation point construct for which construct-type-clause is |
| 3313 | // taskgroup must be nested inside a task construct. A cancellation |
| 3314 | // point construct for which construct-type-clause is not taskgroup must |
| 3315 | // be closely nested inside an OpenMP construct that matches the type |
| 3316 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3317 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 3318 | // nested inside a task construct. A cancel construct for which |
| 3319 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 3320 | // OpenMP construct that matches the type specified in |
| 3321 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3322 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3323 | !((CancelRegion == OMPD_parallel && |
| 3324 | (ParentRegion == OMPD_parallel || |
| 3325 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3326 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3327 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 3328 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3329 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 3330 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 3331 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 3332 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3333 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3334 | // OpenMP [2.16, Nesting of Regions] |
| 3335 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3336 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3337 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3338 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3339 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 3340 | // OpenMP [2.16, Nesting of Regions] |
| 3341 | // A critical region may not be nested (closely or otherwise) inside a |
| 3342 | // critical region with the same name. Note that this restriction is not |
| 3343 | // sufficient to prevent deadlock. |
| 3344 | SourceLocation PreviousCriticalLoc; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3345 | bool DeadLock = Stack->hasDirective( |
| 3346 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 3347 | const DeclarationNameInfo &DNI, |
| 3348 | SourceLocation Loc) -> bool { |
| 3349 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 3350 | PreviousCriticalLoc = Loc; |
| 3351 | return true; |
| 3352 | } else |
| 3353 | return false; |
| 3354 | }, |
| 3355 | false /* skip top directive */); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3356 | if (DeadLock) { |
| 3357 | SemaRef.Diag(StartLoc, |
| 3358 | diag::err_omp_prohibited_region_critical_same_name) |
| 3359 | << CurrentName.getName(); |
| 3360 | if (PreviousCriticalLoc.isValid()) |
| 3361 | SemaRef.Diag(PreviousCriticalLoc, |
| 3362 | diag::note_omp_previous_critical_region); |
| 3363 | return true; |
| 3364 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3365 | } else if (CurrentRegion == OMPD_barrier) { |
| 3366 | // OpenMP [2.16, Nesting of Regions] |
| 3367 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3368 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3369 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3370 | isOpenMPTaskingDirective(ParentRegion) || |
| 3371 | ParentRegion == OMPD_master || |
| 3372 | ParentRegion == OMPD_critical || |
| 3373 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3374 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3375 | !isOpenMPParallelDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3376 | // OpenMP [2.16, Nesting of Regions] |
| 3377 | // A worksharing region may not be closely nested inside a worksharing, |
| 3378 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3379 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 3380 | isOpenMPTaskingDirective(ParentRegion) || |
| 3381 | ParentRegion == OMPD_master || |
| 3382 | ParentRegion == OMPD_critical || |
| 3383 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3384 | Recommend = ShouldBeInParallelRegion; |
| 3385 | } else if (CurrentRegion == OMPD_ordered) { |
| 3386 | // OpenMP [2.16, Nesting of Regions] |
| 3387 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3388 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3389 | // An ordered region must be closely nested inside a loop region (or |
| 3390 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3391 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 3392 | // An ordered construct with the simd clause is the only OpenMP construct |
| 3393 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3394 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 3395 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 3396 | !(isOpenMPSimdDirective(ParentRegion) || |
| 3397 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3398 | Recommend = ShouldBeInOrderedRegion; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3399 | } else if (isOpenMPTeamsDirective(CurrentRegion)) { |
| 3400 | // OpenMP [2.16, Nesting of Regions] |
| 3401 | // If specified, a teams construct must be contained within a target |
| 3402 | // construct. |
| 3403 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3404 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3405 | Recommend = ShouldBeInTargetRegion; |
| 3406 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 3407 | } |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3408 | if (!NestingProhibited && ParentRegion == OMPD_teams) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3409 | // OpenMP [2.16, Nesting of Regions] |
| 3410 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 3411 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 3412 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3413 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 3414 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3415 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3416 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3417 | if (!NestingProhibited && |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3418 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3419 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3420 | // The region associated with the distribute construct must be strictly |
| 3421 | // nested inside a teams region |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3422 | NestingProhibited = ParentRegion != OMPD_teams; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3423 | Recommend = ShouldBeInTeamsRegion; |
| 3424 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3425 | if (!NestingProhibited && |
| 3426 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 3427 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 3428 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 3429 | // If a target, target update, target data, target enter data, or |
| 3430 | // target exit data construct is encountered during execution of a |
| 3431 | // target region, the behavior is unspecified. |
| 3432 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3433 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 3434 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 3435 | if (isOpenMPTargetExecutionDirective(K)) { |
| 3436 | OffendingRegion = K; |
| 3437 | return true; |
| 3438 | } else |
| 3439 | return false; |
| 3440 | }, |
| 3441 | false /* don't skip top directive */); |
| 3442 | CloseNesting = false; |
| 3443 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3444 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 3445 | if (OrphanSeen) { |
| 3446 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 3447 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 3448 | } else { |
| 3449 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 3450 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 3451 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 3452 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3453 | return true; |
| 3454 | } |
| 3455 | } |
| 3456 | return false; |
| 3457 | } |
| 3458 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3459 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 3460 | ArrayRef<OMPClause *> Clauses, |
| 3461 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 3462 | bool ErrorFound = false; |
| 3463 | unsigned NamedModifiersNumber = 0; |
| 3464 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 3465 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3466 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3467 | for (const auto *C : Clauses) { |
| 3468 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 3469 | // At most one if clause without a directive-name-modifier can appear on |
| 3470 | // the directive. |
| 3471 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 3472 | if (FoundNameModifiers[CurNM]) { |
| 3473 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 3474 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 3475 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 3476 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3477 | } else if (CurNM != OMPD_unknown) { |
| 3478 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3479 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3480 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3481 | FoundNameModifiers[CurNM] = IC; |
| 3482 | if (CurNM == OMPD_unknown) |
| 3483 | continue; |
| 3484 | // Check if the specified name modifier is allowed for the current |
| 3485 | // directive. |
| 3486 | // At most one if clause with the particular directive-name-modifier can |
| 3487 | // appear on the directive. |
| 3488 | bool MatchFound = false; |
| 3489 | for (auto NM : AllowedNameModifiers) { |
| 3490 | if (CurNM == NM) { |
| 3491 | MatchFound = true; |
| 3492 | break; |
| 3493 | } |
| 3494 | } |
| 3495 | if (!MatchFound) { |
| 3496 | S.Diag(IC->getNameModifierLoc(), |
| 3497 | diag::err_omp_wrong_if_directive_name_modifier) |
| 3498 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 3499 | ErrorFound = true; |
| 3500 | } |
| 3501 | } |
| 3502 | } |
| 3503 | // If any if clause on the directive includes a directive-name-modifier then |
| 3504 | // all if clauses on the directive must include a directive-name-modifier. |
| 3505 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 3506 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 3507 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 3508 | diag::err_omp_no_more_if_clause); |
| 3509 | } else { |
| 3510 | std::string Values; |
| 3511 | std::string Sep(", "); |
| 3512 | unsigned AllowedCnt = 0; |
| 3513 | unsigned TotalAllowedNum = |
| 3514 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 3515 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 3516 | ++Cnt) { |
| 3517 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 3518 | if (!FoundNameModifiers[NM]) { |
| 3519 | Values += "'"; |
| 3520 | Values += getOpenMPDirectiveName(NM); |
| 3521 | Values += "'"; |
| 3522 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 3523 | Values += " or "; |
| 3524 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 3525 | Values += Sep; |
| 3526 | ++AllowedCnt; |
| 3527 | } |
| 3528 | } |
| 3529 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 3530 | diag::err_omp_unnamed_if_clause) |
| 3531 | << (TotalAllowedNum > 1) << Values; |
| 3532 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 3533 | for (auto Loc : NameModifierLoc) { |
| 3534 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 3535 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3536 | ErrorFound = true; |
| 3537 | } |
| 3538 | return ErrorFound; |
| 3539 | } |
| 3540 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3541 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 3542 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 3543 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 3544 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3545 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3546 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 3547 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 3548 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3549 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3550 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3551 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3552 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3553 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3554 | if (AStmt) { |
| 3555 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 3556 | |
| 3557 | // Check default data sharing attributes for referenced variables. |
| 3558 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 3559 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 3560 | if (DSAChecker.isErrorFound()) |
| 3561 | return StmtError(); |
| 3562 | // Generate list of implicitly defined firstprivate variables. |
| 3563 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3564 | |
| 3565 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 3566 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 3567 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 3568 | SourceLocation(), SourceLocation())) { |
| 3569 | ClausesWithImplicit.push_back(Implicit); |
| 3570 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 3571 | DSAChecker.getImplicitFirstprivate().size(); |
| 3572 | } else |
| 3573 | ErrorFound = true; |
| 3574 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3575 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 3576 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3577 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3578 | switch (Kind) { |
| 3579 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3580 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3581 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3582 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3583 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3584 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3585 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3586 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 3587 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3588 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3589 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 3590 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 3591 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 3592 | case OMPD_for_simd: |
| 3593 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3594 | EndLoc, VarsWithInheritedDSA); |
| 3595 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 3596 | case OMPD_sections: |
| 3597 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3598 | EndLoc); |
| 3599 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3600 | case OMPD_section: |
| 3601 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3602 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 3603 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 3604 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 3605 | case OMPD_single: |
| 3606 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3607 | EndLoc); |
| 3608 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 3609 | case OMPD_master: |
| 3610 | assert(ClausesWithImplicit.empty() && |
| 3611 | "No clauses are allowed for 'omp master' directive"); |
| 3612 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 3613 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3614 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 3615 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 3616 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 3617 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3618 | case OMPD_parallel_for: |
| 3619 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3620 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3621 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3622 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3623 | case OMPD_parallel_for_simd: |
| 3624 | Res = ActOnOpenMPParallelForSimdDirective( |
| 3625 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3626 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 3627 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3628 | case OMPD_parallel_sections: |
| 3629 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 3630 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3631 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 3632 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3633 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3634 | Res = |
| 3635 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3636 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3637 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 3638 | case OMPD_taskyield: |
| 3639 | assert(ClausesWithImplicit.empty() && |
| 3640 | "No clauses are allowed for 'omp taskyield' directive"); |
| 3641 | assert(AStmt == nullptr && |
| 3642 | "No associated statement allowed for 'omp taskyield' directive"); |
| 3643 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 3644 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 3645 | case OMPD_barrier: |
| 3646 | assert(ClausesWithImplicit.empty() && |
| 3647 | "No clauses are allowed for 'omp barrier' directive"); |
| 3648 | assert(AStmt == nullptr && |
| 3649 | "No associated statement allowed for 'omp barrier' directive"); |
| 3650 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 3651 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 3652 | case OMPD_taskwait: |
| 3653 | assert(ClausesWithImplicit.empty() && |
| 3654 | "No clauses are allowed for 'omp taskwait' directive"); |
| 3655 | assert(AStmt == nullptr && |
| 3656 | "No associated statement allowed for 'omp taskwait' directive"); |
| 3657 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 3658 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 3659 | case OMPD_taskgroup: |
| 3660 | assert(ClausesWithImplicit.empty() && |
| 3661 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 3662 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 3663 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 3664 | case OMPD_flush: |
| 3665 | assert(AStmt == nullptr && |
| 3666 | "No associated statement allowed for 'omp flush' directive"); |
| 3667 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3668 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3669 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 3670 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3671 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 3672 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 3673 | case OMPD_atomic: |
| 3674 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3675 | EndLoc); |
| 3676 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 3677 | case OMPD_teams: |
| 3678 | Res = |
| 3679 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 3680 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3681 | case OMPD_target: |
| 3682 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3683 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3684 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 3685 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 3686 | case OMPD_target_parallel: |
| 3687 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 3688 | StartLoc, EndLoc); |
| 3689 | AllowedNameModifiers.push_back(OMPD_target); |
| 3690 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3691 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 3692 | case OMPD_target_parallel_for: |
| 3693 | Res = ActOnOpenMPTargetParallelForDirective( |
| 3694 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3695 | AllowedNameModifiers.push_back(OMPD_target); |
| 3696 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3697 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 3698 | case OMPD_cancellation_point: |
| 3699 | assert(ClausesWithImplicit.empty() && |
| 3700 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 3701 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 3702 | "cancellation point' directive"); |
| 3703 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 3704 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3705 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3706 | assert(AStmt == nullptr && |
| 3707 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 3708 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 3709 | CancelRegion); |
| 3710 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 3711 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3712 | case OMPD_target_data: |
| 3713 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3714 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3715 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 3716 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 3717 | case OMPD_target_enter_data: |
| 3718 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 3719 | EndLoc); |
| 3720 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 3721 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 3722 | case OMPD_target_exit_data: |
| 3723 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 3724 | EndLoc); |
| 3725 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 3726 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 3727 | case OMPD_taskloop: |
| 3728 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3729 | EndLoc, VarsWithInheritedDSA); |
| 3730 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3731 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 3732 | case OMPD_taskloop_simd: |
| 3733 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3734 | EndLoc, VarsWithInheritedDSA); |
| 3735 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 3736 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 3737 | case OMPD_distribute: |
| 3738 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3739 | EndLoc, VarsWithInheritedDSA); |
| 3740 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 3741 | case OMPD_target_update: |
| 3742 | assert(!AStmt && "Statement is not allowed for target update"); |
| 3743 | Res = |
| 3744 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 3745 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 3746 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 3747 | case OMPD_distribute_parallel_for: |
| 3748 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 3749 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3750 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3751 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 3752 | case OMPD_distribute_parallel_for_simd: |
| 3753 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 3754 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3755 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3756 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 3757 | case OMPD_distribute_simd: |
| 3758 | Res = ActOnOpenMPDistributeSimdDirective( |
| 3759 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3760 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 3761 | case OMPD_target_parallel_for_simd: |
| 3762 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 3763 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 3764 | AllowedNameModifiers.push_back(OMPD_target); |
| 3765 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 3766 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 3767 | case OMPD_target_simd: |
| 3768 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 3769 | EndLoc, VarsWithInheritedDSA); |
| 3770 | AllowedNameModifiers.push_back(OMPD_target); |
| 3771 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3772 | case OMPD_teams_distribute: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3773 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 3774 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 3775 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 3776 | case OMPD_declare_target: |
| 3777 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 3778 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3779 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3780 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3781 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 3782 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3783 | llvm_unreachable("Unknown OpenMP directive"); |
| 3784 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 3785 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3786 | for (auto P : VarsWithInheritedDSA) { |
| 3787 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 3788 | << P.first << P.second->getSourceRange(); |
| 3789 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 3790 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 3791 | |
| 3792 | if (!AllowedNameModifiers.empty()) |
| 3793 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 3794 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3795 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 3796 | if (ErrorFound) |
| 3797 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 3798 | return Res; |
| 3799 | } |
| 3800 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3801 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 3802 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3803 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3804 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 3805 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3806 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3807 | assert(Linears.size() == LinModifiers.size()); |
| 3808 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3809 | if (!DG || DG.get().isNull()) |
| 3810 | return DeclGroupPtrTy(); |
| 3811 | |
| 3812 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 3813 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3814 | return DG; |
| 3815 | } |
| 3816 | auto *ADecl = DG.get().getSingleDecl(); |
| 3817 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 3818 | ADecl = FTD->getTemplatedDecl(); |
| 3819 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3820 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 3821 | if (!FD) { |
| 3822 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 3823 | return DeclGroupPtrTy(); |
| 3824 | } |
| 3825 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3826 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3827 | // The parameter of the simdlen clause must be a constant positive integer |
| 3828 | // expression. |
| 3829 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3830 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3831 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3832 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3833 | // The special this pointer can be used as if was one of the arguments to the |
| 3834 | // function in any of the linear, aligned, or uniform clauses. |
| 3835 | // The uniform clause declares one or more arguments to have an invariant |
| 3836 | // value for all concurrent invocations of the function in the execution of a |
| 3837 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3838 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 3839 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3840 | for (auto *E : Uniforms) { |
| 3841 | E = E->IgnoreParenImpCasts(); |
| 3842 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3843 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 3844 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3845 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3846 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 3847 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3848 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3849 | } |
| 3850 | if (isa<CXXThisExpr>(E)) { |
| 3851 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3852 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3853 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 3854 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3855 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 3856 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 3857 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3858 | // The aligned clause declares that the object to which each list item points |
| 3859 | // is aligned to the number of bytes expressed in the optional parameter of |
| 3860 | // the aligned clause. |
| 3861 | // The special this pointer can be used as if was one of the arguments to the |
| 3862 | // function in any of the linear, aligned, or uniform clauses. |
| 3863 | // The type of list items appearing in the aligned clause must be array, |
| 3864 | // pointer, reference to array, or reference to pointer. |
| 3865 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 3866 | Expr *AlignedThis = nullptr; |
| 3867 | for (auto *E : Aligneds) { |
| 3868 | E = E->IgnoreParenImpCasts(); |
| 3869 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3870 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3871 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3872 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3873 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3874 | ->getCanonicalDecl() == CanonPVD) { |
| 3875 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3876 | // A list-item cannot appear in more than one aligned clause. |
| 3877 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 3878 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3879 | << 1 << E->getSourceRange(); |
| 3880 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 3881 | diag::note_omp_explicit_dsa) |
| 3882 | << getOpenMPClauseName(OMPC_aligned); |
| 3883 | continue; |
| 3884 | } |
| 3885 | AlignedArgs[CanonPVD] = E; |
| 3886 | QualType QTy = PVD->getType() |
| 3887 | .getNonReferenceType() |
| 3888 | .getUnqualifiedType() |
| 3889 | .getCanonicalType(); |
| 3890 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 3891 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 3892 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 3893 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 3894 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 3895 | } |
| 3896 | continue; |
| 3897 | } |
| 3898 | } |
| 3899 | if (isa<CXXThisExpr>(E)) { |
| 3900 | if (AlignedThis) { |
| 3901 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 3902 | << 2 << E->getSourceRange(); |
| 3903 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3904 | << getOpenMPClauseName(OMPC_aligned); |
| 3905 | } |
| 3906 | AlignedThis = E; |
| 3907 | continue; |
| 3908 | } |
| 3909 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3910 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3911 | } |
| 3912 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 3913 | // positive integer expression. If no optional parameter is specified, |
| 3914 | // implementation-defined default alignments for SIMD instructions on the |
| 3915 | // target platforms are assumed. |
| 3916 | SmallVector<Expr *, 4> NewAligns; |
| 3917 | for (auto *E : Alignments) { |
| 3918 | ExprResult Align; |
| 3919 | if (E) |
| 3920 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 3921 | NewAligns.push_back(Align.get()); |
| 3922 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 3923 | // OpenMP [2.8.2, declare simd construct, Description] |
| 3924 | // The linear clause declares one or more list items to be private to a SIMD |
| 3925 | // lane and to have a linear relationship with respect to the iteration space |
| 3926 | // of a loop. |
| 3927 | // The special this pointer can be used as if was one of the arguments to the |
| 3928 | // function in any of the linear, aligned, or uniform clauses. |
| 3929 | // When a linear-step expression is specified in a linear clause it must be |
| 3930 | // either a constant integer expression or an integer-typed parameter that is |
| 3931 | // specified in a uniform clause on the directive. |
| 3932 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 3933 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 3934 | auto MI = LinModifiers.begin(); |
| 3935 | for (auto *E : Linears) { |
| 3936 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 3937 | ++MI; |
| 3938 | E = E->IgnoreParenImpCasts(); |
| 3939 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 3940 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 3941 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 3942 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 3943 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 3944 | ->getCanonicalDecl() == CanonPVD) { |
| 3945 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 3946 | // A list-item cannot appear in more than one linear clause. |
| 3947 | if (LinearArgs.count(CanonPVD) > 0) { |
| 3948 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3949 | << getOpenMPClauseName(OMPC_linear) |
| 3950 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 3951 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 3952 | diag::note_omp_explicit_dsa) |
| 3953 | << getOpenMPClauseName(OMPC_linear); |
| 3954 | continue; |
| 3955 | } |
| 3956 | // Each argument can appear in at most one uniform or linear clause. |
| 3957 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 3958 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3959 | << getOpenMPClauseName(OMPC_linear) |
| 3960 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 3961 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 3962 | diag::note_omp_explicit_dsa) |
| 3963 | << getOpenMPClauseName(OMPC_uniform); |
| 3964 | continue; |
| 3965 | } |
| 3966 | LinearArgs[CanonPVD] = E; |
| 3967 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3968 | E->isInstantiationDependent() || |
| 3969 | E->containsUnexpandedParameterPack()) |
| 3970 | continue; |
| 3971 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 3972 | PVD->getOriginalType()); |
| 3973 | continue; |
| 3974 | } |
| 3975 | } |
| 3976 | if (isa<CXXThisExpr>(E)) { |
| 3977 | if (UniformedLinearThis) { |
| 3978 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 3979 | << getOpenMPClauseName(OMPC_linear) |
| 3980 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 3981 | << E->getSourceRange(); |
| 3982 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 3983 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 3984 | : OMPC_linear); |
| 3985 | continue; |
| 3986 | } |
| 3987 | UniformedLinearThis = E; |
| 3988 | if (E->isValueDependent() || E->isTypeDependent() || |
| 3989 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 3990 | continue; |
| 3991 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 3992 | E->getType()); |
| 3993 | continue; |
| 3994 | } |
| 3995 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 3996 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 3997 | } |
| 3998 | Expr *Step = nullptr; |
| 3999 | Expr *NewStep = nullptr; |
| 4000 | SmallVector<Expr *, 4> NewSteps; |
| 4001 | for (auto *E : Steps) { |
| 4002 | // Skip the same step expression, it was checked already. |
| 4003 | if (Step == E || !E) { |
| 4004 | NewSteps.push_back(E ? NewStep : nullptr); |
| 4005 | continue; |
| 4006 | } |
| 4007 | Step = E; |
| 4008 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 4009 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 4010 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 4011 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 4012 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 4013 | << Step->getSourceRange(); |
| 4014 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 4015 | E->isInstantiationDependent() || |
| 4016 | E->containsUnexpandedParameterPack() || |
| 4017 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 4018 | NewSteps.push_back(Step); |
| 4019 | else { |
| 4020 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 4021 | << Step->getSourceRange(); |
| 4022 | } |
| 4023 | continue; |
| 4024 | } |
| 4025 | NewStep = Step; |
| 4026 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 4027 | !Step->isInstantiationDependent() && |
| 4028 | !Step->containsUnexpandedParameterPack()) { |
| 4029 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 4030 | .get(); |
| 4031 | if (NewStep) |
| 4032 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 4033 | } |
| 4034 | NewSteps.push_back(NewStep); |
| 4035 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 4036 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 4037 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 4038 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 4039 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 4040 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 4041 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 4042 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 4043 | ADecl->addAttr(NewAttr); |
| 4044 | return ConvertDeclToDeclGroup(ADecl); |
| 4045 | } |
| 4046 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4047 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 4048 | Stmt *AStmt, |
| 4049 | SourceLocation StartLoc, |
| 4050 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4051 | if (!AStmt) |
| 4052 | return StmtError(); |
| 4053 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 4054 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4055 | // 1.2.2 OpenMP Language Terminology |
| 4056 | // Structured block - An executable statement with a single entry at the |
| 4057 | // top and a single exit at the bottom. |
| 4058 | // The point of exit cannot be a branch out of the structured block. |
| 4059 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4060 | CS->getCapturedDecl()->setNothrow(); |
| 4061 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4062 | getCurFunction()->setHasBranchProtectedScope(); |
| 4063 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4064 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4065 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 4066 | } |
| 4067 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4068 | namespace { |
| 4069 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 4070 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 4071 | /// for IR generation. |
| 4072 | class OpenMPIterationSpaceChecker { |
| 4073 | /// \brief Reference to Sema. |
| 4074 | Sema &SemaRef; |
| 4075 | /// \brief A location for diagnostics (when there is no some better location). |
| 4076 | SourceLocation DefaultLoc; |
| 4077 | /// \brief A location for diagnostics (when increment is not compatible). |
| 4078 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4079 | /// \brief A source location for referring to loop init later. |
| 4080 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4081 | /// \brief A source location for referring to condition later. |
| 4082 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4083 | /// \brief A source location for referring to increment later. |
| 4084 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4085 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4086 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4087 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4088 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4089 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4090 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4091 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4092 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4093 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4094 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4095 | /// \brief This flag is true when condition is one of: |
| 4096 | /// Var < UB |
| 4097 | /// Var <= UB |
| 4098 | /// UB > Var |
| 4099 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4100 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4101 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4102 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4103 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4104 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4105 | |
| 4106 | public: |
| 4107 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4108 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4109 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 4110 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4111 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4112 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 4113 | /// for less/greater and for strict/non-strict comparison. |
| 4114 | bool CheckCond(Expr *S); |
| 4115 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 4116 | /// does not conform, otherwise save loop step (#Step). |
| 4117 | bool CheckInc(Expr *S); |
| 4118 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4119 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4120 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4121 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4122 | /// \brief Source range of the loop init. |
| 4123 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 4124 | /// \brief Source range of the loop condition. |
| 4125 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 4126 | /// \brief Source range of the loop increment. |
| 4127 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 4128 | /// \brief True if the step should be subtracted. |
| 4129 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 4130 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4131 | Expr * |
| 4132 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 4133 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4134 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4135 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 4136 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4137 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4138 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 4139 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4140 | /// \brief Build reference expression to the private counter be used for |
| 4141 | /// codegen. |
| 4142 | Expr *BuildPrivateCounterVar() const; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4143 | /// \brief Build initialization of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4144 | Expr *BuildCounterInit() const; |
| 4145 | /// \brief Build step of the counter be used for codegen. |
| 4146 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4147 | /// \brief Return true if any expression is dependent. |
| 4148 | bool Dependent() const; |
| 4149 | |
| 4150 | private: |
| 4151 | /// \brief Check the right-hand side of an assignment in the increment |
| 4152 | /// expression. |
| 4153 | bool CheckIncRHS(Expr *RHS); |
| 4154 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4155 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4156 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 4157 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 4158 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4159 | /// \brief Helper to set loop increment. |
| 4160 | bool SetStep(Expr *NewStep, bool Subtract); |
| 4161 | }; |
| 4162 | |
| 4163 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4164 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4165 | assert(!LB && !UB && !Step); |
| 4166 | return false; |
| 4167 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4168 | return LCDecl->getType()->isDependentType() || |
| 4169 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 4170 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4173 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4174 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 4175 | E = ExprTemp->getSubExpr(); |
| 4176 | |
| 4177 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 4178 | E = MTE->GetTemporaryExpr(); |
| 4179 | |
| 4180 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 4181 | E = Binder->getSubExpr(); |
| 4182 | |
| 4183 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 4184 | E = ICE->getSubExprAsWritten(); |
| 4185 | return E->IgnoreParens(); |
| 4186 | } |
| 4187 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4188 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 4189 | Expr *NewLCRefExpr, |
| 4190 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4191 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4192 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 4193 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4194 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4195 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4196 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 4197 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4198 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 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) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4203 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4204 | LB = NewLB; |
| 4205 | return false; |
| 4206 | } |
| 4207 | |
| 4208 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 4209 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4210 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4211 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 4212 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4213 | if (!NewUB) |
| 4214 | return true; |
| 4215 | UB = NewUB; |
| 4216 | TestIsLessOp = LessOp; |
| 4217 | TestIsStrictOp = StrictOp; |
| 4218 | ConditionSrcRange = SR; |
| 4219 | ConditionLoc = SL; |
| 4220 | return false; |
| 4221 | } |
| 4222 | |
| 4223 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 4224 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4225 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4226 | if (!NewStep) |
| 4227 | return true; |
| 4228 | if (!NewStep->isValueDependent()) { |
| 4229 | // Check that the step is integer expression. |
| 4230 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 4231 | ExprResult Val = |
| 4232 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 4233 | if (Val.isInvalid()) |
| 4234 | return true; |
| 4235 | NewStep = Val.get(); |
| 4236 | |
| 4237 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 4238 | // If test-expr is of form var relational-op b and relational-op is < or |
| 4239 | // <= then incr-expr must cause var to increase on each iteration of the |
| 4240 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 4241 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 4242 | // the loop. |
| 4243 | // If test-expr is of form b relational-op var and relational-op is < or |
| 4244 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 4245 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 4246 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 4247 | // the loop. |
| 4248 | llvm::APSInt Result; |
| 4249 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4250 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 4251 | bool IsConstNeg = |
| 4252 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4253 | bool IsConstPos = |
| 4254 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4255 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 4256 | if (UB && (IsConstZero || |
| 4257 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4258 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4259 | SemaRef.Diag(NewStep->getExprLoc(), |
| 4260 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4261 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4262 | SemaRef.Diag(ConditionLoc, |
| 4263 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 4264 | << TestIsLessOp << ConditionSrcRange; |
| 4265 | return true; |
| 4266 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4267 | if (TestIsLessOp == Subtract) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4268 | NewStep = |
| 4269 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 4270 | .get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4271 | Subtract = !Subtract; |
| 4272 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | Step = NewStep; |
| 4276 | SubtractStep = Subtract; |
| 4277 | return false; |
| 4278 | } |
| 4279 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4280 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4281 | // Check init-expr for canonical loop form and save loop counter |
| 4282 | // variable - #Var and its initialization value - #LB. |
| 4283 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 4284 | // var = lb |
| 4285 | // integer-type var = lb |
| 4286 | // random-access-iterator-type var = lb |
| 4287 | // pointer-type var = lb |
| 4288 | // |
| 4289 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4290 | if (EmitDiags) { |
| 4291 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 4292 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4293 | return true; |
| 4294 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4295 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4296 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4297 | S = ExprTemp->getSubExpr(); |
| 4298 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4299 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4300 | if (Expr *E = dyn_cast<Expr>(S)) |
| 4301 | S = E->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4302 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4303 | if (BO->getOpcode() == BO_Assign) { |
| 4304 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 4305 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 4306 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4307 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4308 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4309 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 4310 | } |
| 4311 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4312 | if (ME->isArrow() && |
| 4313 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4314 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4315 | } |
| 4316 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4317 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4318 | if (DS->isSingleDecl()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4319 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4320 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4321 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4322 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4323 | SemaRef.Diag(S->getLocStart(), |
| 4324 | diag::ext_omp_loop_not_canonical_init) |
| 4325 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4326 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4327 | } |
| 4328 | } |
| 4329 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4330 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4331 | if (CE->getOperator() == OO_Equal) { |
| 4332 | auto *LHS = CE->getArg(0); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4333 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4334 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 4335 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4336 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4337 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 4338 | } |
| 4339 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 4340 | if (ME->isArrow() && |
| 4341 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4342 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 4343 | } |
| 4344 | } |
| 4345 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4346 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4347 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4348 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4349 | if (EmitDiags) { |
| 4350 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 4351 | << S->getSourceRange(); |
| 4352 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4353 | return true; |
| 4354 | } |
| 4355 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4356 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4357 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4358 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4359 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 4360 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4361 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4362 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 4363 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 4364 | if ((Ctor->isCopyOrMoveConstructor() || |
| 4365 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 4366 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4367 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4368 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 4369 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 4370 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 4371 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 4372 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4373 | return getCanonicalDecl(VD); |
| 4374 | } |
| 4375 | } |
| 4376 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 4377 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 4378 | return getCanonicalDecl(ME->getMemberDecl()); |
| 4379 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 4383 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 4384 | // less/greater and for strict/non-strict comparison. |
| 4385 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4386 | // var relational-op b |
| 4387 | // b relational-op var |
| 4388 | // |
| 4389 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4390 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4391 | return true; |
| 4392 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4393 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4394 | SourceLocation CondLoc = S->getLocStart(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4395 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4396 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4397 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4398 | return SetUB(BO->getRHS(), |
| 4399 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 4400 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4401 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4402 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4403 | return SetUB(BO->getLHS(), |
| 4404 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 4405 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 4406 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 4407 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4408 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4409 | if (CE->getNumArgs() == 2) { |
| 4410 | auto Op = CE->getOperator(); |
| 4411 | switch (Op) { |
| 4412 | case OO_Greater: |
| 4413 | case OO_GreaterEqual: |
| 4414 | case OO_Less: |
| 4415 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4416 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4417 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 4418 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4419 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4420 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4421 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 4422 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 4423 | CE->getOperatorLoc()); |
| 4424 | break; |
| 4425 | default: |
| 4426 | break; |
| 4427 | } |
| 4428 | } |
| 4429 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4430 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4431 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4432 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4433 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4434 | return true; |
| 4435 | } |
| 4436 | |
| 4437 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 4438 | // RHS of canonical loop form increment can be: |
| 4439 | // var + incr |
| 4440 | // incr + var |
| 4441 | // var - incr |
| 4442 | // |
| 4443 | RHS = RHS->IgnoreParenImpCasts(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4444 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4445 | if (BO->isAdditiveOp()) { |
| 4446 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4447 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4448 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4449 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4450 | return SetStep(BO->getLHS(), false); |
| 4451 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4452 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4453 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 4454 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4455 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4456 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4457 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4458 | return SetStep(CE->getArg(0), false); |
| 4459 | } |
| 4460 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4461 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4462 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4463 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4464 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4465 | return true; |
| 4466 | } |
| 4467 | |
| 4468 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 4469 | // Check incr-expr for canonical loop form and return true if it |
| 4470 | // does not conform. |
| 4471 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 4472 | // ++var |
| 4473 | // var++ |
| 4474 | // --var |
| 4475 | // var-- |
| 4476 | // var += incr |
| 4477 | // var -= incr |
| 4478 | // var = var + incr |
| 4479 | // var = incr + var |
| 4480 | // var = var - incr |
| 4481 | // |
| 4482 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4483 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4484 | return true; |
| 4485 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 4486 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 4487 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 4488 | S = ExprTemp->getSubExpr(); |
| 4489 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4490 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4491 | S = S->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4492 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4493 | if (UO->isIncrementDecrementOp() && |
| 4494 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4495 | return SetStep(SemaRef |
| 4496 | .ActOnIntegerConstant(UO->getLocStart(), |
| 4497 | (UO->isDecrementOp() ? -1 : 1)) |
| 4498 | .get(), |
| 4499 | false); |
| 4500 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4501 | switch (BO->getOpcode()) { |
| 4502 | case BO_AddAssign: |
| 4503 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4504 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4505 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 4506 | break; |
| 4507 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4508 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4509 | return CheckIncRHS(BO->getRHS()); |
| 4510 | break; |
| 4511 | default: |
| 4512 | break; |
| 4513 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4514 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4515 | switch (CE->getOperator()) { |
| 4516 | case OO_PlusPlus: |
| 4517 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4518 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4519 | return SetStep(SemaRef |
| 4520 | .ActOnIntegerConstant( |
| 4521 | CE->getLocStart(), |
| 4522 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 4523 | .get(), |
| 4524 | false); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4525 | break; |
| 4526 | case OO_PlusEqual: |
| 4527 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4528 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4529 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 4530 | break; |
| 4531 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4532 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4533 | return CheckIncRHS(CE->getArg(1)); |
| 4534 | break; |
| 4535 | default: |
| 4536 | break; |
| 4537 | } |
| 4538 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4539 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 4540 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4541 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4542 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4543 | return true; |
| 4544 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4545 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4546 | static ExprResult |
| 4547 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 4548 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 4549 | if (SemaRef.CurContext->isDependentContext()) |
| 4550 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4551 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 4552 | return SemaRef.PerformImplicitConversion( |
| 4553 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 4554 | /*AllowExplicit=*/true); |
| 4555 | auto I = Captures.find(Capture); |
| 4556 | if (I != Captures.end()) |
| 4557 | return buildCapture(SemaRef, Capture, I->second); |
| 4558 | DeclRefExpr *Ref = nullptr; |
| 4559 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 4560 | Captures[Capture] = Ref; |
| 4561 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4562 | } |
| 4563 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4564 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4565 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 4566 | Scope *S, const bool LimitedType, |
| 4567 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4568 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4569 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4570 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4571 | SemaRef.getLangOpts().CPlusPlus) { |
| 4572 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4573 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 4574 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4575 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 4576 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4577 | if (!Upper || !Lower) |
| 4578 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4579 | |
| 4580 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 4581 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4582 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4583 | // BuildBinOp already emitted error, this one is to point user to upper |
| 4584 | // and lower bound, and to tell what is passed to 'operator-'. |
| 4585 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 4586 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 4587 | return nullptr; |
| 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | if (!Diff.isUsable()) |
| 4592 | return nullptr; |
| 4593 | |
| 4594 | // Upper - Lower [- 1] |
| 4595 | if (TestIsStrictOp) |
| 4596 | Diff = SemaRef.BuildBinOp( |
| 4597 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 4598 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4599 | if (!Diff.isUsable()) |
| 4600 | return nullptr; |
| 4601 | |
| 4602 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4603 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 4604 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4605 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4606 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4607 | if (!Diff.isUsable()) |
| 4608 | return nullptr; |
| 4609 | |
| 4610 | // Parentheses (for dumping/debugging purposes only). |
| 4611 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 4612 | if (!Diff.isUsable()) |
| 4613 | return nullptr; |
| 4614 | |
| 4615 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4616 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4617 | if (!Diff.isUsable()) |
| 4618 | return nullptr; |
| 4619 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4620 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4621 | QualType Type = Diff.get()->getType(); |
| 4622 | auto &C = SemaRef.Context; |
| 4623 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 4624 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 4625 | if (!Type->isIntegerType() || UseVarType) { |
| 4626 | unsigned NewSize = |
| 4627 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 4628 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 4629 | : Type->hasSignedIntegerRepresentation(); |
| 4630 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4631 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 4632 | Diff = SemaRef.PerformImplicitConversion( |
| 4633 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 4634 | if (!Diff.isUsable()) |
| 4635 | return nullptr; |
| 4636 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4637 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4638 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4639 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 4640 | if (NewSize != C.getTypeSize(Type)) { |
| 4641 | if (NewSize < C.getTypeSize(Type)) { |
| 4642 | assert(NewSize == 64 && "incorrect loop var size"); |
| 4643 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 4644 | << InitSrcRange << ConditionSrcRange; |
| 4645 | } |
| 4646 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4647 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 4648 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4649 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 4650 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 4651 | Sema::AA_Converting, true); |
| 4652 | if (!Diff.isUsable()) |
| 4653 | return nullptr; |
| 4654 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4655 | } |
| 4656 | } |
| 4657 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4658 | return Diff.get(); |
| 4659 | } |
| 4660 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4661 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 4662 | Scope *S, Expr *Cond, |
| 4663 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4664 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 4665 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4666 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4667 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4668 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 4669 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 4670 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 4671 | return nullptr; |
| 4672 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4673 | auto CondExpr = SemaRef.BuildBinOp( |
| 4674 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 4675 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4676 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4677 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4678 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 4679 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4680 | CondExpr = SemaRef.PerformImplicitConversion( |
| 4681 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 4682 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4683 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4684 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 4685 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 4686 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 4687 | } |
| 4688 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4689 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4690 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4691 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4692 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 4693 | if (!VD) { |
| 4694 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 4695 | auto *Ref = buildDeclRefExpr( |
| 4696 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4697 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 4698 | // If the loop control decl is explicitly marked as private, do not mark it |
| 4699 | // as captured again. |
| 4700 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 4701 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4702 | return Ref; |
| 4703 | } |
| 4704 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4705 | DefaultLoc); |
| 4706 | } |
| 4707 | |
| 4708 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4709 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 4710 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 4711 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4712 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 4713 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4714 | if (PrivateVar->isInvalidDecl()) |
| 4715 | return nullptr; |
| 4716 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 4717 | } |
| 4718 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4719 | } |
| 4720 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4721 | /// \brief Build instillation of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4722 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 4723 | |
| 4724 | /// \brief Build step of the counter be used for codegen. |
| 4725 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 4726 | |
| 4727 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4728 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4729 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4730 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4731 | /// \brief This expression calculates the number of iterations in the loop. |
| 4732 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4733 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4734 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4735 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4736 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4737 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4738 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4739 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4740 | /// \brief This is step for the #CounterVar used to generate its update: |
| 4741 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4742 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4743 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4744 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4745 | /// \brief Source range of the loop init. |
| 4746 | SourceRange InitSrcRange; |
| 4747 | /// \brief Source range of the loop condition. |
| 4748 | SourceRange CondSrcRange; |
| 4749 | /// \brief Source range of the loop increment. |
| 4750 | SourceRange IncSrcRange; |
| 4751 | }; |
| 4752 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 4753 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4754 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4755 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 4756 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 4757 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4758 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 4759 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4760 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 4761 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4762 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 4763 | if (auto *D = ISC.GetLoopDecl()) { |
| 4764 | auto *VD = dyn_cast<VarDecl>(D); |
| 4765 | if (!VD) { |
| 4766 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 4767 | VD = Private; |
| 4768 | else { |
| 4769 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 4770 | /*WithInit=*/false); |
| 4771 | VD = cast<VarDecl>(Ref->getDecl()); |
| 4772 | } |
| 4773 | } |
| 4774 | DSAStack->addLoopControlVariable(D, VD); |
| 4775 | } |
| 4776 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4777 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 4778 | } |
| 4779 | } |
| 4780 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4781 | /// \brief Called on a for stmt to check and extract its iteration space |
| 4782 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4783 | static bool CheckOpenMPIterationSpace( |
| 4784 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 4785 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4786 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4787 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4788 | LoopIterationSpace &ResultIterSpace, |
| 4789 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4790 | // OpenMP [2.6, Canonical Loop Form] |
| 4791 | // for (init-expr; test-expr; incr-expr) structured-block |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4792 | auto *For = dyn_cast_or_null<ForStmt>(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4793 | if (!For) { |
| 4794 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4795 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 4796 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 4797 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 4798 | if (NestedLoopCount > 1) { |
| 4799 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 4800 | SemaRef.Diag(DSA.getConstructLoc(), |
| 4801 | diag::note_omp_collapse_ordered_expr) |
| 4802 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 4803 | << OrderedLoopCountExpr->getSourceRange(); |
| 4804 | else if (CollapseLoopCountExpr) |
| 4805 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 4806 | diag::note_omp_collapse_ordered_expr) |
| 4807 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 4808 | else |
| 4809 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 4810 | diag::note_omp_collapse_ordered_expr) |
| 4811 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 4812 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4813 | return true; |
| 4814 | } |
| 4815 | assert(For->getBody()); |
| 4816 | |
| 4817 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 4818 | |
| 4819 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 4820 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4821 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4822 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4823 | |
| 4824 | bool HasErrors = false; |
| 4825 | |
| 4826 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4827 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 4828 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4829 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4830 | // OpenMP [2.6, Canonical Loop Form] |
| 4831 | // Var is one of the following: |
| 4832 | // A variable of signed or unsigned integer type. |
| 4833 | // For C++, a variable of a random access iterator type. |
| 4834 | // For C, a variable of a pointer type. |
| 4835 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 4836 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 4837 | !VarType->isPointerType() && |
| 4838 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 4839 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 4840 | << SemaRef.getLangOpts().CPlusPlus; |
| 4841 | HasErrors = true; |
| 4842 | } |
| 4843 | |
| 4844 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 4845 | // a Construct |
| 4846 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4847 | // parallel for construct is (are) private. |
| 4848 | // The loop iteration variable in the associated for-loop of a simd |
| 4849 | // construct with just one associated for-loop is linear with a |
| 4850 | // constant-linear-step that is the increment of the associated for-loop. |
| 4851 | // Exclude loop var from the list of variables with implicitly defined data |
| 4852 | // sharing attributes. |
| 4853 | VarsWithImplicitDSA.erase(LCDecl); |
| 4854 | |
| 4855 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 4856 | // in a Construct, C/C++]. |
| 4857 | // The loop iteration variable in the associated for-loop of a simd |
| 4858 | // construct with just one associated for-loop may be listed in a linear |
| 4859 | // clause with a constant-linear-step that is the increment of the |
| 4860 | // associated for-loop. |
| 4861 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 4862 | // parallel for construct may be listed in a private or lastprivate clause. |
| 4863 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 4864 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 4865 | // declared in the loop and it is predetermined as a private. |
| 4866 | auto PredeterminedCKind = |
| 4867 | isOpenMPSimdDirective(DKind) |
| 4868 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 4869 | : OMPC_private; |
| 4870 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4871 | DVar.CKind != PredeterminedCKind) || |
| 4872 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 4873 | isOpenMPDistributeDirective(DKind)) && |
| 4874 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 4875 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 4876 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 4877 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 4878 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 4879 | << getOpenMPClauseName(PredeterminedCKind); |
| 4880 | if (DVar.RefExpr == nullptr) |
| 4881 | DVar.CKind = PredeterminedCKind; |
| 4882 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 4883 | HasErrors = true; |
| 4884 | } else if (LoopDeclRefExpr != nullptr) { |
| 4885 | // Make the loop iteration variable private (for worksharing constructs), |
| 4886 | // linear (for simd directives with the only one associated loop) or |
| 4887 | // lastprivate (for simd directives with several collapsed or ordered |
| 4888 | // loops). |
| 4889 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 4890 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 4891 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 4892 | /*FromParent=*/false); |
| 4893 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 4894 | } |
| 4895 | |
| 4896 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 4897 | |
| 4898 | // Check test-expr. |
| 4899 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 4900 | |
| 4901 | // Check incr-expr. |
| 4902 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4903 | } |
| 4904 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4905 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4906 | return HasErrors; |
| 4907 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4908 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4909 | ResultIterSpace.PreCond = |
| 4910 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 4911 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4912 | DSA.getCurScope(), |
| 4913 | (isOpenMPWorksharingDirective(DKind) || |
| 4914 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 4915 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4916 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4917 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4918 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 4919 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 4920 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 4921 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 4922 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 4923 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 4924 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 4925 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 4926 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4927 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4928 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4929 | ResultIterSpace.CounterInit == nullptr || |
| 4930 | ResultIterSpace.CounterStep == nullptr); |
| 4931 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4932 | return HasErrors; |
| 4933 | } |
| 4934 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4935 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4936 | static ExprResult |
| 4937 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 4938 | ExprResult Start, |
| 4939 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4940 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4941 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 4942 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4943 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4944 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 4945 | VarRef.get()->getType())) { |
| 4946 | NewStart = SemaRef.PerformImplicitConversion( |
| 4947 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 4948 | /*AllowExplicit=*/true); |
| 4949 | if (!NewStart.isUsable()) |
| 4950 | return ExprError(); |
| 4951 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4952 | |
| 4953 | auto Init = |
| 4954 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4955 | return Init; |
| 4956 | } |
| 4957 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4958 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4959 | static ExprResult |
| 4960 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 4961 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 4962 | ExprResult Step, bool Subtract, |
| 4963 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4964 | // Add parentheses (for debugging purposes only). |
| 4965 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 4966 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 4967 | !Step.isUsable()) |
| 4968 | return ExprError(); |
| 4969 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4970 | ExprResult NewStep = Step; |
| 4971 | if (Captures) |
| 4972 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4973 | if (NewStep.isInvalid()) |
| 4974 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4975 | ExprResult Update = |
| 4976 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4977 | if (!Update.isUsable()) |
| 4978 | return ExprError(); |
| 4979 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4980 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 4981 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4982 | ExprResult NewStart = Start; |
| 4983 | if (Captures) |
| 4984 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4985 | if (NewStart.isInvalid()) |
| 4986 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4987 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 4988 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 4989 | ExprResult SavedUpdate = Update; |
| 4990 | ExprResult UpdateVal; |
| 4991 | if (VarRef.get()->getType()->isOverloadableType() || |
| 4992 | NewStart.get()->getType()->isOverloadableType() || |
| 4993 | Update.get()->getType()->isOverloadableType()) { |
| 4994 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 4995 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 4996 | Update = |
| 4997 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 4998 | if (Update.isUsable()) { |
| 4999 | UpdateVal = |
| 5000 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 5001 | VarRef.get(), SavedUpdate.get()); |
| 5002 | if (UpdateVal.isUsable()) { |
| 5003 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 5004 | UpdateVal.get()); |
| 5005 | } |
| 5006 | } |
| 5007 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 5008 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5009 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 5010 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 5011 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 5012 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 5013 | NewStart.get(), SavedUpdate.get()); |
| 5014 | if (!Update.isUsable()) |
| 5015 | return ExprError(); |
| 5016 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 5017 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 5018 | VarRef.get()->getType())) { |
| 5019 | Update = SemaRef.PerformImplicitConversion( |
| 5020 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 5021 | if (!Update.isUsable()) |
| 5022 | return ExprError(); |
| 5023 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 5024 | |
| 5025 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 5026 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5027 | return Update; |
| 5028 | } |
| 5029 | |
| 5030 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 5031 | /// bits. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5032 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5033 | if (E == nullptr) |
| 5034 | return ExprError(); |
| 5035 | auto &C = SemaRef.Context; |
| 5036 | QualType OldType = E->getType(); |
| 5037 | unsigned HasBits = C.getTypeSize(OldType); |
| 5038 | if (HasBits >= Bits) |
| 5039 | return ExprResult(E); |
| 5040 | // OK to convert to signed, because new type has more bits than old. |
| 5041 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 5042 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 5043 | true); |
| 5044 | } |
| 5045 | |
| 5046 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 5047 | /// into \a Bits bits. |
| 5048 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 5049 | if (E == nullptr) |
| 5050 | return false; |
| 5051 | llvm::APSInt Result; |
| 5052 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 5053 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 5054 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5055 | } |
| 5056 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5057 | /// Build preinits statement for the given declarations. |
| 5058 | static Stmt *buildPreInits(ASTContext &Context, |
| 5059 | SmallVectorImpl<Decl *> &PreInits) { |
| 5060 | if (!PreInits.empty()) { |
| 5061 | return new (Context) DeclStmt( |
| 5062 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 5063 | SourceLocation(), SourceLocation()); |
| 5064 | } |
| 5065 | return nullptr; |
| 5066 | } |
| 5067 | |
| 5068 | /// Build preinits statement for the given declarations. |
| 5069 | static Stmt *buildPreInits(ASTContext &Context, |
| 5070 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 5071 | if (!Captures.empty()) { |
| 5072 | SmallVector<Decl *, 16> PreInits; |
| 5073 | for (auto &Pair : Captures) |
| 5074 | PreInits.push_back(Pair.second->getDecl()); |
| 5075 | return buildPreInits(Context, PreInits); |
| 5076 | } |
| 5077 | return nullptr; |
| 5078 | } |
| 5079 | |
| 5080 | /// Build postupdate expression for the given list of postupdates expressions. |
| 5081 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 5082 | Expr *PostUpdate = nullptr; |
| 5083 | if (!PostUpdates.empty()) { |
| 5084 | for (auto *E : PostUpdates) { |
| 5085 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 5086 | E->getExprLoc(), |
| 5087 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 5088 | E->getExprLoc(), E) |
| 5089 | .get(); |
| 5090 | PostUpdate = PostUpdate |
| 5091 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 5092 | PostUpdate, ConvE) |
| 5093 | .get() |
| 5094 | : ConvE; |
| 5095 | } |
| 5096 | } |
| 5097 | return PostUpdate; |
| 5098 | } |
| 5099 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5100 | /// \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] | 5101 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 5102 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5103 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5104 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 5105 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 5106 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5107 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5108 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5109 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5110 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5111 | // Found 'collapse' clause - calculate collapse number. |
| 5112 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5113 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5114 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5115 | } |
| 5116 | if (OrderedLoopCountExpr) { |
| 5117 | // Found 'ordered' clause - calculate collapse number. |
| 5118 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 5119 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 5120 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 5121 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 5122 | diag::err_omp_wrong_ordered_loop_count) |
| 5123 | << OrderedLoopCountExpr->getSourceRange(); |
| 5124 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 5125 | diag::note_collapse_loop_count) |
| 5126 | << CollapseLoopCountExpr->getSourceRange(); |
| 5127 | } |
| 5128 | NestedLoopCount = Result.getLimitedValue(); |
| 5129 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5130 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5131 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 5132 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5133 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5134 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 5135 | IterSpaces.resize(NestedLoopCount); |
| 5136 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5137 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5138 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5139 | NestedLoopCount, CollapseLoopCountExpr, |
| 5140 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5141 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5142 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5143 | // 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] | 5144 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 5145 | // All loops associated with the construct must be perfectly nested; that |
| 5146 | // is, there must be no intervening code nor any OpenMP directive between |
| 5147 | // any two loops. |
| 5148 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5149 | } |
| 5150 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5151 | Built.clear(/* size */ NestedLoopCount); |
| 5152 | |
| 5153 | if (SemaRef.CurContext->isDependentContext()) |
| 5154 | return NestedLoopCount; |
| 5155 | |
| 5156 | // An example of what is generated for the following code: |
| 5157 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5158 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5159 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5160 | // for (k = 0; k < NK; ++k) |
| 5161 | // for (j = J0; j < NJ; j+=2) { |
| 5162 | // <loop body> |
| 5163 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5164 | // |
| 5165 | // We generate the code below. |
| 5166 | // Note: the loop body may be outlined in CodeGen. |
| 5167 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 5168 | // iterations and operator+= to calculate counter value. |
| 5169 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 5170 | // or i64 is currently supported). |
| 5171 | // |
| 5172 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 5173 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 5174 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 5175 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 5176 | // // similar updates for vars in clauses (e.g. 'linear') |
| 5177 | // <loop body (using local i and j)> |
| 5178 | // } |
| 5179 | // i = NI; // assign final values of counters |
| 5180 | // j = NJ; |
| 5181 | // |
| 5182 | |
| 5183 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 5184 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5185 | // Precondition tests if there is at least one iteration (all conditions are |
| 5186 | // true). |
| 5187 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5188 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5189 | ExprResult LastIteration32 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5190 | 32 /* Bits */, SemaRef |
| 5191 | .PerformImplicitConversion( |
| 5192 | N0->IgnoreImpCasts(), N0->getType(), |
| 5193 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5194 | .get(), |
| 5195 | SemaRef); |
| 5196 | ExprResult LastIteration64 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5197 | 64 /* Bits */, SemaRef |
| 5198 | .PerformImplicitConversion( |
| 5199 | N0->IgnoreImpCasts(), N0->getType(), |
| 5200 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5201 | .get(), |
| 5202 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5203 | |
| 5204 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 5205 | return NestedLoopCount; |
| 5206 | |
| 5207 | auto &C = SemaRef.Context; |
| 5208 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 5209 | |
| 5210 | Scope *CurScope = DSA.getCurScope(); |
| 5211 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 5212 | if (PreCond.isUsable()) { |
| 5213 | PreCond = SemaRef.BuildBinOp(CurScope, SourceLocation(), BO_LAnd, |
| 5214 | PreCond.get(), IterSpaces[Cnt].PreCond); |
| 5215 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5216 | auto N = IterSpaces[Cnt].NumIterations; |
| 5217 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 5218 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5219 | LastIteration32 = SemaRef.BuildBinOp( |
| 5220 | CurScope, SourceLocation(), BO_Mul, LastIteration32.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5221 | SemaRef |
| 5222 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5223 | Sema::AA_Converting, |
| 5224 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5225 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5226 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5227 | LastIteration64 = SemaRef.BuildBinOp( |
| 5228 | CurScope, SourceLocation(), BO_Mul, LastIteration64.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5229 | SemaRef |
| 5230 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 5231 | Sema::AA_Converting, |
| 5232 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5233 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5234 | } |
| 5235 | |
| 5236 | // Choose either the 32-bit or 64-bit version. |
| 5237 | ExprResult LastIteration = LastIteration64; |
| 5238 | if (LastIteration32.isUsable() && |
| 5239 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 5240 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 5241 | FitsInto( |
| 5242 | 32 /* Bits */, |
| 5243 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 5244 | LastIteration64.get(), SemaRef))) |
| 5245 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5246 | QualType VType = LastIteration.get()->getType(); |
| 5247 | QualType RealVType = VType; |
| 5248 | QualType StrideVType = VType; |
| 5249 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 5250 | VType = |
| 5251 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 5252 | StrideVType = |
| 5253 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 5254 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5255 | |
| 5256 | if (!LastIteration.isUsable()) |
| 5257 | return 0; |
| 5258 | |
| 5259 | // Save the number of iterations. |
| 5260 | ExprResult NumIterations = LastIteration; |
| 5261 | { |
| 5262 | LastIteration = SemaRef.BuildBinOp( |
| 5263 | CurScope, SourceLocation(), BO_Sub, LastIteration.get(), |
| 5264 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5265 | if (!LastIteration.isUsable()) |
| 5266 | return 0; |
| 5267 | } |
| 5268 | |
| 5269 | // Calculate the last iteration number beforehand instead of doing this on |
| 5270 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 5271 | llvm::APSInt Result; |
| 5272 | bool IsConstant = |
| 5273 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 5274 | ExprResult CalcLastIteration; |
| 5275 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5276 | ExprResult SaveRef = |
| 5277 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5278 | LastIteration = SaveRef; |
| 5279 | |
| 5280 | // Prepare SaveRef + 1. |
| 5281 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5282 | CurScope, SourceLocation(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5283 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 5284 | if (!NumIterations.isUsable()) |
| 5285 | return 0; |
| 5286 | } |
| 5287 | |
| 5288 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 5289 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5290 | // Build variables passed into runtime, necessary for worksharing directives. |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5291 | ExprResult LB, UB, IL, ST, EUB, PrevLB, PrevUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5292 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5293 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5294 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5295 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 5296 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5297 | SemaRef.AddInitializerToDecl( |
| 5298 | LBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5299 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5300 | |
| 5301 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5302 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 5303 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5304 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
| 5305 | /*DirectInit*/ false, |
| 5306 | /*TypeMayContainAuto*/ false); |
| 5307 | |
| 5308 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 5309 | // This will be used to implement clause 'lastprivate'. |
| 5310 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5311 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 5312 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5313 | SemaRef.AddInitializerToDecl( |
| 5314 | ILDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 5315 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5316 | |
| 5317 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5318 | VarDecl *STDecl = |
| 5319 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 5320 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5321 | SemaRef.AddInitializerToDecl( |
| 5322 | STDecl, SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 5323 | /*DirectInit*/ false, /*TypeMayContainAuto*/ false); |
| 5324 | |
| 5325 | // Build expression: UB = min(UB, LastIteration) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5326 | // It is necessary for CodeGen of directives with static scheduling. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5327 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 5328 | UB.get(), LastIteration.get()); |
| 5329 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 5330 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 5331 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 5332 | CondOp.get()); |
| 5333 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5334 | |
| 5335 | // If we have a combined directive that combines 'distribute', 'for' or |
| 5336 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 5337 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 5338 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 5339 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 5340 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| 5341 | |
| 5342 | // We expect to have at least 2 more parameters than the 'parallel' |
| 5343 | // directive does - the lower and upper bounds of the previous schedule. |
| 5344 | assert(CD->getNumParams() >= 4 && |
| 5345 | "Unexpected number of parameters in loop combined directive"); |
| 5346 | |
| 5347 | // Set the proper type for the bounds given what we learned from the |
| 5348 | // enclosed loops. |
| 5349 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 5350 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 5351 | |
| 5352 | // Previous lower and upper bounds are obtained from the region |
| 5353 | // parameters. |
| 5354 | PrevLB = |
| 5355 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 5356 | PrevUB = |
| 5357 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 5358 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5359 | } |
| 5360 | |
| 5361 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5362 | ExprResult IV; |
| 5363 | ExprResult Init; |
| 5364 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 5365 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 5366 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5367 | Expr *RHS = |
| 5368 | (isOpenMPWorksharingDirective(DKind) || |
| 5369 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 5370 | ? LB.get() |
| 5371 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5372 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 5373 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5374 | } |
| 5375 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5376 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5377 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5378 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5379 | (isOpenMPWorksharingDirective(DKind) || |
| 5380 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5381 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 5382 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 5383 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5384 | |
| 5385 | // Loop increment (IV = IV + 1) |
| 5386 | SourceLocation IncLoc; |
| 5387 | ExprResult Inc = |
| 5388 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 5389 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 5390 | if (!Inc.isUsable()) |
| 5391 | return 0; |
| 5392 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5393 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 5394 | if (!Inc.isUsable()) |
| 5395 | return 0; |
| 5396 | |
| 5397 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 5398 | // Used for directives with static scheduling. |
| 5399 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5400 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 5401 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5402 | // LB + ST |
| 5403 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 5404 | if (!NextLB.isUsable()) |
| 5405 | return 0; |
| 5406 | // LB = LB + ST |
| 5407 | NextLB = |
| 5408 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 5409 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 5410 | if (!NextLB.isUsable()) |
| 5411 | return 0; |
| 5412 | // UB + ST |
| 5413 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 5414 | if (!NextUB.isUsable()) |
| 5415 | return 0; |
| 5416 | // UB = UB + ST |
| 5417 | NextUB = |
| 5418 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 5419 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 5420 | if (!NextUB.isUsable()) |
| 5421 | return 0; |
| 5422 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5423 | |
| 5424 | // Build updates and final values of the loop counters. |
| 5425 | bool HasErrors = false; |
| 5426 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5427 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5428 | Built.Updates.resize(NestedLoopCount); |
| 5429 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5430 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5431 | { |
| 5432 | ExprResult Div; |
| 5433 | // Go from inner nested loop to outer. |
| 5434 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5435 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 5436 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 5437 | // Build: Iter = (IV / Div) % IS.NumIters |
| 5438 | // where Div is product of previous iterations' IS.NumIters. |
| 5439 | ExprResult Iter; |
| 5440 | if (Div.isUsable()) { |
| 5441 | Iter = |
| 5442 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 5443 | } else { |
| 5444 | Iter = IV; |
| 5445 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 5446 | "unusable div expected on first iteration only"); |
| 5447 | } |
| 5448 | |
| 5449 | if (Cnt != 0 && Iter.isUsable()) |
| 5450 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 5451 | IS.NumIterations); |
| 5452 | if (!Iter.isUsable()) { |
| 5453 | HasErrors = true; |
| 5454 | break; |
| 5455 | } |
| 5456 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5457 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5458 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 5459 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 5460 | IS.CounterVar->getExprLoc(), |
| 5461 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5462 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5463 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5464 | if (!Init.isUsable()) { |
| 5465 | HasErrors = true; |
| 5466 | break; |
| 5467 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5468 | ExprResult Update = BuildCounterUpdate( |
| 5469 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 5470 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5471 | if (!Update.isUsable()) { |
| 5472 | HasErrors = true; |
| 5473 | break; |
| 5474 | } |
| 5475 | |
| 5476 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 5477 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 5478 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5479 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5480 | if (!Final.isUsable()) { |
| 5481 | HasErrors = true; |
| 5482 | break; |
| 5483 | } |
| 5484 | |
| 5485 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 5486 | if (Cnt != 0) { |
| 5487 | if (Div.isUnset()) |
| 5488 | Div = IS.NumIterations; |
| 5489 | else |
| 5490 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 5491 | IS.NumIterations); |
| 5492 | |
| 5493 | // Add parentheses (for debugging purposes only). |
| 5494 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5495 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5496 | if (!Div.isUsable()) { |
| 5497 | HasErrors = true; |
| 5498 | break; |
| 5499 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5500 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5501 | } |
| 5502 | if (!Update.isUsable() || !Final.isUsable()) { |
| 5503 | HasErrors = true; |
| 5504 | break; |
| 5505 | } |
| 5506 | // Save results |
| 5507 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 5508 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 5509 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5510 | Built.Updates[Cnt] = Update.get(); |
| 5511 | Built.Finals[Cnt] = Final.get(); |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | if (HasErrors) |
| 5516 | return 0; |
| 5517 | |
| 5518 | // Save results |
| 5519 | Built.IterationVarRef = IV.get(); |
| 5520 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5521 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 5522 | Built.CalcLastIteration = |
| 5523 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5524 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5525 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5526 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5527 | Built.Init = Init.get(); |
| 5528 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5529 | Built.LB = LB.get(); |
| 5530 | Built.UB = UB.get(); |
| 5531 | Built.IL = IL.get(); |
| 5532 | Built.ST = ST.get(); |
| 5533 | Built.EUB = EUB.get(); |
| 5534 | Built.NLB = NextLB.get(); |
| 5535 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5536 | Built.PrevLB = PrevLB.get(); |
| 5537 | Built.PrevUB = PrevUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5538 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5539 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 5540 | // Fill data for doacross depend clauses. |
| 5541 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 5542 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 5543 | Pair.first->setCounterValue(CounterVal); |
| 5544 | else { |
| 5545 | if (NestedLoopCount != Pair.second.size() || |
| 5546 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 5547 | // Erroneous case - clause has some problems. |
| 5548 | Pair.first->setCounterValue(CounterVal); |
| 5549 | continue; |
| 5550 | } |
| 5551 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 5552 | auto I = Pair.second.rbegin(); |
| 5553 | auto IS = IterSpaces.rbegin(); |
| 5554 | auto ILM = LoopMultipliers.rbegin(); |
| 5555 | Expr *UpCounterVal = CounterVal; |
| 5556 | Expr *Multiplier = nullptr; |
| 5557 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 5558 | if (I->first) { |
| 5559 | assert(IS->CounterStep); |
| 5560 | Expr *NormalizedOffset = |
| 5561 | SemaRef |
| 5562 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 5563 | I->first, IS->CounterStep) |
| 5564 | .get(); |
| 5565 | if (Multiplier) { |
| 5566 | NormalizedOffset = |
| 5567 | SemaRef |
| 5568 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 5569 | NormalizedOffset, Multiplier) |
| 5570 | .get(); |
| 5571 | } |
| 5572 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 5573 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5574 | UpCounterVal = SemaRef |
| 5575 | .BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 5576 | UpCounterVal, NormalizedOffset) |
| 5577 | .get(); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 5578 | } |
| 5579 | Multiplier = *ILM; |
| 5580 | ++I; |
| 5581 | ++IS; |
| 5582 | ++ILM; |
| 5583 | } |
| 5584 | Pair.first->setCounterValue(UpCounterVal); |
| 5585 | } |
| 5586 | } |
| 5587 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5588 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 5589 | } |
| 5590 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5591 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5592 | auto CollapseClauses = |
| 5593 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 5594 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 5595 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 5596 | return nullptr; |
| 5597 | } |
| 5598 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5599 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 5600 | auto OrderedClauses = |
| 5601 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 5602 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 5603 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5604 | return nullptr; |
| 5605 | } |
| 5606 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5607 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 5608 | const ArrayRef<OMPClause *> Clauses) { |
| 5609 | OMPSafelenClause *Safelen = nullptr; |
| 5610 | OMPSimdlenClause *Simdlen = nullptr; |
| 5611 | |
| 5612 | for (auto *Clause : Clauses) { |
| 5613 | if (Clause->getClauseKind() == OMPC_safelen) |
| 5614 | Safelen = cast<OMPSafelenClause>(Clause); |
| 5615 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 5616 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 5617 | if (Safelen && Simdlen) |
| 5618 | break; |
| 5619 | } |
| 5620 | |
| 5621 | if (Simdlen && Safelen) { |
| 5622 | llvm::APSInt SimdlenRes, SafelenRes; |
| 5623 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 5624 | auto SafelenLength = Safelen->getSafelen(); |
| 5625 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 5626 | SimdlenLength->isInstantiationDependent() || |
| 5627 | SimdlenLength->containsUnexpandedParameterPack()) |
| 5628 | return false; |
| 5629 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 5630 | SafelenLength->isInstantiationDependent() || |
| 5631 | SafelenLength->containsUnexpandedParameterPack()) |
| 5632 | return false; |
| 5633 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 5634 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 5635 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 5636 | // If both simdlen and safelen clauses are specified, the value of the |
| 5637 | // simdlen parameter must be less than or equal to the value of the safelen |
| 5638 | // parameter. |
| 5639 | if (SimdlenRes > SafelenRes) { |
| 5640 | S.Diag(SimdlenLength->getExprLoc(), |
| 5641 | diag::err_omp_wrong_simdlen_safelen_values) |
| 5642 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 5643 | return true; |
| 5644 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5645 | } |
| 5646 | return false; |
| 5647 | } |
| 5648 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5649 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 5650 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5651 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5652 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5653 | if (!AStmt) |
| 5654 | return StmtError(); |
| 5655 | |
| 5656 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5657 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5658 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5659 | // define the nested loops number. |
| 5660 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5661 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5662 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5663 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5664 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5665 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5666 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5667 | "omp simd loop exprs were not built"); |
| 5668 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5669 | if (!CurContext->isDependentContext()) { |
| 5670 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5671 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5672 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5673 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5674 | B.NumIterations, *this, CurScope, |
| 5675 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 5676 | return StmtError(); |
| 5677 | } |
| 5678 | } |
| 5679 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5680 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5681 | return StmtError(); |
| 5682 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5683 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5684 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5685 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5688 | StmtResult Sema::ActOnOpenMPForDirective( |
| 5689 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5690 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5691 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5692 | if (!AStmt) |
| 5693 | return StmtError(); |
| 5694 | |
| 5695 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5696 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5697 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5698 | // define the nested loops number. |
| 5699 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5700 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 5701 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 5702 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5703 | return StmtError(); |
| 5704 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5705 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5706 | "omp for loop exprs were not built"); |
| 5707 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5708 | if (!CurContext->isDependentContext()) { |
| 5709 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5710 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5711 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5712 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5713 | B.NumIterations, *this, CurScope, |
| 5714 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5715 | return StmtError(); |
| 5716 | } |
| 5717 | } |
| 5718 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5719 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5720 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5721 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 5722 | } |
| 5723 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5724 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 5725 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5726 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5727 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5728 | if (!AStmt) |
| 5729 | return StmtError(); |
| 5730 | |
| 5731 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5732 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5733 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5734 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5735 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5736 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 5737 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5738 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5739 | if (NestedLoopCount == 0) |
| 5740 | return StmtError(); |
| 5741 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5742 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5743 | "omp for simd loop exprs were not built"); |
| 5744 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5745 | if (!CurContext->isDependentContext()) { |
| 5746 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5747 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5748 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5749 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5750 | B.NumIterations, *this, CurScope, |
| 5751 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 5752 | return StmtError(); |
| 5753 | } |
| 5754 | } |
| 5755 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 5756 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 5757 | return StmtError(); |
| 5758 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5759 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5760 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 5761 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 5762 | } |
| 5763 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5764 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 5765 | Stmt *AStmt, |
| 5766 | SourceLocation StartLoc, |
| 5767 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5768 | if (!AStmt) |
| 5769 | return StmtError(); |
| 5770 | |
| 5771 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5772 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5773 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5774 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5775 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5776 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5777 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5778 | return StmtError(); |
| 5779 | // All associated statements must be '#pragma omp section' except for |
| 5780 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 5781 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5782 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 5783 | if (SectionStmt) |
| 5784 | Diag(SectionStmt->getLocStart(), |
| 5785 | diag::err_omp_sections_substmt_not_section); |
| 5786 | return StmtError(); |
| 5787 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5788 | cast<OMPSectionDirective>(SectionStmt) |
| 5789 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5790 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5791 | } else { |
| 5792 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 5793 | return StmtError(); |
| 5794 | } |
| 5795 | |
| 5796 | getCurFunction()->setHasBranchProtectedScope(); |
| 5797 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5798 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 5799 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 5800 | } |
| 5801 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5802 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 5803 | SourceLocation StartLoc, |
| 5804 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5805 | if (!AStmt) |
| 5806 | return StmtError(); |
| 5807 | |
| 5808 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5809 | |
| 5810 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5811 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5812 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5813 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 5814 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 5815 | } |
| 5816 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5817 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 5818 | Stmt *AStmt, |
| 5819 | SourceLocation StartLoc, |
| 5820 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5821 | if (!AStmt) |
| 5822 | return StmtError(); |
| 5823 | |
| 5824 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5825 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5826 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 5827 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 5828 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 5829 | // The copyprivate clause must not be used with the nowait clause. |
| 5830 | OMPClause *Nowait = nullptr; |
| 5831 | OMPClause *Copyprivate = nullptr; |
| 5832 | for (auto *Clause : Clauses) { |
| 5833 | if (Clause->getClauseKind() == OMPC_nowait) |
| 5834 | Nowait = Clause; |
| 5835 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 5836 | Copyprivate = Clause; |
| 5837 | if (Copyprivate && Nowait) { |
| 5838 | Diag(Copyprivate->getLocStart(), |
| 5839 | diag::err_omp_single_copyprivate_with_nowait); |
| 5840 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 5841 | return StmtError(); |
| 5842 | } |
| 5843 | } |
| 5844 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 5845 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5846 | } |
| 5847 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5848 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 5849 | SourceLocation StartLoc, |
| 5850 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5851 | if (!AStmt) |
| 5852 | return StmtError(); |
| 5853 | |
| 5854 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 5855 | |
| 5856 | getCurFunction()->setHasBranchProtectedScope(); |
| 5857 | |
| 5858 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 5859 | } |
| 5860 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5861 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 5862 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 5863 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5864 | if (!AStmt) |
| 5865 | return StmtError(); |
| 5866 | |
| 5867 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5868 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5869 | bool ErrorFound = false; |
| 5870 | llvm::APSInt Hint; |
| 5871 | SourceLocation HintLoc; |
| 5872 | bool DependentHint = false; |
| 5873 | for (auto *C : Clauses) { |
| 5874 | if (C->getClauseKind() == OMPC_hint) { |
| 5875 | if (!DirName.getName()) { |
| 5876 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 5877 | ErrorFound = true; |
| 5878 | } |
| 5879 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 5880 | if (E->isTypeDependent() || E->isValueDependent() || |
| 5881 | E->isInstantiationDependent()) |
| 5882 | DependentHint = true; |
| 5883 | else { |
| 5884 | Hint = E->EvaluateKnownConstInt(Context); |
| 5885 | HintLoc = C->getLocStart(); |
| 5886 | } |
| 5887 | } |
| 5888 | } |
| 5889 | if (ErrorFound) |
| 5890 | return StmtError(); |
| 5891 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 5892 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 5893 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 5894 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 5895 | if (HintLoc.isValid()) { |
| 5896 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 5897 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 5898 | } else |
| 5899 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 5900 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 5901 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 5902 | << 1 |
| 5903 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 5904 | /*Radix=*/10, /*Signed=*/false); |
| 5905 | } else |
| 5906 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 5907 | } |
| 5908 | } |
| 5909 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5910 | getCurFunction()->setHasBranchProtectedScope(); |
| 5911 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 5912 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 5913 | Clauses, AStmt); |
| 5914 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 5915 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 5916 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 5917 | } |
| 5918 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5919 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 5920 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5921 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5922 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5923 | if (!AStmt) |
| 5924 | return StmtError(); |
| 5925 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5926 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5927 | // 1.2.2 OpenMP Language Terminology |
| 5928 | // Structured block - An executable statement with a single entry at the |
| 5929 | // top and a single exit at the bottom. |
| 5930 | // The point of exit cannot be a branch out of the structured block. |
| 5931 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5932 | CS->getCapturedDecl()->setNothrow(); |
| 5933 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5934 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5935 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5936 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5937 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5938 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 5939 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5940 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5941 | if (NestedLoopCount == 0) |
| 5942 | return StmtError(); |
| 5943 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 5944 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5945 | "omp parallel for loop exprs were not built"); |
| 5946 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5947 | if (!CurContext->isDependentContext()) { |
| 5948 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5949 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5950 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5951 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5952 | B.NumIterations, *this, CurScope, |
| 5953 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 5954 | return StmtError(); |
| 5955 | } |
| 5956 | } |
| 5957 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5958 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5959 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5960 | NestedLoopCount, Clauses, AStmt, B, |
| 5961 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 5962 | } |
| 5963 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5964 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 5965 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5966 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5967 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5968 | if (!AStmt) |
| 5969 | return StmtError(); |
| 5970 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5971 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5972 | // 1.2.2 OpenMP Language Terminology |
| 5973 | // Structured block - An executable statement with a single entry at the |
| 5974 | // top and a single exit at the bottom. |
| 5975 | // The point of exit cannot be a branch out of the structured block. |
| 5976 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5977 | CS->getCapturedDecl()->setNothrow(); |
| 5978 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 5979 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5980 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5981 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5982 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 5983 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 5984 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5985 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 5986 | if (NestedLoopCount == 0) |
| 5987 | return StmtError(); |
| 5988 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5989 | if (!CurContext->isDependentContext()) { |
| 5990 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5991 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5992 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5993 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5994 | B.NumIterations, *this, CurScope, |
| 5995 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 5996 | return StmtError(); |
| 5997 | } |
| 5998 | } |
| 5999 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6000 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6001 | return StmtError(); |
| 6002 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6003 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 6004 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 6005 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 6006 | } |
| 6007 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6008 | StmtResult |
| 6009 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 6010 | Stmt *AStmt, SourceLocation StartLoc, |
| 6011 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6012 | if (!AStmt) |
| 6013 | return StmtError(); |
| 6014 | |
| 6015 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6016 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6017 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6018 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6019 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6020 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 6021 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6022 | return StmtError(); |
| 6023 | // All associated statements must be '#pragma omp section' except for |
| 6024 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 6025 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6026 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 6027 | if (SectionStmt) |
| 6028 | Diag(SectionStmt->getLocStart(), |
| 6029 | diag::err_omp_parallel_sections_substmt_not_section); |
| 6030 | return StmtError(); |
| 6031 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6032 | cast<OMPSectionDirective>(SectionStmt) |
| 6033 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6034 | } |
| 6035 | } else { |
| 6036 | Diag(AStmt->getLocStart(), |
| 6037 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 6038 | return StmtError(); |
| 6039 | } |
| 6040 | |
| 6041 | getCurFunction()->setHasBranchProtectedScope(); |
| 6042 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6043 | return OMPParallelSectionsDirective::Create( |
| 6044 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 6045 | } |
| 6046 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6047 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 6048 | Stmt *AStmt, SourceLocation StartLoc, |
| 6049 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6050 | if (!AStmt) |
| 6051 | return StmtError(); |
| 6052 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6053 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6054 | // 1.2.2 OpenMP Language Terminology |
| 6055 | // Structured block - An executable statement with a single entry at the |
| 6056 | // top and a single exit at the bottom. |
| 6057 | // The point of exit cannot be a branch out of the structured block. |
| 6058 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6059 | CS->getCapturedDecl()->setNothrow(); |
| 6060 | |
| 6061 | getCurFunction()->setHasBranchProtectedScope(); |
| 6062 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 6063 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 6064 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 6065 | } |
| 6066 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 6067 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 6068 | SourceLocation EndLoc) { |
| 6069 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 6070 | } |
| 6071 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 6072 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 6073 | SourceLocation EndLoc) { |
| 6074 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 6075 | } |
| 6076 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 6077 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 6078 | SourceLocation EndLoc) { |
| 6079 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 6080 | } |
| 6081 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 6082 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 6083 | SourceLocation StartLoc, |
| 6084 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6085 | if (!AStmt) |
| 6086 | return StmtError(); |
| 6087 | |
| 6088 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 6089 | |
| 6090 | getCurFunction()->setHasBranchProtectedScope(); |
| 6091 | |
| 6092 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 6093 | } |
| 6094 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6095 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 6096 | SourceLocation StartLoc, |
| 6097 | SourceLocation EndLoc) { |
| 6098 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 6099 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 6100 | } |
| 6101 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6102 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 6103 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6104 | SourceLocation StartLoc, |
| 6105 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6106 | OMPClause *DependFound = nullptr; |
| 6107 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6108 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6109 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6110 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6111 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6112 | for (auto *C : Clauses) { |
| 6113 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 6114 | DependFound = C; |
| 6115 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 6116 | if (DependSourceClause) { |
| 6117 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 6118 | << getOpenMPDirectiveName(OMPD_ordered) |
| 6119 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 6120 | ErrorFound = true; |
| 6121 | } else |
| 6122 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6123 | if (DependSinkClause) { |
| 6124 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 6125 | << 0; |
| 6126 | ErrorFound = true; |
| 6127 | } |
| 6128 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 6129 | if (DependSourceClause) { |
| 6130 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 6131 | << 1; |
| 6132 | ErrorFound = true; |
| 6133 | } |
| 6134 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6135 | } |
| 6136 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6137 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6138 | else if (C->getClauseKind() == OMPC_simd) |
| 6139 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6140 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6141 | if (!ErrorFound && !SC && |
| 6142 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6143 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 6144 | // An ordered construct with the simd clause is the only OpenMP construct |
| 6145 | // that can appear in the simd region. |
| 6146 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6147 | ErrorFound = true; |
| 6148 | } else if (DependFound && (TC || SC)) { |
| 6149 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 6150 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 6151 | ErrorFound = true; |
| 6152 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 6153 | Diag(DependFound->getLocStart(), |
| 6154 | diag::err_omp_ordered_directive_without_param); |
| 6155 | ErrorFound = true; |
| 6156 | } else if (TC || Clauses.empty()) { |
| 6157 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 6158 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 6159 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 6160 | << (TC != nullptr); |
| 6161 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 6162 | ErrorFound = true; |
| 6163 | } |
| 6164 | } |
| 6165 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6166 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 6167 | |
| 6168 | if (AStmt) { |
| 6169 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6170 | |
| 6171 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6172 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6173 | |
| 6174 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 6175 | } |
| 6176 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6177 | namespace { |
| 6178 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 6179 | /// construct. |
| 6180 | class OpenMPAtomicUpdateChecker { |
| 6181 | /// \brief Error results for atomic update expressions. |
| 6182 | enum ExprAnalysisErrorCode { |
| 6183 | /// \brief A statement is not an expression statement. |
| 6184 | NotAnExpression, |
| 6185 | /// \brief Expression is not builtin binary or unary operation. |
| 6186 | NotABinaryOrUnaryExpression, |
| 6187 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 6188 | NotAnUnaryIncDecExpression, |
| 6189 | /// \brief An expression is not of scalar type. |
| 6190 | NotAScalarType, |
| 6191 | /// \brief A binary operation is not an assignment operation. |
| 6192 | NotAnAssignmentOp, |
| 6193 | /// \brief RHS part of the binary operation is not a binary expression. |
| 6194 | NotABinaryExpression, |
| 6195 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 6196 | /// expression. |
| 6197 | NotABinaryOperator, |
| 6198 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 6199 | /// part. |
| 6200 | NotAnUpdateExpression, |
| 6201 | /// \brief No errors is found. |
| 6202 | NoError |
| 6203 | }; |
| 6204 | /// \brief Reference to Sema. |
| 6205 | Sema &SemaRef; |
| 6206 | /// \brief A location for note diagnostics (when error is found). |
| 6207 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6208 | /// \brief 'x' lvalue part of the source atomic expression. |
| 6209 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6210 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 6211 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6212 | /// \brief Helper expression of the form |
| 6213 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6214 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6215 | Expr *UpdateExpr; |
| 6216 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 6217 | /// important for non-associative operations. |
| 6218 | bool IsXLHSInRHSPart; |
| 6219 | BinaryOperatorKind Op; |
| 6220 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6221 | /// \brief true if the source expression is a postfix unary operation, false |
| 6222 | /// if it is a prefix unary operation. |
| 6223 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6224 | |
| 6225 | public: |
| 6226 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6227 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6228 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6229 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 6230 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6231 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 6232 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6233 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 6234 | /// \param NoteId Diagnostic note for the main error message. |
| 6235 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6236 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6237 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 6238 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6239 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 6240 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6241 | /// \brief Return the update expression used in calculation of the updated |
| 6242 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 6243 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 6244 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 6245 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 6246 | /// false otherwise. |
| 6247 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 6248 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6249 | /// \brief true if the source expression is a postfix unary operation, false |
| 6250 | /// if it is a prefix unary operation. |
| 6251 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 6252 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6253 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6254 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 6255 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6256 | }; |
| 6257 | } // namespace |
| 6258 | |
| 6259 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 6260 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 6261 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6262 | SourceLocation ErrorLoc, NoteLoc; |
| 6263 | SourceRange ErrorRange, NoteRange; |
| 6264 | // Allowed constructs are: |
| 6265 | // x = x binop expr; |
| 6266 | // x = expr binop x; |
| 6267 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 6268 | X = AtomicBinOp->getLHS(); |
| 6269 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 6270 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 6271 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 6272 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 6273 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6274 | Op = AtomicInnerBinOp->getOpcode(); |
| 6275 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6276 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 6277 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 6278 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 6279 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 6280 | /*Canonical=*/true); |
| 6281 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 6282 | /*Canonical=*/true); |
| 6283 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 6284 | /*Canonical=*/true); |
| 6285 | if (XId == LHSId) { |
| 6286 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6287 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6288 | } else if (XId == RHSId) { |
| 6289 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6290 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6291 | } else { |
| 6292 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6293 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6294 | NoteLoc = X->getExprLoc(); |
| 6295 | NoteRange = X->getSourceRange(); |
| 6296 | ErrorFound = NotAnUpdateExpression; |
| 6297 | } |
| 6298 | } else { |
| 6299 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 6300 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 6301 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 6302 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6303 | ErrorFound = NotABinaryOperator; |
| 6304 | } |
| 6305 | } else { |
| 6306 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 6307 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 6308 | ErrorFound = NotABinaryExpression; |
| 6309 | } |
| 6310 | } else { |
| 6311 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6312 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6313 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 6314 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6315 | ErrorFound = NotAnAssignmentOp; |
| 6316 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6317 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6318 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6319 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6320 | return true; |
| 6321 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6322 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6323 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6324 | } |
| 6325 | |
| 6326 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 6327 | unsigned NoteId) { |
| 6328 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 6329 | SourceLocation ErrorLoc, NoteLoc; |
| 6330 | SourceRange ErrorRange, NoteRange; |
| 6331 | // Allowed constructs are: |
| 6332 | // x++; |
| 6333 | // x--; |
| 6334 | // ++x; |
| 6335 | // --x; |
| 6336 | // x binop= expr; |
| 6337 | // x = x binop expr; |
| 6338 | // x = expr binop x; |
| 6339 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 6340 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 6341 | if (AtomicBody->getType()->isScalarType() || |
| 6342 | AtomicBody->isInstantiationDependent()) { |
| 6343 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 6344 | AtomicBody->IgnoreParenImpCasts())) { |
| 6345 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6346 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6347 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6348 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6349 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6350 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6351 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6352 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 6353 | AtomicBody->IgnoreParenImpCasts())) { |
| 6354 | // Check for Binary Operation |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6355 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6356 | return true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6357 | } else if (auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| 6358 | AtomicBody->IgnoreParenImpCasts())) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6359 | // Check for Unary Operation |
| 6360 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6361 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6362 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 6363 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 6364 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6365 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 6366 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6367 | } else { |
| 6368 | ErrorFound = NotAnUnaryIncDecExpression; |
| 6369 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 6370 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 6371 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 6372 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 6373 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6374 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6375 | ErrorFound = NotABinaryOrUnaryExpression; |
| 6376 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 6377 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 6378 | } |
| 6379 | } else { |
| 6380 | ErrorFound = NotAScalarType; |
| 6381 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 6382 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6383 | } |
| 6384 | } else { |
| 6385 | ErrorFound = NotAnExpression; |
| 6386 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 6387 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 6388 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6389 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6390 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 6391 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 6392 | return true; |
| 6393 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6394 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6395 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6396 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 6397 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 6398 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 6399 | auto *OVEX = new (SemaRef.getASTContext()) |
| 6400 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 6401 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 6402 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 6403 | auto Update = |
| 6404 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 6405 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 6406 | if (Update.isInvalid()) |
| 6407 | return true; |
| 6408 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 6409 | Sema::AA_Casting); |
| 6410 | if (Update.isInvalid()) |
| 6411 | return true; |
| 6412 | UpdateExpr = Update.get(); |
| 6413 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6414 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6415 | } |
| 6416 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6417 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 6418 | Stmt *AStmt, |
| 6419 | SourceLocation StartLoc, |
| 6420 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6421 | if (!AStmt) |
| 6422 | return StmtError(); |
| 6423 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6424 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6425 | // 1.2.2 OpenMP Language Terminology |
| 6426 | // Structured block - An executable statement with a single entry at the |
| 6427 | // top and a single exit at the bottom. |
| 6428 | // The point of exit cannot be a branch out of the structured block. |
| 6429 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6430 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 6431 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6432 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6433 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6434 | C->getClauseKind() == OMPC_update || |
| 6435 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6436 | if (AtomicKind != OMPC_unknown) { |
| 6437 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 6438 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 6439 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 6440 | << getOpenMPClauseName(AtomicKind); |
| 6441 | } else { |
| 6442 | AtomicKind = C->getClauseKind(); |
| 6443 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6444 | } |
| 6445 | } |
| 6446 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6447 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6448 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 6449 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 6450 | Body = EWC->getSubExpr(); |
| 6451 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6452 | Expr *X = nullptr; |
| 6453 | Expr *V = nullptr; |
| 6454 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6455 | Expr *UE = nullptr; |
| 6456 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6457 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6458 | // OpenMP [2.12.6, atomic Construct] |
| 6459 | // In the next expressions: |
| 6460 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 6461 | // * During the execution of an atomic region, multiple syntactic |
| 6462 | // occurrences of x must designate the same storage location. |
| 6463 | // * Neither of v and expr (as applicable) may access the storage location |
| 6464 | // designated by x. |
| 6465 | // * Neither of x and expr (as applicable) may access the storage location |
| 6466 | // designated by v. |
| 6467 | // * expr is an expression with scalar type. |
| 6468 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 6469 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 6470 | // * The expression x binop expr must be numerically equivalent to x binop |
| 6471 | // (expr). This requirement is satisfied if the operators in expr have |
| 6472 | // precedence greater than binop, or by using parentheses around expr or |
| 6473 | // subexpressions of expr. |
| 6474 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 6475 | // binop x. This requirement is satisfied if the operators in expr have |
| 6476 | // precedence equal to or greater than binop, or by using parentheses around |
| 6477 | // expr or subexpressions of expr. |
| 6478 | // * For forms that allow multiple occurrences of x, the number of times |
| 6479 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6480 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6481 | enum { |
| 6482 | NotAnExpression, |
| 6483 | NotAnAssignmentOp, |
| 6484 | NotAScalarType, |
| 6485 | NotAnLValue, |
| 6486 | NoError |
| 6487 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6488 | SourceLocation ErrorLoc, NoteLoc; |
| 6489 | SourceRange ErrorRange, NoteRange; |
| 6490 | // If clause is read: |
| 6491 | // v = x; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6492 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6493 | auto *AtomicBinOp = |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6494 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6495 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6496 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6497 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6498 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6499 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 6500 | if (!X->isLValue() || !V->isLValue()) { |
| 6501 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 6502 | ErrorFound = NotAnLValue; |
| 6503 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6504 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6505 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 6506 | NoteRange = NotLValueExpr->getSourceRange(); |
| 6507 | } |
| 6508 | } else if (!X->isInstantiationDependent() || |
| 6509 | !V->isInstantiationDependent()) { |
| 6510 | auto NotScalarExpr = |
| 6511 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6512 | ? V |
| 6513 | : X; |
| 6514 | ErrorFound = NotAScalarType; |
| 6515 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6516 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6517 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6518 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6519 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6520 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6521 | ErrorFound = NotAnAssignmentOp; |
| 6522 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6523 | ErrorRange = AtomicBody->getSourceRange(); |
| 6524 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6525 | : AtomicBody->getExprLoc(); |
| 6526 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6527 | : AtomicBody->getSourceRange(); |
| 6528 | } |
| 6529 | } else { |
| 6530 | ErrorFound = NotAnExpression; |
| 6531 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6532 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6533 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6534 | if (ErrorFound != NoError) { |
| 6535 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 6536 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6537 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6538 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6539 | return StmtError(); |
| 6540 | } else if (CurContext->isDependentContext()) |
| 6541 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6542 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6543 | enum { |
| 6544 | NotAnExpression, |
| 6545 | NotAnAssignmentOp, |
| 6546 | NotAScalarType, |
| 6547 | NotAnLValue, |
| 6548 | NoError |
| 6549 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6550 | SourceLocation ErrorLoc, NoteLoc; |
| 6551 | SourceRange ErrorRange, NoteRange; |
| 6552 | // If clause is write: |
| 6553 | // x = expr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6554 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6555 | auto *AtomicBinOp = |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6556 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6557 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 6558 | X = AtomicBinOp->getLHS(); |
| 6559 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6560 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 6561 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 6562 | if (!X->isLValue()) { |
| 6563 | ErrorFound = NotAnLValue; |
| 6564 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6565 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6566 | NoteLoc = X->getExprLoc(); |
| 6567 | NoteRange = X->getSourceRange(); |
| 6568 | } |
| 6569 | } else if (!X->isInstantiationDependent() || |
| 6570 | !E->isInstantiationDependent()) { |
| 6571 | auto NotScalarExpr = |
| 6572 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 6573 | ? E |
| 6574 | : X; |
| 6575 | ErrorFound = NotAScalarType; |
| 6576 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 6577 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 6578 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 6579 | NoteRange = NotScalarExpr->getSourceRange(); |
| 6580 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6581 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6582 | ErrorFound = NotAnAssignmentOp; |
| 6583 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6584 | ErrorRange = AtomicBody->getSourceRange(); |
| 6585 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6586 | : AtomicBody->getExprLoc(); |
| 6587 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6588 | : AtomicBody->getSourceRange(); |
| 6589 | } |
| 6590 | } else { |
| 6591 | ErrorFound = NotAnExpression; |
| 6592 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6593 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6594 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 6595 | if (ErrorFound != NoError) { |
| 6596 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 6597 | << ErrorRange; |
| 6598 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 6599 | << NoteRange; |
| 6600 | return StmtError(); |
| 6601 | } else if (CurContext->isDependentContext()) |
| 6602 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6603 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6604 | // If clause is update: |
| 6605 | // x++; |
| 6606 | // x--; |
| 6607 | // ++x; |
| 6608 | // --x; |
| 6609 | // x binop= expr; |
| 6610 | // x = x binop expr; |
| 6611 | // x = expr binop x; |
| 6612 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6613 | if (Checker.checkStatement( |
| 6614 | Body, (AtomicKind == OMPC_update) |
| 6615 | ? diag::err_omp_atomic_update_not_expression_statement |
| 6616 | : diag::err_omp_atomic_not_expression_statement, |
| 6617 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6618 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 6619 | if (!CurContext->isDependentContext()) { |
| 6620 | E = Checker.getExpr(); |
| 6621 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 6622 | UE = Checker.getUpdateExpr(); |
| 6623 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6624 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6625 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6626 | enum { |
| 6627 | NotAnAssignmentOp, |
| 6628 | NotACompoundStatement, |
| 6629 | NotTwoSubstatements, |
| 6630 | NotASpecificExpression, |
| 6631 | NoError |
| 6632 | } ErrorFound = NoError; |
| 6633 | SourceLocation ErrorLoc, NoteLoc; |
| 6634 | SourceRange ErrorRange, NoteRange; |
| 6635 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 6636 | // If clause is a capture: |
| 6637 | // v = x++; |
| 6638 | // v = x--; |
| 6639 | // v = ++x; |
| 6640 | // v = --x; |
| 6641 | // v = x binop= expr; |
| 6642 | // v = x = x binop expr; |
| 6643 | // v = x = expr binop x; |
| 6644 | auto *AtomicBinOp = |
| 6645 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 6646 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 6647 | V = AtomicBinOp->getLHS(); |
| 6648 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6649 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6650 | if (Checker.checkStatement( |
| 6651 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 6652 | diag::note_omp_atomic_update)) |
| 6653 | return StmtError(); |
| 6654 | E = Checker.getExpr(); |
| 6655 | X = Checker.getX(); |
| 6656 | UE = Checker.getUpdateExpr(); |
| 6657 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 6658 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6659 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6660 | ErrorLoc = AtomicBody->getExprLoc(); |
| 6661 | ErrorRange = AtomicBody->getSourceRange(); |
| 6662 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 6663 | : AtomicBody->getExprLoc(); |
| 6664 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 6665 | : AtomicBody->getSourceRange(); |
| 6666 | ErrorFound = NotAnAssignmentOp; |
| 6667 | } |
| 6668 | if (ErrorFound != NoError) { |
| 6669 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 6670 | << ErrorRange; |
| 6671 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6672 | return StmtError(); |
| 6673 | } else if (CurContext->isDependentContext()) { |
| 6674 | UE = V = E = X = nullptr; |
| 6675 | } |
| 6676 | } else { |
| 6677 | // If clause is a capture: |
| 6678 | // { v = x; x = expr; } |
| 6679 | // { v = x; x++; } |
| 6680 | // { v = x; x--; } |
| 6681 | // { v = x; ++x; } |
| 6682 | // { v = x; --x; } |
| 6683 | // { v = x; x binop= expr; } |
| 6684 | // { v = x; x = x binop expr; } |
| 6685 | // { v = x; x = expr binop x; } |
| 6686 | // { x++; v = x; } |
| 6687 | // { x--; v = x; } |
| 6688 | // { ++x; v = x; } |
| 6689 | // { --x; v = x; } |
| 6690 | // { x binop= expr; v = x; } |
| 6691 | // { x = x binop expr; v = x; } |
| 6692 | // { x = expr binop x; v = x; } |
| 6693 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 6694 | // Check that this is { expr1; expr2; } |
| 6695 | if (CS->size() == 2) { |
| 6696 | auto *First = CS->body_front(); |
| 6697 | auto *Second = CS->body_back(); |
| 6698 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 6699 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6700 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 6701 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 6702 | // Need to find what subexpression is 'v' and what is 'x'. |
| 6703 | OpenMPAtomicUpdateChecker Checker(*this); |
| 6704 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 6705 | BinaryOperator *BinOp = nullptr; |
| 6706 | if (IsUpdateExprFound) { |
| 6707 | BinOp = dyn_cast<BinaryOperator>(First); |
| 6708 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6709 | } |
| 6710 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6711 | // { v = x; x++; } |
| 6712 | // { v = x; x--; } |
| 6713 | // { v = x; ++x; } |
| 6714 | // { v = x; --x; } |
| 6715 | // { v = x; x binop= expr; } |
| 6716 | // { v = x; x = x binop expr; } |
| 6717 | // { v = x; x = expr binop x; } |
| 6718 | // Check that the first expression has form v = x. |
| 6719 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6720 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6721 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6722 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6723 | IsUpdateExprFound = XId == PossibleXId; |
| 6724 | if (IsUpdateExprFound) { |
| 6725 | V = BinOp->getLHS(); |
| 6726 | X = Checker.getX(); |
| 6727 | E = Checker.getExpr(); |
| 6728 | UE = Checker.getUpdateExpr(); |
| 6729 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6730 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6731 | } |
| 6732 | } |
| 6733 | if (!IsUpdateExprFound) { |
| 6734 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 6735 | BinOp = nullptr; |
| 6736 | if (IsUpdateExprFound) { |
| 6737 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 6738 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 6739 | } |
| 6740 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 6741 | // { x++; v = x; } |
| 6742 | // { x--; v = x; } |
| 6743 | // { ++x; v = x; } |
| 6744 | // { --x; v = x; } |
| 6745 | // { x binop= expr; v = x; } |
| 6746 | // { x = x binop expr; v = x; } |
| 6747 | // { x = expr binop x; v = x; } |
| 6748 | // Check that the second expression has form v = x. |
| 6749 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 6750 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 6751 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 6752 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 6753 | IsUpdateExprFound = XId == PossibleXId; |
| 6754 | if (IsUpdateExprFound) { |
| 6755 | V = BinOp->getLHS(); |
| 6756 | X = Checker.getX(); |
| 6757 | E = Checker.getExpr(); |
| 6758 | UE = Checker.getUpdateExpr(); |
| 6759 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 6760 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6761 | } |
| 6762 | } |
| 6763 | } |
| 6764 | if (!IsUpdateExprFound) { |
| 6765 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6766 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 6767 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 6768 | if (!FirstExpr || !SecondExpr || |
| 6769 | !(FirstExpr->isInstantiationDependent() || |
| 6770 | SecondExpr->isInstantiationDependent())) { |
| 6771 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 6772 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6773 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6774 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 6775 | : First->getLocStart(); |
| 6776 | NoteRange = ErrorRange = FirstBinOp |
| 6777 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6778 | : SourceRange(ErrorLoc, ErrorLoc); |
| 6779 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6780 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 6781 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 6782 | ErrorFound = NotAnAssignmentOp; |
| 6783 | NoteLoc = ErrorLoc = SecondBinOp |
| 6784 | ? SecondBinOp->getOperatorLoc() |
| 6785 | : Second->getLocStart(); |
| 6786 | NoteRange = ErrorRange = |
| 6787 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 6788 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6789 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 6790 | auto *PossibleXRHSInFirst = |
| 6791 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 6792 | auto *PossibleXLHSInSecond = |
| 6793 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 6794 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 6795 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 6796 | /*Canonical=*/true); |
| 6797 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 6798 | /*Canonical=*/true); |
| 6799 | IsUpdateExprFound = X1Id == X2Id; |
| 6800 | if (IsUpdateExprFound) { |
| 6801 | V = FirstBinOp->getLHS(); |
| 6802 | X = SecondBinOp->getLHS(); |
| 6803 | E = SecondBinOp->getRHS(); |
| 6804 | UE = nullptr; |
| 6805 | IsXLHSInRHSPart = false; |
| 6806 | IsPostfixUpdate = true; |
| 6807 | } else { |
| 6808 | ErrorFound = NotASpecificExpression; |
| 6809 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 6810 | ErrorRange = FirstBinOp->getSourceRange(); |
| 6811 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 6812 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 6813 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6814 | } |
| 6815 | } |
| 6816 | } |
| 6817 | } |
| 6818 | } else { |
| 6819 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6820 | NoteRange = ErrorRange = |
| 6821 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6822 | ErrorFound = NotTwoSubstatements; |
| 6823 | } |
| 6824 | } else { |
| 6825 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 6826 | NoteRange = ErrorRange = |
| 6827 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 6828 | ErrorFound = NotACompoundStatement; |
| 6829 | } |
| 6830 | if (ErrorFound != NoError) { |
| 6831 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 6832 | << ErrorRange; |
| 6833 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 6834 | return StmtError(); |
| 6835 | } else if (CurContext->isDependentContext()) { |
| 6836 | UE = V = E = X = nullptr; |
| 6837 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6838 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6839 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6840 | |
| 6841 | getCurFunction()->setHasBranchProtectedScope(); |
| 6842 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 6843 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 6844 | X, V, E, UE, IsXLHSInRHSPart, |
| 6845 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 6846 | } |
| 6847 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6848 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 6849 | Stmt *AStmt, |
| 6850 | SourceLocation StartLoc, |
| 6851 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6852 | if (!AStmt) |
| 6853 | return StmtError(); |
| 6854 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 6855 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6856 | // 1.2.2 OpenMP Language Terminology |
| 6857 | // Structured block - An executable statement with a single entry at the |
| 6858 | // top and a single exit at the bottom. |
| 6859 | // The point of exit cannot be a branch out of the structured block. |
| 6860 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6861 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6862 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6863 | // OpenMP [2.16, Nesting of Regions] |
| 6864 | // If specified, a teams construct must be contained within a target |
| 6865 | // construct. That target construct must contain no statements or directives |
| 6866 | // outside of the teams construct. |
| 6867 | if (DSAStack->hasInnerTeamsRegion()) { |
| 6868 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 6869 | bool OMPTeamsFound = true; |
| 6870 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 6871 | auto I = CS->body_begin(); |
| 6872 | while (I != CS->body_end()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6873 | auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6874 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 6875 | OMPTeamsFound = false; |
| 6876 | break; |
| 6877 | } |
| 6878 | ++I; |
| 6879 | } |
| 6880 | assert(I != CS->body_end() && "Not found statement"); |
| 6881 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 6882 | } else { |
| 6883 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 6884 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 6885 | } |
| 6886 | if (!OMPTeamsFound) { |
| 6887 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 6888 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 6889 | diag::note_omp_nested_teams_construct_here); |
| 6890 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 6891 | << isa<OMPExecutableDirective>(S); |
| 6892 | return StmtError(); |
| 6893 | } |
| 6894 | } |
| 6895 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 6896 | getCurFunction()->setHasBranchProtectedScope(); |
| 6897 | |
| 6898 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 6899 | } |
| 6900 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 6901 | StmtResult |
| 6902 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 6903 | Stmt *AStmt, SourceLocation StartLoc, |
| 6904 | SourceLocation EndLoc) { |
| 6905 | if (!AStmt) |
| 6906 | return StmtError(); |
| 6907 | |
| 6908 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6909 | // 1.2.2 OpenMP Language Terminology |
| 6910 | // Structured block - An executable statement with a single entry at the |
| 6911 | // top and a single exit at the bottom. |
| 6912 | // The point of exit cannot be a branch out of the structured block. |
| 6913 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6914 | CS->getCapturedDecl()->setNothrow(); |
| 6915 | |
| 6916 | getCurFunction()->setHasBranchProtectedScope(); |
| 6917 | |
| 6918 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6919 | AStmt); |
| 6920 | } |
| 6921 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6922 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 6923 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6924 | SourceLocation EndLoc, |
| 6925 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6926 | if (!AStmt) |
| 6927 | return StmtError(); |
| 6928 | |
| 6929 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6930 | // 1.2.2 OpenMP Language Terminology |
| 6931 | // Structured block - An executable statement with a single entry at the |
| 6932 | // top and a single exit at the bottom. |
| 6933 | // The point of exit cannot be a branch out of the structured block. |
| 6934 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6935 | CS->getCapturedDecl()->setNothrow(); |
| 6936 | |
| 6937 | OMPLoopDirective::HelperExprs B; |
| 6938 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6939 | // define the nested loops number. |
| 6940 | unsigned NestedLoopCount = |
| 6941 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 6942 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6943 | VarsWithImplicitDSA, B); |
| 6944 | if (NestedLoopCount == 0) |
| 6945 | return StmtError(); |
| 6946 | |
| 6947 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6948 | "omp target parallel for loop exprs were not built"); |
| 6949 | |
| 6950 | if (!CurContext->isDependentContext()) { |
| 6951 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6952 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6953 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6954 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6955 | B.NumIterations, *this, CurScope, |
| 6956 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 6957 | return StmtError(); |
| 6958 | } |
| 6959 | } |
| 6960 | |
| 6961 | getCurFunction()->setHasBranchProtectedScope(); |
| 6962 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 6963 | NestedLoopCount, Clauses, AStmt, |
| 6964 | B, DSAStack->isCancelRegion()); |
| 6965 | } |
| 6966 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 6967 | /// \brief Check for existence of a map clause in the list of clauses. |
| 6968 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 6969 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 6970 | I != E; ++I) { |
| 6971 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 6972 | return true; |
| 6973 | } |
| 6974 | } |
| 6975 | |
| 6976 | return false; |
| 6977 | } |
| 6978 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6979 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 6980 | Stmt *AStmt, |
| 6981 | SourceLocation StartLoc, |
| 6982 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6983 | if (!AStmt) |
| 6984 | return StmtError(); |
| 6985 | |
| 6986 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6987 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6988 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 6989 | // At least one map clause must appear on the directive. |
| 6990 | if (!HasMapClause(Clauses)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6991 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 6992 | << getOpenMPDirectiveName(OMPD_target_data); |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 6993 | return StmtError(); |
| 6994 | } |
| 6995 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 6996 | getCurFunction()->setHasBranchProtectedScope(); |
| 6997 | |
| 6998 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6999 | AStmt); |
| 7000 | } |
| 7001 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 7002 | StmtResult |
| 7003 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 7004 | SourceLocation StartLoc, |
| 7005 | SourceLocation EndLoc) { |
| 7006 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 7007 | // At least one map clause must appear on the directive. |
| 7008 | if (!HasMapClause(Clauses)) { |
| 7009 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 7010 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 7011 | return StmtError(); |
| 7012 | } |
| 7013 | |
| 7014 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 7015 | Clauses); |
| 7016 | } |
| 7017 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 7018 | StmtResult |
| 7019 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 7020 | SourceLocation StartLoc, |
| 7021 | SourceLocation EndLoc) { |
| 7022 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 7023 | // At least one map clause must appear on the directive. |
| 7024 | if (!HasMapClause(Clauses)) { |
| 7025 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 7026 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 7027 | return StmtError(); |
| 7028 | } |
| 7029 | |
| 7030 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 7031 | } |
| 7032 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7033 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 7034 | SourceLocation StartLoc, |
| 7035 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7036 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7037 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7038 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7039 | seenMotionClause = true; |
| 7040 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 7041 | if (!seenMotionClause) { |
| 7042 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 7043 | return StmtError(); |
| 7044 | } |
| 7045 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 7046 | } |
| 7047 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7048 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 7049 | Stmt *AStmt, SourceLocation StartLoc, |
| 7050 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7051 | if (!AStmt) |
| 7052 | return StmtError(); |
| 7053 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 7054 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7055 | // 1.2.2 OpenMP Language Terminology |
| 7056 | // Structured block - An executable statement with a single entry at the |
| 7057 | // top and a single exit at the bottom. |
| 7058 | // The point of exit cannot be a branch out of the structured block. |
| 7059 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7060 | CS->getCapturedDecl()->setNothrow(); |
| 7061 | |
| 7062 | getCurFunction()->setHasBranchProtectedScope(); |
| 7063 | |
| 7064 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 7065 | } |
| 7066 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7067 | StmtResult |
| 7068 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 7069 | SourceLocation EndLoc, |
| 7070 | OpenMPDirectiveKind CancelRegion) { |
| 7071 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 7072 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 7073 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 7074 | << getOpenMPDirectiveName(CancelRegion); |
| 7075 | return StmtError(); |
| 7076 | } |
| 7077 | if (DSAStack->isParentNowaitRegion()) { |
| 7078 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 7079 | return StmtError(); |
| 7080 | } |
| 7081 | if (DSAStack->isParentOrderedRegion()) { |
| 7082 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 7083 | return StmtError(); |
| 7084 | } |
| 7085 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 7086 | CancelRegion); |
| 7087 | } |
| 7088 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 7089 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 7090 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7091 | SourceLocation EndLoc, |
| 7092 | OpenMPDirectiveKind CancelRegion) { |
| 7093 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 7094 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 7095 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 7096 | << getOpenMPDirectiveName(CancelRegion); |
| 7097 | return StmtError(); |
| 7098 | } |
| 7099 | if (DSAStack->isParentNowaitRegion()) { |
| 7100 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 7101 | return StmtError(); |
| 7102 | } |
| 7103 | if (DSAStack->isParentOrderedRegion()) { |
| 7104 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 7105 | return StmtError(); |
| 7106 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 7107 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 7108 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 7109 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 7110 | } |
| 7111 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7112 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 7113 | ArrayRef<OMPClause *> Clauses) { |
| 7114 | OMPClause *PrevClause = nullptr; |
| 7115 | bool ErrorFound = false; |
| 7116 | for (auto *C : Clauses) { |
| 7117 | if (C->getClauseKind() == OMPC_grainsize || |
| 7118 | C->getClauseKind() == OMPC_num_tasks) { |
| 7119 | if (!PrevClause) |
| 7120 | PrevClause = C; |
| 7121 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 7122 | S.Diag(C->getLocStart(), |
| 7123 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 7124 | << getOpenMPClauseName(C->getClauseKind()) |
| 7125 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 7126 | S.Diag(PrevClause->getLocStart(), |
| 7127 | diag::note_omp_previous_grainsize_num_tasks) |
| 7128 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 7129 | ErrorFound = true; |
| 7130 | } |
| 7131 | } |
| 7132 | } |
| 7133 | return ErrorFound; |
| 7134 | } |
| 7135 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7136 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 7137 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7138 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7139 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7140 | if (!AStmt) |
| 7141 | return StmtError(); |
| 7142 | |
| 7143 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7144 | OMPLoopDirective::HelperExprs B; |
| 7145 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7146 | // define the nested loops number. |
| 7147 | unsigned NestedLoopCount = |
| 7148 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7149 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7150 | VarsWithImplicitDSA, B); |
| 7151 | if (NestedLoopCount == 0) |
| 7152 | return StmtError(); |
| 7153 | |
| 7154 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7155 | "omp for loop exprs were not built"); |
| 7156 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7157 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7158 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7159 | // not appear on the same taskloop directive. |
| 7160 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7161 | return StmtError(); |
| 7162 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 7163 | getCurFunction()->setHasBranchProtectedScope(); |
| 7164 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 7165 | NestedLoopCount, Clauses, AStmt, B); |
| 7166 | } |
| 7167 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7168 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 7169 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7170 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7171 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7172 | if (!AStmt) |
| 7173 | return StmtError(); |
| 7174 | |
| 7175 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7176 | OMPLoopDirective::HelperExprs B; |
| 7177 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7178 | // define the nested loops number. |
| 7179 | unsigned NestedLoopCount = |
| 7180 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 7181 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 7182 | VarsWithImplicitDSA, B); |
| 7183 | if (NestedLoopCount == 0) |
| 7184 | return StmtError(); |
| 7185 | |
| 7186 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7187 | "omp for loop exprs were not built"); |
| 7188 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7189 | if (!CurContext->isDependentContext()) { |
| 7190 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7191 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7192 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7193 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 7194 | B.NumIterations, *this, CurScope, |
| 7195 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7196 | return StmtError(); |
| 7197 | } |
| 7198 | } |
| 7199 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7200 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 7201 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 7202 | // not appear on the same taskloop directive. |
| 7203 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 7204 | return StmtError(); |
| 7205 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 7206 | getCurFunction()->setHasBranchProtectedScope(); |
| 7207 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7208 | NestedLoopCount, Clauses, AStmt, B); |
| 7209 | } |
| 7210 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7211 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 7212 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7213 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7214 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7215 | if (!AStmt) |
| 7216 | return StmtError(); |
| 7217 | |
| 7218 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 7219 | OMPLoopDirective::HelperExprs B; |
| 7220 | // In presence of clause 'collapse' with number of loops, it will |
| 7221 | // define the nested loops number. |
| 7222 | unsigned NestedLoopCount = |
| 7223 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 7224 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7225 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7226 | if (NestedLoopCount == 0) |
| 7227 | return StmtError(); |
| 7228 | |
| 7229 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7230 | "omp for loop exprs were not built"); |
| 7231 | |
| 7232 | getCurFunction()->setHasBranchProtectedScope(); |
| 7233 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 7234 | NestedLoopCount, Clauses, AStmt, B); |
| 7235 | } |
| 7236 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 7237 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 7238 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7239 | SourceLocation EndLoc, |
| 7240 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7241 | if (!AStmt) |
| 7242 | return StmtError(); |
| 7243 | |
| 7244 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7245 | // 1.2.2 OpenMP Language Terminology |
| 7246 | // Structured block - An executable statement with a single entry at the |
| 7247 | // top and a single exit at the bottom. |
| 7248 | // The point of exit cannot be a branch out of the structured block. |
| 7249 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7250 | CS->getCapturedDecl()->setNothrow(); |
| 7251 | |
| 7252 | OMPLoopDirective::HelperExprs B; |
| 7253 | // In presence of clause 'collapse' with number of loops, it will |
| 7254 | // define the nested loops number. |
| 7255 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7256 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 7257 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 7258 | VarsWithImplicitDSA, B); |
| 7259 | if (NestedLoopCount == 0) |
| 7260 | return StmtError(); |
| 7261 | |
| 7262 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7263 | "omp for loop exprs were not built"); |
| 7264 | |
| 7265 | getCurFunction()->setHasBranchProtectedScope(); |
| 7266 | return OMPDistributeParallelForDirective::Create( |
| 7267 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7268 | } |
| 7269 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7270 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 7271 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7272 | SourceLocation EndLoc, |
| 7273 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7274 | if (!AStmt) |
| 7275 | return StmtError(); |
| 7276 | |
| 7277 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7278 | // 1.2.2 OpenMP Language Terminology |
| 7279 | // Structured block - An executable statement with a single entry at the |
| 7280 | // top and a single exit at the bottom. |
| 7281 | // The point of exit cannot be a branch out of the structured block. |
| 7282 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7283 | CS->getCapturedDecl()->setNothrow(); |
| 7284 | |
| 7285 | OMPLoopDirective::HelperExprs B; |
| 7286 | // In presence of clause 'collapse' with number of loops, it will |
| 7287 | // define the nested loops number. |
| 7288 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7289 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 7290 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 7291 | VarsWithImplicitDSA, B); |
| 7292 | if (NestedLoopCount == 0) |
| 7293 | return StmtError(); |
| 7294 | |
| 7295 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7296 | "omp for loop exprs were not built"); |
| 7297 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7298 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7299 | return StmtError(); |
| 7300 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 7301 | getCurFunction()->setHasBranchProtectedScope(); |
| 7302 | return OMPDistributeParallelForSimdDirective::Create( |
| 7303 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7304 | } |
| 7305 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7306 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 7307 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7308 | SourceLocation EndLoc, |
| 7309 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7310 | if (!AStmt) |
| 7311 | return StmtError(); |
| 7312 | |
| 7313 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7314 | // 1.2.2 OpenMP Language Terminology |
| 7315 | // Structured block - An executable statement with a single entry at the |
| 7316 | // top and a single exit at the bottom. |
| 7317 | // The point of exit cannot be a branch out of the structured block. |
| 7318 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7319 | CS->getCapturedDecl()->setNothrow(); |
| 7320 | |
| 7321 | OMPLoopDirective::HelperExprs B; |
| 7322 | // In presence of clause 'collapse' with number of loops, it will |
| 7323 | // define the nested loops number. |
| 7324 | unsigned NestedLoopCount = |
| 7325 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 7326 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7327 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7328 | if (NestedLoopCount == 0) |
| 7329 | return StmtError(); |
| 7330 | |
| 7331 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7332 | "omp for loop exprs were not built"); |
| 7333 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7334 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7335 | return StmtError(); |
| 7336 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 7337 | getCurFunction()->setHasBranchProtectedScope(); |
| 7338 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7339 | NestedLoopCount, Clauses, AStmt, B); |
| 7340 | } |
| 7341 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7342 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 7343 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7344 | SourceLocation EndLoc, |
| 7345 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7346 | if (!AStmt) |
| 7347 | return StmtError(); |
| 7348 | |
| 7349 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7350 | // 1.2.2 OpenMP Language Terminology |
| 7351 | // Structured block - An executable statement with a single entry at the |
| 7352 | // top and a single exit at the bottom. |
| 7353 | // The point of exit cannot be a branch out of the structured block. |
| 7354 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7355 | CS->getCapturedDecl()->setNothrow(); |
| 7356 | |
| 7357 | OMPLoopDirective::HelperExprs B; |
| 7358 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 7359 | // define the nested loops number. |
| 7360 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 7361 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 7362 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 7363 | VarsWithImplicitDSA, B); |
| 7364 | if (NestedLoopCount == 0) |
| 7365 | return StmtError(); |
| 7366 | |
| 7367 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7368 | "omp target parallel for simd loop exprs were not built"); |
| 7369 | |
| 7370 | if (!CurContext->isDependentContext()) { |
| 7371 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7372 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7373 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7374 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7375 | B.NumIterations, *this, CurScope, |
| 7376 | DSAStack)) |
| 7377 | return StmtError(); |
| 7378 | } |
| 7379 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 7380 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 7381 | return StmtError(); |
| 7382 | |
| 7383 | getCurFunction()->setHasBranchProtectedScope(); |
| 7384 | return OMPTargetParallelForSimdDirective::Create( |
| 7385 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 7386 | } |
| 7387 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7388 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 7389 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7390 | SourceLocation EndLoc, |
| 7391 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7392 | if (!AStmt) |
| 7393 | return StmtError(); |
| 7394 | |
| 7395 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7396 | // 1.2.2 OpenMP Language Terminology |
| 7397 | // Structured block - An executable statement with a single entry at the |
| 7398 | // top and a single exit at the bottom. |
| 7399 | // The point of exit cannot be a branch out of the structured block. |
| 7400 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7401 | CS->getCapturedDecl()->setNothrow(); |
| 7402 | |
| 7403 | OMPLoopDirective::HelperExprs B; |
| 7404 | // In presence of clause 'collapse' with number of loops, it will define the |
| 7405 | // nested loops number. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7406 | unsigned NestedLoopCount = |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7407 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 7408 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 7409 | VarsWithImplicitDSA, B); |
| 7410 | if (NestedLoopCount == 0) |
| 7411 | return StmtError(); |
| 7412 | |
| 7413 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7414 | "omp target simd loop exprs were not built"); |
| 7415 | |
| 7416 | if (!CurContext->isDependentContext()) { |
| 7417 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 7418 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7419 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 7420 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 7421 | B.NumIterations, *this, CurScope, |
| 7422 | DSAStack)) |
| 7423 | return StmtError(); |
| 7424 | } |
| 7425 | } |
| 7426 | |
| 7427 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 7428 | return StmtError(); |
| 7429 | |
| 7430 | getCurFunction()->setHasBranchProtectedScope(); |
| 7431 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 7432 | NestedLoopCount, Clauses, AStmt, B); |
| 7433 | } |
| 7434 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7435 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 7436 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 7437 | SourceLocation EndLoc, |
| 7438 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 7439 | if (!AStmt) |
| 7440 | return StmtError(); |
| 7441 | |
| 7442 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 7443 | // 1.2.2 OpenMP Language Terminology |
| 7444 | // Structured block - An executable statement with a single entry at the |
| 7445 | // top and a single exit at the bottom. |
| 7446 | // The point of exit cannot be a branch out of the structured block. |
| 7447 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 7448 | CS->getCapturedDecl()->setNothrow(); |
| 7449 | |
| 7450 | OMPLoopDirective::HelperExprs B; |
| 7451 | // In presence of clause 'collapse' with number of loops, it will |
| 7452 | // define the nested loops number. |
| 7453 | unsigned NestedLoopCount = |
| 7454 | CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| 7455 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 7456 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 7457 | if (NestedLoopCount == 0) |
| 7458 | return StmtError(); |
| 7459 | |
| 7460 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 7461 | "omp teams distribute loop exprs were not built"); |
| 7462 | |
| 7463 | getCurFunction()->setHasBranchProtectedScope(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7464 | return OMPTeamsDistributeDirective::Create( |
| 7465 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 7466 | } |
| 7467 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7468 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7469 | SourceLocation StartLoc, |
| 7470 | SourceLocation LParenLoc, |
| 7471 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7472 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7473 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7474 | case OMPC_final: |
| 7475 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7476 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7477 | case OMPC_num_threads: |
| 7478 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7479 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7480 | case OMPC_safelen: |
| 7481 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7482 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7483 | case OMPC_simdlen: |
| 7484 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7485 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7486 | case OMPC_collapse: |
| 7487 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7488 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7489 | case OMPC_ordered: |
| 7490 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 7491 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7492 | case OMPC_device: |
| 7493 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7494 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7495 | case OMPC_num_teams: |
| 7496 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7497 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7498 | case OMPC_thread_limit: |
| 7499 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7500 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7501 | case OMPC_priority: |
| 7502 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7503 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7504 | case OMPC_grainsize: |
| 7505 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7506 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7507 | case OMPC_num_tasks: |
| 7508 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7509 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7510 | case OMPC_hint: |
| 7511 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 7512 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7513 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7514 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7515 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7516 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7517 | case OMPC_private: |
| 7518 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7519 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7520 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7521 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7522 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7523 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7524 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7525 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7526 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7527 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7528 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7529 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7530 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7531 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7532 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7533 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7534 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7535 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7536 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7537 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7538 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7539 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7540 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7541 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7542 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7543 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7544 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7545 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7546 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7547 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7548 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7549 | llvm_unreachable("Clause is not allowed."); |
| 7550 | } |
| 7551 | return Res; |
| 7552 | } |
| 7553 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7554 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 7555 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7556 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7557 | SourceLocation NameModifierLoc, |
| 7558 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7559 | SourceLocation EndLoc) { |
| 7560 | Expr *ValExpr = Condition; |
| 7561 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7562 | !Condition->isInstantiationDependent() && |
| 7563 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7564 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7565 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7566 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7567 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7568 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7569 | } |
| 7570 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7571 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 7572 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7573 | } |
| 7574 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7575 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 7576 | SourceLocation StartLoc, |
| 7577 | SourceLocation LParenLoc, |
| 7578 | SourceLocation EndLoc) { |
| 7579 | Expr *ValExpr = Condition; |
| 7580 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7581 | !Condition->isInstantiationDependent() && |
| 7582 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7583 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7584 | if (Val.isInvalid()) |
| 7585 | return nullptr; |
| 7586 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7587 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7591 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7592 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 7593 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7594 | if (!Op) |
| 7595 | return ExprError(); |
| 7596 | |
| 7597 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 7598 | public: |
| 7599 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7600 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 7601 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 7602 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7603 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 7604 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7605 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 7606 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7607 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 7608 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7609 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 7610 | QualType T, |
| 7611 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7612 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 7613 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7614 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 7615 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7616 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7617 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7618 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7619 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 7620 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7621 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 7622 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7623 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 7624 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7625 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7626 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7627 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7628 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 7629 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7630 | llvm_unreachable("conversion functions are permitted"); |
| 7631 | } |
| 7632 | } ConvertDiagnoser; |
| 7633 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 7634 | } |
| 7635 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7636 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7637 | OpenMPClauseKind CKind, |
| 7638 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7639 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7640 | !ValExpr->isInstantiationDependent()) { |
| 7641 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7642 | ExprResult Value = |
| 7643 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7644 | if (Value.isInvalid()) |
| 7645 | return false; |
| 7646 | |
| 7647 | ValExpr = Value.get(); |
| 7648 | // The expression must evaluate to a non-negative integer value. |
| 7649 | llvm::APSInt Result; |
| 7650 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7651 | Result.isSigned() && |
| 7652 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 7653 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7654 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7655 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7656 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7657 | return false; |
| 7658 | } |
| 7659 | } |
| 7660 | return true; |
| 7661 | } |
| 7662 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7663 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 7664 | SourceLocation StartLoc, |
| 7665 | SourceLocation LParenLoc, |
| 7666 | SourceLocation EndLoc) { |
| 7667 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7668 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7669 | // OpenMP [2.5, Restrictions] |
| 7670 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7671 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 7672 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7673 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7674 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7675 | return new (Context) |
| 7676 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7677 | } |
| 7678 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7679 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7680 | OpenMPClauseKind CKind, |
| 7681 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7682 | if (!E) |
| 7683 | return ExprError(); |
| 7684 | if (E->isValueDependent() || E->isTypeDependent() || |
| 7685 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7686 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7687 | llvm::APSInt Result; |
| 7688 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 7689 | if (ICE.isInvalid()) |
| 7690 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7691 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 7692 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7693 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7694 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7695 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7696 | return ExprError(); |
| 7697 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 7698 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 7699 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 7700 | << E->getSourceRange(); |
| 7701 | return ExprError(); |
| 7702 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7703 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 7704 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7705 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7706 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7707 | return ICE; |
| 7708 | } |
| 7709 | |
| 7710 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 7711 | SourceLocation LParenLoc, |
| 7712 | SourceLocation EndLoc) { |
| 7713 | // OpenMP [2.8.1, simd construct, Description] |
| 7714 | // The parameter of the safelen clause must be a constant |
| 7715 | // positive integer expression. |
| 7716 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 7717 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7718 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7719 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7720 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7721 | } |
| 7722 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7723 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 7724 | SourceLocation LParenLoc, |
| 7725 | SourceLocation EndLoc) { |
| 7726 | // OpenMP [2.8.1, simd construct, Description] |
| 7727 | // The parameter of the simdlen clause must be a constant |
| 7728 | // positive integer expression. |
| 7729 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 7730 | if (Simdlen.isInvalid()) |
| 7731 | return nullptr; |
| 7732 | return new (Context) |
| 7733 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 7734 | } |
| 7735 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7736 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 7737 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7738 | SourceLocation LParenLoc, |
| 7739 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7740 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7741 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7742 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7743 | // The parameter of the collapse clause must be a constant |
| 7744 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7745 | ExprResult NumForLoopsResult = |
| 7746 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 7747 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7748 | return nullptr; |
| 7749 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7750 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7751 | } |
| 7752 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7753 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 7754 | SourceLocation EndLoc, |
| 7755 | SourceLocation LParenLoc, |
| 7756 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7757 | // OpenMP [2.7.1, loop construct, Description] |
| 7758 | // OpenMP [2.8.1, simd construct, Description] |
| 7759 | // OpenMP [2.9.6, distribute construct, Description] |
| 7760 | // The parameter of the ordered clause must be a constant |
| 7761 | // positive integer expression if any. |
| 7762 | if (NumForLoops && LParenLoc.isValid()) { |
| 7763 | ExprResult NumForLoopsResult = |
| 7764 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 7765 | if (NumForLoopsResult.isInvalid()) |
| 7766 | return nullptr; |
| 7767 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7768 | } else |
| 7769 | NumForLoops = nullptr; |
| 7770 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7771 | return new (Context) |
| 7772 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 7773 | } |
| 7774 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7775 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 7776 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 7777 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7778 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7779 | switch (Kind) { |
| 7780 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7781 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7782 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 7783 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7784 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7785 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7786 | Res = ActOnOpenMPProcBindClause( |
| 7787 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 7788 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7789 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7790 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7791 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7792 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7793 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7794 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7795 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7796 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7797 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7798 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7799 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7800 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7801 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7802 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7803 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7804 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7805 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7806 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7807 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7808 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7809 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7810 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7811 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7812 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7813 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7814 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7815 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7816 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7817 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7818 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7819 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7820 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7821 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7822 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7823 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7824 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7825 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7826 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7827 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7828 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7829 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7830 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7831 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7832 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7833 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7834 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7835 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7836 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7837 | llvm_unreachable("Clause is not allowed."); |
| 7838 | } |
| 7839 | return Res; |
| 7840 | } |
| 7841 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7842 | static std::string |
| 7843 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 7844 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 7845 | std::string Values; |
| 7846 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 7847 | unsigned Skipped = Exclude.size(); |
| 7848 | auto S = Exclude.begin(), E = Exclude.end(); |
| 7849 | for (unsigned i = First; i < Last; ++i) { |
| 7850 | if (std::find(S, E, i) != E) { |
| 7851 | --Skipped; |
| 7852 | continue; |
| 7853 | } |
| 7854 | Values += "'"; |
| 7855 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 7856 | Values += "'"; |
| 7857 | if (i == Bound - Skipped) |
| 7858 | Values += " or "; |
| 7859 | else if (i != Bound + 1 - Skipped) |
| 7860 | Values += ", "; |
| 7861 | } |
| 7862 | return Values; |
| 7863 | } |
| 7864 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7865 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7866 | SourceLocation KindKwLoc, |
| 7867 | SourceLocation StartLoc, |
| 7868 | SourceLocation LParenLoc, |
| 7869 | SourceLocation EndLoc) { |
| 7870 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7871 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7872 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7873 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7874 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7875 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7876 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7877 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7878 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7879 | switch (Kind) { |
| 7880 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7881 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7882 | break; |
| 7883 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7884 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7885 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7886 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7887 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7888 | break; |
| 7889 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7890 | return new (Context) |
| 7891 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7892 | } |
| 7893 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7894 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7895 | SourceLocation KindKwLoc, |
| 7896 | SourceLocation StartLoc, |
| 7897 | SourceLocation LParenLoc, |
| 7898 | SourceLocation EndLoc) { |
| 7899 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7900 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7901 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7902 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7903 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7904 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7905 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7906 | return new (Context) |
| 7907 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7908 | } |
| 7909 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7910 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7911 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7912 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7913 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7914 | SourceLocation EndLoc) { |
| 7915 | OMPClause *Res = nullptr; |
| 7916 | switch (Kind) { |
| 7917 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7918 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7919 | assert(Argument.size() == NumberOfElements && |
| 7920 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7921 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7922 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7923 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7924 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7925 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7926 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7927 | break; |
| 7928 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7929 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7930 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7931 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7932 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7933 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7934 | case OMPC_dist_schedule: |
| 7935 | Res = ActOnOpenMPDistScheduleClause( |
| 7936 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7937 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7938 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7939 | case OMPC_defaultmap: |
| 7940 | enum { Modifier, DefaultmapKind }; |
| 7941 | Res = ActOnOpenMPDefaultmapClause( |
| 7942 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7943 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7944 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 7945 | EndLoc); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7946 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7947 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7948 | case OMPC_num_threads: |
| 7949 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7950 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7951 | case OMPC_collapse: |
| 7952 | case OMPC_default: |
| 7953 | case OMPC_proc_bind: |
| 7954 | case OMPC_private: |
| 7955 | case OMPC_firstprivate: |
| 7956 | case OMPC_lastprivate: |
| 7957 | case OMPC_shared: |
| 7958 | case OMPC_reduction: |
| 7959 | case OMPC_linear: |
| 7960 | case OMPC_aligned: |
| 7961 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7962 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7963 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7964 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7965 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7966 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7967 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7968 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7969 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7970 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7971 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7972 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7973 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7974 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7975 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7976 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7977 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7978 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7979 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7980 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7981 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7982 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7983 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7984 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7985 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7986 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7987 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7988 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7989 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7990 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7991 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7992 | llvm_unreachable("Clause is not allowed."); |
| 7993 | } |
| 7994 | return Res; |
| 7995 | } |
| 7996 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7997 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7998 | OpenMPScheduleClauseModifier M2, |
| 7999 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 8000 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 8001 | SmallVector<unsigned, 2> Excluded; |
| 8002 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 8003 | Excluded.push_back(M2); |
| 8004 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 8005 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 8006 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 8007 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 8008 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 8009 | << getListOfPossibleValues(OMPC_schedule, |
| 8010 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 8011 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 8012 | Excluded) |
| 8013 | << getOpenMPClauseName(OMPC_schedule); |
| 8014 | return true; |
| 8015 | } |
| 8016 | return false; |
| 8017 | } |
| 8018 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8019 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8020 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8021 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8022 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 8023 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 8024 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 8025 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 8026 | return nullptr; |
| 8027 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 8028 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 8029 | // but not both. |
| 8030 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 8031 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 8032 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 8033 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 8034 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 8035 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 8036 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 8037 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 8038 | return nullptr; |
| 8039 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8040 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 8041 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8042 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 8043 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 8044 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 8045 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 8046 | Exclude); |
| 8047 | } else { |
| 8048 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 8049 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8050 | } |
| 8051 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 8052 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 8053 | return nullptr; |
| 8054 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8055 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 8056 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 8057 | // schedule(guided). |
| 8058 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 8059 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 8060 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 8061 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 8062 | diag::err_omp_schedule_nonmonotonic_static); |
| 8063 | return nullptr; |
| 8064 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8065 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 8066 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8067 | if (ChunkSize) { |
| 8068 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 8069 | !ChunkSize->isInstantiationDependent() && |
| 8070 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 8071 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 8072 | ExprResult Val = |
| 8073 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 8074 | if (Val.isInvalid()) |
| 8075 | return nullptr; |
| 8076 | |
| 8077 | ValExpr = Val.get(); |
| 8078 | |
| 8079 | // OpenMP [2.7.1, Restrictions] |
| 8080 | // chunk_size must be a loop invariant integer expression with a positive |
| 8081 | // value. |
| 8082 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 8083 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 8084 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 8085 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8086 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 8087 | return nullptr; |
| 8088 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 8089 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 8090 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8091 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 8092 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 8093 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8094 | } |
| 8095 | } |
| 8096 | } |
| 8097 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 8098 | return new (Context) |
| 8099 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 8100 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8101 | } |
| 8102 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8103 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 8104 | SourceLocation StartLoc, |
| 8105 | SourceLocation EndLoc) { |
| 8106 | OMPClause *Res = nullptr; |
| 8107 | switch (Kind) { |
| 8108 | case OMPC_ordered: |
| 8109 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 8110 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8111 | case OMPC_nowait: |
| 8112 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 8113 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8114 | case OMPC_untied: |
| 8115 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 8116 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8117 | case OMPC_mergeable: |
| 8118 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 8119 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8120 | case OMPC_read: |
| 8121 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 8122 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8123 | case OMPC_write: |
| 8124 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 8125 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8126 | case OMPC_update: |
| 8127 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 8128 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8129 | case OMPC_capture: |
| 8130 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 8131 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8132 | case OMPC_seq_cst: |
| 8133 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 8134 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8135 | case OMPC_threads: |
| 8136 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 8137 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8138 | case OMPC_simd: |
| 8139 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 8140 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8141 | case OMPC_nogroup: |
| 8142 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 8143 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8144 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8145 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8146 | case OMPC_num_threads: |
| 8147 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8148 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8149 | case OMPC_collapse: |
| 8150 | case OMPC_schedule: |
| 8151 | case OMPC_private: |
| 8152 | case OMPC_firstprivate: |
| 8153 | case OMPC_lastprivate: |
| 8154 | case OMPC_shared: |
| 8155 | case OMPC_reduction: |
| 8156 | case OMPC_linear: |
| 8157 | case OMPC_aligned: |
| 8158 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8159 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8160 | case OMPC_default: |
| 8161 | case OMPC_proc_bind: |
| 8162 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8163 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8164 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8165 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8166 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8167 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8168 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8169 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8170 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8171 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8172 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8173 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8174 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8175 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8176 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8177 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8178 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8179 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8180 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8181 | llvm_unreachable("Clause is not allowed."); |
| 8182 | } |
| 8183 | return Res; |
| 8184 | } |
| 8185 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8186 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 8187 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 8188 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8189 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 8190 | } |
| 8191 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8192 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 8193 | SourceLocation EndLoc) { |
| 8194 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 8195 | } |
| 8196 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8197 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 8198 | SourceLocation EndLoc) { |
| 8199 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 8200 | } |
| 8201 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8202 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 8203 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8204 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 8205 | } |
| 8206 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8207 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 8208 | SourceLocation EndLoc) { |
| 8209 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 8210 | } |
| 8211 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8212 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 8213 | SourceLocation EndLoc) { |
| 8214 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 8215 | } |
| 8216 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8217 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 8218 | SourceLocation EndLoc) { |
| 8219 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 8220 | } |
| 8221 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8222 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 8223 | SourceLocation EndLoc) { |
| 8224 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 8225 | } |
| 8226 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8227 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 8228 | SourceLocation EndLoc) { |
| 8229 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 8230 | } |
| 8231 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8232 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 8233 | SourceLocation EndLoc) { |
| 8234 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 8235 | } |
| 8236 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8237 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 8238 | SourceLocation EndLoc) { |
| 8239 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 8240 | } |
| 8241 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8242 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 8243 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 8244 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 8245 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8246 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8247 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 8248 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 8249 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 8250 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8251 | switch (Kind) { |
| 8252 | case OMPC_private: |
| 8253 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8254 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8255 | case OMPC_firstprivate: |
| 8256 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8257 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8258 | case OMPC_lastprivate: |
| 8259 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8260 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8261 | case OMPC_shared: |
| 8262 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8263 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8264 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8265 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 8266 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8267 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8268 | case OMPC_linear: |
| 8269 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8270 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8271 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 8272 | case OMPC_aligned: |
| 8273 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 8274 | ColonLoc, EndLoc); |
| 8275 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 8276 | case OMPC_copyin: |
| 8277 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8278 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 8279 | case OMPC_copyprivate: |
| 8280 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8281 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 8282 | case OMPC_flush: |
| 8283 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8284 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8285 | case OMPC_depend: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8286 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 8287 | StartLoc, LParenLoc, EndLoc); |
| 8288 | break; |
| 8289 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 8290 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 8291 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 8292 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 8293 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 8294 | case OMPC_to: |
| 8295 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8296 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 8297 | case OMPC_from: |
| 8298 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8299 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 8300 | case OMPC_use_device_ptr: |
| 8301 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8302 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 8303 | case OMPC_is_device_ptr: |
| 8304 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 8305 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 8306 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 8307 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 8308 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 8309 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 8310 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 8311 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8312 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 8313 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 8314 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 8315 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 8316 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 8317 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 8318 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8319 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 8320 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 8321 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 8322 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 8323 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 8324 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 8325 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 8326 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 8327 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 8328 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 8329 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 8330 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 8331 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 8332 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 8333 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 8334 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 8335 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 8336 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8337 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 8338 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8339 | llvm_unreachable("Clause is not allowed."); |
| 8340 | } |
| 8341 | return Res; |
| 8342 | } |
| 8343 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8344 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8345 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8346 | ExprResult Res = BuildDeclRefExpr( |
| 8347 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 8348 | if (!Res.isUsable()) |
| 8349 | return ExprError(); |
| 8350 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 8351 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 8352 | if (!Res.isUsable()) |
| 8353 | return ExprError(); |
| 8354 | } |
| 8355 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 8356 | Res = DefaultLvalueConversion(Res.get()); |
| 8357 | if (!Res.isUsable()) |
| 8358 | return ExprError(); |
| 8359 | } |
| 8360 | return Res; |
| 8361 | } |
| 8362 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8363 | static std::pair<ValueDecl *, bool> |
| 8364 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 8365 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8366 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 8367 | RefExpr->containsUnexpandedParameterPack()) |
| 8368 | return std::make_pair(nullptr, true); |
| 8369 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8370 | // OpenMP [3.1, C/C++] |
| 8371 | // A list item is a variable name. |
| 8372 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 8373 | // A variable that is part of another variable (as an array or |
| 8374 | // structure element) cannot appear in a private clause. |
| 8375 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8376 | enum { |
| 8377 | NoArrayExpr = -1, |
| 8378 | ArraySubscript = 0, |
| 8379 | OMPArraySection = 1 |
| 8380 | } IsArrayExpr = NoArrayExpr; |
| 8381 | if (AllowArraySection) { |
| 8382 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 8383 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 8384 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8385 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8386 | RefExpr = Base; |
| 8387 | IsArrayExpr = ArraySubscript; |
| 8388 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 8389 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 8390 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 8391 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 8392 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 8393 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 8394 | RefExpr = Base; |
| 8395 | IsArrayExpr = OMPArraySection; |
| 8396 | } |
| 8397 | } |
| 8398 | ELoc = RefExpr->getExprLoc(); |
| 8399 | ERange = RefExpr->getSourceRange(); |
| 8400 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8401 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 8402 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 8403 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 8404 | (S.getCurrentThisType().isNull() || !ME || |
| 8405 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 8406 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8407 | if (IsArrayExpr != NoArrayExpr) |
| 8408 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 8409 | << ERange; |
| 8410 | else { |
| 8411 | S.Diag(ELoc, |
| 8412 | AllowArraySection |
| 8413 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 8414 | : diag::err_omp_expected_var_name_member_expr) |
| 8415 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 8416 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8417 | return std::make_pair(nullptr, false); |
| 8418 | } |
| 8419 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 8420 | } |
| 8421 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8422 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 8423 | SourceLocation StartLoc, |
| 8424 | SourceLocation LParenLoc, |
| 8425 | SourceLocation EndLoc) { |
| 8426 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8427 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8428 | for (auto &RefExpr : VarList) { |
| 8429 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8430 | SourceLocation ELoc; |
| 8431 | SourceRange ERange; |
| 8432 | Expr *SimpleRefExpr = RefExpr; |
| 8433 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8434 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8435 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8436 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8437 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8438 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8439 | ValueDecl *D = Res.first; |
| 8440 | if (!D) |
| 8441 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8442 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8443 | QualType Type = D->getType(); |
| 8444 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8445 | |
| 8446 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8447 | // A variable that appears in a private clause must not have an incomplete |
| 8448 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8449 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8450 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8451 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8452 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8453 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8454 | // in a Construct] |
| 8455 | // Variables with the predetermined data-sharing attributes may not be |
| 8456 | // listed in data-sharing attributes clauses, except for the cases |
| 8457 | // listed below. For these exceptions only, listing a predetermined |
| 8458 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8459 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8460 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8461 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8462 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8463 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8464 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8465 | continue; |
| 8466 | } |
| 8467 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8468 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8469 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8470 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8471 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8472 | << getOpenMPClauseName(OMPC_private) << Type |
| 8473 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8474 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8475 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8476 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8477 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8478 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8479 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8480 | continue; |
| 8481 | } |
| 8482 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8483 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8484 | // A list item cannot appear in both a map clause and a data-sharing |
| 8485 | // attribute clause on the same construct |
| 8486 | if (DSAStack->getCurrentDirective() == OMPD_target) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8487 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8488 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8489 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8490 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8491 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8492 | ConflictKind = WhereFoundClauseKind; |
| 8493 | return true; |
| 8494 | })) { |
| 8495 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8496 | << getOpenMPClauseName(OMPC_private) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8497 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8498 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8499 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8500 | continue; |
| 8501 | } |
| 8502 | } |
| 8503 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8504 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 8505 | // A variable of class type (or array thereof) that appears in a private |
| 8506 | // clause requires an accessible, unambiguous default constructor for the |
| 8507 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8508 | // Generate helper private variable and initialize it with the default |
| 8509 | // value. The address of the original variable is replaced by the address of |
| 8510 | // the new private variable in CodeGen. This new variable is not added to |
| 8511 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 8512 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8513 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8514 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8515 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8516 | ActOnUninitializedDecl(VDPrivate, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8517 | if (VDPrivate->isInvalidDecl()) |
| 8518 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8519 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8520 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8521 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8522 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8523 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8524 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8525 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8526 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8527 | ? RefExpr->IgnoreParens() |
| 8528 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8529 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8530 | } |
| 8531 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8532 | if (Vars.empty()) |
| 8533 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8534 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8535 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8536 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8537 | } |
| 8538 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8539 | namespace { |
| 8540 | class DiagsUninitializedSeveretyRAII { |
| 8541 | private: |
| 8542 | DiagnosticsEngine &Diags; |
| 8543 | SourceLocation SavedLoc; |
| 8544 | bool IsIgnored; |
| 8545 | |
| 8546 | public: |
| 8547 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 8548 | bool IsIgnored) |
| 8549 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 8550 | if (!IsIgnored) { |
| 8551 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 8552 | /*Map*/ diag::Severity::Ignored, Loc); |
| 8553 | } |
| 8554 | } |
| 8555 | ~DiagsUninitializedSeveretyRAII() { |
| 8556 | if (!IsIgnored) |
| 8557 | Diags.popMappings(SavedLoc); |
| 8558 | } |
| 8559 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 8560 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8561 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8562 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 8563 | SourceLocation StartLoc, |
| 8564 | SourceLocation LParenLoc, |
| 8565 | SourceLocation EndLoc) { |
| 8566 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8567 | SmallVector<Expr *, 8> PrivateCopies; |
| 8568 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8569 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8570 | bool IsImplicitClause = |
| 8571 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 8572 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 8573 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8574 | for (auto &RefExpr : VarList) { |
| 8575 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8576 | SourceLocation ELoc; |
| 8577 | SourceRange ERange; |
| 8578 | Expr *SimpleRefExpr = RefExpr; |
| 8579 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8580 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8581 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8582 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8583 | PrivateCopies.push_back(nullptr); |
| 8584 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8585 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8586 | ValueDecl *D = Res.first; |
| 8587 | if (!D) |
| 8588 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8589 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8590 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8591 | QualType Type = D->getType(); |
| 8592 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8593 | |
| 8594 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8595 | // A variable that appears in a private clause must not have an incomplete |
| 8596 | // type or a reference type. |
| 8597 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8598 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8599 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8600 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8601 | |
| 8602 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 8603 | // 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] | 8604 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8605 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8606 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8607 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8608 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8609 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8610 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8611 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8612 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8613 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8614 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 8615 | // A list item that specifies a given variable may not appear in more |
| 8616 | // than one clause on the same directive, except that a variable may be |
| 8617 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8618 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8619 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8620 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8621 | << getOpenMPClauseName(DVar.CKind) |
| 8622 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8623 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8624 | continue; |
| 8625 | } |
| 8626 | |
| 8627 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8628 | // in a Construct] |
| 8629 | // Variables with the predetermined data-sharing attributes may not be |
| 8630 | // listed in data-sharing attributes clauses, except for the cases |
| 8631 | // listed below. For these exceptions only, listing a predetermined |
| 8632 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8633 | // the variable's predetermined data-sharing attributes. |
| 8634 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8635 | // in a Construct, C/C++, p.2] |
| 8636 | // Variables with const-qualified type having no mutable member may be |
| 8637 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8638 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8639 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 8640 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8641 | << getOpenMPClauseName(DVar.CKind) |
| 8642 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8643 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8644 | continue; |
| 8645 | } |
| 8646 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8647 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8648 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 8649 | // A list item that is private within a parallel region must not appear |
| 8650 | // in a firstprivate clause on a worksharing construct if any of the |
| 8651 | // worksharing regions arising from the worksharing construct ever bind |
| 8652 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8653 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8654 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8655 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8656 | if (DVar.CKind != OMPC_shared && |
| 8657 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8658 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8659 | Diag(ELoc, diag::err_omp_required_access) |
| 8660 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8661 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8662 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8663 | continue; |
| 8664 | } |
| 8665 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8666 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 8667 | // A list item that appears in a reduction clause of a parallel construct |
| 8668 | // must not appear in a firstprivate clause on a worksharing or task |
| 8669 | // construct if any of the worksharing or task regions arising from the |
| 8670 | // worksharing or task construct ever bind to any of the parallel regions |
| 8671 | // arising from the parallel construct. |
| 8672 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 8673 | // A list item that appears in a reduction clause in worksharing |
| 8674 | // construct must not appear in a firstprivate clause in a task construct |
| 8675 | // encountered during execution of any of the worksharing regions arising |
| 8676 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8677 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8678 | DVar = DSAStack->hasInnermostDSA( |
| 8679 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8680 | [](OpenMPDirectiveKind K) -> bool { |
| 8681 | return isOpenMPParallelDirective(K) || |
| 8682 | isOpenMPWorksharingDirective(K); |
| 8683 | }, |
| 8684 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8685 | if (DVar.CKind == OMPC_reduction && |
| 8686 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8687 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 8688 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 8689 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8690 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8691 | continue; |
| 8692 | } |
| 8693 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8694 | |
| 8695 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8696 | // A list item that is private within a teams region must not appear in a |
| 8697 | // firstprivate clause on a distribute construct if any of the distribute |
| 8698 | // regions arising from the distribute construct ever bind to any of the |
| 8699 | // teams regions arising from the teams construct. |
| 8700 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8701 | // A list item that appears in a reduction clause of a teams construct |
| 8702 | // must not appear in a firstprivate clause on a distribute construct if |
| 8703 | // any of the distribute regions arising from the distribute construct |
| 8704 | // ever bind to any of the teams regions arising from the teams construct. |
| 8705 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8706 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8707 | // both. |
| 8708 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8709 | DVar = DSAStack->hasInnermostDSA( |
| 8710 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 8711 | [](OpenMPDirectiveKind K) -> bool { |
| 8712 | return isOpenMPTeamsDirective(K); |
| 8713 | }, |
| 8714 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8715 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 8716 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8717 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8718 | continue; |
| 8719 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8720 | DVar = DSAStack->hasInnermostDSA( |
| 8721 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8722 | [](OpenMPDirectiveKind K) -> bool { |
| 8723 | return isOpenMPTeamsDirective(K); |
| 8724 | }, |
| 8725 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8726 | if (DVar.CKind == OMPC_reduction && |
| 8727 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 8728 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8729 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8730 | continue; |
| 8731 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8732 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8733 | if (DVar.CKind == OMPC_lastprivate) { |
| 8734 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8735 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8736 | continue; |
| 8737 | } |
| 8738 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8739 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8740 | // A list item cannot appear in both a map clause and a data-sharing |
| 8741 | // attribute clause on the same construct |
| 8742 | if (CurrDir == OMPD_target) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8743 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8744 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8745 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8746 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8747 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8748 | ConflictKind = WhereFoundClauseKind; |
| 8749 | return true; |
| 8750 | })) { |
| 8751 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8752 | << getOpenMPClauseName(OMPC_firstprivate) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8753 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8754 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8755 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8756 | continue; |
| 8757 | } |
| 8758 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8759 | } |
| 8760 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8761 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8762 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8763 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8764 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8765 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 8766 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8767 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8768 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8769 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8770 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8771 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8772 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8773 | continue; |
| 8774 | } |
| 8775 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8776 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8777 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8778 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8779 | // Generate helper private variable and initialize it with the value of the |
| 8780 | // original variable. The address of the original variable is replaced by |
| 8781 | // the address of the new private variable in the CodeGen. This new variable |
| 8782 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 8783 | // original variable for proper diagnostics and variable capturing. |
| 8784 | Expr *VDInitRefExpr = nullptr; |
| 8785 | // For arrays generate initializer for single element and replace it by the |
| 8786 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8787 | if (Type->isArrayType()) { |
| 8788 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8789 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8790 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8791 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8792 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8793 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8794 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8795 | InitializedEntity Entity = |
| 8796 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8797 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 8798 | |
| 8799 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 8800 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 8801 | if (Result.isInvalid()) |
| 8802 | VDPrivate->setInvalidDecl(); |
| 8803 | else |
| 8804 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8805 | // Remove temp variable declaration. |
| 8806 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8807 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8808 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 8809 | ".firstprivate.temp"); |
| 8810 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 8811 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8812 | AddInitializerToDecl(VDPrivate, |
| 8813 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 8814 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8815 | } |
| 8816 | if (VDPrivate->isInvalidDecl()) { |
| 8817 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8818 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8819 | diag::note_omp_task_predetermined_firstprivate_here); |
| 8820 | } |
| 8821 | continue; |
| 8822 | } |
| 8823 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8824 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8825 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 8826 | RefExpr->getExprLoc()); |
| 8827 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8828 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8829 | if (TopDVar.CKind == OMPC_lastprivate) |
| 8830 | Ref = TopDVar.PrivateCopy; |
| 8831 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8832 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8833 | if (!IsOpenMPCapturedDecl(D)) |
| 8834 | ExprCaptures.push_back(Ref->getDecl()); |
| 8835 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8836 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8837 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8838 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8839 | ? RefExpr->IgnoreParens() |
| 8840 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8841 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 8842 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8843 | } |
| 8844 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8845 | if (Vars.empty()) |
| 8846 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8847 | |
| 8848 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8849 | Vars, PrivateCopies, Inits, |
| 8850 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8851 | } |
| 8852 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8853 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 8854 | SourceLocation StartLoc, |
| 8855 | SourceLocation LParenLoc, |
| 8856 | SourceLocation EndLoc) { |
| 8857 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8858 | SmallVector<Expr *, 8> SrcExprs; |
| 8859 | SmallVector<Expr *, 8> DstExprs; |
| 8860 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8861 | SmallVector<Decl *, 4> ExprCaptures; |
| 8862 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8863 | for (auto &RefExpr : VarList) { |
| 8864 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8865 | SourceLocation ELoc; |
| 8866 | SourceRange ERange; |
| 8867 | Expr *SimpleRefExpr = RefExpr; |
| 8868 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8869 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8870 | // It will be analyzed later. |
| 8871 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8872 | SrcExprs.push_back(nullptr); |
| 8873 | DstExprs.push_back(nullptr); |
| 8874 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8875 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8876 | ValueDecl *D = Res.first; |
| 8877 | if (!D) |
| 8878 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8879 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8880 | QualType Type = D->getType(); |
| 8881 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8882 | |
| 8883 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 8884 | // A variable that appears in a lastprivate clause must not have an |
| 8885 | // incomplete type or a reference type. |
| 8886 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8887 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8888 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8889 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8890 | |
| 8891 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8892 | // in a Construct] |
| 8893 | // Variables with the predetermined data-sharing attributes may not be |
| 8894 | // listed in data-sharing attributes clauses, except for the cases |
| 8895 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8896 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8897 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 8898 | DVar.CKind != OMPC_firstprivate && |
| 8899 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 8900 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8901 | << getOpenMPClauseName(DVar.CKind) |
| 8902 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8903 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8904 | continue; |
| 8905 | } |
| 8906 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8907 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8908 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8909 | // A list item that is private within a parallel region, or that appears in |
| 8910 | // the reduction clause of a parallel construct, must not appear in a |
| 8911 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8912 | // worksharing regions ever binds to any of the corresponding parallel |
| 8913 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8914 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8915 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 8916 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8917 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8918 | if (DVar.CKind != OMPC_shared) { |
| 8919 | Diag(ELoc, diag::err_omp_required_access) |
| 8920 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8921 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8922 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8923 | continue; |
| 8924 | } |
| 8925 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8926 | |
| 8927 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8928 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8929 | // both. |
| 8930 | if (CurrDir == OMPD_distribute) { |
| 8931 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8932 | if (DVar.CKind == OMPC_firstprivate) { |
| 8933 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8934 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8935 | continue; |
| 8936 | } |
| 8937 | } |
| 8938 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8939 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8940 | // A variable of class type (or array thereof) that appears in a |
| 8941 | // lastprivate clause requires an accessible, unambiguous default |
| 8942 | // constructor for the class type, unless the list item is also specified |
| 8943 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8944 | // A variable of class type (or array thereof) that appears in a |
| 8945 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8946 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8947 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8948 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8949 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8950 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8951 | auto *PseudoSrcExpr = |
| 8952 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8953 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8954 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8955 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8956 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8957 | // For arrays generate assignment operation for single element and replace |
| 8958 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8959 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8960 | PseudoDstExpr, PseudoSrcExpr); |
| 8961 | if (AssignmentOp.isInvalid()) |
| 8962 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8963 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8964 | /*DiscardedValue=*/true); |
| 8965 | if (AssignmentOp.isInvalid()) |
| 8966 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8967 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8968 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8969 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8970 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8971 | Ref = TopDVar.PrivateCopy; |
| 8972 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8973 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8974 | if (!IsOpenMPCapturedDecl(D)) |
| 8975 | ExprCaptures.push_back(Ref->getDecl()); |
| 8976 | } |
| 8977 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8978 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8979 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8980 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8981 | if (!RefRes.isUsable()) |
| 8982 | continue; |
| 8983 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8984 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8985 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8986 | if (!PostUpdateRes.isUsable()) |
| 8987 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8988 | ExprPostUpdates.push_back( |
| 8989 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8990 | } |
| 8991 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8992 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8993 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8994 | ? RefExpr->IgnoreParens() |
| 8995 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8996 | SrcExprs.push_back(PseudoSrcExpr); |
| 8997 | DstExprs.push_back(PseudoDstExpr); |
| 8998 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8999 | } |
| 9000 | |
| 9001 | if (Vars.empty()) |
| 9002 | return nullptr; |
| 9003 | |
| 9004 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 9005 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9006 | buildPreInits(Context, ExprCaptures), |
| 9007 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 9008 | } |
| 9009 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9010 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 9011 | SourceLocation StartLoc, |
| 9012 | SourceLocation LParenLoc, |
| 9013 | SourceLocation EndLoc) { |
| 9014 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9015 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9016 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9017 | SourceLocation ELoc; |
| 9018 | SourceRange ERange; |
| 9019 | Expr *SimpleRefExpr = RefExpr; |
| 9020 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9021 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9022 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9023 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9024 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9025 | ValueDecl *D = Res.first; |
| 9026 | if (!D) |
| 9027 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9028 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9029 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9030 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9031 | // in a Construct] |
| 9032 | // Variables with the predetermined data-sharing attributes may not be |
| 9033 | // listed in data-sharing attributes clauses, except for the cases |
| 9034 | // listed below. For these exceptions only, listing a predetermined |
| 9035 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9036 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9037 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9038 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 9039 | DVar.RefExpr) { |
| 9040 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9041 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9042 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9043 | continue; |
| 9044 | } |
| 9045 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9046 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9047 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9048 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 9049 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9050 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 9051 | ? RefExpr->IgnoreParens() |
| 9052 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9053 | } |
| 9054 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9055 | if (Vars.empty()) |
| 9056 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 9057 | |
| 9058 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 9059 | } |
| 9060 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9061 | namespace { |
| 9062 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 9063 | DSAStackTy *Stack; |
| 9064 | |
| 9065 | public: |
| 9066 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 9067 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 9068 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9069 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 9070 | return false; |
| 9071 | if (DVar.CKind != OMPC_unknown) |
| 9072 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 9073 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 9074 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 9075 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9076 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9077 | return true; |
| 9078 | return false; |
| 9079 | } |
| 9080 | return false; |
| 9081 | } |
| 9082 | bool VisitStmt(Stmt *S) { |
| 9083 | for (auto Child : S->children()) { |
| 9084 | if (Child && Visit(Child)) |
| 9085 | return true; |
| 9086 | } |
| 9087 | return false; |
| 9088 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9089 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9090 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9091 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9092 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9093 | namespace { |
| 9094 | // Transform MemberExpression for specified FieldDecl of current class to |
| 9095 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 9096 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 9097 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 9098 | ValueDecl *Field; |
| 9099 | DeclRefExpr *CapturedExpr; |
| 9100 | |
| 9101 | public: |
| 9102 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 9103 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 9104 | |
| 9105 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 9106 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 9107 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9108 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9109 | return CapturedExpr; |
| 9110 | } |
| 9111 | return BaseTransform::TransformMemberExpr(E); |
| 9112 | } |
| 9113 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 9114 | }; |
| 9115 | } // namespace |
| 9116 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9117 | template <typename T> |
| 9118 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 9119 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 9120 | for (auto &Set : Lookups) { |
| 9121 | for (auto *D : Set) { |
| 9122 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 9123 | return Res; |
| 9124 | } |
| 9125 | } |
| 9126 | return T(); |
| 9127 | } |
| 9128 | |
| 9129 | static ExprResult |
| 9130 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 9131 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 9132 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 9133 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 9134 | if (ReductionIdScopeSpec.isInvalid()) |
| 9135 | return ExprError(); |
| 9136 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 9137 | if (S) { |
| 9138 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 9139 | Lookup.suppressDiagnostics(); |
| 9140 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 9141 | auto *D = Lookup.getRepresentativeDecl(); |
| 9142 | do { |
| 9143 | S = S->getParent(); |
| 9144 | } while (S && !S->isDeclScope(D)); |
| 9145 | if (S) |
| 9146 | S = S->getParent(); |
| 9147 | Lookups.push_back(UnresolvedSet<8>()); |
| 9148 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 9149 | Lookup.clear(); |
| 9150 | } |
| 9151 | } else if (auto *ULE = |
| 9152 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 9153 | Lookups.push_back(UnresolvedSet<8>()); |
| 9154 | Decl *PrevD = nullptr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9155 | for (auto *D : ULE->decls()) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9156 | if (D == PrevD) |
| 9157 | Lookups.push_back(UnresolvedSet<8>()); |
| 9158 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 9159 | Lookups.back().addDecl(DRD); |
| 9160 | PrevD = D; |
| 9161 | } |
| 9162 | } |
| 9163 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 9164 | Ty->containsUnexpandedParameterPack() || |
| 9165 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 9166 | return !D->isInvalidDecl() && |
| 9167 | (D->getType()->isDependentType() || |
| 9168 | D->getType()->isInstantiationDependentType() || |
| 9169 | D->getType()->containsUnexpandedParameterPack()); |
| 9170 | })) { |
| 9171 | UnresolvedSet<8> ResSet; |
| 9172 | for (auto &Set : Lookups) { |
| 9173 | ResSet.append(Set.begin(), Set.end()); |
| 9174 | // The last item marks the end of all declarations at the specified scope. |
| 9175 | ResSet.addDecl(Set[Set.size() - 1]); |
| 9176 | } |
| 9177 | return UnresolvedLookupExpr::Create( |
| 9178 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 9179 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 9180 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 9181 | } |
| 9182 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 9183 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 9184 | if (!D->isInvalidDecl() && |
| 9185 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 9186 | return D; |
| 9187 | return nullptr; |
| 9188 | })) |
| 9189 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 9190 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 9191 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 9192 | if (!D->isInvalidDecl() && |
| 9193 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 9194 | !Ty.isMoreQualifiedThan(D->getType())) |
| 9195 | return D; |
| 9196 | return nullptr; |
| 9197 | })) { |
| 9198 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 9199 | /*DetectVirtual=*/false); |
| 9200 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 9201 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 9202 | VD->getType().getUnqualifiedType()))) { |
| 9203 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 9204 | /*DiagID=*/0) != |
| 9205 | Sema::AR_inaccessible) { |
| 9206 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 9207 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 9208 | } |
| 9209 | } |
| 9210 | } |
| 9211 | } |
| 9212 | if (ReductionIdScopeSpec.isSet()) { |
| 9213 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 9214 | return ExprError(); |
| 9215 | } |
| 9216 | return ExprEmpty(); |
| 9217 | } |
| 9218 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9219 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 9220 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 9221 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9222 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 9223 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9224 | auto DN = ReductionId.getName(); |
| 9225 | auto OOK = DN.getCXXOverloadedOperator(); |
| 9226 | BinaryOperatorKind BOK = BO_Comma; |
| 9227 | |
| 9228 | // OpenMP [2.14.3.6, reduction clause] |
| 9229 | // C |
| 9230 | // reduction-identifier is either an identifier or one of the following |
| 9231 | // operators: +, -, *, &, |, ^, && and || |
| 9232 | // C++ |
| 9233 | // reduction-identifier is either an id-expression or one of the following |
| 9234 | // operators: +, -, *, &, |, ^, && and || |
| 9235 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 9236 | switch (OOK) { |
| 9237 | case OO_Plus: |
| 9238 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9239 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9240 | break; |
| 9241 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9242 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9243 | break; |
| 9244 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9245 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9246 | break; |
| 9247 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9248 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9249 | break; |
| 9250 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9251 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9252 | break; |
| 9253 | case OO_AmpAmp: |
| 9254 | BOK = BO_LAnd; |
| 9255 | break; |
| 9256 | case OO_PipePipe: |
| 9257 | BOK = BO_LOr; |
| 9258 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9259 | case OO_New: |
| 9260 | case OO_Delete: |
| 9261 | case OO_Array_New: |
| 9262 | case OO_Array_Delete: |
| 9263 | case OO_Slash: |
| 9264 | case OO_Percent: |
| 9265 | case OO_Tilde: |
| 9266 | case OO_Exclaim: |
| 9267 | case OO_Equal: |
| 9268 | case OO_Less: |
| 9269 | case OO_Greater: |
| 9270 | case OO_LessEqual: |
| 9271 | case OO_GreaterEqual: |
| 9272 | case OO_PlusEqual: |
| 9273 | case OO_MinusEqual: |
| 9274 | case OO_StarEqual: |
| 9275 | case OO_SlashEqual: |
| 9276 | case OO_PercentEqual: |
| 9277 | case OO_CaretEqual: |
| 9278 | case OO_AmpEqual: |
| 9279 | case OO_PipeEqual: |
| 9280 | case OO_LessLess: |
| 9281 | case OO_GreaterGreater: |
| 9282 | case OO_LessLessEqual: |
| 9283 | case OO_GreaterGreaterEqual: |
| 9284 | case OO_EqualEqual: |
| 9285 | case OO_ExclaimEqual: |
| 9286 | case OO_PlusPlus: |
| 9287 | case OO_MinusMinus: |
| 9288 | case OO_Comma: |
| 9289 | case OO_ArrowStar: |
| 9290 | case OO_Arrow: |
| 9291 | case OO_Call: |
| 9292 | case OO_Subscript: |
| 9293 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 9294 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9295 | case NUM_OVERLOADED_OPERATORS: |
| 9296 | llvm_unreachable("Unexpected reduction identifier"); |
| 9297 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9298 | if (auto II = DN.getAsIdentifierInfo()) { |
| 9299 | if (II->isStr("max")) |
| 9300 | BOK = BO_GT; |
| 9301 | else if (II->isStr("min")) |
| 9302 | BOK = BO_LT; |
| 9303 | } |
| 9304 | break; |
| 9305 | } |
| 9306 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9307 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9308 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9309 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9310 | |
| 9311 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9312 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9313 | SmallVector<Expr *, 8> LHSs; |
| 9314 | SmallVector<Expr *, 8> RHSs; |
| 9315 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9316 | SmallVector<Decl *, 4> ExprCaptures; |
| 9317 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9318 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 9319 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9320 | for (auto RefExpr : VarList) { |
| 9321 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9322 | // OpenMP [2.1, C/C++] |
| 9323 | // A list item is a variable or array section, subject to the restrictions |
| 9324 | // specified in Section 2.4 on page 42 and in each of the sections |
| 9325 | // describing clauses and directives for which a list appears. |
| 9326 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 9327 | // A variable that is part of another variable (as an array or |
| 9328 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9329 | if (!FirstIter && IR != ER) |
| 9330 | ++IR; |
| 9331 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9332 | SourceLocation ELoc; |
| 9333 | SourceRange ERange; |
| 9334 | Expr *SimpleRefExpr = RefExpr; |
| 9335 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9336 | /*AllowArraySection=*/true); |
| 9337 | if (Res.second) { |
| 9338 | // It will be analyzed later. |
| 9339 | Vars.push_back(RefExpr); |
| 9340 | Privates.push_back(nullptr); |
| 9341 | LHSs.push_back(nullptr); |
| 9342 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9343 | // Try to find 'declare reduction' corresponding construct before using |
| 9344 | // builtin/overloaded operators. |
| 9345 | QualType Type = Context.DependentTy; |
| 9346 | CXXCastPath BasePath; |
| 9347 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9348 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9349 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9350 | if (CurContext->isDependentContext() && |
| 9351 | (DeclareReductionRef.isUnset() || |
| 9352 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 9353 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9354 | else |
| 9355 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9356 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9357 | ValueDecl *D = Res.first; |
| 9358 | if (!D) |
| 9359 | continue; |
| 9360 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9361 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9362 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 9363 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 9364 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9365 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9366 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9367 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 9368 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 9369 | Type = ATy->getElementType(); |
| 9370 | else |
| 9371 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9372 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9373 | } else |
| 9374 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 9375 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9376 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9377 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 9378 | // A variable that appears in a private clause must not have an incomplete |
| 9379 | // type or a reference type. |
| 9380 | if (RequireCompleteType(ELoc, Type, |
| 9381 | diag::err_omp_reduction_incomplete_type)) |
| 9382 | continue; |
| 9383 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9384 | // A list item that appears in a reduction clause must not be |
| 9385 | // const-qualified. |
| 9386 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9387 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9388 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9389 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9390 | bool IsDecl = !VD || |
| 9391 | VD->isThisDeclarationADefinition(Context) == |
| 9392 | VarDecl::DeclarationOnly; |
| 9393 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9394 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9395 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9396 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9397 | continue; |
| 9398 | } |
| 9399 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 9400 | // If a list-item is a reference type then it must bind to the same object |
| 9401 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9402 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9403 | VarDecl *VDDef = VD->getDefinition(); |
David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame^] | 9404 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9405 | DSARefChecker Check(DSAStack); |
| 9406 | if (Check.Visit(VDDef->getInit())) { |
| 9407 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 9408 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 9409 | continue; |
| 9410 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9411 | } |
| 9412 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9413 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9414 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 9415 | // in a Construct] |
| 9416 | // Variables with the predetermined data-sharing attributes may not be |
| 9417 | // listed in data-sharing attributes clauses, except for the cases |
| 9418 | // listed below. For these exceptions only, listing a predetermined |
| 9419 | // variable in a data-sharing attribute clause is allowed and overrides |
| 9420 | // the variable's predetermined data-sharing attributes. |
| 9421 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 9422 | // Any number of reduction clauses can be specified on the directive, |
| 9423 | // but a list item can appear only once in the reduction clauses for that |
| 9424 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 9425 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9426 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9427 | if (DVar.CKind == OMPC_reduction) { |
| 9428 | Diag(ELoc, diag::err_omp_once_referenced) |
| 9429 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9430 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9431 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9432 | } else if (DVar.CKind != OMPC_unknown) { |
| 9433 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9434 | << getOpenMPClauseName(DVar.CKind) |
| 9435 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9436 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9437 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9438 | } |
| 9439 | |
| 9440 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 9441 | // A list item that appears in a reduction clause of a worksharing |
| 9442 | // construct must be shared in the parallel regions to which any of the |
| 9443 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9444 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 9445 | if (isOpenMPWorksharingDirective(CurrDir) && |
| 9446 | !isOpenMPParallelDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9447 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9448 | if (DVar.CKind != OMPC_shared) { |
| 9449 | Diag(ELoc, diag::err_omp_required_access) |
| 9450 | << getOpenMPClauseName(OMPC_reduction) |
| 9451 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9452 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9453 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9454 | } |
| 9455 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9456 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9457 | // Try to find 'declare reduction' corresponding construct before using |
| 9458 | // builtin/overloaded operators. |
| 9459 | CXXCastPath BasePath; |
| 9460 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9461 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9462 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9463 | if (DeclareReductionRef.isInvalid()) |
| 9464 | continue; |
| 9465 | if (CurContext->isDependentContext() && |
| 9466 | (DeclareReductionRef.isUnset() || |
| 9467 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 9468 | Vars.push_back(RefExpr); |
| 9469 | Privates.push_back(nullptr); |
| 9470 | LHSs.push_back(nullptr); |
| 9471 | RHSs.push_back(nullptr); |
| 9472 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9473 | continue; |
| 9474 | } |
| 9475 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 9476 | // Not allowed reduction identifier is found. |
| 9477 | Diag(ReductionId.getLocStart(), |
| 9478 | diag::err_omp_unknown_reduction_identifier) |
| 9479 | << Type << ReductionIdRange; |
| 9480 | continue; |
| 9481 | } |
| 9482 | |
| 9483 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 9484 | // The type of a list item that appears in a reduction clause must be valid |
| 9485 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 9486 | // of the list item must be an allowed arithmetic data type: char, int, |
| 9487 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 9488 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 9489 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 9490 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 9491 | if (DeclareReductionRef.isUnset()) { |
| 9492 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 9493 | !(Type->isScalarType() || |
| 9494 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 9495 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 9496 | << getLangOpts().CPlusPlus; |
| 9497 | if (!ASE && !OASE) { |
| 9498 | bool IsDecl = !VD || |
| 9499 | VD->isThisDeclarationADefinition(Context) == |
| 9500 | VarDecl::DeclarationOnly; |
| 9501 | Diag(D->getLocation(), |
| 9502 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9503 | << D; |
| 9504 | } |
| 9505 | continue; |
| 9506 | } |
| 9507 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 9508 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 9509 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 9510 | if (!ASE && !OASE) { |
| 9511 | bool IsDecl = !VD || |
| 9512 | VD->isThisDeclarationADefinition(Context) == |
| 9513 | VarDecl::DeclarationOnly; |
| 9514 | Diag(D->getLocation(), |
| 9515 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9516 | << D; |
| 9517 | } |
| 9518 | continue; |
| 9519 | } |
| 9520 | } |
| 9521 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9522 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9523 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9524 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9525 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9526 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9527 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9528 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9529 | (!ASE && |
| 9530 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9531 | // For arrays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9532 | // Create pseudo array type for private copy. The size for this array will |
| 9533 | // be generated during codegen. |
| 9534 | // For array subscripts or single variables Private Ty is the same as Type |
| 9535 | // (type of the variable or single array element). |
| 9536 | PrivateTy = Context.getVariableArrayType( |
| 9537 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 9538 | Context.getSizeType(), VK_RValue), |
| 9539 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9540 | } else if (!ASE && !OASE && |
| 9541 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 9542 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9543 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9544 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 9545 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9546 | // Add initializer for private variable. |
| 9547 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9548 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 9549 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 9550 | if (DeclareReductionRef.isUsable()) { |
| 9551 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 9552 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 9553 | if (DRD->getInitializer()) { |
| 9554 | Init = DRDRef; |
| 9555 | RHSVD->setInit(DRDRef); |
| 9556 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9557 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9558 | } else { |
| 9559 | switch (BOK) { |
| 9560 | case BO_Add: |
| 9561 | case BO_Xor: |
| 9562 | case BO_Or: |
| 9563 | case BO_LOr: |
| 9564 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 9565 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 9566 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 9567 | break; |
| 9568 | case BO_Mul: |
| 9569 | case BO_LAnd: |
| 9570 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 9571 | // '*' and '&&' reduction ops - initializer is '1'. |
| 9572 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9573 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9574 | break; |
| 9575 | case BO_And: { |
| 9576 | // '&' reduction op - initializer is '~0'. |
| 9577 | QualType OrigType = Type; |
| 9578 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 9579 | Type = ComplexTy->getElementType(); |
| 9580 | if (Type->isRealFloatingType()) { |
| 9581 | llvm::APFloat InitValue = |
| 9582 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 9583 | /*isIEEE=*/true); |
| 9584 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9585 | Type, ELoc); |
| 9586 | } else if (Type->isScalarType()) { |
| 9587 | auto Size = Context.getTypeSize(Type); |
| 9588 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 9589 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 9590 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9591 | } |
| 9592 | if (Init && OrigType->isAnyComplexType()) { |
| 9593 | // Init = 0xFFFF + 0xFFFFi; |
| 9594 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 9595 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 9596 | } |
| 9597 | Type = OrigType; |
| 9598 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9599 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9600 | case BO_LT: |
| 9601 | case BO_GT: { |
| 9602 | // 'min' reduction op - initializer is 'Largest representable number in |
| 9603 | // the reduction list item type'. |
| 9604 | // 'max' reduction op - initializer is 'Least representable number in |
| 9605 | // the reduction list item type'. |
| 9606 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 9607 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 9608 | auto Size = Context.getTypeSize(Type); |
| 9609 | QualType IntTy = |
| 9610 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 9611 | llvm::APInt InitValue = |
| 9612 | (BOK != BO_LT) |
| 9613 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 9614 | : llvm::APInt::getMinValue(Size) |
| 9615 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 9616 | : llvm::APInt::getMaxValue(Size); |
| 9617 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9618 | if (Type->isPointerType()) { |
| 9619 | // Cast to pointer type. |
| 9620 | auto CastExpr = BuildCStyleCastExpr( |
| 9621 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 9622 | SourceLocation(), Init); |
| 9623 | if (CastExpr.isInvalid()) |
| 9624 | continue; |
| 9625 | Init = CastExpr.get(); |
| 9626 | } |
| 9627 | } else if (Type->isRealFloatingType()) { |
| 9628 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 9629 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 9630 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9631 | Type, ELoc); |
| 9632 | } |
| 9633 | break; |
| 9634 | } |
| 9635 | case BO_PtrMemD: |
| 9636 | case BO_PtrMemI: |
| 9637 | case BO_MulAssign: |
| 9638 | case BO_Div: |
| 9639 | case BO_Rem: |
| 9640 | case BO_Sub: |
| 9641 | case BO_Shl: |
| 9642 | case BO_Shr: |
| 9643 | case BO_LE: |
| 9644 | case BO_GE: |
| 9645 | case BO_EQ: |
| 9646 | case BO_NE: |
| 9647 | case BO_AndAssign: |
| 9648 | case BO_XorAssign: |
| 9649 | case BO_OrAssign: |
| 9650 | case BO_Assign: |
| 9651 | case BO_AddAssign: |
| 9652 | case BO_SubAssign: |
| 9653 | case BO_DivAssign: |
| 9654 | case BO_RemAssign: |
| 9655 | case BO_ShlAssign: |
| 9656 | case BO_ShrAssign: |
| 9657 | case BO_Comma: |
| 9658 | llvm_unreachable("Unexpected reduction operation"); |
| 9659 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9660 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9661 | if (Init && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9662 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false, |
| 9663 | /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9664 | } else if (!Init) |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9665 | ActOnUninitializedDecl(RHSVD, /*TypeMayContainAuto=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9666 | if (RHSVD->isInvalidDecl()) |
| 9667 | continue; |
| 9668 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9669 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 9670 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9671 | bool IsDecl = |
| 9672 | !VD || |
| 9673 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9674 | Diag(D->getLocation(), |
| 9675 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9676 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9677 | continue; |
| 9678 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9679 | // Store initializer for single element in private copy. Will be used during |
| 9680 | // codegen. |
| 9681 | PrivateVD->setInit(RHSVD->getInit()); |
| 9682 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9683 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9684 | ExprResult ReductionOp; |
| 9685 | if (DeclareReductionRef.isUsable()) { |
| 9686 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 9687 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 9688 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 9689 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 9690 | if (!BasePath.empty()) { |
| 9691 | LHS = DefaultLvalueConversion(LHS.get()); |
| 9692 | RHS = DefaultLvalueConversion(RHS.get()); |
| 9693 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9694 | CK_UncheckedDerivedToBase, LHS.get(), |
| 9695 | &BasePath, LHS.get()->getValueKind()); |
| 9696 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9697 | CK_UncheckedDerivedToBase, RHS.get(), |
| 9698 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9699 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9700 | FunctionProtoType::ExtProtoInfo EPI; |
| 9701 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 9702 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 9703 | auto *OVE = new (Context) OpaqueValueExpr( |
| 9704 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 9705 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 9706 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 9707 | ReductionOp = new (Context) |
| 9708 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 9709 | } else { |
| 9710 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 9711 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 9712 | if (ReductionOp.isUsable()) { |
| 9713 | if (BOK != BO_LT && BOK != BO_GT) { |
| 9714 | ReductionOp = |
| 9715 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9716 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 9717 | } else { |
| 9718 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 9719 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 9720 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 9721 | ReductionOp = |
| 9722 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9723 | BO_Assign, LHSDRE, ConditionalOp); |
| 9724 | } |
| 9725 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 9726 | } |
| 9727 | if (ReductionOp.isInvalid()) |
| 9728 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9729 | } |
| 9730 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9731 | DeclRefExpr *Ref = nullptr; |
| 9732 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9733 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9734 | if (ASE || OASE) { |
| 9735 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 9736 | VarsExpr = |
| 9737 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 9738 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9739 | } else { |
| 9740 | VarsExpr = Ref = |
| 9741 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9742 | } |
| 9743 | if (!IsOpenMPCapturedDecl(D)) { |
| 9744 | ExprCaptures.push_back(Ref->getDecl()); |
| 9745 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9746 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9747 | if (!RefRes.isUsable()) |
| 9748 | continue; |
| 9749 | ExprResult PostUpdateRes = |
| 9750 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9751 | SimpleRefExpr, RefRes.get()); |
| 9752 | if (!PostUpdateRes.isUsable()) |
| 9753 | continue; |
| 9754 | ExprPostUpdates.push_back( |
| 9755 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9756 | } |
| 9757 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9758 | } |
| 9759 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 9760 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9761 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9762 | LHSs.push_back(LHSDRE); |
| 9763 | RHSs.push_back(RHSDRE); |
| 9764 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9765 | } |
| 9766 | |
| 9767 | if (Vars.empty()) |
| 9768 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9769 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9770 | return OMPReductionClause::Create( |
| 9771 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9772 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9773 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 9774 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9775 | } |
| 9776 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9777 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 9778 | SourceLocation LinLoc) { |
| 9779 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 9780 | LinKind == OMPC_LINEAR_unknown) { |
| 9781 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 9782 | return true; |
| 9783 | } |
| 9784 | return false; |
| 9785 | } |
| 9786 | |
| 9787 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 9788 | OpenMPLinearClauseKind LinKind, |
| 9789 | QualType Type) { |
| 9790 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 9791 | // A variable must not have an incomplete type or a reference type. |
| 9792 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 9793 | return true; |
| 9794 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 9795 | !Type->isReferenceType()) { |
| 9796 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 9797 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 9798 | return true; |
| 9799 | } |
| 9800 | Type = Type.getNonReferenceType(); |
| 9801 | |
| 9802 | // A list item must not be const-qualified. |
| 9803 | if (Type.isConstant(Context)) { |
| 9804 | Diag(ELoc, diag::err_omp_const_variable) |
| 9805 | << getOpenMPClauseName(OMPC_linear); |
| 9806 | if (D) { |
| 9807 | bool IsDecl = |
| 9808 | !VD || |
| 9809 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9810 | Diag(D->getLocation(), |
| 9811 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9812 | << D; |
| 9813 | } |
| 9814 | return true; |
| 9815 | } |
| 9816 | |
| 9817 | // A list item must be of integral or pointer type. |
| 9818 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 9819 | const auto *Ty = Type.getTypePtrOrNull(); |
| 9820 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 9821 | !Ty->isPointerType())) { |
| 9822 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 9823 | if (D) { |
| 9824 | bool IsDecl = |
| 9825 | !VD || |
| 9826 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9827 | Diag(D->getLocation(), |
| 9828 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9829 | << D; |
| 9830 | } |
| 9831 | return true; |
| 9832 | } |
| 9833 | return false; |
| 9834 | } |
| 9835 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9836 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 9837 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 9838 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 9839 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9840 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9841 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9842 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9843 | SmallVector<Decl *, 4> ExprCaptures; |
| 9844 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9845 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9846 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9847 | for (auto &RefExpr : VarList) { |
| 9848 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9849 | SourceLocation ELoc; |
| 9850 | SourceRange ERange; |
| 9851 | Expr *SimpleRefExpr = RefExpr; |
| 9852 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9853 | /*AllowArraySection=*/false); |
| 9854 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9855 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9856 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9857 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9858 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9859 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9860 | ValueDecl *D = Res.first; |
| 9861 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9862 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9863 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9864 | QualType Type = D->getType(); |
| 9865 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9866 | |
| 9867 | // OpenMP [2.14.3.7, linear clause] |
| 9868 | // A list-item cannot appear in more than one linear clause. |
| 9869 | // A list-item that appears in a linear clause cannot appear in any |
| 9870 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9871 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9872 | if (DVar.RefExpr) { |
| 9873 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9874 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9875 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9876 | continue; |
| 9877 | } |
| 9878 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9879 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9880 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9881 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9882 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9883 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9884 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9885 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9886 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9887 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9888 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9889 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9890 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9891 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9892 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 9893 | if (!IsOpenMPCapturedDecl(D)) { |
| 9894 | ExprCaptures.push_back(Ref->getDecl()); |
| 9895 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9896 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9897 | if (!RefRes.isUsable()) |
| 9898 | continue; |
| 9899 | ExprResult PostUpdateRes = |
| 9900 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9901 | SimpleRefExpr, RefRes.get()); |
| 9902 | if (!PostUpdateRes.isUsable()) |
| 9903 | continue; |
| 9904 | ExprPostUpdates.push_back( |
| 9905 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9906 | } |
| 9907 | } |
| 9908 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9909 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9910 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9911 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9912 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9913 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9914 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 9915 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9916 | |
| 9917 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9918 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9919 | ? RefExpr->IgnoreParens() |
| 9920 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9921 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9922 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9923 | } |
| 9924 | |
| 9925 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9926 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9927 | |
| 9928 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9929 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9930 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9931 | !Step->isInstantiationDependent() && |
| 9932 | !Step->containsUnexpandedParameterPack()) { |
| 9933 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9934 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9935 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9936 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9937 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9938 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9939 | // Build var to save the step value. |
| 9940 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9941 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9942 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9943 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9944 | ExprResult CalcStep = |
| 9945 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9946 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9947 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9948 | // Warn about zero linear step (it would be probably better specified as |
| 9949 | // making corresponding variables 'const'). |
| 9950 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9951 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9952 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9953 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9954 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9955 | if (!IsConstant && CalcStep.isUsable()) { |
| 9956 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9957 | // (This is not used if the number of iterations may be kfold-ed). |
| 9958 | CalcStepExpr = CalcStep.get(); |
| 9959 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9960 | } |
| 9961 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9962 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9963 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9964 | StepExpr, CalcStepExpr, |
| 9965 | buildPreInits(Context, ExprCaptures), |
| 9966 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9967 | } |
| 9968 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9969 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9970 | Expr *NumIterations, Sema &SemaRef, |
| 9971 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9972 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9973 | SmallVector<Expr *, 8> Updates; |
| 9974 | SmallVector<Expr *, 8> Finals; |
| 9975 | Expr *Step = Clause.getStep(); |
| 9976 | Expr *CalcStep = Clause.getCalcStep(); |
| 9977 | // OpenMP [2.14.3.7, linear clause] |
| 9978 | // If linear-step is not specified it is assumed to be 1. |
| 9979 | if (Step == nullptr) |
| 9980 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9981 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9982 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9983 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9984 | bool HasErrors = false; |
| 9985 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9986 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9987 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9988 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9989 | SourceLocation ELoc; |
| 9990 | SourceRange ERange; |
| 9991 | Expr *SimpleRefExpr = RefExpr; |
| 9992 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9993 | /*AllowArraySection=*/false); |
| 9994 | ValueDecl *D = Res.first; |
| 9995 | if (Res.second || !D) { |
| 9996 | Updates.push_back(nullptr); |
| 9997 | Finals.push_back(nullptr); |
| 9998 | HasErrors = true; |
| 9999 | continue; |
| 10000 | } |
| 10001 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 10002 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 10003 | ->getMemberDecl(); |
| 10004 | } |
| 10005 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 10006 | Expr *InitExpr = *CurInit; |
| 10007 | |
| 10008 | // Build privatized reference to the current linear var. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10009 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 10010 | Expr *CapturedRef; |
| 10011 | if (LinKind == OMPC_LINEAR_uval) |
| 10012 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 10013 | else |
| 10014 | CapturedRef = |
| 10015 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 10016 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 10017 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 10018 | |
| 10019 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 10020 | ExprResult Update; |
| 10021 | if (!Info.first) { |
| 10022 | Update = |
| 10023 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 10024 | InitExpr, IV, Step, /* Subtract */ false); |
| 10025 | } else |
| 10026 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 10027 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 10028 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 10029 | |
| 10030 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 10031 | ExprResult Final; |
| 10032 | if (!Info.first) { |
| 10033 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 10034 | InitExpr, NumIterations, Step, |
| 10035 | /* Subtract */ false); |
| 10036 | } else |
| 10037 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 10038 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 10039 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 10040 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 10041 | if (!Update.isUsable() || !Final.isUsable()) { |
| 10042 | Updates.push_back(nullptr); |
| 10043 | Finals.push_back(nullptr); |
| 10044 | HasErrors = true; |
| 10045 | } else { |
| 10046 | Updates.push_back(Update.get()); |
| 10047 | Finals.push_back(Final.get()); |
| 10048 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 10049 | ++CurInit; |
| 10050 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 10051 | } |
| 10052 | Clause.setUpdates(Updates); |
| 10053 | Clause.setFinals(Finals); |
| 10054 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 10055 | } |
| 10056 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10057 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 10058 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 10059 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 10060 | |
| 10061 | SmallVector<Expr *, 8> Vars; |
| 10062 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10063 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 10064 | SourceLocation ELoc; |
| 10065 | SourceRange ERange; |
| 10066 | Expr *SimpleRefExpr = RefExpr; |
| 10067 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 10068 | /*AllowArraySection=*/false); |
| 10069 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10070 | // It will be analyzed later. |
| 10071 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10072 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10073 | ValueDecl *D = Res.first; |
| 10074 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10075 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10076 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10077 | QualType QType = D->getType(); |
| 10078 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10079 | |
| 10080 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 10081 | // The type of list items appearing in the aligned clause must be |
| 10082 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10083 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10084 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10085 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10086 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10087 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10088 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10089 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10090 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10091 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10092 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10093 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10094 | continue; |
| 10095 | } |
| 10096 | |
| 10097 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 10098 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10099 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 10100 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10101 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 10102 | << getOpenMPClauseName(OMPC_aligned); |
| 10103 | continue; |
| 10104 | } |
| 10105 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 10106 | DeclRefExpr *Ref = nullptr; |
| 10107 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 10108 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 10109 | Vars.push_back(DefaultFunctionArrayConversion( |
| 10110 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 10111 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 10112 | } |
| 10113 | |
| 10114 | // OpenMP [2.8.1, simd construct, Description] |
| 10115 | // The parameter of the aligned clause, alignment, must be a constant |
| 10116 | // positive integer expression. |
| 10117 | // If no optional parameter is specified, implementation-defined default |
| 10118 | // alignments for SIMD instructions on the target platforms are assumed. |
| 10119 | if (Alignment != nullptr) { |
| 10120 | ExprResult AlignResult = |
| 10121 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 10122 | if (AlignResult.isInvalid()) |
| 10123 | return nullptr; |
| 10124 | Alignment = AlignResult.get(); |
| 10125 | } |
| 10126 | if (Vars.empty()) |
| 10127 | return nullptr; |
| 10128 | |
| 10129 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 10130 | EndLoc, Vars, Alignment); |
| 10131 | } |
| 10132 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10133 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 10134 | SourceLocation StartLoc, |
| 10135 | SourceLocation LParenLoc, |
| 10136 | SourceLocation EndLoc) { |
| 10137 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10138 | SmallVector<Expr *, 8> SrcExprs; |
| 10139 | SmallVector<Expr *, 8> DstExprs; |
| 10140 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10141 | for (auto &RefExpr : VarList) { |
| 10142 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 10143 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10144 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10145 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10146 | SrcExprs.push_back(nullptr); |
| 10147 | DstExprs.push_back(nullptr); |
| 10148 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10149 | continue; |
| 10150 | } |
| 10151 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10152 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10153 | // OpenMP [2.1, C/C++] |
| 10154 | // A list item is a variable name. |
| 10155 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 10156 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10157 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10158 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10159 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 10160 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10161 | continue; |
| 10162 | } |
| 10163 | |
| 10164 | Decl *D = DE->getDecl(); |
| 10165 | VarDecl *VD = cast<VarDecl>(D); |
| 10166 | |
| 10167 | QualType Type = VD->getType(); |
| 10168 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 10169 | // It will be analyzed later. |
| 10170 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10171 | SrcExprs.push_back(nullptr); |
| 10172 | DstExprs.push_back(nullptr); |
| 10173 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10174 | continue; |
| 10175 | } |
| 10176 | |
| 10177 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 10178 | // A list item that appears in a copyin clause must be threadprivate. |
| 10179 | if (!DSAStack->isThreadPrivate(VD)) { |
| 10180 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10181 | << getOpenMPClauseName(OMPC_copyin) |
| 10182 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10183 | continue; |
| 10184 | } |
| 10185 | |
| 10186 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 10187 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 10188 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10189 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10190 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 10191 | auto *SrcVD = |
| 10192 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 10193 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 10194 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10195 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 10196 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 10197 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 10198 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10199 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 10200 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10201 | // For arrays generate assignment operation for single element and replace |
| 10202 | // it by the original array element in CodeGen. |
| 10203 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 10204 | PseudoDstExpr, PseudoSrcExpr); |
| 10205 | if (AssignmentOp.isInvalid()) |
| 10206 | continue; |
| 10207 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 10208 | /*DiscardedValue=*/true); |
| 10209 | if (AssignmentOp.isInvalid()) |
| 10210 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10211 | |
| 10212 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 10213 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10214 | SrcExprs.push_back(PseudoSrcExpr); |
| 10215 | DstExprs.push_back(PseudoDstExpr); |
| 10216 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10217 | } |
| 10218 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 10219 | if (Vars.empty()) |
| 10220 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10221 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 10222 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 10223 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 10224 | } |
| 10225 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10226 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 10227 | SourceLocation StartLoc, |
| 10228 | SourceLocation LParenLoc, |
| 10229 | SourceLocation EndLoc) { |
| 10230 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10231 | SmallVector<Expr *, 8> SrcExprs; |
| 10232 | SmallVector<Expr *, 8> DstExprs; |
| 10233 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10234 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10235 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 10236 | SourceLocation ELoc; |
| 10237 | SourceRange ERange; |
| 10238 | Expr *SimpleRefExpr = RefExpr; |
| 10239 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 10240 | /*AllowArraySection=*/false); |
| 10241 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10242 | // It will be analyzed later. |
| 10243 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10244 | SrcExprs.push_back(nullptr); |
| 10245 | DstExprs.push_back(nullptr); |
| 10246 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10247 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10248 | ValueDecl *D = Res.first; |
| 10249 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10250 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10251 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10252 | QualType Type = D->getType(); |
| 10253 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10254 | |
| 10255 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 10256 | // A list item that appears in a copyprivate clause may not appear in a |
| 10257 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10258 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 10259 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10260 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 10261 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10262 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 10263 | << getOpenMPClauseName(DVar.CKind) |
| 10264 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10265 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10266 | continue; |
| 10267 | } |
| 10268 | |
| 10269 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 10270 | // All list items that appear in a copyprivate clause must be either |
| 10271 | // threadprivate or private in the enclosing context. |
| 10272 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10273 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10274 | if (DVar.CKind == OMPC_shared) { |
| 10275 | Diag(ELoc, diag::err_omp_required_access) |
| 10276 | << getOpenMPClauseName(OMPC_copyprivate) |
| 10277 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10278 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10279 | continue; |
| 10280 | } |
| 10281 | } |
| 10282 | } |
| 10283 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10284 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 10285 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10286 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10287 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 10288 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10289 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10290 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10291 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10292 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10293 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10294 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 10295 | continue; |
| 10296 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 10297 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10298 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 10299 | // A variable of class type (or array thereof) that appears in a |
| 10300 | // copyin clause requires an accessible, unambiguous copy assignment |
| 10301 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 10302 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 10303 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10304 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10305 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 10306 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 10307 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 10308 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10309 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 10310 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10311 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10312 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10313 | PseudoDstExpr, PseudoSrcExpr); |
| 10314 | if (AssignmentOp.isInvalid()) |
| 10315 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10316 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10317 | /*DiscardedValue=*/true); |
| 10318 | if (AssignmentOp.isInvalid()) |
| 10319 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10320 | |
| 10321 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 10322 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 10323 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 10324 | Vars.push_back( |
| 10325 | VD ? RefExpr->IgnoreParens() |
| 10326 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10327 | SrcExprs.push_back(PseudoSrcExpr); |
| 10328 | DstExprs.push_back(PseudoDstExpr); |
| 10329 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10330 | } |
| 10331 | |
| 10332 | if (Vars.empty()) |
| 10333 | return nullptr; |
| 10334 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 10335 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10336 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 10337 | } |
| 10338 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 10339 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 10340 | SourceLocation StartLoc, |
| 10341 | SourceLocation LParenLoc, |
| 10342 | SourceLocation EndLoc) { |
| 10343 | if (VarList.empty()) |
| 10344 | return nullptr; |
| 10345 | |
| 10346 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 10347 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 10348 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10349 | OMPClause * |
| 10350 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 10351 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 10352 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10353 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10354 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10355 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10356 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10357 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 10358 | return nullptr; |
| 10359 | } |
| 10360 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10361 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 10362 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10363 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10364 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 10365 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 10366 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 10367 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10368 | return nullptr; |
| 10369 | } |
| 10370 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10371 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10372 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 10373 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 10374 | if (DepKind == OMPC_DEPEND_sink) { |
| 10375 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 10376 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 10377 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10378 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10379 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10380 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 10381 | DSAStack->getParentOrderedRegionParam()) { |
| 10382 | for (auto &RefExpr : VarList) { |
| 10383 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10384 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10385 | // It will be analyzed later. |
| 10386 | Vars.push_back(RefExpr); |
| 10387 | continue; |
| 10388 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10389 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10390 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 10391 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 10392 | if (DepKind == OMPC_DEPEND_sink) { |
| 10393 | if (DepCounter >= TotalDepCount) { |
| 10394 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 10395 | continue; |
| 10396 | } |
| 10397 | ++DepCounter; |
| 10398 | // OpenMP [2.13.9, Summary] |
| 10399 | // depend(dependence-type : vec), where dependence-type is: |
| 10400 | // 'sink' and where vec is the iteration vector, which has the form: |
| 10401 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 10402 | // where n is the value specified by the ordered clause in the loop |
| 10403 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 10404 | // loop associated with the loop directive, and di is a constant |
| 10405 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10406 | if (CurContext->isDependentContext()) { |
| 10407 | // It will be analyzed later. |
| 10408 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10409 | continue; |
| 10410 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10411 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 10412 | OverloadedOperatorKind OOK = OO_None; |
| 10413 | SourceLocation OOLoc; |
| 10414 | Expr *LHS = SimpleExpr; |
| 10415 | Expr *RHS = nullptr; |
| 10416 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 10417 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 10418 | OOLoc = BO->getOperatorLoc(); |
| 10419 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 10420 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 10421 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 10422 | OOK = OCE->getOperator(); |
| 10423 | OOLoc = OCE->getOperatorLoc(); |
| 10424 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10425 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 10426 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 10427 | OOK = MCE->getMethodDecl() |
| 10428 | ->getNameInfo() |
| 10429 | .getName() |
| 10430 | .getCXXOverloadedOperator(); |
| 10431 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 10432 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 10433 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 10434 | } |
| 10435 | SourceLocation ELoc; |
| 10436 | SourceRange ERange; |
| 10437 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 10438 | /*AllowArraySection=*/false); |
| 10439 | if (Res.second) { |
| 10440 | // It will be analyzed later. |
| 10441 | Vars.push_back(RefExpr); |
| 10442 | } |
| 10443 | ValueDecl *D = Res.first; |
| 10444 | if (!D) |
| 10445 | continue; |
| 10446 | |
| 10447 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 10448 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 10449 | continue; |
| 10450 | } |
| 10451 | if (RHS) { |
| 10452 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 10453 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 10454 | if (RHSRes.isInvalid()) |
| 10455 | continue; |
| 10456 | } |
| 10457 | if (!CurContext->isDependentContext() && |
| 10458 | DSAStack->getParentOrderedRegionParam() && |
| 10459 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 10460 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10461 | << DSAStack->getParentLoopControlVariable( |
| 10462 | DepCounter.getZExtValue()); |
| 10463 | continue; |
| 10464 | } |
| 10465 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10466 | } else { |
| 10467 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 10468 | // A variable that is part of another variable (such as a field of a |
| 10469 | // structure) but is not an array element or an array section cannot |
| 10470 | // appear in a depend clause. |
| 10471 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 10472 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 10473 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 10474 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 10475 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10476 | (ASE && |
| 10477 | !ASE->getBase() |
| 10478 | ->getType() |
| 10479 | .getNonReferenceType() |
| 10480 | ->isPointerType() && |
| 10481 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10482 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 10483 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10484 | continue; |
| 10485 | } |
| 10486 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10487 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 10488 | } |
| 10489 | |
| 10490 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 10491 | TotalDepCount > VarList.size() && |
| 10492 | DSAStack->getParentOrderedRegionParam()) { |
| 10493 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10494 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 10495 | } |
| 10496 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 10497 | Vars.empty()) |
| 10498 | return nullptr; |
| 10499 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10500 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10501 | DepKind, DepLoc, ColonLoc, Vars); |
| 10502 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 10503 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 10504 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10505 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10506 | |
| 10507 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 10508 | SourceLocation LParenLoc, |
| 10509 | SourceLocation EndLoc) { |
| 10510 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10511 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10512 | // OpenMP [2.9.1, Restrictions] |
| 10513 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10514 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 10515 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10516 | return nullptr; |
| 10517 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10518 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10519 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10520 | |
| 10521 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 10522 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 10523 | if (!RD || RD->isInvalidDecl()) |
| 10524 | return true; |
| 10525 | |
Alexey Bataev | c9bd03d | 2015-12-17 06:55:08 +0000 | [diff] [blame] | 10526 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(RD)) |
| 10527 | if (auto *CTD = CTSD->getSpecializedTemplate()) |
| 10528 | RD = CTD->getTemplatedDecl(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10529 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 10530 | if (RD->isDynamicClass()) { |
| 10531 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10532 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 10533 | return false; |
| 10534 | } |
| 10535 | auto *DC = RD; |
| 10536 | bool IsCorrect = true; |
| 10537 | for (auto *I : DC->decls()) { |
| 10538 | if (I) { |
| 10539 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 10540 | if (MD->isStatic()) { |
| 10541 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10542 | SemaRef.Diag(MD->getLocation(), |
| 10543 | diag::note_omp_static_member_in_target); |
| 10544 | IsCorrect = false; |
| 10545 | } |
| 10546 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 10547 | if (VD->isStaticDataMember()) { |
| 10548 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10549 | SemaRef.Diag(VD->getLocation(), |
| 10550 | diag::note_omp_static_member_in_target); |
| 10551 | IsCorrect = false; |
| 10552 | } |
| 10553 | } |
| 10554 | } |
| 10555 | } |
| 10556 | |
| 10557 | for (auto &I : RD->bases()) { |
| 10558 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 10559 | I.getType()->getAsCXXRecordDecl())) |
| 10560 | IsCorrect = false; |
| 10561 | } |
| 10562 | return IsCorrect; |
| 10563 | } |
| 10564 | |
| 10565 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 10566 | DSAStackTy *Stack, QualType QTy) { |
| 10567 | NamedDecl *ND; |
| 10568 | if (QTy->isIncompleteType(&ND)) { |
| 10569 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 10570 | return false; |
| 10571 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10572 | if (!RD->isInvalidDecl() && !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10573 | return false; |
| 10574 | } |
| 10575 | return true; |
| 10576 | } |
| 10577 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10578 | /// \brief Return true if it can be proven that the provided array expression |
| 10579 | /// (array section or array subscript) does NOT specify the whole size of the |
| 10580 | /// array whose base type is \a BaseQTy. |
| 10581 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 10582 | const Expr *E, |
| 10583 | QualType BaseQTy) { |
| 10584 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10585 | |
| 10586 | // If this is an array subscript, it refers to the whole size if the size of |
| 10587 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 10588 | // format of an array subscript if no colon is used. |
| 10589 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 10590 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10591 | return ATy->getSize().getSExtValue() != 1; |
| 10592 | // Size can't be evaluated statically. |
| 10593 | return false; |
| 10594 | } |
| 10595 | |
| 10596 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10597 | auto *LowerBound = OASE->getLowerBound(); |
| 10598 | auto *Length = OASE->getLength(); |
| 10599 | |
| 10600 | // If there is a lower bound that does not evaluates to zero, we are not |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10601 | // covering the whole dimension. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10602 | if (LowerBound) { |
| 10603 | llvm::APSInt ConstLowerBound; |
| 10604 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 10605 | return false; // Can't get the integer value as a constant. |
| 10606 | if (ConstLowerBound.getSExtValue()) |
| 10607 | return true; |
| 10608 | } |
| 10609 | |
| 10610 | // If we don't have a length we covering the whole dimension. |
| 10611 | if (!Length) |
| 10612 | return false; |
| 10613 | |
| 10614 | // If the base is a pointer, we don't have a way to get the size of the |
| 10615 | // pointee. |
| 10616 | if (BaseQTy->isPointerType()) |
| 10617 | return false; |
| 10618 | |
| 10619 | // We can only check if the length is the same as the size of the dimension |
| 10620 | // if we have a constant array. |
| 10621 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 10622 | if (!CATy) |
| 10623 | return false; |
| 10624 | |
| 10625 | llvm::APSInt ConstLength; |
| 10626 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10627 | return false; // Can't get the integer value as a constant. |
| 10628 | |
| 10629 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 10630 | } |
| 10631 | |
| 10632 | // Return true if it can be proven that the provided array expression (array |
| 10633 | // section or array subscript) does NOT specify a single element of the array |
| 10634 | // whose base type is \a BaseQTy. |
| 10635 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10636 | const Expr *E, |
| 10637 | QualType BaseQTy) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10638 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10639 | |
| 10640 | // An array subscript always refer to a single element. Also, an array section |
| 10641 | // assumes the format of an array subscript if no colon is used. |
| 10642 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 10643 | return false; |
| 10644 | |
| 10645 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10646 | auto *Length = OASE->getLength(); |
| 10647 | |
| 10648 | // If we don't have a length we have to check if the array has unitary size |
| 10649 | // for this dimension. Also, we should always expect a length if the base type |
| 10650 | // is pointer. |
| 10651 | if (!Length) { |
| 10652 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10653 | return ATy->getSize().getSExtValue() != 1; |
| 10654 | // We cannot assume anything. |
| 10655 | return false; |
| 10656 | } |
| 10657 | |
| 10658 | // Check if the length evaluates to 1. |
| 10659 | llvm::APSInt ConstLength; |
| 10660 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10661 | return false; // Can't get the integer value as a constant. |
| 10662 | |
| 10663 | return ConstLength.getSExtValue() != 1; |
| 10664 | } |
| 10665 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10666 | // Return the expression of the base of the mappable expression or null if it |
| 10667 | // cannot be determined and do all the necessary checks to see if the expression |
| 10668 | // 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] | 10669 | // components of the expression. |
| 10670 | static Expr *CheckMapClauseExpressionBase( |
| 10671 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10672 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 10673 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10674 | SourceLocation ELoc = E->getExprLoc(); |
| 10675 | SourceRange ERange = E->getSourceRange(); |
| 10676 | |
| 10677 | // The base of elements of list in a map clause have to be either: |
| 10678 | // - a reference to variable or field. |
| 10679 | // - a member expression. |
| 10680 | // - an array expression. |
| 10681 | // |
| 10682 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 10683 | // reference to 'r'. |
| 10684 | // |
| 10685 | // If we have: |
| 10686 | // |
| 10687 | // struct SS { |
| 10688 | // Bla S; |
| 10689 | // foo() { |
| 10690 | // #pragma omp target map (S.Arr[:12]); |
| 10691 | // } |
| 10692 | // } |
| 10693 | // |
| 10694 | // We want to retrieve the member expression 'this->S'; |
| 10695 | |
| 10696 | Expr *RelevantExpr = nullptr; |
| 10697 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10698 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 10699 | // If a list item is an array section, it must specify contiguous storage. |
| 10700 | // |
| 10701 | // For this restriction it is sufficient that we make sure only references |
| 10702 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10703 | // exist except in the rightmost expression (unless they cover the whole |
| 10704 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10705 | // |
| 10706 | // r.ArrS[3:5].Arr[6:7] |
| 10707 | // |
| 10708 | // r.ArrS[3:5].x |
| 10709 | // |
| 10710 | // but these would be valid: |
| 10711 | // r.ArrS[3].Arr[6:7] |
| 10712 | // |
| 10713 | // r.ArrS[3].x |
| 10714 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10715 | bool AllowUnitySizeArraySection = true; |
| 10716 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10717 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 10718 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10719 | E = E->IgnoreParenImpCasts(); |
| 10720 | |
| 10721 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 10722 | if (!isa<VarDecl>(CurE->getDecl())) |
| 10723 | break; |
| 10724 | |
| 10725 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10726 | |
| 10727 | // If we got a reference to a declaration, we should not expect any array |
| 10728 | // section before that. |
| 10729 | AllowUnitySizeArraySection = false; |
| 10730 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10731 | |
| 10732 | // Record the component. |
| 10733 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 10734 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10735 | continue; |
| 10736 | } |
| 10737 | |
| 10738 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 10739 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 10740 | |
| 10741 | if (isa<CXXThisExpr>(BaseE)) |
| 10742 | // We found a base expression: this->Val. |
| 10743 | RelevantExpr = CurE; |
| 10744 | else |
| 10745 | E = BaseE; |
| 10746 | |
| 10747 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 10748 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 10749 | << CurE->getSourceRange(); |
| 10750 | break; |
| 10751 | } |
| 10752 | |
| 10753 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 10754 | |
| 10755 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 10756 | // A bit-field cannot appear in a map clause. |
| 10757 | // |
| 10758 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10759 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 10760 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10761 | break; |
| 10762 | } |
| 10763 | |
| 10764 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10765 | // If the type of a list item is a reference to a type T then the type |
| 10766 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10767 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10768 | |
| 10769 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 10770 | // A list item cannot be a variable that is a member of a structure with |
| 10771 | // a union type. |
| 10772 | // |
| 10773 | if (auto *RT = CurType->getAs<RecordType>()) |
| 10774 | if (RT->isUnionType()) { |
| 10775 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 10776 | << CurE->getSourceRange(); |
| 10777 | break; |
| 10778 | } |
| 10779 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10780 | // If we got a member expression, we should not expect any array section |
| 10781 | // before that: |
| 10782 | // |
| 10783 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 10784 | // If a list item is an element of a structure, only the rightmost symbol |
| 10785 | // of the variable reference can be an array section. |
| 10786 | // |
| 10787 | AllowUnitySizeArraySection = false; |
| 10788 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10789 | |
| 10790 | // Record the component. |
| 10791 | CurComponents.push_back( |
| 10792 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10793 | continue; |
| 10794 | } |
| 10795 | |
| 10796 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 10797 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10798 | |
| 10799 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 10800 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10801 | << 0 << CurE->getSourceRange(); |
| 10802 | break; |
| 10803 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10804 | |
| 10805 | // If we got an array subscript that express the whole dimension we |
| 10806 | // can have any array expressions before. If it only expressing part of |
| 10807 | // the dimension, we can only have unitary-size array expressions. |
| 10808 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 10809 | E->getType())) |
| 10810 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10811 | |
| 10812 | // Record the component - we don't have any declaration associated. |
| 10813 | CurComponents.push_back( |
| 10814 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10815 | continue; |
| 10816 | } |
| 10817 | |
| 10818 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10819 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10820 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10821 | auto CurType = |
| 10822 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10823 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10824 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10825 | // If the type of a list item is a reference to a type T then the type |
| 10826 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10827 | if (CurType->isReferenceType()) |
| 10828 | CurType = CurType->getPointeeType(); |
| 10829 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10830 | bool IsPointer = CurType->isAnyPointerType(); |
| 10831 | |
| 10832 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10833 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10834 | << 0 << CurE->getSourceRange(); |
| 10835 | break; |
| 10836 | } |
| 10837 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10838 | bool NotWhole = |
| 10839 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 10840 | bool NotUnity = |
| 10841 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 10842 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10843 | if (AllowWholeSizeArraySection) { |
| 10844 | // Any array section is currently allowed. Allowing a whole size array |
| 10845 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10846 | // |
| 10847 | // If this array section refers to the whole dimension we can still |
| 10848 | // accept other array sections before this one, except if the base is a |
| 10849 | // pointer. Otherwise, only unitary sections are accepted. |
| 10850 | if (NotWhole || IsPointer) |
| 10851 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10852 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10853 | // A unity or whole array section is not allowed and that is not |
| 10854 | // compatible with the properties of the current array section. |
| 10855 | SemaRef.Diag( |
| 10856 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 10857 | << CurE->getSourceRange(); |
| 10858 | break; |
| 10859 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10860 | |
| 10861 | // Record the component - we don't have any declaration associated. |
| 10862 | CurComponents.push_back( |
| 10863 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10864 | continue; |
| 10865 | } |
| 10866 | |
| 10867 | // If nothing else worked, this is not a valid map clause expression. |
| 10868 | SemaRef.Diag(ELoc, |
| 10869 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 10870 | << ERange; |
| 10871 | break; |
| 10872 | } |
| 10873 | |
| 10874 | return RelevantExpr; |
| 10875 | } |
| 10876 | |
| 10877 | // Return true if expression E associated with value VD has conflicts with other |
| 10878 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10879 | static bool CheckMapConflicts( |
| 10880 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 10881 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10882 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 10883 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10884 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10885 | SourceLocation ELoc = E->getExprLoc(); |
| 10886 | SourceRange ERange = E->getSourceRange(); |
| 10887 | |
| 10888 | // In order to easily check the conflicts we need to match each component of |
| 10889 | // the expression under test with the components of the expressions that are |
| 10890 | // already in the stack. |
| 10891 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10892 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10893 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10894 | "Map clause expression with unexpected base!"); |
| 10895 | |
| 10896 | // Variables to help detecting enclosing problems in data environment nests. |
| 10897 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10898 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10899 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10900 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 10901 | VD, CurrentRegionOnly, |
| 10902 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10903 | StackComponents, |
| 10904 | OpenMPClauseKind) -> bool { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10905 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10906 | assert(!StackComponents.empty() && |
| 10907 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10908 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10909 | "Map clause expression with unexpected base!"); |
| 10910 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10911 | // The whole expression in the stack. |
| 10912 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10913 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10914 | // Expressions must start from the same base. Here we detect at which |
| 10915 | // point both expressions diverge from each other and see if we can |
| 10916 | // detect if the memory referred to both expressions is contiguous and |
| 10917 | // do not overlap. |
| 10918 | auto CI = CurComponents.rbegin(); |
| 10919 | auto CE = CurComponents.rend(); |
| 10920 | auto SI = StackComponents.rbegin(); |
| 10921 | auto SE = StackComponents.rend(); |
| 10922 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10923 | |
| 10924 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10925 | // At most one list item can be an array item derived from a given |
| 10926 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10927 | if (CurrentRegionOnly && |
| 10928 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10929 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10930 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10931 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10932 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10933 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10934 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10935 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10936 | diag::note_used_here) |
| 10937 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10938 | return true; |
| 10939 | } |
| 10940 | |
| 10941 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10942 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10943 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10944 | break; |
| 10945 | |
| 10946 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10947 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10948 | break; |
| 10949 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10950 | // Check if the extra components of the expressions in the enclosing |
| 10951 | // data environment are redundant for the current base declaration. |
| 10952 | // If they are, the maps completely overlap, which is legal. |
| 10953 | for (; SI != SE; ++SI) { |
| 10954 | QualType Type; |
| 10955 | if (auto *ASE = |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10956 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10957 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10958 | } else if (auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| 10959 | SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10960 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10961 | Type = |
| 10962 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10963 | } |
| 10964 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10965 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10966 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10967 | break; |
| 10968 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10969 | |
| 10970 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10971 | // List items of map clauses in the same construct must not share |
| 10972 | // original storage. |
| 10973 | // |
| 10974 | // If the expressions are exactly the same or one is a subset of the |
| 10975 | // other, it means they are sharing storage. |
| 10976 | if (CI == CE && SI == SE) { |
| 10977 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10978 | if (CKind == OMPC_map) |
| 10979 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10980 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10981 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10982 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10983 | << ERange; |
| 10984 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10985 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10986 | << RE->getSourceRange(); |
| 10987 | return true; |
| 10988 | } else { |
| 10989 | // If we find the same expression in the enclosing data environment, |
| 10990 | // that is legal. |
| 10991 | IsEnclosedByDataEnvironmentExpr = true; |
| 10992 | return false; |
| 10993 | } |
| 10994 | } |
| 10995 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10996 | QualType DerivedType = |
| 10997 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10998 | SourceLocation DerivedLoc = |
| 10999 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11000 | |
| 11001 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 11002 | // If the type of a list item is a reference to a type T then the type |
| 11003 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11004 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11005 | |
| 11006 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 11007 | // A variable for which the type is pointer and an array section |
| 11008 | // derived from that variable must not appear as list items of map |
| 11009 | // clauses of the same construct. |
| 11010 | // |
| 11011 | // Also, cover one of the cases in: |
| 11012 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 11013 | // If any part of the original storage of a list item has corresponding |
| 11014 | // storage in the device data environment, all of the original storage |
| 11015 | // must have corresponding storage in the device data environment. |
| 11016 | // |
| 11017 | if (DerivedType->isAnyPointerType()) { |
| 11018 | if (CI == CE || SI == SE) { |
| 11019 | SemaRef.Diag( |
| 11020 | DerivedLoc, |
| 11021 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 11022 | << DerivedLoc; |
| 11023 | } else { |
| 11024 | assert(CI != CE && SI != SE); |
| 11025 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 11026 | << DerivedLoc; |
| 11027 | } |
| 11028 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 11029 | << RE->getSourceRange(); |
| 11030 | return true; |
| 11031 | } |
| 11032 | |
| 11033 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 11034 | // List items of map clauses in the same construct must not share |
| 11035 | // original storage. |
| 11036 | // |
| 11037 | // An expression is a subset of the other. |
| 11038 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11039 | if (CKind == OMPC_map) |
| 11040 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 11041 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11042 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11043 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 11044 | << ERange; |
| 11045 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11046 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 11047 | << RE->getSourceRange(); |
| 11048 | return true; |
| 11049 | } |
| 11050 | |
| 11051 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11052 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11053 | if (!CurrentRegionOnly && SI != SE) |
| 11054 | EnclosingExpr = RE; |
| 11055 | |
| 11056 | // The current expression is a subset of the expression in the data |
| 11057 | // environment. |
| 11058 | IsEnclosedByDataEnvironmentExpr |= |
| 11059 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 11060 | |
| 11061 | return false; |
| 11062 | }); |
| 11063 | |
| 11064 | if (CurrentRegionOnly) |
| 11065 | return FoundError; |
| 11066 | |
| 11067 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 11068 | // If any part of the original storage of a list item has corresponding |
| 11069 | // storage in the device data environment, all of the original storage must |
| 11070 | // have corresponding storage in the device data environment. |
| 11071 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 11072 | // If a list item is an element of a structure, and a different element of |
| 11073 | // the structure has a corresponding list item in the device data environment |
| 11074 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11075 | // 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] | 11076 | // data environment prior to the task encountering the construct. |
| 11077 | // |
| 11078 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 11079 | SemaRef.Diag(ELoc, |
| 11080 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 11081 | << ERange; |
| 11082 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 11083 | << EnclosingExpr->getSourceRange(); |
| 11084 | return true; |
| 11085 | } |
| 11086 | |
| 11087 | return FoundError; |
| 11088 | } |
| 11089 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11090 | namespace { |
| 11091 | // Utility struct that gathers all the related lists associated with a mappable |
| 11092 | // expression. |
| 11093 | struct MappableVarListInfo final { |
| 11094 | // The list of expressions. |
| 11095 | ArrayRef<Expr *> VarList; |
| 11096 | // The list of processed expressions. |
| 11097 | SmallVector<Expr *, 16> ProcessedVarList; |
| 11098 | // The mappble components for each expression. |
| 11099 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 11100 | // The base declaration of the variable. |
| 11101 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 11102 | |
| 11103 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 11104 | // We have a list of components and base declarations for each entry in the |
| 11105 | // variable list. |
| 11106 | VarComponents.reserve(VarList.size()); |
| 11107 | VarBaseDeclarations.reserve(VarList.size()); |
| 11108 | } |
| 11109 | }; |
| 11110 | } |
| 11111 | |
| 11112 | // Check the validity of the provided variable list for the provided clause kind |
| 11113 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 11114 | // components and variables are extracted and used to fill \a Vars, |
| 11115 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 11116 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 11117 | static void |
| 11118 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 11119 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 11120 | SourceLocation StartLoc, |
| 11121 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 11122 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11123 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 11124 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11125 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11126 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11127 | // Keep track of the mappable components and base declarations in this clause. |
| 11128 | // Each entry in the list is going to have a list of components associated. We |
| 11129 | // record each set of the components so that we can build the clause later on. |
| 11130 | // In the end we should have the same amount of declarations and component |
| 11131 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11132 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11133 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11134 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11135 | SourceLocation ELoc = RE->getExprLoc(); |
| 11136 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11137 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 11138 | |
| 11139 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 11140 | VE->isInstantiationDependent() || |
| 11141 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11142 | // We can only analyze this information once the missing information is |
| 11143 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11144 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11145 | continue; |
| 11146 | } |
| 11147 | |
| 11148 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11149 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11150 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11151 | SemaRef.Diag(ELoc, |
| 11152 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11153 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11154 | continue; |
| 11155 | } |
| 11156 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11157 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 11158 | ValueDecl *CurDeclaration = nullptr; |
| 11159 | |
| 11160 | // Obtain the array or member expression bases if required. Also, fill the |
| 11161 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11162 | auto *BE = |
| 11163 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11164 | if (!BE) |
| 11165 | continue; |
| 11166 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11167 | assert(!CurComponents.empty() && |
| 11168 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11169 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11170 | // For the following checks, we rely on the base declaration which is |
| 11171 | // expected to be associated with the last component. The declaration is |
| 11172 | // expected to be a variable or a field (if 'this' is being mapped). |
| 11173 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 11174 | assert(CurDeclaration && "Null decl on map clause."); |
| 11175 | assert( |
| 11176 | CurDeclaration->isCanonicalDecl() && |
| 11177 | "Expecting components to have associated only canonical declarations."); |
| 11178 | |
| 11179 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 11180 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11181 | |
| 11182 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 11183 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11184 | |
| 11185 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11186 | // threadprivate variables cannot appear in a map clause. |
| 11187 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 11188 | // threadprivate variables cannot appear in a from clause. |
| 11189 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 11190 | auto DVar = DSAS->getTopDSA(VD, false); |
| 11191 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 11192 | << getOpenMPClauseName(CKind); |
| 11193 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11194 | continue; |
| 11195 | } |
| 11196 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11197 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 11198 | // A list item cannot appear in both a map clause and a data-sharing |
| 11199 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11200 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11201 | // Check conflicts with other map clause expressions. We check the conflicts |
| 11202 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11203 | // environment, because the restrictions are different. We only have to |
| 11204 | // check conflicts across regions for the map clauses. |
| 11205 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 11206 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11207 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11208 | if (CKind == OMPC_map && |
| 11209 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 11210 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11211 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11212 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11213 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11214 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 11215 | // If the type of a list item is a reference to a type T then the type will |
| 11216 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11217 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11218 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11219 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 11220 | // 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] | 11221 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11222 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11223 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 11224 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11225 | continue; |
| 11226 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11227 | if (CKind == OMPC_map) { |
| 11228 | // target enter data |
| 11229 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 11230 | // A map-type must be specified in all map clauses and must be either |
| 11231 | // to or alloc. |
| 11232 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 11233 | if (DKind == OMPD_target_enter_data && |
| 11234 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 11235 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 11236 | << (IsMapTypeImplicit ? 1 : 0) |
| 11237 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 11238 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 11239 | continue; |
| 11240 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11241 | |
| 11242 | // target exit_data |
| 11243 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 11244 | // A map-type must be specified in all map clauses and must be either |
| 11245 | // from, release, or delete. |
| 11246 | if (DKind == OMPD_target_exit_data && |
| 11247 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 11248 | MapType == OMPC_MAP_delete)) { |
| 11249 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 11250 | << (IsMapTypeImplicit ? 1 : 0) |
| 11251 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 11252 | << getOpenMPDirectiveName(DKind); |
| 11253 | continue; |
| 11254 | } |
| 11255 | |
| 11256 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 11257 | // A list item cannot appear in both a map clause and a data-sharing |
| 11258 | // attribute clause on the same construct |
| 11259 | if (DKind == OMPD_target && VD) { |
| 11260 | auto DVar = DSAS->getTopDSA(VD, false); |
| 11261 | if (isOpenMPPrivate(DVar.CKind)) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11262 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11263 | << getOpenMPClauseName(DVar.CKind) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11264 | << getOpenMPClauseName(OMPC_map) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11265 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 11266 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 11267 | continue; |
| 11268 | } |
| 11269 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 11270 | } |
| 11271 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11272 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11273 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11274 | |
| 11275 | // Store the components in the stack so that they can be used to check |
| 11276 | // against other clauses later on. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11277 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 11278 | /*WhereFoundClauseKind=*/OMPC_map); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 11279 | |
| 11280 | // Save the components and declaration to create the clause. For purposes of |
| 11281 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 11282 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11283 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11284 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 11285 | CurComponents.end()); |
| 11286 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 11287 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11288 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11289 | } |
| 11290 | |
| 11291 | OMPClause * |
| 11292 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 11293 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 11294 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 11295 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 11296 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 11297 | MappableVarListInfo MVLI(VarList); |
| 11298 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 11299 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11300 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 11301 | // We need to produce a map clause even if we don't have variables so that |
| 11302 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11303 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11304 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11305 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 11306 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 11307 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11308 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11309 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 11310 | TypeResult ParsedType) { |
| 11311 | assert(ParsedType.isUsable()); |
| 11312 | |
| 11313 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 11314 | if (ReductionType.isNull()) |
| 11315 | return QualType(); |
| 11316 | |
| 11317 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 11318 | // A type name in a declare reduction directive cannot be a function type, an |
| 11319 | // array type, a reference type, or a type qualified with const, volatile or |
| 11320 | // restrict. |
| 11321 | if (ReductionType.hasQualifiers()) { |
| 11322 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 11323 | return QualType(); |
| 11324 | } |
| 11325 | |
| 11326 | if (ReductionType->isFunctionType()) { |
| 11327 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 11328 | return QualType(); |
| 11329 | } |
| 11330 | if (ReductionType->isReferenceType()) { |
| 11331 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 11332 | return QualType(); |
| 11333 | } |
| 11334 | if (ReductionType->isArrayType()) { |
| 11335 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 11336 | return QualType(); |
| 11337 | } |
| 11338 | return ReductionType; |
| 11339 | } |
| 11340 | |
| 11341 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 11342 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 11343 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 11344 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 11345 | SmallVector<Decl *, 8> Decls; |
| 11346 | Decls.reserve(ReductionTypes.size()); |
| 11347 | |
| 11348 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 11349 | ForRedeclaration); |
| 11350 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 11351 | // A reduction-identifier may not be re-declared in the current scope for the |
| 11352 | // same type or for a type that is compatible according to the base language |
| 11353 | // rules. |
| 11354 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 11355 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 11356 | bool InCompoundScope = true; |
| 11357 | if (S != nullptr) { |
| 11358 | // Find previous declaration with the same name not referenced in other |
| 11359 | // declarations. |
| 11360 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 11361 | InCompoundScope = |
| 11362 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 11363 | LookupName(Lookup, S); |
| 11364 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 11365 | /*AllowInlineNamespace=*/false); |
| 11366 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 11367 | auto Filter = Lookup.makeFilter(); |
| 11368 | while (Filter.hasNext()) { |
| 11369 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 11370 | if (InCompoundScope) { |
| 11371 | auto I = UsedAsPrevious.find(PrevDecl); |
| 11372 | if (I == UsedAsPrevious.end()) |
| 11373 | UsedAsPrevious[PrevDecl] = false; |
| 11374 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 11375 | UsedAsPrevious[D] = true; |
| 11376 | } |
| 11377 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 11378 | PrevDecl->getLocation(); |
| 11379 | } |
| 11380 | Filter.done(); |
| 11381 | if (InCompoundScope) { |
| 11382 | for (auto &PrevData : UsedAsPrevious) { |
| 11383 | if (!PrevData.second) { |
| 11384 | PrevDRD = PrevData.first; |
| 11385 | break; |
| 11386 | } |
| 11387 | } |
| 11388 | } |
| 11389 | } else if (PrevDeclInScope != nullptr) { |
| 11390 | auto *PrevDRDInScope = PrevDRD = |
| 11391 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 11392 | do { |
| 11393 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 11394 | PrevDRDInScope->getLocation(); |
| 11395 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 11396 | } while (PrevDRDInScope != nullptr); |
| 11397 | } |
| 11398 | for (auto &TyData : ReductionTypes) { |
| 11399 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 11400 | bool Invalid = false; |
| 11401 | if (I != PreviousRedeclTypes.end()) { |
| 11402 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 11403 | << TyData.first; |
| 11404 | Diag(I->second, diag::note_previous_definition); |
| 11405 | Invalid = true; |
| 11406 | } |
| 11407 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 11408 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 11409 | Name, TyData.first, PrevDRD); |
| 11410 | DC->addDecl(DRD); |
| 11411 | DRD->setAccess(AS); |
| 11412 | Decls.push_back(DRD); |
| 11413 | if (Invalid) |
| 11414 | DRD->setInvalidDecl(); |
| 11415 | else |
| 11416 | PrevDRD = DRD; |
| 11417 | } |
| 11418 | |
| 11419 | return DeclGroupPtrTy::make( |
| 11420 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 11421 | } |
| 11422 | |
| 11423 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 11424 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11425 | |
| 11426 | // Enter new function scope. |
| 11427 | PushFunctionScope(); |
| 11428 | getCurFunction()->setHasBranchProtectedScope(); |
| 11429 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 11430 | |
| 11431 | if (S != nullptr) |
| 11432 | PushDeclContext(S, DRD); |
| 11433 | else |
| 11434 | CurContext = DRD; |
| 11435 | |
| 11436 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 11437 | |
| 11438 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11439 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 11440 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 11441 | // uses semantics of argument handles by value, but it should be passed by |
| 11442 | // reference. C lang does not support references, so pass all parameters as |
| 11443 | // pointers. |
| 11444 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11445 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11446 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11447 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 11448 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 11449 | // uses semantics of argument handles by value, but it should be passed by |
| 11450 | // reference. C lang does not support references, so pass all parameters as |
| 11451 | // pointers. |
| 11452 | // Create 'T omp_out;' variable. |
| 11453 | auto *OmpOutParm = |
| 11454 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 11455 | if (S != nullptr) { |
| 11456 | PushOnScopeChains(OmpInParm, S); |
| 11457 | PushOnScopeChains(OmpOutParm, S); |
| 11458 | } else { |
| 11459 | DRD->addDecl(OmpInParm); |
| 11460 | DRD->addDecl(OmpOutParm); |
| 11461 | } |
| 11462 | } |
| 11463 | |
| 11464 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 11465 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11466 | DiscardCleanupsInEvaluationContext(); |
| 11467 | PopExpressionEvaluationContext(); |
| 11468 | |
| 11469 | PopDeclContext(); |
| 11470 | PopFunctionScopeInfo(); |
| 11471 | |
| 11472 | if (Combiner != nullptr) |
| 11473 | DRD->setCombiner(Combiner); |
| 11474 | else |
| 11475 | DRD->setInvalidDecl(); |
| 11476 | } |
| 11477 | |
| 11478 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 11479 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11480 | |
| 11481 | // Enter new function scope. |
| 11482 | PushFunctionScope(); |
| 11483 | getCurFunction()->setHasBranchProtectedScope(); |
| 11484 | |
| 11485 | if (S != nullptr) |
| 11486 | PushDeclContext(S, DRD); |
| 11487 | else |
| 11488 | CurContext = DRD; |
| 11489 | |
| 11490 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 11491 | |
| 11492 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11493 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 11494 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 11495 | // uses semantics of argument handles by value, but it should be passed by |
| 11496 | // reference. C lang does not support references, so pass all parameters as |
| 11497 | // pointers. |
| 11498 | // Create 'T omp_priv;' variable. |
| 11499 | auto *OmpPrivParm = |
| 11500 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11501 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 11502 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 11503 | // uses semantics of argument handles by value, but it should be passed by |
| 11504 | // reference. C lang does not support references, so pass all parameters as |
| 11505 | // pointers. |
| 11506 | // Create 'T omp_orig;' variable. |
| 11507 | auto *OmpOrigParm = |
| 11508 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11509 | if (S != nullptr) { |
| 11510 | PushOnScopeChains(OmpPrivParm, S); |
| 11511 | PushOnScopeChains(OmpOrigParm, S); |
| 11512 | } else { |
| 11513 | DRD->addDecl(OmpPrivParm); |
| 11514 | DRD->addDecl(OmpOrigParm); |
| 11515 | } |
| 11516 | } |
| 11517 | |
| 11518 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 11519 | Expr *Initializer) { |
| 11520 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11521 | DiscardCleanupsInEvaluationContext(); |
| 11522 | PopExpressionEvaluationContext(); |
| 11523 | |
| 11524 | PopDeclContext(); |
| 11525 | PopFunctionScopeInfo(); |
| 11526 | |
| 11527 | if (Initializer != nullptr) |
| 11528 | DRD->setInitializer(Initializer); |
| 11529 | else |
| 11530 | DRD->setInvalidDecl(); |
| 11531 | } |
| 11532 | |
| 11533 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11534 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 11535 | for (auto *D : DeclReductions.get()) { |
| 11536 | if (IsValid) { |
| 11537 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11538 | if (S != nullptr) |
| 11539 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 11540 | } else |
| 11541 | D->setInvalidDecl(); |
| 11542 | } |
| 11543 | return DeclReductions; |
| 11544 | } |
| 11545 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11546 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11547 | SourceLocation StartLoc, |
| 11548 | SourceLocation LParenLoc, |
| 11549 | SourceLocation EndLoc) { |
| 11550 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11551 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11552 | // OpenMP [teams Constrcut, Restrictions] |
| 11553 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11554 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 11555 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11556 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11557 | |
| 11558 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11559 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11560 | |
| 11561 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 11562 | SourceLocation StartLoc, |
| 11563 | SourceLocation LParenLoc, |
| 11564 | SourceLocation EndLoc) { |
| 11565 | Expr *ValExpr = ThreadLimit; |
| 11566 | |
| 11567 | // OpenMP [teams Constrcut, Restrictions] |
| 11568 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11569 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 11570 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11571 | return nullptr; |
| 11572 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11573 | return new (Context) |
| 11574 | OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11575 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11576 | |
| 11577 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 11578 | SourceLocation StartLoc, |
| 11579 | SourceLocation LParenLoc, |
| 11580 | SourceLocation EndLoc) { |
| 11581 | Expr *ValExpr = Priority; |
| 11582 | |
| 11583 | // OpenMP [2.9.1, task Constrcut] |
| 11584 | // The priority-value is a non-negative numerical scalar expression. |
| 11585 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 11586 | /*StrictlyPositive=*/false)) |
| 11587 | return nullptr; |
| 11588 | |
| 11589 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11590 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11591 | |
| 11592 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 11593 | SourceLocation StartLoc, |
| 11594 | SourceLocation LParenLoc, |
| 11595 | SourceLocation EndLoc) { |
| 11596 | Expr *ValExpr = Grainsize; |
| 11597 | |
| 11598 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11599 | // The parameter of the grainsize clause must be a positive integer |
| 11600 | // expression. |
| 11601 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 11602 | /*StrictlyPositive=*/true)) |
| 11603 | return nullptr; |
| 11604 | |
| 11605 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11606 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11607 | |
| 11608 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 11609 | SourceLocation StartLoc, |
| 11610 | SourceLocation LParenLoc, |
| 11611 | SourceLocation EndLoc) { |
| 11612 | Expr *ValExpr = NumTasks; |
| 11613 | |
| 11614 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11615 | // The parameter of the num_tasks clause must be a positive integer |
| 11616 | // expression. |
| 11617 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 11618 | /*StrictlyPositive=*/true)) |
| 11619 | return nullptr; |
| 11620 | |
| 11621 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11622 | } |
| 11623 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11624 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11625 | SourceLocation LParenLoc, |
| 11626 | SourceLocation EndLoc) { |
| 11627 | // OpenMP [2.13.2, critical construct, Description] |
| 11628 | // ... where hint-expression is an integer constant expression that evaluates |
| 11629 | // to a valid lock hint. |
| 11630 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 11631 | if (HintExpr.isInvalid()) |
| 11632 | return nullptr; |
| 11633 | return new (Context) |
| 11634 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 11635 | } |
| 11636 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11637 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 11638 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11639 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 11640 | SourceLocation EndLoc) { |
| 11641 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 11642 | std::string Values; |
| 11643 | Values += "'"; |
| 11644 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 11645 | Values += "'"; |
| 11646 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11647 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 11648 | return nullptr; |
| 11649 | } |
| 11650 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11651 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11652 | if (ChunkSize) { |
| 11653 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 11654 | !ChunkSize->isInstantiationDependent() && |
| 11655 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 11656 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 11657 | ExprResult Val = |
| 11658 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 11659 | if (Val.isInvalid()) |
| 11660 | return nullptr; |
| 11661 | |
| 11662 | ValExpr = Val.get(); |
| 11663 | |
| 11664 | // OpenMP [2.7.1, Restrictions] |
| 11665 | // chunk_size must be a loop invariant integer expression with a positive |
| 11666 | // value. |
| 11667 | llvm::APSInt Result; |
| 11668 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 11669 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 11670 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 11671 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 11672 | return nullptr; |
| 11673 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 11674 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 11675 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11676 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11677 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11678 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11679 | } |
| 11680 | } |
| 11681 | } |
| 11682 | |
| 11683 | return new (Context) |
| 11684 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11685 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11686 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11687 | |
| 11688 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 11689 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 11690 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 11691 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 11692 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11693 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11694 | std::string Value; |
| 11695 | SourceLocation Loc; |
| 11696 | Value += "'"; |
| 11697 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 11698 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11699 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11700 | Loc = MLoc; |
| 11701 | } else { |
| 11702 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11703 | OMPC_DEFAULTMAP_scalar); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11704 | Loc = KindLoc; |
| 11705 | } |
| 11706 | Value += "'"; |
| 11707 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 11708 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 11709 | return nullptr; |
| 11710 | } |
| 11711 | |
| 11712 | return new (Context) |
| 11713 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 11714 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11715 | |
| 11716 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 11717 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 11718 | if (!CurLexicalContext->isFileContext() && |
| 11719 | !CurLexicalContext->isExternCContext() && |
| 11720 | !CurLexicalContext->isExternCXXContext()) { |
| 11721 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 11722 | return false; |
| 11723 | } |
| 11724 | if (IsInOpenMPDeclareTargetContext) { |
| 11725 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 11726 | return false; |
| 11727 | } |
| 11728 | |
| 11729 | IsInOpenMPDeclareTargetContext = true; |
| 11730 | return true; |
| 11731 | } |
| 11732 | |
| 11733 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 11734 | assert(IsInOpenMPDeclareTargetContext && |
| 11735 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 11736 | |
| 11737 | IsInOpenMPDeclareTargetContext = false; |
| 11738 | } |
| 11739 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11740 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 11741 | CXXScopeSpec &ScopeSpec, |
| 11742 | const DeclarationNameInfo &Id, |
| 11743 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11744 | NamedDeclSetType &SameDirectiveDecls) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11745 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 11746 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 11747 | |
| 11748 | if (Lookup.isAmbiguous()) |
| 11749 | return; |
| 11750 | Lookup.suppressDiagnostics(); |
| 11751 | |
| 11752 | if (!Lookup.isSingleResult()) { |
| 11753 | if (TypoCorrection Corrected = |
| 11754 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 11755 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 11756 | CTK_ErrorRecovery)) { |
| 11757 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 11758 | << Id.getName()); |
| 11759 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 11760 | return; |
| 11761 | } |
| 11762 | |
| 11763 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 11764 | return; |
| 11765 | } |
| 11766 | |
| 11767 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 11768 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 11769 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 11770 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 11771 | |
| 11772 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 11773 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 11774 | ND->addAttr(A); |
| 11775 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 11776 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 11777 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 11778 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 11779 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 11780 | << Id.getName(); |
| 11781 | } |
| 11782 | } else |
| 11783 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 11784 | } |
| 11785 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11786 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 11787 | Sema &SemaRef, Decl *D) { |
| 11788 | if (!D) |
| 11789 | return; |
| 11790 | Decl *LD = nullptr; |
| 11791 | if (isa<TagDecl>(D)) { |
| 11792 | LD = cast<TagDecl>(D)->getDefinition(); |
| 11793 | } else if (isa<VarDecl>(D)) { |
| 11794 | LD = cast<VarDecl>(D)->getDefinition(); |
| 11795 | |
| 11796 | // If this is an implicit variable that is legal and we do not need to do |
| 11797 | // anything. |
| 11798 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11799 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11800 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11801 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11802 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11803 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11804 | return; |
| 11805 | } |
| 11806 | |
| 11807 | } else if (isa<FunctionDecl>(D)) { |
| 11808 | const FunctionDecl *FD = nullptr; |
| 11809 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 11810 | LD = const_cast<FunctionDecl *>(FD); |
| 11811 | |
| 11812 | // If the definition is associated with the current declaration in the |
| 11813 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 11814 | // to do anything else. |
| 11815 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11816 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11817 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11818 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11819 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11820 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11821 | return; |
| 11822 | } |
| 11823 | } |
| 11824 | if (!LD) |
| 11825 | LD = D; |
| 11826 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11827 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 11828 | // Outlined declaration is not declared target. |
| 11829 | if (LD->isOutOfLine()) { |
| 11830 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11831 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11832 | } else { |
| 11833 | DeclContext *DC = LD->getDeclContext(); |
| 11834 | while (DC) { |
| 11835 | if (isa<FunctionDecl>(DC) && |
| 11836 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11837 | break; |
| 11838 | DC = DC->getParent(); |
| 11839 | } |
| 11840 | if (DC) |
| 11841 | return; |
| 11842 | |
| 11843 | // Is not declared in target context. |
| 11844 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11845 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11846 | } |
| 11847 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11848 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11849 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11850 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11851 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11852 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11853 | } |
| 11854 | } |
| 11855 | |
| 11856 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 11857 | Sema &SemaRef, DSAStackTy *Stack, |
| 11858 | ValueDecl *VD) { |
| 11859 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11860 | return true; |
| 11861 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 11862 | return false; |
| 11863 | return true; |
| 11864 | } |
| 11865 | |
| 11866 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 11867 | if (!D || D->isInvalidDecl()) |
| 11868 | return; |
| 11869 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 11870 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 11871 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 11872 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 11873 | if (DSAStack->isThreadPrivate(VD)) { |
| 11874 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 11875 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 11876 | return; |
| 11877 | } |
| 11878 | } |
| 11879 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 11880 | // Problem if any with var declared with incomplete type will be reported |
| 11881 | // as normal, so no need to check it here. |
| 11882 | if ((E || !VD->getType()->isIncompleteType()) && |
| 11883 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 11884 | // Mark decl as declared target to prevent further diagnostic. |
| 11885 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11886 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11887 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11888 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11889 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11890 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11891 | } |
| 11892 | return; |
| 11893 | } |
| 11894 | } |
| 11895 | if (!E) { |
| 11896 | // Checking declaration inside declare target region. |
| 11897 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11898 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11899 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11900 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11901 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11902 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11903 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11904 | } |
| 11905 | return; |
| 11906 | } |
| 11907 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 11908 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11909 | |
| 11910 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 11911 | SourceLocation StartLoc, |
| 11912 | SourceLocation LParenLoc, |
| 11913 | SourceLocation EndLoc) { |
| 11914 | MappableVarListInfo MVLI(VarList); |
| 11915 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 11916 | if (MVLI.ProcessedVarList.empty()) |
| 11917 | return nullptr; |
| 11918 | |
| 11919 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11920 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11921 | MVLI.VarComponents); |
| 11922 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11923 | |
| 11924 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11925 | SourceLocation StartLoc, |
| 11926 | SourceLocation LParenLoc, |
| 11927 | SourceLocation EndLoc) { |
| 11928 | MappableVarListInfo MVLI(VarList); |
| 11929 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11930 | if (MVLI.ProcessedVarList.empty()) |
| 11931 | return nullptr; |
| 11932 | |
| 11933 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11934 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11935 | MVLI.VarComponents); |
| 11936 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11937 | |
| 11938 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11939 | SourceLocation StartLoc, |
| 11940 | SourceLocation LParenLoc, |
| 11941 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11942 | MappableVarListInfo MVLI(VarList); |
| 11943 | SmallVector<Expr *, 8> PrivateCopies; |
| 11944 | SmallVector<Expr *, 8> Inits; |
| 11945 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11946 | for (auto &RefExpr : VarList) { |
| 11947 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11948 | SourceLocation ELoc; |
| 11949 | SourceRange ERange; |
| 11950 | Expr *SimpleRefExpr = RefExpr; |
| 11951 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11952 | if (Res.second) { |
| 11953 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11954 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11955 | PrivateCopies.push_back(nullptr); |
| 11956 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11957 | } |
| 11958 | ValueDecl *D = Res.first; |
| 11959 | if (!D) |
| 11960 | continue; |
| 11961 | |
| 11962 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11963 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11964 | |
| 11965 | auto *VD = dyn_cast<VarDecl>(D); |
| 11966 | |
| 11967 | // Item should be a pointer or reference to pointer. |
| 11968 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11969 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11970 | << 0 << RefExpr->getSourceRange(); |
| 11971 | continue; |
| 11972 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11973 | |
| 11974 | // Build the private variable and the expression that refers to it. |
| 11975 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11976 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11977 | if (VDPrivate->isInvalidDecl()) |
| 11978 | continue; |
| 11979 | |
| 11980 | CurContext->addDecl(VDPrivate); |
| 11981 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11982 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11983 | |
| 11984 | // Add temporary variable to initialize the private copy of the pointer. |
| 11985 | auto *VDInit = |
| 11986 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11987 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11988 | RefExpr->getExprLoc()); |
| 11989 | AddInitializerToDecl(VDPrivate, |
| 11990 | DefaultLvalueConversion(VDInitRefExpr).get(), |
| 11991 | /*DirectInit=*/false, /*TypeMayContainAuto=*/false); |
| 11992 | |
| 11993 | // If required, build a capture to implement the privatization initialized |
| 11994 | // with the current list item value. |
| 11995 | DeclRefExpr *Ref = nullptr; |
| 11996 | if (!VD) |
| 11997 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11998 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11999 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 12000 | Inits.push_back(VDInitRefExpr); |
| 12001 | |
| 12002 | // We need to add a data sharing attribute for this variable to make sure it |
| 12003 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 12004 | // similar properties of a first private variable. |
| 12005 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 12006 | |
| 12007 | // Create a mappable component for the list item. List items in this clause |
| 12008 | // only need a component. |
| 12009 | MVLI.VarBaseDeclarations.push_back(D); |
| 12010 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 12011 | MVLI.VarComponents.back().push_back( |
| 12012 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 12013 | } |
| 12014 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 12015 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 12016 | return nullptr; |
| 12017 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 12018 | return OMPUseDevicePtrClause::Create( |
| 12019 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 12020 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 12021 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12022 | |
| 12023 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 12024 | SourceLocation StartLoc, |
| 12025 | SourceLocation LParenLoc, |
| 12026 | SourceLocation EndLoc) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12027 | MappableVarListInfo MVLI(VarList); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12028 | for (auto &RefExpr : VarList) { |
| 12029 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 12030 | SourceLocation ELoc; |
| 12031 | SourceRange ERange; |
| 12032 | Expr *SimpleRefExpr = RefExpr; |
| 12033 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 12034 | if (Res.second) { |
| 12035 | // It will be analyzed later. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12036 | MVLI.ProcessedVarList.push_back(RefExpr); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12037 | } |
| 12038 | ValueDecl *D = Res.first; |
| 12039 | if (!D) |
| 12040 | continue; |
| 12041 | |
| 12042 | QualType Type = D->getType(); |
| 12043 | // item should be a pointer or array or reference to pointer or array |
| 12044 | if (!Type.getNonReferenceType()->isPointerType() && |
| 12045 | !Type.getNonReferenceType()->isArrayType()) { |
| 12046 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 12047 | << 0 << RefExpr->getSourceRange(); |
| 12048 | continue; |
| 12049 | } |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12050 | |
| 12051 | // Check if the declaration in the clause does not show up in any data |
| 12052 | // sharing attribute. |
| 12053 | auto DVar = DSAStack->getTopDSA(D, false); |
| 12054 | if (isOpenMPPrivate(DVar.CKind)) { |
| 12055 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 12056 | << getOpenMPClauseName(DVar.CKind) |
| 12057 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 12058 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 12059 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 12060 | continue; |
| 12061 | } |
| 12062 | |
| 12063 | Expr *ConflictExpr; |
| 12064 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 12065 | D, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12066 | [&ConflictExpr]( |
| 12067 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 12068 | OpenMPClauseKind) -> bool { |
| 12069 | ConflictExpr = R.front().getAssociatedExpression(); |
| 12070 | return true; |
| 12071 | })) { |
| 12072 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 12073 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 12074 | << ConflictExpr->getSourceRange(); |
| 12075 | continue; |
| 12076 | } |
| 12077 | |
| 12078 | // Store the components in the stack so that they can be used to check |
| 12079 | // against other clauses later on. |
| 12080 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 12081 | DSAStack->addMappableExpressionComponents( |
| 12082 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 12083 | |
| 12084 | // Record the expression we've just processed. |
| 12085 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 12086 | |
| 12087 | // Create a mappable component for the list item. List items in this clause |
| 12088 | // only need a component. We use a null declaration to signal fields in |
| 12089 | // 'this'. |
| 12090 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 12091 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 12092 | "Unexpected device pointer expression!"); |
| 12093 | MVLI.VarBaseDeclarations.push_back( |
| 12094 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 12095 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 12096 | MVLI.VarComponents.back().push_back(MC); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12097 | } |
| 12098 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12099 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12100 | return nullptr; |
| 12101 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 12102 | return OMPIsDevicePtrClause::Create( |
| 12103 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 12104 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 12105 | } |