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 | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 329 | /// Do the check specified in \a Check to all component lists and return true |
| 330 | /// if any issue is found. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 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 | 4c8035b | 2016-12-12 18:00:20 +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. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 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 |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 922 | // behavior. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 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); |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 1053 | PushExpressionEvaluationContext( |
| 1054 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1057 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1058 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1061 | void Sema::EndOpenMPClause() { |
| 1062 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1065 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1066 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1067 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1068 | // clause requires an accessible, unambiguous default constructor for the |
| 1069 | // class type, unless the list item is also specified in a firstprivate |
| 1070 | // clause. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1071 | if (auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1072 | for (auto *C : D->clauses()) { |
| 1073 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1074 | SmallVector<Expr *, 8> PrivateCopies; |
| 1075 | for (auto *DE : Clause->varlists()) { |
| 1076 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1077 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1078 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1079 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1080 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1081 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1082 | QualType Type = VD->getType().getNonReferenceType(); |
| 1083 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1084 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1085 | // Generate helper private variable and initialize it with the |
| 1086 | // default value. The address of the original variable is replaced |
| 1087 | // by the address of the new private variable in CodeGen. This new |
| 1088 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1089 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1090 | auto *VDPrivate = buildVarDecl( |
| 1091 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1092 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1093 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1094 | if (VDPrivate->isInvalidDecl()) |
| 1095 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1096 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1097 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1098 | } else { |
| 1099 | // The variable is also a firstprivate, so initialization sequence |
| 1100 | // for private copy is generated already. |
| 1101 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1102 | } |
| 1103 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1104 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1105 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1106 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | } |
| 1110 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1111 | DSAStack->pop(); |
| 1112 | DiscardCleanupsInEvaluationContext(); |
| 1113 | PopExpressionEvaluationContext(); |
| 1114 | } |
| 1115 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1116 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1117 | Expr *NumIterations, Sema &SemaRef, |
| 1118 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1119 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1120 | namespace { |
| 1121 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1122 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1123 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1124 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1125 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1126 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1127 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1128 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1129 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1130 | if (auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1131 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1132 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1133 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1134 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1135 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1136 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1137 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1138 | |
| 1139 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1140 | private: |
| 1141 | Sema &SemaRef; |
| 1142 | |
| 1143 | public: |
| 1144 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1145 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1146 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1147 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1148 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1149 | SemaRef.getCurScope()); |
| 1150 | } |
| 1151 | return false; |
| 1152 | } |
| 1153 | }; |
| 1154 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1155 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1156 | |
| 1157 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1158 | CXXScopeSpec &ScopeSpec, |
| 1159 | const DeclarationNameInfo &Id) { |
| 1160 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1161 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1162 | |
| 1163 | if (Lookup.isAmbiguous()) |
| 1164 | return ExprError(); |
| 1165 | |
| 1166 | VarDecl *VD; |
| 1167 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1168 | if (TypoCorrection Corrected = CorrectTypo( |
| 1169 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1170 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1171 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1172 | PDiag(Lookup.empty() |
| 1173 | ? diag::err_undeclared_var_use_suggest |
| 1174 | : diag::err_omp_expected_var_arg_suggest) |
| 1175 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1176 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1177 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1178 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1179 | : diag::err_omp_expected_var_arg) |
| 1180 | << Id.getName(); |
| 1181 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1182 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1183 | } else { |
| 1184 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1185 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1186 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1187 | return ExprError(); |
| 1188 | } |
| 1189 | } |
| 1190 | Lookup.suppressDiagnostics(); |
| 1191 | |
| 1192 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1193 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1194 | if (!VD->hasGlobalStorage()) { |
| 1195 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1196 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1197 | bool IsDecl = |
| 1198 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1199 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1200 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1201 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1202 | return ExprError(); |
| 1203 | } |
| 1204 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1205 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1206 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1207 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1208 | // A threadprivate directive for file-scope variables must appear outside |
| 1209 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1210 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1211 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1212 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1213 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1214 | bool IsDecl = |
| 1215 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1216 | Diag(VD->getLocation(), |
| 1217 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1218 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1219 | return ExprError(); |
| 1220 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1221 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1222 | // A threadprivate directive for static class member variables must appear |
| 1223 | // in the class definition, in the same scope in which the member |
| 1224 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1225 | if (CanonicalVD->isStaticDataMember() && |
| 1226 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1227 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1228 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1229 | bool IsDecl = |
| 1230 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1231 | Diag(VD->getLocation(), |
| 1232 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1233 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1234 | return ExprError(); |
| 1235 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1236 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1237 | // A threadprivate directive for namespace-scope variables must appear |
| 1238 | // outside any definition or declaration other than the namespace |
| 1239 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1240 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1241 | (!getCurLexicalContext()->isFileContext() || |
| 1242 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1243 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1244 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1245 | bool IsDecl = |
| 1246 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1247 | Diag(VD->getLocation(), |
| 1248 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1249 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1250 | return ExprError(); |
| 1251 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1252 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1253 | // A threadprivate directive for static block-scope variables must appear |
| 1254 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1255 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1256 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1257 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1258 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1259 | bool IsDecl = |
| 1260 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1261 | Diag(VD->getLocation(), |
| 1262 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1263 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1264 | return ExprError(); |
| 1265 | } |
| 1266 | |
| 1267 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1268 | // A threadprivate directive must lexically precede all references to any |
| 1269 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1270 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1271 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1272 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1273 | return ExprError(); |
| 1274 | } |
| 1275 | |
| 1276 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1277 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1278 | SourceLocation(), VD, |
| 1279 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1280 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1283 | Sema::DeclGroupPtrTy |
| 1284 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1285 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1286 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1287 | CurContext->addDecl(D); |
| 1288 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1289 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1290 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1293 | namespace { |
| 1294 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1295 | Sema &SemaRef; |
| 1296 | |
| 1297 | public: |
| 1298 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1299 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1300 | if (VD->hasLocalStorage()) { |
| 1301 | SemaRef.Diag(E->getLocStart(), |
| 1302 | diag::err_omp_local_var_in_threadprivate_init) |
| 1303 | << E->getSourceRange(); |
| 1304 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1305 | << VD << VD->getSourceRange(); |
| 1306 | return true; |
| 1307 | } |
| 1308 | } |
| 1309 | return false; |
| 1310 | } |
| 1311 | bool VisitStmt(const Stmt *S) { |
| 1312 | for (auto Child : S->children()) { |
| 1313 | if (Child && Visit(Child)) |
| 1314 | return true; |
| 1315 | } |
| 1316 | return false; |
| 1317 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1318 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1319 | }; |
| 1320 | } // namespace |
| 1321 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1322 | OMPThreadPrivateDecl * |
| 1323 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1324 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1325 | for (auto &RefExpr : VarList) { |
| 1326 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1327 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1328 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1329 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1330 | // Mark variable as used. |
| 1331 | VD->setReferenced(); |
| 1332 | VD->markUsed(Context); |
| 1333 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1334 | QualType QType = VD->getType(); |
| 1335 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1336 | // It will be analyzed later. |
| 1337 | Vars.push_back(DE); |
| 1338 | continue; |
| 1339 | } |
| 1340 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1341 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1342 | // A threadprivate variable must not have an incomplete type. |
| 1343 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1344 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1345 | continue; |
| 1346 | } |
| 1347 | |
| 1348 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1349 | // A threadprivate variable must not have a reference type. |
| 1350 | if (VD->getType()->isReferenceType()) { |
| 1351 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1352 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1353 | bool IsDecl = |
| 1354 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1355 | Diag(VD->getLocation(), |
| 1356 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1357 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1358 | continue; |
| 1359 | } |
| 1360 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1361 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1362 | // the corresponding diagnostic. |
| 1363 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1364 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1365 | getLangOpts().OpenMPUseTLS && |
| 1366 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1367 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1368 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1369 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1370 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1371 | bool IsDecl = |
| 1372 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1373 | Diag(VD->getLocation(), |
| 1374 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1375 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1376 | continue; |
| 1377 | } |
| 1378 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1379 | // Check if initial value of threadprivate variable reference variable with |
| 1380 | // local storage (it is not supported by runtime). |
| 1381 | if (auto Init = VD->getAnyInitializer()) { |
| 1382 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1383 | if (Checker.Visit(Init)) |
| 1384 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1385 | } |
| 1386 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1387 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1388 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1389 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1390 | Context, SourceRange(Loc, Loc))); |
| 1391 | if (auto *ML = Context.getASTMutationListener()) |
| 1392 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1393 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1394 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1395 | if (!Vars.empty()) { |
| 1396 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1397 | Vars); |
| 1398 | D->setAccess(AS_public); |
| 1399 | } |
| 1400 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1401 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1402 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1403 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1404 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1405 | bool IsLoopIterVar = false) { |
| 1406 | if (DVar.RefExpr) { |
| 1407 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1408 | << getOpenMPClauseName(DVar.CKind); |
| 1409 | return; |
| 1410 | } |
| 1411 | enum { |
| 1412 | PDSA_StaticMemberShared, |
| 1413 | PDSA_StaticLocalVarShared, |
| 1414 | PDSA_LoopIterVarPrivate, |
| 1415 | PDSA_LoopIterVarLinear, |
| 1416 | PDSA_LoopIterVarLastprivate, |
| 1417 | PDSA_ConstVarShared, |
| 1418 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1419 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1420 | PDSA_LocalVarPrivate, |
| 1421 | PDSA_Implicit |
| 1422 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1423 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1424 | auto ReportLoc = D->getLocation(); |
| 1425 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1426 | if (IsLoopIterVar) { |
| 1427 | if (DVar.CKind == OMPC_private) |
| 1428 | Reason = PDSA_LoopIterVarPrivate; |
| 1429 | else if (DVar.CKind == OMPC_lastprivate) |
| 1430 | Reason = PDSA_LoopIterVarLastprivate; |
| 1431 | else |
| 1432 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1433 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1434 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1435 | Reason = PDSA_TaskVarFirstprivate; |
| 1436 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1437 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1438 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1439 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1440 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1441 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1442 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1443 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1444 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1445 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1446 | ReportHint = true; |
| 1447 | Reason = PDSA_LocalVarPrivate; |
| 1448 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1449 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1450 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1451 | << Reason << ReportHint |
| 1452 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1453 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1454 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1455 | << getOpenMPClauseName(DVar.CKind); |
| 1456 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1459 | namespace { |
| 1460 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1461 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1462 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1463 | bool ErrorFound; |
| 1464 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1465 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1466 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1467 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1468 | public: |
| 1469 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1470 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1471 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1472 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1473 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1474 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1475 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1476 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1477 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1478 | auto DVar = Stack->getTopDSA(VD, false); |
| 1479 | // 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] | 1480 | if (DVar.RefExpr) |
| 1481 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1482 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1483 | auto ELoc = E->getExprLoc(); |
| 1484 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1485 | // The default(none) clause requires that each variable that is referenced |
| 1486 | // in the construct, and does not have a predetermined data-sharing |
| 1487 | // attribute, must have its data-sharing attribute explicitly determined |
| 1488 | // by being listed in a data-sharing attribute clause. |
| 1489 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1490 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1491 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1492 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1493 | return; |
| 1494 | } |
| 1495 | |
| 1496 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1497 | // A list item that appears in a reduction clause of the innermost |
| 1498 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1499 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1500 | DVar = Stack->hasInnermostDSA( |
| 1501 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1502 | [](OpenMPDirectiveKind K) -> bool { |
| 1503 | return isOpenMPParallelDirective(K) || |
| 1504 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1505 | }, |
| 1506 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1507 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1508 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1509 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1510 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1511 | return; |
| 1512 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1513 | |
| 1514 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1515 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1516 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1517 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1518 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1519 | } |
| 1520 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1521 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1522 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1523 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1524 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1525 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1526 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1527 | auto DVar = Stack->getTopDSA(FD, false); |
| 1528 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1529 | // so. |
| 1530 | if (DVar.RefExpr) |
| 1531 | return; |
| 1532 | |
| 1533 | auto ELoc = E->getExprLoc(); |
| 1534 | auto DKind = Stack->getCurrentDirective(); |
| 1535 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1536 | // A list item that appears in a reduction clause of the innermost |
| 1537 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1538 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1539 | DVar = Stack->hasInnermostDSA( |
| 1540 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1541 | [](OpenMPDirectiveKind K) -> bool { |
| 1542 | return isOpenMPParallelDirective(K) || |
| 1543 | isOpenMPWorksharingDirective(K) || |
| 1544 | isOpenMPTeamsDirective(K); |
| 1545 | }, |
| 1546 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1547 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1548 | ErrorFound = true; |
| 1549 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1550 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1551 | return; |
| 1552 | } |
| 1553 | |
| 1554 | // Define implicit data-sharing attributes for task. |
| 1555 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1556 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1557 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1558 | ImplicitFirstprivate.push_back(E); |
| 1559 | } |
Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 1560 | } else |
| 1561 | Visit(E->getBase()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1562 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1563 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1564 | for (auto *C : S->clauses()) { |
| 1565 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1566 | // for task directives. |
| 1567 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1568 | for (auto *CC : C->children()) { |
| 1569 | if (CC) |
| 1570 | Visit(CC); |
| 1571 | } |
| 1572 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1573 | } |
| 1574 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1575 | for (auto *C : S->children()) { |
| 1576 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1577 | Visit(C); |
| 1578 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1579 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1580 | |
| 1581 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1582 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1583 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1584 | return VarsWithInheritedDSA; |
| 1585 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1586 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1587 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1588 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1589 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1590 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1591 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1592 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1593 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1594 | case OMPD_parallel: |
| 1595 | case OMPD_parallel_for: |
| 1596 | case OMPD_parallel_for_simd: |
| 1597 | case OMPD_parallel_sections: |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1598 | case OMPD_teams: { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1599 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 2377fe9 | 2015-09-10 08:12:02 +0000 | [diff] [blame] | 1600 | QualType KmpInt32PtrTy = |
| 1601 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1602 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1603 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1604 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1605 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1606 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1607 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1608 | Params); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1609 | break; |
| 1610 | } |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1611 | case OMPD_target_teams: |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1612 | case OMPD_target_parallel: { |
| 1613 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 1614 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1615 | }; |
| 1616 | // Start a captured region for 'target' with no implicit parameters. |
| 1617 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1618 | ParamsTarget); |
| 1619 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1620 | QualType KmpInt32PtrTy = |
| 1621 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1622 | Sema::CapturedParamNameType ParamsTeamsOrParallel[] = { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1623 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1624 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1625 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1626 | }; |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1627 | // Start a captured region for 'teams' or 'parallel'. Both regions have |
| 1628 | // the same implicit parameters. |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1629 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
Arpith Chacko Jacob | 99a1e0e | 2017-01-25 02:18:43 +0000 | [diff] [blame] | 1630 | ParamsTeamsOrParallel); |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1631 | break; |
| 1632 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1633 | case OMPD_simd: |
| 1634 | case OMPD_for: |
| 1635 | case OMPD_for_simd: |
| 1636 | case OMPD_sections: |
| 1637 | case OMPD_section: |
| 1638 | case OMPD_single: |
| 1639 | case OMPD_master: |
| 1640 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1641 | case OMPD_taskgroup: |
| 1642 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1643 | case OMPD_ordered: |
| 1644 | case OMPD_atomic: |
| 1645 | case OMPD_target_data: |
| 1646 | case OMPD_target: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1647 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1648 | case OMPD_target_parallel_for_simd: |
| 1649 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1650 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1651 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1652 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1653 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1654 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1655 | break; |
| 1656 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1657 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1658 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1659 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1660 | FunctionProtoType::ExtProtoInfo EPI; |
| 1661 | EPI.Variadic = true; |
| 1662 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1663 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1664 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1665 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1666 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1667 | std::make_pair(".copy_fn.", |
| 1668 | Context.getPointerType(CopyFnType).withConst()), |
| 1669 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1670 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1671 | }; |
| 1672 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1673 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1674 | // Mark this captured region as inlined, because we don't use outlined |
| 1675 | // function directly. |
| 1676 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1677 | AlwaysInlineAttr::CreateImplicit( |
| 1678 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1679 | break; |
| 1680 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1681 | case OMPD_taskloop: |
| 1682 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1683 | QualType KmpInt32Ty = |
| 1684 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1685 | QualType KmpUInt64Ty = |
| 1686 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1687 | QualType KmpInt64Ty = |
| 1688 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1689 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1690 | FunctionProtoType::ExtProtoInfo EPI; |
| 1691 | EPI.Variadic = true; |
| 1692 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1693 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1694 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1695 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1696 | std::make_pair(".privates.", |
| 1697 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1698 | std::make_pair( |
| 1699 | ".copy_fn.", |
| 1700 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1701 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1702 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1703 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1704 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1705 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1706 | }; |
| 1707 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1708 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1709 | // Mark this captured region as inlined, because we don't use outlined |
| 1710 | // function directly. |
| 1711 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1712 | AlwaysInlineAttr::CreateImplicit( |
| 1713 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1714 | break; |
| 1715 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1716 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1717 | case OMPD_distribute_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1718 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1719 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1720 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1721 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1722 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1723 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1724 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1725 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1726 | case OMPD_target_teams_distribute_simd: { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1727 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1728 | QualType KmpInt32PtrTy = |
| 1729 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1730 | Sema::CapturedParamNameType Params[] = { |
| 1731 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1732 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1733 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1734 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1735 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1736 | }; |
| 1737 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1738 | Params); |
| 1739 | break; |
| 1740 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1741 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1742 | case OMPD_taskyield: |
| 1743 | case OMPD_barrier: |
| 1744 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1745 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1746 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1747 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1748 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1749 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1750 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1751 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1752 | case OMPD_declare_target: |
| 1753 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1754 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1755 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1756 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1757 | llvm_unreachable("Unknown OpenMP directive"); |
| 1758 | } |
| 1759 | } |
| 1760 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1761 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 1762 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 1763 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 1764 | return CaptureRegions.size(); |
| 1765 | } |
| 1766 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1767 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1768 | Expr *CaptureExpr, bool WithInit, |
| 1769 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1770 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1771 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1772 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1773 | QualType Ty = Init->getType(); |
| 1774 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1775 | if (S.getLangOpts().CPlusPlus) |
| 1776 | Ty = C.getLValueReferenceType(Ty); |
| 1777 | else { |
| 1778 | Ty = C.getPointerType(Ty); |
| 1779 | ExprResult Res = |
| 1780 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1781 | if (!Res.isUsable()) |
| 1782 | return nullptr; |
| 1783 | Init = Res.get(); |
| 1784 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1785 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1786 | } |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 1787 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| 1788 | CaptureExpr->getLocStart()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1789 | if (!WithInit) |
| 1790 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1791 | S.CurContext->addHiddenDecl(CED); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1792 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1793 | return CED; |
| 1794 | } |
| 1795 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1796 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1797 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1798 | OMPCapturedExprDecl *CD; |
| 1799 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1800 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1801 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1802 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1803 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1804 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1805 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1808 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1809 | if (!Ref) { |
| 1810 | auto *CD = |
| 1811 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1812 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1813 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1814 | CaptureExpr->getExprLoc()); |
| 1815 | } |
| 1816 | ExprResult Res = Ref; |
| 1817 | if (!S.getLangOpts().CPlusPlus && |
| 1818 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1819 | Ref->getType()->isPointerType()) |
| 1820 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1821 | if (!Res.isUsable()) |
| 1822 | return ExprError(); |
| 1823 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1826 | namespace { |
| 1827 | // OpenMP directives parsed in this section are represented as a |
| 1828 | // CapturedStatement with an associated statement. If a syntax error |
| 1829 | // is detected during the parsing of the associated statement, the |
| 1830 | // compiler must abort processing and close the CapturedStatement. |
| 1831 | // |
| 1832 | // Combined directives such as 'target parallel' have more than one |
| 1833 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 1834 | // of all the nested CapturedStatements when an error is found. |
| 1835 | class CaptureRegionUnwinderRAII { |
| 1836 | private: |
| 1837 | Sema &S; |
| 1838 | bool &ErrorFound; |
| 1839 | OpenMPDirectiveKind DKind; |
| 1840 | |
| 1841 | public: |
| 1842 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 1843 | OpenMPDirectiveKind DKind) |
| 1844 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 1845 | ~CaptureRegionUnwinderRAII() { |
| 1846 | if (ErrorFound) { |
| 1847 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 1848 | while (--ThisCaptureLevel >= 0) |
| 1849 | S.ActOnCapturedRegionError(); |
| 1850 | } |
| 1851 | } |
| 1852 | }; |
| 1853 | } // namespace |
| 1854 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1855 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1856 | ArrayRef<OMPClause *> Clauses) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1857 | bool ErrorFound = false; |
| 1858 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 1859 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1860 | if (!S.isUsable()) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1861 | ErrorFound = true; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1862 | return StmtError(); |
| 1863 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1864 | |
| 1865 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1866 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1867 | SmallVector<OMPLinearClause *, 4> LCs; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1868 | SmallVector<OMPClauseWithPreInit *, 8> PICs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1869 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1870 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1871 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1872 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1873 | (getLangOpts().OpenMPUseTLS && |
| 1874 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1875 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1876 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1877 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1878 | for (auto *VarRef : Clause->children()) { |
| 1879 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1880 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1881 | } |
| 1882 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1883 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1884 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1885 | if (auto *C = OMPClauseWithPreInit::get(Clause)) |
| 1886 | PICs.push_back(C); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1887 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1888 | if (auto *E = C->getPostUpdateExpr()) |
| 1889 | MarkDeclarationsReferencedInExpr(E); |
| 1890 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1891 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1892 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1893 | SC = cast<OMPScheduleClause>(Clause); |
| 1894 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1895 | OC = cast<OMPOrderedClause>(Clause); |
| 1896 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1897 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1898 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1899 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1900 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1901 | // specified. |
| 1902 | if (SC && |
| 1903 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1904 | SC->getSecondScheduleModifier() == |
| 1905 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1906 | OC) { |
| 1907 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1908 | ? SC->getFirstScheduleModifierLoc() |
| 1909 | : SC->getSecondScheduleModifierLoc(), |
| 1910 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1911 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1912 | ErrorFound = true; |
| 1913 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1914 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1915 | for (auto *C : LCs) { |
| 1916 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1917 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1918 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1919 | ErrorFound = true; |
| 1920 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1921 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1922 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1923 | OC->getNumForLoops()) { |
| 1924 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1925 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1926 | ErrorFound = true; |
| 1927 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1928 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1929 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1930 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1931 | StmtResult SR = S; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1932 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 1933 | getOpenMPCaptureRegions(CaptureRegions, DSAStack->getCurrentDirective()); |
| 1934 | for (auto ThisCaptureRegion : llvm::reverse(CaptureRegions)) { |
| 1935 | // Mark all variables in private list clauses as used in inner region. |
| 1936 | // Required for proper codegen of combined directives. |
| 1937 | // TODO: add processing for other clauses. |
| 1938 | if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
| 1939 | for (auto *C : PICs) { |
| 1940 | OpenMPDirectiveKind CaptureRegion = C->getCaptureRegion(); |
| 1941 | // Find the particular capture region for the clause if the |
| 1942 | // directive is a combined one with multiple capture regions. |
| 1943 | // If the directive is not a combined one, the capture region |
| 1944 | // associated with the clause is OMPD_unknown and is generated |
| 1945 | // only once. |
| 1946 | if (CaptureRegion == ThisCaptureRegion || |
| 1947 | CaptureRegion == OMPD_unknown) { |
| 1948 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1949 | for (auto *D : DS->decls()) |
| 1950 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1951 | } |
| 1952 | } |
| 1953 | } |
| 1954 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1955 | SR = ActOnCapturedRegionEnd(SR.get()); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 1956 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1957 | return SR; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 1960 | static bool checkCancelRegion(Sema &SemaRef, OpenMPDirectiveKind CurrentRegion, |
| 1961 | OpenMPDirectiveKind CancelRegion, |
| 1962 | SourceLocation StartLoc) { |
| 1963 | // CancelRegion is only needed for cancel and cancellation_point. |
| 1964 | if (CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_cancellation_point) |
| 1965 | return false; |
| 1966 | |
| 1967 | if (CancelRegion == OMPD_parallel || CancelRegion == OMPD_for || |
| 1968 | CancelRegion == OMPD_sections || CancelRegion == OMPD_taskgroup) |
| 1969 | return false; |
| 1970 | |
| 1971 | SemaRef.Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 1972 | << getOpenMPDirectiveName(CancelRegion); |
| 1973 | return true; |
| 1974 | } |
| 1975 | |
| 1976 | static bool checkNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1977 | OpenMPDirectiveKind CurrentRegion, |
| 1978 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1979 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1980 | SourceLocation StartLoc) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1981 | if (Stack->getCurScope()) { |
| 1982 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1983 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1984 | bool NestingProhibited = false; |
| 1985 | bool CloseNesting = true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1986 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1987 | enum { |
| 1988 | NoRecommend, |
| 1989 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1990 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1991 | ShouldBeInTargetRegion, |
| 1992 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1993 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1994 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1995 | // OpenMP [2.16, Nesting of Regions] |
| 1996 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1997 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1998 | // An ordered construct with the simd clause is the only OpenMP |
| 1999 | // construct that can appear in the simd region. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2000 | // Allowing a SIMD construct nested in another SIMD construct is an |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 2001 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 2002 | // message. |
| 2003 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 2004 | ? diag::err_omp_prohibited_region_simd |
| 2005 | : diag::warn_omp_nesting_simd); |
| 2006 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2007 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2008 | if (ParentRegion == OMPD_atomic) { |
| 2009 | // OpenMP [2.16, Nesting of Regions] |
| 2010 | // OpenMP constructs may not be nested inside an atomic region. |
| 2011 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 2012 | return true; |
| 2013 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2014 | if (CurrentRegion == OMPD_section) { |
| 2015 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 2016 | // Orphaned section directives are prohibited. That is, the section |
| 2017 | // directives must appear within the sections construct and must not be |
| 2018 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2019 | if (ParentRegion != OMPD_sections && |
| 2020 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2021 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 2022 | << (ParentRegion != OMPD_unknown) |
| 2023 | << getOpenMPDirectiveName(ParentRegion); |
| 2024 | return true; |
| 2025 | } |
| 2026 | return false; |
| 2027 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2028 | // Allow some constructs (except teams) to be orphaned (they could be |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2029 | // used in functions, called from OpenMP regions with the required |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2030 | // preconditions). |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2031 | if (ParentRegion == OMPD_unknown && |
| 2032 | !isOpenMPNestingTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2033 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2034 | if (CurrentRegion == OMPD_cancellation_point || |
| 2035 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2036 | // OpenMP [2.16, Nesting of Regions] |
| 2037 | // A cancellation point construct for which construct-type-clause is |
| 2038 | // taskgroup must be nested inside a task construct. A cancellation |
| 2039 | // point construct for which construct-type-clause is not taskgroup must |
| 2040 | // be closely nested inside an OpenMP construct that matches the type |
| 2041 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2042 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2043 | // nested inside a task construct. A cancel construct for which |
| 2044 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2045 | // OpenMP construct that matches the type specified in |
| 2046 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2047 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2048 | !((CancelRegion == OMPD_parallel && |
| 2049 | (ParentRegion == OMPD_parallel || |
| 2050 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2051 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2052 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2053 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2054 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2055 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2056 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2057 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2058 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2059 | // OpenMP [2.16, Nesting of Regions] |
| 2060 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2061 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2062 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2063 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2064 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2065 | // OpenMP [2.16, Nesting of Regions] |
| 2066 | // A critical region may not be nested (closely or otherwise) inside a |
| 2067 | // critical region with the same name. Note that this restriction is not |
| 2068 | // sufficient to prevent deadlock. |
| 2069 | SourceLocation PreviousCriticalLoc; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2070 | bool DeadLock = Stack->hasDirective( |
| 2071 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 2072 | const DeclarationNameInfo &DNI, |
| 2073 | SourceLocation Loc) -> bool { |
| 2074 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 2075 | PreviousCriticalLoc = Loc; |
| 2076 | return true; |
| 2077 | } else |
| 2078 | return false; |
| 2079 | }, |
| 2080 | false /* skip top directive */); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2081 | if (DeadLock) { |
| 2082 | SemaRef.Diag(StartLoc, |
| 2083 | diag::err_omp_prohibited_region_critical_same_name) |
| 2084 | << CurrentName.getName(); |
| 2085 | if (PreviousCriticalLoc.isValid()) |
| 2086 | SemaRef.Diag(PreviousCriticalLoc, |
| 2087 | diag::note_omp_previous_critical_region); |
| 2088 | return true; |
| 2089 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2090 | } else if (CurrentRegion == OMPD_barrier) { |
| 2091 | // OpenMP [2.16, Nesting of Regions] |
| 2092 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2093 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2094 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2095 | isOpenMPTaskingDirective(ParentRegion) || |
| 2096 | ParentRegion == OMPD_master || |
| 2097 | ParentRegion == OMPD_critical || |
| 2098 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2099 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2100 | !isOpenMPParallelDirective(CurrentRegion) && |
| 2101 | !isOpenMPTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2102 | // OpenMP [2.16, Nesting of Regions] |
| 2103 | // A worksharing region may not be closely nested inside a worksharing, |
| 2104 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2105 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2106 | isOpenMPTaskingDirective(ParentRegion) || |
| 2107 | ParentRegion == OMPD_master || |
| 2108 | ParentRegion == OMPD_critical || |
| 2109 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2110 | Recommend = ShouldBeInParallelRegion; |
| 2111 | } else if (CurrentRegion == OMPD_ordered) { |
| 2112 | // OpenMP [2.16, Nesting of Regions] |
| 2113 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2114 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2115 | // An ordered region must be closely nested inside a loop region (or |
| 2116 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2117 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2118 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2119 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2120 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2121 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2122 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2123 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2124 | Recommend = ShouldBeInOrderedRegion; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2125 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2126 | // OpenMP [2.16, Nesting of Regions] |
| 2127 | // If specified, a teams construct must be contained within a target |
| 2128 | // construct. |
| 2129 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2130 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2131 | Recommend = ShouldBeInTargetRegion; |
| 2132 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2133 | } |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2134 | if (!NestingProhibited && |
| 2135 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 2136 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 2137 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2138 | // OpenMP [2.16, Nesting of Regions] |
| 2139 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2140 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2141 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2142 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2143 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2144 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2145 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2146 | if (!NestingProhibited && |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2147 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2148 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2149 | // The region associated with the distribute construct must be strictly |
| 2150 | // nested inside a teams region |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2151 | NestingProhibited = |
| 2152 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2153 | Recommend = ShouldBeInTeamsRegion; |
| 2154 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2155 | if (!NestingProhibited && |
| 2156 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2157 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2158 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2159 | // If a target, target update, target data, target enter data, or |
| 2160 | // target exit data construct is encountered during execution of a |
| 2161 | // target region, the behavior is unspecified. |
| 2162 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2163 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 2164 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2165 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2166 | OffendingRegion = K; |
| 2167 | return true; |
| 2168 | } else |
| 2169 | return false; |
| 2170 | }, |
| 2171 | false /* don't skip top directive */); |
| 2172 | CloseNesting = false; |
| 2173 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2174 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2175 | if (OrphanSeen) { |
| 2176 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 2177 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 2178 | } else { |
| 2179 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 2180 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2181 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 2182 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2183 | return true; |
| 2184 | } |
| 2185 | } |
| 2186 | return false; |
| 2187 | } |
| 2188 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2189 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2190 | ArrayRef<OMPClause *> Clauses, |
| 2191 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2192 | bool ErrorFound = false; |
| 2193 | unsigned NamedModifiersNumber = 0; |
| 2194 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2195 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2196 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2197 | for (const auto *C : Clauses) { |
| 2198 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2199 | // At most one if clause without a directive-name-modifier can appear on |
| 2200 | // the directive. |
| 2201 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2202 | if (FoundNameModifiers[CurNM]) { |
| 2203 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2204 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2205 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2206 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2207 | } else if (CurNM != OMPD_unknown) { |
| 2208 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2209 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2210 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2211 | FoundNameModifiers[CurNM] = IC; |
| 2212 | if (CurNM == OMPD_unknown) |
| 2213 | continue; |
| 2214 | // Check if the specified name modifier is allowed for the current |
| 2215 | // directive. |
| 2216 | // At most one if clause with the particular directive-name-modifier can |
| 2217 | // appear on the directive. |
| 2218 | bool MatchFound = false; |
| 2219 | for (auto NM : AllowedNameModifiers) { |
| 2220 | if (CurNM == NM) { |
| 2221 | MatchFound = true; |
| 2222 | break; |
| 2223 | } |
| 2224 | } |
| 2225 | if (!MatchFound) { |
| 2226 | S.Diag(IC->getNameModifierLoc(), |
| 2227 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2228 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2229 | ErrorFound = true; |
| 2230 | } |
| 2231 | } |
| 2232 | } |
| 2233 | // If any if clause on the directive includes a directive-name-modifier then |
| 2234 | // all if clauses on the directive must include a directive-name-modifier. |
| 2235 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2236 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2237 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2238 | diag::err_omp_no_more_if_clause); |
| 2239 | } else { |
| 2240 | std::string Values; |
| 2241 | std::string Sep(", "); |
| 2242 | unsigned AllowedCnt = 0; |
| 2243 | unsigned TotalAllowedNum = |
| 2244 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2245 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2246 | ++Cnt) { |
| 2247 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2248 | if (!FoundNameModifiers[NM]) { |
| 2249 | Values += "'"; |
| 2250 | Values += getOpenMPDirectiveName(NM); |
| 2251 | Values += "'"; |
| 2252 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2253 | Values += " or "; |
| 2254 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2255 | Values += Sep; |
| 2256 | ++AllowedCnt; |
| 2257 | } |
| 2258 | } |
| 2259 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2260 | diag::err_omp_unnamed_if_clause) |
| 2261 | << (TotalAllowedNum > 1) << Values; |
| 2262 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2263 | for (auto Loc : NameModifierLoc) { |
| 2264 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2265 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2266 | ErrorFound = true; |
| 2267 | } |
| 2268 | return ErrorFound; |
| 2269 | } |
| 2270 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2271 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2272 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2273 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2274 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2275 | StmtResult Res = StmtError(); |
Jonas Hahnfeld | 64a9e3c | 2017-02-22 06:49:10 +0000 | [diff] [blame] | 2276 | // First check CancelRegion which is then used in checkNestingOfRegions. |
| 2277 | if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) || |
| 2278 | checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2279 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2280 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2281 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2282 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2283 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2284 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2285 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2286 | if (AStmt) { |
| 2287 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2288 | |
| 2289 | // Check default data sharing attributes for referenced variables. |
| 2290 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
Arpith Chacko Jacob | 1f46b70 | 2017-01-23 15:38:49 +0000 | [diff] [blame] | 2291 | int ThisCaptureLevel = getOpenMPCaptureLevels(Kind); |
| 2292 | Stmt *S = AStmt; |
| 2293 | while (--ThisCaptureLevel >= 0) |
| 2294 | S = cast<CapturedStmt>(S)->getCapturedStmt(); |
| 2295 | DSAChecker.Visit(S); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2296 | if (DSAChecker.isErrorFound()) |
| 2297 | return StmtError(); |
| 2298 | // Generate list of implicitly defined firstprivate variables. |
| 2299 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2300 | |
| 2301 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2302 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2303 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2304 | SourceLocation(), SourceLocation())) { |
| 2305 | ClausesWithImplicit.push_back(Implicit); |
| 2306 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2307 | DSAChecker.getImplicitFirstprivate().size(); |
| 2308 | } else |
| 2309 | ErrorFound = true; |
| 2310 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2311 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2312 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2313 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2314 | switch (Kind) { |
| 2315 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2316 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2317 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2318 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2319 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2320 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2321 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2322 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2323 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2324 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2325 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2326 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2327 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2328 | case OMPD_for_simd: |
| 2329 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2330 | EndLoc, VarsWithInheritedDSA); |
| 2331 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2332 | case OMPD_sections: |
| 2333 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2334 | EndLoc); |
| 2335 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2336 | case OMPD_section: |
| 2337 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2338 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2339 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2340 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2341 | case OMPD_single: |
| 2342 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2343 | EndLoc); |
| 2344 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2345 | case OMPD_master: |
| 2346 | assert(ClausesWithImplicit.empty() && |
| 2347 | "No clauses are allowed for 'omp master' directive"); |
| 2348 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2349 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2350 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2351 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2352 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2353 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2354 | case OMPD_parallel_for: |
| 2355 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2356 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2357 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2358 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2359 | case OMPD_parallel_for_simd: |
| 2360 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2361 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2362 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2363 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2364 | case OMPD_parallel_sections: |
| 2365 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2366 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2367 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2368 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2369 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2370 | Res = |
| 2371 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2372 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2373 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2374 | case OMPD_taskyield: |
| 2375 | assert(ClausesWithImplicit.empty() && |
| 2376 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2377 | assert(AStmt == nullptr && |
| 2378 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2379 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2380 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2381 | case OMPD_barrier: |
| 2382 | assert(ClausesWithImplicit.empty() && |
| 2383 | "No clauses are allowed for 'omp barrier' directive"); |
| 2384 | assert(AStmt == nullptr && |
| 2385 | "No associated statement allowed for 'omp barrier' directive"); |
| 2386 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2387 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2388 | case OMPD_taskwait: |
| 2389 | assert(ClausesWithImplicit.empty() && |
| 2390 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2391 | assert(AStmt == nullptr && |
| 2392 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2393 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2394 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2395 | case OMPD_taskgroup: |
| 2396 | assert(ClausesWithImplicit.empty() && |
| 2397 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2398 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2399 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2400 | case OMPD_flush: |
| 2401 | assert(AStmt == nullptr && |
| 2402 | "No associated statement allowed for 'omp flush' directive"); |
| 2403 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2404 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2405 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2406 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2407 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2408 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2409 | case OMPD_atomic: |
| 2410 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2411 | EndLoc); |
| 2412 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2413 | case OMPD_teams: |
| 2414 | Res = |
| 2415 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2416 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2417 | case OMPD_target: |
| 2418 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2419 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2420 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2421 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2422 | case OMPD_target_parallel: |
| 2423 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 2424 | StartLoc, EndLoc); |
| 2425 | AllowedNameModifiers.push_back(OMPD_target); |
| 2426 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2427 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2428 | case OMPD_target_parallel_for: |
| 2429 | Res = ActOnOpenMPTargetParallelForDirective( |
| 2430 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2431 | AllowedNameModifiers.push_back(OMPD_target); |
| 2432 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2433 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2434 | case OMPD_cancellation_point: |
| 2435 | assert(ClausesWithImplicit.empty() && |
| 2436 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2437 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2438 | "cancellation point' directive"); |
| 2439 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2440 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2441 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2442 | assert(AStmt == nullptr && |
| 2443 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2444 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2445 | CancelRegion); |
| 2446 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2447 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2448 | case OMPD_target_data: |
| 2449 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2450 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2451 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2452 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2453 | case OMPD_target_enter_data: |
| 2454 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2455 | EndLoc); |
| 2456 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2457 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2458 | case OMPD_target_exit_data: |
| 2459 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2460 | EndLoc); |
| 2461 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2462 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2463 | case OMPD_taskloop: |
| 2464 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2465 | EndLoc, VarsWithInheritedDSA); |
| 2466 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2467 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2468 | case OMPD_taskloop_simd: |
| 2469 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2470 | EndLoc, VarsWithInheritedDSA); |
| 2471 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2472 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2473 | case OMPD_distribute: |
| 2474 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2475 | EndLoc, VarsWithInheritedDSA); |
| 2476 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 2477 | case OMPD_target_update: |
| 2478 | assert(!AStmt && "Statement is not allowed for target update"); |
| 2479 | Res = |
| 2480 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2481 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 2482 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2483 | case OMPD_distribute_parallel_for: |
| 2484 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 2485 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2486 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2487 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2488 | case OMPD_distribute_parallel_for_simd: |
| 2489 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 2490 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2491 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2492 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2493 | case OMPD_distribute_simd: |
| 2494 | Res = ActOnOpenMPDistributeSimdDirective( |
| 2495 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2496 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2497 | case OMPD_target_parallel_for_simd: |
| 2498 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 2499 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2500 | AllowedNameModifiers.push_back(OMPD_target); |
| 2501 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2502 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2503 | case OMPD_target_simd: |
| 2504 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2505 | EndLoc, VarsWithInheritedDSA); |
| 2506 | AllowedNameModifiers.push_back(OMPD_target); |
| 2507 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2508 | case OMPD_teams_distribute: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2509 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 2510 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2511 | break; |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2512 | case OMPD_teams_distribute_simd: |
| 2513 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 2514 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2515 | break; |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2516 | case OMPD_teams_distribute_parallel_for_simd: |
| 2517 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 2518 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2519 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2520 | break; |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2521 | case OMPD_teams_distribute_parallel_for: |
| 2522 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 2523 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2524 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2525 | break; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2526 | case OMPD_target_teams: |
| 2527 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2528 | EndLoc); |
| 2529 | AllowedNameModifiers.push_back(OMPD_target); |
| 2530 | break; |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2531 | case OMPD_target_teams_distribute: |
| 2532 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 2533 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2534 | AllowedNameModifiers.push_back(OMPD_target); |
| 2535 | break; |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2536 | case OMPD_target_teams_distribute_parallel_for: |
| 2537 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 2538 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2539 | AllowedNameModifiers.push_back(OMPD_target); |
| 2540 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2541 | break; |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2542 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 2543 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 2544 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2545 | AllowedNameModifiers.push_back(OMPD_target); |
| 2546 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2547 | break; |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 2548 | case OMPD_target_teams_distribute_simd: |
| 2549 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 2550 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2551 | AllowedNameModifiers.push_back(OMPD_target); |
| 2552 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2553 | case OMPD_declare_target: |
| 2554 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2555 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2556 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2557 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2558 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2559 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2560 | llvm_unreachable("Unknown OpenMP directive"); |
| 2561 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2562 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2563 | for (auto P : VarsWithInheritedDSA) { |
| 2564 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2565 | << P.first << P.second->getSourceRange(); |
| 2566 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2567 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2568 | |
| 2569 | if (!AllowedNameModifiers.empty()) |
| 2570 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2571 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2572 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2573 | if (ErrorFound) |
| 2574 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2575 | return Res; |
| 2576 | } |
| 2577 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2578 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 2579 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2580 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2581 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 2582 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2583 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2584 | assert(Linears.size() == LinModifiers.size()); |
| 2585 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2586 | if (!DG || DG.get().isNull()) |
| 2587 | return DeclGroupPtrTy(); |
| 2588 | |
| 2589 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 2590 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2591 | return DG; |
| 2592 | } |
| 2593 | auto *ADecl = DG.get().getSingleDecl(); |
| 2594 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 2595 | ADecl = FTD->getTemplatedDecl(); |
| 2596 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2597 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 2598 | if (!FD) { |
| 2599 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2600 | return DeclGroupPtrTy(); |
| 2601 | } |
| 2602 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2603 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2604 | // The parameter of the simdlen clause must be a constant positive integer |
| 2605 | // expression. |
| 2606 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2607 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2608 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2609 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2610 | // The special this pointer can be used as if was one of the arguments to the |
| 2611 | // function in any of the linear, aligned, or uniform clauses. |
| 2612 | // The uniform clause declares one or more arguments to have an invariant |
| 2613 | // value for all concurrent invocations of the function in the execution of a |
| 2614 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2615 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 2616 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2617 | for (auto *E : Uniforms) { |
| 2618 | E = E->IgnoreParenImpCasts(); |
| 2619 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2620 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 2621 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2622 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2623 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 2624 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2625 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2626 | } |
| 2627 | if (isa<CXXThisExpr>(E)) { |
| 2628 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2629 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2630 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2631 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2632 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2633 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2634 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2635 | // The aligned clause declares that the object to which each list item points |
| 2636 | // is aligned to the number of bytes expressed in the optional parameter of |
| 2637 | // the aligned clause. |
| 2638 | // The special this pointer can be used as if was one of the arguments to the |
| 2639 | // function in any of the linear, aligned, or uniform clauses. |
| 2640 | // The type of list items appearing in the aligned clause must be array, |
| 2641 | // pointer, reference to array, or reference to pointer. |
| 2642 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 2643 | Expr *AlignedThis = nullptr; |
| 2644 | for (auto *E : Aligneds) { |
| 2645 | E = E->IgnoreParenImpCasts(); |
| 2646 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2647 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2648 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2649 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2650 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2651 | ->getCanonicalDecl() == CanonPVD) { |
| 2652 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2653 | // A list-item cannot appear in more than one aligned clause. |
| 2654 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 2655 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2656 | << 1 << E->getSourceRange(); |
| 2657 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 2658 | diag::note_omp_explicit_dsa) |
| 2659 | << getOpenMPClauseName(OMPC_aligned); |
| 2660 | continue; |
| 2661 | } |
| 2662 | AlignedArgs[CanonPVD] = E; |
| 2663 | QualType QTy = PVD->getType() |
| 2664 | .getNonReferenceType() |
| 2665 | .getUnqualifiedType() |
| 2666 | .getCanonicalType(); |
| 2667 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 2668 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 2669 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 2670 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 2671 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 2672 | } |
| 2673 | continue; |
| 2674 | } |
| 2675 | } |
| 2676 | if (isa<CXXThisExpr>(E)) { |
| 2677 | if (AlignedThis) { |
| 2678 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2679 | << 2 << E->getSourceRange(); |
| 2680 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2681 | << getOpenMPClauseName(OMPC_aligned); |
| 2682 | } |
| 2683 | AlignedThis = E; |
| 2684 | continue; |
| 2685 | } |
| 2686 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2687 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2688 | } |
| 2689 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 2690 | // positive integer expression. If no optional parameter is specified, |
| 2691 | // implementation-defined default alignments for SIMD instructions on the |
| 2692 | // target platforms are assumed. |
| 2693 | SmallVector<Expr *, 4> NewAligns; |
| 2694 | for (auto *E : Alignments) { |
| 2695 | ExprResult Align; |
| 2696 | if (E) |
| 2697 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 2698 | NewAligns.push_back(Align.get()); |
| 2699 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2700 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2701 | // The linear clause declares one or more list items to be private to a SIMD |
| 2702 | // lane and to have a linear relationship with respect to the iteration space |
| 2703 | // of a loop. |
| 2704 | // The special this pointer can be used as if was one of the arguments to the |
| 2705 | // function in any of the linear, aligned, or uniform clauses. |
| 2706 | // When a linear-step expression is specified in a linear clause it must be |
| 2707 | // either a constant integer expression or an integer-typed parameter that is |
| 2708 | // specified in a uniform clause on the directive. |
| 2709 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 2710 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 2711 | auto MI = LinModifiers.begin(); |
| 2712 | for (auto *E : Linears) { |
| 2713 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 2714 | ++MI; |
| 2715 | E = E->IgnoreParenImpCasts(); |
| 2716 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2717 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2718 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2719 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2720 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2721 | ->getCanonicalDecl() == CanonPVD) { |
| 2722 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 2723 | // A list-item cannot appear in more than one linear clause. |
| 2724 | if (LinearArgs.count(CanonPVD) > 0) { |
| 2725 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2726 | << getOpenMPClauseName(OMPC_linear) |
| 2727 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 2728 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 2729 | diag::note_omp_explicit_dsa) |
| 2730 | << getOpenMPClauseName(OMPC_linear); |
| 2731 | continue; |
| 2732 | } |
| 2733 | // Each argument can appear in at most one uniform or linear clause. |
| 2734 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 2735 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2736 | << getOpenMPClauseName(OMPC_linear) |
| 2737 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 2738 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 2739 | diag::note_omp_explicit_dsa) |
| 2740 | << getOpenMPClauseName(OMPC_uniform); |
| 2741 | continue; |
| 2742 | } |
| 2743 | LinearArgs[CanonPVD] = E; |
| 2744 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2745 | E->isInstantiationDependent() || |
| 2746 | E->containsUnexpandedParameterPack()) |
| 2747 | continue; |
| 2748 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 2749 | PVD->getOriginalType()); |
| 2750 | continue; |
| 2751 | } |
| 2752 | } |
| 2753 | if (isa<CXXThisExpr>(E)) { |
| 2754 | if (UniformedLinearThis) { |
| 2755 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2756 | << getOpenMPClauseName(OMPC_linear) |
| 2757 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 2758 | << E->getSourceRange(); |
| 2759 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2760 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 2761 | : OMPC_linear); |
| 2762 | continue; |
| 2763 | } |
| 2764 | UniformedLinearThis = E; |
| 2765 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2766 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 2767 | continue; |
| 2768 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 2769 | E->getType()); |
| 2770 | continue; |
| 2771 | } |
| 2772 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2773 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2774 | } |
| 2775 | Expr *Step = nullptr; |
| 2776 | Expr *NewStep = nullptr; |
| 2777 | SmallVector<Expr *, 4> NewSteps; |
| 2778 | for (auto *E : Steps) { |
| 2779 | // Skip the same step expression, it was checked already. |
| 2780 | if (Step == E || !E) { |
| 2781 | NewSteps.push_back(E ? NewStep : nullptr); |
| 2782 | continue; |
| 2783 | } |
| 2784 | Step = E; |
| 2785 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 2786 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2787 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2788 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 2789 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 2790 | << Step->getSourceRange(); |
| 2791 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 2792 | E->isInstantiationDependent() || |
| 2793 | E->containsUnexpandedParameterPack() || |
| 2794 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 2795 | NewSteps.push_back(Step); |
| 2796 | else { |
| 2797 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 2798 | << Step->getSourceRange(); |
| 2799 | } |
| 2800 | continue; |
| 2801 | } |
| 2802 | NewStep = Step; |
| 2803 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 2804 | !Step->isInstantiationDependent() && |
| 2805 | !Step->containsUnexpandedParameterPack()) { |
| 2806 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 2807 | .get(); |
| 2808 | if (NewStep) |
| 2809 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 2810 | } |
| 2811 | NewSteps.push_back(NewStep); |
| 2812 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2813 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 2814 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2815 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2816 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 2817 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 2818 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 2819 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2820 | ADecl->addAttr(NewAttr); |
| 2821 | return ConvertDeclToDeclGroup(ADecl); |
| 2822 | } |
| 2823 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2824 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2825 | Stmt *AStmt, |
| 2826 | SourceLocation StartLoc, |
| 2827 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2828 | if (!AStmt) |
| 2829 | return StmtError(); |
| 2830 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2831 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2832 | // 1.2.2 OpenMP Language Terminology |
| 2833 | // Structured block - An executable statement with a single entry at the |
| 2834 | // top and a single exit at the bottom. |
| 2835 | // The point of exit cannot be a branch out of the structured block. |
| 2836 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2837 | CS->getCapturedDecl()->setNothrow(); |
| 2838 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2839 | getCurFunction()->setHasBranchProtectedScope(); |
| 2840 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2841 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2842 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2843 | } |
| 2844 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2845 | namespace { |
| 2846 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2847 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2848 | /// for IR generation. |
| 2849 | class OpenMPIterationSpaceChecker { |
| 2850 | /// \brief Reference to Sema. |
| 2851 | Sema &SemaRef; |
| 2852 | /// \brief A location for diagnostics (when there is no some better location). |
| 2853 | SourceLocation DefaultLoc; |
| 2854 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2855 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2856 | /// \brief A source location for referring to loop init later. |
| 2857 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2858 | /// \brief A source location for referring to condition later. |
| 2859 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2860 | /// \brief A source location for referring to increment later. |
| 2861 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2862 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2863 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2864 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2865 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2866 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2867 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2868 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2869 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2870 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2871 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2872 | /// \brief This flag is true when condition is one of: |
| 2873 | /// Var < UB |
| 2874 | /// Var <= UB |
| 2875 | /// UB > Var |
| 2876 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2877 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2878 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2879 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2880 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2881 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2882 | |
| 2883 | public: |
| 2884 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2885 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2886 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2887 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2888 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2889 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2890 | /// for less/greater and for strict/non-strict comparison. |
| 2891 | bool CheckCond(Expr *S); |
| 2892 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2893 | /// does not conform, otherwise save loop step (#Step). |
| 2894 | bool CheckInc(Expr *S); |
| 2895 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2896 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2897 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2898 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2899 | /// \brief Source range of the loop init. |
| 2900 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2901 | /// \brief Source range of the loop condition. |
| 2902 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2903 | /// \brief Source range of the loop increment. |
| 2904 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2905 | /// \brief True if the step should be subtracted. |
| 2906 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2907 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2908 | Expr * |
| 2909 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 2910 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2911 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2912 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 2913 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2914 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 2915 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 2916 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2917 | /// \brief Build reference expression to the private counter be used for |
| 2918 | /// codegen. |
| 2919 | Expr *BuildPrivateCounterVar() const; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2920 | /// \brief Build initialization of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2921 | Expr *BuildCounterInit() const; |
| 2922 | /// \brief Build step of the counter be used for codegen. |
| 2923 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2924 | /// \brief Return true if any expression is dependent. |
| 2925 | bool Dependent() const; |
| 2926 | |
| 2927 | private: |
| 2928 | /// \brief Check the right-hand side of an assignment in the increment |
| 2929 | /// expression. |
| 2930 | bool CheckIncRHS(Expr *RHS); |
| 2931 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2932 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2933 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2934 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2935 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2936 | /// \brief Helper to set loop increment. |
| 2937 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2938 | }; |
| 2939 | |
| 2940 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2941 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2942 | assert(!LB && !UB && !Step); |
| 2943 | return false; |
| 2944 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2945 | return LCDecl->getType()->isDependentType() || |
| 2946 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 2947 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2948 | } |
| 2949 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2950 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2951 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2952 | E = ExprTemp->getSubExpr(); |
| 2953 | |
| 2954 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2955 | E = MTE->GetTemporaryExpr(); |
| 2956 | |
| 2957 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2958 | E = Binder->getSubExpr(); |
| 2959 | |
| 2960 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2961 | E = ICE->getSubExprAsWritten(); |
| 2962 | return E->IgnoreParens(); |
| 2963 | } |
| 2964 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2965 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 2966 | Expr *NewLCRefExpr, |
| 2967 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2968 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2969 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2970 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2971 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2972 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2973 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 2974 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2975 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2976 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2977 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2978 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2979 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2980 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2981 | LB = NewLB; |
| 2982 | return false; |
| 2983 | } |
| 2984 | |
| 2985 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2986 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2987 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2988 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 2989 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2990 | if (!NewUB) |
| 2991 | return true; |
| 2992 | UB = NewUB; |
| 2993 | TestIsLessOp = LessOp; |
| 2994 | TestIsStrictOp = StrictOp; |
| 2995 | ConditionSrcRange = SR; |
| 2996 | ConditionLoc = SL; |
| 2997 | return false; |
| 2998 | } |
| 2999 | |
| 3000 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 3001 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3002 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3003 | if (!NewStep) |
| 3004 | return true; |
| 3005 | if (!NewStep->isValueDependent()) { |
| 3006 | // Check that the step is integer expression. |
| 3007 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 3008 | ExprResult Val = |
| 3009 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 3010 | if (Val.isInvalid()) |
| 3011 | return true; |
| 3012 | NewStep = Val.get(); |
| 3013 | |
| 3014 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 3015 | // If test-expr is of form var relational-op b and relational-op is < or |
| 3016 | // <= then incr-expr must cause var to increase on each iteration of the |
| 3017 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 3018 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 3019 | // the loop. |
| 3020 | // If test-expr is of form b relational-op var and relational-op is < or |
| 3021 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 3022 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 3023 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 3024 | // the loop. |
| 3025 | llvm::APSInt Result; |
| 3026 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 3027 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 3028 | bool IsConstNeg = |
| 3029 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3030 | bool IsConstPos = |
| 3031 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3032 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 3033 | if (UB && (IsConstZero || |
| 3034 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3035 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3036 | SemaRef.Diag(NewStep->getExprLoc(), |
| 3037 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3038 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3039 | SemaRef.Diag(ConditionLoc, |
| 3040 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3041 | << TestIsLessOp << ConditionSrcRange; |
| 3042 | return true; |
| 3043 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3044 | if (TestIsLessOp == Subtract) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3045 | NewStep = |
| 3046 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 3047 | .get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3048 | Subtract = !Subtract; |
| 3049 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | Step = NewStep; |
| 3053 | SubtractStep = Subtract; |
| 3054 | return false; |
| 3055 | } |
| 3056 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3057 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3058 | // Check init-expr for canonical loop form and save loop counter |
| 3059 | // variable - #Var and its initialization value - #LB. |
| 3060 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3061 | // var = lb |
| 3062 | // integer-type var = lb |
| 3063 | // random-access-iterator-type var = lb |
| 3064 | // pointer-type var = lb |
| 3065 | // |
| 3066 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3067 | if (EmitDiags) { |
| 3068 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3069 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3070 | return true; |
| 3071 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3072 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3073 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3074 | S = ExprTemp->getSubExpr(); |
| 3075 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3076 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3077 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3078 | S = E->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3079 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3080 | if (BO->getOpcode() == BO_Assign) { |
| 3081 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3082 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3083 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3084 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3085 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3086 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3087 | } |
| 3088 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3089 | if (ME->isArrow() && |
| 3090 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3091 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3092 | } |
| 3093 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3094 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3095 | if (DS->isSingleDecl()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3096 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3097 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3098 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3099 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3100 | SemaRef.Diag(S->getLocStart(), |
| 3101 | diag::ext_omp_loop_not_canonical_init) |
| 3102 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3103 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3104 | } |
| 3105 | } |
| 3106 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3107 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3108 | if (CE->getOperator() == OO_Equal) { |
| 3109 | auto *LHS = CE->getArg(0); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3110 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3111 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3112 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3113 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3114 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3115 | } |
| 3116 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3117 | if (ME->isArrow() && |
| 3118 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3119 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3120 | } |
| 3121 | } |
| 3122 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3123 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3124 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3125 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3126 | if (EmitDiags) { |
| 3127 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3128 | << S->getSourceRange(); |
| 3129 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3130 | return true; |
| 3131 | } |
| 3132 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3133 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3134 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3135 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3136 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3137 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3138 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3139 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3140 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3141 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3142 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3143 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3144 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3145 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3146 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 3147 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 3148 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3149 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3150 | return getCanonicalDecl(VD); |
| 3151 | } |
| 3152 | } |
| 3153 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3154 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3155 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3156 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3160 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3161 | // less/greater and for strict/non-strict comparison. |
| 3162 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3163 | // var relational-op b |
| 3164 | // b relational-op var |
| 3165 | // |
| 3166 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3167 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3168 | return true; |
| 3169 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3170 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3171 | SourceLocation CondLoc = S->getLocStart(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3172 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3173 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3174 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3175 | return SetUB(BO->getRHS(), |
| 3176 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3177 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3178 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3179 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3180 | return SetUB(BO->getLHS(), |
| 3181 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3182 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3183 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3184 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3185 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | if (CE->getNumArgs() == 2) { |
| 3187 | auto Op = CE->getOperator(); |
| 3188 | switch (Op) { |
| 3189 | case OO_Greater: |
| 3190 | case OO_GreaterEqual: |
| 3191 | case OO_Less: |
| 3192 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3193 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3194 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3195 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3196 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3197 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3198 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3199 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3200 | CE->getOperatorLoc()); |
| 3201 | break; |
| 3202 | default: |
| 3203 | break; |
| 3204 | } |
| 3205 | } |
| 3206 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3207 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3208 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3209 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3210 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3211 | return true; |
| 3212 | } |
| 3213 | |
| 3214 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3215 | // RHS of canonical loop form increment can be: |
| 3216 | // var + incr |
| 3217 | // incr + var |
| 3218 | // var - incr |
| 3219 | // |
| 3220 | RHS = RHS->IgnoreParenImpCasts(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3221 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3222 | if (BO->isAdditiveOp()) { |
| 3223 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3224 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3225 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3226 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3227 | return SetStep(BO->getLHS(), false); |
| 3228 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3229 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3230 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3231 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3232 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3233 | return SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3234 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3235 | return SetStep(CE->getArg(0), false); |
| 3236 | } |
| 3237 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3238 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3239 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3240 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3241 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3242 | return true; |
| 3243 | } |
| 3244 | |
| 3245 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3246 | // Check incr-expr for canonical loop form and return true if it |
| 3247 | // does not conform. |
| 3248 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3249 | // ++var |
| 3250 | // var++ |
| 3251 | // --var |
| 3252 | // var-- |
| 3253 | // var += incr |
| 3254 | // var -= incr |
| 3255 | // var = var + incr |
| 3256 | // var = incr + var |
| 3257 | // var = var - incr |
| 3258 | // |
| 3259 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3260 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3261 | return true; |
| 3262 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3263 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3264 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3265 | S = ExprTemp->getSubExpr(); |
| 3266 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3267 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3268 | S = S->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3269 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3270 | if (UO->isIncrementDecrementOp() && |
| 3271 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3272 | return SetStep(SemaRef |
| 3273 | .ActOnIntegerConstant(UO->getLocStart(), |
| 3274 | (UO->isDecrementOp() ? -1 : 1)) |
| 3275 | .get(), |
| 3276 | false); |
| 3277 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3278 | switch (BO->getOpcode()) { |
| 3279 | case BO_AddAssign: |
| 3280 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3281 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3282 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3283 | break; |
| 3284 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3285 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3286 | return CheckIncRHS(BO->getRHS()); |
| 3287 | break; |
| 3288 | default: |
| 3289 | break; |
| 3290 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3291 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3292 | switch (CE->getOperator()) { |
| 3293 | case OO_PlusPlus: |
| 3294 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3295 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3296 | return SetStep(SemaRef |
| 3297 | .ActOnIntegerConstant( |
| 3298 | CE->getLocStart(), |
| 3299 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 3300 | .get(), |
| 3301 | false); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3302 | break; |
| 3303 | case OO_PlusEqual: |
| 3304 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3305 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3306 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3307 | break; |
| 3308 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3309 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3310 | return CheckIncRHS(CE->getArg(1)); |
| 3311 | break; |
| 3312 | default: |
| 3313 | break; |
| 3314 | } |
| 3315 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3316 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3317 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3318 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3319 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3320 | return true; |
| 3321 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3322 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3323 | static ExprResult |
| 3324 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3325 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 3326 | if (SemaRef.CurContext->isDependentContext()) |
| 3327 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3328 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3329 | return SemaRef.PerformImplicitConversion( |
| 3330 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3331 | /*AllowExplicit=*/true); |
| 3332 | auto I = Captures.find(Capture); |
| 3333 | if (I != Captures.end()) |
| 3334 | return buildCapture(SemaRef, Capture, I->second); |
| 3335 | DeclRefExpr *Ref = nullptr; |
| 3336 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3337 | Captures[Capture] = Ref; |
| 3338 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3339 | } |
| 3340 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3341 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3342 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3343 | Scope *S, const bool LimitedType, |
| 3344 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3345 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3346 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3347 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3348 | SemaRef.getLangOpts().CPlusPlus) { |
| 3349 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3350 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3351 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3352 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3353 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3354 | if (!Upper || !Lower) |
| 3355 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3356 | |
| 3357 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3358 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3359 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3360 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3361 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3362 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3363 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3364 | return nullptr; |
| 3365 | } |
| 3366 | } |
| 3367 | |
| 3368 | if (!Diff.isUsable()) |
| 3369 | return nullptr; |
| 3370 | |
| 3371 | // Upper - Lower [- 1] |
| 3372 | if (TestIsStrictOp) |
| 3373 | Diff = SemaRef.BuildBinOp( |
| 3374 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3375 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3376 | if (!Diff.isUsable()) |
| 3377 | return nullptr; |
| 3378 | |
| 3379 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3380 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3381 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3382 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3383 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3384 | if (!Diff.isUsable()) |
| 3385 | return nullptr; |
| 3386 | |
| 3387 | // Parentheses (for dumping/debugging purposes only). |
| 3388 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3389 | if (!Diff.isUsable()) |
| 3390 | return nullptr; |
| 3391 | |
| 3392 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3393 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3394 | if (!Diff.isUsable()) |
| 3395 | return nullptr; |
| 3396 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3397 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3398 | QualType Type = Diff.get()->getType(); |
| 3399 | auto &C = SemaRef.Context; |
| 3400 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3401 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3402 | if (!Type->isIntegerType() || UseVarType) { |
| 3403 | unsigned NewSize = |
| 3404 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3405 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3406 | : Type->hasSignedIntegerRepresentation(); |
| 3407 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3408 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3409 | Diff = SemaRef.PerformImplicitConversion( |
| 3410 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3411 | if (!Diff.isUsable()) |
| 3412 | return nullptr; |
| 3413 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3414 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3415 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3416 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3417 | if (NewSize != C.getTypeSize(Type)) { |
| 3418 | if (NewSize < C.getTypeSize(Type)) { |
| 3419 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3420 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3421 | << InitSrcRange << ConditionSrcRange; |
| 3422 | } |
| 3423 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3424 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3425 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3426 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3427 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3428 | Sema::AA_Converting, true); |
| 3429 | if (!Diff.isUsable()) |
| 3430 | return nullptr; |
| 3431 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3432 | } |
| 3433 | } |
| 3434 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3435 | return Diff.get(); |
| 3436 | } |
| 3437 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3438 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3439 | Scope *S, Expr *Cond, |
| 3440 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3441 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3442 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3443 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3444 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3445 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3446 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3447 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3448 | return nullptr; |
| 3449 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3450 | auto CondExpr = SemaRef.BuildBinOp( |
| 3451 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3452 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3453 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3454 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3455 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3456 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3457 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3458 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3459 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3460 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3461 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3462 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3463 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3464 | } |
| 3465 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3466 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3467 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3468 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3469 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 3470 | if (!VD) { |
| 3471 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 3472 | auto *Ref = buildDeclRefExpr( |
| 3473 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3474 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 3475 | // If the loop control decl is explicitly marked as private, do not mark it |
| 3476 | // as captured again. |
| 3477 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 3478 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3479 | return Ref; |
| 3480 | } |
| 3481 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3482 | DefaultLoc); |
| 3483 | } |
| 3484 | |
| 3485 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3486 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 3487 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3488 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3489 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 3490 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3491 | if (PrivateVar->isInvalidDecl()) |
| 3492 | return nullptr; |
| 3493 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3494 | } |
| 3495 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3496 | } |
| 3497 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 3498 | /// \brief Build initialization of the counter to be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3499 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3500 | |
| 3501 | /// \brief Build step of the counter be used for codegen. |
| 3502 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3503 | |
| 3504 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3505 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3506 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3507 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3508 | /// \brief This expression calculates the number of iterations in the loop. |
| 3509 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3510 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3511 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3512 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3513 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3514 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3515 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3516 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3517 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3518 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3519 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3520 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3521 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3522 | /// \brief Source range of the loop init. |
| 3523 | SourceRange InitSrcRange; |
| 3524 | /// \brief Source range of the loop condition. |
| 3525 | SourceRange CondSrcRange; |
| 3526 | /// \brief Source range of the loop increment. |
| 3527 | SourceRange IncSrcRange; |
| 3528 | }; |
| 3529 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3530 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3531 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3532 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3533 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3534 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3535 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3536 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3537 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3538 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3539 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3540 | if (auto *D = ISC.GetLoopDecl()) { |
| 3541 | auto *VD = dyn_cast<VarDecl>(D); |
| 3542 | if (!VD) { |
| 3543 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 3544 | VD = Private; |
| 3545 | else { |
| 3546 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 3547 | /*WithInit=*/false); |
| 3548 | VD = cast<VarDecl>(Ref->getDecl()); |
| 3549 | } |
| 3550 | } |
| 3551 | DSAStack->addLoopControlVariable(D, VD); |
| 3552 | } |
| 3553 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3554 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3555 | } |
| 3556 | } |
| 3557 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3558 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3559 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3560 | static bool CheckOpenMPIterationSpace( |
| 3561 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3562 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3563 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3564 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3565 | LoopIterationSpace &ResultIterSpace, |
| 3566 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3567 | // OpenMP [2.6, Canonical Loop Form] |
| 3568 | // for (init-expr; test-expr; incr-expr) structured-block |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3569 | auto *For = dyn_cast_or_null<ForStmt>(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3570 | if (!For) { |
| 3571 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3572 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3573 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3574 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3575 | if (NestedLoopCount > 1) { |
| 3576 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3577 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3578 | diag::note_omp_collapse_ordered_expr) |
| 3579 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3580 | << OrderedLoopCountExpr->getSourceRange(); |
| 3581 | else if (CollapseLoopCountExpr) |
| 3582 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3583 | diag::note_omp_collapse_ordered_expr) |
| 3584 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3585 | else |
| 3586 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3587 | diag::note_omp_collapse_ordered_expr) |
| 3588 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3589 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3590 | return true; |
| 3591 | } |
| 3592 | assert(For->getBody()); |
| 3593 | |
| 3594 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3595 | |
| 3596 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3597 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3598 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3599 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3600 | |
| 3601 | bool HasErrors = false; |
| 3602 | |
| 3603 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3604 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 3605 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3606 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3607 | // OpenMP [2.6, Canonical Loop Form] |
| 3608 | // Var is one of the following: |
| 3609 | // A variable of signed or unsigned integer type. |
| 3610 | // For C++, a variable of a random access iterator type. |
| 3611 | // For C, a variable of a pointer type. |
| 3612 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 3613 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3614 | !VarType->isPointerType() && |
| 3615 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3616 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3617 | << SemaRef.getLangOpts().CPlusPlus; |
| 3618 | HasErrors = true; |
| 3619 | } |
| 3620 | |
| 3621 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 3622 | // a Construct |
| 3623 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3624 | // parallel for construct is (are) private. |
| 3625 | // The loop iteration variable in the associated for-loop of a simd |
| 3626 | // construct with just one associated for-loop is linear with a |
| 3627 | // constant-linear-step that is the increment of the associated for-loop. |
| 3628 | // Exclude loop var from the list of variables with implicitly defined data |
| 3629 | // sharing attributes. |
| 3630 | VarsWithImplicitDSA.erase(LCDecl); |
| 3631 | |
| 3632 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 3633 | // in a Construct, C/C++]. |
| 3634 | // The loop iteration variable in the associated for-loop of a simd |
| 3635 | // construct with just one associated for-loop may be listed in a linear |
| 3636 | // clause with a constant-linear-step that is the increment of the |
| 3637 | // associated for-loop. |
| 3638 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3639 | // parallel for construct may be listed in a private or lastprivate clause. |
| 3640 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 3641 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3642 | // declared in the loop and it is predetermined as a private. |
| 3643 | auto PredeterminedCKind = |
| 3644 | isOpenMPSimdDirective(DKind) |
| 3645 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3646 | : OMPC_private; |
| 3647 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3648 | DVar.CKind != PredeterminedCKind) || |
| 3649 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3650 | isOpenMPDistributeDirective(DKind)) && |
| 3651 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3652 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3653 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 3654 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 3655 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3656 | << getOpenMPClauseName(PredeterminedCKind); |
| 3657 | if (DVar.RefExpr == nullptr) |
| 3658 | DVar.CKind = PredeterminedCKind; |
| 3659 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 3660 | HasErrors = true; |
| 3661 | } else if (LoopDeclRefExpr != nullptr) { |
| 3662 | // Make the loop iteration variable private (for worksharing constructs), |
| 3663 | // linear (for simd directives with the only one associated loop) or |
| 3664 | // lastprivate (for simd directives with several collapsed or ordered |
| 3665 | // loops). |
| 3666 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3667 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 3668 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3669 | /*FromParent=*/false); |
| 3670 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 3671 | } |
| 3672 | |
| 3673 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 3674 | |
| 3675 | // Check test-expr. |
| 3676 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3677 | |
| 3678 | // Check incr-expr. |
| 3679 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3682 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3683 | return HasErrors; |
| 3684 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3685 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3686 | ResultIterSpace.PreCond = |
| 3687 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3688 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3689 | DSA.getCurScope(), |
| 3690 | (isOpenMPWorksharingDirective(DKind) || |
| 3691 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 3692 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3693 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3694 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3695 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3696 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3697 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3698 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3699 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3700 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3701 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3702 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3703 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3704 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3705 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3706 | ResultIterSpace.CounterInit == nullptr || |
| 3707 | ResultIterSpace.CounterStep == nullptr); |
| 3708 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3709 | return HasErrors; |
| 3710 | } |
| 3711 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3712 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3713 | static ExprResult |
| 3714 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 3715 | ExprResult Start, |
| 3716 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3717 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3718 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 3719 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3720 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3721 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3722 | VarRef.get()->getType())) { |
| 3723 | NewStart = SemaRef.PerformImplicitConversion( |
| 3724 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3725 | /*AllowExplicit=*/true); |
| 3726 | if (!NewStart.isUsable()) |
| 3727 | return ExprError(); |
| 3728 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3729 | |
| 3730 | auto Init = |
| 3731 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3732 | return Init; |
| 3733 | } |
| 3734 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3735 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3736 | static ExprResult |
| 3737 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3738 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 3739 | ExprResult Step, bool Subtract, |
| 3740 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3741 | // Add parentheses (for debugging purposes only). |
| 3742 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3743 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3744 | !Step.isUsable()) |
| 3745 | return ExprError(); |
| 3746 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3747 | ExprResult NewStep = Step; |
| 3748 | if (Captures) |
| 3749 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3750 | if (NewStep.isInvalid()) |
| 3751 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3752 | ExprResult Update = |
| 3753 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3754 | if (!Update.isUsable()) |
| 3755 | return ExprError(); |
| 3756 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3757 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 3758 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3759 | ExprResult NewStart = Start; |
| 3760 | if (Captures) |
| 3761 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3762 | if (NewStart.isInvalid()) |
| 3763 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3764 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3765 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 3766 | ExprResult SavedUpdate = Update; |
| 3767 | ExprResult UpdateVal; |
| 3768 | if (VarRef.get()->getType()->isOverloadableType() || |
| 3769 | NewStart.get()->getType()->isOverloadableType() || |
| 3770 | Update.get()->getType()->isOverloadableType()) { |
| 3771 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3772 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 3773 | Update = |
| 3774 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3775 | if (Update.isUsable()) { |
| 3776 | UpdateVal = |
| 3777 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 3778 | VarRef.get(), SavedUpdate.get()); |
| 3779 | if (UpdateVal.isUsable()) { |
| 3780 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 3781 | UpdateVal.get()); |
| 3782 | } |
| 3783 | } |
| 3784 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3785 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3786 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3787 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 3788 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 3789 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 3790 | NewStart.get(), SavedUpdate.get()); |
| 3791 | if (!Update.isUsable()) |
| 3792 | return ExprError(); |
| 3793 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3794 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 3795 | VarRef.get()->getType())) { |
| 3796 | Update = SemaRef.PerformImplicitConversion( |
| 3797 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3798 | if (!Update.isUsable()) |
| 3799 | return ExprError(); |
| 3800 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3801 | |
| 3802 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3803 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3804 | return Update; |
| 3805 | } |
| 3806 | |
| 3807 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3808 | /// bits. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3809 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3810 | if (E == nullptr) |
| 3811 | return ExprError(); |
| 3812 | auto &C = SemaRef.Context; |
| 3813 | QualType OldType = E->getType(); |
| 3814 | unsigned HasBits = C.getTypeSize(OldType); |
| 3815 | if (HasBits >= Bits) |
| 3816 | return ExprResult(E); |
| 3817 | // OK to convert to signed, because new type has more bits than old. |
| 3818 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3819 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3820 | true); |
| 3821 | } |
| 3822 | |
| 3823 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3824 | /// into \a Bits bits. |
| 3825 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3826 | if (E == nullptr) |
| 3827 | return false; |
| 3828 | llvm::APSInt Result; |
| 3829 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3830 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3831 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3834 | /// Build preinits statement for the given declarations. |
| 3835 | static Stmt *buildPreInits(ASTContext &Context, |
| 3836 | SmallVectorImpl<Decl *> &PreInits) { |
| 3837 | if (!PreInits.empty()) { |
| 3838 | return new (Context) DeclStmt( |
| 3839 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 3840 | SourceLocation(), SourceLocation()); |
| 3841 | } |
| 3842 | return nullptr; |
| 3843 | } |
| 3844 | |
| 3845 | /// Build preinits statement for the given declarations. |
| 3846 | static Stmt *buildPreInits(ASTContext &Context, |
| 3847 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3848 | if (!Captures.empty()) { |
| 3849 | SmallVector<Decl *, 16> PreInits; |
| 3850 | for (auto &Pair : Captures) |
| 3851 | PreInits.push_back(Pair.second->getDecl()); |
| 3852 | return buildPreInits(Context, PreInits); |
| 3853 | } |
| 3854 | return nullptr; |
| 3855 | } |
| 3856 | |
| 3857 | /// Build postupdate expression for the given list of postupdates expressions. |
| 3858 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 3859 | Expr *PostUpdate = nullptr; |
| 3860 | if (!PostUpdates.empty()) { |
| 3861 | for (auto *E : PostUpdates) { |
| 3862 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 3863 | E->getExprLoc(), |
| 3864 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 3865 | E->getExprLoc(), E) |
| 3866 | .get(); |
| 3867 | PostUpdate = PostUpdate |
| 3868 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 3869 | PostUpdate, ConvE) |
| 3870 | .get() |
| 3871 | : ConvE; |
| 3872 | } |
| 3873 | } |
| 3874 | return PostUpdate; |
| 3875 | } |
| 3876 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3877 | /// \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] | 3878 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3879 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3880 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3881 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3882 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3883 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3884 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3885 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3886 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3887 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3888 | // Found 'collapse' clause - calculate collapse number. |
| 3889 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3890 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3891 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3892 | } |
| 3893 | if (OrderedLoopCountExpr) { |
| 3894 | // Found 'ordered' clause - calculate collapse number. |
| 3895 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3896 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3897 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3898 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3899 | diag::err_omp_wrong_ordered_loop_count) |
| 3900 | << OrderedLoopCountExpr->getSourceRange(); |
| 3901 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3902 | diag::note_collapse_loop_count) |
| 3903 | << CollapseLoopCountExpr->getSourceRange(); |
| 3904 | } |
| 3905 | NestedLoopCount = Result.getLimitedValue(); |
| 3906 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3907 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3908 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3909 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3910 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3911 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3912 | IterSpaces.resize(NestedLoopCount); |
| 3913 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3914 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3915 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3916 | NestedLoopCount, CollapseLoopCountExpr, |
| 3917 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3918 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3919 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3920 | // 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] | 3921 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3922 | // All loops associated with the construct must be perfectly nested; that |
| 3923 | // is, there must be no intervening code nor any OpenMP directive between |
| 3924 | // any two loops. |
| 3925 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3926 | } |
| 3927 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3928 | Built.clear(/* size */ NestedLoopCount); |
| 3929 | |
| 3930 | if (SemaRef.CurContext->isDependentContext()) |
| 3931 | return NestedLoopCount; |
| 3932 | |
| 3933 | // An example of what is generated for the following code: |
| 3934 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3935 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3936 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3937 | // for (k = 0; k < NK; ++k) |
| 3938 | // for (j = J0; j < NJ; j+=2) { |
| 3939 | // <loop body> |
| 3940 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3941 | // |
| 3942 | // We generate the code below. |
| 3943 | // Note: the loop body may be outlined in CodeGen. |
| 3944 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3945 | // iterations and operator+= to calculate counter value. |
| 3946 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3947 | // or i64 is currently supported). |
| 3948 | // |
| 3949 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3950 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3951 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3952 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3953 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3954 | // <loop body (using local i and j)> |
| 3955 | // } |
| 3956 | // i = NI; // assign final values of counters |
| 3957 | // j = NJ; |
| 3958 | // |
| 3959 | |
| 3960 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3961 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3962 | // Precondition tests if there is at least one iteration (all conditions are |
| 3963 | // true). |
| 3964 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3965 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3966 | ExprResult LastIteration32 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3967 | 32 /* Bits */, SemaRef |
| 3968 | .PerformImplicitConversion( |
| 3969 | N0->IgnoreImpCasts(), N0->getType(), |
| 3970 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3971 | .get(), |
| 3972 | SemaRef); |
| 3973 | ExprResult LastIteration64 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3974 | 64 /* Bits */, SemaRef |
| 3975 | .PerformImplicitConversion( |
| 3976 | N0->IgnoreImpCasts(), N0->getType(), |
| 3977 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3978 | .get(), |
| 3979 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3980 | |
| 3981 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3982 | return NestedLoopCount; |
| 3983 | |
| 3984 | auto &C = SemaRef.Context; |
| 3985 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3986 | |
| 3987 | Scope *CurScope = DSA.getCurScope(); |
| 3988 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3989 | if (PreCond.isUsable()) { |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3990 | PreCond = |
| 3991 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 3992 | PreCond.get(), IterSpaces[Cnt].PreCond); |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3993 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3994 | auto N = IterSpaces[Cnt].NumIterations; |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3995 | SourceLocation Loc = N->getExprLoc(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3996 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3997 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3998 | LastIteration32 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3999 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4000 | SemaRef |
| 4001 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4002 | Sema::AA_Converting, |
| 4003 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4004 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4005 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4006 | LastIteration64 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4007 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4008 | SemaRef |
| 4009 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 4010 | Sema::AA_Converting, |
| 4011 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4012 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | // Choose either the 32-bit or 64-bit version. |
| 4016 | ExprResult LastIteration = LastIteration64; |
| 4017 | if (LastIteration32.isUsable() && |
| 4018 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 4019 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 4020 | FitsInto( |
| 4021 | 32 /* Bits */, |
| 4022 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 4023 | LastIteration64.get(), SemaRef))) |
| 4024 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4025 | QualType VType = LastIteration.get()->getType(); |
| 4026 | QualType RealVType = VType; |
| 4027 | QualType StrideVType = VType; |
| 4028 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 4029 | VType = |
| 4030 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 4031 | StrideVType = |
| 4032 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 4033 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4034 | |
| 4035 | if (!LastIteration.isUsable()) |
| 4036 | return 0; |
| 4037 | |
| 4038 | // Save the number of iterations. |
| 4039 | ExprResult NumIterations = LastIteration; |
| 4040 | { |
| 4041 | LastIteration = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4042 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 4043 | LastIteration.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4044 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4045 | if (!LastIteration.isUsable()) |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | // Calculate the last iteration number beforehand instead of doing this on |
| 4050 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4051 | llvm::APSInt Result; |
| 4052 | bool IsConstant = |
| 4053 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4054 | ExprResult CalcLastIteration; |
| 4055 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4056 | ExprResult SaveRef = |
| 4057 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4058 | LastIteration = SaveRef; |
| 4059 | |
| 4060 | // Prepare SaveRef + 1. |
| 4061 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4062 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4063 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4064 | if (!NumIterations.isUsable()) |
| 4065 | return 0; |
| 4066 | } |
| 4067 | |
| 4068 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4069 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4070 | // Build variables passed into runtime, necessary for worksharing directives. |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4071 | ExprResult LB, UB, IL, ST, EUB, CombLB, CombUB, PrevLB, PrevUB, CombEUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4072 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4073 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4074 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4075 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4076 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4077 | SemaRef.AddInitializerToDecl(LBDecl, |
| 4078 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4079 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4080 | |
| 4081 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4082 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4083 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4084 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4085 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4086 | |
| 4087 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4088 | // This will be used to implement clause 'lastprivate'. |
| 4089 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4090 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4091 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4092 | SemaRef.AddInitializerToDecl(ILDecl, |
| 4093 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4094 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4095 | |
| 4096 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4097 | VarDecl *STDecl = |
| 4098 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 4099 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4100 | SemaRef.AddInitializerToDecl(STDecl, |
| 4101 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4102 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4103 | |
| 4104 | // Build expression: UB = min(UB, LastIteration) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4105 | // It is necessary for CodeGen of directives with static scheduling. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4106 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4107 | UB.get(), LastIteration.get()); |
| 4108 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4109 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4110 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4111 | CondOp.get()); |
| 4112 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4113 | |
| 4114 | // If we have a combined directive that combines 'distribute', 'for' or |
| 4115 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 4116 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 4117 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 4118 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4119 | |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4120 | // Lower bound variable, initialized with zero. |
| 4121 | VarDecl *CombLBDecl = |
| 4122 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.lb"); |
| 4123 | CombLB = buildDeclRefExpr(SemaRef, CombLBDecl, VType, InitLoc); |
| 4124 | SemaRef.AddInitializerToDecl( |
| 4125 | CombLBDecl, SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4126 | /*DirectInit*/ false); |
| 4127 | |
| 4128 | // Upper bound variable, initialized with last iteration number. |
| 4129 | VarDecl *CombUBDecl = |
| 4130 | buildVarDecl(SemaRef, InitLoc, VType, ".omp.comb.ub"); |
| 4131 | CombUB = buildDeclRefExpr(SemaRef, CombUBDecl, VType, InitLoc); |
| 4132 | SemaRef.AddInitializerToDecl(CombUBDecl, LastIteration.get(), |
| 4133 | /*DirectInit*/ false); |
| 4134 | |
| 4135 | ExprResult CombIsUBGreater = SemaRef.BuildBinOp( |
| 4136 | CurScope, InitLoc, BO_GT, CombUB.get(), LastIteration.get()); |
| 4137 | ExprResult CombCondOp = |
| 4138 | SemaRef.ActOnConditionalOp(InitLoc, InitLoc, CombIsUBGreater.get(), |
| 4139 | LastIteration.get(), CombUB.get()); |
| 4140 | CombEUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, CombUB.get(), |
| 4141 | CombCondOp.get()); |
| 4142 | CombEUB = SemaRef.ActOnFinishFullExpr(CombEUB.get()); |
| 4143 | |
| 4144 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4145 | // We expect to have at least 2 more parameters than the 'parallel' |
| 4146 | // directive does - the lower and upper bounds of the previous schedule. |
| 4147 | assert(CD->getNumParams() >= 4 && |
| 4148 | "Unexpected number of parameters in loop combined directive"); |
| 4149 | |
| 4150 | // Set the proper type for the bounds given what we learned from the |
| 4151 | // enclosed loops. |
| 4152 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 4153 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 4154 | |
| 4155 | // Previous lower and upper bounds are obtained from the region |
| 4156 | // parameters. |
| 4157 | PrevLB = |
| 4158 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 4159 | PrevUB = |
| 4160 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 4161 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4162 | } |
| 4163 | |
| 4164 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4165 | ExprResult IV; |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4166 | ExprResult Init, CombInit; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4167 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4168 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 4169 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4170 | Expr *RHS = |
| 4171 | (isOpenMPWorksharingDirective(DKind) || |
| 4172 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 4173 | ? LB.get() |
| 4174 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4175 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4176 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4177 | |
| 4178 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4179 | Expr *CombRHS = |
| 4180 | (isOpenMPWorksharingDirective(DKind) || |
| 4181 | isOpenMPTaskLoopDirective(DKind) || |
| 4182 | isOpenMPDistributeDirective(DKind)) |
| 4183 | ? CombLB.get() |
| 4184 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
| 4185 | CombInit = |
| 4186 | SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), CombRHS); |
| 4187 | CombInit = SemaRef.ActOnFinishFullExpr(CombInit.get()); |
| 4188 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4189 | } |
| 4190 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4191 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4192 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4193 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4194 | (isOpenMPWorksharingDirective(DKind) || |
| 4195 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4196 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4197 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4198 | NumIterations.get()); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4199 | ExprResult CombCond; |
| 4200 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4201 | CombCond = |
| 4202 | SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), CombUB.get()); |
| 4203 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4204 | // Loop increment (IV = IV + 1) |
| 4205 | SourceLocation IncLoc; |
| 4206 | ExprResult Inc = |
| 4207 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4208 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4209 | if (!Inc.isUsable()) |
| 4210 | return 0; |
| 4211 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4212 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4213 | if (!Inc.isUsable()) |
| 4214 | return 0; |
| 4215 | |
| 4216 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4217 | // Used for directives with static scheduling. |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4218 | // In combined construct, add combined version that use CombLB and CombUB |
| 4219 | // base variables for the update |
| 4220 | ExprResult NextLB, NextUB, CombNextLB, CombNextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4221 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4222 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4223 | // LB + ST |
| 4224 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4225 | if (!NextLB.isUsable()) |
| 4226 | return 0; |
| 4227 | // LB = LB + ST |
| 4228 | NextLB = |
| 4229 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4230 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4231 | if (!NextLB.isUsable()) |
| 4232 | return 0; |
| 4233 | // UB + ST |
| 4234 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4235 | if (!NextUB.isUsable()) |
| 4236 | return 0; |
| 4237 | // UB = UB + ST |
| 4238 | NextUB = |
| 4239 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4240 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4241 | if (!NextUB.isUsable()) |
| 4242 | return 0; |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4243 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4244 | CombNextLB = |
| 4245 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombLB.get(), ST.get()); |
| 4246 | if (!NextLB.isUsable()) |
| 4247 | return 0; |
| 4248 | // LB = LB + ST |
| 4249 | CombNextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombLB.get(), |
| 4250 | CombNextLB.get()); |
| 4251 | CombNextLB = SemaRef.ActOnFinishFullExpr(CombNextLB.get()); |
| 4252 | if (!CombNextLB.isUsable()) |
| 4253 | return 0; |
| 4254 | // UB + ST |
| 4255 | CombNextUB = |
| 4256 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, CombUB.get(), ST.get()); |
| 4257 | if (!CombNextUB.isUsable()) |
| 4258 | return 0; |
| 4259 | // UB = UB + ST |
| 4260 | CombNextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, CombUB.get(), |
| 4261 | CombNextUB.get()); |
| 4262 | CombNextUB = SemaRef.ActOnFinishFullExpr(CombNextUB.get()); |
| 4263 | if (!CombNextUB.isUsable()) |
| 4264 | return 0; |
| 4265 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4266 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4267 | |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4268 | // Create increment expression for distribute loop when combined in a same |
Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 4269 | // directive with for as IV = IV + ST; ensure upper bound expression based |
| 4270 | // on PrevUB instead of NumIterations - used to implement 'for' when found |
| 4271 | // in combination with 'distribute', like in 'distribute parallel for' |
| 4272 | SourceLocation DistIncLoc; |
| 4273 | ExprResult DistCond, DistInc, PrevEUB; |
| 4274 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4275 | DistCond = SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()); |
| 4276 | assert(DistCond.isUsable() && "distribute cond expr was not built"); |
| 4277 | |
| 4278 | DistInc = |
| 4279 | SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Add, IV.get(), ST.get()); |
| 4280 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 4281 | DistInc = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, IV.get(), |
| 4282 | DistInc.get()); |
| 4283 | DistInc = SemaRef.ActOnFinishFullExpr(DistInc.get()); |
| 4284 | assert(DistInc.isUsable() && "distribute inc expr was not built"); |
| 4285 | |
| 4286 | // Build expression: UB = min(UB, prevUB) for #for in composite or combined |
| 4287 | // construct |
| 4288 | SourceLocation DistEUBLoc; |
| 4289 | ExprResult IsUBGreater = |
| 4290 | SemaRef.BuildBinOp(CurScope, DistEUBLoc, BO_GT, UB.get(), PrevUB.get()); |
| 4291 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4292 | DistEUBLoc, DistEUBLoc, IsUBGreater.get(), PrevUB.get(), UB.get()); |
| 4293 | PrevEUB = SemaRef.BuildBinOp(CurScope, DistIncLoc, BO_Assign, UB.get(), |
| 4294 | CondOp.get()); |
| 4295 | PrevEUB = SemaRef.ActOnFinishFullExpr(PrevEUB.get()); |
| 4296 | } |
| 4297 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4298 | // Build updates and final values of the loop counters. |
| 4299 | bool HasErrors = false; |
| 4300 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4301 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4302 | Built.Updates.resize(NestedLoopCount); |
| 4303 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4304 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4305 | { |
| 4306 | ExprResult Div; |
| 4307 | // Go from inner nested loop to outer. |
| 4308 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4309 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4310 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4311 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4312 | // where Div is product of previous iterations' IS.NumIters. |
| 4313 | ExprResult Iter; |
| 4314 | if (Div.isUsable()) { |
| 4315 | Iter = |
| 4316 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4317 | } else { |
| 4318 | Iter = IV; |
| 4319 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4320 | "unusable div expected on first iteration only"); |
| 4321 | } |
| 4322 | |
| 4323 | if (Cnt != 0 && Iter.isUsable()) |
| 4324 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4325 | IS.NumIterations); |
| 4326 | if (!Iter.isUsable()) { |
| 4327 | HasErrors = true; |
| 4328 | break; |
| 4329 | } |
| 4330 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4331 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4332 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 4333 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 4334 | IS.CounterVar->getExprLoc(), |
| 4335 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4336 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4337 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4338 | if (!Init.isUsable()) { |
| 4339 | HasErrors = true; |
| 4340 | break; |
| 4341 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4342 | ExprResult Update = BuildCounterUpdate( |
| 4343 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4344 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4345 | if (!Update.isUsable()) { |
| 4346 | HasErrors = true; |
| 4347 | break; |
| 4348 | } |
| 4349 | |
| 4350 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4351 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4352 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4353 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4354 | if (!Final.isUsable()) { |
| 4355 | HasErrors = true; |
| 4356 | break; |
| 4357 | } |
| 4358 | |
| 4359 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4360 | if (Cnt != 0) { |
| 4361 | if (Div.isUnset()) |
| 4362 | Div = IS.NumIterations; |
| 4363 | else |
| 4364 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4365 | IS.NumIterations); |
| 4366 | |
| 4367 | // Add parentheses (for debugging purposes only). |
| 4368 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4369 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4370 | if (!Div.isUsable()) { |
| 4371 | HasErrors = true; |
| 4372 | break; |
| 4373 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4374 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4375 | } |
| 4376 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4377 | HasErrors = true; |
| 4378 | break; |
| 4379 | } |
| 4380 | // Save results |
| 4381 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4382 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4383 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4384 | Built.Updates[Cnt] = Update.get(); |
| 4385 | Built.Finals[Cnt] = Final.get(); |
| 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | if (HasErrors) |
| 4390 | return 0; |
| 4391 | |
| 4392 | // Save results |
| 4393 | Built.IterationVarRef = IV.get(); |
| 4394 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4395 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4396 | Built.CalcLastIteration = |
| 4397 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4398 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4399 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4400 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4401 | Built.Init = Init.get(); |
| 4402 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4403 | Built.LB = LB.get(); |
| 4404 | Built.UB = UB.get(); |
| 4405 | Built.IL = IL.get(); |
| 4406 | Built.ST = ST.get(); |
| 4407 | Built.EUB = EUB.get(); |
| 4408 | Built.NLB = NextLB.get(); |
| 4409 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4410 | Built.PrevLB = PrevLB.get(); |
| 4411 | Built.PrevUB = PrevUB.get(); |
Carlo Bertolli | 8429d81 | 2017-02-17 21:29:13 +0000 | [diff] [blame] | 4412 | Built.DistInc = DistInc.get(); |
| 4413 | Built.PrevEUB = PrevEUB.get(); |
Carlo Bertolli | ffafe10 | 2017-04-20 00:39:39 +0000 | [diff] [blame] | 4414 | Built.DistCombinedFields.LB = CombLB.get(); |
| 4415 | Built.DistCombinedFields.UB = CombUB.get(); |
| 4416 | Built.DistCombinedFields.EUB = CombEUB.get(); |
| 4417 | Built.DistCombinedFields.Init = CombInit.get(); |
| 4418 | Built.DistCombinedFields.Cond = CombCond.get(); |
| 4419 | Built.DistCombinedFields.NLB = CombNextLB.get(); |
| 4420 | Built.DistCombinedFields.NUB = CombNextUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4421 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4422 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 4423 | // Fill data for doacross depend clauses. |
| 4424 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 4425 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4426 | Pair.first->setCounterValue(CounterVal); |
| 4427 | else { |
| 4428 | if (NestedLoopCount != Pair.second.size() || |
| 4429 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 4430 | // Erroneous case - clause has some problems. |
| 4431 | Pair.first->setCounterValue(CounterVal); |
| 4432 | continue; |
| 4433 | } |
| 4434 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 4435 | auto I = Pair.second.rbegin(); |
| 4436 | auto IS = IterSpaces.rbegin(); |
| 4437 | auto ILM = LoopMultipliers.rbegin(); |
| 4438 | Expr *UpCounterVal = CounterVal; |
| 4439 | Expr *Multiplier = nullptr; |
| 4440 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4441 | if (I->first) { |
| 4442 | assert(IS->CounterStep); |
| 4443 | Expr *NormalizedOffset = |
| 4444 | SemaRef |
| 4445 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 4446 | I->first, IS->CounterStep) |
| 4447 | .get(); |
| 4448 | if (Multiplier) { |
| 4449 | NormalizedOffset = |
| 4450 | SemaRef |
| 4451 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 4452 | NormalizedOffset, Multiplier) |
| 4453 | .get(); |
| 4454 | } |
| 4455 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 4456 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4457 | UpCounterVal = SemaRef |
| 4458 | .BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 4459 | UpCounterVal, NormalizedOffset) |
| 4460 | .get(); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4461 | } |
| 4462 | Multiplier = *ILM; |
| 4463 | ++I; |
| 4464 | ++IS; |
| 4465 | ++ILM; |
| 4466 | } |
| 4467 | Pair.first->setCounterValue(UpCounterVal); |
| 4468 | } |
| 4469 | } |
| 4470 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4471 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4472 | } |
| 4473 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4474 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4475 | auto CollapseClauses = |
| 4476 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4477 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4478 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4479 | return nullptr; |
| 4480 | } |
| 4481 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4482 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4483 | auto OrderedClauses = |
| 4484 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4485 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4486 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4487 | return nullptr; |
| 4488 | } |
| 4489 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4490 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 4491 | const ArrayRef<OMPClause *> Clauses) { |
| 4492 | OMPSafelenClause *Safelen = nullptr; |
| 4493 | OMPSimdlenClause *Simdlen = nullptr; |
| 4494 | |
| 4495 | for (auto *Clause : Clauses) { |
| 4496 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4497 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4498 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4499 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4500 | if (Safelen && Simdlen) |
| 4501 | break; |
| 4502 | } |
| 4503 | |
| 4504 | if (Simdlen && Safelen) { |
| 4505 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4506 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 4507 | auto SafelenLength = Safelen->getSafelen(); |
| 4508 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 4509 | SimdlenLength->isInstantiationDependent() || |
| 4510 | SimdlenLength->containsUnexpandedParameterPack()) |
| 4511 | return false; |
| 4512 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 4513 | SafelenLength->isInstantiationDependent() || |
| 4514 | SafelenLength->containsUnexpandedParameterPack()) |
| 4515 | return false; |
| 4516 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 4517 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 4518 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 4519 | // If both simdlen and safelen clauses are specified, the value of the |
| 4520 | // simdlen parameter must be less than or equal to the value of the safelen |
| 4521 | // parameter. |
| 4522 | if (SimdlenRes > SafelenRes) { |
| 4523 | S.Diag(SimdlenLength->getExprLoc(), |
| 4524 | diag::err_omp_wrong_simdlen_safelen_values) |
| 4525 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 4526 | return true; |
| 4527 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4528 | } |
| 4529 | return false; |
| 4530 | } |
| 4531 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4532 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4533 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4534 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4535 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4536 | if (!AStmt) |
| 4537 | return StmtError(); |
| 4538 | |
| 4539 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4540 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4541 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4542 | // define the nested loops number. |
| 4543 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4544 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4545 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4546 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4547 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4548 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4549 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4550 | "omp simd loop exprs were not built"); |
| 4551 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4552 | if (!CurContext->isDependentContext()) { |
| 4553 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4554 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4555 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4556 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4557 | B.NumIterations, *this, CurScope, |
| 4558 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4559 | return StmtError(); |
| 4560 | } |
| 4561 | } |
| 4562 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4563 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4564 | return StmtError(); |
| 4565 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4566 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4567 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4568 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4569 | } |
| 4570 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4571 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4572 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4573 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4574 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4575 | if (!AStmt) |
| 4576 | return StmtError(); |
| 4577 | |
| 4578 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4579 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4580 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4581 | // define the nested loops number. |
| 4582 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4583 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4584 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4585 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4586 | return StmtError(); |
| 4587 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4588 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4589 | "omp for loop exprs were not built"); |
| 4590 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4591 | if (!CurContext->isDependentContext()) { |
| 4592 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4593 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4594 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4595 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4596 | B.NumIterations, *this, CurScope, |
| 4597 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4598 | return StmtError(); |
| 4599 | } |
| 4600 | } |
| 4601 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4602 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4603 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4604 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4605 | } |
| 4606 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4607 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4608 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4609 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4610 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4611 | if (!AStmt) |
| 4612 | return StmtError(); |
| 4613 | |
| 4614 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4615 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4616 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4617 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4618 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4619 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4620 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4621 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4622 | if (NestedLoopCount == 0) |
| 4623 | return StmtError(); |
| 4624 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4625 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4626 | "omp for simd loop exprs were not built"); |
| 4627 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4628 | if (!CurContext->isDependentContext()) { |
| 4629 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4630 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4631 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4632 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4633 | B.NumIterations, *this, CurScope, |
| 4634 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4635 | return StmtError(); |
| 4636 | } |
| 4637 | } |
| 4638 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4639 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4640 | return StmtError(); |
| 4641 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4642 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4643 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4644 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4647 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4648 | Stmt *AStmt, |
| 4649 | SourceLocation StartLoc, |
| 4650 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4651 | if (!AStmt) |
| 4652 | return StmtError(); |
| 4653 | |
| 4654 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4655 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4656 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4657 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4658 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4659 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4660 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4661 | return StmtError(); |
| 4662 | // All associated statements must be '#pragma omp section' except for |
| 4663 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4664 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4665 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4666 | if (SectionStmt) |
| 4667 | Diag(SectionStmt->getLocStart(), |
| 4668 | diag::err_omp_sections_substmt_not_section); |
| 4669 | return StmtError(); |
| 4670 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4671 | cast<OMPSectionDirective>(SectionStmt) |
| 4672 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4673 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4674 | } else { |
| 4675 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4676 | return StmtError(); |
| 4677 | } |
| 4678 | |
| 4679 | getCurFunction()->setHasBranchProtectedScope(); |
| 4680 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4681 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4682 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4683 | } |
| 4684 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4685 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4686 | SourceLocation StartLoc, |
| 4687 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4688 | if (!AStmt) |
| 4689 | return StmtError(); |
| 4690 | |
| 4691 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4692 | |
| 4693 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4694 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4695 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4696 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4697 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4698 | } |
| 4699 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4700 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4701 | Stmt *AStmt, |
| 4702 | SourceLocation StartLoc, |
| 4703 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4704 | if (!AStmt) |
| 4705 | return StmtError(); |
| 4706 | |
| 4707 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4708 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4709 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4710 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4711 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4712 | // The copyprivate clause must not be used with the nowait clause. |
| 4713 | OMPClause *Nowait = nullptr; |
| 4714 | OMPClause *Copyprivate = nullptr; |
| 4715 | for (auto *Clause : Clauses) { |
| 4716 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4717 | Nowait = Clause; |
| 4718 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4719 | Copyprivate = Clause; |
| 4720 | if (Copyprivate && Nowait) { |
| 4721 | Diag(Copyprivate->getLocStart(), |
| 4722 | diag::err_omp_single_copyprivate_with_nowait); |
| 4723 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4724 | return StmtError(); |
| 4725 | } |
| 4726 | } |
| 4727 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4728 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4729 | } |
| 4730 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4731 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4732 | SourceLocation StartLoc, |
| 4733 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4734 | if (!AStmt) |
| 4735 | return StmtError(); |
| 4736 | |
| 4737 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4738 | |
| 4739 | getCurFunction()->setHasBranchProtectedScope(); |
| 4740 | |
| 4741 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4742 | } |
| 4743 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4744 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4745 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4746 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4747 | if (!AStmt) |
| 4748 | return StmtError(); |
| 4749 | |
| 4750 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4751 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4752 | bool ErrorFound = false; |
| 4753 | llvm::APSInt Hint; |
| 4754 | SourceLocation HintLoc; |
| 4755 | bool DependentHint = false; |
| 4756 | for (auto *C : Clauses) { |
| 4757 | if (C->getClauseKind() == OMPC_hint) { |
| 4758 | if (!DirName.getName()) { |
| 4759 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4760 | ErrorFound = true; |
| 4761 | } |
| 4762 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4763 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4764 | E->isInstantiationDependent()) |
| 4765 | DependentHint = true; |
| 4766 | else { |
| 4767 | Hint = E->EvaluateKnownConstInt(Context); |
| 4768 | HintLoc = C->getLocStart(); |
| 4769 | } |
| 4770 | } |
| 4771 | } |
| 4772 | if (ErrorFound) |
| 4773 | return StmtError(); |
| 4774 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4775 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4776 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4777 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4778 | if (HintLoc.isValid()) { |
| 4779 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4780 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4781 | } else |
| 4782 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4783 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4784 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4785 | << 1 |
| 4786 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4787 | /*Radix=*/10, /*Signed=*/false); |
| 4788 | } else |
| 4789 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4790 | } |
| 4791 | } |
| 4792 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4793 | getCurFunction()->setHasBranchProtectedScope(); |
| 4794 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4795 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4796 | Clauses, AStmt); |
| 4797 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4798 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4799 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4800 | } |
| 4801 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4802 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4803 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4804 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4805 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4806 | if (!AStmt) |
| 4807 | return StmtError(); |
| 4808 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4809 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4810 | // 1.2.2 OpenMP Language Terminology |
| 4811 | // Structured block - An executable statement with a single entry at the |
| 4812 | // top and a single exit at the bottom. |
| 4813 | // The point of exit cannot be a branch out of the structured block. |
| 4814 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4815 | CS->getCapturedDecl()->setNothrow(); |
| 4816 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4817 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4818 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4819 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4820 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4821 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4822 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4823 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4824 | if (NestedLoopCount == 0) |
| 4825 | return StmtError(); |
| 4826 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4827 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4828 | "omp parallel for loop exprs were not built"); |
| 4829 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4830 | if (!CurContext->isDependentContext()) { |
| 4831 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4832 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4833 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4834 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4835 | B.NumIterations, *this, CurScope, |
| 4836 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4837 | return StmtError(); |
| 4838 | } |
| 4839 | } |
| 4840 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4841 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4842 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4843 | NestedLoopCount, Clauses, AStmt, B, |
| 4844 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4845 | } |
| 4846 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4847 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4848 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4849 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4850 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4851 | if (!AStmt) |
| 4852 | return StmtError(); |
| 4853 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4854 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4855 | // 1.2.2 OpenMP Language Terminology |
| 4856 | // Structured block - An executable statement with a single entry at the |
| 4857 | // top and a single exit at the bottom. |
| 4858 | // The point of exit cannot be a branch out of the structured block. |
| 4859 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4860 | CS->getCapturedDecl()->setNothrow(); |
| 4861 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4862 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4863 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4864 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4865 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4866 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4867 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4868 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4869 | if (NestedLoopCount == 0) |
| 4870 | return StmtError(); |
| 4871 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4872 | if (!CurContext->isDependentContext()) { |
| 4873 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4874 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4875 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4876 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4877 | B.NumIterations, *this, CurScope, |
| 4878 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4879 | return StmtError(); |
| 4880 | } |
| 4881 | } |
| 4882 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4883 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4884 | return StmtError(); |
| 4885 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4886 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4887 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4888 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4891 | StmtResult |
| 4892 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4893 | Stmt *AStmt, SourceLocation StartLoc, |
| 4894 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4895 | if (!AStmt) |
| 4896 | return StmtError(); |
| 4897 | |
| 4898 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4899 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4900 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4901 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4902 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4903 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4904 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4905 | return StmtError(); |
| 4906 | // All associated statements must be '#pragma omp section' except for |
| 4907 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4908 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4909 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4910 | if (SectionStmt) |
| 4911 | Diag(SectionStmt->getLocStart(), |
| 4912 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4913 | return StmtError(); |
| 4914 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4915 | cast<OMPSectionDirective>(SectionStmt) |
| 4916 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4917 | } |
| 4918 | } else { |
| 4919 | Diag(AStmt->getLocStart(), |
| 4920 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4921 | return StmtError(); |
| 4922 | } |
| 4923 | |
| 4924 | getCurFunction()->setHasBranchProtectedScope(); |
| 4925 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4926 | return OMPParallelSectionsDirective::Create( |
| 4927 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4928 | } |
| 4929 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4930 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4931 | Stmt *AStmt, SourceLocation StartLoc, |
| 4932 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4933 | if (!AStmt) |
| 4934 | return StmtError(); |
| 4935 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4936 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4937 | // 1.2.2 OpenMP Language Terminology |
| 4938 | // Structured block - An executable statement with a single entry at the |
| 4939 | // top and a single exit at the bottom. |
| 4940 | // The point of exit cannot be a branch out of the structured block. |
| 4941 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4942 | CS->getCapturedDecl()->setNothrow(); |
| 4943 | |
| 4944 | getCurFunction()->setHasBranchProtectedScope(); |
| 4945 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4946 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4947 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4948 | } |
| 4949 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4950 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4951 | SourceLocation EndLoc) { |
| 4952 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4953 | } |
| 4954 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4955 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4956 | SourceLocation EndLoc) { |
| 4957 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4958 | } |
| 4959 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4960 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4961 | SourceLocation EndLoc) { |
| 4962 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4963 | } |
| 4964 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4965 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4966 | SourceLocation StartLoc, |
| 4967 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4968 | if (!AStmt) |
| 4969 | return StmtError(); |
| 4970 | |
| 4971 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4972 | |
| 4973 | getCurFunction()->setHasBranchProtectedScope(); |
| 4974 | |
| 4975 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4976 | } |
| 4977 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4978 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4979 | SourceLocation StartLoc, |
| 4980 | SourceLocation EndLoc) { |
| 4981 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4982 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4983 | } |
| 4984 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4985 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4986 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4987 | SourceLocation StartLoc, |
| 4988 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4989 | OMPClause *DependFound = nullptr; |
| 4990 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4991 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4992 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4993 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4994 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4995 | for (auto *C : Clauses) { |
| 4996 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4997 | DependFound = C; |
| 4998 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4999 | if (DependSourceClause) { |
| 5000 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 5001 | << getOpenMPDirectiveName(OMPD_ordered) |
| 5002 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 5003 | ErrorFound = true; |
| 5004 | } else |
| 5005 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 5006 | if (DependSinkClause) { |
| 5007 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5008 | << 0; |
| 5009 | ErrorFound = true; |
| 5010 | } |
| 5011 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 5012 | if (DependSourceClause) { |
| 5013 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 5014 | << 1; |
| 5015 | ErrorFound = true; |
| 5016 | } |
| 5017 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5018 | } |
| 5019 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5020 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5021 | else if (C->getClauseKind() == OMPC_simd) |
| 5022 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5023 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5024 | if (!ErrorFound && !SC && |
| 5025 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5026 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 5027 | // An ordered construct with the simd clause is the only OpenMP construct |
| 5028 | // that can appear in the simd region. |
| 5029 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5030 | ErrorFound = true; |
| 5031 | } else if (DependFound && (TC || SC)) { |
| 5032 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 5033 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 5034 | ErrorFound = true; |
| 5035 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 5036 | Diag(DependFound->getLocStart(), |
| 5037 | diag::err_omp_ordered_directive_without_param); |
| 5038 | ErrorFound = true; |
| 5039 | } else if (TC || Clauses.empty()) { |
| 5040 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 5041 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 5042 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 5043 | << (TC != nullptr); |
| 5044 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 5045 | ErrorFound = true; |
| 5046 | } |
| 5047 | } |
| 5048 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5049 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 5050 | |
| 5051 | if (AStmt) { |
| 5052 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5053 | |
| 5054 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 5055 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 5056 | |
| 5057 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 5058 | } |
| 5059 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5060 | namespace { |
| 5061 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 5062 | /// construct. |
| 5063 | class OpenMPAtomicUpdateChecker { |
| 5064 | /// \brief Error results for atomic update expressions. |
| 5065 | enum ExprAnalysisErrorCode { |
| 5066 | /// \brief A statement is not an expression statement. |
| 5067 | NotAnExpression, |
| 5068 | /// \brief Expression is not builtin binary or unary operation. |
| 5069 | NotABinaryOrUnaryExpression, |
| 5070 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 5071 | NotAnUnaryIncDecExpression, |
| 5072 | /// \brief An expression is not of scalar type. |
| 5073 | NotAScalarType, |
| 5074 | /// \brief A binary operation is not an assignment operation. |
| 5075 | NotAnAssignmentOp, |
| 5076 | /// \brief RHS part of the binary operation is not a binary expression. |
| 5077 | NotABinaryExpression, |
| 5078 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 5079 | /// expression. |
| 5080 | NotABinaryOperator, |
| 5081 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 5082 | /// part. |
| 5083 | NotAnUpdateExpression, |
| 5084 | /// \brief No errors is found. |
| 5085 | NoError |
| 5086 | }; |
| 5087 | /// \brief Reference to Sema. |
| 5088 | Sema &SemaRef; |
| 5089 | /// \brief A location for note diagnostics (when error is found). |
| 5090 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5091 | /// \brief 'x' lvalue part of the source atomic expression. |
| 5092 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5093 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 5094 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5095 | /// \brief Helper expression of the form |
| 5096 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5097 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5098 | Expr *UpdateExpr; |
| 5099 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 5100 | /// important for non-associative operations. |
| 5101 | bool IsXLHSInRHSPart; |
| 5102 | BinaryOperatorKind Op; |
| 5103 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5104 | /// \brief true if the source expression is a postfix unary operation, false |
| 5105 | /// if it is a prefix unary operation. |
| 5106 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5107 | |
| 5108 | public: |
| 5109 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5110 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5111 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5112 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 5113 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5114 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 5115 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5116 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 5117 | /// \param NoteId Diagnostic note for the main error message. |
| 5118 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5119 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5120 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 5121 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5122 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 5123 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5124 | /// \brief Return the update expression used in calculation of the updated |
| 5125 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 5126 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 5127 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 5128 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 5129 | /// false otherwise. |
| 5130 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 5131 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5132 | /// \brief true if the source expression is a postfix unary operation, false |
| 5133 | /// if it is a prefix unary operation. |
| 5134 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 5135 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5136 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5137 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 5138 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5139 | }; |
| 5140 | } // namespace |
| 5141 | |
| 5142 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5143 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5144 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5145 | SourceLocation ErrorLoc, NoteLoc; |
| 5146 | SourceRange ErrorRange, NoteRange; |
| 5147 | // Allowed constructs are: |
| 5148 | // x = x binop expr; |
| 5149 | // x = expr binop x; |
| 5150 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5151 | X = AtomicBinOp->getLHS(); |
| 5152 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5153 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5154 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5155 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5156 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5157 | Op = AtomicInnerBinOp->getOpcode(); |
| 5158 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5159 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5160 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5161 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5162 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5163 | /*Canonical=*/true); |
| 5164 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5165 | /*Canonical=*/true); |
| 5166 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5167 | /*Canonical=*/true); |
| 5168 | if (XId == LHSId) { |
| 5169 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5170 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5171 | } else if (XId == RHSId) { |
| 5172 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5173 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5174 | } else { |
| 5175 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5176 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5177 | NoteLoc = X->getExprLoc(); |
| 5178 | NoteRange = X->getSourceRange(); |
| 5179 | ErrorFound = NotAnUpdateExpression; |
| 5180 | } |
| 5181 | } else { |
| 5182 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5183 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5184 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5185 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5186 | ErrorFound = NotABinaryOperator; |
| 5187 | } |
| 5188 | } else { |
| 5189 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5190 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5191 | ErrorFound = NotABinaryExpression; |
| 5192 | } |
| 5193 | } else { |
| 5194 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5195 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5196 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5197 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5198 | ErrorFound = NotAnAssignmentOp; |
| 5199 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5200 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5201 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5202 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5203 | return true; |
| 5204 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5205 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5206 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5207 | } |
| 5208 | |
| 5209 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5210 | unsigned NoteId) { |
| 5211 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5212 | SourceLocation ErrorLoc, NoteLoc; |
| 5213 | SourceRange ErrorRange, NoteRange; |
| 5214 | // Allowed constructs are: |
| 5215 | // x++; |
| 5216 | // x--; |
| 5217 | // ++x; |
| 5218 | // --x; |
| 5219 | // x binop= expr; |
| 5220 | // x = x binop expr; |
| 5221 | // x = expr binop x; |
| 5222 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5223 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5224 | if (AtomicBody->getType()->isScalarType() || |
| 5225 | AtomicBody->isInstantiationDependent()) { |
| 5226 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5227 | AtomicBody->IgnoreParenImpCasts())) { |
| 5228 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5229 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5230 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5231 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5232 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5233 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5234 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5235 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5236 | AtomicBody->IgnoreParenImpCasts())) { |
| 5237 | // Check for Binary Operation |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5238 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5239 | return true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5240 | } else if (auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| 5241 | AtomicBody->IgnoreParenImpCasts())) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5242 | // Check for Unary Operation |
| 5243 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5244 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5245 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5246 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5247 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5248 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5249 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5250 | } else { |
| 5251 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5252 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5253 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5254 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5255 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5256 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5257 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5258 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5259 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5260 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5261 | } |
| 5262 | } else { |
| 5263 | ErrorFound = NotAScalarType; |
| 5264 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5265 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5266 | } |
| 5267 | } else { |
| 5268 | ErrorFound = NotAnExpression; |
| 5269 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5270 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5271 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5272 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5273 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5274 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5275 | return true; |
| 5276 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5277 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5278 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5279 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5280 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5281 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5282 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5283 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5284 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5285 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5286 | auto Update = |
| 5287 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5288 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5289 | if (Update.isInvalid()) |
| 5290 | return true; |
| 5291 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5292 | Sema::AA_Casting); |
| 5293 | if (Update.isInvalid()) |
| 5294 | return true; |
| 5295 | UpdateExpr = Update.get(); |
| 5296 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5297 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5300 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5301 | Stmt *AStmt, |
| 5302 | SourceLocation StartLoc, |
| 5303 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5304 | if (!AStmt) |
| 5305 | return StmtError(); |
| 5306 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5307 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5308 | // 1.2.2 OpenMP Language Terminology |
| 5309 | // Structured block - An executable statement with a single entry at the |
| 5310 | // top and a single exit at the bottom. |
| 5311 | // The point of exit cannot be a branch out of the structured block. |
| 5312 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5313 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5314 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5315 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5316 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5317 | C->getClauseKind() == OMPC_update || |
| 5318 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5319 | if (AtomicKind != OMPC_unknown) { |
| 5320 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5321 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5322 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5323 | << getOpenMPClauseName(AtomicKind); |
| 5324 | } else { |
| 5325 | AtomicKind = C->getClauseKind(); |
| 5326 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5327 | } |
| 5328 | } |
| 5329 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5330 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5331 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5332 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5333 | Body = EWC->getSubExpr(); |
| 5334 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5335 | Expr *X = nullptr; |
| 5336 | Expr *V = nullptr; |
| 5337 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5338 | Expr *UE = nullptr; |
| 5339 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5340 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5341 | // OpenMP [2.12.6, atomic Construct] |
| 5342 | // In the next expressions: |
| 5343 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5344 | // * During the execution of an atomic region, multiple syntactic |
| 5345 | // occurrences of x must designate the same storage location. |
| 5346 | // * Neither of v and expr (as applicable) may access the storage location |
| 5347 | // designated by x. |
| 5348 | // * Neither of x and expr (as applicable) may access the storage location |
| 5349 | // designated by v. |
| 5350 | // * expr is an expression with scalar type. |
| 5351 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5352 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5353 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5354 | // (expr). This requirement is satisfied if the operators in expr have |
| 5355 | // precedence greater than binop, or by using parentheses around expr or |
| 5356 | // subexpressions of expr. |
| 5357 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5358 | // binop x. This requirement is satisfied if the operators in expr have |
| 5359 | // precedence equal to or greater than binop, or by using parentheses around |
| 5360 | // expr or subexpressions of expr. |
| 5361 | // * For forms that allow multiple occurrences of x, the number of times |
| 5362 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5363 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5364 | enum { |
| 5365 | NotAnExpression, |
| 5366 | NotAnAssignmentOp, |
| 5367 | NotAScalarType, |
| 5368 | NotAnLValue, |
| 5369 | NoError |
| 5370 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5371 | SourceLocation ErrorLoc, NoteLoc; |
| 5372 | SourceRange ErrorRange, NoteRange; |
| 5373 | // If clause is read: |
| 5374 | // v = x; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5375 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5376 | auto *AtomicBinOp = |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5377 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5378 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5379 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5380 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5381 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5382 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5383 | if (!X->isLValue() || !V->isLValue()) { |
| 5384 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5385 | ErrorFound = NotAnLValue; |
| 5386 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5387 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5388 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5389 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5390 | } |
| 5391 | } else if (!X->isInstantiationDependent() || |
| 5392 | !V->isInstantiationDependent()) { |
| 5393 | auto NotScalarExpr = |
| 5394 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5395 | ? V |
| 5396 | : X; |
| 5397 | ErrorFound = NotAScalarType; |
| 5398 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5399 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5400 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5401 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5402 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5403 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5404 | ErrorFound = NotAnAssignmentOp; |
| 5405 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5406 | ErrorRange = AtomicBody->getSourceRange(); |
| 5407 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5408 | : AtomicBody->getExprLoc(); |
| 5409 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5410 | : AtomicBody->getSourceRange(); |
| 5411 | } |
| 5412 | } else { |
| 5413 | ErrorFound = NotAnExpression; |
| 5414 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5415 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5416 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5417 | if (ErrorFound != NoError) { |
| 5418 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5419 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5420 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5421 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5422 | return StmtError(); |
| 5423 | } else if (CurContext->isDependentContext()) |
| 5424 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5425 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5426 | enum { |
| 5427 | NotAnExpression, |
| 5428 | NotAnAssignmentOp, |
| 5429 | NotAScalarType, |
| 5430 | NotAnLValue, |
| 5431 | NoError |
| 5432 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5433 | SourceLocation ErrorLoc, NoteLoc; |
| 5434 | SourceRange ErrorRange, NoteRange; |
| 5435 | // If clause is write: |
| 5436 | // x = expr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5437 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5438 | auto *AtomicBinOp = |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5439 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5440 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5441 | X = AtomicBinOp->getLHS(); |
| 5442 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5443 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5444 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5445 | if (!X->isLValue()) { |
| 5446 | ErrorFound = NotAnLValue; |
| 5447 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5448 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5449 | NoteLoc = X->getExprLoc(); |
| 5450 | NoteRange = X->getSourceRange(); |
| 5451 | } |
| 5452 | } else if (!X->isInstantiationDependent() || |
| 5453 | !E->isInstantiationDependent()) { |
| 5454 | auto NotScalarExpr = |
| 5455 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5456 | ? E |
| 5457 | : X; |
| 5458 | ErrorFound = NotAScalarType; |
| 5459 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5460 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5461 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5462 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5463 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5464 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5465 | ErrorFound = NotAnAssignmentOp; |
| 5466 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5467 | ErrorRange = AtomicBody->getSourceRange(); |
| 5468 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5469 | : AtomicBody->getExprLoc(); |
| 5470 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5471 | : AtomicBody->getSourceRange(); |
| 5472 | } |
| 5473 | } else { |
| 5474 | ErrorFound = NotAnExpression; |
| 5475 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5476 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5477 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5478 | if (ErrorFound != NoError) { |
| 5479 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5480 | << ErrorRange; |
| 5481 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5482 | << NoteRange; |
| 5483 | return StmtError(); |
| 5484 | } else if (CurContext->isDependentContext()) |
| 5485 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5486 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5487 | // If clause is update: |
| 5488 | // x++; |
| 5489 | // x--; |
| 5490 | // ++x; |
| 5491 | // --x; |
| 5492 | // x binop= expr; |
| 5493 | // x = x binop expr; |
| 5494 | // x = expr binop x; |
| 5495 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5496 | if (Checker.checkStatement( |
| 5497 | Body, (AtomicKind == OMPC_update) |
| 5498 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5499 | : diag::err_omp_atomic_not_expression_statement, |
| 5500 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5501 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5502 | if (!CurContext->isDependentContext()) { |
| 5503 | E = Checker.getExpr(); |
| 5504 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5505 | UE = Checker.getUpdateExpr(); |
| 5506 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5507 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5508 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5509 | enum { |
| 5510 | NotAnAssignmentOp, |
| 5511 | NotACompoundStatement, |
| 5512 | NotTwoSubstatements, |
| 5513 | NotASpecificExpression, |
| 5514 | NoError |
| 5515 | } ErrorFound = NoError; |
| 5516 | SourceLocation ErrorLoc, NoteLoc; |
| 5517 | SourceRange ErrorRange, NoteRange; |
| 5518 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5519 | // If clause is a capture: |
| 5520 | // v = x++; |
| 5521 | // v = x--; |
| 5522 | // v = ++x; |
| 5523 | // v = --x; |
| 5524 | // v = x binop= expr; |
| 5525 | // v = x = x binop expr; |
| 5526 | // v = x = expr binop x; |
| 5527 | auto *AtomicBinOp = |
| 5528 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5529 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5530 | V = AtomicBinOp->getLHS(); |
| 5531 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5532 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5533 | if (Checker.checkStatement( |
| 5534 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5535 | diag::note_omp_atomic_update)) |
| 5536 | return StmtError(); |
| 5537 | E = Checker.getExpr(); |
| 5538 | X = Checker.getX(); |
| 5539 | UE = Checker.getUpdateExpr(); |
| 5540 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5541 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5542 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5543 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5544 | ErrorRange = AtomicBody->getSourceRange(); |
| 5545 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5546 | : AtomicBody->getExprLoc(); |
| 5547 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5548 | : AtomicBody->getSourceRange(); |
| 5549 | ErrorFound = NotAnAssignmentOp; |
| 5550 | } |
| 5551 | if (ErrorFound != NoError) { |
| 5552 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5553 | << ErrorRange; |
| 5554 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5555 | return StmtError(); |
| 5556 | } else if (CurContext->isDependentContext()) { |
| 5557 | UE = V = E = X = nullptr; |
| 5558 | } |
| 5559 | } else { |
| 5560 | // If clause is a capture: |
| 5561 | // { v = x; x = expr; } |
| 5562 | // { v = x; x++; } |
| 5563 | // { v = x; x--; } |
| 5564 | // { v = x; ++x; } |
| 5565 | // { v = x; --x; } |
| 5566 | // { v = x; x binop= expr; } |
| 5567 | // { v = x; x = x binop expr; } |
| 5568 | // { v = x; x = expr binop x; } |
| 5569 | // { x++; v = x; } |
| 5570 | // { x--; v = x; } |
| 5571 | // { ++x; v = x; } |
| 5572 | // { --x; v = x; } |
| 5573 | // { x binop= expr; v = x; } |
| 5574 | // { x = x binop expr; v = x; } |
| 5575 | // { x = expr binop x; v = x; } |
| 5576 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5577 | // Check that this is { expr1; expr2; } |
| 5578 | if (CS->size() == 2) { |
| 5579 | auto *First = CS->body_front(); |
| 5580 | auto *Second = CS->body_back(); |
| 5581 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5582 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5583 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5584 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5585 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5586 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5587 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5588 | BinaryOperator *BinOp = nullptr; |
| 5589 | if (IsUpdateExprFound) { |
| 5590 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5591 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5592 | } |
| 5593 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5594 | // { v = x; x++; } |
| 5595 | // { v = x; x--; } |
| 5596 | // { v = x; ++x; } |
| 5597 | // { v = x; --x; } |
| 5598 | // { v = x; x binop= expr; } |
| 5599 | // { v = x; x = x binop expr; } |
| 5600 | // { v = x; x = expr binop x; } |
| 5601 | // Check that the first expression has form v = x. |
| 5602 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5603 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5604 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5605 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5606 | IsUpdateExprFound = XId == PossibleXId; |
| 5607 | if (IsUpdateExprFound) { |
| 5608 | V = BinOp->getLHS(); |
| 5609 | X = Checker.getX(); |
| 5610 | E = Checker.getExpr(); |
| 5611 | UE = Checker.getUpdateExpr(); |
| 5612 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5613 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5614 | } |
| 5615 | } |
| 5616 | if (!IsUpdateExprFound) { |
| 5617 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5618 | BinOp = nullptr; |
| 5619 | if (IsUpdateExprFound) { |
| 5620 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5621 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5622 | } |
| 5623 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5624 | // { x++; v = x; } |
| 5625 | // { x--; v = x; } |
| 5626 | // { ++x; v = x; } |
| 5627 | // { --x; v = x; } |
| 5628 | // { x binop= expr; v = x; } |
| 5629 | // { x = x binop expr; v = x; } |
| 5630 | // { x = expr binop x; v = x; } |
| 5631 | // Check that the second expression has form v = x. |
| 5632 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5633 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5634 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5635 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5636 | IsUpdateExprFound = XId == PossibleXId; |
| 5637 | if (IsUpdateExprFound) { |
| 5638 | V = BinOp->getLHS(); |
| 5639 | X = Checker.getX(); |
| 5640 | E = Checker.getExpr(); |
| 5641 | UE = Checker.getUpdateExpr(); |
| 5642 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5643 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5644 | } |
| 5645 | } |
| 5646 | } |
| 5647 | if (!IsUpdateExprFound) { |
| 5648 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5649 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5650 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5651 | if (!FirstExpr || !SecondExpr || |
| 5652 | !(FirstExpr->isInstantiationDependent() || |
| 5653 | SecondExpr->isInstantiationDependent())) { |
| 5654 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5655 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5656 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5657 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5658 | : First->getLocStart(); |
| 5659 | NoteRange = ErrorRange = FirstBinOp |
| 5660 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5661 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5662 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5663 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5664 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5665 | ErrorFound = NotAnAssignmentOp; |
| 5666 | NoteLoc = ErrorLoc = SecondBinOp |
| 5667 | ? SecondBinOp->getOperatorLoc() |
| 5668 | : Second->getLocStart(); |
| 5669 | NoteRange = ErrorRange = |
| 5670 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5671 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5672 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5673 | auto *PossibleXRHSInFirst = |
| 5674 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5675 | auto *PossibleXLHSInSecond = |
| 5676 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5677 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5678 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5679 | /*Canonical=*/true); |
| 5680 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5681 | /*Canonical=*/true); |
| 5682 | IsUpdateExprFound = X1Id == X2Id; |
| 5683 | if (IsUpdateExprFound) { |
| 5684 | V = FirstBinOp->getLHS(); |
| 5685 | X = SecondBinOp->getLHS(); |
| 5686 | E = SecondBinOp->getRHS(); |
| 5687 | UE = nullptr; |
| 5688 | IsXLHSInRHSPart = false; |
| 5689 | IsPostfixUpdate = true; |
| 5690 | } else { |
| 5691 | ErrorFound = NotASpecificExpression; |
| 5692 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5693 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5694 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5695 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5696 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5697 | } |
| 5698 | } |
| 5699 | } |
| 5700 | } |
| 5701 | } else { |
| 5702 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5703 | NoteRange = ErrorRange = |
| 5704 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5705 | ErrorFound = NotTwoSubstatements; |
| 5706 | } |
| 5707 | } else { |
| 5708 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5709 | NoteRange = ErrorRange = |
| 5710 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5711 | ErrorFound = NotACompoundStatement; |
| 5712 | } |
| 5713 | if (ErrorFound != NoError) { |
| 5714 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5715 | << ErrorRange; |
| 5716 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5717 | return StmtError(); |
| 5718 | } else if (CurContext->isDependentContext()) { |
| 5719 | UE = V = E = X = nullptr; |
| 5720 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5721 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5722 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5723 | |
| 5724 | getCurFunction()->setHasBranchProtectedScope(); |
| 5725 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5726 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5727 | X, V, E, UE, IsXLHSInRHSPart, |
| 5728 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5729 | } |
| 5730 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5731 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5732 | Stmt *AStmt, |
| 5733 | SourceLocation StartLoc, |
| 5734 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5735 | if (!AStmt) |
| 5736 | return StmtError(); |
| 5737 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5738 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5739 | // 1.2.2 OpenMP Language Terminology |
| 5740 | // Structured block - An executable statement with a single entry at the |
| 5741 | // top and a single exit at the bottom. |
| 5742 | // The point of exit cannot be a branch out of the structured block. |
| 5743 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5744 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5745 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5746 | // OpenMP [2.16, Nesting of Regions] |
| 5747 | // If specified, a teams construct must be contained within a target |
| 5748 | // construct. That target construct must contain no statements or directives |
| 5749 | // outside of the teams construct. |
| 5750 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5751 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5752 | bool OMPTeamsFound = true; |
| 5753 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5754 | auto I = CS->body_begin(); |
| 5755 | while (I != CS->body_end()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5756 | auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5757 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5758 | OMPTeamsFound = false; |
| 5759 | break; |
| 5760 | } |
| 5761 | ++I; |
| 5762 | } |
| 5763 | assert(I != CS->body_end() && "Not found statement"); |
| 5764 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 5765 | } else { |
| 5766 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 5767 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5768 | } |
| 5769 | if (!OMPTeamsFound) { |
| 5770 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5771 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5772 | diag::note_omp_nested_teams_construct_here); |
| 5773 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5774 | << isa<OMPExecutableDirective>(S); |
| 5775 | return StmtError(); |
| 5776 | } |
| 5777 | } |
| 5778 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5779 | getCurFunction()->setHasBranchProtectedScope(); |
| 5780 | |
| 5781 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5782 | } |
| 5783 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5784 | StmtResult |
| 5785 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5786 | Stmt *AStmt, SourceLocation StartLoc, |
| 5787 | SourceLocation EndLoc) { |
| 5788 | if (!AStmt) |
| 5789 | return StmtError(); |
| 5790 | |
| 5791 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5792 | // 1.2.2 OpenMP Language Terminology |
| 5793 | // Structured block - An executable statement with a single entry at the |
| 5794 | // top and a single exit at the bottom. |
| 5795 | // The point of exit cannot be a branch out of the structured block. |
| 5796 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5797 | CS->getCapturedDecl()->setNothrow(); |
| 5798 | |
| 5799 | getCurFunction()->setHasBranchProtectedScope(); |
| 5800 | |
| 5801 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5802 | AStmt); |
| 5803 | } |
| 5804 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5805 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5806 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5807 | SourceLocation EndLoc, |
| 5808 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5809 | if (!AStmt) |
| 5810 | return StmtError(); |
| 5811 | |
| 5812 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5813 | // 1.2.2 OpenMP Language Terminology |
| 5814 | // Structured block - An executable statement with a single entry at the |
| 5815 | // top and a single exit at the bottom. |
| 5816 | // The point of exit cannot be a branch out of the structured block. |
| 5817 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5818 | CS->getCapturedDecl()->setNothrow(); |
| 5819 | |
| 5820 | OMPLoopDirective::HelperExprs B; |
| 5821 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5822 | // define the nested loops number. |
| 5823 | unsigned NestedLoopCount = |
| 5824 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5825 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5826 | VarsWithImplicitDSA, B); |
| 5827 | if (NestedLoopCount == 0) |
| 5828 | return StmtError(); |
| 5829 | |
| 5830 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5831 | "omp target parallel for loop exprs were not built"); |
| 5832 | |
| 5833 | if (!CurContext->isDependentContext()) { |
| 5834 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5835 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5836 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5837 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5838 | B.NumIterations, *this, CurScope, |
| 5839 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5840 | return StmtError(); |
| 5841 | } |
| 5842 | } |
| 5843 | |
| 5844 | getCurFunction()->setHasBranchProtectedScope(); |
| 5845 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5846 | NestedLoopCount, Clauses, AStmt, |
| 5847 | B, DSAStack->isCancelRegion()); |
| 5848 | } |
| 5849 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5850 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5851 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5852 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5853 | I != E; ++I) { |
| 5854 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5855 | return true; |
| 5856 | } |
| 5857 | } |
| 5858 | |
| 5859 | return false; |
| 5860 | } |
| 5861 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5862 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5863 | Stmt *AStmt, |
| 5864 | SourceLocation StartLoc, |
| 5865 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5866 | if (!AStmt) |
| 5867 | return StmtError(); |
| 5868 | |
| 5869 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5870 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5871 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5872 | // At least one map clause must appear on the directive. |
| 5873 | if (!HasMapClause(Clauses)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5874 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5875 | << getOpenMPDirectiveName(OMPD_target_data); |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5876 | return StmtError(); |
| 5877 | } |
| 5878 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5879 | getCurFunction()->setHasBranchProtectedScope(); |
| 5880 | |
| 5881 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5882 | AStmt); |
| 5883 | } |
| 5884 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5885 | StmtResult |
| 5886 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5887 | SourceLocation StartLoc, |
| 5888 | SourceLocation EndLoc) { |
| 5889 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5890 | // At least one map clause must appear on the directive. |
| 5891 | if (!HasMapClause(Clauses)) { |
| 5892 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5893 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5894 | return StmtError(); |
| 5895 | } |
| 5896 | |
| 5897 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5898 | Clauses); |
| 5899 | } |
| 5900 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5901 | StmtResult |
| 5902 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5903 | SourceLocation StartLoc, |
| 5904 | SourceLocation EndLoc) { |
| 5905 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5906 | // At least one map clause must appear on the directive. |
| 5907 | if (!HasMapClause(Clauses)) { |
| 5908 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5909 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5910 | return StmtError(); |
| 5911 | } |
| 5912 | |
| 5913 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5914 | } |
| 5915 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5916 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 5917 | SourceLocation StartLoc, |
| 5918 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5919 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5920 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 5921 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5922 | seenMotionClause = true; |
| 5923 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5924 | if (!seenMotionClause) { |
| 5925 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 5926 | return StmtError(); |
| 5927 | } |
| 5928 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5929 | } |
| 5930 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5931 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5932 | Stmt *AStmt, SourceLocation StartLoc, |
| 5933 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5934 | if (!AStmt) |
| 5935 | return StmtError(); |
| 5936 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5937 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5938 | // 1.2.2 OpenMP Language Terminology |
| 5939 | // Structured block - An executable statement with a single entry at the |
| 5940 | // top and a single exit at the bottom. |
| 5941 | // The point of exit cannot be a branch out of the structured block. |
| 5942 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5943 | CS->getCapturedDecl()->setNothrow(); |
| 5944 | |
| 5945 | getCurFunction()->setHasBranchProtectedScope(); |
| 5946 | |
| 5947 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5948 | } |
| 5949 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5950 | StmtResult |
| 5951 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5952 | SourceLocation EndLoc, |
| 5953 | OpenMPDirectiveKind CancelRegion) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5954 | if (DSAStack->isParentNowaitRegion()) { |
| 5955 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5956 | return StmtError(); |
| 5957 | } |
| 5958 | if (DSAStack->isParentOrderedRegion()) { |
| 5959 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5960 | return StmtError(); |
| 5961 | } |
| 5962 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5963 | CancelRegion); |
| 5964 | } |
| 5965 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5966 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5967 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5968 | SourceLocation EndLoc, |
| 5969 | OpenMPDirectiveKind CancelRegion) { |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5970 | if (DSAStack->isParentNowaitRegion()) { |
| 5971 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5972 | return StmtError(); |
| 5973 | } |
| 5974 | if (DSAStack->isParentOrderedRegion()) { |
| 5975 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5976 | return StmtError(); |
| 5977 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5978 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5979 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5980 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5981 | } |
| 5982 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5983 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5984 | ArrayRef<OMPClause *> Clauses) { |
| 5985 | OMPClause *PrevClause = nullptr; |
| 5986 | bool ErrorFound = false; |
| 5987 | for (auto *C : Clauses) { |
| 5988 | if (C->getClauseKind() == OMPC_grainsize || |
| 5989 | C->getClauseKind() == OMPC_num_tasks) { |
| 5990 | if (!PrevClause) |
| 5991 | PrevClause = C; |
| 5992 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5993 | S.Diag(C->getLocStart(), |
| 5994 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5995 | << getOpenMPClauseName(C->getClauseKind()) |
| 5996 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5997 | S.Diag(PrevClause->getLocStart(), |
| 5998 | diag::note_omp_previous_grainsize_num_tasks) |
| 5999 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 6000 | ErrorFound = true; |
| 6001 | } |
| 6002 | } |
| 6003 | } |
| 6004 | return ErrorFound; |
| 6005 | } |
| 6006 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6007 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 6008 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6009 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6010 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6011 | if (!AStmt) |
| 6012 | return StmtError(); |
| 6013 | |
| 6014 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6015 | OMPLoopDirective::HelperExprs B; |
| 6016 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6017 | // define the nested loops number. |
| 6018 | unsigned NestedLoopCount = |
| 6019 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6020 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6021 | VarsWithImplicitDSA, B); |
| 6022 | if (NestedLoopCount == 0) |
| 6023 | return StmtError(); |
| 6024 | |
| 6025 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6026 | "omp for loop exprs were not built"); |
| 6027 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6028 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6029 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6030 | // not appear on the same taskloop directive. |
| 6031 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6032 | return StmtError(); |
| 6033 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 6034 | getCurFunction()->setHasBranchProtectedScope(); |
| 6035 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 6036 | NestedLoopCount, Clauses, AStmt, B); |
| 6037 | } |
| 6038 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6039 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 6040 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6041 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6042 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6043 | if (!AStmt) |
| 6044 | return StmtError(); |
| 6045 | |
| 6046 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6047 | OMPLoopDirective::HelperExprs B; |
| 6048 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6049 | // define the nested loops number. |
| 6050 | unsigned NestedLoopCount = |
| 6051 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 6052 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 6053 | VarsWithImplicitDSA, B); |
| 6054 | if (NestedLoopCount == 0) |
| 6055 | return StmtError(); |
| 6056 | |
| 6057 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6058 | "omp for loop exprs were not built"); |
| 6059 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6060 | if (!CurContext->isDependentContext()) { |
| 6061 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6062 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6063 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6064 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 6065 | B.NumIterations, *this, CurScope, |
| 6066 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 6067 | return StmtError(); |
| 6068 | } |
| 6069 | } |
| 6070 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6071 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 6072 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 6073 | // not appear on the same taskloop directive. |
| 6074 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 6075 | return StmtError(); |
| 6076 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 6077 | getCurFunction()->setHasBranchProtectedScope(); |
| 6078 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6079 | NestedLoopCount, Clauses, AStmt, B); |
| 6080 | } |
| 6081 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6082 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 6083 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6084 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 6085 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 6086 | if (!AStmt) |
| 6087 | return StmtError(); |
| 6088 | |
| 6089 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 6090 | OMPLoopDirective::HelperExprs B; |
| 6091 | // In presence of clause 'collapse' with number of loops, it will |
| 6092 | // define the nested loops number. |
| 6093 | unsigned NestedLoopCount = |
| 6094 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 6095 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6096 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6097 | if (NestedLoopCount == 0) |
| 6098 | return StmtError(); |
| 6099 | |
| 6100 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6101 | "omp for loop exprs were not built"); |
| 6102 | |
| 6103 | getCurFunction()->setHasBranchProtectedScope(); |
| 6104 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 6105 | NestedLoopCount, Clauses, AStmt, B); |
| 6106 | } |
| 6107 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 6108 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 6109 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6110 | SourceLocation EndLoc, |
| 6111 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6112 | if (!AStmt) |
| 6113 | return StmtError(); |
| 6114 | |
| 6115 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6116 | // 1.2.2 OpenMP Language Terminology |
| 6117 | // Structured block - An executable statement with a single entry at the |
| 6118 | // top and a single exit at the bottom. |
| 6119 | // The point of exit cannot be a branch out of the structured block. |
| 6120 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6121 | CS->getCapturedDecl()->setNothrow(); |
| 6122 | |
| 6123 | OMPLoopDirective::HelperExprs B; |
| 6124 | // In presence of clause 'collapse' with number of loops, it will |
| 6125 | // define the nested loops number. |
| 6126 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6127 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6128 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6129 | VarsWithImplicitDSA, B); |
| 6130 | if (NestedLoopCount == 0) |
| 6131 | return StmtError(); |
| 6132 | |
| 6133 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6134 | "omp for loop exprs were not built"); |
| 6135 | |
| 6136 | getCurFunction()->setHasBranchProtectedScope(); |
| 6137 | return OMPDistributeParallelForDirective::Create( |
| 6138 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6139 | } |
| 6140 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6141 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 6142 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6143 | SourceLocation EndLoc, |
| 6144 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6145 | if (!AStmt) |
| 6146 | return StmtError(); |
| 6147 | |
| 6148 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6149 | // 1.2.2 OpenMP Language Terminology |
| 6150 | // Structured block - An executable statement with a single entry at the |
| 6151 | // top and a single exit at the bottom. |
| 6152 | // The point of exit cannot be a branch out of the structured block. |
| 6153 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6154 | CS->getCapturedDecl()->setNothrow(); |
| 6155 | |
| 6156 | OMPLoopDirective::HelperExprs B; |
| 6157 | // In presence of clause 'collapse' with number of loops, it will |
| 6158 | // define the nested loops number. |
| 6159 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6160 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6161 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6162 | VarsWithImplicitDSA, B); |
| 6163 | if (NestedLoopCount == 0) |
| 6164 | return StmtError(); |
| 6165 | |
| 6166 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6167 | "omp for loop exprs were not built"); |
| 6168 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6169 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6170 | return StmtError(); |
| 6171 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6172 | getCurFunction()->setHasBranchProtectedScope(); |
| 6173 | return OMPDistributeParallelForSimdDirective::Create( |
| 6174 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6175 | } |
| 6176 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6177 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 6178 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6179 | SourceLocation EndLoc, |
| 6180 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6181 | if (!AStmt) |
| 6182 | return StmtError(); |
| 6183 | |
| 6184 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6185 | // 1.2.2 OpenMP Language Terminology |
| 6186 | // Structured block - An executable statement with a single entry at the |
| 6187 | // top and a single exit at the bottom. |
| 6188 | // The point of exit cannot be a branch out of the structured block. |
| 6189 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6190 | CS->getCapturedDecl()->setNothrow(); |
| 6191 | |
| 6192 | OMPLoopDirective::HelperExprs B; |
| 6193 | // In presence of clause 'collapse' with number of loops, it will |
| 6194 | // define the nested loops number. |
| 6195 | unsigned NestedLoopCount = |
| 6196 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6197 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6198 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6199 | if (NestedLoopCount == 0) |
| 6200 | return StmtError(); |
| 6201 | |
| 6202 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6203 | "omp for loop exprs were not built"); |
| 6204 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6205 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6206 | return StmtError(); |
| 6207 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6208 | getCurFunction()->setHasBranchProtectedScope(); |
| 6209 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6210 | NestedLoopCount, Clauses, AStmt, B); |
| 6211 | } |
| 6212 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6213 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 6214 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6215 | SourceLocation EndLoc, |
| 6216 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6217 | if (!AStmt) |
| 6218 | return StmtError(); |
| 6219 | |
| 6220 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6221 | // 1.2.2 OpenMP Language Terminology |
| 6222 | // Structured block - An executable statement with a single entry at the |
| 6223 | // top and a single exit at the bottom. |
| 6224 | // The point of exit cannot be a branch out of the structured block. |
| 6225 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6226 | CS->getCapturedDecl()->setNothrow(); |
| 6227 | |
| 6228 | OMPLoopDirective::HelperExprs B; |
| 6229 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6230 | // define the nested loops number. |
| 6231 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6232 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6233 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6234 | VarsWithImplicitDSA, B); |
| 6235 | if (NestedLoopCount == 0) |
| 6236 | return StmtError(); |
| 6237 | |
| 6238 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6239 | "omp target parallel for simd loop exprs were not built"); |
| 6240 | |
| 6241 | if (!CurContext->isDependentContext()) { |
| 6242 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6243 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6244 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6245 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6246 | B.NumIterations, *this, CurScope, |
| 6247 | DSAStack)) |
| 6248 | return StmtError(); |
| 6249 | } |
| 6250 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6251 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6252 | return StmtError(); |
| 6253 | |
| 6254 | getCurFunction()->setHasBranchProtectedScope(); |
| 6255 | return OMPTargetParallelForSimdDirective::Create( |
| 6256 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6257 | } |
| 6258 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6259 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 6260 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6261 | SourceLocation EndLoc, |
| 6262 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6263 | if (!AStmt) |
| 6264 | return StmtError(); |
| 6265 | |
| 6266 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6267 | // 1.2.2 OpenMP Language Terminology |
| 6268 | // Structured block - An executable statement with a single entry at the |
| 6269 | // top and a single exit at the bottom. |
| 6270 | // The point of exit cannot be a branch out of the structured block. |
| 6271 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6272 | CS->getCapturedDecl()->setNothrow(); |
| 6273 | |
| 6274 | OMPLoopDirective::HelperExprs B; |
| 6275 | // In presence of clause 'collapse' with number of loops, it will define the |
| 6276 | // nested loops number. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6277 | unsigned NestedLoopCount = |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6278 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 6279 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6280 | VarsWithImplicitDSA, B); |
| 6281 | if (NestedLoopCount == 0) |
| 6282 | return StmtError(); |
| 6283 | |
| 6284 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6285 | "omp target simd loop exprs were not built"); |
| 6286 | |
| 6287 | if (!CurContext->isDependentContext()) { |
| 6288 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6289 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6290 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6291 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6292 | B.NumIterations, *this, CurScope, |
| 6293 | DSAStack)) |
| 6294 | return StmtError(); |
| 6295 | } |
| 6296 | } |
| 6297 | |
| 6298 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6299 | return StmtError(); |
| 6300 | |
| 6301 | getCurFunction()->setHasBranchProtectedScope(); |
| 6302 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6303 | NestedLoopCount, Clauses, AStmt, B); |
| 6304 | } |
| 6305 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6306 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 6307 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6308 | SourceLocation EndLoc, |
| 6309 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6310 | if (!AStmt) |
| 6311 | return StmtError(); |
| 6312 | |
| 6313 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6314 | // 1.2.2 OpenMP Language Terminology |
| 6315 | // Structured block - An executable statement with a single entry at the |
| 6316 | // top and a single exit at the bottom. |
| 6317 | // The point of exit cannot be a branch out of the structured block. |
| 6318 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6319 | CS->getCapturedDecl()->setNothrow(); |
| 6320 | |
| 6321 | OMPLoopDirective::HelperExprs B; |
| 6322 | // In presence of clause 'collapse' with number of loops, it will |
| 6323 | // define the nested loops number. |
| 6324 | unsigned NestedLoopCount = |
| 6325 | CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| 6326 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6327 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6328 | if (NestedLoopCount == 0) |
| 6329 | return StmtError(); |
| 6330 | |
| 6331 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6332 | "omp teams distribute loop exprs were not built"); |
| 6333 | |
| 6334 | getCurFunction()->setHasBranchProtectedScope(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6335 | return OMPTeamsDistributeDirective::Create( |
| 6336 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6337 | } |
| 6338 | |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6339 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 6340 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6341 | SourceLocation EndLoc, |
| 6342 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6343 | if (!AStmt) |
| 6344 | return StmtError(); |
| 6345 | |
| 6346 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6347 | // 1.2.2 OpenMP Language Terminology |
| 6348 | // Structured block - An executable statement with a single entry at the |
| 6349 | // top and a single exit at the bottom. |
| 6350 | // The point of exit cannot be a branch out of the structured block. |
| 6351 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6352 | CS->getCapturedDecl()->setNothrow(); |
| 6353 | |
| 6354 | OMPLoopDirective::HelperExprs B; |
| 6355 | // In presence of clause 'collapse' with number of loops, it will |
| 6356 | // define the nested loops number. |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 6357 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6358 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6359 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6360 | VarsWithImplicitDSA, B); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6361 | |
| 6362 | if (NestedLoopCount == 0) |
| 6363 | return StmtError(); |
| 6364 | |
| 6365 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6366 | "omp teams distribute simd loop exprs were not built"); |
| 6367 | |
| 6368 | if (!CurContext->isDependentContext()) { |
| 6369 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6370 | for (auto C : Clauses) { |
| 6371 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6372 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6373 | B.NumIterations, *this, CurScope, |
| 6374 | DSAStack)) |
| 6375 | return StmtError(); |
| 6376 | } |
| 6377 | } |
| 6378 | |
| 6379 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6380 | return StmtError(); |
| 6381 | |
| 6382 | getCurFunction()->setHasBranchProtectedScope(); |
| 6383 | return OMPTeamsDistributeSimdDirective::Create( |
| 6384 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6385 | } |
| 6386 | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 6387 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 6388 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6389 | SourceLocation EndLoc, |
| 6390 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6391 | if (!AStmt) |
| 6392 | return StmtError(); |
| 6393 | |
| 6394 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6395 | // 1.2.2 OpenMP Language Terminology |
| 6396 | // Structured block - An executable statement with a single entry at the |
| 6397 | // top and a single exit at the bottom. |
| 6398 | // The point of exit cannot be a branch out of the structured block. |
| 6399 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6400 | CS->getCapturedDecl()->setNothrow(); |
| 6401 | |
| 6402 | OMPLoopDirective::HelperExprs B; |
| 6403 | // In presence of clause 'collapse' with number of loops, it will |
| 6404 | // define the nested loops number. |
| 6405 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6406 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6407 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6408 | VarsWithImplicitDSA, B); |
| 6409 | |
| 6410 | if (NestedLoopCount == 0) |
| 6411 | return StmtError(); |
| 6412 | |
| 6413 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6414 | "omp for loop exprs were not built"); |
| 6415 | |
| 6416 | if (!CurContext->isDependentContext()) { |
| 6417 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6418 | for (auto C : Clauses) { |
| 6419 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6420 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6421 | B.NumIterations, *this, CurScope, |
| 6422 | DSAStack)) |
| 6423 | return StmtError(); |
| 6424 | } |
| 6425 | } |
| 6426 | |
| 6427 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6428 | return StmtError(); |
| 6429 | |
| 6430 | getCurFunction()->setHasBranchProtectedScope(); |
| 6431 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 6432 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6433 | } |
| 6434 | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 6435 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 6436 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6437 | SourceLocation EndLoc, |
| 6438 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6439 | if (!AStmt) |
| 6440 | return StmtError(); |
| 6441 | |
| 6442 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6443 | // 1.2.2 OpenMP Language Terminology |
| 6444 | // Structured block - An executable statement with a single entry at the |
| 6445 | // top and a single exit at the bottom. |
| 6446 | // The point of exit cannot be a branch out of the structured block. |
| 6447 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6448 | CS->getCapturedDecl()->setNothrow(); |
| 6449 | |
| 6450 | OMPLoopDirective::HelperExprs B; |
| 6451 | // In presence of clause 'collapse' with number of loops, it will |
| 6452 | // define the nested loops number. |
| 6453 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6454 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6455 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6456 | VarsWithImplicitDSA, B); |
| 6457 | |
| 6458 | if (NestedLoopCount == 0) |
| 6459 | return StmtError(); |
| 6460 | |
| 6461 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6462 | "omp for loop exprs were not built"); |
| 6463 | |
| 6464 | if (!CurContext->isDependentContext()) { |
| 6465 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6466 | for (auto C : Clauses) { |
| 6467 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6468 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6469 | B.NumIterations, *this, CurScope, |
| 6470 | DSAStack)) |
| 6471 | return StmtError(); |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | getCurFunction()->setHasBranchProtectedScope(); |
| 6476 | return OMPTeamsDistributeParallelForDirective::Create( |
| 6477 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6478 | } |
| 6479 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 6480 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6481 | Stmt *AStmt, |
| 6482 | SourceLocation StartLoc, |
| 6483 | SourceLocation EndLoc) { |
| 6484 | if (!AStmt) |
| 6485 | return StmtError(); |
| 6486 | |
| 6487 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6488 | // 1.2.2 OpenMP Language Terminology |
| 6489 | // Structured block - An executable statement with a single entry at the |
| 6490 | // top and a single exit at the bottom. |
| 6491 | // The point of exit cannot be a branch out of the structured block. |
| 6492 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6493 | CS->getCapturedDecl()->setNothrow(); |
| 6494 | |
| 6495 | getCurFunction()->setHasBranchProtectedScope(); |
| 6496 | |
| 6497 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6498 | AStmt); |
| 6499 | } |
| 6500 | |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 6501 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 6502 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6503 | SourceLocation EndLoc, |
| 6504 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6505 | if (!AStmt) |
| 6506 | return StmtError(); |
| 6507 | |
| 6508 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6509 | // 1.2.2 OpenMP Language Terminology |
| 6510 | // Structured block - An executable statement with a single entry at the |
| 6511 | // top and a single exit at the bottom. |
| 6512 | // The point of exit cannot be a branch out of the structured block. |
| 6513 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6514 | CS->getCapturedDecl()->setNothrow(); |
| 6515 | |
| 6516 | OMPLoopDirective::HelperExprs B; |
| 6517 | // In presence of clause 'collapse' with number of loops, it will |
| 6518 | // define the nested loops number. |
| 6519 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6520 | OMPD_target_teams_distribute, |
| 6521 | getCollapseNumberExpr(Clauses), |
| 6522 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6523 | VarsWithImplicitDSA, B); |
| 6524 | if (NestedLoopCount == 0) |
| 6525 | return StmtError(); |
| 6526 | |
| 6527 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6528 | "omp target teams distribute loop exprs were not built"); |
| 6529 | |
| 6530 | getCurFunction()->setHasBranchProtectedScope(); |
| 6531 | return OMPTargetTeamsDistributeDirective::Create( |
| 6532 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6533 | } |
| 6534 | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 6535 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 6536 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6537 | SourceLocation EndLoc, |
| 6538 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6539 | if (!AStmt) |
| 6540 | return StmtError(); |
| 6541 | |
| 6542 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6543 | // 1.2.2 OpenMP Language Terminology |
| 6544 | // Structured block - An executable statement with a single entry at the |
| 6545 | // top and a single exit at the bottom. |
| 6546 | // The point of exit cannot be a branch out of the structured block. |
| 6547 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6548 | CS->getCapturedDecl()->setNothrow(); |
| 6549 | |
| 6550 | OMPLoopDirective::HelperExprs B; |
| 6551 | // In presence of clause 'collapse' with number of loops, it will |
| 6552 | // define the nested loops number. |
| 6553 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6554 | OMPD_target_teams_distribute_parallel_for, |
| 6555 | getCollapseNumberExpr(Clauses), |
| 6556 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6557 | VarsWithImplicitDSA, B); |
| 6558 | if (NestedLoopCount == 0) |
| 6559 | return StmtError(); |
| 6560 | |
| 6561 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6562 | "omp target teams distribute parallel for loop exprs were not built"); |
| 6563 | |
| 6564 | if (!CurContext->isDependentContext()) { |
| 6565 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6566 | for (auto C : Clauses) { |
| 6567 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6568 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6569 | B.NumIterations, *this, CurScope, |
| 6570 | DSAStack)) |
| 6571 | return StmtError(); |
| 6572 | } |
| 6573 | } |
| 6574 | |
| 6575 | getCurFunction()->setHasBranchProtectedScope(); |
| 6576 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| 6577 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6578 | } |
| 6579 | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 6580 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 6581 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6582 | SourceLocation EndLoc, |
| 6583 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6584 | if (!AStmt) |
| 6585 | return StmtError(); |
| 6586 | |
| 6587 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6588 | // 1.2.2 OpenMP Language Terminology |
| 6589 | // Structured block - An executable statement with a single entry at the |
| 6590 | // top and a single exit at the bottom. |
| 6591 | // The point of exit cannot be a branch out of the structured block. |
| 6592 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6593 | CS->getCapturedDecl()->setNothrow(); |
| 6594 | |
| 6595 | OMPLoopDirective::HelperExprs B; |
| 6596 | // In presence of clause 'collapse' with number of loops, it will |
| 6597 | // define the nested loops number. |
| 6598 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6599 | OMPD_target_teams_distribute_parallel_for_simd, |
| 6600 | getCollapseNumberExpr(Clauses), |
| 6601 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6602 | VarsWithImplicitDSA, B); |
| 6603 | if (NestedLoopCount == 0) |
| 6604 | return StmtError(); |
| 6605 | |
| 6606 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6607 | "omp target teams distribute parallel for simd loop exprs were not " |
| 6608 | "built"); |
| 6609 | |
| 6610 | if (!CurContext->isDependentContext()) { |
| 6611 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6612 | for (auto C : Clauses) { |
| 6613 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6614 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6615 | B.NumIterations, *this, CurScope, |
| 6616 | DSAStack)) |
| 6617 | return StmtError(); |
| 6618 | } |
| 6619 | } |
| 6620 | |
| 6621 | getCurFunction()->setHasBranchProtectedScope(); |
| 6622 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 6623 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6624 | } |
| 6625 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 6626 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 6627 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6628 | SourceLocation EndLoc, |
| 6629 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6630 | if (!AStmt) |
| 6631 | return StmtError(); |
| 6632 | |
| 6633 | auto *CS = cast<CapturedStmt>(AStmt); |
| 6634 | // 1.2.2 OpenMP Language Terminology |
| 6635 | // Structured block - An executable statement with a single entry at the |
| 6636 | // top and a single exit at the bottom. |
| 6637 | // The point of exit cannot be a branch out of the structured block. |
| 6638 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6639 | CS->getCapturedDecl()->setNothrow(); |
| 6640 | |
| 6641 | OMPLoopDirective::HelperExprs B; |
| 6642 | // In presence of clause 'collapse' with number of loops, it will |
| 6643 | // define the nested loops number. |
| 6644 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6645 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6646 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6647 | VarsWithImplicitDSA, B); |
| 6648 | if (NestedLoopCount == 0) |
| 6649 | return StmtError(); |
| 6650 | |
| 6651 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6652 | "omp target teams distribute simd loop exprs were not built"); |
| 6653 | |
| 6654 | getCurFunction()->setHasBranchProtectedScope(); |
| 6655 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 6656 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6657 | } |
| 6658 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6659 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6660 | SourceLocation StartLoc, |
| 6661 | SourceLocation LParenLoc, |
| 6662 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6663 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6664 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6665 | case OMPC_final: |
| 6666 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6667 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6668 | case OMPC_num_threads: |
| 6669 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6670 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6671 | case OMPC_safelen: |
| 6672 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6673 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6674 | case OMPC_simdlen: |
| 6675 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6676 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6677 | case OMPC_collapse: |
| 6678 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6679 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6680 | case OMPC_ordered: |
| 6681 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6682 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6683 | case OMPC_device: |
| 6684 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6685 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6686 | case OMPC_num_teams: |
| 6687 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6688 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6689 | case OMPC_thread_limit: |
| 6690 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6691 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6692 | case OMPC_priority: |
| 6693 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6694 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6695 | case OMPC_grainsize: |
| 6696 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6697 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6698 | case OMPC_num_tasks: |
| 6699 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6700 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6701 | case OMPC_hint: |
| 6702 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6703 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6704 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6705 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6706 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6707 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6708 | case OMPC_private: |
| 6709 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6710 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6711 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6712 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6713 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6714 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6715 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6716 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6717 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6718 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6719 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6720 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6721 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6722 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6723 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6724 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6725 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6726 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6727 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6728 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6729 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6730 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6731 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6732 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6733 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6734 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6735 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6736 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6737 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6738 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6739 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6740 | llvm_unreachable("Clause is not allowed."); |
| 6741 | } |
| 6742 | return Res; |
| 6743 | } |
| 6744 | |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 6745 | // An OpenMP directive such as 'target parallel' has two captured regions: |
| 6746 | // for the 'target' and 'parallel' respectively. This function returns |
| 6747 | // the region in which to capture expressions associated with a clause. |
| 6748 | // A return value of OMPD_unknown signifies that the expression should not |
| 6749 | // be captured. |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 6750 | static OpenMPDirectiveKind getOpenMPCaptureRegionForClause( |
| 6751 | OpenMPDirectiveKind DKind, OpenMPClauseKind CKind, |
| 6752 | OpenMPDirectiveKind NameModifier = OMPD_unknown) { |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 6753 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
| 6754 | |
| 6755 | switch (CKind) { |
| 6756 | case OMPC_if: |
| 6757 | switch (DKind) { |
| 6758 | case OMPD_target_parallel: |
| 6759 | // If this clause applies to the nested 'parallel' region, capture within |
| 6760 | // the 'target' region, otherwise do not capture. |
| 6761 | if (NameModifier == OMPD_unknown || NameModifier == OMPD_parallel) |
| 6762 | CaptureRegion = OMPD_target; |
| 6763 | break; |
| 6764 | case OMPD_cancel: |
| 6765 | case OMPD_parallel: |
| 6766 | case OMPD_parallel_sections: |
| 6767 | case OMPD_parallel_for: |
| 6768 | case OMPD_parallel_for_simd: |
| 6769 | case OMPD_target: |
| 6770 | case OMPD_target_simd: |
| 6771 | case OMPD_target_parallel_for: |
| 6772 | case OMPD_target_parallel_for_simd: |
| 6773 | case OMPD_target_teams: |
| 6774 | case OMPD_target_teams_distribute: |
| 6775 | case OMPD_target_teams_distribute_simd: |
| 6776 | case OMPD_target_teams_distribute_parallel_for: |
| 6777 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6778 | case OMPD_teams_distribute_parallel_for: |
| 6779 | case OMPD_teams_distribute_parallel_for_simd: |
| 6780 | case OMPD_distribute_parallel_for: |
| 6781 | case OMPD_distribute_parallel_for_simd: |
| 6782 | case OMPD_task: |
| 6783 | case OMPD_taskloop: |
| 6784 | case OMPD_taskloop_simd: |
| 6785 | case OMPD_target_data: |
| 6786 | case OMPD_target_enter_data: |
| 6787 | case OMPD_target_exit_data: |
| 6788 | case OMPD_target_update: |
| 6789 | // Do not capture if-clause expressions. |
| 6790 | break; |
| 6791 | case OMPD_threadprivate: |
| 6792 | case OMPD_taskyield: |
| 6793 | case OMPD_barrier: |
| 6794 | case OMPD_taskwait: |
| 6795 | case OMPD_cancellation_point: |
| 6796 | case OMPD_flush: |
| 6797 | case OMPD_declare_reduction: |
| 6798 | case OMPD_declare_simd: |
| 6799 | case OMPD_declare_target: |
| 6800 | case OMPD_end_declare_target: |
| 6801 | case OMPD_teams: |
| 6802 | case OMPD_simd: |
| 6803 | case OMPD_for: |
| 6804 | case OMPD_for_simd: |
| 6805 | case OMPD_sections: |
| 6806 | case OMPD_section: |
| 6807 | case OMPD_single: |
| 6808 | case OMPD_master: |
| 6809 | case OMPD_critical: |
| 6810 | case OMPD_taskgroup: |
| 6811 | case OMPD_distribute: |
| 6812 | case OMPD_ordered: |
| 6813 | case OMPD_atomic: |
| 6814 | case OMPD_distribute_simd: |
| 6815 | case OMPD_teams_distribute: |
| 6816 | case OMPD_teams_distribute_simd: |
| 6817 | llvm_unreachable("Unexpected OpenMP directive with if-clause"); |
| 6818 | case OMPD_unknown: |
| 6819 | llvm_unreachable("Unknown OpenMP directive"); |
| 6820 | } |
| 6821 | break; |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 6822 | case OMPC_num_threads: |
| 6823 | switch (DKind) { |
| 6824 | case OMPD_target_parallel: |
| 6825 | CaptureRegion = OMPD_target; |
| 6826 | break; |
| 6827 | case OMPD_cancel: |
| 6828 | case OMPD_parallel: |
| 6829 | case OMPD_parallel_sections: |
| 6830 | case OMPD_parallel_for: |
| 6831 | case OMPD_parallel_for_simd: |
| 6832 | case OMPD_target: |
| 6833 | case OMPD_target_simd: |
| 6834 | case OMPD_target_parallel_for: |
| 6835 | case OMPD_target_parallel_for_simd: |
| 6836 | case OMPD_target_teams: |
| 6837 | case OMPD_target_teams_distribute: |
| 6838 | case OMPD_target_teams_distribute_simd: |
| 6839 | case OMPD_target_teams_distribute_parallel_for: |
| 6840 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6841 | case OMPD_teams_distribute_parallel_for: |
| 6842 | case OMPD_teams_distribute_parallel_for_simd: |
| 6843 | case OMPD_distribute_parallel_for: |
| 6844 | case OMPD_distribute_parallel_for_simd: |
| 6845 | case OMPD_task: |
| 6846 | case OMPD_taskloop: |
| 6847 | case OMPD_taskloop_simd: |
| 6848 | case OMPD_target_data: |
| 6849 | case OMPD_target_enter_data: |
| 6850 | case OMPD_target_exit_data: |
| 6851 | case OMPD_target_update: |
| 6852 | // Do not capture num_threads-clause expressions. |
| 6853 | break; |
| 6854 | case OMPD_threadprivate: |
| 6855 | case OMPD_taskyield: |
| 6856 | case OMPD_barrier: |
| 6857 | case OMPD_taskwait: |
| 6858 | case OMPD_cancellation_point: |
| 6859 | case OMPD_flush: |
| 6860 | case OMPD_declare_reduction: |
| 6861 | case OMPD_declare_simd: |
| 6862 | case OMPD_declare_target: |
| 6863 | case OMPD_end_declare_target: |
| 6864 | case OMPD_teams: |
| 6865 | case OMPD_simd: |
| 6866 | case OMPD_for: |
| 6867 | case OMPD_for_simd: |
| 6868 | case OMPD_sections: |
| 6869 | case OMPD_section: |
| 6870 | case OMPD_single: |
| 6871 | case OMPD_master: |
| 6872 | case OMPD_critical: |
| 6873 | case OMPD_taskgroup: |
| 6874 | case OMPD_distribute: |
| 6875 | case OMPD_ordered: |
| 6876 | case OMPD_atomic: |
| 6877 | case OMPD_distribute_simd: |
| 6878 | case OMPD_teams_distribute: |
| 6879 | case OMPD_teams_distribute_simd: |
| 6880 | llvm_unreachable("Unexpected OpenMP directive with num_threads-clause"); |
| 6881 | case OMPD_unknown: |
| 6882 | llvm_unreachable("Unknown OpenMP directive"); |
| 6883 | } |
| 6884 | break; |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 6885 | case OMPC_num_teams: |
| 6886 | switch (DKind) { |
| 6887 | case OMPD_target_teams: |
| 6888 | CaptureRegion = OMPD_target; |
| 6889 | break; |
| 6890 | case OMPD_cancel: |
| 6891 | case OMPD_parallel: |
| 6892 | case OMPD_parallel_sections: |
| 6893 | case OMPD_parallel_for: |
| 6894 | case OMPD_parallel_for_simd: |
| 6895 | case OMPD_target: |
| 6896 | case OMPD_target_simd: |
| 6897 | case OMPD_target_parallel: |
| 6898 | case OMPD_target_parallel_for: |
| 6899 | case OMPD_target_parallel_for_simd: |
| 6900 | case OMPD_target_teams_distribute: |
| 6901 | case OMPD_target_teams_distribute_simd: |
| 6902 | case OMPD_target_teams_distribute_parallel_for: |
| 6903 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6904 | case OMPD_teams_distribute_parallel_for: |
| 6905 | case OMPD_teams_distribute_parallel_for_simd: |
| 6906 | case OMPD_distribute_parallel_for: |
| 6907 | case OMPD_distribute_parallel_for_simd: |
| 6908 | case OMPD_task: |
| 6909 | case OMPD_taskloop: |
| 6910 | case OMPD_taskloop_simd: |
| 6911 | case OMPD_target_data: |
| 6912 | case OMPD_target_enter_data: |
| 6913 | case OMPD_target_exit_data: |
| 6914 | case OMPD_target_update: |
| 6915 | case OMPD_teams: |
| 6916 | case OMPD_teams_distribute: |
| 6917 | case OMPD_teams_distribute_simd: |
| 6918 | // Do not capture num_teams-clause expressions. |
| 6919 | break; |
| 6920 | case OMPD_threadprivate: |
| 6921 | case OMPD_taskyield: |
| 6922 | case OMPD_barrier: |
| 6923 | case OMPD_taskwait: |
| 6924 | case OMPD_cancellation_point: |
| 6925 | case OMPD_flush: |
| 6926 | case OMPD_declare_reduction: |
| 6927 | case OMPD_declare_simd: |
| 6928 | case OMPD_declare_target: |
| 6929 | case OMPD_end_declare_target: |
| 6930 | case OMPD_simd: |
| 6931 | case OMPD_for: |
| 6932 | case OMPD_for_simd: |
| 6933 | case OMPD_sections: |
| 6934 | case OMPD_section: |
| 6935 | case OMPD_single: |
| 6936 | case OMPD_master: |
| 6937 | case OMPD_critical: |
| 6938 | case OMPD_taskgroup: |
| 6939 | case OMPD_distribute: |
| 6940 | case OMPD_ordered: |
| 6941 | case OMPD_atomic: |
| 6942 | case OMPD_distribute_simd: |
| 6943 | llvm_unreachable("Unexpected OpenMP directive with num_teams-clause"); |
| 6944 | case OMPD_unknown: |
| 6945 | llvm_unreachable("Unknown OpenMP directive"); |
| 6946 | } |
| 6947 | break; |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 6948 | case OMPC_thread_limit: |
| 6949 | switch (DKind) { |
| 6950 | case OMPD_target_teams: |
| 6951 | CaptureRegion = OMPD_target; |
| 6952 | break; |
| 6953 | case OMPD_cancel: |
| 6954 | case OMPD_parallel: |
| 6955 | case OMPD_parallel_sections: |
| 6956 | case OMPD_parallel_for: |
| 6957 | case OMPD_parallel_for_simd: |
| 6958 | case OMPD_target: |
| 6959 | case OMPD_target_simd: |
| 6960 | case OMPD_target_parallel: |
| 6961 | case OMPD_target_parallel_for: |
| 6962 | case OMPD_target_parallel_for_simd: |
| 6963 | case OMPD_target_teams_distribute: |
| 6964 | case OMPD_target_teams_distribute_simd: |
| 6965 | case OMPD_target_teams_distribute_parallel_for: |
| 6966 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 6967 | case OMPD_teams_distribute_parallel_for: |
| 6968 | case OMPD_teams_distribute_parallel_for_simd: |
| 6969 | case OMPD_distribute_parallel_for: |
| 6970 | case OMPD_distribute_parallel_for_simd: |
| 6971 | case OMPD_task: |
| 6972 | case OMPD_taskloop: |
| 6973 | case OMPD_taskloop_simd: |
| 6974 | case OMPD_target_data: |
| 6975 | case OMPD_target_enter_data: |
| 6976 | case OMPD_target_exit_data: |
| 6977 | case OMPD_target_update: |
| 6978 | case OMPD_teams: |
| 6979 | case OMPD_teams_distribute: |
| 6980 | case OMPD_teams_distribute_simd: |
| 6981 | // Do not capture thread_limit-clause expressions. |
| 6982 | break; |
| 6983 | case OMPD_threadprivate: |
| 6984 | case OMPD_taskyield: |
| 6985 | case OMPD_barrier: |
| 6986 | case OMPD_taskwait: |
| 6987 | case OMPD_cancellation_point: |
| 6988 | case OMPD_flush: |
| 6989 | case OMPD_declare_reduction: |
| 6990 | case OMPD_declare_simd: |
| 6991 | case OMPD_declare_target: |
| 6992 | case OMPD_end_declare_target: |
| 6993 | case OMPD_simd: |
| 6994 | case OMPD_for: |
| 6995 | case OMPD_for_simd: |
| 6996 | case OMPD_sections: |
| 6997 | case OMPD_section: |
| 6998 | case OMPD_single: |
| 6999 | case OMPD_master: |
| 7000 | case OMPD_critical: |
| 7001 | case OMPD_taskgroup: |
| 7002 | case OMPD_distribute: |
| 7003 | case OMPD_ordered: |
| 7004 | case OMPD_atomic: |
| 7005 | case OMPD_distribute_simd: |
| 7006 | llvm_unreachable("Unexpected OpenMP directive with thread_limit-clause"); |
| 7007 | case OMPD_unknown: |
| 7008 | llvm_unreachable("Unknown OpenMP directive"); |
| 7009 | } |
| 7010 | break; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7011 | case OMPC_schedule: |
| 7012 | case OMPC_dist_schedule: |
| 7013 | case OMPC_firstprivate: |
| 7014 | case OMPC_lastprivate: |
| 7015 | case OMPC_reduction: |
| 7016 | case OMPC_linear: |
| 7017 | case OMPC_default: |
| 7018 | case OMPC_proc_bind: |
| 7019 | case OMPC_final: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7020 | case OMPC_safelen: |
| 7021 | case OMPC_simdlen: |
| 7022 | case OMPC_collapse: |
| 7023 | case OMPC_private: |
| 7024 | case OMPC_shared: |
| 7025 | case OMPC_aligned: |
| 7026 | case OMPC_copyin: |
| 7027 | case OMPC_copyprivate: |
| 7028 | case OMPC_ordered: |
| 7029 | case OMPC_nowait: |
| 7030 | case OMPC_untied: |
| 7031 | case OMPC_mergeable: |
| 7032 | case OMPC_threadprivate: |
| 7033 | case OMPC_flush: |
| 7034 | case OMPC_read: |
| 7035 | case OMPC_write: |
| 7036 | case OMPC_update: |
| 7037 | case OMPC_capture: |
| 7038 | case OMPC_seq_cst: |
| 7039 | case OMPC_depend: |
| 7040 | case OMPC_device: |
| 7041 | case OMPC_threads: |
| 7042 | case OMPC_simd: |
| 7043 | case OMPC_map: |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7044 | case OMPC_priority: |
| 7045 | case OMPC_grainsize: |
| 7046 | case OMPC_nogroup: |
| 7047 | case OMPC_num_tasks: |
| 7048 | case OMPC_hint: |
| 7049 | case OMPC_defaultmap: |
| 7050 | case OMPC_unknown: |
| 7051 | case OMPC_uniform: |
| 7052 | case OMPC_to: |
| 7053 | case OMPC_from: |
| 7054 | case OMPC_use_device_ptr: |
| 7055 | case OMPC_is_device_ptr: |
| 7056 | llvm_unreachable("Unexpected OpenMP clause."); |
| 7057 | } |
| 7058 | return CaptureRegion; |
| 7059 | } |
| 7060 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7061 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 7062 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7063 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7064 | SourceLocation NameModifierLoc, |
| 7065 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7066 | SourceLocation EndLoc) { |
| 7067 | Expr *ValExpr = Condition; |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7068 | Stmt *HelperValStmt = nullptr; |
| 7069 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7070 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7071 | !Condition->isInstantiationDependent() && |
| 7072 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7073 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7074 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7075 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7076 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7077 | ValExpr = MakeFullExpr(Val.get()).get(); |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7078 | |
| 7079 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 7080 | CaptureRegion = |
| 7081 | getOpenMPCaptureRegionForClause(DKind, OMPC_if, NameModifier); |
| 7082 | if (CaptureRegion != OMPD_unknown) { |
| 7083 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7084 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7085 | HelperValStmt = buildPreInits(Context, Captures); |
| 7086 | } |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7087 | } |
| 7088 | |
Arpith Chacko Jacob | fe4890a | 2017-01-18 20:40:48 +0000 | [diff] [blame] | 7089 | return new (Context) |
| 7090 | OMPIfClause(NameModifier, ValExpr, HelperValStmt, CaptureRegion, StartLoc, |
| 7091 | LParenLoc, NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7092 | } |
| 7093 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7094 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 7095 | SourceLocation StartLoc, |
| 7096 | SourceLocation LParenLoc, |
| 7097 | SourceLocation EndLoc) { |
| 7098 | Expr *ValExpr = Condition; |
| 7099 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 7100 | !Condition->isInstantiationDependent() && |
| 7101 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7102 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7103 | if (Val.isInvalid()) |
| 7104 | return nullptr; |
| 7105 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 7106 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7107 | } |
| 7108 | |
| 7109 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 7110 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 7111 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 7112 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7113 | if (!Op) |
| 7114 | return ExprError(); |
| 7115 | |
| 7116 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 7117 | public: |
| 7118 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7119 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 7120 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 7121 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7122 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 7123 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7124 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 7125 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7126 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 7127 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7128 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 7129 | QualType T, |
| 7130 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7131 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 7132 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7133 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 7134 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7135 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7136 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7137 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7138 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 7139 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7140 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 7141 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7142 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 7143 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7144 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7145 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7146 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7147 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 7148 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7149 | llvm_unreachable("conversion functions are permitted"); |
| 7150 | } |
| 7151 | } ConvertDiagnoser; |
| 7152 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 7153 | } |
| 7154 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7155 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7156 | OpenMPClauseKind CKind, |
| 7157 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7158 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 7159 | !ValExpr->isInstantiationDependent()) { |
| 7160 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 7161 | ExprResult Value = |
| 7162 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 7163 | if (Value.isInvalid()) |
| 7164 | return false; |
| 7165 | |
| 7166 | ValExpr = Value.get(); |
| 7167 | // The expression must evaluate to a non-negative integer value. |
| 7168 | llvm::APSInt Result; |
| 7169 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7170 | Result.isSigned() && |
| 7171 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 7172 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7173 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7174 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7175 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7176 | return false; |
| 7177 | } |
| 7178 | } |
| 7179 | return true; |
| 7180 | } |
| 7181 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7182 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 7183 | SourceLocation StartLoc, |
| 7184 | SourceLocation LParenLoc, |
| 7185 | SourceLocation EndLoc) { |
| 7186 | Expr *ValExpr = NumThreads; |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7187 | Stmt *HelperValStmt = nullptr; |
| 7188 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7189 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7190 | // OpenMP [2.5, Restrictions] |
| 7191 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7192 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 7193 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7194 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7195 | |
Arpith Chacko Jacob | 33c849a | 2017-01-25 00:57:16 +0000 | [diff] [blame] | 7196 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 7197 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_num_threads); |
| 7198 | if (CaptureRegion != OMPD_unknown) { |
| 7199 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7200 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7201 | HelperValStmt = buildPreInits(Context, Captures); |
| 7202 | } |
| 7203 | |
| 7204 | return new (Context) OMPNumThreadsClause( |
| 7205 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7206 | } |
| 7207 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7208 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7209 | OpenMPClauseKind CKind, |
| 7210 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7211 | if (!E) |
| 7212 | return ExprError(); |
| 7213 | if (E->isValueDependent() || E->isTypeDependent() || |
| 7214 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 7215 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7216 | llvm::APSInt Result; |
| 7217 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 7218 | if (ICE.isInvalid()) |
| 7219 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7220 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 7221 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7222 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7223 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 7224 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7225 | return ExprError(); |
| 7226 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 7227 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 7228 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 7229 | << E->getSourceRange(); |
| 7230 | return ExprError(); |
| 7231 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7232 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 7233 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 7234 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 7235 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7236 | return ICE; |
| 7237 | } |
| 7238 | |
| 7239 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 7240 | SourceLocation LParenLoc, |
| 7241 | SourceLocation EndLoc) { |
| 7242 | // OpenMP [2.8.1, simd construct, Description] |
| 7243 | // The parameter of the safelen clause must be a constant |
| 7244 | // positive integer expression. |
| 7245 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 7246 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7247 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7248 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 7249 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7250 | } |
| 7251 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7252 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 7253 | SourceLocation LParenLoc, |
| 7254 | SourceLocation EndLoc) { |
| 7255 | // OpenMP [2.8.1, simd construct, Description] |
| 7256 | // The parameter of the simdlen clause must be a constant |
| 7257 | // positive integer expression. |
| 7258 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 7259 | if (Simdlen.isInvalid()) |
| 7260 | return nullptr; |
| 7261 | return new (Context) |
| 7262 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 7263 | } |
| 7264 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7265 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 7266 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7267 | SourceLocation LParenLoc, |
| 7268 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7269 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7270 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7271 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7272 | // The parameter of the collapse clause must be a constant |
| 7273 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7274 | ExprResult NumForLoopsResult = |
| 7275 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 7276 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7277 | return nullptr; |
| 7278 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 7279 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7280 | } |
| 7281 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7282 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 7283 | SourceLocation EndLoc, |
| 7284 | SourceLocation LParenLoc, |
| 7285 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7286 | // OpenMP [2.7.1, loop construct, Description] |
| 7287 | // OpenMP [2.8.1, simd construct, Description] |
| 7288 | // OpenMP [2.9.6, distribute construct, Description] |
| 7289 | // The parameter of the ordered clause must be a constant |
| 7290 | // positive integer expression if any. |
| 7291 | if (NumForLoops && LParenLoc.isValid()) { |
| 7292 | ExprResult NumForLoopsResult = |
| 7293 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 7294 | if (NumForLoopsResult.isInvalid()) |
| 7295 | return nullptr; |
| 7296 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7297 | } else |
| 7298 | NumForLoops = nullptr; |
| 7299 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 7300 | return new (Context) |
| 7301 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 7302 | } |
| 7303 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7304 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 7305 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 7306 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7307 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7308 | switch (Kind) { |
| 7309 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7310 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7311 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 7312 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7313 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7314 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7315 | Res = ActOnOpenMPProcBindClause( |
| 7316 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 7317 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7318 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7319 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7320 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7321 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7322 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7323 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7324 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7325 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7326 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7327 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7328 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7329 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7330 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7331 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7332 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7333 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7334 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7335 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7336 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7337 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7338 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7339 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7340 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7341 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7342 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7343 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7344 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7345 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7346 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7347 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7348 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7349 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7350 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7351 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7352 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7353 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7354 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7355 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7356 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7357 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7358 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7359 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7360 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7361 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7362 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7363 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7364 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7365 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7366 | llvm_unreachable("Clause is not allowed."); |
| 7367 | } |
| 7368 | return Res; |
| 7369 | } |
| 7370 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7371 | static std::string |
| 7372 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 7373 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 7374 | std::string Values; |
| 7375 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 7376 | unsigned Skipped = Exclude.size(); |
| 7377 | auto S = Exclude.begin(), E = Exclude.end(); |
| 7378 | for (unsigned i = First; i < Last; ++i) { |
| 7379 | if (std::find(S, E, i) != E) { |
| 7380 | --Skipped; |
| 7381 | continue; |
| 7382 | } |
| 7383 | Values += "'"; |
| 7384 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 7385 | Values += "'"; |
| 7386 | if (i == Bound - Skipped) |
| 7387 | Values += " or "; |
| 7388 | else if (i != Bound + 1 - Skipped) |
| 7389 | Values += ", "; |
| 7390 | } |
| 7391 | return Values; |
| 7392 | } |
| 7393 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7394 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 7395 | SourceLocation KindKwLoc, |
| 7396 | SourceLocation StartLoc, |
| 7397 | SourceLocation LParenLoc, |
| 7398 | SourceLocation EndLoc) { |
| 7399 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 7400 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 7401 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7402 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7403 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 7404 | /*Last=*/OMPC_DEFAULT_unknown) |
| 7405 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7406 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7407 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7408 | switch (Kind) { |
| 7409 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7410 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7411 | break; |
| 7412 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7413 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7414 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7415 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7416 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7417 | break; |
| 7418 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7419 | return new (Context) |
| 7420 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7421 | } |
| 7422 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7423 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 7424 | SourceLocation KindKwLoc, |
| 7425 | SourceLocation StartLoc, |
| 7426 | SourceLocation LParenLoc, |
| 7427 | SourceLocation EndLoc) { |
| 7428 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7429 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7430 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 7431 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 7432 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7433 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7434 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7435 | return new (Context) |
| 7436 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7437 | } |
| 7438 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7439 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7440 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7441 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7442 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7443 | SourceLocation EndLoc) { |
| 7444 | OMPClause *Res = nullptr; |
| 7445 | switch (Kind) { |
| 7446 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7447 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 7448 | assert(Argument.size() == NumberOfElements && |
| 7449 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7450 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7451 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 7452 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 7453 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 7454 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 7455 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7456 | break; |
| 7457 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7458 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 7459 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 7460 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 7461 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 7462 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7463 | case OMPC_dist_schedule: |
| 7464 | Res = ActOnOpenMPDistScheduleClause( |
| 7465 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 7466 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 7467 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7468 | case OMPC_defaultmap: |
| 7469 | enum { Modifier, DefaultmapKind }; |
| 7470 | Res = ActOnOpenMPDefaultmapClause( |
| 7471 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7472 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7473 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 7474 | EndLoc); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7475 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7476 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7477 | case OMPC_num_threads: |
| 7478 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7479 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7480 | case OMPC_collapse: |
| 7481 | case OMPC_default: |
| 7482 | case OMPC_proc_bind: |
| 7483 | case OMPC_private: |
| 7484 | case OMPC_firstprivate: |
| 7485 | case OMPC_lastprivate: |
| 7486 | case OMPC_shared: |
| 7487 | case OMPC_reduction: |
| 7488 | case OMPC_linear: |
| 7489 | case OMPC_aligned: |
| 7490 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7491 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7492 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7493 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7494 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7495 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7496 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7497 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7498 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7499 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7500 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7501 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7502 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7503 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7504 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7505 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7506 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7507 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7508 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7509 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7510 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7511 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7512 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7513 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7514 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7515 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7516 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7517 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7518 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7519 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7520 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7521 | llvm_unreachable("Clause is not allowed."); |
| 7522 | } |
| 7523 | return Res; |
| 7524 | } |
| 7525 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7526 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7527 | OpenMPScheduleClauseModifier M2, |
| 7528 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7529 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7530 | SmallVector<unsigned, 2> Excluded; |
| 7531 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7532 | Excluded.push_back(M2); |
| 7533 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7534 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7535 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7536 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7537 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7538 | << getListOfPossibleValues(OMPC_schedule, |
| 7539 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7540 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7541 | Excluded) |
| 7542 | << getOpenMPClauseName(OMPC_schedule); |
| 7543 | return true; |
| 7544 | } |
| 7545 | return false; |
| 7546 | } |
| 7547 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7548 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7549 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7550 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7551 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7552 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7553 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7554 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7555 | return nullptr; |
| 7556 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7557 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7558 | // but not both. |
| 7559 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7560 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7561 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7562 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7563 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7564 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7565 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7566 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7567 | return nullptr; |
| 7568 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7569 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7570 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7571 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7572 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7573 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7574 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7575 | Exclude); |
| 7576 | } else { |
| 7577 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7578 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7579 | } |
| 7580 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7581 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7582 | return nullptr; |
| 7583 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7584 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7585 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7586 | // schedule(guided). |
| 7587 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7588 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7589 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7590 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7591 | diag::err_omp_schedule_nonmonotonic_static); |
| 7592 | return nullptr; |
| 7593 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7594 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7595 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7596 | if (ChunkSize) { |
| 7597 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7598 | !ChunkSize->isInstantiationDependent() && |
| 7599 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7600 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7601 | ExprResult Val = |
| 7602 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7603 | if (Val.isInvalid()) |
| 7604 | return nullptr; |
| 7605 | |
| 7606 | ValExpr = Val.get(); |
| 7607 | |
| 7608 | // OpenMP [2.7.1, Restrictions] |
| 7609 | // chunk_size must be a loop invariant integer expression with a positive |
| 7610 | // value. |
| 7611 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7612 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7613 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7614 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7615 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7616 | return nullptr; |
| 7617 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7618 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7619 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7620 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7621 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7622 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7623 | } |
| 7624 | } |
| 7625 | } |
| 7626 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7627 | return new (Context) |
| 7628 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7629 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7630 | } |
| 7631 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7632 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7633 | SourceLocation StartLoc, |
| 7634 | SourceLocation EndLoc) { |
| 7635 | OMPClause *Res = nullptr; |
| 7636 | switch (Kind) { |
| 7637 | case OMPC_ordered: |
| 7638 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7639 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7640 | case OMPC_nowait: |
| 7641 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7642 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7643 | case OMPC_untied: |
| 7644 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7645 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7646 | case OMPC_mergeable: |
| 7647 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7648 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7649 | case OMPC_read: |
| 7650 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7651 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7652 | case OMPC_write: |
| 7653 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7654 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7655 | case OMPC_update: |
| 7656 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7657 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7658 | case OMPC_capture: |
| 7659 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7660 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7661 | case OMPC_seq_cst: |
| 7662 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7663 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7664 | case OMPC_threads: |
| 7665 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7666 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7667 | case OMPC_simd: |
| 7668 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7669 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7670 | case OMPC_nogroup: |
| 7671 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7672 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7673 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7674 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7675 | case OMPC_num_threads: |
| 7676 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7677 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7678 | case OMPC_collapse: |
| 7679 | case OMPC_schedule: |
| 7680 | case OMPC_private: |
| 7681 | case OMPC_firstprivate: |
| 7682 | case OMPC_lastprivate: |
| 7683 | case OMPC_shared: |
| 7684 | case OMPC_reduction: |
| 7685 | case OMPC_linear: |
| 7686 | case OMPC_aligned: |
| 7687 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7688 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7689 | case OMPC_default: |
| 7690 | case OMPC_proc_bind: |
| 7691 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7692 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7693 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7694 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7695 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7696 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7697 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7698 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7699 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7700 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7701 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7702 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7703 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7704 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7705 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7706 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7707 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7708 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7709 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7710 | llvm_unreachable("Clause is not allowed."); |
| 7711 | } |
| 7712 | return Res; |
| 7713 | } |
| 7714 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7715 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7716 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7717 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7718 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7719 | } |
| 7720 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7721 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7722 | SourceLocation EndLoc) { |
| 7723 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7724 | } |
| 7725 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7726 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7727 | SourceLocation EndLoc) { |
| 7728 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7729 | } |
| 7730 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7731 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7732 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7733 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7734 | } |
| 7735 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7736 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7737 | SourceLocation EndLoc) { |
| 7738 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7739 | } |
| 7740 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7741 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7742 | SourceLocation EndLoc) { |
| 7743 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7744 | } |
| 7745 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7746 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7747 | SourceLocation EndLoc) { |
| 7748 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7749 | } |
| 7750 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7751 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7752 | SourceLocation EndLoc) { |
| 7753 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7754 | } |
| 7755 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7756 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7757 | SourceLocation EndLoc) { |
| 7758 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7759 | } |
| 7760 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7761 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7762 | SourceLocation EndLoc) { |
| 7763 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7764 | } |
| 7765 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7766 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7767 | SourceLocation EndLoc) { |
| 7768 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7769 | } |
| 7770 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7771 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7772 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7773 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7774 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7775 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7776 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7777 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7778 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7779 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7780 | switch (Kind) { |
| 7781 | case OMPC_private: |
| 7782 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7783 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7784 | case OMPC_firstprivate: |
| 7785 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7786 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7787 | case OMPC_lastprivate: |
| 7788 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7789 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7790 | case OMPC_shared: |
| 7791 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7792 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7793 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7794 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7795 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7796 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7797 | case OMPC_linear: |
| 7798 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7799 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7800 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7801 | case OMPC_aligned: |
| 7802 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7803 | ColonLoc, EndLoc); |
| 7804 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7805 | case OMPC_copyin: |
| 7806 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7807 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7808 | case OMPC_copyprivate: |
| 7809 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7810 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7811 | case OMPC_flush: |
| 7812 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7813 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7814 | case OMPC_depend: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7815 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7816 | StartLoc, LParenLoc, EndLoc); |
| 7817 | break; |
| 7818 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7819 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7820 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7821 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7822 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7823 | case OMPC_to: |
| 7824 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7825 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7826 | case OMPC_from: |
| 7827 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7828 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7829 | case OMPC_use_device_ptr: |
| 7830 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7831 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7832 | case OMPC_is_device_ptr: |
| 7833 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7834 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7835 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7836 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7837 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7838 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7839 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7840 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7841 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7842 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7843 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7844 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7845 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7846 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7847 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7848 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7849 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7850 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7851 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7852 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7853 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7854 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7855 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7856 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7857 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7858 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7859 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7860 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7861 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7862 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7863 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7864 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7865 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7866 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7867 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7868 | llvm_unreachable("Clause is not allowed."); |
| 7869 | } |
| 7870 | return Res; |
| 7871 | } |
| 7872 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7873 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7874 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7875 | ExprResult Res = BuildDeclRefExpr( |
| 7876 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7877 | if (!Res.isUsable()) |
| 7878 | return ExprError(); |
| 7879 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7880 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7881 | if (!Res.isUsable()) |
| 7882 | return ExprError(); |
| 7883 | } |
| 7884 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7885 | Res = DefaultLvalueConversion(Res.get()); |
| 7886 | if (!Res.isUsable()) |
| 7887 | return ExprError(); |
| 7888 | } |
| 7889 | return Res; |
| 7890 | } |
| 7891 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7892 | static std::pair<ValueDecl *, bool> |
| 7893 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7894 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7895 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7896 | RefExpr->containsUnexpandedParameterPack()) |
| 7897 | return std::make_pair(nullptr, true); |
| 7898 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7899 | // OpenMP [3.1, C/C++] |
| 7900 | // A list item is a variable name. |
| 7901 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7902 | // A variable that is part of another variable (as an array or |
| 7903 | // structure element) cannot appear in a private clause. |
| 7904 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7905 | enum { |
| 7906 | NoArrayExpr = -1, |
| 7907 | ArraySubscript = 0, |
| 7908 | OMPArraySection = 1 |
| 7909 | } IsArrayExpr = NoArrayExpr; |
| 7910 | if (AllowArraySection) { |
| 7911 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7912 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7913 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7914 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7915 | RefExpr = Base; |
| 7916 | IsArrayExpr = ArraySubscript; |
| 7917 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7918 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7919 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7920 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7921 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7922 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7923 | RefExpr = Base; |
| 7924 | IsArrayExpr = OMPArraySection; |
| 7925 | } |
| 7926 | } |
| 7927 | ELoc = RefExpr->getExprLoc(); |
| 7928 | ERange = RefExpr->getSourceRange(); |
| 7929 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7930 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7931 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7932 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7933 | (S.getCurrentThisType().isNull() || !ME || |
| 7934 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7935 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7936 | if (IsArrayExpr != NoArrayExpr) |
| 7937 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7938 | << ERange; |
| 7939 | else { |
| 7940 | S.Diag(ELoc, |
| 7941 | AllowArraySection |
| 7942 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7943 | : diag::err_omp_expected_var_name_member_expr) |
| 7944 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7945 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7946 | return std::make_pair(nullptr, false); |
| 7947 | } |
| 7948 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7949 | } |
| 7950 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7951 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7952 | SourceLocation StartLoc, |
| 7953 | SourceLocation LParenLoc, |
| 7954 | SourceLocation EndLoc) { |
| 7955 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7956 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7957 | for (auto &RefExpr : VarList) { |
| 7958 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7959 | SourceLocation ELoc; |
| 7960 | SourceRange ERange; |
| 7961 | Expr *SimpleRefExpr = RefExpr; |
| 7962 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7963 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7964 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7965 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7966 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7967 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7968 | ValueDecl *D = Res.first; |
| 7969 | if (!D) |
| 7970 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7971 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7972 | QualType Type = D->getType(); |
| 7973 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7974 | |
| 7975 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7976 | // A variable that appears in a private clause must not have an incomplete |
| 7977 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7978 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7979 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7980 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7981 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7982 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7983 | // in a Construct] |
| 7984 | // Variables with the predetermined data-sharing attributes may not be |
| 7985 | // listed in data-sharing attributes clauses, except for the cases |
| 7986 | // listed below. For these exceptions only, listing a predetermined |
| 7987 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7988 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7989 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7990 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7991 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7992 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7993 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7994 | continue; |
| 7995 | } |
| 7996 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7997 | auto CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7998 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7999 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8000 | isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8001 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8002 | << getOpenMPClauseName(OMPC_private) << Type |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8003 | << getOpenMPDirectiveName(CurrDir); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8004 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8005 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8006 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8007 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8008 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8009 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8010 | continue; |
| 8011 | } |
| 8012 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8013 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8014 | // A list item cannot appear in both a map clause and a data-sharing |
| 8015 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8016 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8017 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8018 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8019 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 8020 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8021 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 8022 | CurrDir == OMPD_target_parallel_for_simd || |
| 8023 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8024 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8025 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8026 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8027 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8028 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8029 | ConflictKind = WhereFoundClauseKind; |
| 8030 | return true; |
| 8031 | })) { |
| 8032 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8033 | << getOpenMPClauseName(OMPC_private) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8034 | << getOpenMPClauseName(ConflictKind) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8035 | << getOpenMPDirectiveName(CurrDir); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8036 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8037 | continue; |
| 8038 | } |
| 8039 | } |
| 8040 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8041 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 8042 | // A variable of class type (or array thereof) that appears in a private |
| 8043 | // clause requires an accessible, unambiguous default constructor for the |
| 8044 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8045 | // Generate helper private variable and initialize it with the default |
| 8046 | // value. The address of the original variable is replaced by the address of |
| 8047 | // the new private variable in CodeGen. This new variable is not added to |
| 8048 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 8049 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8050 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8051 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8052 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8053 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8054 | if (VDPrivate->isInvalidDecl()) |
| 8055 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8056 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 8057 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8058 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8059 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8060 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8061 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 8062 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8063 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8064 | ? RefExpr->IgnoreParens() |
| 8065 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8066 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8067 | } |
| 8068 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8069 | if (Vars.empty()) |
| 8070 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8071 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 8072 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 8073 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 8074 | } |
| 8075 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8076 | namespace { |
| 8077 | class DiagsUninitializedSeveretyRAII { |
| 8078 | private: |
| 8079 | DiagnosticsEngine &Diags; |
| 8080 | SourceLocation SavedLoc; |
| 8081 | bool IsIgnored; |
| 8082 | |
| 8083 | public: |
| 8084 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 8085 | bool IsIgnored) |
| 8086 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 8087 | if (!IsIgnored) { |
| 8088 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 8089 | /*Map*/ diag::Severity::Ignored, Loc); |
| 8090 | } |
| 8091 | } |
| 8092 | ~DiagsUninitializedSeveretyRAII() { |
| 8093 | if (!IsIgnored) |
| 8094 | Diags.popMappings(SavedLoc); |
| 8095 | } |
| 8096 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 8097 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8098 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8099 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 8100 | SourceLocation StartLoc, |
| 8101 | SourceLocation LParenLoc, |
| 8102 | SourceLocation EndLoc) { |
| 8103 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8104 | SmallVector<Expr *, 8> PrivateCopies; |
| 8105 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8106 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8107 | bool IsImplicitClause = |
| 8108 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 8109 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 8110 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8111 | for (auto &RefExpr : VarList) { |
| 8112 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8113 | SourceLocation ELoc; |
| 8114 | SourceRange ERange; |
| 8115 | Expr *SimpleRefExpr = RefExpr; |
| 8116 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8117 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8118 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8119 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8120 | PrivateCopies.push_back(nullptr); |
| 8121 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8122 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8123 | ValueDecl *D = Res.first; |
| 8124 | if (!D) |
| 8125 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8126 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8127 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8128 | QualType Type = D->getType(); |
| 8129 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8130 | |
| 8131 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8132 | // A variable that appears in a private clause must not have an incomplete |
| 8133 | // type or a reference type. |
| 8134 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8135 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8136 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8137 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8138 | |
| 8139 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 8140 | // 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] | 8141 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8142 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8143 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8144 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8145 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8146 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8147 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8148 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8149 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8150 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8151 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 8152 | // A list item that specifies a given variable may not appear in more |
| 8153 | // than one clause on the same directive, except that a variable may be |
| 8154 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8155 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8156 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8157 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8158 | << getOpenMPClauseName(DVar.CKind) |
| 8159 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8160 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8161 | continue; |
| 8162 | } |
| 8163 | |
| 8164 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8165 | // in a Construct] |
| 8166 | // Variables with the predetermined data-sharing attributes may not be |
| 8167 | // listed in data-sharing attributes clauses, except for the cases |
| 8168 | // listed below. For these exceptions only, listing a predetermined |
| 8169 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8170 | // the variable's predetermined data-sharing attributes. |
| 8171 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8172 | // in a Construct, C/C++, p.2] |
| 8173 | // Variables with const-qualified type having no mutable member may be |
| 8174 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8175 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8176 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 8177 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8178 | << getOpenMPClauseName(DVar.CKind) |
| 8179 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8180 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8181 | continue; |
| 8182 | } |
| 8183 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8184 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8185 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 8186 | // A list item that is private within a parallel region must not appear |
| 8187 | // in a firstprivate clause on a worksharing construct if any of the |
| 8188 | // worksharing regions arising from the worksharing construct ever bind |
| 8189 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8190 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8191 | !isOpenMPParallelDirective(CurrDir) && |
| 8192 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8193 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8194 | if (DVar.CKind != OMPC_shared && |
| 8195 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8196 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8197 | Diag(ELoc, diag::err_omp_required_access) |
| 8198 | << getOpenMPClauseName(OMPC_firstprivate) |
| 8199 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8200 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8201 | continue; |
| 8202 | } |
| 8203 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8204 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 8205 | // A list item that appears in a reduction clause of a parallel construct |
| 8206 | // must not appear in a firstprivate clause on a worksharing or task |
| 8207 | // construct if any of the worksharing or task regions arising from the |
| 8208 | // worksharing or task construct ever bind to any of the parallel regions |
| 8209 | // arising from the parallel construct. |
| 8210 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 8211 | // A list item that appears in a reduction clause in worksharing |
| 8212 | // construct must not appear in a firstprivate clause in a task construct |
| 8213 | // encountered during execution of any of the worksharing regions arising |
| 8214 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8215 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8216 | DVar = DSAStack->hasInnermostDSA( |
| 8217 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8218 | [](OpenMPDirectiveKind K) -> bool { |
| 8219 | return isOpenMPParallelDirective(K) || |
| 8220 | isOpenMPWorksharingDirective(K); |
| 8221 | }, |
| 8222 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8223 | if (DVar.CKind == OMPC_reduction && |
| 8224 | (isOpenMPParallelDirective(DVar.DKind) || |
| 8225 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 8226 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 8227 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8228 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8229 | continue; |
| 8230 | } |
| 8231 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8232 | |
| 8233 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8234 | // A list item that is private within a teams region must not appear in a |
| 8235 | // firstprivate clause on a distribute construct if any of the distribute |
| 8236 | // regions arising from the distribute construct ever bind to any of the |
| 8237 | // teams regions arising from the teams construct. |
| 8238 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 8239 | // A list item that appears in a reduction clause of a teams construct |
| 8240 | // must not appear in a firstprivate clause on a distribute construct if |
| 8241 | // any of the distribute regions arising from the distribute construct |
| 8242 | // ever bind to any of the teams regions arising from the teams construct. |
| 8243 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8244 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8245 | // both. |
| 8246 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8247 | DVar = DSAStack->hasInnermostDSA( |
| 8248 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 8249 | [](OpenMPDirectiveKind K) -> bool { |
| 8250 | return isOpenMPTeamsDirective(K); |
| 8251 | }, |
| 8252 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8253 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 8254 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8255 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8256 | continue; |
| 8257 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8258 | DVar = DSAStack->hasInnermostDSA( |
| 8259 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 8260 | [](OpenMPDirectiveKind K) -> bool { |
| 8261 | return isOpenMPTeamsDirective(K); |
| 8262 | }, |
| 8263 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8264 | if (DVar.CKind == OMPC_reduction && |
| 8265 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 8266 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8267 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8268 | continue; |
| 8269 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8270 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8271 | if (DVar.CKind == OMPC_lastprivate) { |
| 8272 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8273 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 8274 | continue; |
| 8275 | } |
| 8276 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8277 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 8278 | // A list item cannot appear in both a map clause and a data-sharing |
| 8279 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 8280 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8281 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 8282 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 8283 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 8284 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 8285 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 8286 | CurrDir == OMPD_target_parallel_for_simd || |
| 8287 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8288 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 8289 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8290 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8291 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 8292 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 8293 | ConflictKind = WhereFoundClauseKind; |
| 8294 | return true; |
| 8295 | })) { |
| 8296 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8297 | << getOpenMPClauseName(OMPC_firstprivate) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 8298 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 8299 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8300 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8301 | continue; |
| 8302 | } |
| 8303 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8304 | } |
| 8305 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8306 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 8307 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 8308 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8309 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 8310 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 8311 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 8312 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8313 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8314 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8315 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8316 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8317 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 8318 | continue; |
| 8319 | } |
| 8320 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8321 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8322 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8323 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8324 | // Generate helper private variable and initialize it with the value of the |
| 8325 | // original variable. The address of the original variable is replaced by |
| 8326 | // the address of the new private variable in the CodeGen. This new variable |
| 8327 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 8328 | // original variable for proper diagnostics and variable capturing. |
| 8329 | Expr *VDInitRefExpr = nullptr; |
| 8330 | // For arrays generate initializer for single element and replace it by the |
| 8331 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8332 | if (Type->isArrayType()) { |
| 8333 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8334 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8335 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8336 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8337 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8338 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 8339 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8340 | InitializedEntity Entity = |
| 8341 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8342 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 8343 | |
| 8344 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 8345 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 8346 | if (Result.isInvalid()) |
| 8347 | VDPrivate->setInvalidDecl(); |
| 8348 | else |
| 8349 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8350 | // Remove temp variable declaration. |
| 8351 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8352 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8353 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 8354 | ".firstprivate.temp"); |
| 8355 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 8356 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 8357 | AddInitializerToDecl(VDPrivate, |
| 8358 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8359 | /*DirectInit=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8360 | } |
| 8361 | if (VDPrivate->isInvalidDecl()) { |
| 8362 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8363 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8364 | diag::note_omp_task_predetermined_firstprivate_here); |
| 8365 | } |
| 8366 | continue; |
| 8367 | } |
| 8368 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8369 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8370 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 8371 | RefExpr->getExprLoc()); |
| 8372 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8373 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8374 | if (TopDVar.CKind == OMPC_lastprivate) |
| 8375 | Ref = TopDVar.PrivateCopy; |
| 8376 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8377 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8378 | if (!IsOpenMPCapturedDecl(D)) |
| 8379 | ExprCaptures.push_back(Ref->getDecl()); |
| 8380 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 8381 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 8382 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8383 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8384 | ? RefExpr->IgnoreParens() |
| 8385 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 8386 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 8387 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8388 | } |
| 8389 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8390 | if (Vars.empty()) |
| 8391 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8392 | |
| 8393 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8394 | Vars, PrivateCopies, Inits, |
| 8395 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 8396 | } |
| 8397 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8398 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 8399 | SourceLocation StartLoc, |
| 8400 | SourceLocation LParenLoc, |
| 8401 | SourceLocation EndLoc) { |
| 8402 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8403 | SmallVector<Expr *, 8> SrcExprs; |
| 8404 | SmallVector<Expr *, 8> DstExprs; |
| 8405 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8406 | SmallVector<Decl *, 4> ExprCaptures; |
| 8407 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8408 | for (auto &RefExpr : VarList) { |
| 8409 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8410 | SourceLocation ELoc; |
| 8411 | SourceRange ERange; |
| 8412 | Expr *SimpleRefExpr = RefExpr; |
| 8413 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8414 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8415 | // It will be analyzed later. |
| 8416 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8417 | SrcExprs.push_back(nullptr); |
| 8418 | DstExprs.push_back(nullptr); |
| 8419 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8420 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8421 | ValueDecl *D = Res.first; |
| 8422 | if (!D) |
| 8423 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8424 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8425 | QualType Type = D->getType(); |
| 8426 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8427 | |
| 8428 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 8429 | // A variable that appears in a lastprivate clause must not have an |
| 8430 | // incomplete type or a reference type. |
| 8431 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8432 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8433 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8434 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8435 | |
| 8436 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8437 | // in a Construct] |
| 8438 | // Variables with the predetermined data-sharing attributes may not be |
| 8439 | // listed in data-sharing attributes clauses, except for the cases |
| 8440 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8441 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8442 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 8443 | DVar.CKind != OMPC_firstprivate && |
| 8444 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 8445 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8446 | << getOpenMPClauseName(DVar.CKind) |
| 8447 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8448 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8449 | continue; |
| 8450 | } |
| 8451 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8452 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8453 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 8454 | // A list item that is private within a parallel region, or that appears in |
| 8455 | // the reduction clause of a parallel construct, must not appear in a |
| 8456 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 8457 | // worksharing regions ever binds to any of the corresponding parallel |
| 8458 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 8459 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 8460 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8461 | !isOpenMPParallelDirective(CurrDir) && |
| 8462 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8463 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8464 | if (DVar.CKind != OMPC_shared) { |
| 8465 | Diag(ELoc, diag::err_omp_required_access) |
| 8466 | << getOpenMPClauseName(OMPC_lastprivate) |
| 8467 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8468 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8469 | continue; |
| 8470 | } |
| 8471 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8472 | |
| 8473 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8474 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8475 | // both. |
| 8476 | if (CurrDir == OMPD_distribute) { |
| 8477 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8478 | if (DVar.CKind == OMPC_firstprivate) { |
| 8479 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8480 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8481 | continue; |
| 8482 | } |
| 8483 | } |
| 8484 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8485 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8486 | // A variable of class type (or array thereof) that appears in a |
| 8487 | // lastprivate clause requires an accessible, unambiguous default |
| 8488 | // constructor for the class type, unless the list item is also specified |
| 8489 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8490 | // A variable of class type (or array thereof) that appears in a |
| 8491 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8492 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8493 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8494 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8495 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8496 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8497 | auto *PseudoSrcExpr = |
| 8498 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8499 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8500 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8501 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8502 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8503 | // For arrays generate assignment operation for single element and replace |
| 8504 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8505 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8506 | PseudoDstExpr, PseudoSrcExpr); |
| 8507 | if (AssignmentOp.isInvalid()) |
| 8508 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8509 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8510 | /*DiscardedValue=*/true); |
| 8511 | if (AssignmentOp.isInvalid()) |
| 8512 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8513 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8514 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8515 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8516 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8517 | Ref = TopDVar.PrivateCopy; |
| 8518 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8519 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8520 | if (!IsOpenMPCapturedDecl(D)) |
| 8521 | ExprCaptures.push_back(Ref->getDecl()); |
| 8522 | } |
| 8523 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8524 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8525 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8526 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8527 | if (!RefRes.isUsable()) |
| 8528 | continue; |
| 8529 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8530 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8531 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8532 | if (!PostUpdateRes.isUsable()) |
| 8533 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8534 | ExprPostUpdates.push_back( |
| 8535 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8536 | } |
| 8537 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8538 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8539 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8540 | ? RefExpr->IgnoreParens() |
| 8541 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8542 | SrcExprs.push_back(PseudoSrcExpr); |
| 8543 | DstExprs.push_back(PseudoDstExpr); |
| 8544 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8545 | } |
| 8546 | |
| 8547 | if (Vars.empty()) |
| 8548 | return nullptr; |
| 8549 | |
| 8550 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8551 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8552 | buildPreInits(Context, ExprCaptures), |
| 8553 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8554 | } |
| 8555 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8556 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8557 | SourceLocation StartLoc, |
| 8558 | SourceLocation LParenLoc, |
| 8559 | SourceLocation EndLoc) { |
| 8560 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8561 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8562 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8563 | SourceLocation ELoc; |
| 8564 | SourceRange ERange; |
| 8565 | Expr *SimpleRefExpr = RefExpr; |
| 8566 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8567 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8568 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8569 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8570 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8571 | ValueDecl *D = Res.first; |
| 8572 | if (!D) |
| 8573 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8574 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8575 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8576 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8577 | // in a Construct] |
| 8578 | // Variables with the predetermined data-sharing attributes may not be |
| 8579 | // listed in data-sharing attributes clauses, except for the cases |
| 8580 | // listed below. For these exceptions only, listing a predetermined |
| 8581 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8582 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8583 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8584 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8585 | DVar.RefExpr) { |
| 8586 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8587 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8588 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8589 | continue; |
| 8590 | } |
| 8591 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8592 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8593 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8594 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8595 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8596 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 8597 | ? RefExpr->IgnoreParens() |
| 8598 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8599 | } |
| 8600 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8601 | if (Vars.empty()) |
| 8602 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8603 | |
| 8604 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8605 | } |
| 8606 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8607 | namespace { |
| 8608 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8609 | DSAStackTy *Stack; |
| 8610 | |
| 8611 | public: |
| 8612 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8613 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8614 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8615 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8616 | return false; |
| 8617 | if (DVar.CKind != OMPC_unknown) |
| 8618 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8619 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8620 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 8621 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8622 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8623 | return true; |
| 8624 | return false; |
| 8625 | } |
| 8626 | return false; |
| 8627 | } |
| 8628 | bool VisitStmt(Stmt *S) { |
| 8629 | for (auto Child : S->children()) { |
| 8630 | if (Child && Visit(Child)) |
| 8631 | return true; |
| 8632 | } |
| 8633 | return false; |
| 8634 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8635 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8636 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8637 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8638 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8639 | namespace { |
| 8640 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8641 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8642 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8643 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8644 | ValueDecl *Field; |
| 8645 | DeclRefExpr *CapturedExpr; |
| 8646 | |
| 8647 | public: |
| 8648 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8649 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8650 | |
| 8651 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8652 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8653 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8654 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8655 | return CapturedExpr; |
| 8656 | } |
| 8657 | return BaseTransform::TransformMemberExpr(E); |
| 8658 | } |
| 8659 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8660 | }; |
| 8661 | } // namespace |
| 8662 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8663 | template <typename T> |
| 8664 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8665 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8666 | for (auto &Set : Lookups) { |
| 8667 | for (auto *D : Set) { |
| 8668 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8669 | return Res; |
| 8670 | } |
| 8671 | } |
| 8672 | return T(); |
| 8673 | } |
| 8674 | |
| 8675 | static ExprResult |
| 8676 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8677 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8678 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8679 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8680 | if (ReductionIdScopeSpec.isInvalid()) |
| 8681 | return ExprError(); |
| 8682 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8683 | if (S) { |
| 8684 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8685 | Lookup.suppressDiagnostics(); |
| 8686 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8687 | auto *D = Lookup.getRepresentativeDecl(); |
| 8688 | do { |
| 8689 | S = S->getParent(); |
| 8690 | } while (S && !S->isDeclScope(D)); |
| 8691 | if (S) |
| 8692 | S = S->getParent(); |
| 8693 | Lookups.push_back(UnresolvedSet<8>()); |
| 8694 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8695 | Lookup.clear(); |
| 8696 | } |
| 8697 | } else if (auto *ULE = |
| 8698 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8699 | Lookups.push_back(UnresolvedSet<8>()); |
| 8700 | Decl *PrevD = nullptr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8701 | for (auto *D : ULE->decls()) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8702 | if (D == PrevD) |
| 8703 | Lookups.push_back(UnresolvedSet<8>()); |
| 8704 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8705 | Lookups.back().addDecl(DRD); |
| 8706 | PrevD = D; |
| 8707 | } |
| 8708 | } |
| 8709 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8710 | Ty->containsUnexpandedParameterPack() || |
| 8711 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8712 | return !D->isInvalidDecl() && |
| 8713 | (D->getType()->isDependentType() || |
| 8714 | D->getType()->isInstantiationDependentType() || |
| 8715 | D->getType()->containsUnexpandedParameterPack()); |
| 8716 | })) { |
| 8717 | UnresolvedSet<8> ResSet; |
| 8718 | for (auto &Set : Lookups) { |
| 8719 | ResSet.append(Set.begin(), Set.end()); |
| 8720 | // The last item marks the end of all declarations at the specified scope. |
| 8721 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8722 | } |
| 8723 | return UnresolvedLookupExpr::Create( |
| 8724 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8725 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8726 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8727 | } |
| 8728 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8729 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8730 | if (!D->isInvalidDecl() && |
| 8731 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8732 | return D; |
| 8733 | return nullptr; |
| 8734 | })) |
| 8735 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8736 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8737 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8738 | if (!D->isInvalidDecl() && |
| 8739 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8740 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8741 | return D; |
| 8742 | return nullptr; |
| 8743 | })) { |
| 8744 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8745 | /*DetectVirtual=*/false); |
| 8746 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8747 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8748 | VD->getType().getUnqualifiedType()))) { |
| 8749 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8750 | /*DiagID=*/0) != |
| 8751 | Sema::AR_inaccessible) { |
| 8752 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8753 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8754 | } |
| 8755 | } |
| 8756 | } |
| 8757 | } |
| 8758 | if (ReductionIdScopeSpec.isSet()) { |
| 8759 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8760 | return ExprError(); |
| 8761 | } |
| 8762 | return ExprEmpty(); |
| 8763 | } |
| 8764 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8765 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 8766 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 8767 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8768 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 8769 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8770 | auto DN = ReductionId.getName(); |
| 8771 | auto OOK = DN.getCXXOverloadedOperator(); |
| 8772 | BinaryOperatorKind BOK = BO_Comma; |
| 8773 | |
| 8774 | // OpenMP [2.14.3.6, reduction clause] |
| 8775 | // C |
| 8776 | // reduction-identifier is either an identifier or one of the following |
| 8777 | // operators: +, -, *, &, |, ^, && and || |
| 8778 | // C++ |
| 8779 | // reduction-identifier is either an id-expression or one of the following |
| 8780 | // operators: +, -, *, &, |, ^, && and || |
| 8781 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8782 | switch (OOK) { |
| 8783 | case OO_Plus: |
| 8784 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8785 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8786 | break; |
| 8787 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8788 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8789 | break; |
| 8790 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8791 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8792 | break; |
| 8793 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8794 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8795 | break; |
| 8796 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8797 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8798 | break; |
| 8799 | case OO_AmpAmp: |
| 8800 | BOK = BO_LAnd; |
| 8801 | break; |
| 8802 | case OO_PipePipe: |
| 8803 | BOK = BO_LOr; |
| 8804 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8805 | case OO_New: |
| 8806 | case OO_Delete: |
| 8807 | case OO_Array_New: |
| 8808 | case OO_Array_Delete: |
| 8809 | case OO_Slash: |
| 8810 | case OO_Percent: |
| 8811 | case OO_Tilde: |
| 8812 | case OO_Exclaim: |
| 8813 | case OO_Equal: |
| 8814 | case OO_Less: |
| 8815 | case OO_Greater: |
| 8816 | case OO_LessEqual: |
| 8817 | case OO_GreaterEqual: |
| 8818 | case OO_PlusEqual: |
| 8819 | case OO_MinusEqual: |
| 8820 | case OO_StarEqual: |
| 8821 | case OO_SlashEqual: |
| 8822 | case OO_PercentEqual: |
| 8823 | case OO_CaretEqual: |
| 8824 | case OO_AmpEqual: |
| 8825 | case OO_PipeEqual: |
| 8826 | case OO_LessLess: |
| 8827 | case OO_GreaterGreater: |
| 8828 | case OO_LessLessEqual: |
| 8829 | case OO_GreaterGreaterEqual: |
| 8830 | case OO_EqualEqual: |
| 8831 | case OO_ExclaimEqual: |
| 8832 | case OO_PlusPlus: |
| 8833 | case OO_MinusMinus: |
| 8834 | case OO_Comma: |
| 8835 | case OO_ArrowStar: |
| 8836 | case OO_Arrow: |
| 8837 | case OO_Call: |
| 8838 | case OO_Subscript: |
| 8839 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8840 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8841 | case NUM_OVERLOADED_OPERATORS: |
| 8842 | llvm_unreachable("Unexpected reduction identifier"); |
| 8843 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8844 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8845 | if (II->isStr("max")) |
| 8846 | BOK = BO_GT; |
| 8847 | else if (II->isStr("min")) |
| 8848 | BOK = BO_LT; |
| 8849 | } |
| 8850 | break; |
| 8851 | } |
| 8852 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8853 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8854 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8855 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8856 | |
| 8857 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8858 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8859 | SmallVector<Expr *, 8> LHSs; |
| 8860 | SmallVector<Expr *, 8> RHSs; |
| 8861 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8862 | SmallVector<Decl *, 4> ExprCaptures; |
| 8863 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8864 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8865 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8866 | for (auto RefExpr : VarList) { |
| 8867 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8868 | // OpenMP [2.1, C/C++] |
| 8869 | // A list item is a variable or array section, subject to the restrictions |
| 8870 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8871 | // describing clauses and directives for which a list appears. |
| 8872 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8873 | // A variable that is part of another variable (as an array or |
| 8874 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8875 | if (!FirstIter && IR != ER) |
| 8876 | ++IR; |
| 8877 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8878 | SourceLocation ELoc; |
| 8879 | SourceRange ERange; |
| 8880 | Expr *SimpleRefExpr = RefExpr; |
| 8881 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8882 | /*AllowArraySection=*/true); |
| 8883 | if (Res.second) { |
| 8884 | // It will be analyzed later. |
| 8885 | Vars.push_back(RefExpr); |
| 8886 | Privates.push_back(nullptr); |
| 8887 | LHSs.push_back(nullptr); |
| 8888 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8889 | // Try to find 'declare reduction' corresponding construct before using |
| 8890 | // builtin/overloaded operators. |
| 8891 | QualType Type = Context.DependentTy; |
| 8892 | CXXCastPath BasePath; |
| 8893 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8894 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8895 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8896 | if (CurContext->isDependentContext() && |
| 8897 | (DeclareReductionRef.isUnset() || |
| 8898 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8899 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8900 | else |
| 8901 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8902 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8903 | ValueDecl *D = Res.first; |
| 8904 | if (!D) |
| 8905 | continue; |
| 8906 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8907 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8908 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8909 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8910 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8911 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8912 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8913 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8914 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8915 | Type = ATy->getElementType(); |
| 8916 | else |
| 8917 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8918 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8919 | } else |
| 8920 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8921 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8922 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8923 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8924 | // A variable that appears in a private clause must not have an incomplete |
| 8925 | // type or a reference type. |
| 8926 | if (RequireCompleteType(ELoc, Type, |
| 8927 | diag::err_omp_reduction_incomplete_type)) |
| 8928 | continue; |
| 8929 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8930 | // A list item that appears in a reduction clause must not be |
| 8931 | // const-qualified. |
| 8932 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8933 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8934 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8935 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8936 | bool IsDecl = !VD || |
| 8937 | VD->isThisDeclarationADefinition(Context) == |
| 8938 | VarDecl::DeclarationOnly; |
| 8939 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8940 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8941 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8942 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8943 | continue; |
| 8944 | } |
| 8945 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8946 | // If a list-item is a reference type then it must bind to the same object |
| 8947 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8948 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8949 | VarDecl *VDDef = VD->getDefinition(); |
David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame] | 8950 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8951 | DSARefChecker Check(DSAStack); |
| 8952 | if (Check.Visit(VDDef->getInit())) { |
| 8953 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8954 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8955 | continue; |
| 8956 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8957 | } |
| 8958 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8959 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8960 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8961 | // in a Construct] |
| 8962 | // Variables with the predetermined data-sharing attributes may not be |
| 8963 | // listed in data-sharing attributes clauses, except for the cases |
| 8964 | // listed below. For these exceptions only, listing a predetermined |
| 8965 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8966 | // the variable's predetermined data-sharing attributes. |
| 8967 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8968 | // Any number of reduction clauses can be specified on the directive, |
| 8969 | // but a list item can appear only once in the reduction clauses for that |
| 8970 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8971 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8972 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8973 | if (DVar.CKind == OMPC_reduction) { |
| 8974 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8975 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8976 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8977 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8978 | } else if (DVar.CKind != OMPC_unknown) { |
| 8979 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8980 | << getOpenMPClauseName(DVar.CKind) |
| 8981 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8982 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8983 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8984 | } |
| 8985 | |
| 8986 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8987 | // A list item that appears in a reduction clause of a worksharing |
| 8988 | // construct must be shared in the parallel regions to which any of the |
| 8989 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8990 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8991 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8992 | !isOpenMPParallelDirective(CurrDir) && |
| 8993 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8994 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8995 | if (DVar.CKind != OMPC_shared) { |
| 8996 | Diag(ELoc, diag::err_omp_required_access) |
| 8997 | << getOpenMPClauseName(OMPC_reduction) |
| 8998 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8999 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9000 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 9001 | } |
| 9002 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9003 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9004 | // Try to find 'declare reduction' corresponding construct before using |
| 9005 | // builtin/overloaded operators. |
| 9006 | CXXCastPath BasePath; |
| 9007 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 9008 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 9009 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 9010 | if (DeclareReductionRef.isInvalid()) |
| 9011 | continue; |
| 9012 | if (CurContext->isDependentContext() && |
| 9013 | (DeclareReductionRef.isUnset() || |
| 9014 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 9015 | Vars.push_back(RefExpr); |
| 9016 | Privates.push_back(nullptr); |
| 9017 | LHSs.push_back(nullptr); |
| 9018 | RHSs.push_back(nullptr); |
| 9019 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 9020 | continue; |
| 9021 | } |
| 9022 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 9023 | // Not allowed reduction identifier is found. |
| 9024 | Diag(ReductionId.getLocStart(), |
| 9025 | diag::err_omp_unknown_reduction_identifier) |
| 9026 | << Type << ReductionIdRange; |
| 9027 | continue; |
| 9028 | } |
| 9029 | |
| 9030 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 9031 | // The type of a list item that appears in a reduction clause must be valid |
| 9032 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 9033 | // of the list item must be an allowed arithmetic data type: char, int, |
| 9034 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 9035 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 9036 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 9037 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 9038 | if (DeclareReductionRef.isUnset()) { |
| 9039 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 9040 | !(Type->isScalarType() || |
| 9041 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 9042 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 9043 | << getLangOpts().CPlusPlus; |
| 9044 | if (!ASE && !OASE) { |
| 9045 | bool IsDecl = !VD || |
| 9046 | VD->isThisDeclarationADefinition(Context) == |
| 9047 | VarDecl::DeclarationOnly; |
| 9048 | Diag(D->getLocation(), |
| 9049 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9050 | << D; |
| 9051 | } |
| 9052 | continue; |
| 9053 | } |
| 9054 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 9055 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 9056 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 9057 | if (!ASE && !OASE) { |
| 9058 | bool IsDecl = !VD || |
| 9059 | VD->isThisDeclarationADefinition(Context) == |
| 9060 | VarDecl::DeclarationOnly; |
| 9061 | Diag(D->getLocation(), |
| 9062 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9063 | << D; |
| 9064 | } |
| 9065 | continue; |
| 9066 | } |
| 9067 | } |
| 9068 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9069 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9070 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9071 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9072 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9073 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9074 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 9075 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9076 | (!ASE && |
| 9077 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9078 | // For arrays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9079 | // Create pseudo array type for private copy. The size for this array will |
| 9080 | // be generated during codegen. |
| 9081 | // For array subscripts or single variables Private Ty is the same as Type |
| 9082 | // (type of the variable or single array element). |
| 9083 | PrivateTy = Context.getVariableArrayType( |
| 9084 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 9085 | Context.getSizeType(), VK_RValue), |
| 9086 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9087 | } else if (!ASE && !OASE && |
| 9088 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 9089 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9090 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9091 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 9092 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9093 | // Add initializer for private variable. |
| 9094 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9095 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 9096 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 9097 | if (DeclareReductionRef.isUsable()) { |
| 9098 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 9099 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 9100 | if (DRD->getInitializer()) { |
| 9101 | Init = DRDRef; |
| 9102 | RHSVD->setInit(DRDRef); |
| 9103 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9104 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9105 | } else { |
| 9106 | switch (BOK) { |
| 9107 | case BO_Add: |
| 9108 | case BO_Xor: |
| 9109 | case BO_Or: |
| 9110 | case BO_LOr: |
| 9111 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 9112 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 9113 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 9114 | break; |
| 9115 | case BO_Mul: |
| 9116 | case BO_LAnd: |
| 9117 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 9118 | // '*' and '&&' reduction ops - initializer is '1'. |
| 9119 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9120 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9121 | break; |
| 9122 | case BO_And: { |
| 9123 | // '&' reduction op - initializer is '~0'. |
| 9124 | QualType OrigType = Type; |
| 9125 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 9126 | Type = ComplexTy->getElementType(); |
| 9127 | if (Type->isRealFloatingType()) { |
| 9128 | llvm::APFloat InitValue = |
| 9129 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 9130 | /*isIEEE=*/true); |
| 9131 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9132 | Type, ELoc); |
| 9133 | } else if (Type->isScalarType()) { |
| 9134 | auto Size = Context.getTypeSize(Type); |
| 9135 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 9136 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 9137 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9138 | } |
| 9139 | if (Init && OrigType->isAnyComplexType()) { |
| 9140 | // Init = 0xFFFF + 0xFFFFi; |
| 9141 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 9142 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 9143 | } |
| 9144 | Type = OrigType; |
| 9145 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9146 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9147 | case BO_LT: |
| 9148 | case BO_GT: { |
| 9149 | // 'min' reduction op - initializer is 'Largest representable number in |
| 9150 | // the reduction list item type'. |
| 9151 | // 'max' reduction op - initializer is 'Least representable number in |
| 9152 | // the reduction list item type'. |
| 9153 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 9154 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 9155 | auto Size = Context.getTypeSize(Type); |
| 9156 | QualType IntTy = |
| 9157 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 9158 | llvm::APInt InitValue = |
| 9159 | (BOK != BO_LT) |
| 9160 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 9161 | : llvm::APInt::getMinValue(Size) |
| 9162 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 9163 | : llvm::APInt::getMaxValue(Size); |
| 9164 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 9165 | if (Type->isPointerType()) { |
| 9166 | // Cast to pointer type. |
| 9167 | auto CastExpr = BuildCStyleCastExpr( |
| 9168 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 9169 | SourceLocation(), Init); |
| 9170 | if (CastExpr.isInvalid()) |
| 9171 | continue; |
| 9172 | Init = CastExpr.get(); |
| 9173 | } |
| 9174 | } else if (Type->isRealFloatingType()) { |
| 9175 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 9176 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 9177 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 9178 | Type, ELoc); |
| 9179 | } |
| 9180 | break; |
| 9181 | } |
| 9182 | case BO_PtrMemD: |
| 9183 | case BO_PtrMemI: |
| 9184 | case BO_MulAssign: |
| 9185 | case BO_Div: |
| 9186 | case BO_Rem: |
| 9187 | case BO_Sub: |
| 9188 | case BO_Shl: |
| 9189 | case BO_Shr: |
| 9190 | case BO_LE: |
| 9191 | case BO_GE: |
| 9192 | case BO_EQ: |
| 9193 | case BO_NE: |
| 9194 | case BO_AndAssign: |
| 9195 | case BO_XorAssign: |
| 9196 | case BO_OrAssign: |
| 9197 | case BO_Assign: |
| 9198 | case BO_AddAssign: |
| 9199 | case BO_SubAssign: |
| 9200 | case BO_DivAssign: |
| 9201 | case BO_RemAssign: |
| 9202 | case BO_ShlAssign: |
| 9203 | case BO_ShrAssign: |
| 9204 | case BO_Comma: |
| 9205 | llvm_unreachable("Unexpected reduction operation"); |
| 9206 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9207 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9208 | if (Init && DeclareReductionRef.isUnset()) { |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9209 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9210 | } else if (!Init) |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9211 | ActOnUninitializedDecl(RHSVD); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9212 | if (RHSVD->isInvalidDecl()) |
| 9213 | continue; |
| 9214 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9215 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 9216 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9217 | bool IsDecl = |
| 9218 | !VD || |
| 9219 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9220 | Diag(D->getLocation(), |
| 9221 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9222 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9223 | continue; |
| 9224 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9225 | // Store initializer for single element in private copy. Will be used during |
| 9226 | // codegen. |
| 9227 | PrivateVD->setInit(RHSVD->getInit()); |
| 9228 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9229 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9230 | ExprResult ReductionOp; |
| 9231 | if (DeclareReductionRef.isUsable()) { |
| 9232 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 9233 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 9234 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 9235 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 9236 | if (!BasePath.empty()) { |
| 9237 | LHS = DefaultLvalueConversion(LHS.get()); |
| 9238 | RHS = DefaultLvalueConversion(RHS.get()); |
| 9239 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9240 | CK_UncheckedDerivedToBase, LHS.get(), |
| 9241 | &BasePath, LHS.get()->getValueKind()); |
| 9242 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 9243 | CK_UncheckedDerivedToBase, RHS.get(), |
| 9244 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9245 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 9246 | FunctionProtoType::ExtProtoInfo EPI; |
| 9247 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 9248 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 9249 | auto *OVE = new (Context) OpaqueValueExpr( |
| 9250 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 9251 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 9252 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 9253 | ReductionOp = new (Context) |
| 9254 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 9255 | } else { |
| 9256 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 9257 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 9258 | if (ReductionOp.isUsable()) { |
| 9259 | if (BOK != BO_LT && BOK != BO_GT) { |
| 9260 | ReductionOp = |
| 9261 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9262 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 9263 | } else { |
| 9264 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 9265 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 9266 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 9267 | ReductionOp = |
| 9268 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 9269 | BO_Assign, LHSDRE, ConditionalOp); |
| 9270 | } |
| 9271 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 9272 | } |
| 9273 | if (ReductionOp.isInvalid()) |
| 9274 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9275 | } |
| 9276 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9277 | DeclRefExpr *Ref = nullptr; |
| 9278 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9279 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9280 | if (ASE || OASE) { |
| 9281 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 9282 | VarsExpr = |
| 9283 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 9284 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9285 | } else { |
| 9286 | VarsExpr = Ref = |
| 9287 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9288 | } |
| 9289 | if (!IsOpenMPCapturedDecl(D)) { |
| 9290 | ExprCaptures.push_back(Ref->getDecl()); |
| 9291 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9292 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9293 | if (!RefRes.isUsable()) |
| 9294 | continue; |
| 9295 | ExprResult PostUpdateRes = |
| 9296 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9297 | SimpleRefExpr, RefRes.get()); |
| 9298 | if (!PostUpdateRes.isUsable()) |
| 9299 | continue; |
| 9300 | ExprPostUpdates.push_back( |
| 9301 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9302 | } |
| 9303 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 9304 | } |
| 9305 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 9306 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9307 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 9308 | LHSs.push_back(LHSDRE); |
| 9309 | RHSs.push_back(RHSDRE); |
| 9310 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9311 | } |
| 9312 | |
| 9313 | if (Vars.empty()) |
| 9314 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 9315 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9316 | return OMPReductionClause::Create( |
| 9317 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 9318 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9319 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 9320 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 9321 | } |
| 9322 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9323 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 9324 | SourceLocation LinLoc) { |
| 9325 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 9326 | LinKind == OMPC_LINEAR_unknown) { |
| 9327 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 9328 | return true; |
| 9329 | } |
| 9330 | return false; |
| 9331 | } |
| 9332 | |
| 9333 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 9334 | OpenMPLinearClauseKind LinKind, |
| 9335 | QualType Type) { |
| 9336 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 9337 | // A variable must not have an incomplete type or a reference type. |
| 9338 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 9339 | return true; |
| 9340 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 9341 | !Type->isReferenceType()) { |
| 9342 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 9343 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 9344 | return true; |
| 9345 | } |
| 9346 | Type = Type.getNonReferenceType(); |
| 9347 | |
| 9348 | // A list item must not be const-qualified. |
| 9349 | if (Type.isConstant(Context)) { |
| 9350 | Diag(ELoc, diag::err_omp_const_variable) |
| 9351 | << getOpenMPClauseName(OMPC_linear); |
| 9352 | if (D) { |
| 9353 | bool IsDecl = |
| 9354 | !VD || |
| 9355 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9356 | Diag(D->getLocation(), |
| 9357 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9358 | << D; |
| 9359 | } |
| 9360 | return true; |
| 9361 | } |
| 9362 | |
| 9363 | // A list item must be of integral or pointer type. |
| 9364 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 9365 | const auto *Ty = Type.getTypePtrOrNull(); |
| 9366 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 9367 | !Ty->isPointerType())) { |
| 9368 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 9369 | if (D) { |
| 9370 | bool IsDecl = |
| 9371 | !VD || |
| 9372 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 9373 | Diag(D->getLocation(), |
| 9374 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 9375 | << D; |
| 9376 | } |
| 9377 | return true; |
| 9378 | } |
| 9379 | return false; |
| 9380 | } |
| 9381 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9382 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 9383 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 9384 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 9385 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9386 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9387 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9388 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9389 | SmallVector<Decl *, 4> ExprCaptures; |
| 9390 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9391 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9392 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9393 | for (auto &RefExpr : VarList) { |
| 9394 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9395 | SourceLocation ELoc; |
| 9396 | SourceRange ERange; |
| 9397 | Expr *SimpleRefExpr = RefExpr; |
| 9398 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9399 | /*AllowArraySection=*/false); |
| 9400 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9401 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9402 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9403 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9404 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9405 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9406 | ValueDecl *D = Res.first; |
| 9407 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9408 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9409 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9410 | QualType Type = D->getType(); |
| 9411 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9412 | |
| 9413 | // OpenMP [2.14.3.7, linear clause] |
| 9414 | // A list-item cannot appear in more than one linear clause. |
| 9415 | // A list-item that appears in a linear clause cannot appear in any |
| 9416 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9417 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9418 | if (DVar.RefExpr) { |
| 9419 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 9420 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9421 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9422 | continue; |
| 9423 | } |
| 9424 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9425 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9426 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 9427 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9428 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9429 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9430 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 9431 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9432 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9433 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9434 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9435 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9436 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9437 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 9438 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 9439 | if (!IsOpenMPCapturedDecl(D)) { |
| 9440 | ExprCaptures.push_back(Ref->getDecl()); |
| 9441 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 9442 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 9443 | if (!RefRes.isUsable()) |
| 9444 | continue; |
| 9445 | ExprResult PostUpdateRes = |
| 9446 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 9447 | SimpleRefExpr, RefRes.get()); |
| 9448 | if (!PostUpdateRes.isUsable()) |
| 9449 | continue; |
| 9450 | ExprPostUpdates.push_back( |
| 9451 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 9452 | } |
| 9453 | } |
| 9454 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9455 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9456 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9457 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9458 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9459 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 9460 | /*DirectInit=*/false); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 9461 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 9462 | |
| 9463 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 9464 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 9465 | ? RefExpr->IgnoreParens() |
| 9466 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9467 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9468 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9469 | } |
| 9470 | |
| 9471 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9472 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9473 | |
| 9474 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9475 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9476 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9477 | !Step->isInstantiationDependent() && |
| 9478 | !Step->containsUnexpandedParameterPack()) { |
| 9479 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9480 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9481 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9482 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9483 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9484 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9485 | // Build var to save the step value. |
| 9486 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9487 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9488 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9489 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9490 | ExprResult CalcStep = |
| 9491 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9492 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9493 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9494 | // Warn about zero linear step (it would be probably better specified as |
| 9495 | // making corresponding variables 'const'). |
| 9496 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9497 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9498 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9499 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9500 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9501 | if (!IsConstant && CalcStep.isUsable()) { |
| 9502 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9503 | // (This is not used if the number of iterations may be kfold-ed). |
| 9504 | CalcStepExpr = CalcStep.get(); |
| 9505 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9506 | } |
| 9507 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9508 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9509 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9510 | StepExpr, CalcStepExpr, |
| 9511 | buildPreInits(Context, ExprCaptures), |
| 9512 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9513 | } |
| 9514 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9515 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9516 | Expr *NumIterations, Sema &SemaRef, |
| 9517 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9518 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9519 | SmallVector<Expr *, 8> Updates; |
| 9520 | SmallVector<Expr *, 8> Finals; |
| 9521 | Expr *Step = Clause.getStep(); |
| 9522 | Expr *CalcStep = Clause.getCalcStep(); |
| 9523 | // OpenMP [2.14.3.7, linear clause] |
| 9524 | // If linear-step is not specified it is assumed to be 1. |
| 9525 | if (Step == nullptr) |
| 9526 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9527 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9528 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9529 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9530 | bool HasErrors = false; |
| 9531 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9532 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9533 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9534 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9535 | SourceLocation ELoc; |
| 9536 | SourceRange ERange; |
| 9537 | Expr *SimpleRefExpr = RefExpr; |
| 9538 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9539 | /*AllowArraySection=*/false); |
| 9540 | ValueDecl *D = Res.first; |
| 9541 | if (Res.second || !D) { |
| 9542 | Updates.push_back(nullptr); |
| 9543 | Finals.push_back(nullptr); |
| 9544 | HasErrors = true; |
| 9545 | continue; |
| 9546 | } |
| 9547 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9548 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9549 | ->getMemberDecl(); |
| 9550 | } |
| 9551 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9552 | Expr *InitExpr = *CurInit; |
| 9553 | |
| 9554 | // Build privatized reference to the current linear var. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9555 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9556 | Expr *CapturedRef; |
| 9557 | if (LinKind == OMPC_LINEAR_uval) |
| 9558 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9559 | else |
| 9560 | CapturedRef = |
| 9561 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9562 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9563 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9564 | |
| 9565 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9566 | ExprResult Update; |
| 9567 | if (!Info.first) { |
| 9568 | Update = |
| 9569 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9570 | InitExpr, IV, Step, /* Subtract */ false); |
| 9571 | } else |
| 9572 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9573 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9574 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9575 | |
| 9576 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9577 | ExprResult Final; |
| 9578 | if (!Info.first) { |
| 9579 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9580 | InitExpr, NumIterations, Step, |
| 9581 | /* Subtract */ false); |
| 9582 | } else |
| 9583 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9584 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9585 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9586 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9587 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9588 | Updates.push_back(nullptr); |
| 9589 | Finals.push_back(nullptr); |
| 9590 | HasErrors = true; |
| 9591 | } else { |
| 9592 | Updates.push_back(Update.get()); |
| 9593 | Finals.push_back(Final.get()); |
| 9594 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9595 | ++CurInit; |
| 9596 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9597 | } |
| 9598 | Clause.setUpdates(Updates); |
| 9599 | Clause.setFinals(Finals); |
| 9600 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9601 | } |
| 9602 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9603 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9604 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9605 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9606 | |
| 9607 | SmallVector<Expr *, 8> Vars; |
| 9608 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9609 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9610 | SourceLocation ELoc; |
| 9611 | SourceRange ERange; |
| 9612 | Expr *SimpleRefExpr = RefExpr; |
| 9613 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9614 | /*AllowArraySection=*/false); |
| 9615 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9616 | // It will be analyzed later. |
| 9617 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9618 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9619 | ValueDecl *D = Res.first; |
| 9620 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9621 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9622 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9623 | QualType QType = D->getType(); |
| 9624 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9625 | |
| 9626 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9627 | // The type of list items appearing in the aligned clause must be |
| 9628 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9629 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9630 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9631 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9632 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9633 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9634 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9635 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9636 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9637 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9638 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9639 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9640 | continue; |
| 9641 | } |
| 9642 | |
| 9643 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9644 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9645 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9646 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9647 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9648 | << getOpenMPClauseName(OMPC_aligned); |
| 9649 | continue; |
| 9650 | } |
| 9651 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9652 | DeclRefExpr *Ref = nullptr; |
| 9653 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9654 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9655 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9656 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9657 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9658 | } |
| 9659 | |
| 9660 | // OpenMP [2.8.1, simd construct, Description] |
| 9661 | // The parameter of the aligned clause, alignment, must be a constant |
| 9662 | // positive integer expression. |
| 9663 | // If no optional parameter is specified, implementation-defined default |
| 9664 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9665 | if (Alignment != nullptr) { |
| 9666 | ExprResult AlignResult = |
| 9667 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9668 | if (AlignResult.isInvalid()) |
| 9669 | return nullptr; |
| 9670 | Alignment = AlignResult.get(); |
| 9671 | } |
| 9672 | if (Vars.empty()) |
| 9673 | return nullptr; |
| 9674 | |
| 9675 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9676 | EndLoc, Vars, Alignment); |
| 9677 | } |
| 9678 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9679 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9680 | SourceLocation StartLoc, |
| 9681 | SourceLocation LParenLoc, |
| 9682 | SourceLocation EndLoc) { |
| 9683 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9684 | SmallVector<Expr *, 8> SrcExprs; |
| 9685 | SmallVector<Expr *, 8> DstExprs; |
| 9686 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9687 | for (auto &RefExpr : VarList) { |
| 9688 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 9689 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9690 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9691 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9692 | SrcExprs.push_back(nullptr); |
| 9693 | DstExprs.push_back(nullptr); |
| 9694 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9695 | continue; |
| 9696 | } |
| 9697 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9698 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9699 | // OpenMP [2.1, C/C++] |
| 9700 | // A list item is a variable name. |
| 9701 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 9702 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9703 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9704 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9705 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 9706 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9707 | continue; |
| 9708 | } |
| 9709 | |
| 9710 | Decl *D = DE->getDecl(); |
| 9711 | VarDecl *VD = cast<VarDecl>(D); |
| 9712 | |
| 9713 | QualType Type = VD->getType(); |
| 9714 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 9715 | // It will be analyzed later. |
| 9716 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9717 | SrcExprs.push_back(nullptr); |
| 9718 | DstExprs.push_back(nullptr); |
| 9719 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9720 | continue; |
| 9721 | } |
| 9722 | |
| 9723 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 9724 | // A list item that appears in a copyin clause must be threadprivate. |
| 9725 | if (!DSAStack->isThreadPrivate(VD)) { |
| 9726 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9727 | << getOpenMPClauseName(OMPC_copyin) |
| 9728 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9729 | continue; |
| 9730 | } |
| 9731 | |
| 9732 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9733 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9734 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9735 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9736 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9737 | auto *SrcVD = |
| 9738 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 9739 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9740 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9741 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 9742 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9743 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 9744 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9745 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9746 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9747 | // For arrays generate assignment operation for single element and replace |
| 9748 | // it by the original array element in CodeGen. |
| 9749 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 9750 | PseudoDstExpr, PseudoSrcExpr); |
| 9751 | if (AssignmentOp.isInvalid()) |
| 9752 | continue; |
| 9753 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 9754 | /*DiscardedValue=*/true); |
| 9755 | if (AssignmentOp.isInvalid()) |
| 9756 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9757 | |
| 9758 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 9759 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9760 | SrcExprs.push_back(PseudoSrcExpr); |
| 9761 | DstExprs.push_back(PseudoDstExpr); |
| 9762 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9763 | } |
| 9764 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9765 | if (Vars.empty()) |
| 9766 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9767 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9768 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9769 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9770 | } |
| 9771 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9772 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 9773 | SourceLocation StartLoc, |
| 9774 | SourceLocation LParenLoc, |
| 9775 | SourceLocation EndLoc) { |
| 9776 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9777 | SmallVector<Expr *, 8> SrcExprs; |
| 9778 | SmallVector<Expr *, 8> DstExprs; |
| 9779 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9780 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9781 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9782 | SourceLocation ELoc; |
| 9783 | SourceRange ERange; |
| 9784 | Expr *SimpleRefExpr = RefExpr; |
| 9785 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9786 | /*AllowArraySection=*/false); |
| 9787 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9788 | // It will be analyzed later. |
| 9789 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9790 | SrcExprs.push_back(nullptr); |
| 9791 | DstExprs.push_back(nullptr); |
| 9792 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9793 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9794 | ValueDecl *D = Res.first; |
| 9795 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9796 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9797 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9798 | QualType Type = D->getType(); |
| 9799 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9800 | |
| 9801 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 9802 | // A list item that appears in a copyprivate clause may not appear in a |
| 9803 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9804 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 9805 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9806 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 9807 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9808 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9809 | << getOpenMPClauseName(DVar.CKind) |
| 9810 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9811 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9812 | continue; |
| 9813 | } |
| 9814 | |
| 9815 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 9816 | // All list items that appear in a copyprivate clause must be either |
| 9817 | // threadprivate or private in the enclosing context. |
| 9818 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9819 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9820 | if (DVar.CKind == OMPC_shared) { |
| 9821 | Diag(ELoc, diag::err_omp_required_access) |
| 9822 | << getOpenMPClauseName(OMPC_copyprivate) |
| 9823 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9824 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9825 | continue; |
| 9826 | } |
| 9827 | } |
| 9828 | } |
| 9829 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9830 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9831 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9832 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9833 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9834 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9835 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9836 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9837 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9838 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9839 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9840 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9841 | continue; |
| 9842 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9843 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9844 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9845 | // A variable of class type (or array thereof) that appears in a |
| 9846 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9847 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9848 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9849 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9850 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9851 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9852 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9853 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9854 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9855 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9856 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9857 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9858 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9859 | PseudoDstExpr, PseudoSrcExpr); |
| 9860 | if (AssignmentOp.isInvalid()) |
| 9861 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9862 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9863 | /*DiscardedValue=*/true); |
| 9864 | if (AssignmentOp.isInvalid()) |
| 9865 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9866 | |
| 9867 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9868 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9869 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9870 | Vars.push_back( |
| 9871 | VD ? RefExpr->IgnoreParens() |
| 9872 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9873 | SrcExprs.push_back(PseudoSrcExpr); |
| 9874 | DstExprs.push_back(PseudoDstExpr); |
| 9875 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9876 | } |
| 9877 | |
| 9878 | if (Vars.empty()) |
| 9879 | return nullptr; |
| 9880 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9881 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9882 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9883 | } |
| 9884 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9885 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9886 | SourceLocation StartLoc, |
| 9887 | SourceLocation LParenLoc, |
| 9888 | SourceLocation EndLoc) { |
| 9889 | if (VarList.empty()) |
| 9890 | return nullptr; |
| 9891 | |
| 9892 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9893 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9894 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9895 | OMPClause * |
| 9896 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9897 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9898 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9899 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9900 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9901 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9902 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9903 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9904 | return nullptr; |
| 9905 | } |
| 9906 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9907 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9908 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9909 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9910 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9911 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9912 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9913 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9914 | return nullptr; |
| 9915 | } |
| 9916 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9917 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9918 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9919 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9920 | if (DepKind == OMPC_DEPEND_sink) { |
| 9921 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9922 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9923 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9924 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9925 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9926 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9927 | DSAStack->getParentOrderedRegionParam()) { |
| 9928 | for (auto &RefExpr : VarList) { |
| 9929 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9930 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9931 | // It will be analyzed later. |
| 9932 | Vars.push_back(RefExpr); |
| 9933 | continue; |
| 9934 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9935 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9936 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9937 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9938 | if (DepKind == OMPC_DEPEND_sink) { |
| 9939 | if (DepCounter >= TotalDepCount) { |
| 9940 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9941 | continue; |
| 9942 | } |
| 9943 | ++DepCounter; |
| 9944 | // OpenMP [2.13.9, Summary] |
| 9945 | // depend(dependence-type : vec), where dependence-type is: |
| 9946 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9947 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9948 | // where n is the value specified by the ordered clause in the loop |
| 9949 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9950 | // loop associated with the loop directive, and di is a constant |
| 9951 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9952 | if (CurContext->isDependentContext()) { |
| 9953 | // It will be analyzed later. |
| 9954 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9955 | continue; |
| 9956 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9957 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9958 | OverloadedOperatorKind OOK = OO_None; |
| 9959 | SourceLocation OOLoc; |
| 9960 | Expr *LHS = SimpleExpr; |
| 9961 | Expr *RHS = nullptr; |
| 9962 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9963 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9964 | OOLoc = BO->getOperatorLoc(); |
| 9965 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9966 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9967 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9968 | OOK = OCE->getOperator(); |
| 9969 | OOLoc = OCE->getOperatorLoc(); |
| 9970 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9971 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9972 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9973 | OOK = MCE->getMethodDecl() |
| 9974 | ->getNameInfo() |
| 9975 | .getName() |
| 9976 | .getCXXOverloadedOperator(); |
| 9977 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9978 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9979 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9980 | } |
| 9981 | SourceLocation ELoc; |
| 9982 | SourceRange ERange; |
| 9983 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 9984 | /*AllowArraySection=*/false); |
| 9985 | if (Res.second) { |
| 9986 | // It will be analyzed later. |
| 9987 | Vars.push_back(RefExpr); |
| 9988 | } |
| 9989 | ValueDecl *D = Res.first; |
| 9990 | if (!D) |
| 9991 | continue; |
| 9992 | |
| 9993 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 9994 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9995 | continue; |
| 9996 | } |
| 9997 | if (RHS) { |
| 9998 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 9999 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 10000 | if (RHSRes.isInvalid()) |
| 10001 | continue; |
| 10002 | } |
| 10003 | if (!CurContext->isDependentContext() && |
| 10004 | DSAStack->getParentOrderedRegionParam() && |
| 10005 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 10006 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10007 | << DSAStack->getParentLoopControlVariable( |
| 10008 | DepCounter.getZExtValue()); |
| 10009 | continue; |
| 10010 | } |
| 10011 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10012 | } else { |
| 10013 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 10014 | // A variable that is part of another variable (such as a field of a |
| 10015 | // structure) but is not an array element or an array section cannot |
| 10016 | // appear in a depend clause. |
| 10017 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 10018 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 10019 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 10020 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 10021 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 10022 | (ASE && |
| 10023 | !ASE->getBase() |
| 10024 | ->getType() |
| 10025 | .getNonReferenceType() |
| 10026 | ->isPointerType() && |
| 10027 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 10028 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 10029 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10030 | continue; |
| 10031 | } |
| 10032 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 10033 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 10034 | } |
| 10035 | |
| 10036 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 10037 | TotalDepCount > VarList.size() && |
| 10038 | DSAStack->getParentOrderedRegionParam()) { |
| 10039 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 10040 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 10041 | } |
| 10042 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 10043 | Vars.empty()) |
| 10044 | return nullptr; |
| 10045 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 10046 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10047 | DepKind, DepLoc, ColonLoc, Vars); |
| 10048 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 10049 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 10050 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 10051 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10052 | |
| 10053 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 10054 | SourceLocation LParenLoc, |
| 10055 | SourceLocation EndLoc) { |
| 10056 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10057 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10058 | // OpenMP [2.9.1, Restrictions] |
| 10059 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10060 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 10061 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10062 | return nullptr; |
| 10063 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 10064 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10065 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10066 | |
| 10067 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 10068 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 10069 | if (!RD || RD->isInvalidDecl()) |
| 10070 | return true; |
| 10071 | |
| 10072 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 10073 | if (RD->isDynamicClass()) { |
| 10074 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10075 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 10076 | return false; |
| 10077 | } |
| 10078 | auto *DC = RD; |
| 10079 | bool IsCorrect = true; |
| 10080 | for (auto *I : DC->decls()) { |
| 10081 | if (I) { |
| 10082 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 10083 | if (MD->isStatic()) { |
| 10084 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10085 | SemaRef.Diag(MD->getLocation(), |
| 10086 | diag::note_omp_static_member_in_target); |
| 10087 | IsCorrect = false; |
| 10088 | } |
| 10089 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 10090 | if (VD->isStaticDataMember()) { |
| 10091 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 10092 | SemaRef.Diag(VD->getLocation(), |
| 10093 | diag::note_omp_static_member_in_target); |
| 10094 | IsCorrect = false; |
| 10095 | } |
| 10096 | } |
| 10097 | } |
| 10098 | } |
| 10099 | |
| 10100 | for (auto &I : RD->bases()) { |
| 10101 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 10102 | I.getType()->getAsCXXRecordDecl())) |
| 10103 | IsCorrect = false; |
| 10104 | } |
| 10105 | return IsCorrect; |
| 10106 | } |
| 10107 | |
| 10108 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 10109 | DSAStackTy *Stack, QualType QTy) { |
| 10110 | NamedDecl *ND; |
| 10111 | if (QTy->isIncompleteType(&ND)) { |
| 10112 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 10113 | return false; |
| 10114 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10115 | if (!RD->isInvalidDecl() && !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10116 | return false; |
| 10117 | } |
| 10118 | return true; |
| 10119 | } |
| 10120 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10121 | /// \brief Return true if it can be proven that the provided array expression |
| 10122 | /// (array section or array subscript) does NOT specify the whole size of the |
| 10123 | /// array whose base type is \a BaseQTy. |
| 10124 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 10125 | const Expr *E, |
| 10126 | QualType BaseQTy) { |
| 10127 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10128 | |
| 10129 | // If this is an array subscript, it refers to the whole size if the size of |
| 10130 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 10131 | // format of an array subscript if no colon is used. |
| 10132 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 10133 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10134 | return ATy->getSize().getSExtValue() != 1; |
| 10135 | // Size can't be evaluated statically. |
| 10136 | return false; |
| 10137 | } |
| 10138 | |
| 10139 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10140 | auto *LowerBound = OASE->getLowerBound(); |
| 10141 | auto *Length = OASE->getLength(); |
| 10142 | |
| 10143 | // 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] | 10144 | // covering the whole dimension. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10145 | if (LowerBound) { |
| 10146 | llvm::APSInt ConstLowerBound; |
| 10147 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 10148 | return false; // Can't get the integer value as a constant. |
| 10149 | if (ConstLowerBound.getSExtValue()) |
| 10150 | return true; |
| 10151 | } |
| 10152 | |
| 10153 | // If we don't have a length we covering the whole dimension. |
| 10154 | if (!Length) |
| 10155 | return false; |
| 10156 | |
| 10157 | // If the base is a pointer, we don't have a way to get the size of the |
| 10158 | // pointee. |
| 10159 | if (BaseQTy->isPointerType()) |
| 10160 | return false; |
| 10161 | |
| 10162 | // We can only check if the length is the same as the size of the dimension |
| 10163 | // if we have a constant array. |
| 10164 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 10165 | if (!CATy) |
| 10166 | return false; |
| 10167 | |
| 10168 | llvm::APSInt ConstLength; |
| 10169 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10170 | return false; // Can't get the integer value as a constant. |
| 10171 | |
| 10172 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 10173 | } |
| 10174 | |
| 10175 | // Return true if it can be proven that the provided array expression (array |
| 10176 | // section or array subscript) does NOT specify a single element of the array |
| 10177 | // whose base type is \a BaseQTy. |
| 10178 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10179 | const Expr *E, |
| 10180 | QualType BaseQTy) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10181 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 10182 | |
| 10183 | // An array subscript always refer to a single element. Also, an array section |
| 10184 | // assumes the format of an array subscript if no colon is used. |
| 10185 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 10186 | return false; |
| 10187 | |
| 10188 | assert(OASE && "Expecting array section if not an array subscript."); |
| 10189 | auto *Length = OASE->getLength(); |
| 10190 | |
| 10191 | // If we don't have a length we have to check if the array has unitary size |
| 10192 | // for this dimension. Also, we should always expect a length if the base type |
| 10193 | // is pointer. |
| 10194 | if (!Length) { |
| 10195 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 10196 | return ATy->getSize().getSExtValue() != 1; |
| 10197 | // We cannot assume anything. |
| 10198 | return false; |
| 10199 | } |
| 10200 | |
| 10201 | // Check if the length evaluates to 1. |
| 10202 | llvm::APSInt ConstLength; |
| 10203 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 10204 | return false; // Can't get the integer value as a constant. |
| 10205 | |
| 10206 | return ConstLength.getSExtValue() != 1; |
| 10207 | } |
| 10208 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10209 | // Return the expression of the base of the mappable expression or null if it |
| 10210 | // cannot be determined and do all the necessary checks to see if the expression |
| 10211 | // 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] | 10212 | // components of the expression. |
| 10213 | static Expr *CheckMapClauseExpressionBase( |
| 10214 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10215 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 10216 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10217 | SourceLocation ELoc = E->getExprLoc(); |
| 10218 | SourceRange ERange = E->getSourceRange(); |
| 10219 | |
| 10220 | // The base of elements of list in a map clause have to be either: |
| 10221 | // - a reference to variable or field. |
| 10222 | // - a member expression. |
| 10223 | // - an array expression. |
| 10224 | // |
| 10225 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 10226 | // reference to 'r'. |
| 10227 | // |
| 10228 | // If we have: |
| 10229 | // |
| 10230 | // struct SS { |
| 10231 | // Bla S; |
| 10232 | // foo() { |
| 10233 | // #pragma omp target map (S.Arr[:12]); |
| 10234 | // } |
| 10235 | // } |
| 10236 | // |
| 10237 | // We want to retrieve the member expression 'this->S'; |
| 10238 | |
| 10239 | Expr *RelevantExpr = nullptr; |
| 10240 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10241 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 10242 | // If a list item is an array section, it must specify contiguous storage. |
| 10243 | // |
| 10244 | // For this restriction it is sufficient that we make sure only references |
| 10245 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10246 | // exist except in the rightmost expression (unless they cover the whole |
| 10247 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10248 | // |
| 10249 | // r.ArrS[3:5].Arr[6:7] |
| 10250 | // |
| 10251 | // r.ArrS[3:5].x |
| 10252 | // |
| 10253 | // but these would be valid: |
| 10254 | // r.ArrS[3].Arr[6:7] |
| 10255 | // |
| 10256 | // r.ArrS[3].x |
| 10257 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10258 | bool AllowUnitySizeArraySection = true; |
| 10259 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10260 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 10261 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10262 | E = E->IgnoreParenImpCasts(); |
| 10263 | |
| 10264 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 10265 | if (!isa<VarDecl>(CurE->getDecl())) |
| 10266 | break; |
| 10267 | |
| 10268 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10269 | |
| 10270 | // If we got a reference to a declaration, we should not expect any array |
| 10271 | // section before that. |
| 10272 | AllowUnitySizeArraySection = false; |
| 10273 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10274 | |
| 10275 | // Record the component. |
| 10276 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 10277 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10278 | continue; |
| 10279 | } |
| 10280 | |
| 10281 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 10282 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 10283 | |
| 10284 | if (isa<CXXThisExpr>(BaseE)) |
| 10285 | // We found a base expression: this->Val. |
| 10286 | RelevantExpr = CurE; |
| 10287 | else |
| 10288 | E = BaseE; |
| 10289 | |
| 10290 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 10291 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 10292 | << CurE->getSourceRange(); |
| 10293 | break; |
| 10294 | } |
| 10295 | |
| 10296 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 10297 | |
| 10298 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 10299 | // A bit-field cannot appear in a map clause. |
| 10300 | // |
| 10301 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10302 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 10303 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10304 | break; |
| 10305 | } |
| 10306 | |
| 10307 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10308 | // If the type of a list item is a reference to a type T then the type |
| 10309 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10310 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10311 | |
| 10312 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 10313 | // A list item cannot be a variable that is a member of a structure with |
| 10314 | // a union type. |
| 10315 | // |
| 10316 | if (auto *RT = CurType->getAs<RecordType>()) |
| 10317 | if (RT->isUnionType()) { |
| 10318 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 10319 | << CurE->getSourceRange(); |
| 10320 | break; |
| 10321 | } |
| 10322 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10323 | // If we got a member expression, we should not expect any array section |
| 10324 | // before that: |
| 10325 | // |
| 10326 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 10327 | // If a list item is an element of a structure, only the rightmost symbol |
| 10328 | // of the variable reference can be an array section. |
| 10329 | // |
| 10330 | AllowUnitySizeArraySection = false; |
| 10331 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10332 | |
| 10333 | // Record the component. |
| 10334 | CurComponents.push_back( |
| 10335 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10336 | continue; |
| 10337 | } |
| 10338 | |
| 10339 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 10340 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10341 | |
| 10342 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 10343 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10344 | << 0 << CurE->getSourceRange(); |
| 10345 | break; |
| 10346 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10347 | |
| 10348 | // If we got an array subscript that express the whole dimension we |
| 10349 | // can have any array expressions before. If it only expressing part of |
| 10350 | // the dimension, we can only have unitary-size array expressions. |
| 10351 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 10352 | E->getType())) |
| 10353 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10354 | |
| 10355 | // Record the component - we don't have any declaration associated. |
| 10356 | CurComponents.push_back( |
| 10357 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10358 | continue; |
| 10359 | } |
| 10360 | |
| 10361 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10362 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 10363 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10364 | auto CurType = |
| 10365 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10366 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10367 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10368 | // If the type of a list item is a reference to a type T then the type |
| 10369 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10370 | if (CurType->isReferenceType()) |
| 10371 | CurType = CurType->getPointeeType(); |
| 10372 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10373 | bool IsPointer = CurType->isAnyPointerType(); |
| 10374 | |
| 10375 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10376 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 10377 | << 0 << CurE->getSourceRange(); |
| 10378 | break; |
| 10379 | } |
| 10380 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10381 | bool NotWhole = |
| 10382 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 10383 | bool NotUnity = |
| 10384 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 10385 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10386 | if (AllowWholeSizeArraySection) { |
| 10387 | // Any array section is currently allowed. Allowing a whole size array |
| 10388 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10389 | // |
| 10390 | // If this array section refers to the whole dimension we can still |
| 10391 | // accept other array sections before this one, except if the base is a |
| 10392 | // pointer. Otherwise, only unitary sections are accepted. |
| 10393 | if (NotWhole || IsPointer) |
| 10394 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 10395 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 10396 | // A unity or whole array section is not allowed and that is not |
| 10397 | // compatible with the properties of the current array section. |
| 10398 | SemaRef.Diag( |
| 10399 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 10400 | << CurE->getSourceRange(); |
| 10401 | break; |
| 10402 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10403 | |
| 10404 | // Record the component - we don't have any declaration associated. |
| 10405 | CurComponents.push_back( |
| 10406 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10407 | continue; |
| 10408 | } |
| 10409 | |
| 10410 | // If nothing else worked, this is not a valid map clause expression. |
| 10411 | SemaRef.Diag(ELoc, |
| 10412 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 10413 | << ERange; |
| 10414 | break; |
| 10415 | } |
| 10416 | |
| 10417 | return RelevantExpr; |
| 10418 | } |
| 10419 | |
| 10420 | // Return true if expression E associated with value VD has conflicts with other |
| 10421 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10422 | static bool CheckMapConflicts( |
| 10423 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 10424 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10425 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 10426 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10427 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10428 | SourceLocation ELoc = E->getExprLoc(); |
| 10429 | SourceRange ERange = E->getSourceRange(); |
| 10430 | |
| 10431 | // In order to easily check the conflicts we need to match each component of |
| 10432 | // the expression under test with the components of the expressions that are |
| 10433 | // already in the stack. |
| 10434 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10435 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10436 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10437 | "Map clause expression with unexpected base!"); |
| 10438 | |
| 10439 | // Variables to help detecting enclosing problems in data environment nests. |
| 10440 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10441 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10442 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10443 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 10444 | VD, CurrentRegionOnly, |
| 10445 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10446 | StackComponents, |
| 10447 | OpenMPClauseKind) -> bool { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10448 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10449 | assert(!StackComponents.empty() && |
| 10450 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10451 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10452 | "Map clause expression with unexpected base!"); |
| 10453 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10454 | // The whole expression in the stack. |
| 10455 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 10456 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10457 | // Expressions must start from the same base. Here we detect at which |
| 10458 | // point both expressions diverge from each other and see if we can |
| 10459 | // detect if the memory referred to both expressions is contiguous and |
| 10460 | // do not overlap. |
| 10461 | auto CI = CurComponents.rbegin(); |
| 10462 | auto CE = CurComponents.rend(); |
| 10463 | auto SI = StackComponents.rbegin(); |
| 10464 | auto SE = StackComponents.rend(); |
| 10465 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 10466 | |
| 10467 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 10468 | // At most one list item can be an array item derived from a given |
| 10469 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10470 | if (CurrentRegionOnly && |
| 10471 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10472 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10473 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10474 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10475 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10476 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10477 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10478 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10479 | diag::note_used_here) |
| 10480 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10481 | return true; |
| 10482 | } |
| 10483 | |
| 10484 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10485 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10486 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10487 | break; |
| 10488 | |
| 10489 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10490 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10491 | break; |
| 10492 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10493 | // Check if the extra components of the expressions in the enclosing |
| 10494 | // data environment are redundant for the current base declaration. |
| 10495 | // If they are, the maps completely overlap, which is legal. |
| 10496 | for (; SI != SE; ++SI) { |
| 10497 | QualType Type; |
| 10498 | if (auto *ASE = |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10499 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10500 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10501 | } else if (auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| 10502 | SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10503 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10504 | Type = |
| 10505 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10506 | } |
| 10507 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10508 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10509 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10510 | break; |
| 10511 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10512 | |
| 10513 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10514 | // List items of map clauses in the same construct must not share |
| 10515 | // original storage. |
| 10516 | // |
| 10517 | // If the expressions are exactly the same or one is a subset of the |
| 10518 | // other, it means they are sharing storage. |
| 10519 | if (CI == CE && SI == SE) { |
| 10520 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10521 | if (CKind == OMPC_map) |
| 10522 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10523 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10524 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10525 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10526 | << ERange; |
| 10527 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10528 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10529 | << RE->getSourceRange(); |
| 10530 | return true; |
| 10531 | } else { |
| 10532 | // If we find the same expression in the enclosing data environment, |
| 10533 | // that is legal. |
| 10534 | IsEnclosedByDataEnvironmentExpr = true; |
| 10535 | return false; |
| 10536 | } |
| 10537 | } |
| 10538 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10539 | QualType DerivedType = |
| 10540 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10541 | SourceLocation DerivedLoc = |
| 10542 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10543 | |
| 10544 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10545 | // If the type of a list item is a reference to a type T then the type |
| 10546 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10547 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10548 | |
| 10549 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10550 | // A variable for which the type is pointer and an array section |
| 10551 | // derived from that variable must not appear as list items of map |
| 10552 | // clauses of the same construct. |
| 10553 | // |
| 10554 | // Also, cover one of the cases in: |
| 10555 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10556 | // If any part of the original storage of a list item has corresponding |
| 10557 | // storage in the device data environment, all of the original storage |
| 10558 | // must have corresponding storage in the device data environment. |
| 10559 | // |
| 10560 | if (DerivedType->isAnyPointerType()) { |
| 10561 | if (CI == CE || SI == SE) { |
| 10562 | SemaRef.Diag( |
| 10563 | DerivedLoc, |
| 10564 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10565 | << DerivedLoc; |
| 10566 | } else { |
| 10567 | assert(CI != CE && SI != SE); |
| 10568 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10569 | << DerivedLoc; |
| 10570 | } |
| 10571 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10572 | << RE->getSourceRange(); |
| 10573 | return true; |
| 10574 | } |
| 10575 | |
| 10576 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10577 | // List items of map clauses in the same construct must not share |
| 10578 | // original storage. |
| 10579 | // |
| 10580 | // An expression is a subset of the other. |
| 10581 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10582 | if (CKind == OMPC_map) |
| 10583 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10584 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10585 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10586 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10587 | << ERange; |
| 10588 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10589 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10590 | << RE->getSourceRange(); |
| 10591 | return true; |
| 10592 | } |
| 10593 | |
| 10594 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10595 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10596 | if (!CurrentRegionOnly && SI != SE) |
| 10597 | EnclosingExpr = RE; |
| 10598 | |
| 10599 | // The current expression is a subset of the expression in the data |
| 10600 | // environment. |
| 10601 | IsEnclosedByDataEnvironmentExpr |= |
| 10602 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10603 | |
| 10604 | return false; |
| 10605 | }); |
| 10606 | |
| 10607 | if (CurrentRegionOnly) |
| 10608 | return FoundError; |
| 10609 | |
| 10610 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10611 | // If any part of the original storage of a list item has corresponding |
| 10612 | // storage in the device data environment, all of the original storage must |
| 10613 | // have corresponding storage in the device data environment. |
| 10614 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10615 | // If a list item is an element of a structure, and a different element of |
| 10616 | // the structure has a corresponding list item in the device data environment |
| 10617 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10618 | // 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] | 10619 | // data environment prior to the task encountering the construct. |
| 10620 | // |
| 10621 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10622 | SemaRef.Diag(ELoc, |
| 10623 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10624 | << ERange; |
| 10625 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10626 | << EnclosingExpr->getSourceRange(); |
| 10627 | return true; |
| 10628 | } |
| 10629 | |
| 10630 | return FoundError; |
| 10631 | } |
| 10632 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10633 | namespace { |
| 10634 | // Utility struct that gathers all the related lists associated with a mappable |
| 10635 | // expression. |
| 10636 | struct MappableVarListInfo final { |
| 10637 | // The list of expressions. |
| 10638 | ArrayRef<Expr *> VarList; |
| 10639 | // The list of processed expressions. |
| 10640 | SmallVector<Expr *, 16> ProcessedVarList; |
| 10641 | // The mappble components for each expression. |
| 10642 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 10643 | // The base declaration of the variable. |
| 10644 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 10645 | |
| 10646 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 10647 | // We have a list of components and base declarations for each entry in the |
| 10648 | // variable list. |
| 10649 | VarComponents.reserve(VarList.size()); |
| 10650 | VarBaseDeclarations.reserve(VarList.size()); |
| 10651 | } |
| 10652 | }; |
| 10653 | } |
| 10654 | |
| 10655 | // Check the validity of the provided variable list for the provided clause kind |
| 10656 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 10657 | // components and variables are extracted and used to fill \a Vars, |
| 10658 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 10659 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 10660 | static void |
| 10661 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 10662 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 10663 | SourceLocation StartLoc, |
| 10664 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 10665 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10666 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 10667 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10668 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10669 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10670 | // Keep track of the mappable components and base declarations in this clause. |
| 10671 | // Each entry in the list is going to have a list of components associated. We |
| 10672 | // record each set of the components so that we can build the clause later on. |
| 10673 | // In the end we should have the same amount of declarations and component |
| 10674 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10675 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10676 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10677 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10678 | SourceLocation ELoc = RE->getExprLoc(); |
| 10679 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10680 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 10681 | |
| 10682 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 10683 | VE->isInstantiationDependent() || |
| 10684 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10685 | // We can only analyze this information once the missing information is |
| 10686 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10687 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10688 | continue; |
| 10689 | } |
| 10690 | |
| 10691 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10692 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10693 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10694 | SemaRef.Diag(ELoc, |
| 10695 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10696 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10697 | continue; |
| 10698 | } |
| 10699 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10700 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 10701 | ValueDecl *CurDeclaration = nullptr; |
| 10702 | |
| 10703 | // Obtain the array or member expression bases if required. Also, fill the |
| 10704 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10705 | auto *BE = |
| 10706 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10707 | if (!BE) |
| 10708 | continue; |
| 10709 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10710 | assert(!CurComponents.empty() && |
| 10711 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10712 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10713 | // For the following checks, we rely on the base declaration which is |
| 10714 | // expected to be associated with the last component. The declaration is |
| 10715 | // expected to be a variable or a field (if 'this' is being mapped). |
| 10716 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 10717 | assert(CurDeclaration && "Null decl on map clause."); |
| 10718 | assert( |
| 10719 | CurDeclaration->isCanonicalDecl() && |
| 10720 | "Expecting components to have associated only canonical declarations."); |
| 10721 | |
| 10722 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 10723 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10724 | |
| 10725 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 10726 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10727 | |
| 10728 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10729 | // threadprivate variables cannot appear in a map clause. |
| 10730 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 10731 | // threadprivate variables cannot appear in a from clause. |
| 10732 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 10733 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10734 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 10735 | << getOpenMPClauseName(CKind); |
| 10736 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10737 | continue; |
| 10738 | } |
| 10739 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10740 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 10741 | // A list item cannot appear in both a map clause and a data-sharing |
| 10742 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10743 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10744 | // Check conflicts with other map clause expressions. We check the conflicts |
| 10745 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10746 | // environment, because the restrictions are different. We only have to |
| 10747 | // check conflicts across regions for the map clauses. |
| 10748 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10749 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10750 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10751 | if (CKind == OMPC_map && |
| 10752 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10753 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10754 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10755 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10756 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10757 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10758 | // If the type of a list item is a reference to a type T then the type will |
| 10759 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10760 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10761 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10762 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 10763 | // 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] | 10764 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10765 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10766 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 10767 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10768 | continue; |
| 10769 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10770 | if (CKind == OMPC_map) { |
| 10771 | // target enter data |
| 10772 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 10773 | // A map-type must be specified in all map clauses and must be either |
| 10774 | // to or alloc. |
| 10775 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 10776 | if (DKind == OMPD_target_enter_data && |
| 10777 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 10778 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10779 | << (IsMapTypeImplicit ? 1 : 0) |
| 10780 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10781 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10782 | continue; |
| 10783 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10784 | |
| 10785 | // target exit_data |
| 10786 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 10787 | // A map-type must be specified in all map clauses and must be either |
| 10788 | // from, release, or delete. |
| 10789 | if (DKind == OMPD_target_exit_data && |
| 10790 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 10791 | MapType == OMPC_MAP_delete)) { |
| 10792 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10793 | << (IsMapTypeImplicit ? 1 : 0) |
| 10794 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10795 | << getOpenMPDirectiveName(DKind); |
| 10796 | continue; |
| 10797 | } |
| 10798 | |
| 10799 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10800 | // A list item cannot appear in both a map clause and a data-sharing |
| 10801 | // attribute clause on the same construct |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10802 | if ((DKind == OMPD_target || DKind == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10803 | DKind == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10804 | DKind == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10805 | DKind == OMPD_target_teams_distribute_parallel_for_simd || |
| 10806 | DKind == OMPD_target_teams_distribute_simd) && VD) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10807 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10808 | if (isOpenMPPrivate(DVar.CKind)) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10809 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10810 | << getOpenMPClauseName(DVar.CKind) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10811 | << getOpenMPClauseName(OMPC_map) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10812 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 10813 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 10814 | continue; |
| 10815 | } |
| 10816 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10817 | } |
| 10818 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10819 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10820 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10821 | |
| 10822 | // Store the components in the stack so that they can be used to check |
| 10823 | // against other clauses later on. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10824 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 10825 | /*WhereFoundClauseKind=*/OMPC_map); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10826 | |
| 10827 | // Save the components and declaration to create the clause. For purposes of |
| 10828 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 10829 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10830 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 10831 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 10832 | CurComponents.end()); |
| 10833 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 10834 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10835 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10836 | } |
| 10837 | |
| 10838 | OMPClause * |
| 10839 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 10840 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 10841 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 10842 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10843 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 10844 | MappableVarListInfo MVLI(VarList); |
| 10845 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 10846 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10847 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10848 | // We need to produce a map clause even if we don't have variables so that |
| 10849 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10850 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10851 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10852 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 10853 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10854 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10855 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10856 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 10857 | TypeResult ParsedType) { |
| 10858 | assert(ParsedType.isUsable()); |
| 10859 | |
| 10860 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 10861 | if (ReductionType.isNull()) |
| 10862 | return QualType(); |
| 10863 | |
| 10864 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 10865 | // A type name in a declare reduction directive cannot be a function type, an |
| 10866 | // array type, a reference type, or a type qualified with const, volatile or |
| 10867 | // restrict. |
| 10868 | if (ReductionType.hasQualifiers()) { |
| 10869 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 10870 | return QualType(); |
| 10871 | } |
| 10872 | |
| 10873 | if (ReductionType->isFunctionType()) { |
| 10874 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 10875 | return QualType(); |
| 10876 | } |
| 10877 | if (ReductionType->isReferenceType()) { |
| 10878 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 10879 | return QualType(); |
| 10880 | } |
| 10881 | if (ReductionType->isArrayType()) { |
| 10882 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 10883 | return QualType(); |
| 10884 | } |
| 10885 | return ReductionType; |
| 10886 | } |
| 10887 | |
| 10888 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 10889 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 10890 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 10891 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 10892 | SmallVector<Decl *, 8> Decls; |
| 10893 | Decls.reserve(ReductionTypes.size()); |
| 10894 | |
| 10895 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 10896 | ForRedeclaration); |
| 10897 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 10898 | // A reduction-identifier may not be re-declared in the current scope for the |
| 10899 | // same type or for a type that is compatible according to the base language |
| 10900 | // rules. |
| 10901 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 10902 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 10903 | bool InCompoundScope = true; |
| 10904 | if (S != nullptr) { |
| 10905 | // Find previous declaration with the same name not referenced in other |
| 10906 | // declarations. |
| 10907 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 10908 | InCompoundScope = |
| 10909 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 10910 | LookupName(Lookup, S); |
| 10911 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 10912 | /*AllowInlineNamespace=*/false); |
| 10913 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 10914 | auto Filter = Lookup.makeFilter(); |
| 10915 | while (Filter.hasNext()) { |
| 10916 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 10917 | if (InCompoundScope) { |
| 10918 | auto I = UsedAsPrevious.find(PrevDecl); |
| 10919 | if (I == UsedAsPrevious.end()) |
| 10920 | UsedAsPrevious[PrevDecl] = false; |
| 10921 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 10922 | UsedAsPrevious[D] = true; |
| 10923 | } |
| 10924 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 10925 | PrevDecl->getLocation(); |
| 10926 | } |
| 10927 | Filter.done(); |
| 10928 | if (InCompoundScope) { |
| 10929 | for (auto &PrevData : UsedAsPrevious) { |
| 10930 | if (!PrevData.second) { |
| 10931 | PrevDRD = PrevData.first; |
| 10932 | break; |
| 10933 | } |
| 10934 | } |
| 10935 | } |
| 10936 | } else if (PrevDeclInScope != nullptr) { |
| 10937 | auto *PrevDRDInScope = PrevDRD = |
| 10938 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 10939 | do { |
| 10940 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 10941 | PrevDRDInScope->getLocation(); |
| 10942 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 10943 | } while (PrevDRDInScope != nullptr); |
| 10944 | } |
| 10945 | for (auto &TyData : ReductionTypes) { |
| 10946 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10947 | bool Invalid = false; |
| 10948 | if (I != PreviousRedeclTypes.end()) { |
| 10949 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10950 | << TyData.first; |
| 10951 | Diag(I->second, diag::note_previous_definition); |
| 10952 | Invalid = true; |
| 10953 | } |
| 10954 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10955 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10956 | Name, TyData.first, PrevDRD); |
| 10957 | DC->addDecl(DRD); |
| 10958 | DRD->setAccess(AS); |
| 10959 | Decls.push_back(DRD); |
| 10960 | if (Invalid) |
| 10961 | DRD->setInvalidDecl(); |
| 10962 | else |
| 10963 | PrevDRD = DRD; |
| 10964 | } |
| 10965 | |
| 10966 | return DeclGroupPtrTy::make( |
| 10967 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10968 | } |
| 10969 | |
| 10970 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10971 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10972 | |
| 10973 | // Enter new function scope. |
| 10974 | PushFunctionScope(); |
| 10975 | getCurFunction()->setHasBranchProtectedScope(); |
| 10976 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10977 | |
| 10978 | if (S != nullptr) |
| 10979 | PushDeclContext(S, DRD); |
| 10980 | else |
| 10981 | CurContext = DRD; |
| 10982 | |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 10983 | PushExpressionEvaluationContext( |
| 10984 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10985 | |
| 10986 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10987 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10988 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10989 | // uses semantics of argument handles by value, but it should be passed by |
| 10990 | // reference. C lang does not support references, so pass all parameters as |
| 10991 | // pointers. |
| 10992 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10993 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10994 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10995 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 10996 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10997 | // uses semantics of argument handles by value, but it should be passed by |
| 10998 | // reference. C lang does not support references, so pass all parameters as |
| 10999 | // pointers. |
| 11000 | // Create 'T omp_out;' variable. |
| 11001 | auto *OmpOutParm = |
| 11002 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 11003 | if (S != nullptr) { |
| 11004 | PushOnScopeChains(OmpInParm, S); |
| 11005 | PushOnScopeChains(OmpOutParm, S); |
| 11006 | } else { |
| 11007 | DRD->addDecl(OmpInParm); |
| 11008 | DRD->addDecl(OmpOutParm); |
| 11009 | } |
| 11010 | } |
| 11011 | |
| 11012 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 11013 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11014 | DiscardCleanupsInEvaluationContext(); |
| 11015 | PopExpressionEvaluationContext(); |
| 11016 | |
| 11017 | PopDeclContext(); |
| 11018 | PopFunctionScopeInfo(); |
| 11019 | |
| 11020 | if (Combiner != nullptr) |
| 11021 | DRD->setCombiner(Combiner); |
| 11022 | else |
| 11023 | DRD->setInvalidDecl(); |
| 11024 | } |
| 11025 | |
| 11026 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 11027 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11028 | |
| 11029 | // Enter new function scope. |
| 11030 | PushFunctionScope(); |
| 11031 | getCurFunction()->setHasBranchProtectedScope(); |
| 11032 | |
| 11033 | if (S != nullptr) |
| 11034 | PushDeclContext(S, DRD); |
| 11035 | else |
| 11036 | CurContext = DRD; |
| 11037 | |
Faisal Vali | d143a0c | 2017-04-01 21:30:49 +0000 | [diff] [blame] | 11038 | PushExpressionEvaluationContext( |
| 11039 | ExpressionEvaluationContext::PotentiallyEvaluated); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11040 | |
| 11041 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11042 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 11043 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 11044 | // uses semantics of argument handles by value, but it should be passed by |
| 11045 | // reference. C lang does not support references, so pass all parameters as |
| 11046 | // pointers. |
| 11047 | // Create 'T omp_priv;' variable. |
| 11048 | auto *OmpPrivParm = |
| 11049 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 11050 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 11051 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 11052 | // uses semantics of argument handles by value, but it should be passed by |
| 11053 | // reference. C lang does not support references, so pass all parameters as |
| 11054 | // pointers. |
| 11055 | // Create 'T omp_orig;' variable. |
| 11056 | auto *OmpOrigParm = |
| 11057 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 11058 | if (S != nullptr) { |
| 11059 | PushOnScopeChains(OmpPrivParm, S); |
| 11060 | PushOnScopeChains(OmpOrigParm, S); |
| 11061 | } else { |
| 11062 | DRD->addDecl(OmpPrivParm); |
| 11063 | DRD->addDecl(OmpOrigParm); |
| 11064 | } |
| 11065 | } |
| 11066 | |
| 11067 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 11068 | Expr *Initializer) { |
| 11069 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11070 | DiscardCleanupsInEvaluationContext(); |
| 11071 | PopExpressionEvaluationContext(); |
| 11072 | |
| 11073 | PopDeclContext(); |
| 11074 | PopFunctionScopeInfo(); |
| 11075 | |
| 11076 | if (Initializer != nullptr) |
| 11077 | DRD->setInitializer(Initializer); |
| 11078 | else |
| 11079 | DRD->setInvalidDecl(); |
| 11080 | } |
| 11081 | |
| 11082 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11083 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 11084 | for (auto *D : DeclReductions.get()) { |
| 11085 | if (IsValid) { |
| 11086 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 11087 | if (S != nullptr) |
| 11088 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 11089 | } else |
| 11090 | D->setInvalidDecl(); |
| 11091 | } |
| 11092 | return DeclReductions; |
| 11093 | } |
| 11094 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11095 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11096 | SourceLocation StartLoc, |
| 11097 | SourceLocation LParenLoc, |
| 11098 | SourceLocation EndLoc) { |
| 11099 | Expr *ValExpr = NumTeams; |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 11100 | Stmt *HelperValStmt = nullptr; |
| 11101 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11102 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11103 | // OpenMP [teams Constrcut, Restrictions] |
| 11104 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11105 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 11106 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11107 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11108 | |
Arpith Chacko Jacob | bc12634 | 2017-01-25 11:28:18 +0000 | [diff] [blame] | 11109 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 11110 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_num_teams); |
| 11111 | if (CaptureRegion != OMPD_unknown) { |
| 11112 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11113 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11114 | HelperValStmt = buildPreInits(Context, Captures); |
| 11115 | } |
| 11116 | |
| 11117 | return new (Context) OMPNumTeamsClause(ValExpr, HelperValStmt, CaptureRegion, |
| 11118 | StartLoc, LParenLoc, EndLoc); |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 11119 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11120 | |
| 11121 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 11122 | SourceLocation StartLoc, |
| 11123 | SourceLocation LParenLoc, |
| 11124 | SourceLocation EndLoc) { |
| 11125 | Expr *ValExpr = ThreadLimit; |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 11126 | Stmt *HelperValStmt = nullptr; |
| 11127 | OpenMPDirectiveKind CaptureRegion = OMPD_unknown; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11128 | |
| 11129 | // OpenMP [teams Constrcut, Restrictions] |
| 11130 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11131 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 11132 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11133 | return nullptr; |
| 11134 | |
Arpith Chacko Jacob | 7ecc0b7 | 2017-01-25 11:44:35 +0000 | [diff] [blame] | 11135 | OpenMPDirectiveKind DKind = DSAStack->getCurrentDirective(); |
| 11136 | CaptureRegion = getOpenMPCaptureRegionForClause(DKind, OMPC_thread_limit); |
| 11137 | if (CaptureRegion != OMPD_unknown) { |
| 11138 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11139 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11140 | HelperValStmt = buildPreInits(Context, Captures); |
| 11141 | } |
| 11142 | |
| 11143 | return new (Context) OMPThreadLimitClause( |
| 11144 | ValExpr, HelperValStmt, CaptureRegion, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 11145 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 11146 | |
| 11147 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 11148 | SourceLocation StartLoc, |
| 11149 | SourceLocation LParenLoc, |
| 11150 | SourceLocation EndLoc) { |
| 11151 | Expr *ValExpr = Priority; |
| 11152 | |
| 11153 | // OpenMP [2.9.1, task Constrcut] |
| 11154 | // The priority-value is a non-negative numerical scalar expression. |
| 11155 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 11156 | /*StrictlyPositive=*/false)) |
| 11157 | return nullptr; |
| 11158 | |
| 11159 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11160 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 11161 | |
| 11162 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 11163 | SourceLocation StartLoc, |
| 11164 | SourceLocation LParenLoc, |
| 11165 | SourceLocation EndLoc) { |
| 11166 | Expr *ValExpr = Grainsize; |
| 11167 | |
| 11168 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11169 | // The parameter of the grainsize clause must be a positive integer |
| 11170 | // expression. |
| 11171 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 11172 | /*StrictlyPositive=*/true)) |
| 11173 | return nullptr; |
| 11174 | |
| 11175 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11176 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 11177 | |
| 11178 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 11179 | SourceLocation StartLoc, |
| 11180 | SourceLocation LParenLoc, |
| 11181 | SourceLocation EndLoc) { |
| 11182 | Expr *ValExpr = NumTasks; |
| 11183 | |
| 11184 | // OpenMP [2.9.2, taskloop Constrcut] |
| 11185 | // The parameter of the num_tasks clause must be a positive integer |
| 11186 | // expression. |
| 11187 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 11188 | /*StrictlyPositive=*/true)) |
| 11189 | return nullptr; |
| 11190 | |
| 11191 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 11192 | } |
| 11193 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 11194 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11195 | SourceLocation LParenLoc, |
| 11196 | SourceLocation EndLoc) { |
| 11197 | // OpenMP [2.13.2, critical construct, Description] |
| 11198 | // ... where hint-expression is an integer constant expression that evaluates |
| 11199 | // to a valid lock hint. |
| 11200 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 11201 | if (HintExpr.isInvalid()) |
| 11202 | return nullptr; |
| 11203 | return new (Context) |
| 11204 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 11205 | } |
| 11206 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11207 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 11208 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11209 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 11210 | SourceLocation EndLoc) { |
| 11211 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 11212 | std::string Values; |
| 11213 | Values += "'"; |
| 11214 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 11215 | Values += "'"; |
| 11216 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 11217 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 11218 | return nullptr; |
| 11219 | } |
| 11220 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11221 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11222 | if (ChunkSize) { |
| 11223 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 11224 | !ChunkSize->isInstantiationDependent() && |
| 11225 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 11226 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 11227 | ExprResult Val = |
| 11228 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 11229 | if (Val.isInvalid()) |
| 11230 | return nullptr; |
| 11231 | |
| 11232 | ValExpr = Val.get(); |
| 11233 | |
| 11234 | // OpenMP [2.7.1, Restrictions] |
| 11235 | // chunk_size must be a loop invariant integer expression with a positive |
| 11236 | // value. |
| 11237 | llvm::APSInt Result; |
| 11238 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 11239 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 11240 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 11241 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 11242 | return nullptr; |
| 11243 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 11244 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 11245 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 11246 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 11247 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 11248 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11249 | } |
| 11250 | } |
| 11251 | } |
| 11252 | |
| 11253 | return new (Context) |
| 11254 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 11255 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 11256 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11257 | |
| 11258 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 11259 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 11260 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 11261 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 11262 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11263 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11264 | std::string Value; |
| 11265 | SourceLocation Loc; |
| 11266 | Value += "'"; |
| 11267 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 11268 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11269 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11270 | Loc = MLoc; |
| 11271 | } else { |
| 11272 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11273 | OMPC_DEFAULTMAP_scalar); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 11274 | Loc = KindLoc; |
| 11275 | } |
| 11276 | Value += "'"; |
| 11277 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 11278 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 11279 | return nullptr; |
| 11280 | } |
| 11281 | |
| 11282 | return new (Context) |
| 11283 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 11284 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11285 | |
| 11286 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 11287 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 11288 | if (!CurLexicalContext->isFileContext() && |
| 11289 | !CurLexicalContext->isExternCContext() && |
| 11290 | !CurLexicalContext->isExternCXXContext()) { |
| 11291 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 11292 | return false; |
| 11293 | } |
| 11294 | if (IsInOpenMPDeclareTargetContext) { |
| 11295 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 11296 | return false; |
| 11297 | } |
| 11298 | |
| 11299 | IsInOpenMPDeclareTargetContext = true; |
| 11300 | return true; |
| 11301 | } |
| 11302 | |
| 11303 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 11304 | assert(IsInOpenMPDeclareTargetContext && |
| 11305 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 11306 | |
| 11307 | IsInOpenMPDeclareTargetContext = false; |
| 11308 | } |
| 11309 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11310 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 11311 | CXXScopeSpec &ScopeSpec, |
| 11312 | const DeclarationNameInfo &Id, |
| 11313 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11314 | NamedDeclSetType &SameDirectiveDecls) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11315 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 11316 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 11317 | |
| 11318 | if (Lookup.isAmbiguous()) |
| 11319 | return; |
| 11320 | Lookup.suppressDiagnostics(); |
| 11321 | |
| 11322 | if (!Lookup.isSingleResult()) { |
| 11323 | if (TypoCorrection Corrected = |
| 11324 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 11325 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 11326 | CTK_ErrorRecovery)) { |
| 11327 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 11328 | << Id.getName()); |
| 11329 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 11330 | return; |
| 11331 | } |
| 11332 | |
| 11333 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 11334 | return; |
| 11335 | } |
| 11336 | |
| 11337 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 11338 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 11339 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 11340 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 11341 | |
| 11342 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 11343 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 11344 | ND->addAttr(A); |
| 11345 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 11346 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 11347 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 11348 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 11349 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 11350 | << Id.getName(); |
| 11351 | } |
| 11352 | } else |
| 11353 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 11354 | } |
| 11355 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11356 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 11357 | Sema &SemaRef, Decl *D) { |
| 11358 | if (!D) |
| 11359 | return; |
| 11360 | Decl *LD = nullptr; |
| 11361 | if (isa<TagDecl>(D)) { |
| 11362 | LD = cast<TagDecl>(D)->getDefinition(); |
| 11363 | } else if (isa<VarDecl>(D)) { |
| 11364 | LD = cast<VarDecl>(D)->getDefinition(); |
| 11365 | |
| 11366 | // If this is an implicit variable that is legal and we do not need to do |
| 11367 | // anything. |
| 11368 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11369 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11370 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11371 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11372 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11373 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11374 | return; |
| 11375 | } |
| 11376 | |
| 11377 | } else if (isa<FunctionDecl>(D)) { |
| 11378 | const FunctionDecl *FD = nullptr; |
| 11379 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 11380 | LD = const_cast<FunctionDecl *>(FD); |
| 11381 | |
| 11382 | // If the definition is associated with the current declaration in the |
| 11383 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 11384 | // to do anything else. |
| 11385 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11386 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11387 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11388 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11389 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11390 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11391 | return; |
| 11392 | } |
| 11393 | } |
| 11394 | if (!LD) |
| 11395 | LD = D; |
| 11396 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11397 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 11398 | // Outlined declaration is not declared target. |
| 11399 | if (LD->isOutOfLine()) { |
| 11400 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11401 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11402 | } else { |
| 11403 | DeclContext *DC = LD->getDeclContext(); |
| 11404 | while (DC) { |
| 11405 | if (isa<FunctionDecl>(DC) && |
| 11406 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11407 | break; |
| 11408 | DC = DC->getParent(); |
| 11409 | } |
| 11410 | if (DC) |
| 11411 | return; |
| 11412 | |
| 11413 | // Is not declared in target context. |
| 11414 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 11415 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 11416 | } |
| 11417 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11418 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11419 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11420 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11421 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11422 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11423 | } |
| 11424 | } |
| 11425 | |
| 11426 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 11427 | Sema &SemaRef, DSAStackTy *Stack, |
| 11428 | ValueDecl *VD) { |
| 11429 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 11430 | return true; |
| 11431 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 11432 | return false; |
| 11433 | return true; |
| 11434 | } |
| 11435 | |
| 11436 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 11437 | if (!D || D->isInvalidDecl()) |
| 11438 | return; |
| 11439 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 11440 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 11441 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 11442 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 11443 | if (DSAStack->isThreadPrivate(VD)) { |
| 11444 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 11445 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 11446 | return; |
| 11447 | } |
| 11448 | } |
| 11449 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 11450 | // Problem if any with var declared with incomplete type will be reported |
| 11451 | // as normal, so no need to check it here. |
| 11452 | if ((E || !VD->getType()->isIncompleteType()) && |
| 11453 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 11454 | // Mark decl as declared target to prevent further diagnostic. |
| 11455 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11456 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11457 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11458 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11459 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11460 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11461 | } |
| 11462 | return; |
| 11463 | } |
| 11464 | } |
| 11465 | if (!E) { |
| 11466 | // Checking declaration inside declare target region. |
| 11467 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 11468 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11469 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 11470 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 11471 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11472 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 11473 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 11474 | } |
| 11475 | return; |
| 11476 | } |
| 11477 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 11478 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 11479 | |
| 11480 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 11481 | SourceLocation StartLoc, |
| 11482 | SourceLocation LParenLoc, |
| 11483 | SourceLocation EndLoc) { |
| 11484 | MappableVarListInfo MVLI(VarList); |
| 11485 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 11486 | if (MVLI.ProcessedVarList.empty()) |
| 11487 | return nullptr; |
| 11488 | |
| 11489 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11490 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11491 | MVLI.VarComponents); |
| 11492 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11493 | |
| 11494 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11495 | SourceLocation StartLoc, |
| 11496 | SourceLocation LParenLoc, |
| 11497 | SourceLocation EndLoc) { |
| 11498 | MappableVarListInfo MVLI(VarList); |
| 11499 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11500 | if (MVLI.ProcessedVarList.empty()) |
| 11501 | return nullptr; |
| 11502 | |
| 11503 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11504 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11505 | MVLI.VarComponents); |
| 11506 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11507 | |
| 11508 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11509 | SourceLocation StartLoc, |
| 11510 | SourceLocation LParenLoc, |
| 11511 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11512 | MappableVarListInfo MVLI(VarList); |
| 11513 | SmallVector<Expr *, 8> PrivateCopies; |
| 11514 | SmallVector<Expr *, 8> Inits; |
| 11515 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11516 | for (auto &RefExpr : VarList) { |
| 11517 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11518 | SourceLocation ELoc; |
| 11519 | SourceRange ERange; |
| 11520 | Expr *SimpleRefExpr = RefExpr; |
| 11521 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11522 | if (Res.second) { |
| 11523 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11524 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11525 | PrivateCopies.push_back(nullptr); |
| 11526 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11527 | } |
| 11528 | ValueDecl *D = Res.first; |
| 11529 | if (!D) |
| 11530 | continue; |
| 11531 | |
| 11532 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11533 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11534 | |
| 11535 | auto *VD = dyn_cast<VarDecl>(D); |
| 11536 | |
| 11537 | // Item should be a pointer or reference to pointer. |
| 11538 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11539 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11540 | << 0 << RefExpr->getSourceRange(); |
| 11541 | continue; |
| 11542 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11543 | |
| 11544 | // Build the private variable and the expression that refers to it. |
| 11545 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11546 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11547 | if (VDPrivate->isInvalidDecl()) |
| 11548 | continue; |
| 11549 | |
| 11550 | CurContext->addDecl(VDPrivate); |
| 11551 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11552 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11553 | |
| 11554 | // Add temporary variable to initialize the private copy of the pointer. |
| 11555 | auto *VDInit = |
| 11556 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11557 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11558 | RefExpr->getExprLoc()); |
| 11559 | AddInitializerToDecl(VDPrivate, |
| 11560 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11561 | /*DirectInit=*/false); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11562 | |
| 11563 | // If required, build a capture to implement the privatization initialized |
| 11564 | // with the current list item value. |
| 11565 | DeclRefExpr *Ref = nullptr; |
| 11566 | if (!VD) |
| 11567 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11568 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11569 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 11570 | Inits.push_back(VDInitRefExpr); |
| 11571 | |
| 11572 | // We need to add a data sharing attribute for this variable to make sure it |
| 11573 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 11574 | // similar properties of a first private variable. |
| 11575 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 11576 | |
| 11577 | // Create a mappable component for the list item. List items in this clause |
| 11578 | // only need a component. |
| 11579 | MVLI.VarBaseDeclarations.push_back(D); |
| 11580 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11581 | MVLI.VarComponents.back().push_back( |
| 11582 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11583 | } |
| 11584 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11585 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11586 | return nullptr; |
| 11587 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11588 | return OMPUseDevicePtrClause::Create( |
| 11589 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11590 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11591 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11592 | |
| 11593 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11594 | SourceLocation StartLoc, |
| 11595 | SourceLocation LParenLoc, |
| 11596 | SourceLocation EndLoc) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11597 | MappableVarListInfo MVLI(VarList); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11598 | for (auto &RefExpr : VarList) { |
Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 11599 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11600 | SourceLocation ELoc; |
| 11601 | SourceRange ERange; |
| 11602 | Expr *SimpleRefExpr = RefExpr; |
| 11603 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11604 | if (Res.second) { |
| 11605 | // It will be analyzed later. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11606 | MVLI.ProcessedVarList.push_back(RefExpr); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11607 | } |
| 11608 | ValueDecl *D = Res.first; |
| 11609 | if (!D) |
| 11610 | continue; |
| 11611 | |
| 11612 | QualType Type = D->getType(); |
| 11613 | // item should be a pointer or array or reference to pointer or array |
| 11614 | if (!Type.getNonReferenceType()->isPointerType() && |
| 11615 | !Type.getNonReferenceType()->isArrayType()) { |
| 11616 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 11617 | << 0 << RefExpr->getSourceRange(); |
| 11618 | continue; |
| 11619 | } |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11620 | |
| 11621 | // Check if the declaration in the clause does not show up in any data |
| 11622 | // sharing attribute. |
| 11623 | auto DVar = DSAStack->getTopDSA(D, false); |
| 11624 | if (isOpenMPPrivate(DVar.CKind)) { |
| 11625 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 11626 | << getOpenMPClauseName(DVar.CKind) |
| 11627 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 11628 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 11629 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 11630 | continue; |
| 11631 | } |
| 11632 | |
| 11633 | Expr *ConflictExpr; |
| 11634 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11635 | D, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11636 | [&ConflictExpr]( |
| 11637 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 11638 | OpenMPClauseKind) -> bool { |
| 11639 | ConflictExpr = R.front().getAssociatedExpression(); |
| 11640 | return true; |
| 11641 | })) { |
| 11642 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 11643 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 11644 | << ConflictExpr->getSourceRange(); |
| 11645 | continue; |
| 11646 | } |
| 11647 | |
| 11648 | // Store the components in the stack so that they can be used to check |
| 11649 | // against other clauses later on. |
| 11650 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 11651 | DSAStack->addMappableExpressionComponents( |
| 11652 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 11653 | |
| 11654 | // Record the expression we've just processed. |
| 11655 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 11656 | |
| 11657 | // Create a mappable component for the list item. List items in this clause |
| 11658 | // only need a component. We use a null declaration to signal fields in |
| 11659 | // 'this'. |
| 11660 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 11661 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 11662 | "Unexpected device pointer expression!"); |
| 11663 | MVLI.VarBaseDeclarations.push_back( |
| 11664 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 11665 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11666 | MVLI.VarComponents.back().push_back(MC); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11667 | } |
| 11668 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11669 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11670 | return nullptr; |
| 11671 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11672 | return OMPIsDevicePtrClause::Create( |
| 11673 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11674 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11675 | } |