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); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1053 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 1054 | } |
| 1055 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1056 | void Sema::StartOpenMPClause(OpenMPClauseKind K) { |
| 1057 | DSAStack->setClauseParsingMode(K); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1058 | } |
| 1059 | |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1060 | void Sema::EndOpenMPClause() { |
| 1061 | DSAStack->setClauseParsingMode(/*K=*/OMPC_unknown); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1064 | void Sema::EndOpenMPDSABlock(Stmt *CurDirective) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1065 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.1] |
| 1066 | // A variable of class type (or array thereof) that appears in a lastprivate |
| 1067 | // clause requires an accessible, unambiguous default constructor for the |
| 1068 | // class type, unless the list item is also specified in a firstprivate |
| 1069 | // clause. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1070 | if (auto *D = dyn_cast_or_null<OMPExecutableDirective>(CurDirective)) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1071 | for (auto *C : D->clauses()) { |
| 1072 | if (auto *Clause = dyn_cast<OMPLastprivateClause>(C)) { |
| 1073 | SmallVector<Expr *, 8> PrivateCopies; |
| 1074 | for (auto *DE : Clause->varlists()) { |
| 1075 | if (DE->isValueDependent() || DE->isTypeDependent()) { |
| 1076 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1077 | continue; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1078 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 1079 | auto *DRE = cast<DeclRefExpr>(DE->IgnoreParens()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1080 | VarDecl *VD = cast<VarDecl>(DRE->getDecl()); |
| 1081 | QualType Type = VD->getType().getNonReferenceType(); |
| 1082 | auto DVar = DSAStack->getTopDSA(VD, false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1083 | if (DVar.CKind == OMPC_lastprivate) { |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1084 | // Generate helper private variable and initialize it with the |
| 1085 | // default value. The address of the original variable is replaced |
| 1086 | // by the address of the new private variable in CodeGen. This new |
| 1087 | // variable is not added to IdResolver, so the code in the OpenMP |
| 1088 | // region uses original variable for proper diagnostics. |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 1089 | auto *VDPrivate = buildVarDecl( |
| 1090 | *this, DE->getExprLoc(), Type.getUnqualifiedType(), |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1091 | VD->getName(), VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1092 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1093 | if (VDPrivate->isInvalidDecl()) |
| 1094 | continue; |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 1095 | PrivateCopies.push_back(buildDeclRefExpr( |
| 1096 | *this, VDPrivate, DE->getType(), DE->getExprLoc())); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1097 | } else { |
| 1098 | // The variable is also a firstprivate, so initialization sequence |
| 1099 | // for private copy is generated already. |
| 1100 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1101 | } |
| 1102 | } |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1103 | // Set initializers to private copies if no errors were found. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1104 | if (PrivateCopies.size() == Clause->varlist_size()) |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1105 | Clause->setPrivateCopies(PrivateCopies); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | } |
| 1109 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1110 | DSAStack->pop(); |
| 1111 | DiscardCleanupsInEvaluationContext(); |
| 1112 | PopExpressionEvaluationContext(); |
| 1113 | } |
| 1114 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 1115 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 1116 | Expr *NumIterations, Sema &SemaRef, |
| 1117 | Scope *S, DSAStackTy *Stack); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1118 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1119 | namespace { |
| 1120 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1121 | class VarDeclFilterCCC : public CorrectionCandidateCallback { |
| 1122 | private: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1123 | Sema &SemaRef; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1124 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1125 | public: |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1126 | explicit VarDeclFilterCCC(Sema &S) : SemaRef(S) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 1127 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1128 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1129 | if (auto *VD = dyn_cast_or_null<VarDecl>(ND)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1130 | return VD->hasGlobalStorage() && |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1131 | SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1132 | SemaRef.getCurScope()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1133 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1134 | return false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1135 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1136 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1137 | |
| 1138 | class VarOrFuncDeclFilterCCC : public CorrectionCandidateCallback { |
| 1139 | private: |
| 1140 | Sema &SemaRef; |
| 1141 | |
| 1142 | public: |
| 1143 | explicit VarOrFuncDeclFilterCCC(Sema &S) : SemaRef(S) {} |
| 1144 | bool ValidateCandidate(const TypoCorrection &Candidate) override { |
| 1145 | NamedDecl *ND = Candidate.getCorrectionDecl(); |
| 1146 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 1147 | return SemaRef.isDeclInScope(ND, SemaRef.getCurLexicalContext(), |
| 1148 | SemaRef.getCurScope()); |
| 1149 | } |
| 1150 | return false; |
| 1151 | } |
| 1152 | }; |
| 1153 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1154 | } // namespace |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1155 | |
| 1156 | ExprResult Sema::ActOnOpenMPIdExpression(Scope *CurScope, |
| 1157 | CXXScopeSpec &ScopeSpec, |
| 1158 | const DeclarationNameInfo &Id) { |
| 1159 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 1160 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 1161 | |
| 1162 | if (Lookup.isAmbiguous()) |
| 1163 | return ExprError(); |
| 1164 | |
| 1165 | VarDecl *VD; |
| 1166 | if (!Lookup.isSingleResult()) { |
Kaelyn Takata | 89c881b | 2014-10-27 18:07:29 +0000 | [diff] [blame] | 1167 | if (TypoCorrection Corrected = CorrectTypo( |
| 1168 | Id, LookupOrdinaryName, CurScope, nullptr, |
| 1169 | llvm::make_unique<VarDeclFilterCCC>(*this), CTK_ErrorRecovery)) { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1170 | diagnoseTypo(Corrected, |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1171 | PDiag(Lookup.empty() |
| 1172 | ? diag::err_undeclared_var_use_suggest |
| 1173 | : diag::err_omp_expected_var_arg_suggest) |
| 1174 | << Id.getName()); |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1175 | VD = Corrected.getCorrectionDeclAs<VarDecl>(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1176 | } else { |
Richard Smith | f9b1510 | 2013-08-17 00:46:16 +0000 | [diff] [blame] | 1177 | Diag(Id.getLoc(), Lookup.empty() ? diag::err_undeclared_var_use |
| 1178 | : diag::err_omp_expected_var_arg) |
| 1179 | << Id.getName(); |
| 1180 | return ExprError(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1181 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1182 | } else { |
| 1183 | if (!(VD = Lookup.getAsSingle<VarDecl>())) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1184 | Diag(Id.getLoc(), diag::err_omp_expected_var_arg) << Id.getName(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1185 | Diag(Lookup.getFoundDecl()->getLocation(), diag::note_declared_at); |
| 1186 | return ExprError(); |
| 1187 | } |
| 1188 | } |
| 1189 | Lookup.suppressDiagnostics(); |
| 1190 | |
| 1191 | // OpenMP [2.9.2, Syntax, C/C++] |
| 1192 | // Variables must be file-scope, namespace-scope, or static block-scope. |
| 1193 | if (!VD->hasGlobalStorage()) { |
| 1194 | Diag(Id.getLoc(), diag::err_omp_global_var_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1195 | << getOpenMPDirectiveName(OMPD_threadprivate) << !VD->isStaticLocal(); |
| 1196 | bool IsDecl = |
| 1197 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1198 | Diag(VD->getLocation(), |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1199 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1200 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1201 | return ExprError(); |
| 1202 | } |
| 1203 | |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1204 | VarDecl *CanonicalVD = VD->getCanonicalDecl(); |
| 1205 | NamedDecl *ND = cast<NamedDecl>(CanonicalVD); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1206 | // OpenMP [2.9.2, Restrictions, C/C++, p.2] |
| 1207 | // A threadprivate directive for file-scope variables must appear outside |
| 1208 | // any definition or declaration. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1209 | if (CanonicalVD->getDeclContext()->isTranslationUnit() && |
| 1210 | !getCurLexicalContext()->isTranslationUnit()) { |
| 1211 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1212 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1213 | bool IsDecl = |
| 1214 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1215 | Diag(VD->getLocation(), |
| 1216 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1217 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1218 | return ExprError(); |
| 1219 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1220 | // OpenMP [2.9.2, Restrictions, C/C++, p.3] |
| 1221 | // A threadprivate directive for static class member variables must appear |
| 1222 | // in the class definition, in the same scope in which the member |
| 1223 | // variables are declared. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1224 | if (CanonicalVD->isStaticDataMember() && |
| 1225 | !CanonicalVD->getDeclContext()->Equals(getCurLexicalContext())) { |
| 1226 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1227 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1228 | bool IsDecl = |
| 1229 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1230 | Diag(VD->getLocation(), |
| 1231 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1232 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1233 | return ExprError(); |
| 1234 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1235 | // OpenMP [2.9.2, Restrictions, C/C++, p.4] |
| 1236 | // A threadprivate directive for namespace-scope variables must appear |
| 1237 | // outside any definition or declaration other than the namespace |
| 1238 | // definition itself. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1239 | if (CanonicalVD->getDeclContext()->isNamespace() && |
| 1240 | (!getCurLexicalContext()->isFileContext() || |
| 1241 | !getCurLexicalContext()->Encloses(CanonicalVD->getDeclContext()))) { |
| 1242 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1243 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1244 | bool IsDecl = |
| 1245 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1246 | Diag(VD->getLocation(), |
| 1247 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1248 | << VD; |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1249 | return ExprError(); |
| 1250 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1251 | // OpenMP [2.9.2, Restrictions, C/C++, p.6] |
| 1252 | // A threadprivate directive for static block-scope variables must appear |
| 1253 | // in the scope of the variable and not in a nested scope. |
Alexey Bataev | 7d2960b | 2013-09-26 03:24:06 +0000 | [diff] [blame] | 1254 | if (CanonicalVD->isStaticLocal() && CurScope && |
| 1255 | !isDeclInScope(ND, getCurLexicalContext(), CurScope)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1256 | Diag(Id.getLoc(), diag::err_omp_var_scope) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1257 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
| 1258 | bool IsDecl = |
| 1259 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1260 | Diag(VD->getLocation(), |
| 1261 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1262 | << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1263 | return ExprError(); |
| 1264 | } |
| 1265 | |
| 1266 | // OpenMP [2.9.2, Restrictions, C/C++, p.2-6] |
| 1267 | // A threadprivate directive must lexically precede all references to any |
| 1268 | // of the variables in its list. |
Alexey Bataev | 6ddfe1a | 2015-04-16 13:49:42 +0000 | [diff] [blame] | 1269 | if (VD->isUsed() && !DSAStack->isThreadPrivate(VD)) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1270 | Diag(Id.getLoc(), diag::err_omp_var_used) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1271 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1272 | return ExprError(); |
| 1273 | } |
| 1274 | |
| 1275 | QualType ExprType = VD->getType().getNonReferenceType(); |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1276 | return DeclRefExpr::Create(Context, NestedNameSpecifierLoc(), |
| 1277 | SourceLocation(), VD, |
| 1278 | /*RefersToEnclosingVariableOrCapture=*/false, |
| 1279 | Id.getLoc(), ExprType, VK_LValue); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1282 | Sema::DeclGroupPtrTy |
| 1283 | Sema::ActOnOpenMPThreadprivateDirective(SourceLocation Loc, |
| 1284 | ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1285 | if (OMPThreadPrivateDecl *D = CheckOMPThreadPrivateDecl(Loc, VarList)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1286 | CurContext->addDecl(D); |
| 1287 | return DeclGroupPtrTy::make(DeclGroupRef(D)); |
| 1288 | } |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1289 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1292 | namespace { |
| 1293 | class LocalVarRefChecker : public ConstStmtVisitor<LocalVarRefChecker, bool> { |
| 1294 | Sema &SemaRef; |
| 1295 | |
| 1296 | public: |
| 1297 | bool VisitDeclRefExpr(const DeclRefExpr *E) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1298 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1299 | if (VD->hasLocalStorage()) { |
| 1300 | SemaRef.Diag(E->getLocStart(), |
| 1301 | diag::err_omp_local_var_in_threadprivate_init) |
| 1302 | << E->getSourceRange(); |
| 1303 | SemaRef.Diag(VD->getLocation(), diag::note_defined_here) |
| 1304 | << VD << VD->getSourceRange(); |
| 1305 | return true; |
| 1306 | } |
| 1307 | } |
| 1308 | return false; |
| 1309 | } |
| 1310 | bool VisitStmt(const Stmt *S) { |
| 1311 | for (auto Child : S->children()) { |
| 1312 | if (Child && Visit(Child)) |
| 1313 | return true; |
| 1314 | } |
| 1315 | return false; |
| 1316 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1317 | explicit LocalVarRefChecker(Sema &SemaRef) : SemaRef(SemaRef) {} |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1318 | }; |
| 1319 | } // namespace |
| 1320 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1321 | OMPThreadPrivateDecl * |
| 1322 | Sema::CheckOMPThreadPrivateDecl(SourceLocation Loc, ArrayRef<Expr *> VarList) { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1323 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1324 | for (auto &RefExpr : VarList) { |
| 1325 | DeclRefExpr *DE = cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1326 | VarDecl *VD = cast<VarDecl>(DE->getDecl()); |
| 1327 | SourceLocation ILoc = DE->getExprLoc(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1328 | |
Alexey Bataev | 376b4a4 | 2016-02-09 09:41:09 +0000 | [diff] [blame] | 1329 | // Mark variable as used. |
| 1330 | VD->setReferenced(); |
| 1331 | VD->markUsed(Context); |
| 1332 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1333 | QualType QType = VD->getType(); |
| 1334 | if (QType->isDependentType() || QType->isInstantiationDependentType()) { |
| 1335 | // It will be analyzed later. |
| 1336 | Vars.push_back(DE); |
| 1337 | continue; |
| 1338 | } |
| 1339 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1340 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1341 | // A threadprivate variable must not have an incomplete type. |
| 1342 | if (RequireCompleteType(ILoc, VD->getType(), |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1343 | diag::err_omp_threadprivate_incomplete_type)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1344 | continue; |
| 1345 | } |
| 1346 | |
| 1347 | // OpenMP [2.9.2, Restrictions, C/C++, p.10] |
| 1348 | // A threadprivate variable must not have a reference type. |
| 1349 | if (VD->getType()->isReferenceType()) { |
| 1350 | Diag(ILoc, diag::err_omp_ref_type_arg) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1351 | << getOpenMPDirectiveName(OMPD_threadprivate) << VD->getType(); |
| 1352 | bool IsDecl = |
| 1353 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1354 | Diag(VD->getLocation(), |
| 1355 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1356 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1357 | continue; |
| 1358 | } |
| 1359 | |
Samuel Antao | f8b5012 | 2015-07-13 22:54:53 +0000 | [diff] [blame] | 1360 | // Check if this is a TLS variable. If TLS is not being supported, produce |
| 1361 | // the corresponding diagnostic. |
| 1362 | if ((VD->getTLSKind() != VarDecl::TLS_None && |
| 1363 | !(VD->hasAttr<OMPThreadPrivateDeclAttr>() && |
| 1364 | getLangOpts().OpenMPUseTLS && |
| 1365 | getASTContext().getTargetInfo().isTLSSupported())) || |
Alexey Bataev | 1a8b3f1 | 2015-05-06 06:34:55 +0000 | [diff] [blame] | 1366 | (VD->getStorageClass() == SC_Register && VD->hasAttr<AsmLabelAttr>() && |
| 1367 | !VD->isLocalVarDecl())) { |
Alexey Bataev | 26a3924 | 2015-01-13 03:35:30 +0000 | [diff] [blame] | 1368 | Diag(ILoc, diag::err_omp_var_thread_local) |
| 1369 | << VD << ((VD->getTLSKind() != VarDecl::TLS_None) ? 0 : 1); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1370 | bool IsDecl = |
| 1371 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 1372 | Diag(VD->getLocation(), |
| 1373 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 1374 | << VD; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1375 | continue; |
| 1376 | } |
| 1377 | |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1378 | // Check if initial value of threadprivate variable reference variable with |
| 1379 | // local storage (it is not supported by runtime). |
| 1380 | if (auto Init = VD->getAnyInitializer()) { |
| 1381 | LocalVarRefChecker Checker(*this); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1382 | if (Checker.Visit(Init)) |
| 1383 | continue; |
Alexey Bataev | 18b92ee | 2014-05-28 07:40:25 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1386 | Vars.push_back(RefExpr); |
Alexey Bataev | d178ad4 | 2014-03-07 08:03:37 +0000 | [diff] [blame] | 1387 | DSAStack->addDSA(VD, DE, OMPC_threadprivate); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 1388 | VD->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 1389 | Context, SourceRange(Loc, Loc))); |
| 1390 | if (auto *ML = Context.getASTMutationListener()) |
| 1391 | ML->DeclarationMarkedOpenMPThreadPrivate(VD); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1392 | } |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 1393 | OMPThreadPrivateDecl *D = nullptr; |
Alexey Bataev | ec3da87 | 2014-01-31 05:15:34 +0000 | [diff] [blame] | 1394 | if (!Vars.empty()) { |
| 1395 | D = OMPThreadPrivateDecl::Create(Context, getCurLexicalContext(), Loc, |
| 1396 | Vars); |
| 1397 | D->setAccess(AS_public); |
| 1398 | } |
| 1399 | return D; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1400 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1401 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1402 | static void ReportOriginalDSA(Sema &SemaRef, DSAStackTy *Stack, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1403 | const ValueDecl *D, DSAStackTy::DSAVarData DVar, |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1404 | bool IsLoopIterVar = false) { |
| 1405 | if (DVar.RefExpr) { |
| 1406 | SemaRef.Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_explicit_dsa) |
| 1407 | << getOpenMPClauseName(DVar.CKind); |
| 1408 | return; |
| 1409 | } |
| 1410 | enum { |
| 1411 | PDSA_StaticMemberShared, |
| 1412 | PDSA_StaticLocalVarShared, |
| 1413 | PDSA_LoopIterVarPrivate, |
| 1414 | PDSA_LoopIterVarLinear, |
| 1415 | PDSA_LoopIterVarLastprivate, |
| 1416 | PDSA_ConstVarShared, |
| 1417 | PDSA_GlobalVarShared, |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1418 | PDSA_TaskVarFirstprivate, |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1419 | PDSA_LocalVarPrivate, |
| 1420 | PDSA_Implicit |
| 1421 | } Reason = PDSA_Implicit; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1422 | bool ReportHint = false; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1423 | auto ReportLoc = D->getLocation(); |
| 1424 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1425 | if (IsLoopIterVar) { |
| 1426 | if (DVar.CKind == OMPC_private) |
| 1427 | Reason = PDSA_LoopIterVarPrivate; |
| 1428 | else if (DVar.CKind == OMPC_lastprivate) |
| 1429 | Reason = PDSA_LoopIterVarLastprivate; |
| 1430 | else |
| 1431 | Reason = PDSA_LoopIterVarLinear; |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1432 | } else if (isOpenMPTaskingDirective(DVar.DKind) && |
| 1433 | DVar.CKind == OMPC_firstprivate) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1434 | Reason = PDSA_TaskVarFirstprivate; |
| 1435 | ReportLoc = DVar.ImplicitDSALoc; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1436 | } else if (VD && VD->isStaticLocal()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1437 | Reason = PDSA_StaticLocalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1438 | else if (VD && VD->isStaticDataMember()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1439 | Reason = PDSA_StaticMemberShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1440 | else if (VD && VD->isFileVarDecl()) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1441 | Reason = PDSA_GlobalVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1442 | else if (D->getType().isConstant(SemaRef.getASTContext())) |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1443 | Reason = PDSA_ConstVarShared; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1444 | else if (VD && VD->isLocalVarDecl() && DVar.CKind == OMPC_private) { |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1445 | ReportHint = true; |
| 1446 | Reason = PDSA_LocalVarPrivate; |
| 1447 | } |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1448 | if (Reason != PDSA_Implicit) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1449 | SemaRef.Diag(ReportLoc, diag::note_omp_predetermined_dsa) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1450 | << Reason << ReportHint |
| 1451 | << getOpenMPDirectiveName(Stack->getCurrentDirective()); |
| 1452 | } else if (DVar.ImplicitDSALoc.isValid()) { |
| 1453 | SemaRef.Diag(DVar.ImplicitDSALoc, diag::note_omp_implicit_dsa) |
| 1454 | << getOpenMPClauseName(DVar.CKind); |
| 1455 | } |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1458 | namespace { |
| 1459 | class DSAAttrChecker : public StmtVisitor<DSAAttrChecker, void> { |
| 1460 | DSAStackTy *Stack; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1461 | Sema &SemaRef; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1462 | bool ErrorFound; |
| 1463 | CapturedStmt *CS; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1464 | llvm::SmallVector<Expr *, 8> ImplicitFirstprivate; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1465 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1466 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1467 | public: |
| 1468 | void VisitDeclRefExpr(DeclRefExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1469 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1470 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1471 | return; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1472 | if (auto *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1473 | // Skip internally declared variables. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1474 | if (VD->isLocalVarDecl() && !CS->capturesVariable(VD)) |
| 1475 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1476 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1477 | auto DVar = Stack->getTopDSA(VD, false); |
| 1478 | // Check if the variable has explicit DSA set and stop analysis if it so. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1479 | if (DVar.RefExpr) |
| 1480 | return; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1481 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1482 | auto ELoc = E->getExprLoc(); |
| 1483 | auto DKind = Stack->getCurrentDirective(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1484 | // The default(none) clause requires that each variable that is referenced |
| 1485 | // in the construct, and does not have a predetermined data-sharing |
| 1486 | // attribute, must have its data-sharing attribute explicitly determined |
| 1487 | // by being listed in a data-sharing attribute clause. |
| 1488 | if (DVar.CKind == OMPC_unknown && Stack->getDefaultDSA() == DSA_none && |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1489 | isParallelOrTaskRegion(DKind) && |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1490 | VarsWithInheritedDSA.count(VD) == 0) { |
| 1491 | VarsWithInheritedDSA[VD] = E; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1492 | return; |
| 1493 | } |
| 1494 | |
| 1495 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1496 | // A list item that appears in a reduction clause of the innermost |
| 1497 | // enclosing worksharing or parallel construct may not be accessed in an |
| 1498 | // explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1499 | DVar = Stack->hasInnermostDSA( |
| 1500 | VD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1501 | [](OpenMPDirectiveKind K) -> bool { |
| 1502 | return isOpenMPParallelDirective(K) || |
| 1503 | isOpenMPWorksharingDirective(K) || isOpenMPTeamsDirective(K); |
| 1504 | }, |
| 1505 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1506 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1507 | ErrorFound = true; |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1508 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1509 | ReportOriginalDSA(SemaRef, Stack, VD, DVar); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1510 | return; |
| 1511 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1512 | |
| 1513 | // Define implicit data-sharing attributes for task. |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1514 | DVar = Stack->getImplicitDSA(VD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1515 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1516 | !Stack->isLoopControlVariable(VD).first) |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1517 | ImplicitFirstprivate.push_back(E); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1518 | } |
| 1519 | } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1520 | void VisitMemberExpr(MemberExpr *E) { |
Alexey Bataev | 07b79c2 | 2016-04-29 09:56:11 +0000 | [diff] [blame] | 1521 | if (E->isTypeDependent() || E->isValueDependent() || |
| 1522 | E->containsUnexpandedParameterPack() || E->isInstantiationDependent()) |
| 1523 | return; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1524 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParens())) { |
| 1525 | if (auto *FD = dyn_cast<FieldDecl>(E->getMemberDecl())) { |
| 1526 | auto DVar = Stack->getTopDSA(FD, false); |
| 1527 | // Check if the variable has explicit DSA set and stop analysis if it |
| 1528 | // so. |
| 1529 | if (DVar.RefExpr) |
| 1530 | return; |
| 1531 | |
| 1532 | auto ELoc = E->getExprLoc(); |
| 1533 | auto DKind = Stack->getCurrentDirective(); |
| 1534 | // OpenMP [2.9.3.6, Restrictions, p.2] |
| 1535 | // A list item that appears in a reduction clause of the innermost |
| 1536 | // enclosing worksharing or parallel construct may not be accessed in |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 1537 | // an explicit task. |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 1538 | DVar = Stack->hasInnermostDSA( |
| 1539 | FD, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 1540 | [](OpenMPDirectiveKind K) -> bool { |
| 1541 | return isOpenMPParallelDirective(K) || |
| 1542 | isOpenMPWorksharingDirective(K) || |
| 1543 | isOpenMPTeamsDirective(K); |
| 1544 | }, |
| 1545 | false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1546 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind == OMPC_reduction) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1547 | ErrorFound = true; |
| 1548 | SemaRef.Diag(ELoc, diag::err_omp_reduction_in_task); |
| 1549 | ReportOriginalDSA(SemaRef, Stack, FD, DVar); |
| 1550 | return; |
| 1551 | } |
| 1552 | |
| 1553 | // Define implicit data-sharing attributes for task. |
| 1554 | DVar = Stack->getImplicitDSA(FD, false); |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 1555 | if (isOpenMPTaskingDirective(DKind) && DVar.CKind != OMPC_shared && |
| 1556 | !Stack->isLoopControlVariable(FD).first) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1557 | ImplicitFirstprivate.push_back(E); |
| 1558 | } |
Alexey Bataev | 7fcacd8 | 2016-11-28 15:55:15 +0000 | [diff] [blame] | 1559 | } else |
| 1560 | Visit(E->getBase()); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1561 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1562 | void VisitOMPExecutableDirective(OMPExecutableDirective *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1563 | for (auto *C : S->clauses()) { |
| 1564 | // Skip analysis of arguments of implicitly defined firstprivate clause |
| 1565 | // for task directives. |
| 1566 | if (C && (!isa<OMPFirstprivateClause>(C) || C->getLocStart().isValid())) |
| 1567 | for (auto *CC : C->children()) { |
| 1568 | if (CC) |
| 1569 | Visit(CC); |
| 1570 | } |
| 1571 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1572 | } |
| 1573 | void VisitStmt(Stmt *S) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1574 | for (auto *C : S->children()) { |
| 1575 | if (C && !isa<OMPExecutableDirective>(C)) |
| 1576 | Visit(C); |
| 1577 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1578 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1579 | |
| 1580 | bool isErrorFound() { return ErrorFound; } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1581 | ArrayRef<Expr *> getImplicitFirstprivate() { return ImplicitFirstprivate; } |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 1582 | llvm::DenseMap<ValueDecl *, Expr *> &getVarsWithInheritedDSA() { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1583 | return VarsWithInheritedDSA; |
| 1584 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1585 | |
Alexey Bataev | 7ff5524 | 2014-06-19 09:13:45 +0000 | [diff] [blame] | 1586 | DSAAttrChecker(DSAStackTy *S, Sema &SemaRef, CapturedStmt *CS) |
| 1587 | : Stack(S), SemaRef(SemaRef), ErrorFound(false), CS(CS) {} |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1588 | }; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 1589 | } // namespace |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1590 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1591 | void Sema::ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope) { |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1592 | switch (DKind) { |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1593 | case OMPD_parallel: |
| 1594 | case OMPD_parallel_for: |
| 1595 | case OMPD_parallel_for_simd: |
| 1596 | case OMPD_parallel_sections: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1597 | case OMPD_teams: |
| 1598 | case OMPD_target_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 | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1611 | case OMPD_target_parallel: { |
| 1612 | Sema::CapturedParamNameType ParamsTarget[] = { |
| 1613 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1614 | }; |
| 1615 | // Start a captured region for 'target' with no implicit parameters. |
| 1616 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1617 | ParamsTarget); |
| 1618 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1619 | QualType KmpInt32PtrTy = |
| 1620 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1621 | Sema::CapturedParamNameType ParamsParallel[] = { |
| 1622 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1623 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1624 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1625 | }; |
| 1626 | // Start a captured region for 'parallel'. |
| 1627 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1628 | ParamsParallel); |
| 1629 | break; |
| 1630 | } |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1631 | case OMPD_simd: |
| 1632 | case OMPD_for: |
| 1633 | case OMPD_for_simd: |
| 1634 | case OMPD_sections: |
| 1635 | case OMPD_section: |
| 1636 | case OMPD_single: |
| 1637 | case OMPD_master: |
| 1638 | case OMPD_critical: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1639 | case OMPD_taskgroup: |
| 1640 | case OMPD_distribute: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1641 | case OMPD_ordered: |
| 1642 | case OMPD_atomic: |
| 1643 | case OMPD_target_data: |
| 1644 | case OMPD_target: |
Kelvin Li | 70a12c5 | 2016-07-13 21:51:49 +0000 | [diff] [blame] | 1645 | case OMPD_target_parallel_for: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1646 | case OMPD_target_parallel_for_simd: |
| 1647 | case OMPD_target_simd: { |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 1648 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1649 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1650 | }; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1651 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1652 | Params); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1653 | break; |
| 1654 | } |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1655 | case OMPD_task: { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1656 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
Alexey Bataev | 3ae88e2 | 2015-05-22 08:56:35 +0000 | [diff] [blame] | 1657 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1658 | FunctionProtoType::ExtProtoInfo EPI; |
| 1659 | EPI.Variadic = true; |
| 1660 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1661 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1662 | std::make_pair(".global_tid.", KmpInt32Ty), |
Alexey Bataev | 48591dd | 2016-04-20 04:01:36 +0000 | [diff] [blame] | 1663 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1664 | std::make_pair(".privates.", Context.VoidPtrTy.withConst()), |
| 1665 | std::make_pair(".copy_fn.", |
| 1666 | Context.getPointerType(CopyFnType).withConst()), |
| 1667 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1668 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1669 | }; |
| 1670 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1671 | Params); |
Alexey Bataev | 62b63b1 | 2015-03-10 07:28:44 +0000 | [diff] [blame] | 1672 | // Mark this captured region as inlined, because we don't use outlined |
| 1673 | // function directly. |
| 1674 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1675 | AlwaysInlineAttr::CreateImplicit( |
| 1676 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1677 | break; |
| 1678 | } |
Alexey Bataev | 1e73ef3 | 2016-04-28 12:14:51 +0000 | [diff] [blame] | 1679 | case OMPD_taskloop: |
| 1680 | case OMPD_taskloop_simd: { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1681 | QualType KmpInt32Ty = |
| 1682 | Context.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1); |
| 1683 | QualType KmpUInt64Ty = |
| 1684 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 1685 | QualType KmpInt64Ty = |
| 1686 | Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 1687 | QualType Args[] = {Context.VoidPtrTy.withConst().withRestrict()}; |
| 1688 | FunctionProtoType::ExtProtoInfo EPI; |
| 1689 | EPI.Variadic = true; |
| 1690 | QualType CopyFnType = Context.getFunctionType(Context.VoidTy, Args, EPI); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1691 | Sema::CapturedParamNameType Params[] = { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1692 | std::make_pair(".global_tid.", KmpInt32Ty), |
| 1693 | std::make_pair(".part_id.", Context.getPointerType(KmpInt32Ty)), |
| 1694 | std::make_pair(".privates.", |
| 1695 | Context.VoidPtrTy.withConst().withRestrict()), |
| 1696 | std::make_pair( |
| 1697 | ".copy_fn.", |
| 1698 | Context.getPointerType(CopyFnType).withConst().withRestrict()), |
| 1699 | std::make_pair(".task_t.", Context.VoidPtrTy.withConst()), |
| 1700 | std::make_pair(".lb.", KmpUInt64Ty), |
| 1701 | std::make_pair(".ub.", KmpUInt64Ty), std::make_pair(".st.", KmpInt64Ty), |
| 1702 | std::make_pair(".liter.", KmpInt32Ty), |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1703 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1704 | }; |
| 1705 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1706 | Params); |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 1707 | // Mark this captured region as inlined, because we don't use outlined |
| 1708 | // function directly. |
| 1709 | getCurCapturedRegion()->TheCapturedDecl->addAttr( |
| 1710 | AlwaysInlineAttr::CreateImplicit( |
| 1711 | Context, AlwaysInlineAttr::Keyword_forceinline, SourceRange())); |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | } |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1714 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1715 | case OMPD_distribute_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1716 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1717 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1718 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1719 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1720 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1721 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1722 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1723 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1724 | case OMPD_target_teams_distribute_simd: { |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1725 | QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1); |
| 1726 | QualType KmpInt32PtrTy = |
| 1727 | Context.getPointerType(KmpInt32Ty).withConst().withRestrict(); |
| 1728 | Sema::CapturedParamNameType Params[] = { |
| 1729 | std::make_pair(".global_tid.", KmpInt32PtrTy), |
| 1730 | std::make_pair(".bound_tid.", KmpInt32PtrTy), |
| 1731 | std::make_pair(".previous.lb.", Context.getSizeType()), |
| 1732 | std::make_pair(".previous.ub.", Context.getSizeType()), |
| 1733 | std::make_pair(StringRef(), QualType()) // __context with shared vars |
| 1734 | }; |
| 1735 | ActOnCapturedRegionStart(DSAStack->getConstructLoc(), CurScope, CR_OpenMP, |
| 1736 | Params); |
| 1737 | break; |
| 1738 | } |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1739 | case OMPD_threadprivate: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1740 | case OMPD_taskyield: |
| 1741 | case OMPD_barrier: |
| 1742 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1743 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1744 | case OMPD_cancel: |
Alexey Bataev | ee9af45 | 2014-11-21 11:33:46 +0000 | [diff] [blame] | 1745 | case OMPD_flush: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1746 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1747 | case OMPD_target_exit_data: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1748 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1749 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1750 | case OMPD_declare_target: |
| 1751 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1752 | case OMPD_target_update: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1753 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 1754 | case OMPD_unknown: |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1755 | llvm_unreachable("Unknown OpenMP directive"); |
| 1756 | } |
| 1757 | } |
| 1758 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1759 | int Sema::getOpenMPCaptureLevels(OpenMPDirectiveKind DKind) { |
| 1760 | SmallVector<OpenMPDirectiveKind, 4> CaptureRegions; |
| 1761 | getOpenMPCaptureRegions(CaptureRegions, DKind); |
| 1762 | return CaptureRegions.size(); |
| 1763 | } |
| 1764 | |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1765 | static OMPCapturedExprDecl *buildCaptureDecl(Sema &S, IdentifierInfo *Id, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1766 | Expr *CaptureExpr, bool WithInit, |
| 1767 | bool AsExpression) { |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1768 | assert(CaptureExpr); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1769 | ASTContext &C = S.getASTContext(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1770 | Expr *Init = AsExpression ? CaptureExpr : CaptureExpr->IgnoreImpCasts(); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1771 | QualType Ty = Init->getType(); |
| 1772 | if (CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue()) { |
| 1773 | if (S.getLangOpts().CPlusPlus) |
| 1774 | Ty = C.getLValueReferenceType(Ty); |
| 1775 | else { |
| 1776 | Ty = C.getPointerType(Ty); |
| 1777 | ExprResult Res = |
| 1778 | S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_AddrOf, Init); |
| 1779 | if (!Res.isUsable()) |
| 1780 | return nullptr; |
| 1781 | Init = Res.get(); |
| 1782 | } |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1783 | WithInit = true; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1784 | } |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 1785 | auto *CED = OMPCapturedExprDecl::Create(C, S.CurContext, Id, Ty, |
| 1786 | CaptureExpr->getLocStart()); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 1787 | if (!WithInit) |
| 1788 | CED->addAttr(OMPCaptureNoInitAttr::CreateImplicit(C, SourceRange())); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1789 | S.CurContext->addHiddenDecl(CED); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 1790 | S.AddInitializerToDecl(CED, Init, /*DirectInit=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1791 | return CED; |
| 1792 | } |
| 1793 | |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 1794 | static DeclRefExpr *buildCapture(Sema &S, ValueDecl *D, Expr *CaptureExpr, |
| 1795 | bool WithInit) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 1796 | OMPCapturedExprDecl *CD; |
| 1797 | if (auto *VD = S.IsOpenMPCapturedDecl(D)) |
| 1798 | CD = cast<OMPCapturedExprDecl>(VD); |
| 1799 | else |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1800 | CD = buildCaptureDecl(S, D->getIdentifier(), CaptureExpr, WithInit, |
| 1801 | /*AsExpression=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1802 | return buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 1803 | CaptureExpr->getExprLoc()); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 1806 | static ExprResult buildCapture(Sema &S, Expr *CaptureExpr, DeclRefExpr *&Ref) { |
| 1807 | if (!Ref) { |
| 1808 | auto *CD = |
| 1809 | buildCaptureDecl(S, &S.getASTContext().Idents.get(".capture_expr."), |
| 1810 | CaptureExpr, /*WithInit=*/true, /*AsExpression=*/true); |
| 1811 | Ref = buildDeclRefExpr(S, CD, CD->getType().getNonReferenceType(), |
| 1812 | CaptureExpr->getExprLoc()); |
| 1813 | } |
| 1814 | ExprResult Res = Ref; |
| 1815 | if (!S.getLangOpts().CPlusPlus && |
| 1816 | CaptureExpr->getObjectKind() == OK_Ordinary && CaptureExpr->isGLValue() && |
| 1817 | Ref->getType()->isPointerType()) |
| 1818 | Res = S.CreateBuiltinUnaryOp(CaptureExpr->getExprLoc(), UO_Deref, Ref); |
| 1819 | if (!Res.isUsable()) |
| 1820 | return ExprError(); |
| 1821 | return CaptureExpr->isGLValue() ? Res : S.DefaultLvalueConversion(Res.get()); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1824 | namespace { |
| 1825 | // OpenMP directives parsed in this section are represented as a |
| 1826 | // CapturedStatement with an associated statement. If a syntax error |
| 1827 | // is detected during the parsing of the associated statement, the |
| 1828 | // compiler must abort processing and close the CapturedStatement. |
| 1829 | // |
| 1830 | // Combined directives such as 'target parallel' have more than one |
| 1831 | // nested CapturedStatements. This RAII ensures that we unwind out |
| 1832 | // of all the nested CapturedStatements when an error is found. |
| 1833 | class CaptureRegionUnwinderRAII { |
| 1834 | private: |
| 1835 | Sema &S; |
| 1836 | bool &ErrorFound; |
| 1837 | OpenMPDirectiveKind DKind; |
| 1838 | |
| 1839 | public: |
| 1840 | CaptureRegionUnwinderRAII(Sema &S, bool &ErrorFound, |
| 1841 | OpenMPDirectiveKind DKind) |
| 1842 | : S(S), ErrorFound(ErrorFound), DKind(DKind) {} |
| 1843 | ~CaptureRegionUnwinderRAII() { |
| 1844 | if (ErrorFound) { |
| 1845 | int ThisCaptureLevel = S.getOpenMPCaptureLevels(DKind); |
| 1846 | while (--ThisCaptureLevel >= 0) |
| 1847 | S.ActOnCapturedRegionError(); |
| 1848 | } |
| 1849 | } |
| 1850 | }; |
| 1851 | } // namespace |
| 1852 | |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1853 | StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S, |
| 1854 | ArrayRef<OMPClause *> Clauses) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1855 | bool ErrorFound = false; |
| 1856 | CaptureRegionUnwinderRAII CaptureRegionUnwinder( |
| 1857 | *this, ErrorFound, DSAStack->getCurrentDirective()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1858 | if (!S.isUsable()) { |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1859 | ErrorFound = true; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1860 | return StmtError(); |
| 1861 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1862 | |
| 1863 | OMPOrderedClause *OC = nullptr; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1864 | OMPScheduleClause *SC = nullptr; |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1865 | SmallVector<OMPLinearClause *, 4> LCs; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1866 | // This is required for proper codegen. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1867 | for (auto *Clause : Clauses) { |
Alexey Bataev | 16dc7b6 | 2015-05-20 03:46:04 +0000 | [diff] [blame] | 1868 | if (isOpenMPPrivate(Clause->getClauseKind()) || |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1869 | Clause->getClauseKind() == OMPC_copyprivate || |
| 1870 | (getLangOpts().OpenMPUseTLS && |
| 1871 | getASTContext().getTargetInfo().isTLSSupported() && |
| 1872 | Clause->getClauseKind() == OMPC_copyin)) { |
| 1873 | DSAStack->setForceVarCapturing(Clause->getClauseKind() == OMPC_copyin); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1874 | // Mark all variables in private list clauses as used in inner region. |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1875 | for (auto *VarRef : Clause->children()) { |
| 1876 | if (auto *E = cast_or_null<Expr>(VarRef)) { |
Alexey Bataev | 8bf6b3e | 2015-04-02 13:07:08 +0000 | [diff] [blame] | 1877 | MarkDeclarationsReferencedInExpr(E); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
Samuel Antao | 9c75cfe | 2015-07-27 16:38:06 +0000 | [diff] [blame] | 1880 | DSAStack->setForceVarCapturing(/*V=*/false); |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1881 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective())) { |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 1882 | // Mark all variables in private list clauses as used in inner region. |
| 1883 | // Required for proper codegen of combined directives. |
| 1884 | // TODO: add processing for other clauses. |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1885 | if (auto *C = OMPClauseWithPreInit::get(Clause)) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1886 | if (auto *DS = cast_or_null<DeclStmt>(C->getPreInitStmt())) { |
| 1887 | for (auto *D : DS->decls()) |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 1888 | MarkVariableReferenced(D->getLocation(), cast<VarDecl>(D)); |
| 1889 | } |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 1890 | } |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 1891 | if (auto *C = OMPClauseWithPostUpdate::get(Clause)) { |
| 1892 | if (auto *E = C->getPostUpdateExpr()) |
| 1893 | MarkDeclarationsReferencedInExpr(E); |
| 1894 | } |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1895 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1896 | if (Clause->getClauseKind() == OMPC_schedule) |
| 1897 | SC = cast<OMPScheduleClause>(Clause); |
| 1898 | else if (Clause->getClauseKind() == OMPC_ordered) |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1899 | OC = cast<OMPOrderedClause>(Clause); |
| 1900 | else if (Clause->getClauseKind() == OMPC_linear) |
| 1901 | LCs.push_back(cast<OMPLinearClause>(Clause)); |
| 1902 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1903 | // OpenMP, 2.7.1 Loop Construct, Restrictions |
| 1904 | // The nonmonotonic modifier cannot be specified if an ordered clause is |
| 1905 | // specified. |
| 1906 | if (SC && |
| 1907 | (SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 1908 | SC->getSecondScheduleModifier() == |
| 1909 | OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 1910 | OC) { |
| 1911 | Diag(SC->getFirstScheduleModifier() == OMPC_SCHEDULE_MODIFIER_nonmonotonic |
| 1912 | ? SC->getFirstScheduleModifierLoc() |
| 1913 | : SC->getSecondScheduleModifierLoc(), |
| 1914 | diag::err_omp_schedule_nonmonotonic_ordered) |
| 1915 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1916 | ErrorFound = true; |
| 1917 | } |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1918 | if (!LCs.empty() && OC && OC->getNumForLoops()) { |
| 1919 | for (auto *C : LCs) { |
| 1920 | Diag(C->getLocStart(), diag::err_omp_linear_ordered) |
| 1921 | << SourceRange(OC->getLocStart(), OC->getLocEnd()); |
| 1922 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1923 | ErrorFound = true; |
| 1924 | } |
Alexey Bataev | 113438c | 2015-12-30 12:06:23 +0000 | [diff] [blame] | 1925 | if (isOpenMPWorksharingDirective(DSAStack->getCurrentDirective()) && |
| 1926 | isOpenMPSimdDirective(DSAStack->getCurrentDirective()) && OC && |
| 1927 | OC->getNumForLoops()) { |
| 1928 | Diag(OC->getLocStart(), diag::err_omp_ordered_simd) |
| 1929 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 1930 | ErrorFound = true; |
| 1931 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1932 | if (ErrorFound) { |
Alexey Bataev | 993d280 | 2015-12-28 06:23:08 +0000 | [diff] [blame] | 1933 | return StmtError(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1934 | } |
Arpith Chacko Jacob | 19b911c | 2017-01-18 18:18:53 +0000 | [diff] [blame] | 1935 | StmtResult SR = S; |
| 1936 | int ThisCaptureLevel = |
| 1937 | getOpenMPCaptureLevels(DSAStack->getCurrentDirective()); |
| 1938 | while (--ThisCaptureLevel >= 0) |
| 1939 | SR = ActOnCapturedRegionEnd(SR.get()); |
| 1940 | return SR; |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1941 | } |
| 1942 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1943 | static bool CheckNestingOfRegions(Sema &SemaRef, DSAStackTy *Stack, |
| 1944 | OpenMPDirectiveKind CurrentRegion, |
| 1945 | const DeclarationNameInfo &CurrentName, |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1946 | OpenMPDirectiveKind CancelRegion, |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1947 | SourceLocation StartLoc) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1948 | if (Stack->getCurScope()) { |
| 1949 | auto ParentRegion = Stack->getParentDirective(); |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 1950 | auto OffendingRegion = ParentRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1951 | bool NestingProhibited = false; |
| 1952 | bool CloseNesting = true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1953 | bool OrphanSeen = false; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1954 | enum { |
| 1955 | NoRecommend, |
| 1956 | ShouldBeInParallelRegion, |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1957 | ShouldBeInOrderedRegion, |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1958 | ShouldBeInTargetRegion, |
| 1959 | ShouldBeInTeamsRegion |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1960 | } Recommend = NoRecommend; |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1961 | if (isOpenMPSimdDirective(ParentRegion) && CurrentRegion != OMPD_ordered) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1962 | // OpenMP [2.16, Nesting of Regions] |
| 1963 | // OpenMP constructs may not be nested inside a simd region. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1964 | // OpenMP [2.8.1,simd Construct, Restrictions] |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1965 | // An ordered construct with the simd clause is the only OpenMP |
| 1966 | // construct that can appear in the simd region. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1967 | // Allowing a SIMD construct nested in another SIMD construct is an |
Kelvin Li | fd8b574 | 2016-07-01 14:30:25 +0000 | [diff] [blame] | 1968 | // extension. The OpenMP 4.5 spec does not allow it. Issue a warning |
| 1969 | // message. |
| 1970 | SemaRef.Diag(StartLoc, (CurrentRegion != OMPD_simd) |
| 1971 | ? diag::err_omp_prohibited_region_simd |
| 1972 | : diag::warn_omp_nesting_simd); |
| 1973 | return CurrentRegion != OMPD_simd; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 1974 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1975 | if (ParentRegion == OMPD_atomic) { |
| 1976 | // OpenMP [2.16, Nesting of Regions] |
| 1977 | // OpenMP constructs may not be nested inside an atomic region. |
| 1978 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region_atomic); |
| 1979 | return true; |
| 1980 | } |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1981 | if (CurrentRegion == OMPD_section) { |
| 1982 | // OpenMP [2.7.2, sections Construct, Restrictions] |
| 1983 | // Orphaned section directives are prohibited. That is, the section |
| 1984 | // directives must appear within the sections construct and must not be |
| 1985 | // encountered elsewhere in the sections region. |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1986 | if (ParentRegion != OMPD_sections && |
| 1987 | ParentRegion != OMPD_parallel_sections) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1988 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_section_directive) |
| 1989 | << (ParentRegion != OMPD_unknown) |
| 1990 | << getOpenMPDirectiveName(ParentRegion); |
| 1991 | return true; |
| 1992 | } |
| 1993 | return false; |
| 1994 | } |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 1995 | // Allow some constructs (except teams) to be orphaned (they could be |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 1996 | // used in functions, called from OpenMP regions with the required |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 1997 | // preconditions). |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1998 | if (ParentRegion == OMPD_unknown && |
| 1999 | !isOpenMPNestingTeamsDirective(CurrentRegion)) |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2000 | return false; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2001 | if (CurrentRegion == OMPD_cancellation_point || |
| 2002 | CurrentRegion == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2003 | // OpenMP [2.16, Nesting of Regions] |
| 2004 | // A cancellation point construct for which construct-type-clause is |
| 2005 | // taskgroup must be nested inside a task construct. A cancellation |
| 2006 | // point construct for which construct-type-clause is not taskgroup must |
| 2007 | // be closely nested inside an OpenMP construct that matches the type |
| 2008 | // specified in construct-type-clause. |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2009 | // A cancel construct for which construct-type-clause is taskgroup must be |
| 2010 | // nested inside a task construct. A cancel construct for which |
| 2011 | // construct-type-clause is not taskgroup must be closely nested inside an |
| 2012 | // OpenMP construct that matches the type specified in |
| 2013 | // construct-type-clause. |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2014 | NestingProhibited = |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2015 | !((CancelRegion == OMPD_parallel && |
| 2016 | (ParentRegion == OMPD_parallel || |
| 2017 | ParentRegion == OMPD_target_parallel)) || |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2018 | (CancelRegion == OMPD_for && |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2019 | (ParentRegion == OMPD_for || ParentRegion == OMPD_parallel_for || |
| 2020 | ParentRegion == OMPD_target_parallel_for)) || |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2021 | (CancelRegion == OMPD_taskgroup && ParentRegion == OMPD_task) || |
| 2022 | (CancelRegion == OMPD_sections && |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2023 | (ParentRegion == OMPD_section || ParentRegion == OMPD_sections || |
| 2024 | ParentRegion == OMPD_parallel_sections))); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2025 | } else if (CurrentRegion == OMPD_master) { |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2026 | // OpenMP [2.16, Nesting of Regions] |
| 2027 | // A master region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2028 | // atomic, or explicit task region. |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2029 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2030 | isOpenMPTaskingDirective(ParentRegion); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2031 | } else if (CurrentRegion == OMPD_critical && CurrentName.getName()) { |
| 2032 | // OpenMP [2.16, Nesting of Regions] |
| 2033 | // A critical region may not be nested (closely or otherwise) inside a |
| 2034 | // critical region with the same name. Note that this restriction is not |
| 2035 | // sufficient to prevent deadlock. |
| 2036 | SourceLocation PreviousCriticalLoc; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2037 | bool DeadLock = Stack->hasDirective( |
| 2038 | [CurrentName, &PreviousCriticalLoc](OpenMPDirectiveKind K, |
| 2039 | const DeclarationNameInfo &DNI, |
| 2040 | SourceLocation Loc) -> bool { |
| 2041 | if (K == OMPD_critical && DNI.getName() == CurrentName.getName()) { |
| 2042 | PreviousCriticalLoc = Loc; |
| 2043 | return true; |
| 2044 | } else |
| 2045 | return false; |
| 2046 | }, |
| 2047 | false /* skip top directive */); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2048 | if (DeadLock) { |
| 2049 | SemaRef.Diag(StartLoc, |
| 2050 | diag::err_omp_prohibited_region_critical_same_name) |
| 2051 | << CurrentName.getName(); |
| 2052 | if (PreviousCriticalLoc.isValid()) |
| 2053 | SemaRef.Diag(PreviousCriticalLoc, |
| 2054 | diag::note_omp_previous_critical_region); |
| 2055 | return true; |
| 2056 | } |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2057 | } else if (CurrentRegion == OMPD_barrier) { |
| 2058 | // OpenMP [2.16, Nesting of Regions] |
| 2059 | // A barrier region may not be closely nested inside a worksharing, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2060 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2061 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2062 | isOpenMPTaskingDirective(ParentRegion) || |
| 2063 | ParentRegion == OMPD_master || |
| 2064 | ParentRegion == OMPD_critical || |
| 2065 | ParentRegion == OMPD_ordered; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2066 | } else if (isOpenMPWorksharingDirective(CurrentRegion) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2067 | !isOpenMPParallelDirective(CurrentRegion) && |
| 2068 | !isOpenMPTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2069 | // OpenMP [2.16, Nesting of Regions] |
| 2070 | // A worksharing region may not be closely nested inside a worksharing, |
| 2071 | // explicit task, critical, ordered, atomic, or master region. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2072 | NestingProhibited = isOpenMPWorksharingDirective(ParentRegion) || |
| 2073 | isOpenMPTaskingDirective(ParentRegion) || |
| 2074 | ParentRegion == OMPD_master || |
| 2075 | ParentRegion == OMPD_critical || |
| 2076 | ParentRegion == OMPD_ordered; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2077 | Recommend = ShouldBeInParallelRegion; |
| 2078 | } else if (CurrentRegion == OMPD_ordered) { |
| 2079 | // OpenMP [2.16, Nesting of Regions] |
| 2080 | // An ordered region may not be closely nested inside a critical, |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2081 | // atomic, or explicit task region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2082 | // An ordered region must be closely nested inside a loop region (or |
| 2083 | // parallel loop region) with an ordered clause. |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2084 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 2085 | // An ordered construct with the simd clause is the only OpenMP construct |
| 2086 | // that can appear in the simd region. |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2087 | NestingProhibited = ParentRegion == OMPD_critical || |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 2088 | isOpenMPTaskingDirective(ParentRegion) || |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2089 | !(isOpenMPSimdDirective(ParentRegion) || |
| 2090 | Stack->isParentOrderedRegion()); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2091 | Recommend = ShouldBeInOrderedRegion; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2092 | } else if (isOpenMPNestingTeamsDirective(CurrentRegion)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2093 | // OpenMP [2.16, Nesting of Regions] |
| 2094 | // If specified, a teams construct must be contained within a target |
| 2095 | // construct. |
| 2096 | NestingProhibited = ParentRegion != OMPD_target; |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2097 | OrphanSeen = ParentRegion == OMPD_unknown; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2098 | Recommend = ShouldBeInTargetRegion; |
| 2099 | Stack->setParentTeamsRegionLoc(Stack->getConstructLoc()); |
| 2100 | } |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2101 | if (!NestingProhibited && |
| 2102 | !isOpenMPTargetExecutionDirective(CurrentRegion) && |
| 2103 | !isOpenMPTargetDataManagementDirective(CurrentRegion) && |
| 2104 | (ParentRegion == OMPD_teams || ParentRegion == OMPD_target_teams)) { |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2105 | // OpenMP [2.16, Nesting of Regions] |
| 2106 | // distribute, parallel, parallel sections, parallel workshare, and the |
| 2107 | // parallel loop and parallel loop SIMD constructs are the only OpenMP |
| 2108 | // constructs that can be closely nested in the teams region. |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2109 | NestingProhibited = !isOpenMPParallelDirective(CurrentRegion) && |
| 2110 | !isOpenMPDistributeDirective(CurrentRegion); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2111 | Recommend = ShouldBeInParallelRegion; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2112 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2113 | if (!NestingProhibited && |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2114 | isOpenMPNestingDistributeDirective(CurrentRegion)) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2115 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2116 | // The region associated with the distribute construct must be strictly |
| 2117 | // nested inside a teams region |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2118 | NestingProhibited = |
| 2119 | (ParentRegion != OMPD_teams && ParentRegion != OMPD_target_teams); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2120 | Recommend = ShouldBeInTeamsRegion; |
| 2121 | } |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2122 | if (!NestingProhibited && |
| 2123 | (isOpenMPTargetExecutionDirective(CurrentRegion) || |
| 2124 | isOpenMPTargetDataManagementDirective(CurrentRegion))) { |
| 2125 | // OpenMP 4.5 [2.17 Nesting of Regions] |
| 2126 | // If a target, target update, target data, target enter data, or |
| 2127 | // target exit data construct is encountered during execution of a |
| 2128 | // target region, the behavior is unspecified. |
| 2129 | NestingProhibited = Stack->hasDirective( |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 2130 | [&OffendingRegion](OpenMPDirectiveKind K, const DeclarationNameInfo &, |
| 2131 | SourceLocation) -> bool { |
Arpith Chacko Jacob | 3d58f26 | 2016-02-02 04:00:47 +0000 | [diff] [blame] | 2132 | if (isOpenMPTargetExecutionDirective(K)) { |
| 2133 | OffendingRegion = K; |
| 2134 | return true; |
| 2135 | } else |
| 2136 | return false; |
| 2137 | }, |
| 2138 | false /* don't skip top directive */); |
| 2139 | CloseNesting = false; |
| 2140 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2141 | if (NestingProhibited) { |
Kelvin Li | 2b51f72 | 2016-07-26 04:32:50 +0000 | [diff] [blame] | 2142 | if (OrphanSeen) { |
| 2143 | SemaRef.Diag(StartLoc, diag::err_omp_orphaned_device_directive) |
| 2144 | << getOpenMPDirectiveName(CurrentRegion) << Recommend; |
| 2145 | } else { |
| 2146 | SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region) |
| 2147 | << CloseNesting << getOpenMPDirectiveName(OffendingRegion) |
| 2148 | << Recommend << getOpenMPDirectiveName(CurrentRegion); |
| 2149 | } |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2150 | return true; |
| 2151 | } |
| 2152 | } |
| 2153 | return false; |
| 2154 | } |
| 2155 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2156 | static bool checkIfClauses(Sema &S, OpenMPDirectiveKind Kind, |
| 2157 | ArrayRef<OMPClause *> Clauses, |
| 2158 | ArrayRef<OpenMPDirectiveKind> AllowedNameModifiers) { |
| 2159 | bool ErrorFound = false; |
| 2160 | unsigned NamedModifiersNumber = 0; |
| 2161 | SmallVector<const OMPIfClause *, OMPC_unknown + 1> FoundNameModifiers( |
| 2162 | OMPD_unknown + 1); |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2163 | SmallVector<SourceLocation, 4> NameModifierLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2164 | for (const auto *C : Clauses) { |
| 2165 | if (const auto *IC = dyn_cast_or_null<OMPIfClause>(C)) { |
| 2166 | // At most one if clause without a directive-name-modifier can appear on |
| 2167 | // the directive. |
| 2168 | OpenMPDirectiveKind CurNM = IC->getNameModifier(); |
| 2169 | if (FoundNameModifiers[CurNM]) { |
| 2170 | S.Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 2171 | << getOpenMPDirectiveName(Kind) << getOpenMPClauseName(OMPC_if) |
| 2172 | << (CurNM != OMPD_unknown) << getOpenMPDirectiveName(CurNM); |
| 2173 | ErrorFound = true; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2174 | } else if (CurNM != OMPD_unknown) { |
| 2175 | NameModifierLoc.push_back(IC->getNameModifierLoc()); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2176 | ++NamedModifiersNumber; |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2177 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2178 | FoundNameModifiers[CurNM] = IC; |
| 2179 | if (CurNM == OMPD_unknown) |
| 2180 | continue; |
| 2181 | // Check if the specified name modifier is allowed for the current |
| 2182 | // directive. |
| 2183 | // At most one if clause with the particular directive-name-modifier can |
| 2184 | // appear on the directive. |
| 2185 | bool MatchFound = false; |
| 2186 | for (auto NM : AllowedNameModifiers) { |
| 2187 | if (CurNM == NM) { |
| 2188 | MatchFound = true; |
| 2189 | break; |
| 2190 | } |
| 2191 | } |
| 2192 | if (!MatchFound) { |
| 2193 | S.Diag(IC->getNameModifierLoc(), |
| 2194 | diag::err_omp_wrong_if_directive_name_modifier) |
| 2195 | << getOpenMPDirectiveName(CurNM) << getOpenMPDirectiveName(Kind); |
| 2196 | ErrorFound = true; |
| 2197 | } |
| 2198 | } |
| 2199 | } |
| 2200 | // If any if clause on the directive includes a directive-name-modifier then |
| 2201 | // all if clauses on the directive must include a directive-name-modifier. |
| 2202 | if (FoundNameModifiers[OMPD_unknown] && NamedModifiersNumber > 0) { |
| 2203 | if (NamedModifiersNumber == AllowedNameModifiers.size()) { |
| 2204 | S.Diag(FoundNameModifiers[OMPD_unknown]->getLocStart(), |
| 2205 | diag::err_omp_no_more_if_clause); |
| 2206 | } else { |
| 2207 | std::string Values; |
| 2208 | std::string Sep(", "); |
| 2209 | unsigned AllowedCnt = 0; |
| 2210 | unsigned TotalAllowedNum = |
| 2211 | AllowedNameModifiers.size() - NamedModifiersNumber; |
| 2212 | for (unsigned Cnt = 0, End = AllowedNameModifiers.size(); Cnt < End; |
| 2213 | ++Cnt) { |
| 2214 | OpenMPDirectiveKind NM = AllowedNameModifiers[Cnt]; |
| 2215 | if (!FoundNameModifiers[NM]) { |
| 2216 | Values += "'"; |
| 2217 | Values += getOpenMPDirectiveName(NM); |
| 2218 | Values += "'"; |
| 2219 | if (AllowedCnt + 2 == TotalAllowedNum) |
| 2220 | Values += " or "; |
| 2221 | else if (AllowedCnt + 1 != TotalAllowedNum) |
| 2222 | Values += Sep; |
| 2223 | ++AllowedCnt; |
| 2224 | } |
| 2225 | } |
| 2226 | S.Diag(FoundNameModifiers[OMPD_unknown]->getCondition()->getLocStart(), |
| 2227 | diag::err_omp_unnamed_if_clause) |
| 2228 | << (TotalAllowedNum > 1) << Values; |
| 2229 | } |
Alexey Bataev | ecb156a | 2015-09-15 17:23:56 +0000 | [diff] [blame] | 2230 | for (auto Loc : NameModifierLoc) { |
| 2231 | S.Diag(Loc, diag::note_omp_previous_named_if_clause); |
| 2232 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2233 | ErrorFound = true; |
| 2234 | } |
| 2235 | return ErrorFound; |
| 2236 | } |
| 2237 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2238 | StmtResult Sema::ActOnOpenMPExecutableDirective( |
| 2239 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 2240 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 2241 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2242 | StmtResult Res = StmtError(); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2243 | if (CheckNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion, |
| 2244 | StartLoc)) |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 2245 | return StmtError(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2246 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2247 | llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 2248 | llvm::DenseMap<ValueDecl *, Expr *> VarsWithInheritedDSA; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2249 | bool ErrorFound = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2250 | ClausesWithImplicit.append(Clauses.begin(), Clauses.end()); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2251 | if (AStmt) { |
| 2252 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 2253 | |
| 2254 | // Check default data sharing attributes for referenced variables. |
| 2255 | DSAAttrChecker DSAChecker(DSAStack, *this, cast<CapturedStmt>(AStmt)); |
| 2256 | DSAChecker.Visit(cast<CapturedStmt>(AStmt)->getCapturedStmt()); |
| 2257 | if (DSAChecker.isErrorFound()) |
| 2258 | return StmtError(); |
| 2259 | // Generate list of implicitly defined firstprivate variables. |
| 2260 | VarsWithInheritedDSA = DSAChecker.getVarsWithInheritedDSA(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2261 | |
| 2262 | if (!DSAChecker.getImplicitFirstprivate().empty()) { |
| 2263 | if (OMPClause *Implicit = ActOnOpenMPFirstprivateClause( |
| 2264 | DSAChecker.getImplicitFirstprivate(), SourceLocation(), |
| 2265 | SourceLocation(), SourceLocation())) { |
| 2266 | ClausesWithImplicit.push_back(Implicit); |
| 2267 | ErrorFound = cast<OMPFirstprivateClause>(Implicit)->varlist_size() != |
| 2268 | DSAChecker.getImplicitFirstprivate().size(); |
| 2269 | } else |
| 2270 | ErrorFound = true; |
| 2271 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2272 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2273 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2274 | llvm::SmallVector<OpenMPDirectiveKind, 4> AllowedNameModifiers; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2275 | switch (Kind) { |
| 2276 | case OMPD_parallel: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2277 | Res = ActOnOpenMPParallelDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2278 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2279 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2280 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2281 | case OMPD_simd: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2282 | Res = ActOnOpenMPSimdDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2283 | VarsWithInheritedDSA); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 2284 | break; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2285 | case OMPD_for: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2286 | Res = ActOnOpenMPForDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc, |
| 2287 | VarsWithInheritedDSA); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 2288 | break; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 2289 | case OMPD_for_simd: |
| 2290 | Res = ActOnOpenMPForSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2291 | EndLoc, VarsWithInheritedDSA); |
| 2292 | break; |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 2293 | case OMPD_sections: |
| 2294 | Res = ActOnOpenMPSectionsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2295 | EndLoc); |
| 2296 | break; |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2297 | case OMPD_section: |
| 2298 | assert(ClausesWithImplicit.empty() && |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2299 | "No clauses are allowed for 'omp section' directive"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 2300 | Res = ActOnOpenMPSectionDirective(AStmt, StartLoc, EndLoc); |
| 2301 | break; |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 2302 | case OMPD_single: |
| 2303 | Res = ActOnOpenMPSingleDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2304 | EndLoc); |
| 2305 | break; |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 2306 | case OMPD_master: |
| 2307 | assert(ClausesWithImplicit.empty() && |
| 2308 | "No clauses are allowed for 'omp master' directive"); |
| 2309 | Res = ActOnOpenMPMasterDirective(AStmt, StartLoc, EndLoc); |
| 2310 | break; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2311 | case OMPD_critical: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2312 | Res = ActOnOpenMPCriticalDirective(DirName, ClausesWithImplicit, AStmt, |
| 2313 | StartLoc, EndLoc); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 2314 | break; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2315 | case OMPD_parallel_for: |
| 2316 | Res = ActOnOpenMPParallelForDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2317 | EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2318 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2319 | break; |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2320 | case OMPD_parallel_for_simd: |
| 2321 | Res = ActOnOpenMPParallelForSimdDirective( |
| 2322 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2323 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2324 | break; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2325 | case OMPD_parallel_sections: |
| 2326 | Res = ActOnOpenMPParallelSectionsDirective(ClausesWithImplicit, AStmt, |
| 2327 | StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2328 | AllowedNameModifiers.push_back(OMPD_parallel); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2329 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2330 | case OMPD_task: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2331 | Res = |
| 2332 | ActOnOpenMPTaskDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2333 | AllowedNameModifiers.push_back(OMPD_task); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2334 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2335 | case OMPD_taskyield: |
| 2336 | assert(ClausesWithImplicit.empty() && |
| 2337 | "No clauses are allowed for 'omp taskyield' directive"); |
| 2338 | assert(AStmt == nullptr && |
| 2339 | "No associated statement allowed for 'omp taskyield' directive"); |
| 2340 | Res = ActOnOpenMPTaskyieldDirective(StartLoc, EndLoc); |
| 2341 | break; |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2342 | case OMPD_barrier: |
| 2343 | assert(ClausesWithImplicit.empty() && |
| 2344 | "No clauses are allowed for 'omp barrier' directive"); |
| 2345 | assert(AStmt == nullptr && |
| 2346 | "No associated statement allowed for 'omp barrier' directive"); |
| 2347 | Res = ActOnOpenMPBarrierDirective(StartLoc, EndLoc); |
| 2348 | break; |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2349 | case OMPD_taskwait: |
| 2350 | assert(ClausesWithImplicit.empty() && |
| 2351 | "No clauses are allowed for 'omp taskwait' directive"); |
| 2352 | assert(AStmt == nullptr && |
| 2353 | "No associated statement allowed for 'omp taskwait' directive"); |
| 2354 | Res = ActOnOpenMPTaskwaitDirective(StartLoc, EndLoc); |
| 2355 | break; |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2356 | case OMPD_taskgroup: |
| 2357 | assert(ClausesWithImplicit.empty() && |
| 2358 | "No clauses are allowed for 'omp taskgroup' directive"); |
| 2359 | Res = ActOnOpenMPTaskgroupDirective(AStmt, StartLoc, EndLoc); |
| 2360 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2361 | case OMPD_flush: |
| 2362 | assert(AStmt == nullptr && |
| 2363 | "No associated statement allowed for 'omp flush' directive"); |
| 2364 | Res = ActOnOpenMPFlushDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2365 | break; |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2366 | case OMPD_ordered: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2367 | Res = ActOnOpenMPOrderedDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2368 | EndLoc); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2369 | break; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2370 | case OMPD_atomic: |
| 2371 | Res = ActOnOpenMPAtomicDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2372 | EndLoc); |
| 2373 | break; |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2374 | case OMPD_teams: |
| 2375 | Res = |
| 2376 | ActOnOpenMPTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, EndLoc); |
| 2377 | break; |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2378 | case OMPD_target: |
| 2379 | Res = ActOnOpenMPTargetDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2380 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2381 | AllowedNameModifiers.push_back(OMPD_target); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2382 | break; |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 2383 | case OMPD_target_parallel: |
| 2384 | Res = ActOnOpenMPTargetParallelDirective(ClausesWithImplicit, AStmt, |
| 2385 | StartLoc, EndLoc); |
| 2386 | AllowedNameModifiers.push_back(OMPD_target); |
| 2387 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2388 | break; |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 2389 | case OMPD_target_parallel_for: |
| 2390 | Res = ActOnOpenMPTargetParallelForDirective( |
| 2391 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2392 | AllowedNameModifiers.push_back(OMPD_target); |
| 2393 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2394 | break; |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2395 | case OMPD_cancellation_point: |
| 2396 | assert(ClausesWithImplicit.empty() && |
| 2397 | "No clauses are allowed for 'omp cancellation point' directive"); |
| 2398 | assert(AStmt == nullptr && "No associated statement allowed for 'omp " |
| 2399 | "cancellation point' directive"); |
| 2400 | Res = ActOnOpenMPCancellationPointDirective(StartLoc, EndLoc, CancelRegion); |
| 2401 | break; |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2402 | case OMPD_cancel: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2403 | assert(AStmt == nullptr && |
| 2404 | "No associated statement allowed for 'omp cancel' directive"); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 2405 | Res = ActOnOpenMPCancelDirective(ClausesWithImplicit, StartLoc, EndLoc, |
| 2406 | CancelRegion); |
| 2407 | AllowedNameModifiers.push_back(OMPD_cancel); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2408 | break; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2409 | case OMPD_target_data: |
| 2410 | Res = ActOnOpenMPTargetDataDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2411 | EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2412 | AllowedNameModifiers.push_back(OMPD_target_data); |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2413 | break; |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 2414 | case OMPD_target_enter_data: |
| 2415 | Res = ActOnOpenMPTargetEnterDataDirective(ClausesWithImplicit, StartLoc, |
| 2416 | EndLoc); |
| 2417 | AllowedNameModifiers.push_back(OMPD_target_enter_data); |
| 2418 | break; |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 2419 | case OMPD_target_exit_data: |
| 2420 | Res = ActOnOpenMPTargetExitDataDirective(ClausesWithImplicit, StartLoc, |
| 2421 | EndLoc); |
| 2422 | AllowedNameModifiers.push_back(OMPD_target_exit_data); |
| 2423 | break; |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 2424 | case OMPD_taskloop: |
| 2425 | Res = ActOnOpenMPTaskLoopDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2426 | EndLoc, VarsWithInheritedDSA); |
| 2427 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2428 | break; |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 2429 | case OMPD_taskloop_simd: |
| 2430 | Res = ActOnOpenMPTaskLoopSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2431 | EndLoc, VarsWithInheritedDSA); |
| 2432 | AllowedNameModifiers.push_back(OMPD_taskloop); |
| 2433 | break; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 2434 | case OMPD_distribute: |
| 2435 | Res = ActOnOpenMPDistributeDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2436 | EndLoc, VarsWithInheritedDSA); |
| 2437 | break; |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 2438 | case OMPD_target_update: |
| 2439 | assert(!AStmt && "Statement is not allowed for target update"); |
| 2440 | Res = |
| 2441 | ActOnOpenMPTargetUpdateDirective(ClausesWithImplicit, StartLoc, EndLoc); |
| 2442 | AllowedNameModifiers.push_back(OMPD_target_update); |
| 2443 | break; |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 2444 | case OMPD_distribute_parallel_for: |
| 2445 | Res = ActOnOpenMPDistributeParallelForDirective( |
| 2446 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2447 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2448 | break; |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 2449 | case OMPD_distribute_parallel_for_simd: |
| 2450 | Res = ActOnOpenMPDistributeParallelForSimdDirective( |
| 2451 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2452 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2453 | break; |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 2454 | case OMPD_distribute_simd: |
| 2455 | Res = ActOnOpenMPDistributeSimdDirective( |
| 2456 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2457 | break; |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 2458 | case OMPD_target_parallel_for_simd: |
| 2459 | Res = ActOnOpenMPTargetParallelForSimdDirective( |
| 2460 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2461 | AllowedNameModifiers.push_back(OMPD_target); |
| 2462 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2463 | break; |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 2464 | case OMPD_target_simd: |
| 2465 | Res = ActOnOpenMPTargetSimdDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2466 | EndLoc, VarsWithInheritedDSA); |
| 2467 | AllowedNameModifiers.push_back(OMPD_target); |
| 2468 | break; |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2469 | case OMPD_teams_distribute: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2470 | Res = ActOnOpenMPTeamsDistributeDirective( |
| 2471 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 2472 | break; |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 2473 | case OMPD_teams_distribute_simd: |
| 2474 | Res = ActOnOpenMPTeamsDistributeSimdDirective( |
| 2475 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2476 | break; |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 2477 | case OMPD_teams_distribute_parallel_for_simd: |
| 2478 | Res = ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 2479 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2480 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2481 | break; |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 2482 | case OMPD_teams_distribute_parallel_for: |
| 2483 | Res = ActOnOpenMPTeamsDistributeParallelForDirective( |
| 2484 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2485 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2486 | break; |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 2487 | case OMPD_target_teams: |
| 2488 | Res = ActOnOpenMPTargetTeamsDirective(ClausesWithImplicit, AStmt, StartLoc, |
| 2489 | EndLoc); |
| 2490 | AllowedNameModifiers.push_back(OMPD_target); |
| 2491 | break; |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 2492 | case OMPD_target_teams_distribute: |
| 2493 | Res = ActOnOpenMPTargetTeamsDistributeDirective( |
| 2494 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2495 | AllowedNameModifiers.push_back(OMPD_target); |
| 2496 | break; |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 2497 | case OMPD_target_teams_distribute_parallel_for: |
| 2498 | Res = ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 2499 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2500 | AllowedNameModifiers.push_back(OMPD_target); |
| 2501 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2502 | break; |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 2503 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 2504 | Res = ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 2505 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2506 | AllowedNameModifiers.push_back(OMPD_target); |
| 2507 | AllowedNameModifiers.push_back(OMPD_parallel); |
| 2508 | break; |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 2509 | case OMPD_target_teams_distribute_simd: |
| 2510 | Res = ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 2511 | ClausesWithImplicit, AStmt, StartLoc, EndLoc, VarsWithInheritedDSA); |
| 2512 | AllowedNameModifiers.push_back(OMPD_target); |
| 2513 | break; |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 2514 | case OMPD_declare_target: |
| 2515 | case OMPD_end_declare_target: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2516 | case OMPD_threadprivate: |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2517 | case OMPD_declare_reduction: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2518 | case OMPD_declare_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2519 | llvm_unreachable("OpenMP Directive is not allowed"); |
| 2520 | case OMPD_unknown: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2521 | llvm_unreachable("Unknown OpenMP directive"); |
| 2522 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2523 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2524 | for (auto P : VarsWithInheritedDSA) { |
| 2525 | Diag(P.second->getExprLoc(), diag::err_omp_no_dsa_for_variable) |
| 2526 | << P.first << P.second->getSourceRange(); |
| 2527 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2528 | ErrorFound = !VarsWithInheritedDSA.empty() || ErrorFound; |
| 2529 | |
| 2530 | if (!AllowedNameModifiers.empty()) |
| 2531 | ErrorFound = checkIfClauses(*this, Kind, Clauses, AllowedNameModifiers) || |
| 2532 | ErrorFound; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 2533 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 2534 | if (ErrorFound) |
| 2535 | return StmtError(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2536 | return Res; |
| 2537 | } |
| 2538 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2539 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareSimdDirective( |
| 2540 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, Expr *Simdlen, |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2541 | ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2542 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 2543 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2544 | assert(Aligneds.size() == Alignments.size()); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2545 | assert(Linears.size() == LinModifiers.size()); |
| 2546 | assert(Linears.size() == Steps.size()); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2547 | if (!DG || DG.get().isNull()) |
| 2548 | return DeclGroupPtrTy(); |
| 2549 | |
| 2550 | if (!DG.get().isSingleDecl()) { |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 2551 | Diag(SR.getBegin(), diag::err_omp_single_decl_in_declare_simd); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2552 | return DG; |
| 2553 | } |
| 2554 | auto *ADecl = DG.get().getSingleDecl(); |
| 2555 | if (auto *FTD = dyn_cast<FunctionTemplateDecl>(ADecl)) |
| 2556 | ADecl = FTD->getTemplatedDecl(); |
| 2557 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2558 | auto *FD = dyn_cast<FunctionDecl>(ADecl); |
| 2559 | if (!FD) { |
| 2560 | Diag(ADecl->getLocation(), diag::err_omp_function_expected); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2561 | return DeclGroupPtrTy(); |
| 2562 | } |
| 2563 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2564 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2565 | // The parameter of the simdlen clause must be a constant positive integer |
| 2566 | // expression. |
| 2567 | ExprResult SL; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2568 | if (Simdlen) |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2569 | SL = VerifyPositiveIntegerConstantInClause(Simdlen, OMPC_simdlen); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2570 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2571 | // The special this pointer can be used as if was one of the arguments to the |
| 2572 | // function in any of the linear, aligned, or uniform clauses. |
| 2573 | // The uniform clause declares one or more arguments to have an invariant |
| 2574 | // value for all concurrent invocations of the function in the execution of a |
| 2575 | // single SIMD loop. |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2576 | llvm::DenseMap<Decl *, Expr *> UniformedArgs; |
| 2577 | Expr *UniformedLinearThis = nullptr; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2578 | for (auto *E : Uniforms) { |
| 2579 | E = E->IgnoreParenImpCasts(); |
| 2580 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2581 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) |
| 2582 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2583 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2584 | ->getCanonicalDecl() == PVD->getCanonicalDecl()) { |
| 2585 | UniformedArgs.insert(std::make_pair(PVD->getCanonicalDecl(), E)); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2586 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2587 | } |
| 2588 | if (isa<CXXThisExpr>(E)) { |
| 2589 | UniformedLinearThis = E; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2590 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2591 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2592 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2593 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2594 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2595 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2596 | // The aligned clause declares that the object to which each list item points |
| 2597 | // is aligned to the number of bytes expressed in the optional parameter of |
| 2598 | // the aligned clause. |
| 2599 | // The special this pointer can be used as if was one of the arguments to the |
| 2600 | // function in any of the linear, aligned, or uniform clauses. |
| 2601 | // The type of list items appearing in the aligned clause must be array, |
| 2602 | // pointer, reference to array, or reference to pointer. |
| 2603 | llvm::DenseMap<Decl *, Expr *> AlignedArgs; |
| 2604 | Expr *AlignedThis = nullptr; |
| 2605 | for (auto *E : Aligneds) { |
| 2606 | E = E->IgnoreParenImpCasts(); |
| 2607 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2608 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2609 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2610 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2611 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2612 | ->getCanonicalDecl() == CanonPVD) { |
| 2613 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 2614 | // A list-item cannot appear in more than one aligned clause. |
| 2615 | if (AlignedArgs.count(CanonPVD) > 0) { |
| 2616 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2617 | << 1 << E->getSourceRange(); |
| 2618 | Diag(AlignedArgs[CanonPVD]->getExprLoc(), |
| 2619 | diag::note_omp_explicit_dsa) |
| 2620 | << getOpenMPClauseName(OMPC_aligned); |
| 2621 | continue; |
| 2622 | } |
| 2623 | AlignedArgs[CanonPVD] = E; |
| 2624 | QualType QTy = PVD->getType() |
| 2625 | .getNonReferenceType() |
| 2626 | .getUnqualifiedType() |
| 2627 | .getCanonicalType(); |
| 2628 | const Type *Ty = QTy.getTypePtrOrNull(); |
| 2629 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
| 2630 | Diag(E->getExprLoc(), diag::err_omp_aligned_expected_array_or_ptr) |
| 2631 | << QTy << getLangOpts().CPlusPlus << E->getSourceRange(); |
| 2632 | Diag(PVD->getLocation(), diag::note_previous_decl) << PVD; |
| 2633 | } |
| 2634 | continue; |
| 2635 | } |
| 2636 | } |
| 2637 | if (isa<CXXThisExpr>(E)) { |
| 2638 | if (AlignedThis) { |
| 2639 | Diag(E->getExprLoc(), diag::err_omp_aligned_twice) |
| 2640 | << 2 << E->getSourceRange(); |
| 2641 | Diag(AlignedThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2642 | << getOpenMPClauseName(OMPC_aligned); |
| 2643 | } |
| 2644 | AlignedThis = E; |
| 2645 | continue; |
| 2646 | } |
| 2647 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2648 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2649 | } |
| 2650 | // The optional parameter of the aligned clause, alignment, must be a constant |
| 2651 | // positive integer expression. If no optional parameter is specified, |
| 2652 | // implementation-defined default alignments for SIMD instructions on the |
| 2653 | // target platforms are assumed. |
| 2654 | SmallVector<Expr *, 4> NewAligns; |
| 2655 | for (auto *E : Alignments) { |
| 2656 | ExprResult Align; |
| 2657 | if (E) |
| 2658 | Align = VerifyPositiveIntegerConstantInClause(E, OMPC_aligned); |
| 2659 | NewAligns.push_back(Align.get()); |
| 2660 | } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2661 | // OpenMP [2.8.2, declare simd construct, Description] |
| 2662 | // The linear clause declares one or more list items to be private to a SIMD |
| 2663 | // lane and to have a linear relationship with respect to the iteration space |
| 2664 | // of a loop. |
| 2665 | // The special this pointer can be used as if was one of the arguments to the |
| 2666 | // function in any of the linear, aligned, or uniform clauses. |
| 2667 | // When a linear-step expression is specified in a linear clause it must be |
| 2668 | // either a constant integer expression or an integer-typed parameter that is |
| 2669 | // specified in a uniform clause on the directive. |
| 2670 | llvm::DenseMap<Decl *, Expr *> LinearArgs; |
| 2671 | const bool IsUniformedThis = UniformedLinearThis != nullptr; |
| 2672 | auto MI = LinModifiers.begin(); |
| 2673 | for (auto *E : Linears) { |
| 2674 | auto LinKind = static_cast<OpenMPLinearClauseKind>(*MI); |
| 2675 | ++MI; |
| 2676 | E = E->IgnoreParenImpCasts(); |
| 2677 | if (auto *DRE = dyn_cast<DeclRefExpr>(E)) |
| 2678 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2679 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2680 | if (FD->getNumParams() > PVD->getFunctionScopeIndex() && |
| 2681 | FD->getParamDecl(PVD->getFunctionScopeIndex()) |
| 2682 | ->getCanonicalDecl() == CanonPVD) { |
| 2683 | // OpenMP [2.15.3.7, linear Clause, Restrictions] |
| 2684 | // A list-item cannot appear in more than one linear clause. |
| 2685 | if (LinearArgs.count(CanonPVD) > 0) { |
| 2686 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2687 | << getOpenMPClauseName(OMPC_linear) |
| 2688 | << getOpenMPClauseName(OMPC_linear) << E->getSourceRange(); |
| 2689 | Diag(LinearArgs[CanonPVD]->getExprLoc(), |
| 2690 | diag::note_omp_explicit_dsa) |
| 2691 | << getOpenMPClauseName(OMPC_linear); |
| 2692 | continue; |
| 2693 | } |
| 2694 | // Each argument can appear in at most one uniform or linear clause. |
| 2695 | if (UniformedArgs.count(CanonPVD) > 0) { |
| 2696 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2697 | << getOpenMPClauseName(OMPC_linear) |
| 2698 | << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange(); |
| 2699 | Diag(UniformedArgs[CanonPVD]->getExprLoc(), |
| 2700 | diag::note_omp_explicit_dsa) |
| 2701 | << getOpenMPClauseName(OMPC_uniform); |
| 2702 | continue; |
| 2703 | } |
| 2704 | LinearArgs[CanonPVD] = E; |
| 2705 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2706 | E->isInstantiationDependent() || |
| 2707 | E->containsUnexpandedParameterPack()) |
| 2708 | continue; |
| 2709 | (void)CheckOpenMPLinearDecl(CanonPVD, E->getExprLoc(), LinKind, |
| 2710 | PVD->getOriginalType()); |
| 2711 | continue; |
| 2712 | } |
| 2713 | } |
| 2714 | if (isa<CXXThisExpr>(E)) { |
| 2715 | if (UniformedLinearThis) { |
| 2716 | Diag(E->getExprLoc(), diag::err_omp_wrong_dsa) |
| 2717 | << getOpenMPClauseName(OMPC_linear) |
| 2718 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform : OMPC_linear) |
| 2719 | << E->getSourceRange(); |
| 2720 | Diag(UniformedLinearThis->getExprLoc(), diag::note_omp_explicit_dsa) |
| 2721 | << getOpenMPClauseName(IsUniformedThis ? OMPC_uniform |
| 2722 | : OMPC_linear); |
| 2723 | continue; |
| 2724 | } |
| 2725 | UniformedLinearThis = E; |
| 2726 | if (E->isValueDependent() || E->isTypeDependent() || |
| 2727 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
| 2728 | continue; |
| 2729 | (void)CheckOpenMPLinearDecl(/*D=*/nullptr, E->getExprLoc(), LinKind, |
| 2730 | E->getType()); |
| 2731 | continue; |
| 2732 | } |
| 2733 | Diag(E->getExprLoc(), diag::err_omp_param_or_this_in_clause) |
| 2734 | << FD->getDeclName() << (isa<CXXMethodDecl>(ADecl) ? 1 : 0); |
| 2735 | } |
| 2736 | Expr *Step = nullptr; |
| 2737 | Expr *NewStep = nullptr; |
| 2738 | SmallVector<Expr *, 4> NewSteps; |
| 2739 | for (auto *E : Steps) { |
| 2740 | // Skip the same step expression, it was checked already. |
| 2741 | if (Step == E || !E) { |
| 2742 | NewSteps.push_back(E ? NewStep : nullptr); |
| 2743 | continue; |
| 2744 | } |
| 2745 | Step = E; |
| 2746 | if (auto *DRE = dyn_cast<DeclRefExpr>(Step)) |
| 2747 | if (auto *PVD = dyn_cast<ParmVarDecl>(DRE->getDecl())) { |
| 2748 | auto *CanonPVD = PVD->getCanonicalDecl(); |
| 2749 | if (UniformedArgs.count(CanonPVD) == 0) { |
| 2750 | Diag(Step->getExprLoc(), diag::err_omp_expected_uniform_param) |
| 2751 | << Step->getSourceRange(); |
| 2752 | } else if (E->isValueDependent() || E->isTypeDependent() || |
| 2753 | E->isInstantiationDependent() || |
| 2754 | E->containsUnexpandedParameterPack() || |
| 2755 | CanonPVD->getType()->hasIntegerRepresentation()) |
| 2756 | NewSteps.push_back(Step); |
| 2757 | else { |
| 2758 | Diag(Step->getExprLoc(), diag::err_omp_expected_int_param) |
| 2759 | << Step->getSourceRange(); |
| 2760 | } |
| 2761 | continue; |
| 2762 | } |
| 2763 | NewStep = Step; |
| 2764 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 2765 | !Step->isInstantiationDependent() && |
| 2766 | !Step->containsUnexpandedParameterPack()) { |
| 2767 | NewStep = PerformOpenMPImplicitIntegerConversion(Step->getExprLoc(), Step) |
| 2768 | .get(); |
| 2769 | if (NewStep) |
| 2770 | NewStep = VerifyIntegerConstantExpression(NewStep).get(); |
| 2771 | } |
| 2772 | NewSteps.push_back(NewStep); |
| 2773 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2774 | auto *NewAttr = OMPDeclareSimdDeclAttr::CreateImplicit( |
| 2775 | Context, BS, SL.get(), const_cast<Expr **>(Uniforms.data()), |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 2776 | Uniforms.size(), const_cast<Expr **>(Aligneds.data()), Aligneds.size(), |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 2777 | const_cast<Expr **>(NewAligns.data()), NewAligns.size(), |
| 2778 | const_cast<Expr **>(Linears.data()), Linears.size(), |
| 2779 | const_cast<unsigned *>(LinModifiers.data()), LinModifiers.size(), |
| 2780 | NewSteps.data(), NewSteps.size(), SR); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 2781 | ADecl->addAttr(NewAttr); |
| 2782 | return ConvertDeclToDeclGroup(ADecl); |
| 2783 | } |
| 2784 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2785 | StmtResult Sema::ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 2786 | Stmt *AStmt, |
| 2787 | SourceLocation StartLoc, |
| 2788 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2789 | if (!AStmt) |
| 2790 | return StmtError(); |
| 2791 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 2792 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 2793 | // 1.2.2 OpenMP Language Terminology |
| 2794 | // Structured block - An executable statement with a single entry at the |
| 2795 | // top and a single exit at the bottom. |
| 2796 | // The point of exit cannot be a branch out of the structured block. |
| 2797 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 2798 | CS->getCapturedDecl()->setNothrow(); |
| 2799 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2800 | getCurFunction()->setHasBranchProtectedScope(); |
| 2801 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 2802 | return OMPParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 2803 | DSAStack->isCancelRegion()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2804 | } |
| 2805 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2806 | namespace { |
| 2807 | /// \brief Helper class for checking canonical form of the OpenMP loops and |
| 2808 | /// extracting iteration space of each loop in the loop nest, that will be used |
| 2809 | /// for IR generation. |
| 2810 | class OpenMPIterationSpaceChecker { |
| 2811 | /// \brief Reference to Sema. |
| 2812 | Sema &SemaRef; |
| 2813 | /// \brief A location for diagnostics (when there is no some better location). |
| 2814 | SourceLocation DefaultLoc; |
| 2815 | /// \brief A location for diagnostics (when increment is not compatible). |
| 2816 | SourceLocation ConditionLoc; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2817 | /// \brief A source location for referring to loop init later. |
| 2818 | SourceRange InitSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2819 | /// \brief A source location for referring to condition later. |
| 2820 | SourceRange ConditionSrcRange; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2821 | /// \brief A source location for referring to increment later. |
| 2822 | SourceRange IncrementSrcRange; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2823 | /// \brief Loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2824 | ValueDecl *LCDecl = nullptr; |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2825 | /// \brief Reference to loop variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2826 | Expr *LCRef = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2827 | /// \brief Lower bound (initializer for the var). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2828 | Expr *LB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2829 | /// \brief Upper bound. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2830 | Expr *UB = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2831 | /// \brief Loop step (increment). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2832 | Expr *Step = nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2833 | /// \brief This flag is true when condition is one of: |
| 2834 | /// Var < UB |
| 2835 | /// Var <= UB |
| 2836 | /// UB > Var |
| 2837 | /// UB >= Var |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2838 | bool TestIsLessOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2839 | /// \brief This flag is true when condition is strict ( < or > ). |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2840 | bool TestIsStrictOp = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2841 | /// \brief This flag is true when step is subtracted on each iteration. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2842 | bool SubtractStep = false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2843 | |
| 2844 | public: |
| 2845 | OpenMPIterationSpaceChecker(Sema &SemaRef, SourceLocation DefaultLoc) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2846 | : SemaRef(SemaRef), DefaultLoc(DefaultLoc), ConditionLoc(DefaultLoc) {} |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2847 | /// \brief Check init-expr for canonical loop form and save loop counter |
| 2848 | /// variable - #Var and its initialization value - #LB. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 2849 | bool CheckInit(Stmt *S, bool EmitDiags = true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2850 | /// \brief Check test-expr for canonical form, save upper-bound (#UB), flags |
| 2851 | /// for less/greater and for strict/non-strict comparison. |
| 2852 | bool CheckCond(Expr *S); |
| 2853 | /// \brief Check incr-expr for canonical loop form and return true if it |
| 2854 | /// does not conform, otherwise save loop step (#Step). |
| 2855 | bool CheckInc(Expr *S); |
| 2856 | /// \brief Return the loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2857 | ValueDecl *GetLoopDecl() const { return LCDecl; } |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2858 | /// \brief Return the reference expression to loop counter variable. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2859 | Expr *GetLoopDeclRefExpr() const { return LCRef; } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2860 | /// \brief Source range of the loop init. |
| 2861 | SourceRange GetInitSrcRange() const { return InitSrcRange; } |
| 2862 | /// \brief Source range of the loop condition. |
| 2863 | SourceRange GetConditionSrcRange() const { return ConditionSrcRange; } |
| 2864 | /// \brief Source range of the loop increment. |
| 2865 | SourceRange GetIncrementSrcRange() const { return IncrementSrcRange; } |
| 2866 | /// \brief True if the step should be subtracted. |
| 2867 | bool ShouldSubtractStep() const { return SubtractStep; } |
| 2868 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2869 | Expr * |
| 2870 | BuildNumIterations(Scope *S, const bool LimitedType, |
| 2871 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 2872 | /// \brief Build the precondition expression for the loops. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 2873 | Expr *BuildPreCond(Scope *S, Expr *Cond, |
| 2874 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2875 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 2876 | DeclRefExpr *BuildCounterVar(llvm::MapVector<Expr *, DeclRefExpr *> &Captures, |
| 2877 | DSAStackTy &DSA) const; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 2878 | /// \brief Build reference expression to the private counter be used for |
| 2879 | /// codegen. |
| 2880 | Expr *BuildPrivateCounterVar() const; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 2881 | /// \brief Build initialization of the counter be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2882 | Expr *BuildCounterInit() const; |
| 2883 | /// \brief Build step of the counter be used for codegen. |
| 2884 | Expr *BuildCounterStep() const; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2885 | /// \brief Return true if any expression is dependent. |
| 2886 | bool Dependent() const; |
| 2887 | |
| 2888 | private: |
| 2889 | /// \brief Check the right-hand side of an assignment in the increment |
| 2890 | /// expression. |
| 2891 | bool CheckIncRHS(Expr *RHS); |
| 2892 | /// \brief Helper to set loop counter variable and its initializer. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2893 | bool SetLCDeclAndLB(ValueDecl *NewLCDecl, Expr *NewDeclRefExpr, Expr *NewLB); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2894 | /// \brief Helper to set upper bound. |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2895 | bool SetUB(Expr *NewUB, bool LessOp, bool StrictOp, SourceRange SR, |
Craig Topper | 9cd5e4f | 2015-09-21 01:23:32 +0000 | [diff] [blame] | 2896 | SourceLocation SL); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2897 | /// \brief Helper to set loop increment. |
| 2898 | bool SetStep(Expr *NewStep, bool Subtract); |
| 2899 | }; |
| 2900 | |
| 2901 | bool OpenMPIterationSpaceChecker::Dependent() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2902 | if (!LCDecl) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2903 | assert(!LB && !UB && !Step); |
| 2904 | return false; |
| 2905 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2906 | return LCDecl->getType()->isDependentType() || |
| 2907 | (LB && LB->isValueDependent()) || (UB && UB->isValueDependent()) || |
| 2908 | (Step && Step->isValueDependent()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2909 | } |
| 2910 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2911 | static Expr *getExprAsWritten(Expr *E) { |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2912 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(E)) |
| 2913 | E = ExprTemp->getSubExpr(); |
| 2914 | |
| 2915 | if (auto *MTE = dyn_cast<MaterializeTemporaryExpr>(E)) |
| 2916 | E = MTE->GetTemporaryExpr(); |
| 2917 | |
| 2918 | while (auto *Binder = dyn_cast<CXXBindTemporaryExpr>(E)) |
| 2919 | E = Binder->getSubExpr(); |
| 2920 | |
| 2921 | if (auto *ICE = dyn_cast<ImplicitCastExpr>(E)) |
| 2922 | E = ICE->getSubExprAsWritten(); |
| 2923 | return E->IgnoreParens(); |
| 2924 | } |
| 2925 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2926 | bool OpenMPIterationSpaceChecker::SetLCDeclAndLB(ValueDecl *NewLCDecl, |
| 2927 | Expr *NewLCRefExpr, |
| 2928 | Expr *NewLB) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2929 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2930 | assert(LCDecl == nullptr && LB == nullptr && LCRef == nullptr && |
Alexey Bataev | caf09b0 | 2014-07-25 06:27:47 +0000 | [diff] [blame] | 2931 | UB == nullptr && Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2932 | if (!NewLCDecl || !NewLB) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2933 | return true; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2934 | LCDecl = getCanonicalDecl(NewLCDecl); |
| 2935 | LCRef = NewLCRefExpr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2936 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(NewLB)) |
| 2937 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 2938 | if ((Ctor->isCopyOrMoveConstructor() || |
| 2939 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 2940 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 2941 | NewLB = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2942 | LB = NewLB; |
| 2943 | return false; |
| 2944 | } |
| 2945 | |
| 2946 | bool OpenMPIterationSpaceChecker::SetUB(Expr *NewUB, bool LessOp, bool StrictOp, |
Craig Topper | e335f25 | 2015-10-04 04:53:55 +0000 | [diff] [blame] | 2947 | SourceRange SR, SourceLocation SL) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2948 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2949 | assert(LCDecl != nullptr && LB != nullptr && UB == nullptr && |
| 2950 | Step == nullptr && !TestIsLessOp && !TestIsStrictOp); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2951 | if (!NewUB) |
| 2952 | return true; |
| 2953 | UB = NewUB; |
| 2954 | TestIsLessOp = LessOp; |
| 2955 | TestIsStrictOp = StrictOp; |
| 2956 | ConditionSrcRange = SR; |
| 2957 | ConditionLoc = SL; |
| 2958 | return false; |
| 2959 | } |
| 2960 | |
| 2961 | bool OpenMPIterationSpaceChecker::SetStep(Expr *NewStep, bool Subtract) { |
| 2962 | // State consistency checking to ensure correct usage. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2963 | assert(LCDecl != nullptr && LB != nullptr && Step == nullptr); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2964 | if (!NewStep) |
| 2965 | return true; |
| 2966 | if (!NewStep->isValueDependent()) { |
| 2967 | // Check that the step is integer expression. |
| 2968 | SourceLocation StepLoc = NewStep->getLocStart(); |
| 2969 | ExprResult Val = |
| 2970 | SemaRef.PerformOpenMPImplicitIntegerConversion(StepLoc, NewStep); |
| 2971 | if (Val.isInvalid()) |
| 2972 | return true; |
| 2973 | NewStep = Val.get(); |
| 2974 | |
| 2975 | // OpenMP [2.6, Canonical Loop Form, Restrictions] |
| 2976 | // If test-expr is of form var relational-op b and relational-op is < or |
| 2977 | // <= then incr-expr must cause var to increase on each iteration of the |
| 2978 | // loop. If test-expr is of form var relational-op b and relational-op is |
| 2979 | // > or >= then incr-expr must cause var to decrease on each iteration of |
| 2980 | // the loop. |
| 2981 | // If test-expr is of form b relational-op var and relational-op is < or |
| 2982 | // <= then incr-expr must cause var to decrease on each iteration of the |
| 2983 | // loop. If test-expr is of form b relational-op var and relational-op is |
| 2984 | // > or >= then incr-expr must cause var to increase on each iteration of |
| 2985 | // the loop. |
| 2986 | llvm::APSInt Result; |
| 2987 | bool IsConstant = NewStep->isIntegerConstantExpr(Result, SemaRef.Context); |
| 2988 | bool IsUnsigned = !NewStep->getType()->hasSignedIntegerRepresentation(); |
| 2989 | bool IsConstNeg = |
| 2990 | IsConstant && Result.isSigned() && (Subtract != Result.isNegative()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2991 | bool IsConstPos = |
| 2992 | IsConstant && Result.isSigned() && (Subtract == Result.isNegative()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2993 | bool IsConstZero = IsConstant && !Result.getBoolValue(); |
| 2994 | if (UB && (IsConstZero || |
| 2995 | (TestIsLessOp ? (IsConstNeg || (IsUnsigned && Subtract)) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 2996 | : (IsConstPos || (IsUnsigned && !Subtract))))) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 2997 | SemaRef.Diag(NewStep->getExprLoc(), |
| 2998 | diag::err_omp_loop_incr_not_compatible) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 2999 | << LCDecl << TestIsLessOp << NewStep->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3000 | SemaRef.Diag(ConditionLoc, |
| 3001 | diag::note_omp_loop_cond_requres_compatible_incr) |
| 3002 | << TestIsLessOp << ConditionSrcRange; |
| 3003 | return true; |
| 3004 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3005 | if (TestIsLessOp == Subtract) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3006 | NewStep = |
| 3007 | SemaRef.CreateBuiltinUnaryOp(NewStep->getExprLoc(), UO_Minus, NewStep) |
| 3008 | .get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3009 | Subtract = !Subtract; |
| 3010 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | Step = NewStep; |
| 3014 | SubtractStep = Subtract; |
| 3015 | return false; |
| 3016 | } |
| 3017 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3018 | bool OpenMPIterationSpaceChecker::CheckInit(Stmt *S, bool EmitDiags) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3019 | // Check init-expr for canonical loop form and save loop counter |
| 3020 | // variable - #Var and its initialization value - #LB. |
| 3021 | // OpenMP [2.6] Canonical loop form. init-expr may be one of the following: |
| 3022 | // var = lb |
| 3023 | // integer-type var = lb |
| 3024 | // random-access-iterator-type var = lb |
| 3025 | // pointer-type var = lb |
| 3026 | // |
| 3027 | if (!S) { |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3028 | if (EmitDiags) { |
| 3029 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_init); |
| 3030 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3031 | return true; |
| 3032 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3033 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3034 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3035 | S = ExprTemp->getSubExpr(); |
| 3036 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3037 | InitSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3038 | if (Expr *E = dyn_cast<Expr>(S)) |
| 3039 | S = E->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3040 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3041 | if (BO->getOpcode() == BO_Assign) { |
| 3042 | auto *LHS = BO->getLHS()->IgnoreParens(); |
| 3043 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
| 3044 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3045 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3046 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3047 | return SetLCDeclAndLB(DRE->getDecl(), DRE, BO->getRHS()); |
| 3048 | } |
| 3049 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3050 | if (ME->isArrow() && |
| 3051 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3052 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3053 | } |
| 3054 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3055 | } else if (auto *DS = dyn_cast<DeclStmt>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3056 | if (DS->isSingleDecl()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3057 | if (auto *Var = dyn_cast_or_null<VarDecl>(DS->getSingleDecl())) { |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3058 | if (Var->hasInit() && !Var->getType()->isReferenceType()) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3059 | // Accept non-canonical init form here but emit ext. warning. |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3060 | if (Var->getInitStyle() != VarDecl::CInit && EmitDiags) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3061 | SemaRef.Diag(S->getLocStart(), |
| 3062 | diag::ext_omp_loop_not_canonical_init) |
| 3063 | << S->getSourceRange(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3064 | return SetLCDeclAndLB(Var, nullptr, Var->getInit()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3065 | } |
| 3066 | } |
| 3067 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3068 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3069 | if (CE->getOperator() == OO_Equal) { |
| 3070 | auto *LHS = CE->getArg(0); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3071 | if (auto *DRE = dyn_cast<DeclRefExpr>(LHS)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3072 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(DRE->getDecl())) |
| 3073 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3074 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3075 | return SetLCDeclAndLB(DRE->getDecl(), DRE, CE->getArg(1)); |
| 3076 | } |
| 3077 | if (auto *ME = dyn_cast<MemberExpr>(LHS)) { |
| 3078 | if (ME->isArrow() && |
| 3079 | isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3080 | return SetLCDeclAndLB(ME->getMemberDecl(), ME, BO->getRHS()); |
| 3081 | } |
| 3082 | } |
| 3083 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3084 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3085 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3086 | return false; |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3087 | if (EmitDiags) { |
| 3088 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_init) |
| 3089 | << S->getSourceRange(); |
| 3090 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3091 | return true; |
| 3092 | } |
| 3093 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3094 | /// \brief Ignore parenthesizes, implicit casts, copy constructor and return the |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3095 | /// variable (which may be the loop variable) if possible. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3096 | static const ValueDecl *GetInitLCDecl(Expr *E) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3097 | if (!E) |
Craig Topper | 4b56692 | 2014-06-09 02:04:02 +0000 | [diff] [blame] | 3098 | return nullptr; |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3099 | E = getExprAsWritten(E); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3100 | if (auto *CE = dyn_cast_or_null<CXXConstructExpr>(E)) |
| 3101 | if (const CXXConstructorDecl *Ctor = CE->getConstructor()) |
Alexey Bataev | 0d08a7f | 2015-07-16 04:19:43 +0000 | [diff] [blame] | 3102 | if ((Ctor->isCopyOrMoveConstructor() || |
| 3103 | Ctor->isConvertingConstructor(/*AllowExplicit=*/false)) && |
| 3104 | CE->getNumArgs() > 0 && CE->getArg(0) != nullptr) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3105 | E = CE->getArg(0)->IgnoreParenImpCasts(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3106 | if (auto *DRE = dyn_cast_or_null<DeclRefExpr>(E)) { |
| 3107 | if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl())) { |
| 3108 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(VD)) |
| 3109 | if (auto *ME = dyn_cast<MemberExpr>(getExprAsWritten(CED->getInit()))) |
| 3110 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3111 | return getCanonicalDecl(VD); |
| 3112 | } |
| 3113 | } |
| 3114 | if (auto *ME = dyn_cast_or_null<MemberExpr>(E)) |
| 3115 | if (ME->isArrow() && isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts())) |
| 3116 | return getCanonicalDecl(ME->getMemberDecl()); |
| 3117 | return nullptr; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | bool OpenMPIterationSpaceChecker::CheckCond(Expr *S) { |
| 3121 | // Check test-expr for canonical form, save upper-bound UB, flags for |
| 3122 | // less/greater and for strict/non-strict comparison. |
| 3123 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3124 | // var relational-op b |
| 3125 | // b relational-op var |
| 3126 | // |
| 3127 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3128 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_cond) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3129 | return true; |
| 3130 | } |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3131 | S = getExprAsWritten(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3132 | SourceLocation CondLoc = S->getLocStart(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3133 | if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3134 | if (BO->isRelationalOp()) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3135 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3136 | return SetUB(BO->getRHS(), |
| 3137 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_LE), |
| 3138 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3139 | BO->getSourceRange(), BO->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3140 | if (GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3141 | return SetUB(BO->getLHS(), |
| 3142 | (BO->getOpcode() == BO_GT || BO->getOpcode() == BO_GE), |
| 3143 | (BO->getOpcode() == BO_LT || BO->getOpcode() == BO_GT), |
| 3144 | BO->getSourceRange(), BO->getOperatorLoc()); |
| 3145 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3146 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3147 | if (CE->getNumArgs() == 2) { |
| 3148 | auto Op = CE->getOperator(); |
| 3149 | switch (Op) { |
| 3150 | case OO_Greater: |
| 3151 | case OO_GreaterEqual: |
| 3152 | case OO_Less: |
| 3153 | case OO_LessEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3154 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3155 | return SetUB(CE->getArg(1), Op == OO_Less || Op == OO_LessEqual, |
| 3156 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3157 | CE->getOperatorLoc()); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3158 | if (GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3159 | return SetUB(CE->getArg(0), Op == OO_Greater || Op == OO_GreaterEqual, |
| 3160 | Op == OO_Less || Op == OO_Greater, CE->getSourceRange(), |
| 3161 | CE->getOperatorLoc()); |
| 3162 | break; |
| 3163 | default: |
| 3164 | break; |
| 3165 | } |
| 3166 | } |
| 3167 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3168 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3169 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3170 | SemaRef.Diag(CondLoc, diag::err_omp_loop_not_canonical_cond) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3171 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3172 | return true; |
| 3173 | } |
| 3174 | |
| 3175 | bool OpenMPIterationSpaceChecker::CheckIncRHS(Expr *RHS) { |
| 3176 | // RHS of canonical loop form increment can be: |
| 3177 | // var + incr |
| 3178 | // incr + var |
| 3179 | // var - incr |
| 3180 | // |
| 3181 | RHS = RHS->IgnoreParenImpCasts(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3182 | if (auto *BO = dyn_cast<BinaryOperator>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3183 | if (BO->isAdditiveOp()) { |
| 3184 | bool IsAdd = BO->getOpcode() == BO_Add; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3185 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3186 | return SetStep(BO->getRHS(), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3187 | if (IsAdd && GetInitLCDecl(BO->getRHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3188 | return SetStep(BO->getLHS(), false); |
| 3189 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3190 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(RHS)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3191 | bool IsAdd = CE->getOperator() == OO_Plus; |
| 3192 | if ((IsAdd || CE->getOperator() == OO_Minus) && CE->getNumArgs() == 2) { |
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 SetStep(CE->getArg(1), !IsAdd); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3195 | if (IsAdd && GetInitLCDecl(CE->getArg(1)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3196 | return SetStep(CE->getArg(0), false); |
| 3197 | } |
| 3198 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3199 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3200 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3201 | SemaRef.Diag(RHS->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3202 | << RHS->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3203 | return true; |
| 3204 | } |
| 3205 | |
| 3206 | bool OpenMPIterationSpaceChecker::CheckInc(Expr *S) { |
| 3207 | // Check incr-expr for canonical loop form and return true if it |
| 3208 | // does not conform. |
| 3209 | // OpenMP [2.6] Canonical loop form. Test-expr may be one of the following: |
| 3210 | // ++var |
| 3211 | // var++ |
| 3212 | // --var |
| 3213 | // var-- |
| 3214 | // var += incr |
| 3215 | // var -= incr |
| 3216 | // var = var + incr |
| 3217 | // var = incr + var |
| 3218 | // var = var - incr |
| 3219 | // |
| 3220 | if (!S) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3221 | SemaRef.Diag(DefaultLoc, diag::err_omp_loop_not_canonical_incr) << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3222 | return true; |
| 3223 | } |
Tim Shen | 4a05bb8 | 2016-06-21 20:29:17 +0000 | [diff] [blame] | 3224 | if (auto *ExprTemp = dyn_cast<ExprWithCleanups>(S)) |
| 3225 | if (!ExprTemp->cleanupsHaveSideEffects()) |
| 3226 | S = ExprTemp->getSubExpr(); |
| 3227 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3228 | IncrementSrcRange = S->getSourceRange(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3229 | S = S->IgnoreParens(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3230 | if (auto *UO = dyn_cast<UnaryOperator>(S)) { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3231 | if (UO->isIncrementDecrementOp() && |
| 3232 | GetInitLCDecl(UO->getSubExpr()) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3233 | return SetStep(SemaRef |
| 3234 | .ActOnIntegerConstant(UO->getLocStart(), |
| 3235 | (UO->isDecrementOp() ? -1 : 1)) |
| 3236 | .get(), |
| 3237 | false); |
| 3238 | } else if (auto *BO = dyn_cast<BinaryOperator>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3239 | switch (BO->getOpcode()) { |
| 3240 | case BO_AddAssign: |
| 3241 | case BO_SubAssign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3242 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3243 | return SetStep(BO->getRHS(), BO->getOpcode() == BO_SubAssign); |
| 3244 | break; |
| 3245 | case BO_Assign: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3246 | if (GetInitLCDecl(BO->getLHS()) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3247 | return CheckIncRHS(BO->getRHS()); |
| 3248 | break; |
| 3249 | default: |
| 3250 | break; |
| 3251 | } |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3252 | } else if (auto *CE = dyn_cast<CXXOperatorCallExpr>(S)) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3253 | switch (CE->getOperator()) { |
| 3254 | case OO_PlusPlus: |
| 3255 | case OO_MinusMinus: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3256 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3257 | return SetStep(SemaRef |
| 3258 | .ActOnIntegerConstant( |
| 3259 | CE->getLocStart(), |
| 3260 | ((CE->getOperator() == OO_MinusMinus) ? -1 : 1)) |
| 3261 | .get(), |
| 3262 | false); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3263 | break; |
| 3264 | case OO_PlusEqual: |
| 3265 | case OO_MinusEqual: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3266 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3267 | return SetStep(CE->getArg(1), CE->getOperator() == OO_MinusEqual); |
| 3268 | break; |
| 3269 | case OO_Equal: |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3270 | if (GetInitLCDecl(CE->getArg(0)) == LCDecl) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3271 | return CheckIncRHS(CE->getArg(1)); |
| 3272 | break; |
| 3273 | default: |
| 3274 | break; |
| 3275 | } |
| 3276 | } |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3277 | if (Dependent() || SemaRef.CurContext->isDependentContext()) |
| 3278 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3279 | SemaRef.Diag(S->getLocStart(), diag::err_omp_loop_not_canonical_incr) |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3280 | << S->getSourceRange() << LCDecl; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3281 | return true; |
| 3282 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3283 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3284 | static ExprResult |
| 3285 | tryBuildCapture(Sema &SemaRef, Expr *Capture, |
| 3286 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 3287 | if (SemaRef.CurContext->isDependentContext()) |
| 3288 | return ExprResult(Capture); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3289 | if (Capture->isEvaluatable(SemaRef.Context, Expr::SE_AllowSideEffects)) |
| 3290 | return SemaRef.PerformImplicitConversion( |
| 3291 | Capture->IgnoreImpCasts(), Capture->getType(), Sema::AA_Converting, |
| 3292 | /*AllowExplicit=*/true); |
| 3293 | auto I = Captures.find(Capture); |
| 3294 | if (I != Captures.end()) |
| 3295 | return buildCapture(SemaRef, Capture, I->second); |
| 3296 | DeclRefExpr *Ref = nullptr; |
| 3297 | ExprResult Res = buildCapture(SemaRef, Capture, Ref); |
| 3298 | Captures[Capture] = Ref; |
| 3299 | return Res; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3300 | } |
| 3301 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3302 | /// \brief Build the expression to calculate the number of iterations. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3303 | Expr *OpenMPIterationSpaceChecker::BuildNumIterations( |
| 3304 | Scope *S, const bool LimitedType, |
| 3305 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3306 | ExprResult Diff; |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3307 | auto VarType = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3308 | if (VarType->isIntegerType() || VarType->isPointerType() || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3309 | SemaRef.getLangOpts().CPlusPlus) { |
| 3310 | // Upper - Lower |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3311 | auto *UBExpr = TestIsLessOp ? UB : LB; |
| 3312 | auto *LBExpr = TestIsLessOp ? LB : UB; |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3313 | Expr *Upper = tryBuildCapture(SemaRef, UBExpr, Captures).get(); |
| 3314 | Expr *Lower = tryBuildCapture(SemaRef, LBExpr, Captures).get(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3315 | if (!Upper || !Lower) |
| 3316 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3317 | |
| 3318 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Sub, Upper, Lower); |
| 3319 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3320 | if (!Diff.isUsable() && VarType->getAsCXXRecordDecl()) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3321 | // BuildBinOp already emitted error, this one is to point user to upper |
| 3322 | // and lower bound, and to tell what is passed to 'operator-'. |
| 3323 | SemaRef.Diag(Upper->getLocStart(), diag::err_omp_loop_diff_cxx) |
| 3324 | << Upper->getSourceRange() << Lower->getSourceRange(); |
| 3325 | return nullptr; |
| 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | if (!Diff.isUsable()) |
| 3330 | return nullptr; |
| 3331 | |
| 3332 | // Upper - Lower [- 1] |
| 3333 | if (TestIsStrictOp) |
| 3334 | Diff = SemaRef.BuildBinOp( |
| 3335 | S, DefaultLoc, BO_Sub, Diff.get(), |
| 3336 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 3337 | if (!Diff.isUsable()) |
| 3338 | return nullptr; |
| 3339 | |
| 3340 | // Upper - Lower [- 1] + Step |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3341 | auto NewStep = tryBuildCapture(SemaRef, Step, Captures); |
| 3342 | if (!NewStep.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3343 | return nullptr; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3344 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Add, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3345 | if (!Diff.isUsable()) |
| 3346 | return nullptr; |
| 3347 | |
| 3348 | // Parentheses (for dumping/debugging purposes only). |
| 3349 | Diff = SemaRef.ActOnParenExpr(DefaultLoc, DefaultLoc, Diff.get()); |
| 3350 | if (!Diff.isUsable()) |
| 3351 | return nullptr; |
| 3352 | |
| 3353 | // (Upper - Lower [- 1] + Step) / Step |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3354 | Diff = SemaRef.BuildBinOp(S, DefaultLoc, BO_Div, Diff.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3355 | if (!Diff.isUsable()) |
| 3356 | return nullptr; |
| 3357 | |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3358 | // OpenMP runtime requires 32-bit or 64-bit loop variables. |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3359 | QualType Type = Diff.get()->getType(); |
| 3360 | auto &C = SemaRef.Context; |
| 3361 | bool UseVarType = VarType->hasIntegerRepresentation() && |
| 3362 | C.getTypeSize(Type) > C.getTypeSize(VarType); |
| 3363 | if (!Type->isIntegerType() || UseVarType) { |
| 3364 | unsigned NewSize = |
| 3365 | UseVarType ? C.getTypeSize(VarType) : C.getTypeSize(Type); |
| 3366 | bool IsSigned = UseVarType ? VarType->hasSignedIntegerRepresentation() |
| 3367 | : Type->hasSignedIntegerRepresentation(); |
| 3368 | Type = C.getIntTypeForBitwidth(NewSize, IsSigned); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3369 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), Type)) { |
| 3370 | Diff = SemaRef.PerformImplicitConversion( |
| 3371 | Diff.get(), Type, Sema::AA_Converting, /*AllowExplicit=*/true); |
| 3372 | if (!Diff.isUsable()) |
| 3373 | return nullptr; |
| 3374 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3375 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3376 | if (LimitedType) { |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3377 | unsigned NewSize = (C.getTypeSize(Type) > 32) ? 64 : 32; |
| 3378 | if (NewSize != C.getTypeSize(Type)) { |
| 3379 | if (NewSize < C.getTypeSize(Type)) { |
| 3380 | assert(NewSize == 64 && "incorrect loop var size"); |
| 3381 | SemaRef.Diag(DefaultLoc, diag::warn_omp_loop_64_bit_var) |
| 3382 | << InitSrcRange << ConditionSrcRange; |
| 3383 | } |
| 3384 | QualType NewType = C.getIntTypeForBitwidth( |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3385 | NewSize, Type->hasSignedIntegerRepresentation() || |
| 3386 | C.getTypeSize(Type) < NewSize); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3387 | if (!SemaRef.Context.hasSameType(Diff.get()->getType(), NewType)) { |
| 3388 | Diff = SemaRef.PerformImplicitConversion(Diff.get(), NewType, |
| 3389 | Sema::AA_Converting, true); |
| 3390 | if (!Diff.isUsable()) |
| 3391 | return nullptr; |
| 3392 | } |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3393 | } |
| 3394 | } |
| 3395 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3396 | return Diff.get(); |
| 3397 | } |
| 3398 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3399 | Expr *OpenMPIterationSpaceChecker::BuildPreCond( |
| 3400 | Scope *S, Expr *Cond, |
| 3401 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) const { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3402 | // Try to build LB <op> UB, where <op> is <, >, <=, or >=. |
| 3403 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3404 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3405 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3406 | auto NewLB = tryBuildCapture(SemaRef, LB, Captures); |
| 3407 | auto NewUB = tryBuildCapture(SemaRef, UB, Captures); |
| 3408 | if (!NewLB.isUsable() || !NewUB.isUsable()) |
| 3409 | return nullptr; |
| 3410 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3411 | auto CondExpr = SemaRef.BuildBinOp( |
| 3412 | S, DefaultLoc, TestIsLessOp ? (TestIsStrictOp ? BO_LT : BO_LE) |
| 3413 | : (TestIsStrictOp ? BO_GT : BO_GE), |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3414 | NewLB.get(), NewUB.get()); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3415 | if (CondExpr.isUsable()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3416 | if (!SemaRef.Context.hasSameUnqualifiedType(CondExpr.get()->getType(), |
| 3417 | SemaRef.Context.BoolTy)) |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3418 | CondExpr = SemaRef.PerformImplicitConversion( |
| 3419 | CondExpr.get(), SemaRef.Context.BoolTy, /*Action=*/Sema::AA_Casting, |
| 3420 | /*AllowExplicit=*/true); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 3421 | } |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3422 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3423 | // Otherwise use original loop conditon and evaluate it in runtime. |
| 3424 | return CondExpr.isUsable() ? CondExpr.get() : Cond; |
| 3425 | } |
| 3426 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3427 | /// \brief Build reference expression to the counter be used for codegen. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3428 | DeclRefExpr *OpenMPIterationSpaceChecker::BuildCounterVar( |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3429 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures, DSAStackTy &DSA) const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3430 | auto *VD = dyn_cast<VarDecl>(LCDecl); |
| 3431 | if (!VD) { |
| 3432 | VD = SemaRef.IsOpenMPCapturedDecl(LCDecl); |
| 3433 | auto *Ref = buildDeclRefExpr( |
| 3434 | SemaRef, VD, VD->getType().getNonReferenceType(), DefaultLoc); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3435 | DSAStackTy::DSAVarData Data = DSA.getTopDSA(LCDecl, /*FromParent=*/false); |
| 3436 | // If the loop control decl is explicitly marked as private, do not mark it |
| 3437 | // as captured again. |
| 3438 | if (!isOpenMPPrivate(Data.CKind) || !Data.RefExpr) |
| 3439 | Captures.insert(std::make_pair(LCRef, Ref)); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3440 | return Ref; |
| 3441 | } |
| 3442 | return buildDeclRefExpr(SemaRef, VD, VD->getType().getNonReferenceType(), |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3443 | DefaultLoc); |
| 3444 | } |
| 3445 | |
| 3446 | Expr *OpenMPIterationSpaceChecker::BuildPrivateCounterVar() const { |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3447 | if (LCDecl && !LCDecl->isInvalidDecl()) { |
| 3448 | auto Type = LCDecl->getType().getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 3449 | auto *PrivateVar = |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3450 | buildVarDecl(SemaRef, DefaultLoc, Type, LCDecl->getName(), |
| 3451 | LCDecl->hasAttrs() ? &LCDecl->getAttrs() : nullptr); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3452 | if (PrivateVar->isInvalidDecl()) |
| 3453 | return nullptr; |
| 3454 | return buildDeclRefExpr(SemaRef, PrivateVar, Type, DefaultLoc); |
| 3455 | } |
| 3456 | return nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3457 | } |
| 3458 | |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 3459 | /// \brief Build initialization of the counter to be used for codegen. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3460 | Expr *OpenMPIterationSpaceChecker::BuildCounterInit() const { return LB; } |
| 3461 | |
| 3462 | /// \brief Build step of the counter be used for codegen. |
| 3463 | Expr *OpenMPIterationSpaceChecker::BuildCounterStep() const { return Step; } |
| 3464 | |
| 3465 | /// \brief Iteration space of a single for loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3466 | struct LoopIterationSpace final { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3467 | /// \brief Condition of the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3468 | Expr *PreCond = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3469 | /// \brief This expression calculates the number of iterations in the loop. |
| 3470 | /// It is always possible to calculate it before starting the loop. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3471 | Expr *NumIterations = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3472 | /// \brief The loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3473 | Expr *CounterVar = nullptr; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3474 | /// \brief Private loop counter variable. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3475 | Expr *PrivateCounterVar = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3476 | /// \brief This is initializer for the initial value of #CounterVar. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3477 | Expr *CounterInit = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3478 | /// \brief This is step for the #CounterVar used to generate its update: |
| 3479 | /// #CounterVar = #CounterInit + #CounterStep * CurrentIteration. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3480 | Expr *CounterStep = nullptr; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3481 | /// \brief Should step be subtracted? |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 3482 | bool Subtract = false; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3483 | /// \brief Source range of the loop init. |
| 3484 | SourceRange InitSrcRange; |
| 3485 | /// \brief Source range of the loop condition. |
| 3486 | SourceRange CondSrcRange; |
| 3487 | /// \brief Source range of the loop increment. |
| 3488 | SourceRange IncSrcRange; |
| 3489 | }; |
| 3490 | |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 3491 | } // namespace |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3492 | |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3493 | void Sema::ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init) { |
| 3494 | assert(getLangOpts().OpenMP && "OpenMP is not active."); |
| 3495 | assert(Init && "Expected loop in canonical form."); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3496 | unsigned AssociatedLoops = DSAStack->getAssociatedLoops(); |
| 3497 | if (AssociatedLoops > 0 && |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3498 | isOpenMPLoopDirective(DSAStack->getCurrentDirective())) { |
| 3499 | OpenMPIterationSpaceChecker ISC(*this, ForLoc); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3500 | if (!ISC.CheckInit(Init, /*EmitDiags=*/false)) { |
| 3501 | if (auto *D = ISC.GetLoopDecl()) { |
| 3502 | auto *VD = dyn_cast<VarDecl>(D); |
| 3503 | if (!VD) { |
| 3504 | if (auto *Private = IsOpenMPCapturedDecl(D)) |
| 3505 | VD = Private; |
| 3506 | else { |
| 3507 | auto *Ref = buildCapture(*this, D, ISC.GetLoopDeclRefExpr(), |
| 3508 | /*WithInit=*/false); |
| 3509 | VD = cast<VarDecl>(Ref->getDecl()); |
| 3510 | } |
| 3511 | } |
| 3512 | DSAStack->addLoopControlVariable(D, VD); |
| 3513 | } |
| 3514 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 3515 | DSAStack->setAssociatedLoops(AssociatedLoops - 1); |
Alexey Bataev | 9c82103 | 2015-04-30 04:23:23 +0000 | [diff] [blame] | 3516 | } |
| 3517 | } |
| 3518 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3519 | /// \brief Called on a for stmt to check and extract its iteration space |
| 3520 | /// for further processing (such as collapsing). |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3521 | static bool CheckOpenMPIterationSpace( |
| 3522 | OpenMPDirectiveKind DKind, Stmt *S, Sema &SemaRef, DSAStackTy &DSA, |
| 3523 | unsigned CurrentNestedLoopCount, unsigned NestedLoopCount, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3524 | Expr *CollapseLoopCountExpr, Expr *OrderedLoopCountExpr, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3525 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3526 | LoopIterationSpace &ResultIterSpace, |
| 3527 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3528 | // OpenMP [2.6, Canonical Loop Form] |
| 3529 | // for (init-expr; test-expr; incr-expr) structured-block |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3530 | auto *For = dyn_cast_or_null<ForStmt>(S); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3531 | if (!For) { |
| 3532 | SemaRef.Diag(S->getLocStart(), diag::err_omp_not_for) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3533 | << (CollapseLoopCountExpr != nullptr || OrderedLoopCountExpr != nullptr) |
| 3534 | << getOpenMPDirectiveName(DKind) << NestedLoopCount |
| 3535 | << (CurrentNestedLoopCount > 0) << CurrentNestedLoopCount; |
| 3536 | if (NestedLoopCount > 1) { |
| 3537 | if (CollapseLoopCountExpr && OrderedLoopCountExpr) |
| 3538 | SemaRef.Diag(DSA.getConstructLoc(), |
| 3539 | diag::note_omp_collapse_ordered_expr) |
| 3540 | << 2 << CollapseLoopCountExpr->getSourceRange() |
| 3541 | << OrderedLoopCountExpr->getSourceRange(); |
| 3542 | else if (CollapseLoopCountExpr) |
| 3543 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3544 | diag::note_omp_collapse_ordered_expr) |
| 3545 | << 0 << CollapseLoopCountExpr->getSourceRange(); |
| 3546 | else |
| 3547 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3548 | diag::note_omp_collapse_ordered_expr) |
| 3549 | << 1 << OrderedLoopCountExpr->getSourceRange(); |
| 3550 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3551 | return true; |
| 3552 | } |
| 3553 | assert(For->getBody()); |
| 3554 | |
| 3555 | OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc()); |
| 3556 | |
| 3557 | // Check init. |
Alexey Bataev | df9b159 | 2014-06-25 04:09:13 +0000 | [diff] [blame] | 3558 | auto Init = For->getInit(); |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3559 | if (ISC.CheckInit(Init)) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3560 | return true; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3561 | |
| 3562 | bool HasErrors = false; |
| 3563 | |
| 3564 | // Check loop variable's type. |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3565 | if (auto *LCDecl = ISC.GetLoopDecl()) { |
| 3566 | auto *LoopDeclRefExpr = ISC.GetLoopDeclRefExpr(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3567 | |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3568 | // OpenMP [2.6, Canonical Loop Form] |
| 3569 | // Var is one of the following: |
| 3570 | // A variable of signed or unsigned integer type. |
| 3571 | // For C++, a variable of a random access iterator type. |
| 3572 | // For C, a variable of a pointer type. |
| 3573 | auto VarType = LCDecl->getType().getNonReferenceType(); |
| 3574 | if (!VarType->isDependentType() && !VarType->isIntegerType() && |
| 3575 | !VarType->isPointerType() && |
| 3576 | !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) { |
| 3577 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_variable_type) |
| 3578 | << SemaRef.getLangOpts().CPlusPlus; |
| 3579 | HasErrors = true; |
| 3580 | } |
| 3581 | |
| 3582 | // OpenMP, 2.14.1.1 Data-sharing Attribute Rules for Variables Referenced in |
| 3583 | // a Construct |
| 3584 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3585 | // parallel for construct is (are) private. |
| 3586 | // The loop iteration variable in the associated for-loop of a simd |
| 3587 | // construct with just one associated for-loop is linear with a |
| 3588 | // constant-linear-step that is the increment of the associated for-loop. |
| 3589 | // Exclude loop var from the list of variables with implicitly defined data |
| 3590 | // sharing attributes. |
| 3591 | VarsWithImplicitDSA.erase(LCDecl); |
| 3592 | |
| 3593 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 3594 | // in a Construct, C/C++]. |
| 3595 | // The loop iteration variable in the associated for-loop of a simd |
| 3596 | // construct with just one associated for-loop may be listed in a linear |
| 3597 | // clause with a constant-linear-step that is the increment of the |
| 3598 | // associated for-loop. |
| 3599 | // The loop iteration variable(s) in the associated for-loop(s) of a for or |
| 3600 | // parallel for construct may be listed in a private or lastprivate clause. |
| 3601 | DSAStackTy::DSAVarData DVar = DSA.getTopDSA(LCDecl, false); |
| 3602 | // If LoopVarRefExpr is nullptr it means the corresponding loop variable is |
| 3603 | // declared in the loop and it is predetermined as a private. |
| 3604 | auto PredeterminedCKind = |
| 3605 | isOpenMPSimdDirective(DKind) |
| 3606 | ? ((NestedLoopCount == 1) ? OMPC_linear : OMPC_lastprivate) |
| 3607 | : OMPC_private; |
| 3608 | if (((isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3609 | DVar.CKind != PredeterminedCKind) || |
| 3610 | ((isOpenMPWorksharingDirective(DKind) || DKind == OMPD_taskloop || |
| 3611 | isOpenMPDistributeDirective(DKind)) && |
| 3612 | !isOpenMPSimdDirective(DKind) && DVar.CKind != OMPC_unknown && |
| 3613 | DVar.CKind != OMPC_private && DVar.CKind != OMPC_lastprivate)) && |
| 3614 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 3615 | SemaRef.Diag(Init->getLocStart(), diag::err_omp_loop_var_dsa) |
| 3616 | << getOpenMPClauseName(DVar.CKind) << getOpenMPDirectiveName(DKind) |
| 3617 | << getOpenMPClauseName(PredeterminedCKind); |
| 3618 | if (DVar.RefExpr == nullptr) |
| 3619 | DVar.CKind = PredeterminedCKind; |
| 3620 | ReportOriginalDSA(SemaRef, &DSA, LCDecl, DVar, /*IsLoopIterVar=*/true); |
| 3621 | HasErrors = true; |
| 3622 | } else if (LoopDeclRefExpr != nullptr) { |
| 3623 | // Make the loop iteration variable private (for worksharing constructs), |
| 3624 | // linear (for simd directives with the only one associated loop) or |
| 3625 | // lastprivate (for simd directives with several collapsed or ordered |
| 3626 | // loops). |
| 3627 | if (DVar.CKind == OMPC_unknown) |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 3628 | DVar = DSA.hasDSA(LCDecl, isOpenMPPrivate, |
| 3629 | [](OpenMPDirectiveKind) -> bool { return true; }, |
Alexey Bataev | c6ad97a | 2016-04-01 09:23:34 +0000 | [diff] [blame] | 3630 | /*FromParent=*/false); |
| 3631 | DSA.addDSA(LCDecl, LoopDeclRefExpr, PredeterminedCKind); |
| 3632 | } |
| 3633 | |
| 3634 | assert(isOpenMPLoopDirective(DKind) && "DSA for non-loop vars"); |
| 3635 | |
| 3636 | // Check test-expr. |
| 3637 | HasErrors |= ISC.CheckCond(For->getCond()); |
| 3638 | |
| 3639 | // Check incr-expr. |
| 3640 | HasErrors |= ISC.CheckInc(For->getInc()); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3643 | if (ISC.Dependent() || SemaRef.CurContext->isDependentContext() || HasErrors) |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3644 | return HasErrors; |
| 3645 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3646 | // Build the loop's iteration space representation. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3647 | ResultIterSpace.PreCond = |
| 3648 | ISC.BuildPreCond(DSA.getCurScope(), For->getCond(), Captures); |
Alexander Musman | 174b3ca | 2014-10-06 11:16:29 +0000 | [diff] [blame] | 3649 | ResultIterSpace.NumIterations = ISC.BuildNumIterations( |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3650 | DSA.getCurScope(), |
| 3651 | (isOpenMPWorksharingDirective(DKind) || |
| 3652 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)), |
| 3653 | Captures); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 3654 | ResultIterSpace.CounterVar = ISC.BuildCounterVar(Captures, DSA); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3655 | ResultIterSpace.PrivateCounterVar = ISC.BuildPrivateCounterVar(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3656 | ResultIterSpace.CounterInit = ISC.BuildCounterInit(); |
| 3657 | ResultIterSpace.CounterStep = ISC.BuildCounterStep(); |
| 3658 | ResultIterSpace.InitSrcRange = ISC.GetInitSrcRange(); |
| 3659 | ResultIterSpace.CondSrcRange = ISC.GetConditionSrcRange(); |
| 3660 | ResultIterSpace.IncSrcRange = ISC.GetIncrementSrcRange(); |
| 3661 | ResultIterSpace.Subtract = ISC.ShouldSubtractStep(); |
| 3662 | |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3663 | HasErrors |= (ResultIterSpace.PreCond == nullptr || |
| 3664 | ResultIterSpace.NumIterations == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3665 | ResultIterSpace.CounterVar == nullptr || |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 3666 | ResultIterSpace.PrivateCounterVar == nullptr || |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3667 | ResultIterSpace.CounterInit == nullptr || |
| 3668 | ResultIterSpace.CounterStep == nullptr); |
| 3669 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3670 | return HasErrors; |
| 3671 | } |
| 3672 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3673 | /// \brief Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3674 | static ExprResult |
| 3675 | BuildCounterInit(Sema &SemaRef, Scope *S, SourceLocation Loc, ExprResult VarRef, |
| 3676 | ExprResult Start, |
| 3677 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3678 | // Build 'VarRef = Start. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3679 | auto NewStart = tryBuildCapture(SemaRef, Start.get(), Captures); |
| 3680 | if (!NewStart.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3681 | return ExprError(); |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3682 | if (!SemaRef.Context.hasSameType(NewStart.get()->getType(), |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3683 | VarRef.get()->getType())) { |
| 3684 | NewStart = SemaRef.PerformImplicitConversion( |
| 3685 | NewStart.get(), VarRef.get()->getType(), Sema::AA_Converting, |
| 3686 | /*AllowExplicit=*/true); |
| 3687 | if (!NewStart.isUsable()) |
| 3688 | return ExprError(); |
| 3689 | } |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3690 | |
| 3691 | auto Init = |
| 3692 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3693 | return Init; |
| 3694 | } |
| 3695 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3696 | /// \brief Build 'VarRef = Start + Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3697 | static ExprResult |
| 3698 | BuildCounterUpdate(Sema &SemaRef, Scope *S, SourceLocation Loc, |
| 3699 | ExprResult VarRef, ExprResult Start, ExprResult Iter, |
| 3700 | ExprResult Step, bool Subtract, |
| 3701 | llvm::MapVector<Expr *, DeclRefExpr *> *Captures = nullptr) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3702 | // Add parentheses (for debugging purposes only). |
| 3703 | Iter = SemaRef.ActOnParenExpr(Loc, Loc, Iter.get()); |
| 3704 | if (!VarRef.isUsable() || !Start.isUsable() || !Iter.isUsable() || |
| 3705 | !Step.isUsable()) |
| 3706 | return ExprError(); |
| 3707 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3708 | ExprResult NewStep = Step; |
| 3709 | if (Captures) |
| 3710 | NewStep = tryBuildCapture(SemaRef, Step.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3711 | if (NewStep.isInvalid()) |
| 3712 | return ExprError(); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3713 | ExprResult Update = |
| 3714 | SemaRef.BuildBinOp(S, Loc, BO_Mul, Iter.get(), NewStep.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3715 | if (!Update.isUsable()) |
| 3716 | return ExprError(); |
| 3717 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3718 | // Try to build 'VarRef = Start, VarRef (+|-)= Iter * Step' or |
| 3719 | // 'VarRef = Start (+|-) Iter * Step'. |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3720 | ExprResult NewStart = Start; |
| 3721 | if (Captures) |
| 3722 | NewStart = tryBuildCapture(SemaRef, Start.get(), *Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3723 | if (NewStart.isInvalid()) |
| 3724 | return ExprError(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3725 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3726 | // First attempt: try to build 'VarRef = Start, VarRef += Iter * Step'. |
| 3727 | ExprResult SavedUpdate = Update; |
| 3728 | ExprResult UpdateVal; |
| 3729 | if (VarRef.get()->getType()->isOverloadableType() || |
| 3730 | NewStart.get()->getType()->isOverloadableType() || |
| 3731 | Update.get()->getType()->isOverloadableType()) { |
| 3732 | bool Suppress = SemaRef.getDiagnostics().getSuppressAllDiagnostics(); |
| 3733 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(/*Val=*/true); |
| 3734 | Update = |
| 3735 | SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), NewStart.get()); |
| 3736 | if (Update.isUsable()) { |
| 3737 | UpdateVal = |
| 3738 | SemaRef.BuildBinOp(S, Loc, Subtract ? BO_SubAssign : BO_AddAssign, |
| 3739 | VarRef.get(), SavedUpdate.get()); |
| 3740 | if (UpdateVal.isUsable()) { |
| 3741 | Update = SemaRef.CreateBuiltinBinOp(Loc, BO_Comma, Update.get(), |
| 3742 | UpdateVal.get()); |
| 3743 | } |
| 3744 | } |
| 3745 | SemaRef.getDiagnostics().setSuppressAllDiagnostics(Suppress); |
| 3746 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3747 | |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3748 | // Second attempt: try to build 'VarRef = Start (+|-) Iter * Step'. |
| 3749 | if (!Update.isUsable() || !UpdateVal.isUsable()) { |
| 3750 | Update = SemaRef.BuildBinOp(S, Loc, Subtract ? BO_Sub : BO_Add, |
| 3751 | NewStart.get(), SavedUpdate.get()); |
| 3752 | if (!Update.isUsable()) |
| 3753 | return ExprError(); |
| 3754 | |
Alexey Bataev | 11481f5 | 2016-02-17 10:29:05 +0000 | [diff] [blame] | 3755 | if (!SemaRef.Context.hasSameType(Update.get()->getType(), |
| 3756 | VarRef.get()->getType())) { |
| 3757 | Update = SemaRef.PerformImplicitConversion( |
| 3758 | Update.get(), VarRef.get()->getType(), Sema::AA_Converting, true); |
| 3759 | if (!Update.isUsable()) |
| 3760 | return ExprError(); |
| 3761 | } |
Alexey Bataev | c0214e0 | 2016-02-16 12:13:49 +0000 | [diff] [blame] | 3762 | |
| 3763 | Update = SemaRef.BuildBinOp(S, Loc, BO_Assign, VarRef.get(), Update.get()); |
| 3764 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3765 | return Update; |
| 3766 | } |
| 3767 | |
| 3768 | /// \brief Convert integer expression \a E to make it have at least \a Bits |
| 3769 | /// bits. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3770 | static ExprResult WidenIterationCount(unsigned Bits, Expr *E, Sema &SemaRef) { |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3771 | if (E == nullptr) |
| 3772 | return ExprError(); |
| 3773 | auto &C = SemaRef.Context; |
| 3774 | QualType OldType = E->getType(); |
| 3775 | unsigned HasBits = C.getTypeSize(OldType); |
| 3776 | if (HasBits >= Bits) |
| 3777 | return ExprResult(E); |
| 3778 | // OK to convert to signed, because new type has more bits than old. |
| 3779 | QualType NewType = C.getIntTypeForBitwidth(Bits, /* Signed */ true); |
| 3780 | return SemaRef.PerformImplicitConversion(E, NewType, Sema::AA_Converting, |
| 3781 | true); |
| 3782 | } |
| 3783 | |
| 3784 | /// \brief Check if the given expression \a E is a constant integer that fits |
| 3785 | /// into \a Bits bits. |
| 3786 | static bool FitsInto(unsigned Bits, bool Signed, Expr *E, Sema &SemaRef) { |
| 3787 | if (E == nullptr) |
| 3788 | return false; |
| 3789 | llvm::APSInt Result; |
| 3790 | if (E->isIntegerConstantExpr(Result, SemaRef.Context)) |
| 3791 | return Signed ? Result.isSignedIntN(Bits) : Result.isIntN(Bits); |
| 3792 | return false; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3795 | /// Build preinits statement for the given declarations. |
| 3796 | static Stmt *buildPreInits(ASTContext &Context, |
| 3797 | SmallVectorImpl<Decl *> &PreInits) { |
| 3798 | if (!PreInits.empty()) { |
| 3799 | return new (Context) DeclStmt( |
| 3800 | DeclGroupRef::Create(Context, PreInits.begin(), PreInits.size()), |
| 3801 | SourceLocation(), SourceLocation()); |
| 3802 | } |
| 3803 | return nullptr; |
| 3804 | } |
| 3805 | |
| 3806 | /// Build preinits statement for the given declarations. |
| 3807 | static Stmt *buildPreInits(ASTContext &Context, |
| 3808 | llvm::MapVector<Expr *, DeclRefExpr *> &Captures) { |
| 3809 | if (!Captures.empty()) { |
| 3810 | SmallVector<Decl *, 16> PreInits; |
| 3811 | for (auto &Pair : Captures) |
| 3812 | PreInits.push_back(Pair.second->getDecl()); |
| 3813 | return buildPreInits(Context, PreInits); |
| 3814 | } |
| 3815 | return nullptr; |
| 3816 | } |
| 3817 | |
| 3818 | /// Build postupdate expression for the given list of postupdates expressions. |
| 3819 | static Expr *buildPostUpdate(Sema &S, ArrayRef<Expr *> PostUpdates) { |
| 3820 | Expr *PostUpdate = nullptr; |
| 3821 | if (!PostUpdates.empty()) { |
| 3822 | for (auto *E : PostUpdates) { |
| 3823 | Expr *ConvE = S.BuildCStyleCastExpr( |
| 3824 | E->getExprLoc(), |
| 3825 | S.Context.getTrivialTypeSourceInfo(S.Context.VoidTy), |
| 3826 | E->getExprLoc(), E) |
| 3827 | .get(); |
| 3828 | PostUpdate = PostUpdate |
| 3829 | ? S.CreateBuiltinBinOp(ConvE->getExprLoc(), BO_Comma, |
| 3830 | PostUpdate, ConvE) |
| 3831 | .get() |
| 3832 | : ConvE; |
| 3833 | } |
| 3834 | } |
| 3835 | return PostUpdate; |
| 3836 | } |
| 3837 | |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3838 | /// \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] | 3839 | /// \return Returns 0 if one of the collapsed stmts is not canonical for loop, |
| 3840 | /// number of collapsed loops otherwise. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 3841 | static unsigned |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3842 | CheckOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr, |
| 3843 | Expr *OrderedLoopCountExpr, Stmt *AStmt, Sema &SemaRef, |
| 3844 | DSAStackTy &DSA, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 3845 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 3846 | OMPLoopDirective::HelperExprs &Built) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3847 | unsigned NestedLoopCount = 1; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3848 | if (CollapseLoopCountExpr) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3849 | // Found 'collapse' clause - calculate collapse number. |
| 3850 | llvm::APSInt Result; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3851 | if (CollapseLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3852 | NestedLoopCount = Result.getLimitedValue(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3853 | } |
| 3854 | if (OrderedLoopCountExpr) { |
| 3855 | // Found 'ordered' clause - calculate collapse number. |
| 3856 | llvm::APSInt Result; |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 3857 | if (OrderedLoopCountExpr->EvaluateAsInt(Result, SemaRef.getASTContext())) { |
| 3858 | if (Result.getLimitedValue() < NestedLoopCount) { |
| 3859 | SemaRef.Diag(OrderedLoopCountExpr->getExprLoc(), |
| 3860 | diag::err_omp_wrong_ordered_loop_count) |
| 3861 | << OrderedLoopCountExpr->getSourceRange(); |
| 3862 | SemaRef.Diag(CollapseLoopCountExpr->getExprLoc(), |
| 3863 | diag::note_collapse_loop_count) |
| 3864 | << CollapseLoopCountExpr->getSourceRange(); |
| 3865 | } |
| 3866 | NestedLoopCount = Result.getLimitedValue(); |
| 3867 | } |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3868 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3869 | // This is helper routine for loop directives (e.g., 'for', 'simd', |
| 3870 | // 'for simd', etc.). |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3871 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3872 | SmallVector<LoopIterationSpace, 4> IterSpaces; |
| 3873 | IterSpaces.resize(NestedLoopCount); |
| 3874 | Stmt *CurStmt = AStmt->IgnoreContainers(/* IgnoreCaptured */ true); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3875 | for (unsigned Cnt = 0; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 3876 | if (CheckOpenMPIterationSpace(DKind, CurStmt, SemaRef, DSA, Cnt, |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3877 | NestedLoopCount, CollapseLoopCountExpr, |
| 3878 | OrderedLoopCountExpr, VarsWithImplicitDSA, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 3879 | IterSpaces[Cnt], Captures)) |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 3880 | return 0; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3881 | // 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] | 3882 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 3883 | // All loops associated with the construct must be perfectly nested; that |
| 3884 | // is, there must be no intervening code nor any OpenMP directive between |
| 3885 | // any two loops. |
| 3886 | CurStmt = cast<ForStmt>(CurStmt)->getBody()->IgnoreContainers(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 3887 | } |
| 3888 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3889 | Built.clear(/* size */ NestedLoopCount); |
| 3890 | |
| 3891 | if (SemaRef.CurContext->isDependentContext()) |
| 3892 | return NestedLoopCount; |
| 3893 | |
| 3894 | // An example of what is generated for the following code: |
| 3895 | // |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3896 | // #pragma omp simd collapse(2) ordered(2) |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3897 | // for (i = 0; i < NI; ++i) |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 3898 | // for (k = 0; k < NK; ++k) |
| 3899 | // for (j = J0; j < NJ; j+=2) { |
| 3900 | // <loop body> |
| 3901 | // } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3902 | // |
| 3903 | // We generate the code below. |
| 3904 | // Note: the loop body may be outlined in CodeGen. |
| 3905 | // Note: some counters may be C++ classes, operator- is used to find number of |
| 3906 | // iterations and operator+= to calculate counter value. |
| 3907 | // Note: decltype(NumIterations) must be integer type (in 'omp for', only i32 |
| 3908 | // or i64 is currently supported). |
| 3909 | // |
| 3910 | // #define NumIterations (NI * ((NJ - J0 - 1 + 2) / 2)) |
| 3911 | // for (int[32|64]_t IV = 0; IV < NumIterations; ++IV ) { |
| 3912 | // .local.i = IV / ((NJ - J0 - 1 + 2) / 2); |
| 3913 | // .local.j = J0 + (IV % ((NJ - J0 - 1 + 2) / 2)) * 2; |
| 3914 | // // similar updates for vars in clauses (e.g. 'linear') |
| 3915 | // <loop body (using local i and j)> |
| 3916 | // } |
| 3917 | // i = NI; // assign final values of counters |
| 3918 | // j = NJ; |
| 3919 | // |
| 3920 | |
| 3921 | // Last iteration number is (I1 * I2 * ... In) - 1, where I1, I2 ... In are |
| 3922 | // the iteration counts of the collapsed for loops. |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3923 | // Precondition tests if there is at least one iteration (all conditions are |
| 3924 | // true). |
| 3925 | auto PreCond = ExprResult(IterSpaces[0].PreCond); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3926 | auto N0 = IterSpaces[0].NumIterations; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3927 | ExprResult LastIteration32 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3928 | 32 /* Bits */, SemaRef |
| 3929 | .PerformImplicitConversion( |
| 3930 | N0->IgnoreImpCasts(), N0->getType(), |
| 3931 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3932 | .get(), |
| 3933 | SemaRef); |
| 3934 | ExprResult LastIteration64 = WidenIterationCount( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3935 | 64 /* Bits */, SemaRef |
| 3936 | .PerformImplicitConversion( |
| 3937 | N0->IgnoreImpCasts(), N0->getType(), |
| 3938 | Sema::AA_Converting, /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3939 | .get(), |
| 3940 | SemaRef); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3941 | |
| 3942 | if (!LastIteration32.isUsable() || !LastIteration64.isUsable()) |
| 3943 | return NestedLoopCount; |
| 3944 | |
| 3945 | auto &C = SemaRef.Context; |
| 3946 | bool AllCountsNeedLessThan32Bits = C.getTypeSize(N0->getType()) < 32; |
| 3947 | |
| 3948 | Scope *CurScope = DSA.getCurScope(); |
| 3949 | for (unsigned Cnt = 1; Cnt < NestedLoopCount; ++Cnt) { |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3950 | if (PreCond.isUsable()) { |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3951 | PreCond = |
| 3952 | SemaRef.BuildBinOp(CurScope, PreCond.get()->getExprLoc(), BO_LAnd, |
| 3953 | PreCond.get(), IterSpaces[Cnt].PreCond); |
Alexey Bataev | 62dbb97 | 2015-04-22 11:59:37 +0000 | [diff] [blame] | 3954 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3955 | auto N = IterSpaces[Cnt].NumIterations; |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3956 | SourceLocation Loc = N->getExprLoc(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3957 | AllCountsNeedLessThan32Bits &= C.getTypeSize(N->getType()) < 32; |
| 3958 | if (LastIteration32.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3959 | LastIteration32 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3960 | CurScope, Loc, BO_Mul, LastIteration32.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3961 | SemaRef |
| 3962 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3963 | Sema::AA_Converting, |
| 3964 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3965 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3966 | if (LastIteration64.isUsable()) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3967 | LastIteration64 = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 3968 | CurScope, Loc, BO_Mul, LastIteration64.get(), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 3969 | SemaRef |
| 3970 | .PerformImplicitConversion(N->IgnoreImpCasts(), N->getType(), |
| 3971 | Sema::AA_Converting, |
| 3972 | /*AllowExplicit=*/true) |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 3973 | .get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | // Choose either the 32-bit or 64-bit version. |
| 3977 | ExprResult LastIteration = LastIteration64; |
| 3978 | if (LastIteration32.isUsable() && |
| 3979 | C.getTypeSize(LastIteration32.get()->getType()) == 32 && |
| 3980 | (AllCountsNeedLessThan32Bits || NestedLoopCount == 1 || |
| 3981 | FitsInto( |
| 3982 | 32 /* Bits */, |
| 3983 | LastIteration32.get()->getType()->hasSignedIntegerRepresentation(), |
| 3984 | LastIteration64.get(), SemaRef))) |
| 3985 | LastIteration = LastIteration32; |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 3986 | QualType VType = LastIteration.get()->getType(); |
| 3987 | QualType RealVType = VType; |
| 3988 | QualType StrideVType = VType; |
| 3989 | if (isOpenMPTaskLoopDirective(DKind)) { |
| 3990 | VType = |
| 3991 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/0); |
| 3992 | StrideVType = |
| 3993 | SemaRef.Context.getIntTypeForBitwidth(/*DestWidth=*/64, /*Signed=*/1); |
| 3994 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 3995 | |
| 3996 | if (!LastIteration.isUsable()) |
| 3997 | return 0; |
| 3998 | |
| 3999 | // Save the number of iterations. |
| 4000 | ExprResult NumIterations = LastIteration; |
| 4001 | { |
| 4002 | LastIteration = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4003 | CurScope, LastIteration.get()->getExprLoc(), BO_Sub, |
| 4004 | LastIteration.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4005 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4006 | if (!LastIteration.isUsable()) |
| 4007 | return 0; |
| 4008 | } |
| 4009 | |
| 4010 | // Calculate the last iteration number beforehand instead of doing this on |
| 4011 | // each iteration. Do not do this if the number of iterations may be kfold-ed. |
| 4012 | llvm::APSInt Result; |
| 4013 | bool IsConstant = |
| 4014 | LastIteration.get()->isIntegerConstantExpr(Result, SemaRef.Context); |
| 4015 | ExprResult CalcLastIteration; |
| 4016 | if (!IsConstant) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4017 | ExprResult SaveRef = |
| 4018 | tryBuildCapture(SemaRef, LastIteration.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4019 | LastIteration = SaveRef; |
| 4020 | |
| 4021 | // Prepare SaveRef + 1. |
| 4022 | NumIterations = SemaRef.BuildBinOp( |
Alexey Bataev | a7206b9 | 2016-12-20 16:51:02 +0000 | [diff] [blame] | 4023 | CurScope, SaveRef.get()->getExprLoc(), BO_Add, SaveRef.get(), |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4024 | SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get()); |
| 4025 | if (!NumIterations.isUsable()) |
| 4026 | return 0; |
| 4027 | } |
| 4028 | |
| 4029 | SourceLocation InitLoc = IterSpaces[0].InitSrcRange.getBegin(); |
| 4030 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4031 | // Build variables passed into runtime, necessary for worksharing directives. |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4032 | ExprResult LB, UB, IL, ST, EUB, PrevLB, PrevUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4033 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4034 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4035 | // Lower bound variable, initialized with zero. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4036 | VarDecl *LBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.lb"); |
| 4037 | LB = buildDeclRefExpr(SemaRef, LBDecl, VType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4038 | SemaRef.AddInitializerToDecl(LBDecl, |
| 4039 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4040 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4041 | |
| 4042 | // Upper bound variable, initialized with last iteration number. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4043 | VarDecl *UBDecl = buildVarDecl(SemaRef, InitLoc, VType, ".omp.ub"); |
| 4044 | UB = buildDeclRefExpr(SemaRef, UBDecl, VType, InitLoc); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4045 | SemaRef.AddInitializerToDecl(UBDecl, LastIteration.get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4046 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4047 | |
| 4048 | // A 32-bit variable-flag where runtime returns 1 for the last iteration. |
| 4049 | // This will be used to implement clause 'lastprivate'. |
| 4050 | QualType Int32Ty = SemaRef.Context.getIntTypeForBitwidth(32, true); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4051 | VarDecl *ILDecl = buildVarDecl(SemaRef, InitLoc, Int32Ty, ".omp.is_last"); |
| 4052 | IL = buildDeclRefExpr(SemaRef, ILDecl, Int32Ty, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4053 | SemaRef.AddInitializerToDecl(ILDecl, |
| 4054 | SemaRef.ActOnIntegerConstant(InitLoc, 0).get(), |
| 4055 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4056 | |
| 4057 | // Stride variable returned by runtime (we initialize it to 1 by default). |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4058 | VarDecl *STDecl = |
| 4059 | buildVarDecl(SemaRef, InitLoc, StrideVType, ".omp.stride"); |
| 4060 | ST = buildDeclRefExpr(SemaRef, STDecl, StrideVType, InitLoc); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 4061 | SemaRef.AddInitializerToDecl(STDecl, |
| 4062 | SemaRef.ActOnIntegerConstant(InitLoc, 1).get(), |
| 4063 | /*DirectInit*/ false); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4064 | |
| 4065 | // Build expression: UB = min(UB, LastIteration) |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4066 | // It is necessary for CodeGen of directives with static scheduling. |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4067 | ExprResult IsUBGreater = SemaRef.BuildBinOp(CurScope, InitLoc, BO_GT, |
| 4068 | UB.get(), LastIteration.get()); |
| 4069 | ExprResult CondOp = SemaRef.ActOnConditionalOp( |
| 4070 | InitLoc, InitLoc, IsUBGreater.get(), LastIteration.get(), UB.get()); |
| 4071 | EUB = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, UB.get(), |
| 4072 | CondOp.get()); |
| 4073 | EUB = SemaRef.ActOnFinishFullExpr(EUB.get()); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4074 | |
| 4075 | // If we have a combined directive that combines 'distribute', 'for' or |
| 4076 | // 'simd' we need to be able to access the bounds of the schedule of the |
| 4077 | // enclosing region. E.g. in 'distribute parallel for' the bounds obtained |
| 4078 | // by scheduling 'distribute' have to be passed to the schedule of 'for'. |
| 4079 | if (isOpenMPLoopBoundSharingDirective(DKind)) { |
| 4080 | auto *CD = cast<CapturedStmt>(AStmt)->getCapturedDecl(); |
| 4081 | |
| 4082 | // We expect to have at least 2 more parameters than the 'parallel' |
| 4083 | // directive does - the lower and upper bounds of the previous schedule. |
| 4084 | assert(CD->getNumParams() >= 4 && |
| 4085 | "Unexpected number of parameters in loop combined directive"); |
| 4086 | |
| 4087 | // Set the proper type for the bounds given what we learned from the |
| 4088 | // enclosed loops. |
| 4089 | auto *PrevLBDecl = CD->getParam(/*PrevLB=*/2); |
| 4090 | auto *PrevUBDecl = CD->getParam(/*PrevUB=*/3); |
| 4091 | |
| 4092 | // Previous lower and upper bounds are obtained from the region |
| 4093 | // parameters. |
| 4094 | PrevLB = |
| 4095 | buildDeclRefExpr(SemaRef, PrevLBDecl, PrevLBDecl->getType(), InitLoc); |
| 4096 | PrevUB = |
| 4097 | buildDeclRefExpr(SemaRef, PrevUBDecl, PrevUBDecl->getType(), InitLoc); |
| 4098 | } |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | // Build the iteration variable and its initialization before loop. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4102 | ExprResult IV; |
| 4103 | ExprResult Init; |
| 4104 | { |
Alexey Bataev | 7292c29 | 2016-04-25 12:22:29 +0000 | [diff] [blame] | 4105 | VarDecl *IVDecl = buildVarDecl(SemaRef, InitLoc, RealVType, ".omp.iv"); |
| 4106 | IV = buildDeclRefExpr(SemaRef, IVDecl, RealVType, InitLoc); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4107 | Expr *RHS = |
| 4108 | (isOpenMPWorksharingDirective(DKind) || |
| 4109 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
| 4110 | ? LB.get() |
| 4111 | : SemaRef.ActOnIntegerConstant(SourceLocation(), 0).get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4112 | Init = SemaRef.BuildBinOp(CurScope, InitLoc, BO_Assign, IV.get(), RHS); |
| 4113 | Init = SemaRef.ActOnFinishFullExpr(Init.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4114 | } |
| 4115 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4116 | // Loop condition (IV < NumIterations) or (IV <= UB) for worksharing loops. |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4117 | SourceLocation CondLoc; |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4118 | ExprResult Cond = |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4119 | (isOpenMPWorksharingDirective(DKind) || |
| 4120 | isOpenMPTaskLoopDirective(DKind) || isOpenMPDistributeDirective(DKind)) |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4121 | ? SemaRef.BuildBinOp(CurScope, CondLoc, BO_LE, IV.get(), UB.get()) |
| 4122 | : SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, IV.get(), |
| 4123 | NumIterations.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4124 | |
| 4125 | // Loop increment (IV = IV + 1) |
| 4126 | SourceLocation IncLoc; |
| 4127 | ExprResult Inc = |
| 4128 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, IV.get(), |
| 4129 | SemaRef.ActOnIntegerConstant(IncLoc, 1).get()); |
| 4130 | if (!Inc.isUsable()) |
| 4131 | return 0; |
| 4132 | Inc = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, IV.get(), Inc.get()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4133 | Inc = SemaRef.ActOnFinishFullExpr(Inc.get()); |
| 4134 | if (!Inc.isUsable()) |
| 4135 | return 0; |
| 4136 | |
| 4137 | // Increments for worksharing loops (LB = LB + ST; UB = UB + ST). |
| 4138 | // Used for directives with static scheduling. |
| 4139 | ExprResult NextLB, NextUB; |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 4140 | if (isOpenMPWorksharingDirective(DKind) || isOpenMPTaskLoopDirective(DKind) || |
| 4141 | isOpenMPDistributeDirective(DKind)) { |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4142 | // LB + ST |
| 4143 | NextLB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, LB.get(), ST.get()); |
| 4144 | if (!NextLB.isUsable()) |
| 4145 | return 0; |
| 4146 | // LB = LB + ST |
| 4147 | NextLB = |
| 4148 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, LB.get(), NextLB.get()); |
| 4149 | NextLB = SemaRef.ActOnFinishFullExpr(NextLB.get()); |
| 4150 | if (!NextLB.isUsable()) |
| 4151 | return 0; |
| 4152 | // UB + ST |
| 4153 | NextUB = SemaRef.BuildBinOp(CurScope, IncLoc, BO_Add, UB.get(), ST.get()); |
| 4154 | if (!NextUB.isUsable()) |
| 4155 | return 0; |
| 4156 | // UB = UB + ST |
| 4157 | NextUB = |
| 4158 | SemaRef.BuildBinOp(CurScope, IncLoc, BO_Assign, UB.get(), NextUB.get()); |
| 4159 | NextUB = SemaRef.ActOnFinishFullExpr(NextUB.get()); |
| 4160 | if (!NextUB.isUsable()) |
| 4161 | return 0; |
| 4162 | } |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4163 | |
| 4164 | // Build updates and final values of the loop counters. |
| 4165 | bool HasErrors = false; |
| 4166 | Built.Counters.resize(NestedLoopCount); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4167 | Built.Inits.resize(NestedLoopCount); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4168 | Built.Updates.resize(NestedLoopCount); |
| 4169 | Built.Finals.resize(NestedLoopCount); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4170 | SmallVector<Expr *, 4> LoopMultipliers; |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4171 | { |
| 4172 | ExprResult Div; |
| 4173 | // Go from inner nested loop to outer. |
| 4174 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4175 | LoopIterationSpace &IS = IterSpaces[Cnt]; |
| 4176 | SourceLocation UpdLoc = IS.IncSrcRange.getBegin(); |
| 4177 | // Build: Iter = (IV / Div) % IS.NumIters |
| 4178 | // where Div is product of previous iterations' IS.NumIters. |
| 4179 | ExprResult Iter; |
| 4180 | if (Div.isUsable()) { |
| 4181 | Iter = |
| 4182 | SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Div, IV.get(), Div.get()); |
| 4183 | } else { |
| 4184 | Iter = IV; |
| 4185 | assert((Cnt == (int)NestedLoopCount - 1) && |
| 4186 | "unusable div expected on first iteration only"); |
| 4187 | } |
| 4188 | |
| 4189 | if (Cnt != 0 && Iter.isUsable()) |
| 4190 | Iter = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Rem, Iter.get(), |
| 4191 | IS.NumIterations); |
| 4192 | if (!Iter.isUsable()) { |
| 4193 | HasErrors = true; |
| 4194 | break; |
| 4195 | } |
| 4196 | |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4197 | // Build update: IS.CounterVar(Private) = IS.Start + Iter * IS.Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4198 | auto *VD = cast<VarDecl>(cast<DeclRefExpr>(IS.CounterVar)->getDecl()); |
| 4199 | auto *CounterVar = buildDeclRefExpr(SemaRef, VD, IS.CounterVar->getType(), |
| 4200 | IS.CounterVar->getExprLoc(), |
| 4201 | /*RefersToCapture=*/true); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4202 | ExprResult Init = BuildCounterInit(SemaRef, CurScope, UpdLoc, CounterVar, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4203 | IS.CounterInit, Captures); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4204 | if (!Init.isUsable()) { |
| 4205 | HasErrors = true; |
| 4206 | break; |
| 4207 | } |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4208 | ExprResult Update = BuildCounterUpdate( |
| 4209 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, Iter, |
| 4210 | IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4211 | if (!Update.isUsable()) { |
| 4212 | HasErrors = true; |
| 4213 | break; |
| 4214 | } |
| 4215 | |
| 4216 | // Build final: IS.CounterVar = IS.Start + IS.NumIters * IS.Step |
| 4217 | ExprResult Final = BuildCounterUpdate( |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 4218 | SemaRef, CurScope, UpdLoc, CounterVar, IS.CounterInit, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4219 | IS.NumIterations, IS.CounterStep, IS.Subtract, &Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4220 | if (!Final.isUsable()) { |
| 4221 | HasErrors = true; |
| 4222 | break; |
| 4223 | } |
| 4224 | |
| 4225 | // Build Div for the next iteration: Div <- Div * IS.NumIters |
| 4226 | if (Cnt != 0) { |
| 4227 | if (Div.isUnset()) |
| 4228 | Div = IS.NumIterations; |
| 4229 | else |
| 4230 | Div = SemaRef.BuildBinOp(CurScope, UpdLoc, BO_Mul, Div.get(), |
| 4231 | IS.NumIterations); |
| 4232 | |
| 4233 | // Add parentheses (for debugging purposes only). |
| 4234 | if (Div.isUsable()) |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4235 | Div = tryBuildCapture(SemaRef, Div.get(), Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4236 | if (!Div.isUsable()) { |
| 4237 | HasErrors = true; |
| 4238 | break; |
| 4239 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4240 | LoopMultipliers.push_back(Div.get()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4241 | } |
| 4242 | if (!Update.isUsable() || !Final.isUsable()) { |
| 4243 | HasErrors = true; |
| 4244 | break; |
| 4245 | } |
| 4246 | // Save results |
| 4247 | Built.Counters[Cnt] = IS.CounterVar; |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 4248 | Built.PrivateCounters[Cnt] = IS.PrivateCounterVar; |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 4249 | Built.Inits[Cnt] = Init.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4250 | Built.Updates[Cnt] = Update.get(); |
| 4251 | Built.Finals[Cnt] = Final.get(); |
| 4252 | } |
| 4253 | } |
| 4254 | |
| 4255 | if (HasErrors) |
| 4256 | return 0; |
| 4257 | |
| 4258 | // Save results |
| 4259 | Built.IterationVarRef = IV.get(); |
| 4260 | Built.LastIteration = LastIteration.get(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4261 | Built.NumIterations = NumIterations.get(); |
Alexey Bataev | 3bed68c | 2015-07-15 12:14:07 +0000 | [diff] [blame] | 4262 | Built.CalcLastIteration = |
| 4263 | SemaRef.ActOnFinishFullExpr(CalcLastIteration.get()).get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4264 | Built.PreCond = PreCond.get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 4265 | Built.PreInits = buildPreInits(C, Captures); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4266 | Built.Cond = Cond.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4267 | Built.Init = Init.get(); |
| 4268 | Built.Inc = Inc.get(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4269 | Built.LB = LB.get(); |
| 4270 | Built.UB = UB.get(); |
| 4271 | Built.IL = IL.get(); |
| 4272 | Built.ST = ST.get(); |
| 4273 | Built.EUB = EUB.get(); |
| 4274 | Built.NLB = NextLB.get(); |
| 4275 | Built.NUB = NextUB.get(); |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 4276 | Built.PrevLB = PrevLB.get(); |
| 4277 | Built.PrevUB = PrevUB.get(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4278 | |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4279 | Expr *CounterVal = SemaRef.DefaultLvalueConversion(IV.get()).get(); |
| 4280 | // Fill data for doacross depend clauses. |
| 4281 | for (auto Pair : DSA.getDoacrossDependClauses()) { |
| 4282 | if (Pair.first->getDependencyKind() == OMPC_DEPEND_source) |
| 4283 | Pair.first->setCounterValue(CounterVal); |
| 4284 | else { |
| 4285 | if (NestedLoopCount != Pair.second.size() || |
| 4286 | NestedLoopCount != LoopMultipliers.size() + 1) { |
| 4287 | // Erroneous case - clause has some problems. |
| 4288 | Pair.first->setCounterValue(CounterVal); |
| 4289 | continue; |
| 4290 | } |
| 4291 | assert(Pair.first->getDependencyKind() == OMPC_DEPEND_sink); |
| 4292 | auto I = Pair.second.rbegin(); |
| 4293 | auto IS = IterSpaces.rbegin(); |
| 4294 | auto ILM = LoopMultipliers.rbegin(); |
| 4295 | Expr *UpCounterVal = CounterVal; |
| 4296 | Expr *Multiplier = nullptr; |
| 4297 | for (int Cnt = NestedLoopCount - 1; Cnt >= 0; --Cnt) { |
| 4298 | if (I->first) { |
| 4299 | assert(IS->CounterStep); |
| 4300 | Expr *NormalizedOffset = |
| 4301 | SemaRef |
| 4302 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Div, |
| 4303 | I->first, IS->CounterStep) |
| 4304 | .get(); |
| 4305 | if (Multiplier) { |
| 4306 | NormalizedOffset = |
| 4307 | SemaRef |
| 4308 | .BuildBinOp(CurScope, I->first->getExprLoc(), BO_Mul, |
| 4309 | NormalizedOffset, Multiplier) |
| 4310 | .get(); |
| 4311 | } |
| 4312 | assert(I->second == OO_Plus || I->second == OO_Minus); |
| 4313 | BinaryOperatorKind BOK = (I->second == OO_Plus) ? BO_Add : BO_Sub; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4314 | UpCounterVal = SemaRef |
| 4315 | .BuildBinOp(CurScope, I->first->getExprLoc(), BOK, |
| 4316 | UpCounterVal, NormalizedOffset) |
| 4317 | .get(); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 4318 | } |
| 4319 | Multiplier = *ILM; |
| 4320 | ++I; |
| 4321 | ++IS; |
| 4322 | ++ILM; |
| 4323 | } |
| 4324 | Pair.first->setCounterValue(UpCounterVal); |
| 4325 | } |
| 4326 | } |
| 4327 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4328 | return NestedLoopCount; |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 4329 | } |
| 4330 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4331 | static Expr *getCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4332 | auto CollapseClauses = |
| 4333 | OMPExecutableDirective::getClausesOfKind<OMPCollapseClause>(Clauses); |
| 4334 | if (CollapseClauses.begin() != CollapseClauses.end()) |
| 4335 | return (*CollapseClauses.begin())->getNumForLoops(); |
Alexey Bataev | e2f07d4 | 2014-06-24 12:55:56 +0000 | [diff] [blame] | 4336 | return nullptr; |
| 4337 | } |
| 4338 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4339 | static Expr *getOrderedNumberExpr(ArrayRef<OMPClause *> Clauses) { |
Benjamin Kramer | fc600dc | 2015-08-30 15:12:28 +0000 | [diff] [blame] | 4340 | auto OrderedClauses = |
| 4341 | OMPExecutableDirective::getClausesOfKind<OMPOrderedClause>(Clauses); |
| 4342 | if (OrderedClauses.begin() != OrderedClauses.end()) |
| 4343 | return (*OrderedClauses.begin())->getNumForLoops(); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4344 | return nullptr; |
| 4345 | } |
| 4346 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4347 | static bool checkSimdlenSafelenSpecified(Sema &S, |
| 4348 | const ArrayRef<OMPClause *> Clauses) { |
| 4349 | OMPSafelenClause *Safelen = nullptr; |
| 4350 | OMPSimdlenClause *Simdlen = nullptr; |
| 4351 | |
| 4352 | for (auto *Clause : Clauses) { |
| 4353 | if (Clause->getClauseKind() == OMPC_safelen) |
| 4354 | Safelen = cast<OMPSafelenClause>(Clause); |
| 4355 | else if (Clause->getClauseKind() == OMPC_simdlen) |
| 4356 | Simdlen = cast<OMPSimdlenClause>(Clause); |
| 4357 | if (Safelen && Simdlen) |
| 4358 | break; |
| 4359 | } |
| 4360 | |
| 4361 | if (Simdlen && Safelen) { |
| 4362 | llvm::APSInt SimdlenRes, SafelenRes; |
| 4363 | auto SimdlenLength = Simdlen->getSimdlen(); |
| 4364 | auto SafelenLength = Safelen->getSafelen(); |
| 4365 | if (SimdlenLength->isValueDependent() || SimdlenLength->isTypeDependent() || |
| 4366 | SimdlenLength->isInstantiationDependent() || |
| 4367 | SimdlenLength->containsUnexpandedParameterPack()) |
| 4368 | return false; |
| 4369 | if (SafelenLength->isValueDependent() || SafelenLength->isTypeDependent() || |
| 4370 | SafelenLength->isInstantiationDependent() || |
| 4371 | SafelenLength->containsUnexpandedParameterPack()) |
| 4372 | return false; |
| 4373 | SimdlenLength->EvaluateAsInt(SimdlenRes, S.Context); |
| 4374 | SafelenLength->EvaluateAsInt(SafelenRes, S.Context); |
| 4375 | // OpenMP 4.5 [2.8.1, simd Construct, Restrictions] |
| 4376 | // If both simdlen and safelen clauses are specified, the value of the |
| 4377 | // simdlen parameter must be less than or equal to the value of the safelen |
| 4378 | // parameter. |
| 4379 | if (SimdlenRes > SafelenRes) { |
| 4380 | S.Diag(SimdlenLength->getExprLoc(), |
| 4381 | diag::err_omp_wrong_simdlen_safelen_values) |
| 4382 | << SimdlenLength->getSourceRange() << SafelenLength->getSourceRange(); |
| 4383 | return true; |
| 4384 | } |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4385 | } |
| 4386 | return false; |
| 4387 | } |
| 4388 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4389 | StmtResult Sema::ActOnOpenMPSimdDirective( |
| 4390 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4391 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4392 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4393 | if (!AStmt) |
| 4394 | return StmtError(); |
| 4395 | |
| 4396 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4397 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4398 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4399 | // define the nested loops number. |
| 4400 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4401 | OMPD_simd, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4402 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4403 | if (NestedLoopCount == 0) |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4404 | return StmtError(); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4405 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4406 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4407 | "omp simd loop exprs were not built"); |
| 4408 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4409 | if (!CurContext->isDependentContext()) { |
| 4410 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4411 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4412 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4413 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4414 | B.NumIterations, *this, CurScope, |
| 4415 | DSAStack)) |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 4416 | return StmtError(); |
| 4417 | } |
| 4418 | } |
| 4419 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4420 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4421 | return StmtError(); |
| 4422 | |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4423 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4424 | return OMPSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4425 | Clauses, AStmt, B); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 4426 | } |
| 4427 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4428 | StmtResult Sema::ActOnOpenMPForDirective( |
| 4429 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4430 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4431 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4432 | if (!AStmt) |
| 4433 | return StmtError(); |
| 4434 | |
| 4435 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4436 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4437 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4438 | // define the nested loops number. |
| 4439 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 4440 | OMPD_for, getCollapseNumberExpr(Clauses), getOrderedNumberExpr(Clauses), |
| 4441 | AStmt, *this, *DSAStack, VarsWithImplicitDSA, B); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 4442 | if (NestedLoopCount == 0) |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4443 | return StmtError(); |
| 4444 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4445 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4446 | "omp for loop exprs were not built"); |
| 4447 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4448 | if (!CurContext->isDependentContext()) { |
| 4449 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4450 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4451 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4452 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4453 | B.NumIterations, *this, CurScope, |
| 4454 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4455 | return StmtError(); |
| 4456 | } |
| 4457 | } |
| 4458 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4459 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4460 | return OMPForDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4461 | Clauses, AStmt, B, DSAStack->isCancelRegion()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4464 | StmtResult Sema::ActOnOpenMPForSimdDirective( |
| 4465 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4466 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4467 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4468 | if (!AStmt) |
| 4469 | return StmtError(); |
| 4470 | |
| 4471 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4472 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4473 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4474 | // define the nested loops number. |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4475 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4476 | CheckOpenMPLoop(OMPD_for_simd, getCollapseNumberExpr(Clauses), |
| 4477 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4478 | VarsWithImplicitDSA, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4479 | if (NestedLoopCount == 0) |
| 4480 | return StmtError(); |
| 4481 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4482 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4483 | "omp for simd loop exprs were not built"); |
| 4484 | |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4485 | if (!CurContext->isDependentContext()) { |
| 4486 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4487 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4488 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4489 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4490 | B.NumIterations, *this, CurScope, |
| 4491 | DSAStack)) |
Alexey Bataev | 58e5bdb | 2015-06-18 04:45:29 +0000 | [diff] [blame] | 4492 | return StmtError(); |
| 4493 | } |
| 4494 | } |
| 4495 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4496 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4497 | return StmtError(); |
| 4498 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4499 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4500 | return OMPForSimdDirective::Create(Context, StartLoc, EndLoc, NestedLoopCount, |
| 4501 | Clauses, AStmt, B); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4504 | StmtResult Sema::ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4505 | Stmt *AStmt, |
| 4506 | SourceLocation StartLoc, |
| 4507 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4508 | if (!AStmt) |
| 4509 | return StmtError(); |
| 4510 | |
| 4511 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4512 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4513 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4514 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4515 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4516 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4517 | if (S.begin() == S.end()) |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4518 | return StmtError(); |
| 4519 | // All associated statements must be '#pragma omp section' except for |
| 4520 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4521 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4522 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4523 | if (SectionStmt) |
| 4524 | Diag(SectionStmt->getLocStart(), |
| 4525 | diag::err_omp_sections_substmt_not_section); |
| 4526 | return StmtError(); |
| 4527 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4528 | cast<OMPSectionDirective>(SectionStmt) |
| 4529 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4530 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4531 | } else { |
| 4532 | Diag(AStmt->getLocStart(), diag::err_omp_sections_not_compound_stmt); |
| 4533 | return StmtError(); |
| 4534 | } |
| 4535 | |
| 4536 | getCurFunction()->setHasBranchProtectedScope(); |
| 4537 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4538 | return OMPSectionsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4539 | DSAStack->isCancelRegion()); |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 4540 | } |
| 4541 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4542 | StmtResult Sema::ActOnOpenMPSectionDirective(Stmt *AStmt, |
| 4543 | SourceLocation StartLoc, |
| 4544 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4545 | if (!AStmt) |
| 4546 | return StmtError(); |
| 4547 | |
| 4548 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4549 | |
| 4550 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4551 | DSAStack->setParentCancelRegion(DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4552 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4553 | return OMPSectionDirective::Create(Context, StartLoc, EndLoc, AStmt, |
| 4554 | DSAStack->isCancelRegion()); |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 4555 | } |
| 4556 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4557 | StmtResult Sema::ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 4558 | Stmt *AStmt, |
| 4559 | SourceLocation StartLoc, |
| 4560 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4561 | if (!AStmt) |
| 4562 | return StmtError(); |
| 4563 | |
| 4564 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4565 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4566 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | 74a05c9 | 2014-07-15 02:55:09 +0000 | [diff] [blame] | 4567 | |
Alexey Bataev | 3255bf3 | 2015-01-19 05:20:46 +0000 | [diff] [blame] | 4568 | // OpenMP [2.7.3, single Construct, Restrictions] |
| 4569 | // The copyprivate clause must not be used with the nowait clause. |
| 4570 | OMPClause *Nowait = nullptr; |
| 4571 | OMPClause *Copyprivate = nullptr; |
| 4572 | for (auto *Clause : Clauses) { |
| 4573 | if (Clause->getClauseKind() == OMPC_nowait) |
| 4574 | Nowait = Clause; |
| 4575 | else if (Clause->getClauseKind() == OMPC_copyprivate) |
| 4576 | Copyprivate = Clause; |
| 4577 | if (Copyprivate && Nowait) { |
| 4578 | Diag(Copyprivate->getLocStart(), |
| 4579 | diag::err_omp_single_copyprivate_with_nowait); |
| 4580 | Diag(Nowait->getLocStart(), diag::note_omp_nowait_clause_here); |
| 4581 | return StmtError(); |
| 4582 | } |
| 4583 | } |
| 4584 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 4585 | return OMPSingleDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 4586 | } |
| 4587 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4588 | StmtResult Sema::ActOnOpenMPMasterDirective(Stmt *AStmt, |
| 4589 | SourceLocation StartLoc, |
| 4590 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4591 | if (!AStmt) |
| 4592 | return StmtError(); |
| 4593 | |
| 4594 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 4595 | |
| 4596 | getCurFunction()->setHasBranchProtectedScope(); |
| 4597 | |
| 4598 | return OMPMasterDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4599 | } |
| 4600 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4601 | StmtResult Sema::ActOnOpenMPCriticalDirective( |
| 4602 | const DeclarationNameInfo &DirName, ArrayRef<OMPClause *> Clauses, |
| 4603 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4604 | if (!AStmt) |
| 4605 | return StmtError(); |
| 4606 | |
| 4607 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4608 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4609 | bool ErrorFound = false; |
| 4610 | llvm::APSInt Hint; |
| 4611 | SourceLocation HintLoc; |
| 4612 | bool DependentHint = false; |
| 4613 | for (auto *C : Clauses) { |
| 4614 | if (C->getClauseKind() == OMPC_hint) { |
| 4615 | if (!DirName.getName()) { |
| 4616 | Diag(C->getLocStart(), diag::err_omp_hint_clause_no_name); |
| 4617 | ErrorFound = true; |
| 4618 | } |
| 4619 | Expr *E = cast<OMPHintClause>(C)->getHint(); |
| 4620 | if (E->isTypeDependent() || E->isValueDependent() || |
| 4621 | E->isInstantiationDependent()) |
| 4622 | DependentHint = true; |
| 4623 | else { |
| 4624 | Hint = E->EvaluateKnownConstInt(Context); |
| 4625 | HintLoc = C->getLocStart(); |
| 4626 | } |
| 4627 | } |
| 4628 | } |
| 4629 | if (ErrorFound) |
| 4630 | return StmtError(); |
| 4631 | auto Pair = DSAStack->getCriticalWithHint(DirName); |
| 4632 | if (Pair.first && DirName.getName() && !DependentHint) { |
| 4633 | if (llvm::APSInt::compareValues(Hint, Pair.second) != 0) { |
| 4634 | Diag(StartLoc, diag::err_omp_critical_with_hint); |
| 4635 | if (HintLoc.isValid()) { |
| 4636 | Diag(HintLoc, diag::note_omp_critical_hint_here) |
| 4637 | << 0 << Hint.toString(/*Radix=*/10, /*Signed=*/false); |
| 4638 | } else |
| 4639 | Diag(StartLoc, diag::note_omp_critical_no_hint) << 0; |
| 4640 | if (auto *C = Pair.first->getSingleClause<OMPHintClause>()) { |
| 4641 | Diag(C->getLocStart(), diag::note_omp_critical_hint_here) |
| 4642 | << 1 |
| 4643 | << C->getHint()->EvaluateKnownConstInt(Context).toString( |
| 4644 | /*Radix=*/10, /*Signed=*/false); |
| 4645 | } else |
| 4646 | Diag(Pair.first->getLocStart(), diag::note_omp_critical_no_hint) << 1; |
| 4647 | } |
| 4648 | } |
| 4649 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4650 | getCurFunction()->setHasBranchProtectedScope(); |
| 4651 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 4652 | auto *Dir = OMPCriticalDirective::Create(Context, DirName, StartLoc, EndLoc, |
| 4653 | Clauses, AStmt); |
| 4654 | if (!Pair.first && DirName.getName() && !DependentHint) |
| 4655 | DSAStack->addCriticalWithHint(Dir, Hint); |
| 4656 | return Dir; |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 4657 | } |
| 4658 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4659 | StmtResult Sema::ActOnOpenMPParallelForDirective( |
| 4660 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4661 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4662 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4663 | if (!AStmt) |
| 4664 | return StmtError(); |
| 4665 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4666 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4667 | // 1.2.2 OpenMP Language Terminology |
| 4668 | // Structured block - An executable statement with a single entry at the |
| 4669 | // top and a single exit at the bottom. |
| 4670 | // The point of exit cannot be a branch out of the structured block. |
| 4671 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4672 | CS->getCapturedDecl()->setNothrow(); |
| 4673 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4674 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4675 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4676 | // define the nested loops number. |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4677 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4678 | CheckOpenMPLoop(OMPD_parallel_for, getCollapseNumberExpr(Clauses), |
| 4679 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4680 | VarsWithImplicitDSA, B); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4681 | if (NestedLoopCount == 0) |
| 4682 | return StmtError(); |
| 4683 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4684 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 4685 | "omp parallel for loop exprs were not built"); |
| 4686 | |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4687 | if (!CurContext->isDependentContext()) { |
| 4688 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4689 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4690 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4691 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4692 | B.NumIterations, *this, CurScope, |
| 4693 | DSAStack)) |
Alexey Bataev | 54acd40 | 2015-08-04 11:18:19 +0000 | [diff] [blame] | 4694 | return StmtError(); |
| 4695 | } |
| 4696 | } |
| 4697 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4698 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4699 | return OMPParallelForDirective::Create(Context, StartLoc, EndLoc, |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4700 | NestedLoopCount, Clauses, AStmt, B, |
| 4701 | DSAStack->isCancelRegion()); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 4702 | } |
| 4703 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4704 | StmtResult Sema::ActOnOpenMPParallelForSimdDirective( |
| 4705 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 4706 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 4707 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4708 | if (!AStmt) |
| 4709 | return StmtError(); |
| 4710 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4711 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 4712 | // 1.2.2 OpenMP Language Terminology |
| 4713 | // Structured block - An executable statement with a single entry at the |
| 4714 | // top and a single exit at the bottom. |
| 4715 | // The point of exit cannot be a branch out of the structured block. |
| 4716 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4717 | CS->getCapturedDecl()->setNothrow(); |
| 4718 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4719 | OMPLoopDirective::HelperExprs B; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4720 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 4721 | // define the nested loops number. |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4722 | unsigned NestedLoopCount = |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 4723 | CheckOpenMPLoop(OMPD_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 4724 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 4725 | VarsWithImplicitDSA, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4726 | if (NestedLoopCount == 0) |
| 4727 | return StmtError(); |
| 4728 | |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4729 | if (!CurContext->isDependentContext()) { |
| 4730 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 4731 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4732 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4733 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 4734 | B.NumIterations, *this, CurScope, |
| 4735 | DSAStack)) |
Alexey Bataev | 3b5b5c4 | 2015-06-18 10:10:12 +0000 | [diff] [blame] | 4736 | return StmtError(); |
| 4737 | } |
| 4738 | } |
| 4739 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 4740 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 4741 | return StmtError(); |
| 4742 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4743 | getCurFunction()->setHasBranchProtectedScope(); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 4744 | return OMPParallelForSimdDirective::Create( |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 4745 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 4746 | } |
| 4747 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4748 | StmtResult |
| 4749 | Sema::ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 4750 | Stmt *AStmt, SourceLocation StartLoc, |
| 4751 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4752 | if (!AStmt) |
| 4753 | return StmtError(); |
| 4754 | |
| 4755 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4756 | auto BaseStmt = AStmt; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4757 | while (auto *CS = dyn_cast_or_null<CapturedStmt>(BaseStmt)) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4758 | BaseStmt = CS->getCapturedStmt(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4759 | if (auto *C = dyn_cast_or_null<CompoundStmt>(BaseStmt)) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4760 | auto S = C->children(); |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4761 | if (S.begin() == S.end()) |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4762 | return StmtError(); |
| 4763 | // All associated statements must be '#pragma omp section' except for |
| 4764 | // the first one. |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 4765 | for (Stmt *SectionStmt : llvm::make_range(std::next(S.begin()), S.end())) { |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4766 | if (!SectionStmt || !isa<OMPSectionDirective>(SectionStmt)) { |
| 4767 | if (SectionStmt) |
| 4768 | Diag(SectionStmt->getLocStart(), |
| 4769 | diag::err_omp_parallel_sections_substmt_not_section); |
| 4770 | return StmtError(); |
| 4771 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4772 | cast<OMPSectionDirective>(SectionStmt) |
| 4773 | ->setHasCancel(DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4774 | } |
| 4775 | } else { |
| 4776 | Diag(AStmt->getLocStart(), |
| 4777 | diag::err_omp_parallel_sections_not_compound_stmt); |
| 4778 | return StmtError(); |
| 4779 | } |
| 4780 | |
| 4781 | getCurFunction()->setHasBranchProtectedScope(); |
| 4782 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4783 | return OMPParallelSectionsDirective::Create( |
| 4784 | Context, StartLoc, EndLoc, Clauses, AStmt, DSAStack->isCancelRegion()); |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 4785 | } |
| 4786 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4787 | StmtResult Sema::ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 4788 | Stmt *AStmt, SourceLocation StartLoc, |
| 4789 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4790 | if (!AStmt) |
| 4791 | return StmtError(); |
| 4792 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 4793 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4794 | // 1.2.2 OpenMP Language Terminology |
| 4795 | // Structured block - An executable statement with a single entry at the |
| 4796 | // top and a single exit at the bottom. |
| 4797 | // The point of exit cannot be a branch out of the structured block. |
| 4798 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 4799 | CS->getCapturedDecl()->setNothrow(); |
| 4800 | |
| 4801 | getCurFunction()->setHasBranchProtectedScope(); |
| 4802 | |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 4803 | return OMPTaskDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
| 4804 | DSAStack->isCancelRegion()); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 4805 | } |
| 4806 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 4807 | StmtResult Sema::ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 4808 | SourceLocation EndLoc) { |
| 4809 | return OMPTaskyieldDirective::Create(Context, StartLoc, EndLoc); |
| 4810 | } |
| 4811 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 4812 | StmtResult Sema::ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 4813 | SourceLocation EndLoc) { |
| 4814 | return OMPBarrierDirective::Create(Context, StartLoc, EndLoc); |
| 4815 | } |
| 4816 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 4817 | StmtResult Sema::ActOnOpenMPTaskwaitDirective(SourceLocation StartLoc, |
| 4818 | SourceLocation EndLoc) { |
| 4819 | return OMPTaskwaitDirective::Create(Context, StartLoc, EndLoc); |
| 4820 | } |
| 4821 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4822 | StmtResult Sema::ActOnOpenMPTaskgroupDirective(Stmt *AStmt, |
| 4823 | SourceLocation StartLoc, |
| 4824 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 4825 | if (!AStmt) |
| 4826 | return StmtError(); |
| 4827 | |
| 4828 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 4829 | |
| 4830 | getCurFunction()->setHasBranchProtectedScope(); |
| 4831 | |
| 4832 | return OMPTaskgroupDirective::Create(Context, StartLoc, EndLoc, AStmt); |
| 4833 | } |
| 4834 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 4835 | StmtResult Sema::ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 4836 | SourceLocation StartLoc, |
| 4837 | SourceLocation EndLoc) { |
| 4838 | assert(Clauses.size() <= 1 && "Extra clauses in flush directive"); |
| 4839 | return OMPFlushDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 4840 | } |
| 4841 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4842 | StmtResult Sema::ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 4843 | Stmt *AStmt, |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4844 | SourceLocation StartLoc, |
| 4845 | SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4846 | OMPClause *DependFound = nullptr; |
| 4847 | OMPClause *DependSourceClause = nullptr; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4848 | OMPClause *DependSinkClause = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4849 | bool ErrorFound = false; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4850 | OMPThreadsClause *TC = nullptr; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4851 | OMPSIMDClause *SC = nullptr; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4852 | for (auto *C : Clauses) { |
| 4853 | if (auto *DC = dyn_cast<OMPDependClause>(C)) { |
| 4854 | DependFound = C; |
| 4855 | if (DC->getDependencyKind() == OMPC_DEPEND_source) { |
| 4856 | if (DependSourceClause) { |
| 4857 | Diag(C->getLocStart(), diag::err_omp_more_one_clause) |
| 4858 | << getOpenMPDirectiveName(OMPD_ordered) |
| 4859 | << getOpenMPClauseName(OMPC_depend) << 2; |
| 4860 | ErrorFound = true; |
| 4861 | } else |
| 4862 | DependSourceClause = C; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 4863 | if (DependSinkClause) { |
| 4864 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4865 | << 0; |
| 4866 | ErrorFound = true; |
| 4867 | } |
| 4868 | } else if (DC->getDependencyKind() == OMPC_DEPEND_sink) { |
| 4869 | if (DependSourceClause) { |
| 4870 | Diag(C->getLocStart(), diag::err_omp_depend_sink_source_not_allowed) |
| 4871 | << 1; |
| 4872 | ErrorFound = true; |
| 4873 | } |
| 4874 | DependSinkClause = C; |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4875 | } |
| 4876 | } else if (C->getClauseKind() == OMPC_threads) |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4877 | TC = cast<OMPThreadsClause>(C); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4878 | else if (C->getClauseKind() == OMPC_simd) |
| 4879 | SC = cast<OMPSIMDClause>(C); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4880 | } |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4881 | if (!ErrorFound && !SC && |
| 4882 | isOpenMPSimdDirective(DSAStack->getParentDirective())) { |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4883 | // OpenMP [2.8.1,simd Construct, Restrictions] |
| 4884 | // An ordered construct with the simd clause is the only OpenMP construct |
| 4885 | // that can appear in the simd region. |
| 4886 | Diag(StartLoc, diag::err_omp_prohibited_region_simd); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4887 | ErrorFound = true; |
| 4888 | } else if (DependFound && (TC || SC)) { |
| 4889 | Diag(DependFound->getLocStart(), diag::err_omp_depend_clause_thread_simd) |
| 4890 | << getOpenMPClauseName(TC ? TC->getClauseKind() : SC->getClauseKind()); |
| 4891 | ErrorFound = true; |
| 4892 | } else if (DependFound && !DSAStack->getParentOrderedRegionParam()) { |
| 4893 | Diag(DependFound->getLocStart(), |
| 4894 | diag::err_omp_ordered_directive_without_param); |
| 4895 | ErrorFound = true; |
| 4896 | } else if (TC || Clauses.empty()) { |
| 4897 | if (auto *Param = DSAStack->getParentOrderedRegionParam()) { |
| 4898 | SourceLocation ErrLoc = TC ? TC->getLocStart() : StartLoc; |
| 4899 | Diag(ErrLoc, diag::err_omp_ordered_directive_with_param) |
| 4900 | << (TC != nullptr); |
| 4901 | Diag(Param->getLocStart(), diag::note_omp_ordered_param); |
| 4902 | ErrorFound = true; |
| 4903 | } |
| 4904 | } |
| 4905 | if ((!AStmt && !DependFound) || ErrorFound) |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4906 | return StmtError(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 4907 | |
| 4908 | if (AStmt) { |
| 4909 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 4910 | |
| 4911 | getCurFunction()->setHasBranchProtectedScope(); |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 4912 | } |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 4913 | |
| 4914 | return OMPOrderedDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4917 | namespace { |
| 4918 | /// \brief Helper class for checking expression in 'omp atomic [update]' |
| 4919 | /// construct. |
| 4920 | class OpenMPAtomicUpdateChecker { |
| 4921 | /// \brief Error results for atomic update expressions. |
| 4922 | enum ExprAnalysisErrorCode { |
| 4923 | /// \brief A statement is not an expression statement. |
| 4924 | NotAnExpression, |
| 4925 | /// \brief Expression is not builtin binary or unary operation. |
| 4926 | NotABinaryOrUnaryExpression, |
| 4927 | /// \brief Unary operation is not post-/pre- increment/decrement operation. |
| 4928 | NotAnUnaryIncDecExpression, |
| 4929 | /// \brief An expression is not of scalar type. |
| 4930 | NotAScalarType, |
| 4931 | /// \brief A binary operation is not an assignment operation. |
| 4932 | NotAnAssignmentOp, |
| 4933 | /// \brief RHS part of the binary operation is not a binary expression. |
| 4934 | NotABinaryExpression, |
| 4935 | /// \brief RHS part is not additive/multiplicative/shift/biwise binary |
| 4936 | /// expression. |
| 4937 | NotABinaryOperator, |
| 4938 | /// \brief RHS binary operation does not have reference to the updated LHS |
| 4939 | /// part. |
| 4940 | NotAnUpdateExpression, |
| 4941 | /// \brief No errors is found. |
| 4942 | NoError |
| 4943 | }; |
| 4944 | /// \brief Reference to Sema. |
| 4945 | Sema &SemaRef; |
| 4946 | /// \brief A location for note diagnostics (when error is found). |
| 4947 | SourceLocation NoteLoc; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4948 | /// \brief 'x' lvalue part of the source atomic expression. |
| 4949 | Expr *X; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4950 | /// \brief 'expr' rvalue part of the source atomic expression. |
| 4951 | Expr *E; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4952 | /// \brief Helper expression of the form |
| 4953 | /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4954 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4955 | Expr *UpdateExpr; |
| 4956 | /// \brief Is 'x' a LHS in a RHS part of full update expression. It is |
| 4957 | /// important for non-associative operations. |
| 4958 | bool IsXLHSInRHSPart; |
| 4959 | BinaryOperatorKind Op; |
| 4960 | SourceLocation OpLoc; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4961 | /// \brief true if the source expression is a postfix unary operation, false |
| 4962 | /// if it is a prefix unary operation. |
| 4963 | bool IsPostfixUpdate; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4964 | |
| 4965 | public: |
| 4966 | OpenMPAtomicUpdateChecker(Sema &SemaRef) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4967 | : SemaRef(SemaRef), X(nullptr), E(nullptr), UpdateExpr(nullptr), |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4968 | IsXLHSInRHSPart(false), Op(BO_PtrMemD), IsPostfixUpdate(false) {} |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4969 | /// \brief Check specified statement that it is suitable for 'atomic update' |
| 4970 | /// constructs and extract 'x', 'expr' and Operation from the original |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4971 | /// expression. If DiagId and NoteId == 0, then only check is performed |
| 4972 | /// without error notification. |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4973 | /// \param DiagId Diagnostic which should be emitted if error is found. |
| 4974 | /// \param NoteId Diagnostic note for the main error message. |
| 4975 | /// \return true if statement is not an update expression, false otherwise. |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4976 | bool checkStatement(Stmt *S, unsigned DiagId = 0, unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4977 | /// \brief Return the 'x' lvalue part of the source atomic expression. |
| 4978 | Expr *getX() const { return X; } |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4979 | /// \brief Return the 'expr' rvalue part of the source atomic expression. |
| 4980 | Expr *getExpr() const { return E; } |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 4981 | /// \brief Return the update expression used in calculation of the updated |
| 4982 | /// value. Always has form 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' or |
| 4983 | /// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. |
| 4984 | Expr *getUpdateExpr() const { return UpdateExpr; } |
| 4985 | /// \brief Return true if 'x' is LHS in RHS part of full update expression, |
| 4986 | /// false otherwise. |
| 4987 | bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; } |
| 4988 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4989 | /// \brief true if the source expression is a postfix unary operation, false |
| 4990 | /// if it is a prefix unary operation. |
| 4991 | bool isPostfixUpdate() const { return IsPostfixUpdate; } |
| 4992 | |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4993 | private: |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 4994 | bool checkBinaryOperation(BinaryOperator *AtomicBinOp, unsigned DiagId = 0, |
| 4995 | unsigned NoteId = 0); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 4996 | }; |
| 4997 | } // namespace |
| 4998 | |
| 4999 | bool OpenMPAtomicUpdateChecker::checkBinaryOperation( |
| 5000 | BinaryOperator *AtomicBinOp, unsigned DiagId, unsigned NoteId) { |
| 5001 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5002 | SourceLocation ErrorLoc, NoteLoc; |
| 5003 | SourceRange ErrorRange, NoteRange; |
| 5004 | // Allowed constructs are: |
| 5005 | // x = x binop expr; |
| 5006 | // x = expr binop x; |
| 5007 | if (AtomicBinOp->getOpcode() == BO_Assign) { |
| 5008 | X = AtomicBinOp->getLHS(); |
| 5009 | if (auto *AtomicInnerBinOp = dyn_cast<BinaryOperator>( |
| 5010 | AtomicBinOp->getRHS()->IgnoreParenImpCasts())) { |
| 5011 | if (AtomicInnerBinOp->isMultiplicativeOp() || |
| 5012 | AtomicInnerBinOp->isAdditiveOp() || AtomicInnerBinOp->isShiftOp() || |
| 5013 | AtomicInnerBinOp->isBitwiseOp()) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5014 | Op = AtomicInnerBinOp->getOpcode(); |
| 5015 | OpLoc = AtomicInnerBinOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5016 | auto *LHS = AtomicInnerBinOp->getLHS(); |
| 5017 | auto *RHS = AtomicInnerBinOp->getRHS(); |
| 5018 | llvm::FoldingSetNodeID XId, LHSId, RHSId; |
| 5019 | X->IgnoreParenImpCasts()->Profile(XId, SemaRef.getASTContext(), |
| 5020 | /*Canonical=*/true); |
| 5021 | LHS->IgnoreParenImpCasts()->Profile(LHSId, SemaRef.getASTContext(), |
| 5022 | /*Canonical=*/true); |
| 5023 | RHS->IgnoreParenImpCasts()->Profile(RHSId, SemaRef.getASTContext(), |
| 5024 | /*Canonical=*/true); |
| 5025 | if (XId == LHSId) { |
| 5026 | E = RHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5027 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5028 | } else if (XId == RHSId) { |
| 5029 | E = LHS; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5030 | IsXLHSInRHSPart = false; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5031 | } else { |
| 5032 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5033 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5034 | NoteLoc = X->getExprLoc(); |
| 5035 | NoteRange = X->getSourceRange(); |
| 5036 | ErrorFound = NotAnUpdateExpression; |
| 5037 | } |
| 5038 | } else { |
| 5039 | ErrorLoc = AtomicInnerBinOp->getExprLoc(); |
| 5040 | ErrorRange = AtomicInnerBinOp->getSourceRange(); |
| 5041 | NoteLoc = AtomicInnerBinOp->getOperatorLoc(); |
| 5042 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5043 | ErrorFound = NotABinaryOperator; |
| 5044 | } |
| 5045 | } else { |
| 5046 | NoteLoc = ErrorLoc = AtomicBinOp->getRHS()->getExprLoc(); |
| 5047 | NoteRange = ErrorRange = AtomicBinOp->getRHS()->getSourceRange(); |
| 5048 | ErrorFound = NotABinaryExpression; |
| 5049 | } |
| 5050 | } else { |
| 5051 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5052 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5053 | NoteLoc = AtomicBinOp->getOperatorLoc(); |
| 5054 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5055 | ErrorFound = NotAnAssignmentOp; |
| 5056 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5057 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5058 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5059 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5060 | return true; |
| 5061 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5062 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5063 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId, |
| 5067 | unsigned NoteId) { |
| 5068 | ExprAnalysisErrorCode ErrorFound = NoError; |
| 5069 | SourceLocation ErrorLoc, NoteLoc; |
| 5070 | SourceRange ErrorRange, NoteRange; |
| 5071 | // Allowed constructs are: |
| 5072 | // x++; |
| 5073 | // x--; |
| 5074 | // ++x; |
| 5075 | // --x; |
| 5076 | // x binop= expr; |
| 5077 | // x = x binop expr; |
| 5078 | // x = expr binop x; |
| 5079 | if (auto *AtomicBody = dyn_cast<Expr>(S)) { |
| 5080 | AtomicBody = AtomicBody->IgnoreParenImpCasts(); |
| 5081 | if (AtomicBody->getType()->isScalarType() || |
| 5082 | AtomicBody->isInstantiationDependent()) { |
| 5083 | if (auto *AtomicCompAssignOp = dyn_cast<CompoundAssignOperator>( |
| 5084 | AtomicBody->IgnoreParenImpCasts())) { |
| 5085 | // Check for Compound Assignment Operation |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5086 | Op = BinaryOperator::getOpForCompoundAssignment( |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5087 | AtomicCompAssignOp->getOpcode()); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5088 | OpLoc = AtomicCompAssignOp->getOperatorLoc(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5089 | E = AtomicCompAssignOp->getRHS(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5090 | X = AtomicCompAssignOp->getLHS()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5091 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5092 | } else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>( |
| 5093 | AtomicBody->IgnoreParenImpCasts())) { |
| 5094 | // Check for Binary Operation |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5095 | if (checkBinaryOperation(AtomicBinOp, DiagId, NoteId)) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5096 | return true; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5097 | } else if (auto *AtomicUnaryOp = dyn_cast<UnaryOperator>( |
| 5098 | AtomicBody->IgnoreParenImpCasts())) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5099 | // Check for Unary Operation |
| 5100 | if (AtomicUnaryOp->isIncrementDecrementOp()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5101 | IsPostfixUpdate = AtomicUnaryOp->isPostfix(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5102 | Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub; |
| 5103 | OpLoc = AtomicUnaryOp->getOperatorLoc(); |
Kelvin Li | 4f161cf | 2016-07-20 19:41:17 +0000 | [diff] [blame] | 5104 | X = AtomicUnaryOp->getSubExpr()->IgnoreParens(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5105 | E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get(); |
| 5106 | IsXLHSInRHSPart = true; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5107 | } else { |
| 5108 | ErrorFound = NotAnUnaryIncDecExpression; |
| 5109 | ErrorLoc = AtomicUnaryOp->getExprLoc(); |
| 5110 | ErrorRange = AtomicUnaryOp->getSourceRange(); |
| 5111 | NoteLoc = AtomicUnaryOp->getOperatorLoc(); |
| 5112 | NoteRange = SourceRange(NoteLoc, NoteLoc); |
| 5113 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5114 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5115 | ErrorFound = NotABinaryOrUnaryExpression; |
| 5116 | NoteLoc = ErrorLoc = AtomicBody->getExprLoc(); |
| 5117 | NoteRange = ErrorRange = AtomicBody->getSourceRange(); |
| 5118 | } |
| 5119 | } else { |
| 5120 | ErrorFound = NotAScalarType; |
| 5121 | NoteLoc = ErrorLoc = AtomicBody->getLocStart(); |
| 5122 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5123 | } |
| 5124 | } else { |
| 5125 | ErrorFound = NotAnExpression; |
| 5126 | NoteLoc = ErrorLoc = S->getLocStart(); |
| 5127 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
| 5128 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5129 | if (ErrorFound != NoError && DiagId != 0 && NoteId != 0) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5130 | SemaRef.Diag(ErrorLoc, DiagId) << ErrorRange; |
| 5131 | SemaRef.Diag(NoteLoc, NoteId) << ErrorFound << NoteRange; |
| 5132 | return true; |
| 5133 | } else if (SemaRef.CurContext->isDependentContext()) |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5134 | E = X = UpdateExpr = nullptr; |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5135 | if (ErrorFound == NoError && E && X) { |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5136 | // Build an update expression of form 'OpaqueValueExpr(x) binop |
| 5137 | // OpaqueValueExpr(expr)' or 'OpaqueValueExpr(expr) binop |
| 5138 | // OpaqueValueExpr(x)' and then cast it to the type of the 'x' expression. |
| 5139 | auto *OVEX = new (SemaRef.getASTContext()) |
| 5140 | OpaqueValueExpr(X->getExprLoc(), X->getType(), VK_RValue); |
| 5141 | auto *OVEExpr = new (SemaRef.getASTContext()) |
| 5142 | OpaqueValueExpr(E->getExprLoc(), E->getType(), VK_RValue); |
| 5143 | auto Update = |
| 5144 | SemaRef.CreateBuiltinBinOp(OpLoc, Op, IsXLHSInRHSPart ? OVEX : OVEExpr, |
| 5145 | IsXLHSInRHSPart ? OVEExpr : OVEX); |
| 5146 | if (Update.isInvalid()) |
| 5147 | return true; |
| 5148 | Update = SemaRef.PerformImplicitConversion(Update.get(), X->getType(), |
| 5149 | Sema::AA_Casting); |
| 5150 | if (Update.isInvalid()) |
| 5151 | return true; |
| 5152 | UpdateExpr = Update.get(); |
| 5153 | } |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5154 | return ErrorFound != NoError; |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5155 | } |
| 5156 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5157 | StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 5158 | Stmt *AStmt, |
| 5159 | SourceLocation StartLoc, |
| 5160 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5161 | if (!AStmt) |
| 5162 | return StmtError(); |
| 5163 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5164 | auto *CS = cast<CapturedStmt>(AStmt); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5165 | // 1.2.2 OpenMP Language Terminology |
| 5166 | // Structured block - An executable statement with a single entry at the |
| 5167 | // top and a single exit at the bottom. |
| 5168 | // The point of exit cannot be a branch out of the structured block. |
| 5169 | // longjmp() and throw() must not violate the entry/exit criteria. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5170 | OpenMPClauseKind AtomicKind = OMPC_unknown; |
| 5171 | SourceLocation AtomicKindLoc; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5172 | for (auto *C : Clauses) { |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5173 | if (C->getClauseKind() == OMPC_read || C->getClauseKind() == OMPC_write || |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5174 | C->getClauseKind() == OMPC_update || |
| 5175 | C->getClauseKind() == OMPC_capture) { |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5176 | if (AtomicKind != OMPC_unknown) { |
| 5177 | Diag(C->getLocStart(), diag::err_omp_atomic_several_clauses) |
| 5178 | << SourceRange(C->getLocStart(), C->getLocEnd()); |
| 5179 | Diag(AtomicKindLoc, diag::note_omp_atomic_previous_clause) |
| 5180 | << getOpenMPClauseName(AtomicKind); |
| 5181 | } else { |
| 5182 | AtomicKind = C->getClauseKind(); |
| 5183 | AtomicKindLoc = C->getLocStart(); |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 5184 | } |
| 5185 | } |
| 5186 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5187 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5188 | auto Body = CS->getCapturedStmt(); |
Alexey Bataev | 10fec57 | 2015-03-11 04:48:56 +0000 | [diff] [blame] | 5189 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Body)) |
| 5190 | Body = EWC->getSubExpr(); |
| 5191 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5192 | Expr *X = nullptr; |
| 5193 | Expr *V = nullptr; |
| 5194 | Expr *E = nullptr; |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5195 | Expr *UE = nullptr; |
| 5196 | bool IsXLHSInRHSPart = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5197 | bool IsPostfixUpdate = false; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5198 | // OpenMP [2.12.6, atomic Construct] |
| 5199 | // In the next expressions: |
| 5200 | // * x and v (as applicable) are both l-value expressions with scalar type. |
| 5201 | // * During the execution of an atomic region, multiple syntactic |
| 5202 | // occurrences of x must designate the same storage location. |
| 5203 | // * Neither of v and expr (as applicable) may access the storage location |
| 5204 | // designated by x. |
| 5205 | // * Neither of x and expr (as applicable) may access the storage location |
| 5206 | // designated by v. |
| 5207 | // * expr is an expression with scalar type. |
| 5208 | // * binop is one of +, *, -, /, &, ^, |, <<, or >>. |
| 5209 | // * binop, binop=, ++, and -- are not overloaded operators. |
| 5210 | // * The expression x binop expr must be numerically equivalent to x binop |
| 5211 | // (expr). This requirement is satisfied if the operators in expr have |
| 5212 | // precedence greater than binop, or by using parentheses around expr or |
| 5213 | // subexpressions of expr. |
| 5214 | // * The expression expr binop x must be numerically equivalent to (expr) |
| 5215 | // binop x. This requirement is satisfied if the operators in expr have |
| 5216 | // precedence equal to or greater than binop, or by using parentheses around |
| 5217 | // expr or subexpressions of expr. |
| 5218 | // * For forms that allow multiple occurrences of x, the number of times |
| 5219 | // that x is evaluated is unspecified. |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5220 | if (AtomicKind == OMPC_read) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5221 | enum { |
| 5222 | NotAnExpression, |
| 5223 | NotAnAssignmentOp, |
| 5224 | NotAScalarType, |
| 5225 | NotAnLValue, |
| 5226 | NoError |
| 5227 | } ErrorFound = NoError; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5228 | SourceLocation ErrorLoc, NoteLoc; |
| 5229 | SourceRange ErrorRange, NoteRange; |
| 5230 | // If clause is read: |
| 5231 | // v = x; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5232 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5233 | auto *AtomicBinOp = |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5234 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5235 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5236 | X = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5237 | V = AtomicBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5238 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5239 | (V->isInstantiationDependent() || V->getType()->isScalarType())) { |
| 5240 | if (!X->isLValue() || !V->isLValue()) { |
| 5241 | auto NotLValueExpr = X->isLValue() ? V : X; |
| 5242 | ErrorFound = NotAnLValue; |
| 5243 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5244 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5245 | NoteLoc = NotLValueExpr->getExprLoc(); |
| 5246 | NoteRange = NotLValueExpr->getSourceRange(); |
| 5247 | } |
| 5248 | } else if (!X->isInstantiationDependent() || |
| 5249 | !V->isInstantiationDependent()) { |
| 5250 | auto NotScalarExpr = |
| 5251 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5252 | ? V |
| 5253 | : X; |
| 5254 | ErrorFound = NotAScalarType; |
| 5255 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5256 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5257 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5258 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5259 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5260 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5261 | ErrorFound = NotAnAssignmentOp; |
| 5262 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5263 | ErrorRange = AtomicBody->getSourceRange(); |
| 5264 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5265 | : AtomicBody->getExprLoc(); |
| 5266 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5267 | : AtomicBody->getSourceRange(); |
| 5268 | } |
| 5269 | } else { |
| 5270 | ErrorFound = NotAnExpression; |
| 5271 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5272 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5273 | } |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5274 | if (ErrorFound != NoError) { |
| 5275 | Diag(ErrorLoc, diag::err_omp_atomic_read_not_expression_statement) |
| 5276 | << ErrorRange; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5277 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5278 | << NoteRange; |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5279 | return StmtError(); |
| 5280 | } else if (CurContext->isDependentContext()) |
| 5281 | V = X = nullptr; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5282 | } else if (AtomicKind == OMPC_write) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5283 | enum { |
| 5284 | NotAnExpression, |
| 5285 | NotAnAssignmentOp, |
| 5286 | NotAScalarType, |
| 5287 | NotAnLValue, |
| 5288 | NoError |
| 5289 | } ErrorFound = NoError; |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5290 | SourceLocation ErrorLoc, NoteLoc; |
| 5291 | SourceRange ErrorRange, NoteRange; |
| 5292 | // If clause is write: |
| 5293 | // x = expr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5294 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5295 | auto *AtomicBinOp = |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5296 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5297 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
Alexey Bataev | b832926 | 2015-02-27 06:33:30 +0000 | [diff] [blame] | 5298 | X = AtomicBinOp->getLHS(); |
| 5299 | E = AtomicBinOp->getRHS(); |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5300 | if ((X->isInstantiationDependent() || X->getType()->isScalarType()) && |
| 5301 | (E->isInstantiationDependent() || E->getType()->isScalarType())) { |
| 5302 | if (!X->isLValue()) { |
| 5303 | ErrorFound = NotAnLValue; |
| 5304 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5305 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5306 | NoteLoc = X->getExprLoc(); |
| 5307 | NoteRange = X->getSourceRange(); |
| 5308 | } |
| 5309 | } else if (!X->isInstantiationDependent() || |
| 5310 | !E->isInstantiationDependent()) { |
| 5311 | auto NotScalarExpr = |
| 5312 | (X->isInstantiationDependent() || X->getType()->isScalarType()) |
| 5313 | ? E |
| 5314 | : X; |
| 5315 | ErrorFound = NotAScalarType; |
| 5316 | ErrorLoc = AtomicBinOp->getExprLoc(); |
| 5317 | ErrorRange = AtomicBinOp->getSourceRange(); |
| 5318 | NoteLoc = NotScalarExpr->getExprLoc(); |
| 5319 | NoteRange = NotScalarExpr->getSourceRange(); |
| 5320 | } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5321 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5322 | ErrorFound = NotAnAssignmentOp; |
| 5323 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5324 | ErrorRange = AtomicBody->getSourceRange(); |
| 5325 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5326 | : AtomicBody->getExprLoc(); |
| 5327 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5328 | : AtomicBody->getSourceRange(); |
| 5329 | } |
| 5330 | } else { |
| 5331 | ErrorFound = NotAnExpression; |
| 5332 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5333 | NoteRange = ErrorRange = SourceRange(NoteLoc, NoteLoc); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5334 | } |
Alexey Bataev | f33eba6 | 2014-11-28 07:21:40 +0000 | [diff] [blame] | 5335 | if (ErrorFound != NoError) { |
| 5336 | Diag(ErrorLoc, diag::err_omp_atomic_write_not_expression_statement) |
| 5337 | << ErrorRange; |
| 5338 | Diag(NoteLoc, diag::note_omp_atomic_read_write) << ErrorFound |
| 5339 | << NoteRange; |
| 5340 | return StmtError(); |
| 5341 | } else if (CurContext->isDependentContext()) |
| 5342 | E = X = nullptr; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5343 | } else if (AtomicKind == OMPC_update || AtomicKind == OMPC_unknown) { |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5344 | // If clause is update: |
| 5345 | // x++; |
| 5346 | // x--; |
| 5347 | // ++x; |
| 5348 | // --x; |
| 5349 | // x binop= expr; |
| 5350 | // x = x binop expr; |
| 5351 | // x = expr binop x; |
| 5352 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5353 | if (Checker.checkStatement( |
| 5354 | Body, (AtomicKind == OMPC_update) |
| 5355 | ? diag::err_omp_atomic_update_not_expression_statement |
| 5356 | : diag::err_omp_atomic_not_expression_statement, |
| 5357 | diag::note_omp_atomic_update)) |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5358 | return StmtError(); |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 5359 | if (!CurContext->isDependentContext()) { |
| 5360 | E = Checker.getExpr(); |
| 5361 | X = Checker.getX(); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 5362 | UE = Checker.getUpdateExpr(); |
| 5363 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 5364 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5365 | } else if (AtomicKind == OMPC_capture) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5366 | enum { |
| 5367 | NotAnAssignmentOp, |
| 5368 | NotACompoundStatement, |
| 5369 | NotTwoSubstatements, |
| 5370 | NotASpecificExpression, |
| 5371 | NoError |
| 5372 | } ErrorFound = NoError; |
| 5373 | SourceLocation ErrorLoc, NoteLoc; |
| 5374 | SourceRange ErrorRange, NoteRange; |
| 5375 | if (auto *AtomicBody = dyn_cast<Expr>(Body)) { |
| 5376 | // If clause is a capture: |
| 5377 | // v = x++; |
| 5378 | // v = x--; |
| 5379 | // v = ++x; |
| 5380 | // v = --x; |
| 5381 | // v = x binop= expr; |
| 5382 | // v = x = x binop expr; |
| 5383 | // v = x = expr binop x; |
| 5384 | auto *AtomicBinOp = |
| 5385 | dyn_cast<BinaryOperator>(AtomicBody->IgnoreParenImpCasts()); |
| 5386 | if (AtomicBinOp && AtomicBinOp->getOpcode() == BO_Assign) { |
| 5387 | V = AtomicBinOp->getLHS(); |
| 5388 | Body = AtomicBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5389 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5390 | if (Checker.checkStatement( |
| 5391 | Body, diag::err_omp_atomic_capture_not_expression_statement, |
| 5392 | diag::note_omp_atomic_update)) |
| 5393 | return StmtError(); |
| 5394 | E = Checker.getExpr(); |
| 5395 | X = Checker.getX(); |
| 5396 | UE = Checker.getUpdateExpr(); |
| 5397 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
| 5398 | IsPostfixUpdate = Checker.isPostfixUpdate(); |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5399 | } else if (!AtomicBody->isInstantiationDependent()) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5400 | ErrorLoc = AtomicBody->getExprLoc(); |
| 5401 | ErrorRange = AtomicBody->getSourceRange(); |
| 5402 | NoteLoc = AtomicBinOp ? AtomicBinOp->getOperatorLoc() |
| 5403 | : AtomicBody->getExprLoc(); |
| 5404 | NoteRange = AtomicBinOp ? AtomicBinOp->getSourceRange() |
| 5405 | : AtomicBody->getSourceRange(); |
| 5406 | ErrorFound = NotAnAssignmentOp; |
| 5407 | } |
| 5408 | if (ErrorFound != NoError) { |
| 5409 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_expression_statement) |
| 5410 | << ErrorRange; |
| 5411 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5412 | return StmtError(); |
| 5413 | } else if (CurContext->isDependentContext()) { |
| 5414 | UE = V = E = X = nullptr; |
| 5415 | } |
| 5416 | } else { |
| 5417 | // If clause is a capture: |
| 5418 | // { v = x; x = expr; } |
| 5419 | // { v = x; x++; } |
| 5420 | // { v = x; x--; } |
| 5421 | // { v = x; ++x; } |
| 5422 | // { v = x; --x; } |
| 5423 | // { v = x; x binop= expr; } |
| 5424 | // { v = x; x = x binop expr; } |
| 5425 | // { v = x; x = expr binop x; } |
| 5426 | // { x++; v = x; } |
| 5427 | // { x--; v = x; } |
| 5428 | // { ++x; v = x; } |
| 5429 | // { --x; v = x; } |
| 5430 | // { x binop= expr; v = x; } |
| 5431 | // { x = x binop expr; v = x; } |
| 5432 | // { x = expr binop x; v = x; } |
| 5433 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) { |
| 5434 | // Check that this is { expr1; expr2; } |
| 5435 | if (CS->size() == 2) { |
| 5436 | auto *First = CS->body_front(); |
| 5437 | auto *Second = CS->body_back(); |
| 5438 | if (auto *EWC = dyn_cast<ExprWithCleanups>(First)) |
| 5439 | First = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5440 | if (auto *EWC = dyn_cast<ExprWithCleanups>(Second)) |
| 5441 | Second = EWC->getSubExpr()->IgnoreParenImpCasts(); |
| 5442 | // Need to find what subexpression is 'v' and what is 'x'. |
| 5443 | OpenMPAtomicUpdateChecker Checker(*this); |
| 5444 | bool IsUpdateExprFound = !Checker.checkStatement(Second); |
| 5445 | BinaryOperator *BinOp = nullptr; |
| 5446 | if (IsUpdateExprFound) { |
| 5447 | BinOp = dyn_cast<BinaryOperator>(First); |
| 5448 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5449 | } |
| 5450 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5451 | // { v = x; x++; } |
| 5452 | // { v = x; x--; } |
| 5453 | // { v = x; ++x; } |
| 5454 | // { v = x; --x; } |
| 5455 | // { v = x; x binop= expr; } |
| 5456 | // { v = x; x = x binop expr; } |
| 5457 | // { v = x; x = expr binop x; } |
| 5458 | // Check that the first expression has form v = x. |
| 5459 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5460 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5461 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5462 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5463 | IsUpdateExprFound = XId == PossibleXId; |
| 5464 | if (IsUpdateExprFound) { |
| 5465 | V = BinOp->getLHS(); |
| 5466 | X = Checker.getX(); |
| 5467 | E = Checker.getExpr(); |
| 5468 | UE = Checker.getUpdateExpr(); |
| 5469 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5470 | IsPostfixUpdate = true; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5471 | } |
| 5472 | } |
| 5473 | if (!IsUpdateExprFound) { |
| 5474 | IsUpdateExprFound = !Checker.checkStatement(First); |
| 5475 | BinOp = nullptr; |
| 5476 | if (IsUpdateExprFound) { |
| 5477 | BinOp = dyn_cast<BinaryOperator>(Second); |
| 5478 | IsUpdateExprFound = BinOp && BinOp->getOpcode() == BO_Assign; |
| 5479 | } |
| 5480 | if (IsUpdateExprFound && !CurContext->isDependentContext()) { |
| 5481 | // { x++; v = x; } |
| 5482 | // { x--; v = x; } |
| 5483 | // { ++x; v = x; } |
| 5484 | // { --x; v = x; } |
| 5485 | // { x binop= expr; v = x; } |
| 5486 | // { x = x binop expr; v = x; } |
| 5487 | // { x = expr binop x; v = x; } |
| 5488 | // Check that the second expression has form v = x. |
| 5489 | auto *PossibleX = BinOp->getRHS()->IgnoreParenImpCasts(); |
| 5490 | llvm::FoldingSetNodeID XId, PossibleXId; |
| 5491 | Checker.getX()->Profile(XId, Context, /*Canonical=*/true); |
| 5492 | PossibleX->Profile(PossibleXId, Context, /*Canonical=*/true); |
| 5493 | IsUpdateExprFound = XId == PossibleXId; |
| 5494 | if (IsUpdateExprFound) { |
| 5495 | V = BinOp->getLHS(); |
| 5496 | X = Checker.getX(); |
| 5497 | E = Checker.getExpr(); |
| 5498 | UE = Checker.getUpdateExpr(); |
| 5499 | IsXLHSInRHSPart = Checker.isXLHSInRHSPart(); |
Alexey Bataev | 5e018f9 | 2015-04-23 06:35:10 +0000 | [diff] [blame] | 5500 | IsPostfixUpdate = false; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5501 | } |
| 5502 | } |
| 5503 | } |
| 5504 | if (!IsUpdateExprFound) { |
| 5505 | // { v = x; x = expr; } |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5506 | auto *FirstExpr = dyn_cast<Expr>(First); |
| 5507 | auto *SecondExpr = dyn_cast<Expr>(Second); |
| 5508 | if (!FirstExpr || !SecondExpr || |
| 5509 | !(FirstExpr->isInstantiationDependent() || |
| 5510 | SecondExpr->isInstantiationDependent())) { |
| 5511 | auto *FirstBinOp = dyn_cast<BinaryOperator>(First); |
| 5512 | if (!FirstBinOp || FirstBinOp->getOpcode() != BO_Assign) { |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5513 | ErrorFound = NotAnAssignmentOp; |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5514 | NoteLoc = ErrorLoc = FirstBinOp ? FirstBinOp->getOperatorLoc() |
| 5515 | : First->getLocStart(); |
| 5516 | NoteRange = ErrorRange = FirstBinOp |
| 5517 | ? FirstBinOp->getSourceRange() |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5518 | : SourceRange(ErrorLoc, ErrorLoc); |
| 5519 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5520 | auto *SecondBinOp = dyn_cast<BinaryOperator>(Second); |
| 5521 | if (!SecondBinOp || SecondBinOp->getOpcode() != BO_Assign) { |
| 5522 | ErrorFound = NotAnAssignmentOp; |
| 5523 | NoteLoc = ErrorLoc = SecondBinOp |
| 5524 | ? SecondBinOp->getOperatorLoc() |
| 5525 | : Second->getLocStart(); |
| 5526 | NoteRange = ErrorRange = |
| 5527 | SecondBinOp ? SecondBinOp->getSourceRange() |
| 5528 | : SourceRange(ErrorLoc, ErrorLoc); |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5529 | } else { |
Alexey Bataev | 5a19547 | 2015-09-04 12:55:50 +0000 | [diff] [blame] | 5530 | auto *PossibleXRHSInFirst = |
| 5531 | FirstBinOp->getRHS()->IgnoreParenImpCasts(); |
| 5532 | auto *PossibleXLHSInSecond = |
| 5533 | SecondBinOp->getLHS()->IgnoreParenImpCasts(); |
| 5534 | llvm::FoldingSetNodeID X1Id, X2Id; |
| 5535 | PossibleXRHSInFirst->Profile(X1Id, Context, |
| 5536 | /*Canonical=*/true); |
| 5537 | PossibleXLHSInSecond->Profile(X2Id, Context, |
| 5538 | /*Canonical=*/true); |
| 5539 | IsUpdateExprFound = X1Id == X2Id; |
| 5540 | if (IsUpdateExprFound) { |
| 5541 | V = FirstBinOp->getLHS(); |
| 5542 | X = SecondBinOp->getLHS(); |
| 5543 | E = SecondBinOp->getRHS(); |
| 5544 | UE = nullptr; |
| 5545 | IsXLHSInRHSPart = false; |
| 5546 | IsPostfixUpdate = true; |
| 5547 | } else { |
| 5548 | ErrorFound = NotASpecificExpression; |
| 5549 | ErrorLoc = FirstBinOp->getExprLoc(); |
| 5550 | ErrorRange = FirstBinOp->getSourceRange(); |
| 5551 | NoteLoc = SecondBinOp->getLHS()->getExprLoc(); |
| 5552 | NoteRange = SecondBinOp->getRHS()->getSourceRange(); |
| 5553 | } |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5554 | } |
| 5555 | } |
| 5556 | } |
| 5557 | } |
| 5558 | } else { |
| 5559 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5560 | NoteRange = ErrorRange = |
| 5561 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5562 | ErrorFound = NotTwoSubstatements; |
| 5563 | } |
| 5564 | } else { |
| 5565 | NoteLoc = ErrorLoc = Body->getLocStart(); |
| 5566 | NoteRange = ErrorRange = |
| 5567 | SourceRange(Body->getLocStart(), Body->getLocStart()); |
| 5568 | ErrorFound = NotACompoundStatement; |
| 5569 | } |
| 5570 | if (ErrorFound != NoError) { |
| 5571 | Diag(ErrorLoc, diag::err_omp_atomic_capture_not_compound_statement) |
| 5572 | << ErrorRange; |
| 5573 | Diag(NoteLoc, diag::note_omp_atomic_capture) << ErrorFound << NoteRange; |
| 5574 | return StmtError(); |
| 5575 | } else if (CurContext->isDependentContext()) { |
| 5576 | UE = V = E = X = nullptr; |
| 5577 | } |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 5578 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 5579 | } |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5580 | |
| 5581 | getCurFunction()->setHasBranchProtectedScope(); |
| 5582 | |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 5583 | return OMPAtomicDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt, |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 5584 | X, V, E, UE, IsXLHSInRHSPart, |
| 5585 | IsPostfixUpdate); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 5586 | } |
| 5587 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5588 | StmtResult Sema::ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 5589 | Stmt *AStmt, |
| 5590 | SourceLocation StartLoc, |
| 5591 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5592 | if (!AStmt) |
| 5593 | return StmtError(); |
| 5594 | |
Samuel Antao | 4af1b7b | 2015-12-02 17:44:43 +0000 | [diff] [blame] | 5595 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5596 | // 1.2.2 OpenMP Language Terminology |
| 5597 | // Structured block - An executable statement with a single entry at the |
| 5598 | // top and a single exit at the bottom. |
| 5599 | // The point of exit cannot be a branch out of the structured block. |
| 5600 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5601 | CS->getCapturedDecl()->setNothrow(); |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5602 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5603 | // OpenMP [2.16, Nesting of Regions] |
| 5604 | // If specified, a teams construct must be contained within a target |
| 5605 | // construct. That target construct must contain no statements or directives |
| 5606 | // outside of the teams construct. |
| 5607 | if (DSAStack->hasInnerTeamsRegion()) { |
| 5608 | auto S = AStmt->IgnoreContainers(/*IgnoreCaptured*/ true); |
| 5609 | bool OMPTeamsFound = true; |
| 5610 | if (auto *CS = dyn_cast<CompoundStmt>(S)) { |
| 5611 | auto I = CS->body_begin(); |
| 5612 | while (I != CS->body_end()) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5613 | auto *OED = dyn_cast<OMPExecutableDirective>(*I); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5614 | if (!OED || !isOpenMPTeamsDirective(OED->getDirectiveKind())) { |
| 5615 | OMPTeamsFound = false; |
| 5616 | break; |
| 5617 | } |
| 5618 | ++I; |
| 5619 | } |
| 5620 | assert(I != CS->body_end() && "Not found statement"); |
| 5621 | S = *I; |
Kelvin Li | 3834dce | 2016-06-27 19:15:43 +0000 | [diff] [blame] | 5622 | } else { |
| 5623 | auto *OED = dyn_cast<OMPExecutableDirective>(S); |
| 5624 | OMPTeamsFound = OED && isOpenMPTeamsDirective(OED->getDirectiveKind()); |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5625 | } |
| 5626 | if (!OMPTeamsFound) { |
| 5627 | Diag(StartLoc, diag::err_omp_target_contains_not_only_teams); |
| 5628 | Diag(DSAStack->getInnerTeamsRegionLoc(), |
| 5629 | diag::note_omp_nested_teams_construct_here); |
| 5630 | Diag(S->getLocStart(), diag::note_omp_nested_statement_here) |
| 5631 | << isa<OMPExecutableDirective>(S); |
| 5632 | return StmtError(); |
| 5633 | } |
| 5634 | } |
| 5635 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 5636 | getCurFunction()->setHasBranchProtectedScope(); |
| 5637 | |
| 5638 | return OMPTargetDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5639 | } |
| 5640 | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 5641 | StmtResult |
| 5642 | Sema::ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 5643 | Stmt *AStmt, SourceLocation StartLoc, |
| 5644 | SourceLocation EndLoc) { |
| 5645 | if (!AStmt) |
| 5646 | return StmtError(); |
| 5647 | |
| 5648 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5649 | // 1.2.2 OpenMP Language Terminology |
| 5650 | // Structured block - An executable statement with a single entry at the |
| 5651 | // top and a single exit at the bottom. |
| 5652 | // The point of exit cannot be a branch out of the structured block. |
| 5653 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5654 | CS->getCapturedDecl()->setNothrow(); |
| 5655 | |
| 5656 | getCurFunction()->setHasBranchProtectedScope(); |
| 5657 | |
| 5658 | return OMPTargetParallelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5659 | AStmt); |
| 5660 | } |
| 5661 | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5662 | StmtResult Sema::ActOnOpenMPTargetParallelForDirective( |
| 5663 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5664 | SourceLocation EndLoc, |
| 5665 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5666 | if (!AStmt) |
| 5667 | return StmtError(); |
| 5668 | |
| 5669 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5670 | // 1.2.2 OpenMP Language Terminology |
| 5671 | // Structured block - An executable statement with a single entry at the |
| 5672 | // top and a single exit at the bottom. |
| 5673 | // The point of exit cannot be a branch out of the structured block. |
| 5674 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5675 | CS->getCapturedDecl()->setNothrow(); |
| 5676 | |
| 5677 | OMPLoopDirective::HelperExprs B; |
| 5678 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5679 | // define the nested loops number. |
| 5680 | unsigned NestedLoopCount = |
| 5681 | CheckOpenMPLoop(OMPD_target_parallel_for, getCollapseNumberExpr(Clauses), |
| 5682 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 5683 | VarsWithImplicitDSA, B); |
| 5684 | if (NestedLoopCount == 0) |
| 5685 | return StmtError(); |
| 5686 | |
| 5687 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5688 | "omp target parallel for loop exprs were not built"); |
| 5689 | |
| 5690 | if (!CurContext->isDependentContext()) { |
| 5691 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5692 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5693 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5694 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5695 | B.NumIterations, *this, CurScope, |
| 5696 | DSAStack)) |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 5697 | return StmtError(); |
| 5698 | } |
| 5699 | } |
| 5700 | |
| 5701 | getCurFunction()->setHasBranchProtectedScope(); |
| 5702 | return OMPTargetParallelForDirective::Create(Context, StartLoc, EndLoc, |
| 5703 | NestedLoopCount, Clauses, AStmt, |
| 5704 | B, DSAStack->isCancelRegion()); |
| 5705 | } |
| 5706 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5707 | /// \brief Check for existence of a map clause in the list of clauses. |
| 5708 | static bool HasMapClause(ArrayRef<OMPClause *> Clauses) { |
| 5709 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 5710 | I != E; ++I) { |
| 5711 | if (*I != nullptr && (*I)->getClauseKind() == OMPC_map) { |
| 5712 | return true; |
| 5713 | } |
| 5714 | } |
| 5715 | |
| 5716 | return false; |
| 5717 | } |
| 5718 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5719 | StmtResult Sema::ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5720 | Stmt *AStmt, |
| 5721 | SourceLocation StartLoc, |
| 5722 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5723 | if (!AStmt) |
| 5724 | return StmtError(); |
| 5725 | |
| 5726 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5727 | |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5728 | // OpenMP [2.10.1, Restrictions, p. 97] |
| 5729 | // At least one map clause must appear on the directive. |
| 5730 | if (!HasMapClause(Clauses)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5731 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5732 | << getOpenMPDirectiveName(OMPD_target_data); |
Arpith Chacko Jacob | 46a04bb | 2016-01-21 19:57:55 +0000 | [diff] [blame] | 5733 | return StmtError(); |
| 5734 | } |
| 5735 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 5736 | getCurFunction()->setHasBranchProtectedScope(); |
| 5737 | |
| 5738 | return OMPTargetDataDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5739 | AStmt); |
| 5740 | } |
| 5741 | |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 5742 | StmtResult |
| 5743 | Sema::ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5744 | SourceLocation StartLoc, |
| 5745 | SourceLocation EndLoc) { |
| 5746 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 5747 | // At least one map clause must appear on the directive. |
| 5748 | if (!HasMapClause(Clauses)) { |
| 5749 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5750 | << getOpenMPDirectiveName(OMPD_target_enter_data); |
| 5751 | return StmtError(); |
| 5752 | } |
| 5753 | |
| 5754 | return OMPTargetEnterDataDirective::Create(Context, StartLoc, EndLoc, |
| 5755 | Clauses); |
| 5756 | } |
| 5757 | |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 5758 | StmtResult |
| 5759 | Sema::ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 5760 | SourceLocation StartLoc, |
| 5761 | SourceLocation EndLoc) { |
| 5762 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 5763 | // At least one map clause must appear on the directive. |
| 5764 | if (!HasMapClause(Clauses)) { |
| 5765 | Diag(StartLoc, diag::err_omp_no_map_for_directive) |
| 5766 | << getOpenMPDirectiveName(OMPD_target_exit_data); |
| 5767 | return StmtError(); |
| 5768 | } |
| 5769 | |
| 5770 | return OMPTargetExitDataDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5771 | } |
| 5772 | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5773 | StmtResult Sema::ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 5774 | SourceLocation StartLoc, |
| 5775 | SourceLocation EndLoc) { |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5776 | bool seenMotionClause = false; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5777 | for (auto *C : Clauses) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 5778 | if (C->getClauseKind() == OMPC_to || C->getClauseKind() == OMPC_from) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 5779 | seenMotionClause = true; |
| 5780 | } |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 5781 | if (!seenMotionClause) { |
| 5782 | Diag(StartLoc, diag::err_omp_at_least_one_motion_clause_required); |
| 5783 | return StmtError(); |
| 5784 | } |
| 5785 | return OMPTargetUpdateDirective::Create(Context, StartLoc, EndLoc, Clauses); |
| 5786 | } |
| 5787 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5788 | StmtResult Sema::ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 5789 | Stmt *AStmt, SourceLocation StartLoc, |
| 5790 | SourceLocation EndLoc) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 5791 | if (!AStmt) |
| 5792 | return StmtError(); |
| 5793 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 5794 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5795 | // 1.2.2 OpenMP Language Terminology |
| 5796 | // Structured block - An executable statement with a single entry at the |
| 5797 | // top and a single exit at the bottom. |
| 5798 | // The point of exit cannot be a branch out of the structured block. |
| 5799 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5800 | CS->getCapturedDecl()->setNothrow(); |
| 5801 | |
| 5802 | getCurFunction()->setHasBranchProtectedScope(); |
| 5803 | |
| 5804 | return OMPTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, AStmt); |
| 5805 | } |
| 5806 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 5807 | StmtResult |
| 5808 | Sema::ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 5809 | SourceLocation EndLoc, |
| 5810 | OpenMPDirectiveKind CancelRegion) { |
| 5811 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5812 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5813 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5814 | << getOpenMPDirectiveName(CancelRegion); |
| 5815 | return StmtError(); |
| 5816 | } |
| 5817 | if (DSAStack->isParentNowaitRegion()) { |
| 5818 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 0; |
| 5819 | return StmtError(); |
| 5820 | } |
| 5821 | if (DSAStack->isParentOrderedRegion()) { |
| 5822 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 0; |
| 5823 | return StmtError(); |
| 5824 | } |
| 5825 | return OMPCancellationPointDirective::Create(Context, StartLoc, EndLoc, |
| 5826 | CancelRegion); |
| 5827 | } |
| 5828 | |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5829 | StmtResult Sema::ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 5830 | SourceLocation StartLoc, |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5831 | SourceLocation EndLoc, |
| 5832 | OpenMPDirectiveKind CancelRegion) { |
| 5833 | if (CancelRegion != OMPD_parallel && CancelRegion != OMPD_for && |
| 5834 | CancelRegion != OMPD_sections && CancelRegion != OMPD_taskgroup) { |
| 5835 | Diag(StartLoc, diag::err_omp_wrong_cancel_region) |
| 5836 | << getOpenMPDirectiveName(CancelRegion); |
| 5837 | return StmtError(); |
| 5838 | } |
| 5839 | if (DSAStack->isParentNowaitRegion()) { |
| 5840 | Diag(StartLoc, diag::err_omp_parent_cancel_region_nowait) << 1; |
| 5841 | return StmtError(); |
| 5842 | } |
| 5843 | if (DSAStack->isParentOrderedRegion()) { |
| 5844 | Diag(StartLoc, diag::err_omp_parent_cancel_region_ordered) << 1; |
| 5845 | return StmtError(); |
| 5846 | } |
Alexey Bataev | 25e5b44 | 2015-09-15 12:52:43 +0000 | [diff] [blame] | 5847 | DSAStack->setParentCancelRegion(/*Cancel=*/true); |
Alexey Bataev | 87933c7 | 2015-09-18 08:07:34 +0000 | [diff] [blame] | 5848 | return OMPCancelDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 5849 | CancelRegion); |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 5850 | } |
| 5851 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5852 | static bool checkGrainsizeNumTasksClauses(Sema &S, |
| 5853 | ArrayRef<OMPClause *> Clauses) { |
| 5854 | OMPClause *PrevClause = nullptr; |
| 5855 | bool ErrorFound = false; |
| 5856 | for (auto *C : Clauses) { |
| 5857 | if (C->getClauseKind() == OMPC_grainsize || |
| 5858 | C->getClauseKind() == OMPC_num_tasks) { |
| 5859 | if (!PrevClause) |
| 5860 | PrevClause = C; |
| 5861 | else if (PrevClause->getClauseKind() != C->getClauseKind()) { |
| 5862 | S.Diag(C->getLocStart(), |
| 5863 | diag::err_omp_grainsize_num_tasks_mutually_exclusive) |
| 5864 | << getOpenMPClauseName(C->getClauseKind()) |
| 5865 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5866 | S.Diag(PrevClause->getLocStart(), |
| 5867 | diag::note_omp_previous_grainsize_num_tasks) |
| 5868 | << getOpenMPClauseName(PrevClause->getClauseKind()); |
| 5869 | ErrorFound = true; |
| 5870 | } |
| 5871 | } |
| 5872 | } |
| 5873 | return ErrorFound; |
| 5874 | } |
| 5875 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5876 | StmtResult Sema::ActOnOpenMPTaskLoopDirective( |
| 5877 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5878 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5879 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5880 | if (!AStmt) |
| 5881 | return StmtError(); |
| 5882 | |
| 5883 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5884 | OMPLoopDirective::HelperExprs B; |
| 5885 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5886 | // define the nested loops number. |
| 5887 | unsigned NestedLoopCount = |
| 5888 | CheckOpenMPLoop(OMPD_taskloop, getCollapseNumberExpr(Clauses), |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5889 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5890 | VarsWithImplicitDSA, B); |
| 5891 | if (NestedLoopCount == 0) |
| 5892 | return StmtError(); |
| 5893 | |
| 5894 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5895 | "omp for loop exprs were not built"); |
| 5896 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5897 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5898 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5899 | // not appear on the same taskloop directive. |
| 5900 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5901 | return StmtError(); |
| 5902 | |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 5903 | getCurFunction()->setHasBranchProtectedScope(); |
| 5904 | return OMPTaskLoopDirective::Create(Context, StartLoc, EndLoc, |
| 5905 | NestedLoopCount, Clauses, AStmt, B); |
| 5906 | } |
| 5907 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5908 | StmtResult Sema::ActOnOpenMPTaskLoopSimdDirective( |
| 5909 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5910 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5911 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5912 | if (!AStmt) |
| 5913 | return StmtError(); |
| 5914 | |
| 5915 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5916 | OMPLoopDirective::HelperExprs B; |
| 5917 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 5918 | // define the nested loops number. |
| 5919 | unsigned NestedLoopCount = |
| 5920 | CheckOpenMPLoop(OMPD_taskloop_simd, getCollapseNumberExpr(Clauses), |
| 5921 | /*OrderedLoopCountExpr=*/nullptr, AStmt, *this, *DSAStack, |
| 5922 | VarsWithImplicitDSA, B); |
| 5923 | if (NestedLoopCount == 0) |
| 5924 | return StmtError(); |
| 5925 | |
| 5926 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5927 | "omp for loop exprs were not built"); |
| 5928 | |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5929 | if (!CurContext->isDependentContext()) { |
| 5930 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 5931 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 5932 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5933 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 5934 | B.NumIterations, *this, CurScope, |
| 5935 | DSAStack)) |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 5936 | return StmtError(); |
| 5937 | } |
| 5938 | } |
| 5939 | |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 5940 | // OpenMP, [2.9.2 taskloop Construct, Restrictions] |
| 5941 | // The grainsize clause and num_tasks clause are mutually exclusive and may |
| 5942 | // not appear on the same taskloop directive. |
| 5943 | if (checkGrainsizeNumTasksClauses(*this, Clauses)) |
| 5944 | return StmtError(); |
| 5945 | |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 5946 | getCurFunction()->setHasBranchProtectedScope(); |
| 5947 | return OMPTaskLoopSimdDirective::Create(Context, StartLoc, EndLoc, |
| 5948 | NestedLoopCount, Clauses, AStmt, B); |
| 5949 | } |
| 5950 | |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5951 | StmtResult Sema::ActOnOpenMPDistributeDirective( |
| 5952 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5953 | SourceLocation EndLoc, |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 5954 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 5955 | if (!AStmt) |
| 5956 | return StmtError(); |
| 5957 | |
| 5958 | assert(isa<CapturedStmt>(AStmt) && "Captured statement expected"); |
| 5959 | OMPLoopDirective::HelperExprs B; |
| 5960 | // In presence of clause 'collapse' with number of loops, it will |
| 5961 | // define the nested loops number. |
| 5962 | unsigned NestedLoopCount = |
| 5963 | CheckOpenMPLoop(OMPD_distribute, getCollapseNumberExpr(Clauses), |
| 5964 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 5965 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 5966 | if (NestedLoopCount == 0) |
| 5967 | return StmtError(); |
| 5968 | |
| 5969 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 5970 | "omp for loop exprs were not built"); |
| 5971 | |
| 5972 | getCurFunction()->setHasBranchProtectedScope(); |
| 5973 | return OMPDistributeDirective::Create(Context, StartLoc, EndLoc, |
| 5974 | NestedLoopCount, Clauses, AStmt, B); |
| 5975 | } |
| 5976 | |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 5977 | StmtResult Sema::ActOnOpenMPDistributeParallelForDirective( |
| 5978 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 5979 | SourceLocation EndLoc, |
| 5980 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 5981 | if (!AStmt) |
| 5982 | return StmtError(); |
| 5983 | |
| 5984 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 5985 | // 1.2.2 OpenMP Language Terminology |
| 5986 | // Structured block - An executable statement with a single entry at the |
| 5987 | // top and a single exit at the bottom. |
| 5988 | // The point of exit cannot be a branch out of the structured block. |
| 5989 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 5990 | CS->getCapturedDecl()->setNothrow(); |
| 5991 | |
| 5992 | OMPLoopDirective::HelperExprs B; |
| 5993 | // In presence of clause 'collapse' with number of loops, it will |
| 5994 | // define the nested loops number. |
| 5995 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 5996 | OMPD_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 5997 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 5998 | VarsWithImplicitDSA, B); |
| 5999 | if (NestedLoopCount == 0) |
| 6000 | return StmtError(); |
| 6001 | |
| 6002 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6003 | "omp for loop exprs were not built"); |
| 6004 | |
| 6005 | getCurFunction()->setHasBranchProtectedScope(); |
| 6006 | return OMPDistributeParallelForDirective::Create( |
| 6007 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6008 | } |
| 6009 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6010 | StmtResult Sema::ActOnOpenMPDistributeParallelForSimdDirective( |
| 6011 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6012 | SourceLocation EndLoc, |
| 6013 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6014 | if (!AStmt) |
| 6015 | return StmtError(); |
| 6016 | |
| 6017 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6018 | // 1.2.2 OpenMP Language Terminology |
| 6019 | // Structured block - An executable statement with a single entry at the |
| 6020 | // top and a single exit at the bottom. |
| 6021 | // The point of exit cannot be a branch out of the structured block. |
| 6022 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6023 | CS->getCapturedDecl()->setNothrow(); |
| 6024 | |
| 6025 | OMPLoopDirective::HelperExprs B; |
| 6026 | // In presence of clause 'collapse' with number of loops, it will |
| 6027 | // define the nested loops number. |
| 6028 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6029 | OMPD_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6030 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6031 | VarsWithImplicitDSA, B); |
| 6032 | if (NestedLoopCount == 0) |
| 6033 | return StmtError(); |
| 6034 | |
| 6035 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6036 | "omp for loop exprs were not built"); |
| 6037 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6038 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6039 | return StmtError(); |
| 6040 | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 6041 | getCurFunction()->setHasBranchProtectedScope(); |
| 6042 | return OMPDistributeParallelForSimdDirective::Create( |
| 6043 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6044 | } |
| 6045 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6046 | StmtResult Sema::ActOnOpenMPDistributeSimdDirective( |
| 6047 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6048 | SourceLocation EndLoc, |
| 6049 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6050 | if (!AStmt) |
| 6051 | return StmtError(); |
| 6052 | |
| 6053 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6054 | // 1.2.2 OpenMP Language Terminology |
| 6055 | // Structured block - An executable statement with a single entry at the |
| 6056 | // top and a single exit at the bottom. |
| 6057 | // The point of exit cannot be a branch out of the structured block. |
| 6058 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6059 | CS->getCapturedDecl()->setNothrow(); |
| 6060 | |
| 6061 | OMPLoopDirective::HelperExprs B; |
| 6062 | // In presence of clause 'collapse' with number of loops, it will |
| 6063 | // define the nested loops number. |
| 6064 | unsigned NestedLoopCount = |
| 6065 | CheckOpenMPLoop(OMPD_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6066 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6067 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6068 | if (NestedLoopCount == 0) |
| 6069 | return StmtError(); |
| 6070 | |
| 6071 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6072 | "omp for loop exprs were not built"); |
| 6073 | |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6074 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6075 | return StmtError(); |
| 6076 | |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 6077 | getCurFunction()->setHasBranchProtectedScope(); |
| 6078 | return OMPDistributeSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6079 | NestedLoopCount, Clauses, AStmt, B); |
| 6080 | } |
| 6081 | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6082 | StmtResult Sema::ActOnOpenMPTargetParallelForSimdDirective( |
| 6083 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6084 | SourceLocation EndLoc, |
| 6085 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6086 | if (!AStmt) |
| 6087 | return StmtError(); |
| 6088 | |
| 6089 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6090 | // 1.2.2 OpenMP Language Terminology |
| 6091 | // Structured block - An executable statement with a single entry at the |
| 6092 | // top and a single exit at the bottom. |
| 6093 | // The point of exit cannot be a branch out of the structured block. |
| 6094 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6095 | CS->getCapturedDecl()->setNothrow(); |
| 6096 | |
| 6097 | OMPLoopDirective::HelperExprs B; |
| 6098 | // In presence of clause 'collapse' or 'ordered' with number of loops, it will |
| 6099 | // define the nested loops number. |
| 6100 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6101 | OMPD_target_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6102 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6103 | VarsWithImplicitDSA, B); |
| 6104 | if (NestedLoopCount == 0) |
| 6105 | return StmtError(); |
| 6106 | |
| 6107 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6108 | "omp target parallel for simd loop exprs were not built"); |
| 6109 | |
| 6110 | if (!CurContext->isDependentContext()) { |
| 6111 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6112 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6113 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6114 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6115 | B.NumIterations, *this, CurScope, |
| 6116 | DSAStack)) |
| 6117 | return StmtError(); |
| 6118 | } |
| 6119 | } |
Kelvin Li | c560949 | 2016-07-15 04:39:07 +0000 | [diff] [blame] | 6120 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 6121 | return StmtError(); |
| 6122 | |
| 6123 | getCurFunction()->setHasBranchProtectedScope(); |
| 6124 | return OMPTargetParallelForSimdDirective::Create( |
| 6125 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6126 | } |
| 6127 | |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6128 | StmtResult Sema::ActOnOpenMPTargetSimdDirective( |
| 6129 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6130 | SourceLocation EndLoc, |
| 6131 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6132 | if (!AStmt) |
| 6133 | return StmtError(); |
| 6134 | |
| 6135 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6136 | // 1.2.2 OpenMP Language Terminology |
| 6137 | // Structured block - An executable statement with a single entry at the |
| 6138 | // top and a single exit at the bottom. |
| 6139 | // The point of exit cannot be a branch out of the structured block. |
| 6140 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6141 | CS->getCapturedDecl()->setNothrow(); |
| 6142 | |
| 6143 | OMPLoopDirective::HelperExprs B; |
| 6144 | // In presence of clause 'collapse' with number of loops, it will define the |
| 6145 | // nested loops number. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6146 | unsigned NestedLoopCount = |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6147 | CheckOpenMPLoop(OMPD_target_simd, getCollapseNumberExpr(Clauses), |
| 6148 | getOrderedNumberExpr(Clauses), AStmt, *this, *DSAStack, |
| 6149 | VarsWithImplicitDSA, B); |
| 6150 | if (NestedLoopCount == 0) |
| 6151 | return StmtError(); |
| 6152 | |
| 6153 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6154 | "omp target simd loop exprs were not built"); |
| 6155 | |
| 6156 | if (!CurContext->isDependentContext()) { |
| 6157 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6158 | for (auto C : Clauses) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6159 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 6160 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6161 | B.NumIterations, *this, CurScope, |
| 6162 | DSAStack)) |
| 6163 | return StmtError(); |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6168 | return StmtError(); |
| 6169 | |
| 6170 | getCurFunction()->setHasBranchProtectedScope(); |
| 6171 | return OMPTargetSimdDirective::Create(Context, StartLoc, EndLoc, |
| 6172 | NestedLoopCount, Clauses, AStmt, B); |
| 6173 | } |
| 6174 | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6175 | StmtResult Sema::ActOnOpenMPTeamsDistributeDirective( |
| 6176 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6177 | SourceLocation EndLoc, |
| 6178 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6179 | if (!AStmt) |
| 6180 | return StmtError(); |
| 6181 | |
| 6182 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6183 | // 1.2.2 OpenMP Language Terminology |
| 6184 | // Structured block - An executable statement with a single entry at the |
| 6185 | // top and a single exit at the bottom. |
| 6186 | // The point of exit cannot be a branch out of the structured block. |
| 6187 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6188 | CS->getCapturedDecl()->setNothrow(); |
| 6189 | |
| 6190 | OMPLoopDirective::HelperExprs B; |
| 6191 | // In presence of clause 'collapse' with number of loops, it will |
| 6192 | // define the nested loops number. |
| 6193 | unsigned NestedLoopCount = |
| 6194 | CheckOpenMPLoop(OMPD_teams_distribute, getCollapseNumberExpr(Clauses), |
| 6195 | nullptr /*ordered not a clause on distribute*/, AStmt, |
| 6196 | *this, *DSAStack, VarsWithImplicitDSA, B); |
| 6197 | if (NestedLoopCount == 0) |
| 6198 | return StmtError(); |
| 6199 | |
| 6200 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6201 | "omp teams distribute loop exprs were not built"); |
| 6202 | |
| 6203 | getCurFunction()->setHasBranchProtectedScope(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 6204 | return OMPTeamsDistributeDirective::Create( |
| 6205 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 6206 | } |
| 6207 | |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6208 | StmtResult Sema::ActOnOpenMPTeamsDistributeSimdDirective( |
| 6209 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6210 | SourceLocation EndLoc, |
| 6211 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6212 | if (!AStmt) |
| 6213 | return StmtError(); |
| 6214 | |
| 6215 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6216 | // 1.2.2 OpenMP Language Terminology |
| 6217 | // Structured block - An executable statement with a single entry at the |
| 6218 | // top and a single exit at the bottom. |
| 6219 | // The point of exit cannot be a branch out of the structured block. |
| 6220 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6221 | CS->getCapturedDecl()->setNothrow(); |
| 6222 | |
| 6223 | OMPLoopDirective::HelperExprs B; |
| 6224 | // In presence of clause 'collapse' with number of loops, it will |
| 6225 | // define the nested loops number. |
Samuel Antao | 4c8035b | 2016-12-12 18:00:20 +0000 | [diff] [blame] | 6226 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6227 | OMPD_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6228 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6229 | VarsWithImplicitDSA, B); |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 6230 | |
| 6231 | if (NestedLoopCount == 0) |
| 6232 | return StmtError(); |
| 6233 | |
| 6234 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6235 | "omp teams distribute simd loop exprs were not built"); |
| 6236 | |
| 6237 | if (!CurContext->isDependentContext()) { |
| 6238 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6239 | for (auto C : Clauses) { |
| 6240 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6241 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6242 | B.NumIterations, *this, CurScope, |
| 6243 | DSAStack)) |
| 6244 | return StmtError(); |
| 6245 | } |
| 6246 | } |
| 6247 | |
| 6248 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6249 | return StmtError(); |
| 6250 | |
| 6251 | getCurFunction()->setHasBranchProtectedScope(); |
| 6252 | return OMPTeamsDistributeSimdDirective::Create( |
| 6253 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6254 | } |
| 6255 | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 6256 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 6257 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6258 | SourceLocation EndLoc, |
| 6259 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6260 | if (!AStmt) |
| 6261 | return StmtError(); |
| 6262 | |
| 6263 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6264 | // 1.2.2 OpenMP Language Terminology |
| 6265 | // Structured block - An executable statement with a single entry at the |
| 6266 | // top and a single exit at the bottom. |
| 6267 | // The point of exit cannot be a branch out of the structured block. |
| 6268 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6269 | CS->getCapturedDecl()->setNothrow(); |
| 6270 | |
| 6271 | OMPLoopDirective::HelperExprs B; |
| 6272 | // In presence of clause 'collapse' with number of loops, it will |
| 6273 | // define the nested loops number. |
| 6274 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6275 | OMPD_teams_distribute_parallel_for_simd, getCollapseNumberExpr(Clauses), |
| 6276 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6277 | VarsWithImplicitDSA, B); |
| 6278 | |
| 6279 | if (NestedLoopCount == 0) |
| 6280 | return StmtError(); |
| 6281 | |
| 6282 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6283 | "omp for loop exprs were not built"); |
| 6284 | |
| 6285 | if (!CurContext->isDependentContext()) { |
| 6286 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6287 | for (auto C : Clauses) { |
| 6288 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6289 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6290 | B.NumIterations, *this, CurScope, |
| 6291 | DSAStack)) |
| 6292 | return StmtError(); |
| 6293 | } |
| 6294 | } |
| 6295 | |
| 6296 | if (checkSimdlenSafelenSpecified(*this, Clauses)) |
| 6297 | return StmtError(); |
| 6298 | |
| 6299 | getCurFunction()->setHasBranchProtectedScope(); |
| 6300 | return OMPTeamsDistributeParallelForSimdDirective::Create( |
| 6301 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6302 | } |
| 6303 | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 6304 | StmtResult Sema::ActOnOpenMPTeamsDistributeParallelForDirective( |
| 6305 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6306 | SourceLocation EndLoc, |
| 6307 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6308 | if (!AStmt) |
| 6309 | return StmtError(); |
| 6310 | |
| 6311 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6312 | // 1.2.2 OpenMP Language Terminology |
| 6313 | // Structured block - An executable statement with a single entry at the |
| 6314 | // top and a single exit at the bottom. |
| 6315 | // The point of exit cannot be a branch out of the structured block. |
| 6316 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6317 | CS->getCapturedDecl()->setNothrow(); |
| 6318 | |
| 6319 | OMPLoopDirective::HelperExprs B; |
| 6320 | // In presence of clause 'collapse' with number of loops, it will |
| 6321 | // define the nested loops number. |
| 6322 | unsigned NestedLoopCount = CheckOpenMPLoop( |
| 6323 | OMPD_teams_distribute_parallel_for, getCollapseNumberExpr(Clauses), |
| 6324 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6325 | VarsWithImplicitDSA, B); |
| 6326 | |
| 6327 | if (NestedLoopCount == 0) |
| 6328 | return StmtError(); |
| 6329 | |
| 6330 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6331 | "omp for loop exprs were not built"); |
| 6332 | |
| 6333 | if (!CurContext->isDependentContext()) { |
| 6334 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6335 | for (auto C : Clauses) { |
| 6336 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6337 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6338 | B.NumIterations, *this, CurScope, |
| 6339 | DSAStack)) |
| 6340 | return StmtError(); |
| 6341 | } |
| 6342 | } |
| 6343 | |
| 6344 | getCurFunction()->setHasBranchProtectedScope(); |
| 6345 | return OMPTeamsDistributeParallelForDirective::Create( |
| 6346 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6347 | } |
| 6348 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 6349 | StmtResult Sema::ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 6350 | Stmt *AStmt, |
| 6351 | SourceLocation StartLoc, |
| 6352 | SourceLocation EndLoc) { |
| 6353 | if (!AStmt) |
| 6354 | return StmtError(); |
| 6355 | |
| 6356 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6357 | // 1.2.2 OpenMP Language Terminology |
| 6358 | // Structured block - An executable statement with a single entry at the |
| 6359 | // top and a single exit at the bottom. |
| 6360 | // The point of exit cannot be a branch out of the structured block. |
| 6361 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6362 | CS->getCapturedDecl()->setNothrow(); |
| 6363 | |
| 6364 | getCurFunction()->setHasBranchProtectedScope(); |
| 6365 | |
| 6366 | return OMPTargetTeamsDirective::Create(Context, StartLoc, EndLoc, Clauses, |
| 6367 | AStmt); |
| 6368 | } |
| 6369 | |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 6370 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeDirective( |
| 6371 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6372 | SourceLocation EndLoc, |
| 6373 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6374 | if (!AStmt) |
| 6375 | return StmtError(); |
| 6376 | |
| 6377 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6378 | // 1.2.2 OpenMP Language Terminology |
| 6379 | // Structured block - An executable statement with a single entry at the |
| 6380 | // top and a single exit at the bottom. |
| 6381 | // The point of exit cannot be a branch out of the structured block. |
| 6382 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6383 | CS->getCapturedDecl()->setNothrow(); |
| 6384 | |
| 6385 | OMPLoopDirective::HelperExprs B; |
| 6386 | // In presence of clause 'collapse' with number of loops, it will |
| 6387 | // define the nested loops number. |
| 6388 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6389 | OMPD_target_teams_distribute, |
| 6390 | getCollapseNumberExpr(Clauses), |
| 6391 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6392 | VarsWithImplicitDSA, B); |
| 6393 | if (NestedLoopCount == 0) |
| 6394 | return StmtError(); |
| 6395 | |
| 6396 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6397 | "omp target teams distribute loop exprs were not built"); |
| 6398 | |
| 6399 | getCurFunction()->setHasBranchProtectedScope(); |
| 6400 | return OMPTargetTeamsDistributeDirective::Create( |
| 6401 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6402 | } |
| 6403 | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 6404 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 6405 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6406 | SourceLocation EndLoc, |
| 6407 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6408 | if (!AStmt) |
| 6409 | return StmtError(); |
| 6410 | |
| 6411 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6412 | // 1.2.2 OpenMP Language Terminology |
| 6413 | // Structured block - An executable statement with a single entry at the |
| 6414 | // top and a single exit at the bottom. |
| 6415 | // The point of exit cannot be a branch out of the structured block. |
| 6416 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6417 | CS->getCapturedDecl()->setNothrow(); |
| 6418 | |
| 6419 | OMPLoopDirective::HelperExprs B; |
| 6420 | // In presence of clause 'collapse' with number of loops, it will |
| 6421 | // define the nested loops number. |
| 6422 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6423 | OMPD_target_teams_distribute_parallel_for, |
| 6424 | getCollapseNumberExpr(Clauses), |
| 6425 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6426 | VarsWithImplicitDSA, B); |
| 6427 | if (NestedLoopCount == 0) |
| 6428 | return StmtError(); |
| 6429 | |
| 6430 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6431 | "omp target teams distribute parallel for loop exprs were not built"); |
| 6432 | |
| 6433 | if (!CurContext->isDependentContext()) { |
| 6434 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6435 | for (auto C : Clauses) { |
| 6436 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6437 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6438 | B.NumIterations, *this, CurScope, |
| 6439 | DSAStack)) |
| 6440 | return StmtError(); |
| 6441 | } |
| 6442 | } |
| 6443 | |
| 6444 | getCurFunction()->setHasBranchProtectedScope(); |
| 6445 | return OMPTargetTeamsDistributeParallelForDirective::Create( |
| 6446 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6447 | } |
| 6448 | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 6449 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 6450 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6451 | SourceLocation EndLoc, |
| 6452 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6453 | if (!AStmt) |
| 6454 | return StmtError(); |
| 6455 | |
| 6456 | CapturedStmt *CS = cast<CapturedStmt>(AStmt); |
| 6457 | // 1.2.2 OpenMP Language Terminology |
| 6458 | // Structured block - An executable statement with a single entry at the |
| 6459 | // top and a single exit at the bottom. |
| 6460 | // The point of exit cannot be a branch out of the structured block. |
| 6461 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6462 | CS->getCapturedDecl()->setNothrow(); |
| 6463 | |
| 6464 | OMPLoopDirective::HelperExprs B; |
| 6465 | // In presence of clause 'collapse' with number of loops, it will |
| 6466 | // define the nested loops number. |
| 6467 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6468 | OMPD_target_teams_distribute_parallel_for_simd, |
| 6469 | getCollapseNumberExpr(Clauses), |
| 6470 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6471 | VarsWithImplicitDSA, B); |
| 6472 | if (NestedLoopCount == 0) |
| 6473 | return StmtError(); |
| 6474 | |
| 6475 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6476 | "omp target teams distribute parallel for simd loop exprs were not " |
| 6477 | "built"); |
| 6478 | |
| 6479 | if (!CurContext->isDependentContext()) { |
| 6480 | // Finalize the clauses that need pre-built expressions for CodeGen. |
| 6481 | for (auto C : Clauses) { |
| 6482 | if (auto *LC = dyn_cast<OMPLinearClause>(C)) |
| 6483 | if (FinishOpenMPLinearClause(*LC, cast<DeclRefExpr>(B.IterationVarRef), |
| 6484 | B.NumIterations, *this, CurScope, |
| 6485 | DSAStack)) |
| 6486 | return StmtError(); |
| 6487 | } |
| 6488 | } |
| 6489 | |
| 6490 | getCurFunction()->setHasBranchProtectedScope(); |
| 6491 | return OMPTargetTeamsDistributeParallelForSimdDirective::Create( |
| 6492 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6493 | } |
| 6494 | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 6495 | StmtResult Sema::ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 6496 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 6497 | SourceLocation EndLoc, |
| 6498 | llvm::DenseMap<ValueDecl *, Expr *> &VarsWithImplicitDSA) { |
| 6499 | if (!AStmt) |
| 6500 | return StmtError(); |
| 6501 | |
| 6502 | auto *CS = cast<CapturedStmt>(AStmt); |
| 6503 | // 1.2.2 OpenMP Language Terminology |
| 6504 | // Structured block - An executable statement with a single entry at the |
| 6505 | // top and a single exit at the bottom. |
| 6506 | // The point of exit cannot be a branch out of the structured block. |
| 6507 | // longjmp() and throw() must not violate the entry/exit criteria. |
| 6508 | CS->getCapturedDecl()->setNothrow(); |
| 6509 | |
| 6510 | OMPLoopDirective::HelperExprs B; |
| 6511 | // In presence of clause 'collapse' with number of loops, it will |
| 6512 | // define the nested loops number. |
| 6513 | auto NestedLoopCount = CheckOpenMPLoop( |
| 6514 | OMPD_target_teams_distribute_simd, getCollapseNumberExpr(Clauses), |
| 6515 | nullptr /*ordered not a clause on distribute*/, AStmt, *this, *DSAStack, |
| 6516 | VarsWithImplicitDSA, B); |
| 6517 | if (NestedLoopCount == 0) |
| 6518 | return StmtError(); |
| 6519 | |
| 6520 | assert((CurContext->isDependentContext() || B.builtAll()) && |
| 6521 | "omp target teams distribute simd loop exprs were not built"); |
| 6522 | |
| 6523 | getCurFunction()->setHasBranchProtectedScope(); |
| 6524 | return OMPTargetTeamsDistributeSimdDirective::Create( |
| 6525 | Context, StartLoc, EndLoc, NestedLoopCount, Clauses, AStmt, B); |
| 6526 | } |
| 6527 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6528 | OMPClause *Sema::ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, Expr *Expr, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6529 | SourceLocation StartLoc, |
| 6530 | SourceLocation LParenLoc, |
| 6531 | SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6532 | OMPClause *Res = nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6533 | switch (Kind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6534 | case OMPC_final: |
| 6535 | Res = ActOnOpenMPFinalClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6536 | break; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6537 | case OMPC_num_threads: |
| 6538 | Res = ActOnOpenMPNumThreadsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6539 | break; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6540 | case OMPC_safelen: |
| 6541 | Res = ActOnOpenMPSafelenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6542 | break; |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6543 | case OMPC_simdlen: |
| 6544 | Res = ActOnOpenMPSimdlenClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6545 | break; |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6546 | case OMPC_collapse: |
| 6547 | Res = ActOnOpenMPCollapseClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6548 | break; |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6549 | case OMPC_ordered: |
| 6550 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Expr); |
| 6551 | break; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6552 | case OMPC_device: |
| 6553 | Res = ActOnOpenMPDeviceClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6554 | break; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6555 | case OMPC_num_teams: |
| 6556 | Res = ActOnOpenMPNumTeamsClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6557 | break; |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6558 | case OMPC_thread_limit: |
| 6559 | Res = ActOnOpenMPThreadLimitClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6560 | break; |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6561 | case OMPC_priority: |
| 6562 | Res = ActOnOpenMPPriorityClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6563 | break; |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6564 | case OMPC_grainsize: |
| 6565 | Res = ActOnOpenMPGrainsizeClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6566 | break; |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6567 | case OMPC_num_tasks: |
| 6568 | Res = ActOnOpenMPNumTasksClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6569 | break; |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6570 | case OMPC_hint: |
| 6571 | Res = ActOnOpenMPHintClause(Expr, StartLoc, LParenLoc, EndLoc); |
| 6572 | break; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6573 | case OMPC_if: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6574 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6575 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6576 | case OMPC_schedule: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6577 | case OMPC_private: |
| 6578 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6579 | case OMPC_lastprivate: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6580 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6581 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6582 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6583 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6584 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6585 | case OMPC_copyprivate: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6586 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6587 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6588 | case OMPC_mergeable: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6589 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6590 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6591 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6592 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6593 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6594 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6595 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6596 | case OMPC_depend: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6597 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6598 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6599 | case OMPC_map: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6600 | case OMPC_nogroup: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6601 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6602 | case OMPC_defaultmap: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6603 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6604 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6605 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6606 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6607 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6608 | case OMPC_is_device_ptr: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6609 | llvm_unreachable("Clause is not allowed."); |
| 6610 | } |
| 6611 | return Res; |
| 6612 | } |
| 6613 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6614 | OMPClause *Sema::ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 6615 | Expr *Condition, SourceLocation StartLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6616 | SourceLocation LParenLoc, |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6617 | SourceLocation NameModifierLoc, |
| 6618 | SourceLocation ColonLoc, |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6619 | SourceLocation EndLoc) { |
| 6620 | Expr *ValExpr = Condition; |
| 6621 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6622 | !Condition->isInstantiationDependent() && |
| 6623 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6624 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6625 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6626 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6627 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6628 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6629 | } |
| 6630 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6631 | return new (Context) OMPIfClause(NameModifier, ValExpr, StartLoc, LParenLoc, |
| 6632 | NameModifierLoc, ColonLoc, EndLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6633 | } |
| 6634 | |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6635 | OMPClause *Sema::ActOnOpenMPFinalClause(Expr *Condition, |
| 6636 | SourceLocation StartLoc, |
| 6637 | SourceLocation LParenLoc, |
| 6638 | SourceLocation EndLoc) { |
| 6639 | Expr *ValExpr = Condition; |
| 6640 | if (!Condition->isValueDependent() && !Condition->isTypeDependent() && |
| 6641 | !Condition->isInstantiationDependent() && |
| 6642 | !Condition->containsUnexpandedParameterPack()) { |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6643 | ExprResult Val = CheckBooleanCondition(StartLoc, Condition); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6644 | if (Val.isInvalid()) |
| 6645 | return nullptr; |
| 6646 | |
Richard Smith | 03a4aa3 | 2016-06-23 19:02:52 +0000 | [diff] [blame] | 6647 | ValExpr = MakeFullExpr(Val.get()).get(); |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6648 | } |
| 6649 | |
| 6650 | return new (Context) OMPFinalClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 6651 | } |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 6652 | ExprResult Sema::PerformOpenMPImplicitIntegerConversion(SourceLocation Loc, |
| 6653 | Expr *Op) { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6654 | if (!Op) |
| 6655 | return ExprError(); |
| 6656 | |
| 6657 | class IntConvertDiagnoser : public ICEConvertDiagnoser { |
| 6658 | public: |
| 6659 | IntConvertDiagnoser() |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6660 | : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, false, true) {} |
Craig Topper | e14c0f8 | 2014-03-12 04:55:44 +0000 | [diff] [blame] | 6661 | SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, |
| 6662 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6663 | return S.Diag(Loc, diag::err_omp_not_integral) << T; |
| 6664 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6665 | SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, |
| 6666 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6667 | return S.Diag(Loc, diag::err_omp_incomplete_type) << T; |
| 6668 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6669 | SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, |
| 6670 | QualType T, |
| 6671 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6672 | return S.Diag(Loc, diag::err_omp_explicit_conversion) << T << ConvTy; |
| 6673 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6674 | SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, |
| 6675 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6676 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6677 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6678 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6679 | SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, |
| 6680 | QualType T) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6681 | return S.Diag(Loc, diag::err_omp_ambiguous_conversion) << T; |
| 6682 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6683 | SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, |
| 6684 | QualType ConvTy) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6685 | return S.Diag(Conv->getLocation(), diag::note_omp_conversion_here) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6686 | << ConvTy->isEnumeralType() << ConvTy; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6687 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6688 | SemaDiagnosticBuilder diagnoseConversion(Sema &, SourceLocation, QualType, |
| 6689 | QualType) override { |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6690 | llvm_unreachable("conversion functions are permitted"); |
| 6691 | } |
| 6692 | } ConvertDiagnoser; |
| 6693 | return PerformContextualImplicitConversion(Loc, Op, ConvertDiagnoser); |
| 6694 | } |
| 6695 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6696 | static bool IsNonNegativeIntegerValue(Expr *&ValExpr, Sema &SemaRef, |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6697 | OpenMPClauseKind CKind, |
| 6698 | bool StrictlyPositive) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6699 | if (!ValExpr->isTypeDependent() && !ValExpr->isValueDependent() && |
| 6700 | !ValExpr->isInstantiationDependent()) { |
| 6701 | SourceLocation Loc = ValExpr->getExprLoc(); |
| 6702 | ExprResult Value = |
| 6703 | SemaRef.PerformOpenMPImplicitIntegerConversion(Loc, ValExpr); |
| 6704 | if (Value.isInvalid()) |
| 6705 | return false; |
| 6706 | |
| 6707 | ValExpr = Value.get(); |
| 6708 | // The expression must evaluate to a non-negative integer value. |
| 6709 | llvm::APSInt Result; |
| 6710 | if (ValExpr->isIntegerConstantExpr(Result, SemaRef.Context) && |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6711 | Result.isSigned() && |
| 6712 | !((!StrictlyPositive && Result.isNonNegative()) || |
| 6713 | (StrictlyPositive && Result.isStrictlyPositive()))) { |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6714 | SemaRef.Diag(Loc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6715 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6716 | << ValExpr->getSourceRange(); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6717 | return false; |
| 6718 | } |
| 6719 | } |
| 6720 | return true; |
| 6721 | } |
| 6722 | |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6723 | OMPClause *Sema::ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 6724 | SourceLocation StartLoc, |
| 6725 | SourceLocation LParenLoc, |
| 6726 | SourceLocation EndLoc) { |
| 6727 | Expr *ValExpr = NumThreads; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6728 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6729 | // OpenMP [2.5, Restrictions] |
| 6730 | // The num_threads expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6731 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_threads, |
| 6732 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6733 | return nullptr; |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6734 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6735 | return new (Context) |
| 6736 | OMPNumThreadsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6737 | } |
| 6738 | |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6739 | ExprResult Sema::VerifyPositiveIntegerConstantInClause(Expr *E, |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6740 | OpenMPClauseKind CKind, |
| 6741 | bool StrictlyPositive) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6742 | if (!E) |
| 6743 | return ExprError(); |
| 6744 | if (E->isValueDependent() || E->isTypeDependent() || |
| 6745 | E->isInstantiationDependent() || E->containsUnexpandedParameterPack()) |
Nikola Smiljanic | 03ff259 | 2014-05-29 14:05:12 +0000 | [diff] [blame] | 6746 | return E; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6747 | llvm::APSInt Result; |
| 6748 | ExprResult ICE = VerifyIntegerConstantExpression(E, &Result); |
| 6749 | if (ICE.isInvalid()) |
| 6750 | return ExprError(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6751 | if ((StrictlyPositive && !Result.isStrictlyPositive()) || |
| 6752 | (!StrictlyPositive && !Result.isNonNegative())) { |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6753 | Diag(E->getExprLoc(), diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6754 | << getOpenMPClauseName(CKind) << (StrictlyPositive ? 1 : 0) |
| 6755 | << E->getSourceRange(); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6756 | return ExprError(); |
| 6757 | } |
Alexander Musman | 09184fe | 2014-09-30 05:29:28 +0000 | [diff] [blame] | 6758 | if (CKind == OMPC_aligned && !Result.isPowerOf2()) { |
| 6759 | Diag(E->getExprLoc(), diag::warn_omp_alignment_not_power_of_two) |
| 6760 | << E->getSourceRange(); |
| 6761 | return ExprError(); |
| 6762 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6763 | if (CKind == OMPC_collapse && DSAStack->getAssociatedLoops() == 1) |
| 6764 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 7b6bc88 | 2015-11-26 07:50:39 +0000 | [diff] [blame] | 6765 | else if (CKind == OMPC_ordered) |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 6766 | DSAStack->setAssociatedLoops(Result.getExtValue()); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6767 | return ICE; |
| 6768 | } |
| 6769 | |
| 6770 | OMPClause *Sema::ActOnOpenMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 6771 | SourceLocation LParenLoc, |
| 6772 | SourceLocation EndLoc) { |
| 6773 | // OpenMP [2.8.1, simd construct, Description] |
| 6774 | // The parameter of the safelen clause must be a constant |
| 6775 | // positive integer expression. |
| 6776 | ExprResult Safelen = VerifyPositiveIntegerConstantInClause(Len, OMPC_safelen); |
| 6777 | if (Safelen.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6778 | return nullptr; |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6779 | return new (Context) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 6780 | OMPSafelenClause(Safelen.get(), StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6781 | } |
| 6782 | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6783 | OMPClause *Sema::ActOnOpenMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 6784 | SourceLocation LParenLoc, |
| 6785 | SourceLocation EndLoc) { |
| 6786 | // OpenMP [2.8.1, simd construct, Description] |
| 6787 | // The parameter of the simdlen clause must be a constant |
| 6788 | // positive integer expression. |
| 6789 | ExprResult Simdlen = VerifyPositiveIntegerConstantInClause(Len, OMPC_simdlen); |
| 6790 | if (Simdlen.isInvalid()) |
| 6791 | return nullptr; |
| 6792 | return new (Context) |
| 6793 | OMPSimdlenClause(Simdlen.get(), StartLoc, LParenLoc, EndLoc); |
| 6794 | } |
| 6795 | |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6796 | OMPClause *Sema::ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 6797 | SourceLocation StartLoc, |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6798 | SourceLocation LParenLoc, |
| 6799 | SourceLocation EndLoc) { |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6800 | // OpenMP [2.7.1, loop construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6801 | // OpenMP [2.8.1, simd construct, Description] |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6802 | // OpenMP [2.9.6, distribute construct, Description] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6803 | // The parameter of the collapse clause must be a constant |
| 6804 | // positive integer expression. |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6805 | ExprResult NumForLoopsResult = |
| 6806 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_collapse); |
| 6807 | if (NumForLoopsResult.isInvalid()) |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6808 | return nullptr; |
| 6809 | return new (Context) |
Alexander Musman | 64d33f1 | 2014-06-04 07:53:32 +0000 | [diff] [blame] | 6810 | OMPCollapseClause(NumForLoopsResult.get(), StartLoc, LParenLoc, EndLoc); |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6811 | } |
| 6812 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6813 | OMPClause *Sema::ActOnOpenMPOrderedClause(SourceLocation StartLoc, |
| 6814 | SourceLocation EndLoc, |
| 6815 | SourceLocation LParenLoc, |
| 6816 | Expr *NumForLoops) { |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6817 | // OpenMP [2.7.1, loop construct, Description] |
| 6818 | // OpenMP [2.8.1, simd construct, Description] |
| 6819 | // OpenMP [2.9.6, distribute construct, Description] |
| 6820 | // The parameter of the ordered clause must be a constant |
| 6821 | // positive integer expression if any. |
| 6822 | if (NumForLoops && LParenLoc.isValid()) { |
| 6823 | ExprResult NumForLoopsResult = |
| 6824 | VerifyPositiveIntegerConstantInClause(NumForLoops, OMPC_ordered); |
| 6825 | if (NumForLoopsResult.isInvalid()) |
| 6826 | return nullptr; |
| 6827 | NumForLoops = NumForLoopsResult.get(); |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6828 | } else |
| 6829 | NumForLoops = nullptr; |
| 6830 | DSAStack->setOrderedRegion(/*IsOrdered=*/true, NumForLoops); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 6831 | return new (Context) |
| 6832 | OMPOrderedClause(NumForLoops, StartLoc, LParenLoc, EndLoc); |
| 6833 | } |
| 6834 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6835 | OMPClause *Sema::ActOnOpenMPSimpleClause( |
| 6836 | OpenMPClauseKind Kind, unsigned Argument, SourceLocation ArgumentLoc, |
| 6837 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6838 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6839 | switch (Kind) { |
| 6840 | case OMPC_default: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6841 | Res = |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6842 | ActOnOpenMPDefaultClause(static_cast<OpenMPDefaultClauseKind>(Argument), |
| 6843 | ArgumentLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6844 | break; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6845 | case OMPC_proc_bind: |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6846 | Res = ActOnOpenMPProcBindClause( |
| 6847 | static_cast<OpenMPProcBindClauseKind>(Argument), ArgumentLoc, StartLoc, |
| 6848 | LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6849 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6850 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 6851 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 6852 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 6853 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 6854 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 6855 | case OMPC_collapse: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6856 | case OMPC_schedule: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6857 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 6858 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 6859 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6860 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 6861 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 6862 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 6863 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 6864 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6865 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 6866 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 6867 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 6868 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 6869 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6870 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 6871 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 6872 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 6873 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 6874 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 6875 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 6876 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 6877 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 6878 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 6879 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 6880 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 6881 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 6882 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 6883 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 6884 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 6885 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 6886 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 6887 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 6888 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6889 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6890 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6891 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 6892 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 6893 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 6894 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 6895 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 6896 | case OMPC_is_device_ptr: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6897 | llvm_unreachable("Clause is not allowed."); |
| 6898 | } |
| 6899 | return Res; |
| 6900 | } |
| 6901 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6902 | static std::string |
| 6903 | getListOfPossibleValues(OpenMPClauseKind K, unsigned First, unsigned Last, |
| 6904 | ArrayRef<unsigned> Exclude = llvm::None) { |
| 6905 | std::string Values; |
| 6906 | unsigned Bound = Last >= 2 ? Last - 2 : 0; |
| 6907 | unsigned Skipped = Exclude.size(); |
| 6908 | auto S = Exclude.begin(), E = Exclude.end(); |
| 6909 | for (unsigned i = First; i < Last; ++i) { |
| 6910 | if (std::find(S, E, i) != E) { |
| 6911 | --Skipped; |
| 6912 | continue; |
| 6913 | } |
| 6914 | Values += "'"; |
| 6915 | Values += getOpenMPSimpleClauseTypeName(K, i); |
| 6916 | Values += "'"; |
| 6917 | if (i == Bound - Skipped) |
| 6918 | Values += " or "; |
| 6919 | else if (i != Bound + 1 - Skipped) |
| 6920 | Values += ", "; |
| 6921 | } |
| 6922 | return Values; |
| 6923 | } |
| 6924 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6925 | OMPClause *Sema::ActOnOpenMPDefaultClause(OpenMPDefaultClauseKind Kind, |
| 6926 | SourceLocation KindKwLoc, |
| 6927 | SourceLocation StartLoc, |
| 6928 | SourceLocation LParenLoc, |
| 6929 | SourceLocation EndLoc) { |
| 6930 | if (Kind == OMPC_DEFAULT_unknown) { |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 6931 | static_assert(OMPC_DEFAULT_unknown > 0, |
| 6932 | "OMPC_DEFAULT_unknown not greater than 0"); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6933 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6934 | << getListOfPossibleValues(OMPC_default, /*First=*/0, |
| 6935 | /*Last=*/OMPC_DEFAULT_unknown) |
| 6936 | << getOpenMPClauseName(OMPC_default); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6937 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6938 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6939 | switch (Kind) { |
| 6940 | case OMPC_DEFAULT_none: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6941 | DSAStack->setDefaultDSANone(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6942 | break; |
| 6943 | case OMPC_DEFAULT_shared: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 6944 | DSAStack->setDefaultDSAShared(KindKwLoc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6945 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6946 | case OMPC_DEFAULT_unknown: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 6947 | llvm_unreachable("Clause kind is not allowed."); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 6948 | break; |
| 6949 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6950 | return new (Context) |
| 6951 | OMPDefaultClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 6952 | } |
| 6953 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6954 | OMPClause *Sema::ActOnOpenMPProcBindClause(OpenMPProcBindClauseKind Kind, |
| 6955 | SourceLocation KindKwLoc, |
| 6956 | SourceLocation StartLoc, |
| 6957 | SourceLocation LParenLoc, |
| 6958 | SourceLocation EndLoc) { |
| 6959 | if (Kind == OMPC_PROC_BIND_unknown) { |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6960 | Diag(KindKwLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6961 | << getListOfPossibleValues(OMPC_proc_bind, /*First=*/0, |
| 6962 | /*Last=*/OMPC_PROC_BIND_unknown) |
| 6963 | << getOpenMPClauseName(OMPC_proc_bind); |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 6964 | return nullptr; |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6965 | } |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 6966 | return new (Context) |
| 6967 | OMPProcBindClause(Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc); |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 6968 | } |
| 6969 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6970 | OMPClause *Sema::ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6971 | OpenMPClauseKind Kind, ArrayRef<unsigned> Argument, Expr *Expr, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6972 | SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6973 | ArrayRef<SourceLocation> ArgumentLoc, SourceLocation DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6974 | SourceLocation EndLoc) { |
| 6975 | OMPClause *Res = nullptr; |
| 6976 | switch (Kind) { |
| 6977 | case OMPC_schedule: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6978 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 6979 | assert(Argument.size() == NumberOfElements && |
| 6980 | ArgumentLoc.size() == NumberOfElements); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6981 | Res = ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6982 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier1]), |
| 6983 | static_cast<OpenMPScheduleClauseModifier>(Argument[Modifier2]), |
| 6984 | static_cast<OpenMPScheduleClauseKind>(Argument[ScheduleKind]), Expr, |
| 6985 | StartLoc, LParenLoc, ArgumentLoc[Modifier1], ArgumentLoc[Modifier2], |
| 6986 | ArgumentLoc[ScheduleKind], DelimLoc, EndLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 6987 | break; |
| 6988 | case OMPC_if: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 6989 | assert(Argument.size() == 1 && ArgumentLoc.size() == 1); |
| 6990 | Res = ActOnOpenMPIfClause(static_cast<OpenMPDirectiveKind>(Argument.back()), |
| 6991 | Expr, StartLoc, LParenLoc, ArgumentLoc.back(), |
| 6992 | DelimLoc, EndLoc); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 6993 | break; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 6994 | case OMPC_dist_schedule: |
| 6995 | Res = ActOnOpenMPDistScheduleClause( |
| 6996 | static_cast<OpenMPDistScheduleClauseKind>(Argument.back()), Expr, |
| 6997 | StartLoc, LParenLoc, ArgumentLoc.back(), DelimLoc, EndLoc); |
| 6998 | break; |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 6999 | case OMPC_defaultmap: |
| 7000 | enum { Modifier, DefaultmapKind }; |
| 7001 | Res = ActOnOpenMPDefaultmapClause( |
| 7002 | static_cast<OpenMPDefaultmapClauseModifier>(Argument[Modifier]), |
| 7003 | static_cast<OpenMPDefaultmapClauseKind>(Argument[DefaultmapKind]), |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7004 | StartLoc, LParenLoc, ArgumentLoc[Modifier], ArgumentLoc[DefaultmapKind], |
| 7005 | EndLoc); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7006 | break; |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7007 | case OMPC_final: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7008 | case OMPC_num_threads: |
| 7009 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7010 | case OMPC_simdlen: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7011 | case OMPC_collapse: |
| 7012 | case OMPC_default: |
| 7013 | case OMPC_proc_bind: |
| 7014 | case OMPC_private: |
| 7015 | case OMPC_firstprivate: |
| 7016 | case OMPC_lastprivate: |
| 7017 | case OMPC_shared: |
| 7018 | case OMPC_reduction: |
| 7019 | case OMPC_linear: |
| 7020 | case OMPC_aligned: |
| 7021 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7022 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7023 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7024 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7025 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7026 | case OMPC_mergeable: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7027 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7028 | case OMPC_flush: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7029 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7030 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7031 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7032 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7033 | case OMPC_seq_cst: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7034 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7035 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7036 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7037 | case OMPC_simd: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7038 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7039 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7040 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7041 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7042 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7043 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7044 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7045 | case OMPC_hint: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7046 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7047 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7048 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7049 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7050 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7051 | case OMPC_is_device_ptr: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7052 | llvm_unreachable("Clause is not allowed."); |
| 7053 | } |
| 7054 | return Res; |
| 7055 | } |
| 7056 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7057 | static bool checkScheduleModifiers(Sema &S, OpenMPScheduleClauseModifier M1, |
| 7058 | OpenMPScheduleClauseModifier M2, |
| 7059 | SourceLocation M1Loc, SourceLocation M2Loc) { |
| 7060 | if (M1 == OMPC_SCHEDULE_MODIFIER_unknown && M1Loc.isValid()) { |
| 7061 | SmallVector<unsigned, 2> Excluded; |
| 7062 | if (M2 != OMPC_SCHEDULE_MODIFIER_unknown) |
| 7063 | Excluded.push_back(M2); |
| 7064 | if (M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) |
| 7065 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_monotonic); |
| 7066 | if (M2 == OMPC_SCHEDULE_MODIFIER_monotonic) |
| 7067 | Excluded.push_back(OMPC_SCHEDULE_MODIFIER_nonmonotonic); |
| 7068 | S.Diag(M1Loc, diag::err_omp_unexpected_clause_value) |
| 7069 | << getListOfPossibleValues(OMPC_schedule, |
| 7070 | /*First=*/OMPC_SCHEDULE_MODIFIER_unknown + 1, |
| 7071 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7072 | Excluded) |
| 7073 | << getOpenMPClauseName(OMPC_schedule); |
| 7074 | return true; |
| 7075 | } |
| 7076 | return false; |
| 7077 | } |
| 7078 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7079 | OMPClause *Sema::ActOnOpenMPScheduleClause( |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7080 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7081 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7082 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 7083 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 7084 | if (checkScheduleModifiers(*this, M1, M2, M1Loc, M2Loc) || |
| 7085 | checkScheduleModifiers(*this, M2, M1, M2Loc, M1Loc)) |
| 7086 | return nullptr; |
| 7087 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7088 | // Either the monotonic modifier or the nonmonotonic modifier can be specified |
| 7089 | // but not both. |
| 7090 | if ((M1 == M2 && M1 != OMPC_SCHEDULE_MODIFIER_unknown) || |
| 7091 | (M1 == OMPC_SCHEDULE_MODIFIER_monotonic && |
| 7092 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) || |
| 7093 | (M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic && |
| 7094 | M2 == OMPC_SCHEDULE_MODIFIER_monotonic)) { |
| 7095 | Diag(M2Loc, diag::err_omp_unexpected_schedule_modifier) |
| 7096 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M2) |
| 7097 | << getOpenMPSimpleClauseTypeName(OMPC_schedule, M1); |
| 7098 | return nullptr; |
| 7099 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7100 | if (Kind == OMPC_SCHEDULE_unknown) { |
| 7101 | std::string Values; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7102 | if (M1Loc.isInvalid() && M2Loc.isInvalid()) { |
| 7103 | unsigned Exclude[] = {OMPC_SCHEDULE_unknown}; |
| 7104 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7105 | /*Last=*/OMPC_SCHEDULE_MODIFIER_last, |
| 7106 | Exclude); |
| 7107 | } else { |
| 7108 | Values = getListOfPossibleValues(OMPC_schedule, /*First=*/0, |
| 7109 | /*Last=*/OMPC_SCHEDULE_unknown); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7110 | } |
| 7111 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 7112 | << Values << getOpenMPClauseName(OMPC_schedule); |
| 7113 | return nullptr; |
| 7114 | } |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7115 | // OpenMP, 2.7.1, Loop Construct, Restrictions |
| 7116 | // The nonmonotonic modifier can only be specified with schedule(dynamic) or |
| 7117 | // schedule(guided). |
| 7118 | if ((M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic || |
| 7119 | M2 == OMPC_SCHEDULE_MODIFIER_nonmonotonic) && |
| 7120 | Kind != OMPC_SCHEDULE_dynamic && Kind != OMPC_SCHEDULE_guided) { |
| 7121 | Diag(M1 == OMPC_SCHEDULE_MODIFIER_nonmonotonic ? M1Loc : M2Loc, |
| 7122 | diag::err_omp_schedule_nonmonotonic_static); |
| 7123 | return nullptr; |
| 7124 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7125 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7126 | Stmt *HelperValStmt = nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7127 | if (ChunkSize) { |
| 7128 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 7129 | !ChunkSize->isInstantiationDependent() && |
| 7130 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 7131 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 7132 | ExprResult Val = |
| 7133 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 7134 | if (Val.isInvalid()) |
| 7135 | return nullptr; |
| 7136 | |
| 7137 | ValExpr = Val.get(); |
| 7138 | |
| 7139 | // OpenMP [2.7.1, Restrictions] |
| 7140 | // chunk_size must be a loop invariant integer expression with a positive |
| 7141 | // value. |
| 7142 | llvm::APSInt Result; |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7143 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 7144 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 7145 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7146 | << "schedule" << 1 << ChunkSize->getSourceRange(); |
Alexey Bataev | 040d540 | 2015-05-12 08:35:28 +0000 | [diff] [blame] | 7147 | return nullptr; |
| 7148 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 7149 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 7150 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7151 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 7152 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 7153 | HelperValStmt = buildPreInits(Context, Captures); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7154 | } |
| 7155 | } |
| 7156 | } |
| 7157 | |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 7158 | return new (Context) |
| 7159 | OMPScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, Kind, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 7160 | ValExpr, HelperValStmt, M1, M1Loc, M2, M2Loc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7161 | } |
| 7162 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7163 | OMPClause *Sema::ActOnOpenMPClause(OpenMPClauseKind Kind, |
| 7164 | SourceLocation StartLoc, |
| 7165 | SourceLocation EndLoc) { |
| 7166 | OMPClause *Res = nullptr; |
| 7167 | switch (Kind) { |
| 7168 | case OMPC_ordered: |
| 7169 | Res = ActOnOpenMPOrderedClause(StartLoc, EndLoc); |
| 7170 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7171 | case OMPC_nowait: |
| 7172 | Res = ActOnOpenMPNowaitClause(StartLoc, EndLoc); |
| 7173 | break; |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7174 | case OMPC_untied: |
| 7175 | Res = ActOnOpenMPUntiedClause(StartLoc, EndLoc); |
| 7176 | break; |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7177 | case OMPC_mergeable: |
| 7178 | Res = ActOnOpenMPMergeableClause(StartLoc, EndLoc); |
| 7179 | break; |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7180 | case OMPC_read: |
| 7181 | Res = ActOnOpenMPReadClause(StartLoc, EndLoc); |
| 7182 | break; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7183 | case OMPC_write: |
| 7184 | Res = ActOnOpenMPWriteClause(StartLoc, EndLoc); |
| 7185 | break; |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7186 | case OMPC_update: |
| 7187 | Res = ActOnOpenMPUpdateClause(StartLoc, EndLoc); |
| 7188 | break; |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7189 | case OMPC_capture: |
| 7190 | Res = ActOnOpenMPCaptureClause(StartLoc, EndLoc); |
| 7191 | break; |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7192 | case OMPC_seq_cst: |
| 7193 | Res = ActOnOpenMPSeqCstClause(StartLoc, EndLoc); |
| 7194 | break; |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7195 | case OMPC_threads: |
| 7196 | Res = ActOnOpenMPThreadsClause(StartLoc, EndLoc); |
| 7197 | break; |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7198 | case OMPC_simd: |
| 7199 | Res = ActOnOpenMPSIMDClause(StartLoc, EndLoc); |
| 7200 | break; |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7201 | case OMPC_nogroup: |
| 7202 | Res = ActOnOpenMPNogroupClause(StartLoc, EndLoc); |
| 7203 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7204 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7205 | case OMPC_final: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7206 | case OMPC_num_threads: |
| 7207 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7208 | case OMPC_simdlen: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7209 | case OMPC_collapse: |
| 7210 | case OMPC_schedule: |
| 7211 | case OMPC_private: |
| 7212 | case OMPC_firstprivate: |
| 7213 | case OMPC_lastprivate: |
| 7214 | case OMPC_shared: |
| 7215 | case OMPC_reduction: |
| 7216 | case OMPC_linear: |
| 7217 | case OMPC_aligned: |
| 7218 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7219 | case OMPC_copyprivate: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7220 | case OMPC_default: |
| 7221 | case OMPC_proc_bind: |
| 7222 | case OMPC_threadprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7223 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7224 | case OMPC_depend: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7225 | case OMPC_device: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7226 | case OMPC_map: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7227 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7228 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7229 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7230 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7231 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7232 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7233 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7234 | case OMPC_defaultmap: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7235 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7236 | case OMPC_uniform: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7237 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7238 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7239 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7240 | case OMPC_is_device_ptr: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7241 | llvm_unreachable("Clause is not allowed."); |
| 7242 | } |
| 7243 | return Res; |
| 7244 | } |
| 7245 | |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7246 | OMPClause *Sema::ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 7247 | SourceLocation EndLoc) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 7248 | DSAStack->setNowaitRegion(); |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7249 | return new (Context) OMPNowaitClause(StartLoc, EndLoc); |
| 7250 | } |
| 7251 | |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7252 | OMPClause *Sema::ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 7253 | SourceLocation EndLoc) { |
| 7254 | return new (Context) OMPUntiedClause(StartLoc, EndLoc); |
| 7255 | } |
| 7256 | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7257 | OMPClause *Sema::ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 7258 | SourceLocation EndLoc) { |
| 7259 | return new (Context) OMPMergeableClause(StartLoc, EndLoc); |
| 7260 | } |
| 7261 | |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7262 | OMPClause *Sema::ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 7263 | SourceLocation EndLoc) { |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7264 | return new (Context) OMPReadClause(StartLoc, EndLoc); |
| 7265 | } |
| 7266 | |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7267 | OMPClause *Sema::ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 7268 | SourceLocation EndLoc) { |
| 7269 | return new (Context) OMPWriteClause(StartLoc, EndLoc); |
| 7270 | } |
| 7271 | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7272 | OMPClause *Sema::ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 7273 | SourceLocation EndLoc) { |
| 7274 | return new (Context) OMPUpdateClause(StartLoc, EndLoc); |
| 7275 | } |
| 7276 | |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7277 | OMPClause *Sema::ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 7278 | SourceLocation EndLoc) { |
| 7279 | return new (Context) OMPCaptureClause(StartLoc, EndLoc); |
| 7280 | } |
| 7281 | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7282 | OMPClause *Sema::ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 7283 | SourceLocation EndLoc) { |
| 7284 | return new (Context) OMPSeqCstClause(StartLoc, EndLoc); |
| 7285 | } |
| 7286 | |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7287 | OMPClause *Sema::ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 7288 | SourceLocation EndLoc) { |
| 7289 | return new (Context) OMPThreadsClause(StartLoc, EndLoc); |
| 7290 | } |
| 7291 | |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7292 | OMPClause *Sema::ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 7293 | SourceLocation EndLoc) { |
| 7294 | return new (Context) OMPSIMDClause(StartLoc, EndLoc); |
| 7295 | } |
| 7296 | |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7297 | OMPClause *Sema::ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 7298 | SourceLocation EndLoc) { |
| 7299 | return new (Context) OMPNogroupClause(StartLoc, EndLoc); |
| 7300 | } |
| 7301 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7302 | OMPClause *Sema::ActOnOpenMPVarListClause( |
| 7303 | OpenMPClauseKind Kind, ArrayRef<Expr *> VarList, Expr *TailExpr, |
| 7304 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 7305 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7306 | const DeclarationNameInfo &ReductionId, OpenMPDependClauseKind DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7307 | OpenMPLinearClauseKind LinKind, OpenMPMapClauseKind MapTypeModifier, |
| 7308 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 7309 | SourceLocation DepLinMapLoc) { |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 7310 | OMPClause *Res = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7311 | switch (Kind) { |
| 7312 | case OMPC_private: |
| 7313 | Res = ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7314 | break; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7315 | case OMPC_firstprivate: |
| 7316 | Res = ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7317 | break; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7318 | case OMPC_lastprivate: |
| 7319 | Res = ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7320 | break; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7321 | case OMPC_shared: |
| 7322 | Res = ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7323 | break; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7324 | case OMPC_reduction: |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 7325 | Res = ActOnOpenMPReductionClause(VarList, StartLoc, LParenLoc, ColonLoc, |
| 7326 | EndLoc, ReductionIdScopeSpec, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 7327 | break; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7328 | case OMPC_linear: |
| 7329 | Res = ActOnOpenMPLinearClause(VarList, TailExpr, StartLoc, LParenLoc, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7330 | LinKind, DepLinMapLoc, ColonLoc, EndLoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 7331 | break; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 7332 | case OMPC_aligned: |
| 7333 | Res = ActOnOpenMPAlignedClause(VarList, TailExpr, StartLoc, LParenLoc, |
| 7334 | ColonLoc, EndLoc); |
| 7335 | break; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 7336 | case OMPC_copyin: |
| 7337 | Res = ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7338 | break; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 7339 | case OMPC_copyprivate: |
| 7340 | Res = ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7341 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 7342 | case OMPC_flush: |
| 7343 | Res = ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7344 | break; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7345 | case OMPC_depend: |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7346 | Res = ActOnOpenMPDependClause(DepKind, DepLinMapLoc, ColonLoc, VarList, |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 7347 | StartLoc, LParenLoc, EndLoc); |
| 7348 | break; |
| 7349 | case OMPC_map: |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 7350 | Res = ActOnOpenMPMapClause(MapTypeModifier, MapType, IsMapTypeImplicit, |
| 7351 | DepLinMapLoc, ColonLoc, VarList, StartLoc, |
| 7352 | LParenLoc, EndLoc); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 7353 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 7354 | case OMPC_to: |
| 7355 | Res = ActOnOpenMPToClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7356 | break; |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 7357 | case OMPC_from: |
| 7358 | Res = ActOnOpenMPFromClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7359 | break; |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 7360 | case OMPC_use_device_ptr: |
| 7361 | Res = ActOnOpenMPUseDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7362 | break; |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 7363 | case OMPC_is_device_ptr: |
| 7364 | Res = ActOnOpenMPIsDevicePtrClause(VarList, StartLoc, LParenLoc, EndLoc); |
| 7365 | break; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 7366 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 7367 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 7368 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 7369 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 7370 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 7371 | case OMPC_collapse: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7372 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 7373 | case OMPC_proc_bind: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 7374 | case OMPC_schedule: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 7375 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 7376 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 7377 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 7378 | case OMPC_mergeable: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7379 | case OMPC_threadprivate: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 7380 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 7381 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 7382 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 7383 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 7384 | case OMPC_seq_cst: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 7385 | case OMPC_device: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 7386 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 7387 | case OMPC_simd: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 7388 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 7389 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 7390 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 7391 | case OMPC_grainsize: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 7392 | case OMPC_nogroup: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 7393 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 7394 | case OMPC_hint: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 7395 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 7396 | case OMPC_defaultmap: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7397 | case OMPC_unknown: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 7398 | case OMPC_uniform: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7399 | llvm_unreachable("Clause is not allowed."); |
| 7400 | } |
| 7401 | return Res; |
| 7402 | } |
| 7403 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7404 | ExprResult Sema::getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7405 | ExprObjectKind OK, SourceLocation Loc) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7406 | ExprResult Res = BuildDeclRefExpr( |
| 7407 | Capture, Capture->getType().getNonReferenceType(), VK_LValue, Loc); |
| 7408 | if (!Res.isUsable()) |
| 7409 | return ExprError(); |
| 7410 | if (OK == OK_Ordinary && !getLangOpts().CPlusPlus) { |
| 7411 | Res = CreateBuiltinUnaryOp(Loc, UO_Deref, Res.get()); |
| 7412 | if (!Res.isUsable()) |
| 7413 | return ExprError(); |
| 7414 | } |
| 7415 | if (VK != VK_LValue && Res.get()->isGLValue()) { |
| 7416 | Res = DefaultLvalueConversion(Res.get()); |
| 7417 | if (!Res.isUsable()) |
| 7418 | return ExprError(); |
| 7419 | } |
| 7420 | return Res; |
| 7421 | } |
| 7422 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7423 | static std::pair<ValueDecl *, bool> |
| 7424 | getPrivateItem(Sema &S, Expr *&RefExpr, SourceLocation &ELoc, |
| 7425 | SourceRange &ERange, bool AllowArraySection = false) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7426 | if (RefExpr->isTypeDependent() || RefExpr->isValueDependent() || |
| 7427 | RefExpr->containsUnexpandedParameterPack()) |
| 7428 | return std::make_pair(nullptr, true); |
| 7429 | |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7430 | // OpenMP [3.1, C/C++] |
| 7431 | // A list item is a variable name. |
| 7432 | // OpenMP [2.9.3.3, Restrictions, p.1] |
| 7433 | // A variable that is part of another variable (as an array or |
| 7434 | // structure element) cannot appear in a private clause. |
| 7435 | RefExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7436 | enum { |
| 7437 | NoArrayExpr = -1, |
| 7438 | ArraySubscript = 0, |
| 7439 | OMPArraySection = 1 |
| 7440 | } IsArrayExpr = NoArrayExpr; |
| 7441 | if (AllowArraySection) { |
| 7442 | if (auto *ASE = dyn_cast_or_null<ArraySubscriptExpr>(RefExpr)) { |
| 7443 | auto *Base = ASE->getBase()->IgnoreParenImpCasts(); |
| 7444 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7445 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7446 | RefExpr = Base; |
| 7447 | IsArrayExpr = ArraySubscript; |
| 7448 | } else if (auto *OASE = dyn_cast_or_null<OMPArraySectionExpr>(RefExpr)) { |
| 7449 | auto *Base = OASE->getBase()->IgnoreParenImpCasts(); |
| 7450 | while (auto *TempOASE = dyn_cast<OMPArraySectionExpr>(Base)) |
| 7451 | Base = TempOASE->getBase()->IgnoreParenImpCasts(); |
| 7452 | while (auto *TempASE = dyn_cast<ArraySubscriptExpr>(Base)) |
| 7453 | Base = TempASE->getBase()->IgnoreParenImpCasts(); |
| 7454 | RefExpr = Base; |
| 7455 | IsArrayExpr = OMPArraySection; |
| 7456 | } |
| 7457 | } |
| 7458 | ELoc = RefExpr->getExprLoc(); |
| 7459 | ERange = RefExpr->getSourceRange(); |
| 7460 | RefExpr = RefExpr->IgnoreParenImpCasts(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7461 | auto *DE = dyn_cast_or_null<DeclRefExpr>(RefExpr); |
| 7462 | auto *ME = dyn_cast_or_null<MemberExpr>(RefExpr); |
| 7463 | if ((!DE || !isa<VarDecl>(DE->getDecl())) && |
| 7464 | (S.getCurrentThisType().isNull() || !ME || |
| 7465 | !isa<CXXThisExpr>(ME->getBase()->IgnoreParenImpCasts()) || |
| 7466 | !isa<FieldDecl>(ME->getMemberDecl()))) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7467 | if (IsArrayExpr != NoArrayExpr) |
| 7468 | S.Diag(ELoc, diag::err_omp_expected_base_var_name) << IsArrayExpr |
| 7469 | << ERange; |
| 7470 | else { |
| 7471 | S.Diag(ELoc, |
| 7472 | AllowArraySection |
| 7473 | ? diag::err_omp_expected_var_name_member_expr_or_array_item |
| 7474 | : diag::err_omp_expected_var_name_member_expr) |
| 7475 | << (S.getCurrentThisType().isNull() ? 0 : 1) << ERange; |
| 7476 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7477 | return std::make_pair(nullptr, false); |
| 7478 | } |
| 7479 | return std::make_pair(DE ? DE->getDecl() : ME->getMemberDecl(), false); |
| 7480 | } |
| 7481 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7482 | OMPClause *Sema::ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 7483 | SourceLocation StartLoc, |
| 7484 | SourceLocation LParenLoc, |
| 7485 | SourceLocation EndLoc) { |
| 7486 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7487 | SmallVector<Expr *, 8> PrivateCopies; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7488 | for (auto &RefExpr : VarList) { |
| 7489 | assert(RefExpr && "NULL expr in OpenMP private clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7490 | SourceLocation ELoc; |
| 7491 | SourceRange ERange; |
| 7492 | Expr *SimpleRefExpr = RefExpr; |
| 7493 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7494 | if (Res.second) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7495 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7496 | Vars.push_back(RefExpr); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7497 | PrivateCopies.push_back(nullptr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7498 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7499 | ValueDecl *D = Res.first; |
| 7500 | if (!D) |
| 7501 | continue; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7502 | |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7503 | QualType Type = D->getType(); |
| 7504 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7505 | |
| 7506 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7507 | // A variable that appears in a private clause must not have an incomplete |
| 7508 | // type or a reference type. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7509 | if (RequireCompleteType(ELoc, Type, diag::err_omp_private_incomplete_type)) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7510 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7511 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7512 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7513 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7514 | // in a Construct] |
| 7515 | // Variables with the predetermined data-sharing attributes may not be |
| 7516 | // listed in data-sharing attributes clauses, except for the cases |
| 7517 | // listed below. For these exceptions only, listing a predetermined |
| 7518 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7519 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7520 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7521 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_private) { |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7522 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 7523 | << getOpenMPClauseName(OMPC_private); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7524 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 7525 | continue; |
| 7526 | } |
| 7527 | |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7528 | auto CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7529 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7530 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7531 | isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7532 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7533 | << getOpenMPClauseName(OMPC_private) << Type |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7534 | << getOpenMPDirectiveName(CurrDir); |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7535 | bool IsDecl = |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7536 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7537 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7538 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7539 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7540 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7541 | continue; |
| 7542 | } |
| 7543 | |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7544 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7545 | // A list item cannot appear in both a map clause and a data-sharing |
| 7546 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7547 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7548 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7549 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7550 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 7551 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7552 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 7553 | CurrDir == OMPD_target_parallel_for_simd || |
| 7554 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7555 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 7556 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7557 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7558 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 7559 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 7560 | ConflictKind = WhereFoundClauseKind; |
| 7561 | return true; |
| 7562 | })) { |
| 7563 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7564 | << getOpenMPClauseName(OMPC_private) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7565 | << getOpenMPClauseName(ConflictKind) |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7566 | << getOpenMPDirectiveName(CurrDir); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7567 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7568 | continue; |
| 7569 | } |
| 7570 | } |
| 7571 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7572 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.1] |
| 7573 | // A variable of class type (or array thereof) that appears in a private |
| 7574 | // clause requires an accessible, unambiguous default constructor for the |
| 7575 | // class type. |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7576 | // Generate helper private variable and initialize it with the default |
| 7577 | // value. The address of the original variable is replaced by the address of |
| 7578 | // the new private variable in CodeGen. This new variable is not added to |
| 7579 | // IdResolver, so the code in the OpenMP region uses original variable for |
| 7580 | // proper diagnostics. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7581 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7582 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7583 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7584 | ActOnUninitializedDecl(VDPrivate); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7585 | if (VDPrivate->isInvalidDecl()) |
| 7586 | continue; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7587 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 7588 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7589 | |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7590 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7591 | if (!VD && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7592 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 7593 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7594 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 7595 | ? RefExpr->IgnoreParens() |
| 7596 | : Ref); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7597 | PrivateCopies.push_back(VDPrivateRefExpr); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7598 | } |
| 7599 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7600 | if (Vars.empty()) |
| 7601 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7602 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 7603 | return OMPPrivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 7604 | PrivateCopies); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 7605 | } |
| 7606 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7607 | namespace { |
| 7608 | class DiagsUninitializedSeveretyRAII { |
| 7609 | private: |
| 7610 | DiagnosticsEngine &Diags; |
| 7611 | SourceLocation SavedLoc; |
| 7612 | bool IsIgnored; |
| 7613 | |
| 7614 | public: |
| 7615 | DiagsUninitializedSeveretyRAII(DiagnosticsEngine &Diags, SourceLocation Loc, |
| 7616 | bool IsIgnored) |
| 7617 | : Diags(Diags), SavedLoc(Loc), IsIgnored(IsIgnored) { |
| 7618 | if (!IsIgnored) { |
| 7619 | Diags.setSeverity(/*Diag*/ diag::warn_uninit_self_reference_in_init, |
| 7620 | /*Map*/ diag::Severity::Ignored, Loc); |
| 7621 | } |
| 7622 | } |
| 7623 | ~DiagsUninitializedSeveretyRAII() { |
| 7624 | if (!IsIgnored) |
| 7625 | Diags.popMappings(SavedLoc); |
| 7626 | } |
| 7627 | }; |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 7628 | } |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7629 | |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7630 | OMPClause *Sema::ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 7631 | SourceLocation StartLoc, |
| 7632 | SourceLocation LParenLoc, |
| 7633 | SourceLocation EndLoc) { |
| 7634 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7635 | SmallVector<Expr *, 8> PrivateCopies; |
| 7636 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7637 | SmallVector<Decl *, 4> ExprCaptures; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7638 | bool IsImplicitClause = |
| 7639 | StartLoc.isInvalid() && LParenLoc.isInvalid() && EndLoc.isInvalid(); |
| 7640 | auto ImplicitClauseLoc = DSAStack->getConstructLoc(); |
| 7641 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7642 | for (auto &RefExpr : VarList) { |
| 7643 | assert(RefExpr && "NULL expr in OpenMP firstprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7644 | SourceLocation ELoc; |
| 7645 | SourceRange ERange; |
| 7646 | Expr *SimpleRefExpr = RefExpr; |
| 7647 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7648 | if (Res.second) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7649 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7650 | Vars.push_back(RefExpr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7651 | PrivateCopies.push_back(nullptr); |
| 7652 | Inits.push_back(nullptr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7653 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7654 | ValueDecl *D = Res.first; |
| 7655 | if (!D) |
| 7656 | continue; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7657 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7658 | ELoc = IsImplicitClause ? ImplicitClauseLoc : ELoc; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7659 | QualType Type = D->getType(); |
| 7660 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7661 | |
| 7662 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 7663 | // A variable that appears in a private clause must not have an incomplete |
| 7664 | // type or a reference type. |
| 7665 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7666 | diag::err_omp_firstprivate_incomplete_type)) |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7667 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7668 | Type = Type.getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7669 | |
| 7670 | // OpenMP [2.9.3.4, Restrictions, C/C++, p.1] |
| 7671 | // 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] | 7672 | // clause requires an accessible, unambiguous copy constructor for the |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7673 | // class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7674 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7675 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7676 | // If an implicit firstprivate variable found it was checked already. |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7677 | DSAStackTy::DSAVarData TopDVar; |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7678 | if (!IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7679 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7680 | TopDVar = DVar; |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7681 | bool IsConstant = ElemType.isConstant(Context); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7682 | // OpenMP [2.4.13, Data-sharing Attribute Clauses] |
| 7683 | // A list item that specifies a given variable may not appear in more |
| 7684 | // than one clause on the same directive, except that a variable may be |
| 7685 | // specified in both firstprivate and lastprivate clauses. |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7686 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_firstprivate && |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7687 | DVar.CKind != OMPC_lastprivate && DVar.RefExpr) { |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7688 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7689 | << getOpenMPClauseName(DVar.CKind) |
| 7690 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7691 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7692 | continue; |
| 7693 | } |
| 7694 | |
| 7695 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7696 | // in a Construct] |
| 7697 | // Variables with the predetermined data-sharing attributes may not be |
| 7698 | // listed in data-sharing attributes clauses, except for the cases |
| 7699 | // listed below. For these exceptions only, listing a predetermined |
| 7700 | // variable in a data-sharing attribute clause is allowed and overrides |
| 7701 | // the variable's predetermined data-sharing attributes. |
| 7702 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7703 | // in a Construct, C/C++, p.2] |
| 7704 | // Variables with const-qualified type having no mutable member may be |
| 7705 | // listed in a firstprivate clause, even if they are static data members. |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7706 | if (!(IsConstant || (VD && VD->isStaticDataMember())) && !DVar.RefExpr && |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7707 | DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared) { |
| 7708 | Diag(ELoc, diag::err_omp_wrong_dsa) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7709 | << getOpenMPClauseName(DVar.CKind) |
| 7710 | << getOpenMPClauseName(OMPC_firstprivate); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7711 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7712 | continue; |
| 7713 | } |
| 7714 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7715 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7716 | // OpenMP [2.9.3.4, Restrictions, p.2] |
| 7717 | // A list item that is private within a parallel region must not appear |
| 7718 | // in a firstprivate clause on a worksharing construct if any of the |
| 7719 | // worksharing regions arising from the worksharing construct ever bind |
| 7720 | // to any of the parallel regions arising from the parallel construct. |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7721 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7722 | !isOpenMPParallelDirective(CurrDir) && |
| 7723 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7724 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7725 | if (DVar.CKind != OMPC_shared && |
| 7726 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7727 | DVar.DKind == OMPD_unknown)) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7728 | Diag(ELoc, diag::err_omp_required_access) |
| 7729 | << getOpenMPClauseName(OMPC_firstprivate) |
| 7730 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7731 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7732 | continue; |
| 7733 | } |
| 7734 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7735 | // OpenMP [2.9.3.4, Restrictions, p.3] |
| 7736 | // A list item that appears in a reduction clause of a parallel construct |
| 7737 | // must not appear in a firstprivate clause on a worksharing or task |
| 7738 | // construct if any of the worksharing or task regions arising from the |
| 7739 | // worksharing or task construct ever bind to any of the parallel regions |
| 7740 | // arising from the parallel construct. |
| 7741 | // OpenMP [2.9.3.4, Restrictions, p.4] |
| 7742 | // A list item that appears in a reduction clause in worksharing |
| 7743 | // construct must not appear in a firstprivate clause in a task construct |
| 7744 | // encountered during execution of any of the worksharing regions arising |
| 7745 | // from the worksharing construct. |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7746 | if (isOpenMPTaskingDirective(CurrDir)) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 7747 | DVar = DSAStack->hasInnermostDSA( |
| 7748 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 7749 | [](OpenMPDirectiveKind K) -> bool { |
| 7750 | return isOpenMPParallelDirective(K) || |
| 7751 | isOpenMPWorksharingDirective(K); |
| 7752 | }, |
| 7753 | false); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7754 | if (DVar.CKind == OMPC_reduction && |
| 7755 | (isOpenMPParallelDirective(DVar.DKind) || |
| 7756 | isOpenMPWorksharingDirective(DVar.DKind))) { |
| 7757 | Diag(ELoc, diag::err_omp_parallel_reduction_in_task_firstprivate) |
| 7758 | << getOpenMPDirectiveName(DVar.DKind); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7759 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 7760 | continue; |
| 7761 | } |
| 7762 | } |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7763 | |
| 7764 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7765 | // A list item that is private within a teams region must not appear in a |
| 7766 | // firstprivate clause on a distribute construct if any of the distribute |
| 7767 | // regions arising from the distribute construct ever bind to any of the |
| 7768 | // teams regions arising from the teams construct. |
| 7769 | // OpenMP 4.5 [2.15.3.4, Restrictions, p.3] |
| 7770 | // A list item that appears in a reduction clause of a teams construct |
| 7771 | // must not appear in a firstprivate clause on a distribute construct if |
| 7772 | // any of the distribute regions arising from the distribute construct |
| 7773 | // ever bind to any of the teams regions arising from the teams construct. |
| 7774 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 7775 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 7776 | // both. |
| 7777 | if (CurrDir == OMPD_distribute) { |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 7778 | DVar = DSAStack->hasInnermostDSA( |
| 7779 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_private; }, |
| 7780 | [](OpenMPDirectiveKind K) -> bool { |
| 7781 | return isOpenMPTeamsDirective(K); |
| 7782 | }, |
| 7783 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7784 | if (DVar.CKind == OMPC_private && isOpenMPTeamsDirective(DVar.DKind)) { |
| 7785 | Diag(ELoc, diag::err_omp_firstprivate_distribute_private_teams); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7786 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7787 | continue; |
| 7788 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 7789 | DVar = DSAStack->hasInnermostDSA( |
| 7790 | D, [](OpenMPClauseKind C) -> bool { return C == OMPC_reduction; }, |
| 7791 | [](OpenMPDirectiveKind K) -> bool { |
| 7792 | return isOpenMPTeamsDirective(K); |
| 7793 | }, |
| 7794 | false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7795 | if (DVar.CKind == OMPC_reduction && |
| 7796 | isOpenMPTeamsDirective(DVar.DKind)) { |
| 7797 | Diag(ELoc, diag::err_omp_firstprivate_distribute_in_teams_reduction); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7798 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7799 | continue; |
| 7800 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7801 | DVar = DSAStack->getTopDSA(D, false); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7802 | if (DVar.CKind == OMPC_lastprivate) { |
| 7803 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7804 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 7805 | continue; |
| 7806 | } |
| 7807 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7808 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 7809 | // A list item cannot appear in both a map clause and a data-sharing |
| 7810 | // attribute clause on the same construct |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 7811 | if (CurrDir == OMPD_target || CurrDir == OMPD_target_parallel || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7812 | CurrDir == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 7813 | CurrDir == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 7814 | CurrDir == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | c4bfc6f | 2017-01-10 04:26:44 +0000 | [diff] [blame] | 7815 | CurrDir == OMPD_target_teams_distribute_parallel_for_simd || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 7816 | CurrDir == OMPD_target_teams_distribute_simd || |
Kelvin Li | 4101032 | 2017-01-10 05:15:35 +0000 | [diff] [blame] | 7817 | CurrDir == OMPD_target_parallel_for_simd || |
| 7818 | CurrDir == OMPD_target_parallel_for) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7819 | OpenMPClauseKind ConflictKind; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 7820 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 7821 | VD, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7822 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef, |
| 7823 | OpenMPClauseKind WhereFoundClauseKind) -> bool { |
| 7824 | ConflictKind = WhereFoundClauseKind; |
| 7825 | return true; |
| 7826 | })) { |
| 7827 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7828 | << getOpenMPClauseName(OMPC_firstprivate) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 7829 | << getOpenMPClauseName(ConflictKind) |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 7830 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7831 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 7832 | continue; |
| 7833 | } |
| 7834 | } |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7835 | } |
| 7836 | |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7837 | // Variably modified types are not supported for tasks. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 7838 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType() && |
Alexey Bataev | 35aaee6 | 2016-04-13 13:36:48 +0000 | [diff] [blame] | 7839 | isOpenMPTaskingDirective(DSAStack->getCurrentDirective())) { |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7840 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
| 7841 | << getOpenMPClauseName(OMPC_firstprivate) << Type |
| 7842 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 7843 | bool IsDecl = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7844 | !VD || |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7845 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7846 | Diag(D->getLocation(), |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7847 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7848 | << D; |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 7849 | continue; |
| 7850 | } |
| 7851 | |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7852 | Type = Type.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7853 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 7854 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7855 | // Generate helper private variable and initialize it with the value of the |
| 7856 | // original variable. The address of the original variable is replaced by |
| 7857 | // the address of the new private variable in the CodeGen. This new variable |
| 7858 | // is not added to IdResolver, so the code in the OpenMP region uses |
| 7859 | // original variable for proper diagnostics and variable capturing. |
| 7860 | Expr *VDInitRefExpr = nullptr; |
| 7861 | // For arrays generate initializer for single element and replace it by the |
| 7862 | // original array element in CodeGen. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7863 | if (Type->isArrayType()) { |
| 7864 | auto VDInit = |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7865 | buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, D->getName()); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7866 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, ElemType, ELoc); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7867 | auto Init = DefaultLvalueConversion(VDInitRefExpr).get(); |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7868 | ElemType = ElemType.getUnqualifiedType(); |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7869 | auto *VDInitTemp = buildVarDecl(*this, RefExpr->getExprLoc(), ElemType, |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 7870 | ".firstprivate.temp"); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7871 | InitializedEntity Entity = |
| 7872 | InitializedEntity::InitializeVariable(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7873 | InitializationKind Kind = InitializationKind::CreateCopy(ELoc, ELoc); |
| 7874 | |
| 7875 | InitializationSequence InitSeq(*this, Entity, Kind, Init); |
| 7876 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, Init); |
| 7877 | if (Result.isInvalid()) |
| 7878 | VDPrivate->setInvalidDecl(); |
| 7879 | else |
| 7880 | VDPrivate->setInit(Result.getAs<Expr>()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 7881 | // Remove temp variable declaration. |
| 7882 | Context.Deallocate(VDInitTemp); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7883 | } else { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7884 | auto *VDInit = buildVarDecl(*this, RefExpr->getExprLoc(), Type, |
| 7885 | ".firstprivate.temp"); |
| 7886 | VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 7887 | RefExpr->getExprLoc()); |
Alexey Bataev | 69c62a9 | 2015-04-15 04:52:20 +0000 | [diff] [blame] | 7888 | AddInitializerToDecl(VDPrivate, |
| 7889 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 7890 | /*DirectInit=*/false); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7891 | } |
| 7892 | if (VDPrivate->isInvalidDecl()) { |
| 7893 | if (IsImplicitClause) { |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7894 | Diag(RefExpr->getExprLoc(), |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7895 | diag::note_omp_task_predetermined_firstprivate_here); |
| 7896 | } |
| 7897 | continue; |
| 7898 | } |
| 7899 | CurContext->addDecl(VDPrivate); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7900 | auto VDPrivateRefExpr = buildDeclRefExpr( |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7901 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), |
| 7902 | RefExpr->getExprLoc()); |
| 7903 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7904 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7905 | if (TopDVar.CKind == OMPC_lastprivate) |
| 7906 | Ref = TopDVar.PrivateCopy; |
| 7907 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 7908 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7909 | if (!IsOpenMPCapturedDecl(D)) |
| 7910 | ExprCaptures.push_back(Ref->getDecl()); |
| 7911 | } |
Alexey Bataev | 417089f | 2016-02-17 13:19:37 +0000 | [diff] [blame] | 7912 | } |
Alexey Bataev | d985eda | 2016-02-10 11:29:16 +0000 | [diff] [blame] | 7913 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 7914 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 7915 | ? RefExpr->IgnoreParens() |
| 7916 | : Ref); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 7917 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 7918 | Inits.push_back(VDInitRefExpr); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7919 | } |
| 7920 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 7921 | if (Vars.empty()) |
| 7922 | return nullptr; |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7923 | |
| 7924 | return OMPFirstprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 7925 | Vars, PrivateCopies, Inits, |
| 7926 | buildPreInits(Context, ExprCaptures)); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 7927 | } |
| 7928 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7929 | OMPClause *Sema::ActOnOpenMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 7930 | SourceLocation StartLoc, |
| 7931 | SourceLocation LParenLoc, |
| 7932 | SourceLocation EndLoc) { |
| 7933 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7934 | SmallVector<Expr *, 8> SrcExprs; |
| 7935 | SmallVector<Expr *, 8> DstExprs; |
| 7936 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 7937 | SmallVector<Decl *, 4> ExprCaptures; |
| 7938 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7939 | for (auto &RefExpr : VarList) { |
| 7940 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 7941 | SourceLocation ELoc; |
| 7942 | SourceRange ERange; |
| 7943 | Expr *SimpleRefExpr = RefExpr; |
| 7944 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7945 | if (Res.second) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7946 | // It will be analyzed later. |
| 7947 | Vars.push_back(RefExpr); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 7948 | SrcExprs.push_back(nullptr); |
| 7949 | DstExprs.push_back(nullptr); |
| 7950 | AssignmentOps.push_back(nullptr); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7951 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7952 | ValueDecl *D = Res.first; |
| 7953 | if (!D) |
| 7954 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7955 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7956 | QualType Type = D->getType(); |
| 7957 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7958 | |
| 7959 | // OpenMP [2.14.3.5, Restrictions, C/C++, p.2] |
| 7960 | // A variable that appears in a lastprivate clause must not have an |
| 7961 | // incomplete type or a reference type. |
| 7962 | if (RequireCompleteType(ELoc, Type, |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7963 | diag::err_omp_lastprivate_incomplete_type)) |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7964 | continue; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 7965 | Type = Type.getNonReferenceType(); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7966 | |
| 7967 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 7968 | // in a Construct] |
| 7969 | // Variables with the predetermined data-sharing attributes may not be |
| 7970 | // listed in data-sharing attributes clauses, except for the cases |
| 7971 | // listed below. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7972 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7973 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_lastprivate && |
| 7974 | DVar.CKind != OMPC_firstprivate && |
| 7975 | (DVar.CKind != OMPC_private || DVar.RefExpr != nullptr)) { |
| 7976 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 7977 | << getOpenMPClauseName(DVar.CKind) |
| 7978 | << getOpenMPClauseName(OMPC_lastprivate); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7979 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 7980 | continue; |
| 7981 | } |
| 7982 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7983 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 7984 | // OpenMP [2.14.3.5, Restrictions, p.2] |
| 7985 | // A list item that is private within a parallel region, or that appears in |
| 7986 | // the reduction clause of a parallel construct, must not appear in a |
| 7987 | // lastprivate clause on a worksharing construct if any of the corresponding |
| 7988 | // worksharing regions ever binds to any of the corresponding parallel |
| 7989 | // regions. |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 7990 | DSAStackTy::DSAVarData TopDVar = DVar; |
Alexey Bataev | 549210e | 2014-06-24 04:39:47 +0000 | [diff] [blame] | 7991 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 7992 | !isOpenMPParallelDirective(CurrDir) && |
| 7993 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7994 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 7995 | if (DVar.CKind != OMPC_shared) { |
| 7996 | Diag(ELoc, diag::err_omp_required_access) |
| 7997 | << getOpenMPClauseName(OMPC_lastprivate) |
| 7998 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 7999 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8000 | continue; |
| 8001 | } |
| 8002 | } |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8003 | |
| 8004 | // OpenMP 4.5 [2.10.8, Distribute Construct, p.3] |
| 8005 | // A list item may appear in a firstprivate or lastprivate clause but not |
| 8006 | // both. |
| 8007 | if (CurrDir == OMPD_distribute) { |
| 8008 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
| 8009 | if (DVar.CKind == OMPC_firstprivate) { |
| 8010 | Diag(ELoc, diag::err_omp_firstprivate_and_lastprivate_in_distribute); |
| 8011 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 8012 | continue; |
| 8013 | } |
| 8014 | } |
| 8015 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8016 | // OpenMP [2.14.3.5, Restrictions, C++, p.1,2] |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8017 | // A variable of class type (or array thereof) that appears in a |
| 8018 | // lastprivate clause requires an accessible, unambiguous default |
| 8019 | // constructor for the class type, unless the list item is also specified |
| 8020 | // in a firstprivate clause. |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8021 | // A variable of class type (or array thereof) that appears in a |
| 8022 | // lastprivate clause requires an accessible, unambiguous copy assignment |
| 8023 | // operator for the class type. |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8024 | Type = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8025 | auto *SrcVD = buildVarDecl(*this, ERange.getBegin(), |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 8026 | Type.getUnqualifiedType(), ".lastprivate.src", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8027 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8028 | auto *PseudoSrcExpr = |
| 8029 | buildDeclRefExpr(*this, SrcVD, Type.getUnqualifiedType(), ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8030 | auto *DstVD = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8031 | buildVarDecl(*this, ERange.getBegin(), Type, ".lastprivate.dst", |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8032 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8033 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8034 | // For arrays generate assignment operation for single element and replace |
| 8035 | // it by the original array element in CodeGen. |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8036 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, ELoc, BO_Assign, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8037 | PseudoDstExpr, PseudoSrcExpr); |
| 8038 | if (AssignmentOp.isInvalid()) |
| 8039 | continue; |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8040 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8041 | /*DiscardedValue=*/true); |
| 8042 | if (AssignmentOp.isInvalid()) |
| 8043 | continue; |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8044 | |
Alexey Bataev | 74caaf2 | 2016-02-20 04:09:36 +0000 | [diff] [blame] | 8045 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8046 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8047 | if (TopDVar.CKind == OMPC_firstprivate) |
| 8048 | Ref = TopDVar.PrivateCopy; |
| 8049 | else { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8050 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8051 | if (!IsOpenMPCapturedDecl(D)) |
| 8052 | ExprCaptures.push_back(Ref->getDecl()); |
| 8053 | } |
| 8054 | if (TopDVar.CKind == OMPC_firstprivate || |
| 8055 | (!IsOpenMPCapturedDecl(D) && |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8056 | Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>())) { |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8057 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8058 | if (!RefRes.isUsable()) |
| 8059 | continue; |
| 8060 | ExprResult PostUpdateRes = |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8061 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, SimpleRefExpr, |
| 8062 | RefRes.get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8063 | if (!PostUpdateRes.isUsable()) |
| 8064 | continue; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8065 | ExprPostUpdates.push_back( |
| 8066 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8067 | } |
| 8068 | } |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8069 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_lastprivate, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8070 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8071 | ? RefExpr->IgnoreParens() |
| 8072 | : Ref); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 8073 | SrcExprs.push_back(PseudoSrcExpr); |
| 8074 | DstExprs.push_back(PseudoDstExpr); |
| 8075 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8076 | } |
| 8077 | |
| 8078 | if (Vars.empty()) |
| 8079 | return nullptr; |
| 8080 | |
| 8081 | return OMPLastprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
Alexey Bataev | 005248a | 2016-02-25 05:25:57 +0000 | [diff] [blame] | 8082 | Vars, SrcExprs, DstExprs, AssignmentOps, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8083 | buildPreInits(Context, ExprCaptures), |
| 8084 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 8085 | } |
| 8086 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8087 | OMPClause *Sema::ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 8088 | SourceLocation StartLoc, |
| 8089 | SourceLocation LParenLoc, |
| 8090 | SourceLocation EndLoc) { |
| 8091 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8092 | for (auto &RefExpr : VarList) { |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8093 | assert(RefExpr && "NULL expr in OpenMP lastprivate clause."); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8094 | SourceLocation ELoc; |
| 8095 | SourceRange ERange; |
| 8096 | Expr *SimpleRefExpr = RefExpr; |
| 8097 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8098 | if (Res.second) { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8099 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8100 | Vars.push_back(RefExpr); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8101 | } |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8102 | ValueDecl *D = Res.first; |
| 8103 | if (!D) |
| 8104 | continue; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8105 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8106 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8107 | // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8108 | // in a Construct] |
| 8109 | // Variables with the predetermined data-sharing attributes may not be |
| 8110 | // listed in data-sharing attributes clauses, except for the cases |
| 8111 | // listed below. For these exceptions only, listing a predetermined |
| 8112 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8113 | // the variable's predetermined data-sharing attributes. |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8114 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8115 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_shared && |
| 8116 | DVar.RefExpr) { |
| 8117 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8118 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8119 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8120 | continue; |
| 8121 | } |
| 8122 | |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8123 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8124 | if (!VD && IsOpenMPCapturedDecl(D) && !CurContext->isDependentContext()) |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8125 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
Alexey Bataev | b7a34b6 | 2016-02-25 03:59:29 +0000 | [diff] [blame] | 8126 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_shared, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8127 | Vars.push_back((VD || !Ref || CurContext->isDependentContext()) |
| 8128 | ? RefExpr->IgnoreParens() |
| 8129 | : Ref); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8130 | } |
| 8131 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8132 | if (Vars.empty()) |
| 8133 | return nullptr; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 8134 | |
| 8135 | return OMPSharedClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars); |
| 8136 | } |
| 8137 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8138 | namespace { |
| 8139 | class DSARefChecker : public StmtVisitor<DSARefChecker, bool> { |
| 8140 | DSAStackTy *Stack; |
| 8141 | |
| 8142 | public: |
| 8143 | bool VisitDeclRefExpr(DeclRefExpr *E) { |
| 8144 | if (VarDecl *VD = dyn_cast<VarDecl>(E->getDecl())) { |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 8145 | DSAStackTy::DSAVarData DVar = Stack->getTopDSA(VD, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8146 | if (DVar.CKind == OMPC_shared && !DVar.RefExpr) |
| 8147 | return false; |
| 8148 | if (DVar.CKind != OMPC_unknown) |
| 8149 | return true; |
Alexey Bataev | 7ace49d | 2016-05-17 08:55:33 +0000 | [diff] [blame] | 8150 | DSAStackTy::DSAVarData DVarPrivate = Stack->hasDSA( |
| 8151 | VD, isOpenMPPrivate, [](OpenMPDirectiveKind) -> bool { return true; }, |
| 8152 | false); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8153 | if (DVarPrivate.CKind != OMPC_unknown) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8154 | return true; |
| 8155 | return false; |
| 8156 | } |
| 8157 | return false; |
| 8158 | } |
| 8159 | bool VisitStmt(Stmt *S) { |
| 8160 | for (auto Child : S->children()) { |
| 8161 | if (Child && Visit(Child)) |
| 8162 | return true; |
| 8163 | } |
| 8164 | return false; |
| 8165 | } |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8166 | explicit DSARefChecker(DSAStackTy *S) : Stack(S) {} |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8167 | }; |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 8168 | } // namespace |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8169 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8170 | namespace { |
| 8171 | // Transform MemberExpression for specified FieldDecl of current class to |
| 8172 | // DeclRefExpr to specified OMPCapturedExprDecl. |
| 8173 | class TransformExprToCaptures : public TreeTransform<TransformExprToCaptures> { |
| 8174 | typedef TreeTransform<TransformExprToCaptures> BaseTransform; |
| 8175 | ValueDecl *Field; |
| 8176 | DeclRefExpr *CapturedExpr; |
| 8177 | |
| 8178 | public: |
| 8179 | TransformExprToCaptures(Sema &SemaRef, ValueDecl *FieldDecl) |
| 8180 | : BaseTransform(SemaRef), Field(FieldDecl), CapturedExpr(nullptr) {} |
| 8181 | |
| 8182 | ExprResult TransformMemberExpr(MemberExpr *E) { |
| 8183 | if (isa<CXXThisExpr>(E->getBase()->IgnoreParenImpCasts()) && |
| 8184 | E->getMemberDecl() == Field) { |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8185 | CapturedExpr = buildCapture(SemaRef, Field, E, /*WithInit=*/false); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8186 | return CapturedExpr; |
| 8187 | } |
| 8188 | return BaseTransform::TransformMemberExpr(E); |
| 8189 | } |
| 8190 | DeclRefExpr *getCapturedExpr() { return CapturedExpr; } |
| 8191 | }; |
| 8192 | } // namespace |
| 8193 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8194 | template <typename T> |
| 8195 | static T filterLookupForUDR(SmallVectorImpl<UnresolvedSet<8>> &Lookups, |
| 8196 | const llvm::function_ref<T(ValueDecl *)> &Gen) { |
| 8197 | for (auto &Set : Lookups) { |
| 8198 | for (auto *D : Set) { |
| 8199 | if (auto Res = Gen(cast<ValueDecl>(D))) |
| 8200 | return Res; |
| 8201 | } |
| 8202 | } |
| 8203 | return T(); |
| 8204 | } |
| 8205 | |
| 8206 | static ExprResult |
| 8207 | buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range, |
| 8208 | Scope *S, CXXScopeSpec &ReductionIdScopeSpec, |
| 8209 | const DeclarationNameInfo &ReductionId, QualType Ty, |
| 8210 | CXXCastPath &BasePath, Expr *UnresolvedReduction) { |
| 8211 | if (ReductionIdScopeSpec.isInvalid()) |
| 8212 | return ExprError(); |
| 8213 | SmallVector<UnresolvedSet<8>, 4> Lookups; |
| 8214 | if (S) { |
| 8215 | LookupResult Lookup(SemaRef, ReductionId, Sema::LookupOMPReductionName); |
| 8216 | Lookup.suppressDiagnostics(); |
| 8217 | while (S && SemaRef.LookupParsedName(Lookup, S, &ReductionIdScopeSpec)) { |
| 8218 | auto *D = Lookup.getRepresentativeDecl(); |
| 8219 | do { |
| 8220 | S = S->getParent(); |
| 8221 | } while (S && !S->isDeclScope(D)); |
| 8222 | if (S) |
| 8223 | S = S->getParent(); |
| 8224 | Lookups.push_back(UnresolvedSet<8>()); |
| 8225 | Lookups.back().append(Lookup.begin(), Lookup.end()); |
| 8226 | Lookup.clear(); |
| 8227 | } |
| 8228 | } else if (auto *ULE = |
| 8229 | cast_or_null<UnresolvedLookupExpr>(UnresolvedReduction)) { |
| 8230 | Lookups.push_back(UnresolvedSet<8>()); |
| 8231 | Decl *PrevD = nullptr; |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8232 | for (auto *D : ULE->decls()) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8233 | if (D == PrevD) |
| 8234 | Lookups.push_back(UnresolvedSet<8>()); |
| 8235 | else if (auto *DRD = cast<OMPDeclareReductionDecl>(D)) |
| 8236 | Lookups.back().addDecl(DRD); |
| 8237 | PrevD = D; |
| 8238 | } |
| 8239 | } |
| 8240 | if (Ty->isDependentType() || Ty->isInstantiationDependentType() || |
| 8241 | Ty->containsUnexpandedParameterPack() || |
| 8242 | filterLookupForUDR<bool>(Lookups, [](ValueDecl *D) -> bool { |
| 8243 | return !D->isInvalidDecl() && |
| 8244 | (D->getType()->isDependentType() || |
| 8245 | D->getType()->isInstantiationDependentType() || |
| 8246 | D->getType()->containsUnexpandedParameterPack()); |
| 8247 | })) { |
| 8248 | UnresolvedSet<8> ResSet; |
| 8249 | for (auto &Set : Lookups) { |
| 8250 | ResSet.append(Set.begin(), Set.end()); |
| 8251 | // The last item marks the end of all declarations at the specified scope. |
| 8252 | ResSet.addDecl(Set[Set.size() - 1]); |
| 8253 | } |
| 8254 | return UnresolvedLookupExpr::Create( |
| 8255 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 8256 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), ReductionId, |
| 8257 | /*ADL=*/true, /*Overloaded=*/true, ResSet.begin(), ResSet.end()); |
| 8258 | } |
| 8259 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8260 | Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * { |
| 8261 | if (!D->isInvalidDecl() && |
| 8262 | SemaRef.Context.hasSameType(D->getType(), Ty)) |
| 8263 | return D; |
| 8264 | return nullptr; |
| 8265 | })) |
| 8266 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8267 | if (auto *VD = filterLookupForUDR<ValueDecl *>( |
| 8268 | Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * { |
| 8269 | if (!D->isInvalidDecl() && |
| 8270 | SemaRef.IsDerivedFrom(Loc, Ty, D->getType()) && |
| 8271 | !Ty.isMoreQualifiedThan(D->getType())) |
| 8272 | return D; |
| 8273 | return nullptr; |
| 8274 | })) { |
| 8275 | CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true, |
| 8276 | /*DetectVirtual=*/false); |
| 8277 | if (SemaRef.IsDerivedFrom(Loc, Ty, VD->getType(), Paths)) { |
| 8278 | if (!Paths.isAmbiguous(SemaRef.Context.getCanonicalType( |
| 8279 | VD->getType().getUnqualifiedType()))) { |
| 8280 | if (SemaRef.CheckBaseClassAccess(Loc, VD->getType(), Ty, Paths.front(), |
| 8281 | /*DiagID=*/0) != |
| 8282 | Sema::AR_inaccessible) { |
| 8283 | SemaRef.BuildBasePathArray(Paths, BasePath); |
| 8284 | return SemaRef.BuildDeclRefExpr(VD, Ty, VK_LValue, Loc); |
| 8285 | } |
| 8286 | } |
| 8287 | } |
| 8288 | } |
| 8289 | if (ReductionIdScopeSpec.isSet()) { |
| 8290 | SemaRef.Diag(Loc, diag::err_omp_not_resolved_reduction_identifier) << Range; |
| 8291 | return ExprError(); |
| 8292 | } |
| 8293 | return ExprEmpty(); |
| 8294 | } |
| 8295 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8296 | OMPClause *Sema::ActOnOpenMPReductionClause( |
| 8297 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 8298 | SourceLocation ColonLoc, SourceLocation EndLoc, |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8299 | CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, |
| 8300 | ArrayRef<Expr *> UnresolvedReductions) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8301 | auto DN = ReductionId.getName(); |
| 8302 | auto OOK = DN.getCXXOverloadedOperator(); |
| 8303 | BinaryOperatorKind BOK = BO_Comma; |
| 8304 | |
| 8305 | // OpenMP [2.14.3.6, reduction clause] |
| 8306 | // C |
| 8307 | // reduction-identifier is either an identifier or one of the following |
| 8308 | // operators: +, -, *, &, |, ^, && and || |
| 8309 | // C++ |
| 8310 | // reduction-identifier is either an id-expression or one of the following |
| 8311 | // operators: +, -, *, &, |, ^, && and || |
| 8312 | // FIXME: Only 'min' and 'max' identifiers are supported for now. |
| 8313 | switch (OOK) { |
| 8314 | case OO_Plus: |
| 8315 | case OO_Minus: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8316 | BOK = BO_Add; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8317 | break; |
| 8318 | case OO_Star: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8319 | BOK = BO_Mul; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8320 | break; |
| 8321 | case OO_Amp: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8322 | BOK = BO_And; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8323 | break; |
| 8324 | case OO_Pipe: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8325 | BOK = BO_Or; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8326 | break; |
| 8327 | case OO_Caret: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8328 | BOK = BO_Xor; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8329 | break; |
| 8330 | case OO_AmpAmp: |
| 8331 | BOK = BO_LAnd; |
| 8332 | break; |
| 8333 | case OO_PipePipe: |
| 8334 | BOK = BO_LOr; |
| 8335 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8336 | case OO_New: |
| 8337 | case OO_Delete: |
| 8338 | case OO_Array_New: |
| 8339 | case OO_Array_Delete: |
| 8340 | case OO_Slash: |
| 8341 | case OO_Percent: |
| 8342 | case OO_Tilde: |
| 8343 | case OO_Exclaim: |
| 8344 | case OO_Equal: |
| 8345 | case OO_Less: |
| 8346 | case OO_Greater: |
| 8347 | case OO_LessEqual: |
| 8348 | case OO_GreaterEqual: |
| 8349 | case OO_PlusEqual: |
| 8350 | case OO_MinusEqual: |
| 8351 | case OO_StarEqual: |
| 8352 | case OO_SlashEqual: |
| 8353 | case OO_PercentEqual: |
| 8354 | case OO_CaretEqual: |
| 8355 | case OO_AmpEqual: |
| 8356 | case OO_PipeEqual: |
| 8357 | case OO_LessLess: |
| 8358 | case OO_GreaterGreater: |
| 8359 | case OO_LessLessEqual: |
| 8360 | case OO_GreaterGreaterEqual: |
| 8361 | case OO_EqualEqual: |
| 8362 | case OO_ExclaimEqual: |
| 8363 | case OO_PlusPlus: |
| 8364 | case OO_MinusMinus: |
| 8365 | case OO_Comma: |
| 8366 | case OO_ArrowStar: |
| 8367 | case OO_Arrow: |
| 8368 | case OO_Call: |
| 8369 | case OO_Subscript: |
| 8370 | case OO_Conditional: |
Richard Smith | 9be594e | 2015-10-22 05:12:22 +0000 | [diff] [blame] | 8371 | case OO_Coawait: |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8372 | case NUM_OVERLOADED_OPERATORS: |
| 8373 | llvm_unreachable("Unexpected reduction identifier"); |
| 8374 | case OO_None: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8375 | if (auto II = DN.getAsIdentifierInfo()) { |
| 8376 | if (II->isStr("max")) |
| 8377 | BOK = BO_GT; |
| 8378 | else if (II->isStr("min")) |
| 8379 | BOK = BO_LT; |
| 8380 | } |
| 8381 | break; |
| 8382 | } |
| 8383 | SourceRange ReductionIdRange; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8384 | if (ReductionIdScopeSpec.isValid()) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8385 | ReductionIdRange.setBegin(ReductionIdScopeSpec.getBeginLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8386 | ReductionIdRange.setEnd(ReductionId.getEndLoc()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8387 | |
| 8388 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8389 | SmallVector<Expr *, 8> Privates; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8390 | SmallVector<Expr *, 8> LHSs; |
| 8391 | SmallVector<Expr *, 8> RHSs; |
| 8392 | SmallVector<Expr *, 8> ReductionOps; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8393 | SmallVector<Decl *, 4> ExprCaptures; |
| 8394 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8395 | auto IR = UnresolvedReductions.begin(), ER = UnresolvedReductions.end(); |
| 8396 | bool FirstIter = true; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8397 | for (auto RefExpr : VarList) { |
| 8398 | assert(RefExpr && "nullptr expr in OpenMP reduction clause."); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8399 | // OpenMP [2.1, C/C++] |
| 8400 | // A list item is a variable or array section, subject to the restrictions |
| 8401 | // specified in Section 2.4 on page 42 and in each of the sections |
| 8402 | // describing clauses and directives for which a list appears. |
| 8403 | // OpenMP [2.14.3.3, Restrictions, p.1] |
| 8404 | // A variable that is part of another variable (as an array or |
| 8405 | // structure element) cannot appear in a private clause. |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8406 | if (!FirstIter && IR != ER) |
| 8407 | ++IR; |
| 8408 | FirstIter = false; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8409 | SourceLocation ELoc; |
| 8410 | SourceRange ERange; |
| 8411 | Expr *SimpleRefExpr = RefExpr; |
| 8412 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8413 | /*AllowArraySection=*/true); |
| 8414 | if (Res.second) { |
| 8415 | // It will be analyzed later. |
| 8416 | Vars.push_back(RefExpr); |
| 8417 | Privates.push_back(nullptr); |
| 8418 | LHSs.push_back(nullptr); |
| 8419 | RHSs.push_back(nullptr); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8420 | // Try to find 'declare reduction' corresponding construct before using |
| 8421 | // builtin/overloaded operators. |
| 8422 | QualType Type = Context.DependentTy; |
| 8423 | CXXCastPath BasePath; |
| 8424 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8425 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8426 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8427 | if (CurContext->isDependentContext() && |
| 8428 | (DeclareReductionRef.isUnset() || |
| 8429 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) |
| 8430 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8431 | else |
| 8432 | ReductionOps.push_back(nullptr); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8433 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8434 | ValueDecl *D = Res.first; |
| 8435 | if (!D) |
| 8436 | continue; |
| 8437 | |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8438 | QualType Type; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8439 | auto *ASE = dyn_cast<ArraySubscriptExpr>(RefExpr->IgnoreParens()); |
| 8440 | auto *OASE = dyn_cast<OMPArraySectionExpr>(RefExpr->IgnoreParens()); |
| 8441 | if (ASE) |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8442 | Type = ASE->getType().getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8443 | else if (OASE) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8444 | auto BaseType = OMPArraySectionExpr::getBaseOriginalType(OASE->getBase()); |
| 8445 | if (auto *ATy = BaseType->getAsArrayTypeUnsafe()) |
| 8446 | Type = ATy->getElementType(); |
| 8447 | else |
| 8448 | Type = BaseType->getPointeeType(); |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 8449 | Type = Type.getNonReferenceType(); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8450 | } else |
| 8451 | Type = Context.getBaseElementType(D->getType().getNonReferenceType()); |
| 8452 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8453 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8454 | // OpenMP [2.9.3.3, Restrictions, C/C++, p.3] |
| 8455 | // A variable that appears in a private clause must not have an incomplete |
| 8456 | // type or a reference type. |
| 8457 | if (RequireCompleteType(ELoc, Type, |
| 8458 | diag::err_omp_reduction_incomplete_type)) |
| 8459 | continue; |
| 8460 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8461 | // A list item that appears in a reduction clause must not be |
| 8462 | // const-qualified. |
| 8463 | if (Type.getNonReferenceType().isConstant(Context)) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8464 | Diag(ELoc, diag::err_omp_const_reduction_list_item) |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8465 | << getOpenMPClauseName(OMPC_reduction) << Type << ERange; |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8466 | if (!ASE && !OASE) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8467 | bool IsDecl = !VD || |
| 8468 | VD->isThisDeclarationADefinition(Context) == |
| 8469 | VarDecl::DeclarationOnly; |
| 8470 | Diag(D->getLocation(), |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8471 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8472 | << D; |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8473 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8474 | continue; |
| 8475 | } |
| 8476 | // OpenMP [2.9.3.6, Restrictions, C/C++, p.4] |
| 8477 | // If a list-item is a reference type then it must bind to the same object |
| 8478 | // for all threads of the team. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8479 | if (!ASE && !OASE && VD) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8480 | VarDecl *VDDef = VD->getDefinition(); |
David Sheinkman | 9258999 | 2016-10-04 14:41:36 +0000 | [diff] [blame] | 8481 | if (VD->getType()->isReferenceType() && VDDef && VDDef->hasInit()) { |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8482 | DSARefChecker Check(DSAStack); |
| 8483 | if (Check.Visit(VDDef->getInit())) { |
| 8484 | Diag(ELoc, diag::err_omp_reduction_ref_type_arg) << ERange; |
| 8485 | Diag(VDDef->getLocation(), diag::note_defined_here) << VDDef; |
| 8486 | continue; |
| 8487 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8488 | } |
| 8489 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8490 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8491 | // OpenMP [2.14.1.1, Data-sharing Attribute Rules for Variables Referenced |
| 8492 | // in a Construct] |
| 8493 | // Variables with the predetermined data-sharing attributes may not be |
| 8494 | // listed in data-sharing attributes clauses, except for the cases |
| 8495 | // listed below. For these exceptions only, listing a predetermined |
| 8496 | // variable in a data-sharing attribute clause is allowed and overrides |
| 8497 | // the variable's predetermined data-sharing attributes. |
| 8498 | // OpenMP [2.14.3.6, Restrictions, p.3] |
| 8499 | // Any number of reduction clauses can be specified on the directive, |
| 8500 | // but a list item can appear only once in the reduction clauses for that |
| 8501 | // directive. |
Alexey Bataev | a176421 | 2015-09-30 09:22:36 +0000 | [diff] [blame] | 8502 | DSAStackTy::DSAVarData DVar; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8503 | DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8504 | if (DVar.CKind == OMPC_reduction) { |
| 8505 | Diag(ELoc, diag::err_omp_once_referenced) |
| 8506 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8507 | if (DVar.RefExpr) |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8508 | Diag(DVar.RefExpr->getExprLoc(), diag::note_omp_referenced); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8509 | } else if (DVar.CKind != OMPC_unknown) { |
| 8510 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 8511 | << getOpenMPClauseName(DVar.CKind) |
| 8512 | << getOpenMPClauseName(OMPC_reduction); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8513 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8514 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8515 | } |
| 8516 | |
| 8517 | // OpenMP [2.14.3.6, Restrictions, p.1] |
| 8518 | // A list item that appears in a reduction clause of a worksharing |
| 8519 | // construct must be shared in the parallel regions to which any of the |
| 8520 | // worksharing regions arising from the worksharing construct bind. |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8521 | OpenMPDirectiveKind CurrDir = DSAStack->getCurrentDirective(); |
| 8522 | if (isOpenMPWorksharingDirective(CurrDir) && |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 8523 | !isOpenMPParallelDirective(CurrDir) && |
| 8524 | !isOpenMPTeamsDirective(CurrDir)) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8525 | DVar = DSAStack->getImplicitDSA(D, true); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8526 | if (DVar.CKind != OMPC_shared) { |
| 8527 | Diag(ELoc, diag::err_omp_required_access) |
| 8528 | << getOpenMPClauseName(OMPC_reduction) |
| 8529 | << getOpenMPClauseName(OMPC_shared); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8530 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8531 | continue; |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 8532 | } |
| 8533 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8534 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8535 | // Try to find 'declare reduction' corresponding construct before using |
| 8536 | // builtin/overloaded operators. |
| 8537 | CXXCastPath BasePath; |
| 8538 | ExprResult DeclareReductionRef = buildDeclareReductionRef( |
| 8539 | *this, ELoc, ERange, DSAStack->getCurScope(), ReductionIdScopeSpec, |
| 8540 | ReductionId, Type, BasePath, IR == ER ? nullptr : *IR); |
| 8541 | if (DeclareReductionRef.isInvalid()) |
| 8542 | continue; |
| 8543 | if (CurContext->isDependentContext() && |
| 8544 | (DeclareReductionRef.isUnset() || |
| 8545 | isa<UnresolvedLookupExpr>(DeclareReductionRef.get()))) { |
| 8546 | Vars.push_back(RefExpr); |
| 8547 | Privates.push_back(nullptr); |
| 8548 | LHSs.push_back(nullptr); |
| 8549 | RHSs.push_back(nullptr); |
| 8550 | ReductionOps.push_back(DeclareReductionRef.get()); |
| 8551 | continue; |
| 8552 | } |
| 8553 | if (BOK == BO_Comma && DeclareReductionRef.isUnset()) { |
| 8554 | // Not allowed reduction identifier is found. |
| 8555 | Diag(ReductionId.getLocStart(), |
| 8556 | diag::err_omp_unknown_reduction_identifier) |
| 8557 | << Type << ReductionIdRange; |
| 8558 | continue; |
| 8559 | } |
| 8560 | |
| 8561 | // OpenMP [2.14.3.6, reduction clause, Restrictions] |
| 8562 | // The type of a list item that appears in a reduction clause must be valid |
| 8563 | // for the reduction-identifier. For a max or min reduction in C, the type |
| 8564 | // of the list item must be an allowed arithmetic data type: char, int, |
| 8565 | // float, double, or _Bool, possibly modified with long, short, signed, or |
| 8566 | // unsigned. For a max or min reduction in C++, the type of the list item |
| 8567 | // must be an allowed arithmetic data type: char, wchar_t, int, float, |
| 8568 | // double, or bool, possibly modified with long, short, signed, or unsigned. |
| 8569 | if (DeclareReductionRef.isUnset()) { |
| 8570 | if ((BOK == BO_GT || BOK == BO_LT) && |
| 8571 | !(Type->isScalarType() || |
| 8572 | (getLangOpts().CPlusPlus && Type->isArithmeticType()))) { |
| 8573 | Diag(ELoc, diag::err_omp_clause_not_arithmetic_type_arg) |
| 8574 | << getLangOpts().CPlusPlus; |
| 8575 | if (!ASE && !OASE) { |
| 8576 | bool IsDecl = !VD || |
| 8577 | VD->isThisDeclarationADefinition(Context) == |
| 8578 | VarDecl::DeclarationOnly; |
| 8579 | Diag(D->getLocation(), |
| 8580 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8581 | << D; |
| 8582 | } |
| 8583 | continue; |
| 8584 | } |
| 8585 | if ((BOK == BO_OrAssign || BOK == BO_AndAssign || BOK == BO_XorAssign) && |
| 8586 | !getLangOpts().CPlusPlus && Type->isFloatingType()) { |
| 8587 | Diag(ELoc, diag::err_omp_clause_floating_type_arg); |
| 8588 | if (!ASE && !OASE) { |
| 8589 | bool IsDecl = !VD || |
| 8590 | VD->isThisDeclarationADefinition(Context) == |
| 8591 | VarDecl::DeclarationOnly; |
| 8592 | Diag(D->getLocation(), |
| 8593 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8594 | << D; |
| 8595 | } |
| 8596 | continue; |
| 8597 | } |
| 8598 | } |
| 8599 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8600 | Type = Type.getNonLValueExprType(Context).getUnqualifiedType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8601 | auto *LHSVD = buildVarDecl(*this, ELoc, Type, ".reduction.lhs", |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8602 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8603 | auto *RHSVD = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8604 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8605 | auto PrivateTy = Type; |
Alexey Bataev | 1189bd0 | 2016-01-26 12:20:39 +0000 | [diff] [blame] | 8606 | if (OASE || |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8607 | (!ASE && |
| 8608 | D->getType().getNonReferenceType()->isVariablyModifiedType())) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 8609 | // For arrays/array sections only: |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8610 | // Create pseudo array type for private copy. The size for this array will |
| 8611 | // be generated during codegen. |
| 8612 | // For array subscripts or single variables Private Ty is the same as Type |
| 8613 | // (type of the variable or single array element). |
| 8614 | PrivateTy = Context.getVariableArrayType( |
| 8615 | Type, new (Context) OpaqueValueExpr(SourceLocation(), |
| 8616 | Context.getSizeType(), VK_RValue), |
| 8617 | ArrayType::Normal, /*IndexTypeQuals=*/0, SourceRange()); |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8618 | } else if (!ASE && !OASE && |
| 8619 | Context.getAsArrayType(D->getType().getNonReferenceType())) |
| 8620 | PrivateTy = D->getType().getNonReferenceType(); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8621 | // Private copy. |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8622 | auto *PrivateVD = buildVarDecl(*this, ELoc, PrivateTy, D->getName(), |
| 8623 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8624 | // Add initializer for private variable. |
| 8625 | Expr *Init = nullptr; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8626 | auto *LHSDRE = buildDeclRefExpr(*this, LHSVD, Type, ELoc); |
| 8627 | auto *RHSDRE = buildDeclRefExpr(*this, RHSVD, Type, ELoc); |
| 8628 | if (DeclareReductionRef.isUsable()) { |
| 8629 | auto *DRDRef = DeclareReductionRef.getAs<DeclRefExpr>(); |
| 8630 | auto *DRD = cast<OMPDeclareReductionDecl>(DRDRef->getDecl()); |
| 8631 | if (DRD->getInitializer()) { |
| 8632 | Init = DRDRef; |
| 8633 | RHSVD->setInit(DRDRef); |
| 8634 | RHSVD->setInitStyle(VarDecl::CallInit); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8635 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8636 | } else { |
| 8637 | switch (BOK) { |
| 8638 | case BO_Add: |
| 8639 | case BO_Xor: |
| 8640 | case BO_Or: |
| 8641 | case BO_LOr: |
| 8642 | // '+', '-', '^', '|', '||' reduction ops - initializer is '0'. |
| 8643 | if (Type->isScalarType() || Type->isAnyComplexType()) |
| 8644 | Init = ActOnIntegerConstant(ELoc, /*Val=*/0).get(); |
| 8645 | break; |
| 8646 | case BO_Mul: |
| 8647 | case BO_LAnd: |
| 8648 | if (Type->isScalarType() || Type->isAnyComplexType()) { |
| 8649 | // '*' and '&&' reduction ops - initializer is '1'. |
| 8650 | Init = ActOnIntegerConstant(ELoc, /*Val=*/1).get(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8651 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8652 | break; |
| 8653 | case BO_And: { |
| 8654 | // '&' reduction op - initializer is '~0'. |
| 8655 | QualType OrigType = Type; |
| 8656 | if (auto *ComplexTy = OrigType->getAs<ComplexType>()) |
| 8657 | Type = ComplexTy->getElementType(); |
| 8658 | if (Type->isRealFloatingType()) { |
| 8659 | llvm::APFloat InitValue = |
| 8660 | llvm::APFloat::getAllOnesValue(Context.getTypeSize(Type), |
| 8661 | /*isIEEE=*/true); |
| 8662 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8663 | Type, ELoc); |
| 8664 | } else if (Type->isScalarType()) { |
| 8665 | auto Size = Context.getTypeSize(Type); |
| 8666 | QualType IntTy = Context.getIntTypeForBitwidth(Size, /*Signed=*/0); |
| 8667 | llvm::APInt InitValue = llvm::APInt::getAllOnesValue(Size); |
| 8668 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8669 | } |
| 8670 | if (Init && OrigType->isAnyComplexType()) { |
| 8671 | // Init = 0xFFFF + 0xFFFFi; |
| 8672 | auto *Im = new (Context) ImaginaryLiteral(Init, OrigType); |
| 8673 | Init = CreateBuiltinBinOp(ELoc, BO_Add, Init, Im).get(); |
| 8674 | } |
| 8675 | Type = OrigType; |
| 8676 | break; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8677 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8678 | case BO_LT: |
| 8679 | case BO_GT: { |
| 8680 | // 'min' reduction op - initializer is 'Largest representable number in |
| 8681 | // the reduction list item type'. |
| 8682 | // 'max' reduction op - initializer is 'Least representable number in |
| 8683 | // the reduction list item type'. |
| 8684 | if (Type->isIntegerType() || Type->isPointerType()) { |
| 8685 | bool IsSigned = Type->hasSignedIntegerRepresentation(); |
| 8686 | auto Size = Context.getTypeSize(Type); |
| 8687 | QualType IntTy = |
| 8688 | Context.getIntTypeForBitwidth(Size, /*Signed=*/IsSigned); |
| 8689 | llvm::APInt InitValue = |
| 8690 | (BOK != BO_LT) |
| 8691 | ? IsSigned ? llvm::APInt::getSignedMinValue(Size) |
| 8692 | : llvm::APInt::getMinValue(Size) |
| 8693 | : IsSigned ? llvm::APInt::getSignedMaxValue(Size) |
| 8694 | : llvm::APInt::getMaxValue(Size); |
| 8695 | Init = IntegerLiteral::Create(Context, InitValue, IntTy, ELoc); |
| 8696 | if (Type->isPointerType()) { |
| 8697 | // Cast to pointer type. |
| 8698 | auto CastExpr = BuildCStyleCastExpr( |
| 8699 | SourceLocation(), Context.getTrivialTypeSourceInfo(Type, ELoc), |
| 8700 | SourceLocation(), Init); |
| 8701 | if (CastExpr.isInvalid()) |
| 8702 | continue; |
| 8703 | Init = CastExpr.get(); |
| 8704 | } |
| 8705 | } else if (Type->isRealFloatingType()) { |
| 8706 | llvm::APFloat InitValue = llvm::APFloat::getLargest( |
| 8707 | Context.getFloatTypeSemantics(Type), BOK != BO_LT); |
| 8708 | Init = FloatingLiteral::Create(Context, InitValue, /*isexact=*/true, |
| 8709 | Type, ELoc); |
| 8710 | } |
| 8711 | break; |
| 8712 | } |
| 8713 | case BO_PtrMemD: |
| 8714 | case BO_PtrMemI: |
| 8715 | case BO_MulAssign: |
| 8716 | case BO_Div: |
| 8717 | case BO_Rem: |
| 8718 | case BO_Sub: |
| 8719 | case BO_Shl: |
| 8720 | case BO_Shr: |
| 8721 | case BO_LE: |
| 8722 | case BO_GE: |
| 8723 | case BO_EQ: |
| 8724 | case BO_NE: |
| 8725 | case BO_AndAssign: |
| 8726 | case BO_XorAssign: |
| 8727 | case BO_OrAssign: |
| 8728 | case BO_Assign: |
| 8729 | case BO_AddAssign: |
| 8730 | case BO_SubAssign: |
| 8731 | case BO_DivAssign: |
| 8732 | case BO_RemAssign: |
| 8733 | case BO_ShlAssign: |
| 8734 | case BO_ShrAssign: |
| 8735 | case BO_Comma: |
| 8736 | llvm_unreachable("Unexpected reduction operation"); |
| 8737 | } |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8738 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8739 | if (Init && DeclareReductionRef.isUnset()) { |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8740 | AddInitializerToDecl(RHSVD, Init, /*DirectInit=*/false); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8741 | } else if (!Init) |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8742 | ActOnUninitializedDecl(RHSVD); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8743 | if (RHSVD->isInvalidDecl()) |
| 8744 | continue; |
| 8745 | if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) { |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8746 | Diag(ELoc, diag::err_omp_reduction_id_not_compatible) << Type |
| 8747 | << ReductionIdRange; |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8748 | bool IsDecl = |
| 8749 | !VD || |
| 8750 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8751 | Diag(D->getLocation(), |
| 8752 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8753 | << D; |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8754 | continue; |
| 8755 | } |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8756 | // Store initializer for single element in private copy. Will be used during |
| 8757 | // codegen. |
| 8758 | PrivateVD->setInit(RHSVD->getInit()); |
| 8759 | PrivateVD->setInitStyle(RHSVD->getInitStyle()); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8760 | auto *PrivateDRE = buildDeclRefExpr(*this, PrivateVD, PrivateTy, ELoc); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8761 | ExprResult ReductionOp; |
| 8762 | if (DeclareReductionRef.isUsable()) { |
| 8763 | QualType RedTy = DeclareReductionRef.get()->getType(); |
| 8764 | QualType PtrRedTy = Context.getPointerType(RedTy); |
| 8765 | ExprResult LHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, LHSDRE); |
| 8766 | ExprResult RHS = CreateBuiltinUnaryOp(ELoc, UO_AddrOf, RHSDRE); |
| 8767 | if (!BasePath.empty()) { |
| 8768 | LHS = DefaultLvalueConversion(LHS.get()); |
| 8769 | RHS = DefaultLvalueConversion(RHS.get()); |
| 8770 | LHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8771 | CK_UncheckedDerivedToBase, LHS.get(), |
| 8772 | &BasePath, LHS.get()->getValueKind()); |
| 8773 | RHS = ImplicitCastExpr::Create(Context, PtrRedTy, |
| 8774 | CK_UncheckedDerivedToBase, RHS.get(), |
| 8775 | &BasePath, RHS.get()->getValueKind()); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8776 | } |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 8777 | FunctionProtoType::ExtProtoInfo EPI; |
| 8778 | QualType Params[] = {PtrRedTy, PtrRedTy}; |
| 8779 | QualType FnTy = Context.getFunctionType(Context.VoidTy, Params, EPI); |
| 8780 | auto *OVE = new (Context) OpaqueValueExpr( |
| 8781 | ELoc, Context.getPointerType(FnTy), VK_RValue, OK_Ordinary, |
| 8782 | DefaultLvalueConversion(DeclareReductionRef.get()).get()); |
| 8783 | Expr *Args[] = {LHS.get(), RHS.get()}; |
| 8784 | ReductionOp = new (Context) |
| 8785 | CallExpr(Context, OVE, Args, Context.VoidTy, VK_RValue, ELoc); |
| 8786 | } else { |
| 8787 | ReductionOp = BuildBinOp(DSAStack->getCurScope(), |
| 8788 | ReductionId.getLocStart(), BOK, LHSDRE, RHSDRE); |
| 8789 | if (ReductionOp.isUsable()) { |
| 8790 | if (BOK != BO_LT && BOK != BO_GT) { |
| 8791 | ReductionOp = |
| 8792 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8793 | BO_Assign, LHSDRE, ReductionOp.get()); |
| 8794 | } else { |
| 8795 | auto *ConditionalOp = new (Context) ConditionalOperator( |
| 8796 | ReductionOp.get(), SourceLocation(), LHSDRE, SourceLocation(), |
| 8797 | RHSDRE, Type, VK_LValue, OK_Ordinary); |
| 8798 | ReductionOp = |
| 8799 | BuildBinOp(DSAStack->getCurScope(), ReductionId.getLocStart(), |
| 8800 | BO_Assign, LHSDRE, ConditionalOp); |
| 8801 | } |
| 8802 | ReductionOp = ActOnFinishFullExpr(ReductionOp.get()); |
| 8803 | } |
| 8804 | if (ReductionOp.isInvalid()) |
| 8805 | continue; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8806 | } |
| 8807 | |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8808 | DeclRefExpr *Ref = nullptr; |
| 8809 | Expr *VarsExpr = RefExpr->IgnoreParens(); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8810 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8811 | if (ASE || OASE) { |
| 8812 | TransformExprToCaptures RebuildToCapture(*this, D); |
| 8813 | VarsExpr = |
| 8814 | RebuildToCapture.TransformExpr(RefExpr->IgnoreParens()).get(); |
| 8815 | Ref = RebuildToCapture.getCapturedExpr(); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8816 | } else { |
| 8817 | VarsExpr = Ref = |
| 8818 | buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8819 | } |
| 8820 | if (!IsOpenMPCapturedDecl(D)) { |
| 8821 | ExprCaptures.push_back(Ref->getDecl()); |
| 8822 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8823 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8824 | if (!RefRes.isUsable()) |
| 8825 | continue; |
| 8826 | ExprResult PostUpdateRes = |
| 8827 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8828 | SimpleRefExpr, RefRes.get()); |
| 8829 | if (!PostUpdateRes.isUsable()) |
| 8830 | continue; |
| 8831 | ExprPostUpdates.push_back( |
| 8832 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8833 | } |
| 8834 | } |
Alexey Bataev | 60da77e | 2016-02-29 05:54:20 +0000 | [diff] [blame] | 8835 | } |
| 8836 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_reduction, Ref); |
| 8837 | Vars.push_back(VarsExpr); |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8838 | Privates.push_back(PrivateDRE); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 8839 | LHSs.push_back(LHSDRE); |
| 8840 | RHSs.push_back(RHSDRE); |
| 8841 | ReductionOps.push_back(ReductionOp.get()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8842 | } |
| 8843 | |
| 8844 | if (Vars.empty()) |
| 8845 | return nullptr; |
Alexey Bataev | 6120507 | 2016-03-02 04:57:40 +0000 | [diff] [blame] | 8846 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8847 | return OMPReductionClause::Create( |
| 8848 | Context, StartLoc, LParenLoc, ColonLoc, EndLoc, Vars, |
Alexey Bataev | f24e7b1 | 2015-10-08 09:10:53 +0000 | [diff] [blame] | 8849 | ReductionIdScopeSpec.getWithLocInContext(Context), ReductionId, Privates, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 8850 | LHSs, RHSs, ReductionOps, buildPreInits(Context, ExprCaptures), |
| 8851 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 8852 | } |
| 8853 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8854 | bool Sema::CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 8855 | SourceLocation LinLoc) { |
| 8856 | if ((!LangOpts.CPlusPlus && LinKind != OMPC_LINEAR_val) || |
| 8857 | LinKind == OMPC_LINEAR_unknown) { |
| 8858 | Diag(LinLoc, diag::err_omp_wrong_linear_modifier) << LangOpts.CPlusPlus; |
| 8859 | return true; |
| 8860 | } |
| 8861 | return false; |
| 8862 | } |
| 8863 | |
| 8864 | bool Sema::CheckOpenMPLinearDecl(ValueDecl *D, SourceLocation ELoc, |
| 8865 | OpenMPLinearClauseKind LinKind, |
| 8866 | QualType Type) { |
| 8867 | auto *VD = dyn_cast_or_null<VarDecl>(D); |
| 8868 | // A variable must not have an incomplete type or a reference type. |
| 8869 | if (RequireCompleteType(ELoc, Type, diag::err_omp_linear_incomplete_type)) |
| 8870 | return true; |
| 8871 | if ((LinKind == OMPC_LINEAR_uval || LinKind == OMPC_LINEAR_ref) && |
| 8872 | !Type->isReferenceType()) { |
| 8873 | Diag(ELoc, diag::err_omp_wrong_linear_modifier_non_reference) |
| 8874 | << Type << getOpenMPSimpleClauseTypeName(OMPC_linear, LinKind); |
| 8875 | return true; |
| 8876 | } |
| 8877 | Type = Type.getNonReferenceType(); |
| 8878 | |
| 8879 | // A list item must not be const-qualified. |
| 8880 | if (Type.isConstant(Context)) { |
| 8881 | Diag(ELoc, diag::err_omp_const_variable) |
| 8882 | << getOpenMPClauseName(OMPC_linear); |
| 8883 | if (D) { |
| 8884 | bool IsDecl = |
| 8885 | !VD || |
| 8886 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8887 | Diag(D->getLocation(), |
| 8888 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8889 | << D; |
| 8890 | } |
| 8891 | return true; |
| 8892 | } |
| 8893 | |
| 8894 | // A list item must be of integral or pointer type. |
| 8895 | Type = Type.getUnqualifiedType().getCanonicalType(); |
| 8896 | const auto *Ty = Type.getTypePtrOrNull(); |
| 8897 | if (!Ty || (!Ty->isDependentType() && !Ty->isIntegralType(Context) && |
| 8898 | !Ty->isPointerType())) { |
| 8899 | Diag(ELoc, diag::err_omp_linear_expected_int_or_ptr) << Type; |
| 8900 | if (D) { |
| 8901 | bool IsDecl = |
| 8902 | !VD || |
| 8903 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
| 8904 | Diag(D->getLocation(), |
| 8905 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
| 8906 | << D; |
| 8907 | } |
| 8908 | return true; |
| 8909 | } |
| 8910 | return false; |
| 8911 | } |
| 8912 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8913 | OMPClause *Sema::ActOnOpenMPLinearClause( |
| 8914 | ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc, |
| 8915 | SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, |
| 8916 | SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8917 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8918 | SmallVector<Expr *, 8> Privates; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8919 | SmallVector<Expr *, 8> Inits; |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8920 | SmallVector<Decl *, 4> ExprCaptures; |
| 8921 | SmallVector<Expr *, 4> ExprPostUpdates; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8922 | if (CheckOpenMPLinearModifier(LinKind, LinLoc)) |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 8923 | LinKind = OMPC_LINEAR_val; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8924 | for (auto &RefExpr : VarList) { |
| 8925 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8926 | SourceLocation ELoc; |
| 8927 | SourceRange ERange; |
| 8928 | Expr *SimpleRefExpr = RefExpr; |
| 8929 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 8930 | /*AllowArraySection=*/false); |
| 8931 | if (Res.second) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8932 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 8933 | Vars.push_back(RefExpr); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8934 | Privates.push_back(nullptr); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8935 | Inits.push_back(nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8936 | } |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8937 | ValueDecl *D = Res.first; |
| 8938 | if (!D) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8939 | continue; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8940 | |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8941 | QualType Type = D->getType(); |
| 8942 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8943 | |
| 8944 | // OpenMP [2.14.3.7, linear clause] |
| 8945 | // A list-item cannot appear in more than one linear clause. |
| 8946 | // A list-item that appears in a linear clause cannot appear in any |
| 8947 | // other data-sharing attribute clause. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8948 | DSAStackTy::DSAVarData DVar = DSAStack->getTopDSA(D, false); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8949 | if (DVar.RefExpr) { |
| 8950 | Diag(ELoc, diag::err_omp_wrong_dsa) << getOpenMPClauseName(DVar.CKind) |
| 8951 | << getOpenMPClauseName(OMPC_linear); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8952 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8953 | continue; |
| 8954 | } |
| 8955 | |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8956 | if (CheckOpenMPLinearDecl(D, ELoc, LinKind, Type)) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8957 | continue; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 8958 | Type = Type.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 8959 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8960 | // Build private copy of original var. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8961 | auto *Private = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 8962 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 8963 | auto *PrivateRef = buildDeclRefExpr(*this, Private, Type, ELoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8964 | // Build var to save initial value. |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8965 | VarDecl *Init = buildVarDecl(*this, ELoc, Type, ".linear.start"); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8966 | Expr *InitExpr; |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8967 | DeclRefExpr *Ref = nullptr; |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8968 | if (!VD && !CurContext->isDependentContext()) { |
Alexey Bataev | 78849fb | 2016-03-09 09:49:00 +0000 | [diff] [blame] | 8969 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false); |
| 8970 | if (!IsOpenMPCapturedDecl(D)) { |
| 8971 | ExprCaptures.push_back(Ref->getDecl()); |
| 8972 | if (Ref->getDecl()->hasAttr<OMPCaptureNoInitAttr>()) { |
| 8973 | ExprResult RefRes = DefaultLvalueConversion(Ref); |
| 8974 | if (!RefRes.isUsable()) |
| 8975 | continue; |
| 8976 | ExprResult PostUpdateRes = |
| 8977 | BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
| 8978 | SimpleRefExpr, RefRes.get()); |
| 8979 | if (!PostUpdateRes.isUsable()) |
| 8980 | continue; |
| 8981 | ExprPostUpdates.push_back( |
| 8982 | IgnoredValueConversions(PostUpdateRes.get()).get()); |
| 8983 | } |
| 8984 | } |
| 8985 | } |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8986 | if (LinKind == OMPC_LINEAR_uval) |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8987 | InitExpr = VD ? VD->getInit() : SimpleRefExpr; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8988 | else |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8989 | InitExpr = VD ? SimpleRefExpr : Ref; |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 8990 | AddInitializerToDecl(Init, DefaultLvalueConversion(InitExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 8991 | /*DirectInit=*/false); |
Alexey Bataev | 2bbf721 | 2016-03-03 03:52:24 +0000 | [diff] [blame] | 8992 | auto InitRef = buildDeclRefExpr(*this, Init, Type, ELoc); |
| 8993 | |
| 8994 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_linear, Ref); |
Alexey Bataev | be8b8b5 | 2016-07-07 11:04:06 +0000 | [diff] [blame] | 8995 | Vars.push_back((VD || CurContext->isDependentContext()) |
| 8996 | ? RefExpr->IgnoreParens() |
| 8997 | : Ref); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 8998 | Privates.push_back(PrivateRef); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 8999 | Inits.push_back(InitRef); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9000 | } |
| 9001 | |
| 9002 | if (Vars.empty()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9003 | return nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9004 | |
| 9005 | Expr *StepExpr = Step; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9006 | Expr *CalcStepExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9007 | if (Step && !Step->isValueDependent() && !Step->isTypeDependent() && |
| 9008 | !Step->isInstantiationDependent() && |
| 9009 | !Step->containsUnexpandedParameterPack()) { |
| 9010 | SourceLocation StepLoc = Step->getLocStart(); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 9011 | ExprResult Val = PerformOpenMPImplicitIntegerConversion(StepLoc, Step); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9012 | if (Val.isInvalid()) |
Alexander Musman | cb7f9c4 | 2014-05-15 13:04:49 +0000 | [diff] [blame] | 9013 | return nullptr; |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 9014 | StepExpr = Val.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9015 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9016 | // Build var to save the step value. |
| 9017 | VarDecl *SaveVar = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9018 | buildVarDecl(*this, StepLoc, StepExpr->getType(), ".linear.step"); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9019 | ExprResult SaveRef = |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9020 | buildDeclRefExpr(*this, SaveVar, StepExpr->getType(), StepLoc); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9021 | ExprResult CalcStep = |
| 9022 | BuildBinOp(CurScope, StepLoc, BO_Assign, SaveRef.get(), StepExpr); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9023 | CalcStep = ActOnFinishFullExpr(CalcStep.get()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9024 | |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9025 | // Warn about zero linear step (it would be probably better specified as |
| 9026 | // making corresponding variables 'const'). |
| 9027 | llvm::APSInt Result; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9028 | bool IsConstant = StepExpr->isIntegerConstantExpr(Result, Context); |
| 9029 | if (IsConstant && !Result.isNegative() && !Result.isStrictlyPositive()) |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9030 | Diag(StepLoc, diag::warn_omp_linear_step_zero) << Vars[0] |
| 9031 | << (Vars.size() > 1); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9032 | if (!IsConstant && CalcStep.isUsable()) { |
| 9033 | // Calculate the step beforehand instead of doing this on each iteration. |
| 9034 | // (This is not used if the number of iterations may be kfold-ed). |
| 9035 | CalcStepExpr = CalcStep.get(); |
| 9036 | } |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9037 | } |
| 9038 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 9039 | return OMPLinearClause::Create(Context, StartLoc, LParenLoc, LinKind, LinLoc, |
| 9040 | ColonLoc, EndLoc, Vars, Privates, Inits, |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9041 | StepExpr, CalcStepExpr, |
| 9042 | buildPreInits(Context, ExprCaptures), |
| 9043 | buildPostUpdate(*this, ExprPostUpdates)); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9044 | } |
| 9045 | |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9046 | static bool FinishOpenMPLinearClause(OMPLinearClause &Clause, DeclRefExpr *IV, |
| 9047 | Expr *NumIterations, Sema &SemaRef, |
| 9048 | Scope *S, DSAStackTy *Stack) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9049 | // Walk the vars and build update/final expressions for the CodeGen. |
| 9050 | SmallVector<Expr *, 8> Updates; |
| 9051 | SmallVector<Expr *, 8> Finals; |
| 9052 | Expr *Step = Clause.getStep(); |
| 9053 | Expr *CalcStep = Clause.getCalcStep(); |
| 9054 | // OpenMP [2.14.3.7, linear clause] |
| 9055 | // If linear-step is not specified it is assumed to be 1. |
| 9056 | if (Step == nullptr) |
| 9057 | Step = SemaRef.ActOnIntegerConstant(SourceLocation(), 1).get(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9058 | else if (CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9059 | Step = cast<BinaryOperator>(CalcStep)->getLHS(); |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 9060 | } |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9061 | bool HasErrors = false; |
| 9062 | auto CurInit = Clause.inits().begin(); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9063 | auto CurPrivate = Clause.privates().begin(); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9064 | auto LinKind = Clause.getModifier(); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9065 | for (auto &RefExpr : Clause.varlists()) { |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9066 | SourceLocation ELoc; |
| 9067 | SourceRange ERange; |
| 9068 | Expr *SimpleRefExpr = RefExpr; |
| 9069 | auto Res = getPrivateItem(SemaRef, SimpleRefExpr, ELoc, ERange, |
| 9070 | /*AllowArraySection=*/false); |
| 9071 | ValueDecl *D = Res.first; |
| 9072 | if (Res.second || !D) { |
| 9073 | Updates.push_back(nullptr); |
| 9074 | Finals.push_back(nullptr); |
| 9075 | HasErrors = true; |
| 9076 | continue; |
| 9077 | } |
| 9078 | if (auto *CED = dyn_cast<OMPCapturedExprDecl>(D)) { |
| 9079 | D = cast<MemberExpr>(CED->getInit()->IgnoreParenImpCasts()) |
| 9080 | ->getMemberDecl(); |
| 9081 | } |
| 9082 | auto &&Info = Stack->isLoopControlVariable(D); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9083 | Expr *InitExpr = *CurInit; |
| 9084 | |
| 9085 | // Build privatized reference to the current linear var. |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9086 | auto *DE = cast<DeclRefExpr>(SimpleRefExpr); |
Alexey Bataev | 84cfb1d | 2015-08-21 06:41:23 +0000 | [diff] [blame] | 9087 | Expr *CapturedRef; |
| 9088 | if (LinKind == OMPC_LINEAR_uval) |
| 9089 | CapturedRef = cast<VarDecl>(DE->getDecl())->getInit(); |
| 9090 | else |
| 9091 | CapturedRef = |
| 9092 | buildDeclRefExpr(SemaRef, cast<VarDecl>(DE->getDecl()), |
| 9093 | DE->getType().getUnqualifiedType(), DE->getExprLoc(), |
| 9094 | /*RefersToCapture=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9095 | |
| 9096 | // Build update: Var = InitExpr + IV * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9097 | ExprResult Update; |
| 9098 | if (!Info.first) { |
| 9099 | Update = |
| 9100 | BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), *CurPrivate, |
| 9101 | InitExpr, IV, Step, /* Subtract */ false); |
| 9102 | } else |
| 9103 | Update = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9104 | Update = SemaRef.ActOnFinishFullExpr(Update.get(), DE->getLocStart(), |
| 9105 | /*DiscardedValue=*/true); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9106 | |
| 9107 | // Build final: Var = InitExpr + NumIterations * Step |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9108 | ExprResult Final; |
| 9109 | if (!Info.first) { |
| 9110 | Final = BuildCounterUpdate(SemaRef, S, RefExpr->getExprLoc(), CapturedRef, |
| 9111 | InitExpr, NumIterations, Step, |
| 9112 | /* Subtract */ false); |
| 9113 | } else |
| 9114 | Final = *CurPrivate; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 9115 | Final = SemaRef.ActOnFinishFullExpr(Final.get(), DE->getLocStart(), |
| 9116 | /*DiscardedValue=*/true); |
Alexey Bataev | 5dff95c | 2016-04-22 03:56:56 +0000 | [diff] [blame] | 9117 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9118 | if (!Update.isUsable() || !Final.isUsable()) { |
| 9119 | Updates.push_back(nullptr); |
| 9120 | Finals.push_back(nullptr); |
| 9121 | HasErrors = true; |
| 9122 | } else { |
| 9123 | Updates.push_back(Update.get()); |
| 9124 | Finals.push_back(Final.get()); |
| 9125 | } |
Richard Trieu | cc3949d | 2016-02-18 22:34:54 +0000 | [diff] [blame] | 9126 | ++CurInit; |
| 9127 | ++CurPrivate; |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 9128 | } |
| 9129 | Clause.setUpdates(Updates); |
| 9130 | Clause.setFinals(Finals); |
| 9131 | return HasErrors; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 9132 | } |
| 9133 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9134 | OMPClause *Sema::ActOnOpenMPAlignedClause( |
| 9135 | ArrayRef<Expr *> VarList, Expr *Alignment, SourceLocation StartLoc, |
| 9136 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc) { |
| 9137 | |
| 9138 | SmallVector<Expr *, 8> Vars; |
| 9139 | for (auto &RefExpr : VarList) { |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9140 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9141 | SourceLocation ELoc; |
| 9142 | SourceRange ERange; |
| 9143 | Expr *SimpleRefExpr = RefExpr; |
| 9144 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9145 | /*AllowArraySection=*/false); |
| 9146 | if (Res.second) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9147 | // It will be analyzed later. |
| 9148 | Vars.push_back(RefExpr); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9149 | } |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9150 | ValueDecl *D = Res.first; |
| 9151 | if (!D) |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9152 | continue; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9153 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9154 | QualType QType = D->getType(); |
| 9155 | auto *VD = dyn_cast<VarDecl>(D); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9156 | |
| 9157 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9158 | // The type of list items appearing in the aligned clause must be |
| 9159 | // array, pointer, reference to array, or reference to pointer. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9160 | QType = QType.getNonReferenceType().getUnqualifiedType().getCanonicalType(); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9161 | const Type *Ty = QType.getTypePtrOrNull(); |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9162 | if (!Ty || (!Ty->isArrayType() && !Ty->isPointerType())) { |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9163 | Diag(ELoc, diag::err_omp_aligned_expected_array_or_ptr) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9164 | << QType << getLangOpts().CPlusPlus << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9165 | bool IsDecl = |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9166 | !VD || |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9167 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9168 | Diag(D->getLocation(), |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9169 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9170 | << D; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9171 | continue; |
| 9172 | } |
| 9173 | |
| 9174 | // OpenMP [2.8.1, simd construct, Restrictions] |
| 9175 | // A list-item cannot appear in more than one aligned clause. |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9176 | if (Expr *PrevRef = DSAStack->addUniqueAligned(D, SimpleRefExpr)) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 9177 | Diag(ELoc, diag::err_omp_aligned_twice) << 0 << ERange; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9178 | Diag(PrevRef->getExprLoc(), diag::note_omp_explicit_dsa) |
| 9179 | << getOpenMPClauseName(OMPC_aligned); |
| 9180 | continue; |
| 9181 | } |
| 9182 | |
Alexey Bataev | 1efd166 | 2016-03-29 10:59:56 +0000 | [diff] [blame] | 9183 | DeclRefExpr *Ref = nullptr; |
| 9184 | if (!VD && IsOpenMPCapturedDecl(D)) |
| 9185 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 9186 | Vars.push_back(DefaultFunctionArrayConversion( |
| 9187 | (VD || !Ref) ? RefExpr->IgnoreParens() : Ref) |
| 9188 | .get()); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 9189 | } |
| 9190 | |
| 9191 | // OpenMP [2.8.1, simd construct, Description] |
| 9192 | // The parameter of the aligned clause, alignment, must be a constant |
| 9193 | // positive integer expression. |
| 9194 | // If no optional parameter is specified, implementation-defined default |
| 9195 | // alignments for SIMD instructions on the target platforms are assumed. |
| 9196 | if (Alignment != nullptr) { |
| 9197 | ExprResult AlignResult = |
| 9198 | VerifyPositiveIntegerConstantInClause(Alignment, OMPC_aligned); |
| 9199 | if (AlignResult.isInvalid()) |
| 9200 | return nullptr; |
| 9201 | Alignment = AlignResult.get(); |
| 9202 | } |
| 9203 | if (Vars.empty()) |
| 9204 | return nullptr; |
| 9205 | |
| 9206 | return OMPAlignedClause::Create(Context, StartLoc, LParenLoc, ColonLoc, |
| 9207 | EndLoc, Vars, Alignment); |
| 9208 | } |
| 9209 | |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9210 | OMPClause *Sema::ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 9211 | SourceLocation StartLoc, |
| 9212 | SourceLocation LParenLoc, |
| 9213 | SourceLocation EndLoc) { |
| 9214 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9215 | SmallVector<Expr *, 8> SrcExprs; |
| 9216 | SmallVector<Expr *, 8> DstExprs; |
| 9217 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9218 | for (auto &RefExpr : VarList) { |
| 9219 | assert(RefExpr && "NULL expr in OpenMP copyin clause."); |
| 9220 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9221 | // It will be analyzed later. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9222 | Vars.push_back(RefExpr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9223 | SrcExprs.push_back(nullptr); |
| 9224 | DstExprs.push_back(nullptr); |
| 9225 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9226 | continue; |
| 9227 | } |
| 9228 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9229 | SourceLocation ELoc = RefExpr->getExprLoc(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9230 | // OpenMP [2.1, C/C++] |
| 9231 | // A list item is a variable name. |
| 9232 | // OpenMP [2.14.4.1, Restrictions, p.1] |
| 9233 | // A list item that appears in a copyin clause must be threadprivate. |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9234 | DeclRefExpr *DE = dyn_cast<DeclRefExpr>(RefExpr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9235 | if (!DE || !isa<VarDecl>(DE->getDecl())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9236 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr) |
| 9237 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9238 | continue; |
| 9239 | } |
| 9240 | |
| 9241 | Decl *D = DE->getDecl(); |
| 9242 | VarDecl *VD = cast<VarDecl>(D); |
| 9243 | |
| 9244 | QualType Type = VD->getType(); |
| 9245 | if (Type->isDependentType() || Type->isInstantiationDependentType()) { |
| 9246 | // It will be analyzed later. |
| 9247 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9248 | SrcExprs.push_back(nullptr); |
| 9249 | DstExprs.push_back(nullptr); |
| 9250 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9251 | continue; |
| 9252 | } |
| 9253 | |
| 9254 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.1] |
| 9255 | // A list item that appears in a copyin clause must be threadprivate. |
| 9256 | if (!DSAStack->isThreadPrivate(VD)) { |
| 9257 | Diag(ELoc, diag::err_omp_required_access) |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9258 | << getOpenMPClauseName(OMPC_copyin) |
| 9259 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9260 | continue; |
| 9261 | } |
| 9262 | |
| 9263 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9264 | // A variable of class type (or array thereof) that appears in a |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 9265 | // copyin clause requires an accessible, unambiguous copy assignment |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9266 | // operator for the class type. |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9267 | auto ElemType = Context.getBaseElementType(Type).getNonReferenceType(); |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9268 | auto *SrcVD = |
| 9269 | buildVarDecl(*this, DE->getLocStart(), ElemType.getUnqualifiedType(), |
| 9270 | ".copyin.src", VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | 39f915b8 | 2015-05-08 10:41:21 +0000 | [diff] [blame] | 9271 | auto *PseudoSrcExpr = buildDeclRefExpr( |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9272 | *this, SrcVD, ElemType.getUnqualifiedType(), DE->getExprLoc()); |
| 9273 | auto *DstVD = |
Alexey Bataev | 1d7f0fa | 2015-09-10 09:48:30 +0000 | [diff] [blame] | 9274 | buildVarDecl(*this, DE->getLocStart(), ElemType, ".copyin.dst", |
| 9275 | VD->hasAttrs() ? &VD->getAttrs() : nullptr); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9276 | auto *PseudoDstExpr = |
Alexey Bataev | f120c0d | 2015-05-19 07:46:42 +0000 | [diff] [blame] | 9277 | buildDeclRefExpr(*this, DstVD, ElemType, DE->getExprLoc()); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9278 | // For arrays generate assignment operation for single element and replace |
| 9279 | // it by the original array element in CodeGen. |
| 9280 | auto AssignmentOp = BuildBinOp(/*S=*/nullptr, DE->getExprLoc(), BO_Assign, |
| 9281 | PseudoDstExpr, PseudoSrcExpr); |
| 9282 | if (AssignmentOp.isInvalid()) |
| 9283 | continue; |
| 9284 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), DE->getExprLoc(), |
| 9285 | /*DiscardedValue=*/true); |
| 9286 | if (AssignmentOp.isInvalid()) |
| 9287 | continue; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9288 | |
| 9289 | DSAStack->addDSA(VD, DE, OMPC_copyin); |
| 9290 | Vars.push_back(DE); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9291 | SrcExprs.push_back(PseudoSrcExpr); |
| 9292 | DstExprs.push_back(PseudoDstExpr); |
| 9293 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9294 | } |
| 9295 | |
Alexey Bataev | ed09d24 | 2014-05-28 05:53:51 +0000 | [diff] [blame] | 9296 | if (Vars.empty()) |
| 9297 | return nullptr; |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9298 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 9299 | return OMPCopyinClause::Create(Context, StartLoc, LParenLoc, EndLoc, Vars, |
| 9300 | SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 9301 | } |
| 9302 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9303 | OMPClause *Sema::ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 9304 | SourceLocation StartLoc, |
| 9305 | SourceLocation LParenLoc, |
| 9306 | SourceLocation EndLoc) { |
| 9307 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9308 | SmallVector<Expr *, 8> SrcExprs; |
| 9309 | SmallVector<Expr *, 8> DstExprs; |
| 9310 | SmallVector<Expr *, 8> AssignmentOps; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9311 | for (auto &RefExpr : VarList) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9312 | assert(RefExpr && "NULL expr in OpenMP linear clause."); |
| 9313 | SourceLocation ELoc; |
| 9314 | SourceRange ERange; |
| 9315 | Expr *SimpleRefExpr = RefExpr; |
| 9316 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange, |
| 9317 | /*AllowArraySection=*/false); |
| 9318 | if (Res.second) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9319 | // It will be analyzed later. |
| 9320 | Vars.push_back(RefExpr); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9321 | SrcExprs.push_back(nullptr); |
| 9322 | DstExprs.push_back(nullptr); |
| 9323 | AssignmentOps.push_back(nullptr); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9324 | } |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9325 | ValueDecl *D = Res.first; |
| 9326 | if (!D) |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9327 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9328 | |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9329 | QualType Type = D->getType(); |
| 9330 | auto *VD = dyn_cast<VarDecl>(D); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9331 | |
| 9332 | // OpenMP [2.14.4.2, Restrictions, p.2] |
| 9333 | // A list item that appears in a copyprivate clause may not appear in a |
| 9334 | // private or firstprivate clause on the single construct. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9335 | if (!VD || !DSAStack->isThreadPrivate(VD)) { |
| 9336 | auto DVar = DSAStack->getTopDSA(D, false); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9337 | if (DVar.CKind != OMPC_unknown && DVar.CKind != OMPC_copyprivate && |
| 9338 | DVar.RefExpr) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9339 | Diag(ELoc, diag::err_omp_wrong_dsa) |
| 9340 | << getOpenMPClauseName(DVar.CKind) |
| 9341 | << getOpenMPClauseName(OMPC_copyprivate); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9342 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9343 | continue; |
| 9344 | } |
| 9345 | |
| 9346 | // OpenMP [2.11.4.2, Restrictions, p.1] |
| 9347 | // All list items that appear in a copyprivate clause must be either |
| 9348 | // threadprivate or private in the enclosing context. |
| 9349 | if (DVar.CKind == OMPC_unknown) { |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9350 | DVar = DSAStack->getImplicitDSA(D, false); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9351 | if (DVar.CKind == OMPC_shared) { |
| 9352 | Diag(ELoc, diag::err_omp_required_access) |
| 9353 | << getOpenMPClauseName(OMPC_copyprivate) |
| 9354 | << "threadprivate or private in the enclosing context"; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9355 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9356 | continue; |
| 9357 | } |
| 9358 | } |
| 9359 | } |
| 9360 | |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9361 | // Variably modified types are not supported. |
Alexey Bataev | 5129d3a | 2015-05-21 09:47:46 +0000 | [diff] [blame] | 9362 | if (!Type->isAnyPointerType() && Type->isVariablyModifiedType()) { |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9363 | Diag(ELoc, diag::err_omp_variably_modified_type_not_supported) |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9364 | << getOpenMPClauseName(OMPC_copyprivate) << Type |
| 9365 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9366 | bool IsDecl = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9367 | !VD || |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9368 | VD->isThisDeclarationADefinition(Context) == VarDecl::DeclarationOnly; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9369 | Diag(D->getLocation(), |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9370 | IsDecl ? diag::note_previous_decl : diag::note_defined_here) |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9371 | << D; |
Alexey Bataev | 7a3e585 | 2015-05-19 08:19:24 +0000 | [diff] [blame] | 9372 | continue; |
| 9373 | } |
Alexey Bataev | ccb59ec | 2015-05-19 08:44:56 +0000 | [diff] [blame] | 9374 | |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9375 | // OpenMP [2.14.4.1, Restrictions, C/C++, p.2] |
| 9376 | // A variable of class type (or array thereof) that appears in a |
| 9377 | // copyin clause requires an accessible, unambiguous copy assignment |
| 9378 | // operator for the class type. |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 9379 | Type = Context.getBaseElementType(Type.getNonReferenceType()) |
| 9380 | .getUnqualifiedType(); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9381 | auto *SrcVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9382 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.src", |
| 9383 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 9384 | auto *PseudoSrcExpr = buildDeclRefExpr(*this, SrcVD, Type, ELoc); |
Alexey Bataev | 420d45b | 2015-04-14 05:11:24 +0000 | [diff] [blame] | 9385 | auto *DstVD = |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9386 | buildVarDecl(*this, RefExpr->getLocStart(), Type, ".copyprivate.dst", |
| 9387 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9388 | auto *PseudoDstExpr = buildDeclRefExpr(*this, DstVD, Type, ELoc); |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9389 | auto AssignmentOp = BuildBinOp(DSAStack->getCurScope(), ELoc, BO_Assign, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9390 | PseudoDstExpr, PseudoSrcExpr); |
| 9391 | if (AssignmentOp.isInvalid()) |
| 9392 | continue; |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9393 | AssignmentOp = ActOnFinishFullExpr(AssignmentOp.get(), ELoc, |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9394 | /*DiscardedValue=*/true); |
| 9395 | if (AssignmentOp.isInvalid()) |
| 9396 | continue; |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9397 | |
| 9398 | // No need to mark vars as copyprivate, they are already threadprivate or |
| 9399 | // implicitly private. |
Alexey Bataev | e122da1 | 2016-03-17 10:50:17 +0000 | [diff] [blame] | 9400 | assert(VD || IsOpenMPCapturedDecl(D)); |
| 9401 | Vars.push_back( |
| 9402 | VD ? RefExpr->IgnoreParens() |
| 9403 | : buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false)); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9404 | SrcExprs.push_back(PseudoSrcExpr); |
| 9405 | DstExprs.push_back(PseudoDstExpr); |
| 9406 | AssignmentOps.push_back(AssignmentOp.get()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9407 | } |
| 9408 | |
| 9409 | if (Vars.empty()) |
| 9410 | return nullptr; |
| 9411 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 9412 | return OMPCopyprivateClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9413 | Vars, SrcExprs, DstExprs, AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 9414 | } |
| 9415 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 9416 | OMPClause *Sema::ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 9417 | SourceLocation StartLoc, |
| 9418 | SourceLocation LParenLoc, |
| 9419 | SourceLocation EndLoc) { |
| 9420 | if (VarList.empty()) |
| 9421 | return nullptr; |
| 9422 | |
| 9423 | return OMPFlushClause::Create(Context, StartLoc, LParenLoc, EndLoc, VarList); |
| 9424 | } |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 9425 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9426 | OMPClause * |
| 9427 | Sema::ActOnOpenMPDependClause(OpenMPDependClauseKind DepKind, |
| 9428 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 9429 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 9430 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9431 | if (DSAStack->getCurrentDirective() == OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9432 | DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9433 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9434 | << "'source' or 'sink'" << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 9435 | return nullptr; |
| 9436 | } |
| 9437 | if (DSAStack->getCurrentDirective() != OMPD_ordered && |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9438 | (DepKind == OMPC_DEPEND_unknown || DepKind == OMPC_DEPEND_source || |
| 9439 | DepKind == OMPC_DEPEND_sink)) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9440 | unsigned Except[] = {OMPC_DEPEND_source, OMPC_DEPEND_sink}; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9441 | Diag(DepLoc, diag::err_omp_unexpected_clause_value) |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 9442 | << getListOfPossibleValues(OMPC_depend, /*First=*/0, |
| 9443 | /*Last=*/OMPC_DEPEND_unknown, Except) |
| 9444 | << getOpenMPClauseName(OMPC_depend); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9445 | return nullptr; |
| 9446 | } |
| 9447 | SmallVector<Expr *, 8> Vars; |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9448 | DSAStackTy::OperatorOffsetTy OpsOffs; |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9449 | llvm::APSInt DepCounter(/*BitWidth=*/32); |
| 9450 | llvm::APSInt TotalDepCount(/*BitWidth=*/32); |
| 9451 | if (DepKind == OMPC_DEPEND_sink) { |
| 9452 | if (auto *OrderedCountExpr = DSAStack->getParentOrderedRegionParam()) { |
| 9453 | TotalDepCount = OrderedCountExpr->EvaluateKnownConstInt(Context); |
| 9454 | TotalDepCount.setIsUnsigned(/*Val=*/true); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9455 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9456 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9457 | if ((DepKind != OMPC_DEPEND_sink && DepKind != OMPC_DEPEND_source) || |
| 9458 | DSAStack->getParentOrderedRegionParam()) { |
| 9459 | for (auto &RefExpr : VarList) { |
| 9460 | assert(RefExpr && "NULL expr in OpenMP shared clause."); |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9461 | if (isa<DependentScopeDeclRefExpr>(RefExpr)) { |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9462 | // It will be analyzed later. |
| 9463 | Vars.push_back(RefExpr); |
| 9464 | continue; |
| 9465 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9466 | |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9467 | SourceLocation ELoc = RefExpr->getExprLoc(); |
| 9468 | auto *SimpleExpr = RefExpr->IgnoreParenCasts(); |
| 9469 | if (DepKind == OMPC_DEPEND_sink) { |
| 9470 | if (DepCounter >= TotalDepCount) { |
| 9471 | Diag(ELoc, diag::err_omp_depend_sink_unexpected_expr); |
| 9472 | continue; |
| 9473 | } |
| 9474 | ++DepCounter; |
| 9475 | // OpenMP [2.13.9, Summary] |
| 9476 | // depend(dependence-type : vec), where dependence-type is: |
| 9477 | // 'sink' and where vec is the iteration vector, which has the form: |
| 9478 | // x1 [+- d1], x2 [+- d2 ], . . . , xn [+- dn] |
| 9479 | // where n is the value specified by the ordered clause in the loop |
| 9480 | // directive, xi denotes the loop iteration variable of the i-th nested |
| 9481 | // loop associated with the loop directive, and di is a constant |
| 9482 | // non-negative integer. |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9483 | if (CurContext->isDependentContext()) { |
| 9484 | // It will be analyzed later. |
| 9485 | Vars.push_back(RefExpr); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9486 | continue; |
| 9487 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9488 | SimpleExpr = SimpleExpr->IgnoreImplicit(); |
| 9489 | OverloadedOperatorKind OOK = OO_None; |
| 9490 | SourceLocation OOLoc; |
| 9491 | Expr *LHS = SimpleExpr; |
| 9492 | Expr *RHS = nullptr; |
| 9493 | if (auto *BO = dyn_cast<BinaryOperator>(SimpleExpr)) { |
| 9494 | OOK = BinaryOperator::getOverloadedOperator(BO->getOpcode()); |
| 9495 | OOLoc = BO->getOperatorLoc(); |
| 9496 | LHS = BO->getLHS()->IgnoreParenImpCasts(); |
| 9497 | RHS = BO->getRHS()->IgnoreParenImpCasts(); |
| 9498 | } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(SimpleExpr)) { |
| 9499 | OOK = OCE->getOperator(); |
| 9500 | OOLoc = OCE->getOperatorLoc(); |
| 9501 | LHS = OCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9502 | RHS = OCE->getArg(/*Arg=*/1)->IgnoreParenImpCasts(); |
| 9503 | } else if (auto *MCE = dyn_cast<CXXMemberCallExpr>(SimpleExpr)) { |
| 9504 | OOK = MCE->getMethodDecl() |
| 9505 | ->getNameInfo() |
| 9506 | .getName() |
| 9507 | .getCXXOverloadedOperator(); |
| 9508 | OOLoc = MCE->getCallee()->getExprLoc(); |
| 9509 | LHS = MCE->getImplicitObjectArgument()->IgnoreParenImpCasts(); |
| 9510 | RHS = MCE->getArg(/*Arg=*/0)->IgnoreParenImpCasts(); |
| 9511 | } |
| 9512 | SourceLocation ELoc; |
| 9513 | SourceRange ERange; |
| 9514 | auto Res = getPrivateItem(*this, LHS, ELoc, ERange, |
| 9515 | /*AllowArraySection=*/false); |
| 9516 | if (Res.second) { |
| 9517 | // It will be analyzed later. |
| 9518 | Vars.push_back(RefExpr); |
| 9519 | } |
| 9520 | ValueDecl *D = Res.first; |
| 9521 | if (!D) |
| 9522 | continue; |
| 9523 | |
| 9524 | if (OOK != OO_Plus && OOK != OO_Minus && (RHS || OOK != OO_None)) { |
| 9525 | Diag(OOLoc, diag::err_omp_depend_sink_expected_plus_minus); |
| 9526 | continue; |
| 9527 | } |
| 9528 | if (RHS) { |
| 9529 | ExprResult RHSRes = VerifyPositiveIntegerConstantInClause( |
| 9530 | RHS, OMPC_depend, /*StrictlyPositive=*/false); |
| 9531 | if (RHSRes.isInvalid()) |
| 9532 | continue; |
| 9533 | } |
| 9534 | if (!CurContext->isDependentContext() && |
| 9535 | DSAStack->getParentOrderedRegionParam() && |
| 9536 | DepCounter != DSAStack->isParentLoopControlVariable(D).first) { |
| 9537 | Diag(ELoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9538 | << DSAStack->getParentLoopControlVariable( |
| 9539 | DepCounter.getZExtValue()); |
| 9540 | continue; |
| 9541 | } |
| 9542 | OpsOffs.push_back({RHS, OOK}); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9543 | } else { |
| 9544 | // OpenMP [2.11.1.1, Restrictions, p.3] |
| 9545 | // A variable that is part of another variable (such as a field of a |
| 9546 | // structure) but is not an array element or an array section cannot |
| 9547 | // appear in a depend clause. |
| 9548 | auto *DE = dyn_cast<DeclRefExpr>(SimpleExpr); |
| 9549 | auto *ASE = dyn_cast<ArraySubscriptExpr>(SimpleExpr); |
| 9550 | auto *OASE = dyn_cast<OMPArraySectionExpr>(SimpleExpr); |
| 9551 | if (!RefExpr->IgnoreParenImpCasts()->isLValue() || |
| 9552 | (!ASE && !DE && !OASE) || (DE && !isa<VarDecl>(DE->getDecl())) || |
Alexey Bataev | 31300ed | 2016-02-04 11:27:03 +0000 | [diff] [blame] | 9553 | (ASE && |
| 9554 | !ASE->getBase() |
| 9555 | ->getType() |
| 9556 | .getNonReferenceType() |
| 9557 | ->isPointerType() && |
| 9558 | !ASE->getBase()->getType().getNonReferenceType()->isArrayType())) { |
Alexey Bataev | 48c0bfb | 2016-01-20 09:07:54 +0000 | [diff] [blame] | 9559 | Diag(ELoc, diag::err_omp_expected_var_name_member_expr_or_array_item) |
| 9560 | << 0 << RefExpr->getSourceRange(); |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9561 | continue; |
| 9562 | } |
| 9563 | } |
Alexey Bataev | a636c7f | 2015-12-23 10:27:45 +0000 | [diff] [blame] | 9564 | Vars.push_back(RefExpr->IgnoreParenImpCasts()); |
| 9565 | } |
| 9566 | |
| 9567 | if (!CurContext->isDependentContext() && DepKind == OMPC_DEPEND_sink && |
| 9568 | TotalDepCount > VarList.size() && |
| 9569 | DSAStack->getParentOrderedRegionParam()) { |
| 9570 | Diag(EndLoc, diag::err_omp_depend_sink_expected_loop_iteration) |
| 9571 | << DSAStack->getParentLoopControlVariable(VarList.size() + 1); |
| 9572 | } |
| 9573 | if (DepKind != OMPC_DEPEND_source && DepKind != OMPC_DEPEND_sink && |
| 9574 | Vars.empty()) |
| 9575 | return nullptr; |
| 9576 | } |
Alexey Bataev | 8b42706 | 2016-05-25 12:36:08 +0000 | [diff] [blame] | 9577 | auto *C = OMPDependClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 9578 | DepKind, DepLoc, ColonLoc, Vars); |
| 9579 | if (DepKind == OMPC_DEPEND_sink || DepKind == OMPC_DEPEND_source) |
| 9580 | DSAStack->addDoacrossDependClause(C, OpsOffs); |
| 9581 | return C; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 9582 | } |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9583 | |
| 9584 | OMPClause *Sema::ActOnOpenMPDeviceClause(Expr *Device, SourceLocation StartLoc, |
| 9585 | SourceLocation LParenLoc, |
| 9586 | SourceLocation EndLoc) { |
| 9587 | Expr *ValExpr = Device; |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9588 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9589 | // OpenMP [2.9.1, Restrictions] |
| 9590 | // The device expression must evaluate to a non-negative integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 9591 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_device, |
| 9592 | /*StrictlyPositive=*/false)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 9593 | return nullptr; |
| 9594 | |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 9595 | return new (Context) OMPDeviceClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 9596 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9597 | |
| 9598 | static bool IsCXXRecordForMappable(Sema &SemaRef, SourceLocation Loc, |
| 9599 | DSAStackTy *Stack, CXXRecordDecl *RD) { |
| 9600 | if (!RD || RD->isInvalidDecl()) |
| 9601 | return true; |
| 9602 | |
| 9603 | auto QTy = SemaRef.Context.getRecordType(RD); |
| 9604 | if (RD->isDynamicClass()) { |
| 9605 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9606 | SemaRef.Diag(RD->getLocation(), diag::note_omp_polymorphic_in_target); |
| 9607 | return false; |
| 9608 | } |
| 9609 | auto *DC = RD; |
| 9610 | bool IsCorrect = true; |
| 9611 | for (auto *I : DC->decls()) { |
| 9612 | if (I) { |
| 9613 | if (auto *MD = dyn_cast<CXXMethodDecl>(I)) { |
| 9614 | if (MD->isStatic()) { |
| 9615 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9616 | SemaRef.Diag(MD->getLocation(), |
| 9617 | diag::note_omp_static_member_in_target); |
| 9618 | IsCorrect = false; |
| 9619 | } |
| 9620 | } else if (auto *VD = dyn_cast<VarDecl>(I)) { |
| 9621 | if (VD->isStaticDataMember()) { |
| 9622 | SemaRef.Diag(Loc, diag::err_omp_not_mappable_type) << QTy; |
| 9623 | SemaRef.Diag(VD->getLocation(), |
| 9624 | diag::note_omp_static_member_in_target); |
| 9625 | IsCorrect = false; |
| 9626 | } |
| 9627 | } |
| 9628 | } |
| 9629 | } |
| 9630 | |
| 9631 | for (auto &I : RD->bases()) { |
| 9632 | if (!IsCXXRecordForMappable(SemaRef, I.getLocStart(), Stack, |
| 9633 | I.getType()->getAsCXXRecordDecl())) |
| 9634 | IsCorrect = false; |
| 9635 | } |
| 9636 | return IsCorrect; |
| 9637 | } |
| 9638 | |
| 9639 | static bool CheckTypeMappable(SourceLocation SL, SourceRange SR, Sema &SemaRef, |
| 9640 | DSAStackTy *Stack, QualType QTy) { |
| 9641 | NamedDecl *ND; |
| 9642 | if (QTy->isIncompleteType(&ND)) { |
| 9643 | SemaRef.Diag(SL, diag::err_incomplete_type) << QTy << SR; |
| 9644 | return false; |
| 9645 | } else if (CXXRecordDecl *RD = dyn_cast_or_null<CXXRecordDecl>(ND)) { |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9646 | if (!RD->isInvalidDecl() && !IsCXXRecordForMappable(SemaRef, SL, Stack, RD)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 9647 | return false; |
| 9648 | } |
| 9649 | return true; |
| 9650 | } |
| 9651 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9652 | /// \brief Return true if it can be proven that the provided array expression |
| 9653 | /// (array section or array subscript) does NOT specify the whole size of the |
| 9654 | /// array whose base type is \a BaseQTy. |
| 9655 | static bool CheckArrayExpressionDoesNotReferToWholeSize(Sema &SemaRef, |
| 9656 | const Expr *E, |
| 9657 | QualType BaseQTy) { |
| 9658 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9659 | |
| 9660 | // If this is an array subscript, it refers to the whole size if the size of |
| 9661 | // the dimension is constant and equals 1. Also, an array section assumes the |
| 9662 | // format of an array subscript if no colon is used. |
| 9663 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) { |
| 9664 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9665 | return ATy->getSize().getSExtValue() != 1; |
| 9666 | // Size can't be evaluated statically. |
| 9667 | return false; |
| 9668 | } |
| 9669 | |
| 9670 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9671 | auto *LowerBound = OASE->getLowerBound(); |
| 9672 | auto *Length = OASE->getLength(); |
| 9673 | |
| 9674 | // 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] | 9675 | // covering the whole dimension. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9676 | if (LowerBound) { |
| 9677 | llvm::APSInt ConstLowerBound; |
| 9678 | if (!LowerBound->EvaluateAsInt(ConstLowerBound, SemaRef.getASTContext())) |
| 9679 | return false; // Can't get the integer value as a constant. |
| 9680 | if (ConstLowerBound.getSExtValue()) |
| 9681 | return true; |
| 9682 | } |
| 9683 | |
| 9684 | // If we don't have a length we covering the whole dimension. |
| 9685 | if (!Length) |
| 9686 | return false; |
| 9687 | |
| 9688 | // If the base is a pointer, we don't have a way to get the size of the |
| 9689 | // pointee. |
| 9690 | if (BaseQTy->isPointerType()) |
| 9691 | return false; |
| 9692 | |
| 9693 | // We can only check if the length is the same as the size of the dimension |
| 9694 | // if we have a constant array. |
| 9695 | auto *CATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr()); |
| 9696 | if (!CATy) |
| 9697 | return false; |
| 9698 | |
| 9699 | llvm::APSInt ConstLength; |
| 9700 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9701 | return false; // Can't get the integer value as a constant. |
| 9702 | |
| 9703 | return CATy->getSize().getSExtValue() != ConstLength.getSExtValue(); |
| 9704 | } |
| 9705 | |
| 9706 | // Return true if it can be proven that the provided array expression (array |
| 9707 | // section or array subscript) does NOT specify a single element of the array |
| 9708 | // whose base type is \a BaseQTy. |
| 9709 | static bool CheckArrayExpressionDoesNotReferToUnitySize(Sema &SemaRef, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 9710 | const Expr *E, |
| 9711 | QualType BaseQTy) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9712 | auto *OASE = dyn_cast<OMPArraySectionExpr>(E); |
| 9713 | |
| 9714 | // An array subscript always refer to a single element. Also, an array section |
| 9715 | // assumes the format of an array subscript if no colon is used. |
| 9716 | if (isa<ArraySubscriptExpr>(E) || (OASE && OASE->getColonLoc().isInvalid())) |
| 9717 | return false; |
| 9718 | |
| 9719 | assert(OASE && "Expecting array section if not an array subscript."); |
| 9720 | auto *Length = OASE->getLength(); |
| 9721 | |
| 9722 | // If we don't have a length we have to check if the array has unitary size |
| 9723 | // for this dimension. Also, we should always expect a length if the base type |
| 9724 | // is pointer. |
| 9725 | if (!Length) { |
| 9726 | if (auto *ATy = dyn_cast<ConstantArrayType>(BaseQTy.getTypePtr())) |
| 9727 | return ATy->getSize().getSExtValue() != 1; |
| 9728 | // We cannot assume anything. |
| 9729 | return false; |
| 9730 | } |
| 9731 | |
| 9732 | // Check if the length evaluates to 1. |
| 9733 | llvm::APSInt ConstLength; |
| 9734 | if (!Length->EvaluateAsInt(ConstLength, SemaRef.getASTContext())) |
| 9735 | return false; // Can't get the integer value as a constant. |
| 9736 | |
| 9737 | return ConstLength.getSExtValue() != 1; |
| 9738 | } |
| 9739 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9740 | // Return the expression of the base of the mappable expression or null if it |
| 9741 | // cannot be determined and do all the necessary checks to see if the expression |
| 9742 | // 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] | 9743 | // components of the expression. |
| 9744 | static Expr *CheckMapClauseExpressionBase( |
| 9745 | Sema &SemaRef, Expr *E, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9746 | OMPClauseMappableExprCommon::MappableExprComponentList &CurComponents, |
| 9747 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9748 | SourceLocation ELoc = E->getExprLoc(); |
| 9749 | SourceRange ERange = E->getSourceRange(); |
| 9750 | |
| 9751 | // The base of elements of list in a map clause have to be either: |
| 9752 | // - a reference to variable or field. |
| 9753 | // - a member expression. |
| 9754 | // - an array expression. |
| 9755 | // |
| 9756 | // E.g. if we have the expression 'r.S.Arr[:12]', we want to retrieve the |
| 9757 | // reference to 'r'. |
| 9758 | // |
| 9759 | // If we have: |
| 9760 | // |
| 9761 | // struct SS { |
| 9762 | // Bla S; |
| 9763 | // foo() { |
| 9764 | // #pragma omp target map (S.Arr[:12]); |
| 9765 | // } |
| 9766 | // } |
| 9767 | // |
| 9768 | // We want to retrieve the member expression 'this->S'; |
| 9769 | |
| 9770 | Expr *RelevantExpr = nullptr; |
| 9771 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9772 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.2] |
| 9773 | // If a list item is an array section, it must specify contiguous storage. |
| 9774 | // |
| 9775 | // For this restriction it is sufficient that we make sure only references |
| 9776 | // to variables or fields and array expressions, and that no array sections |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9777 | // exist except in the rightmost expression (unless they cover the whole |
| 9778 | // dimension of the array). E.g. these would be invalid: |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9779 | // |
| 9780 | // r.ArrS[3:5].Arr[6:7] |
| 9781 | // |
| 9782 | // r.ArrS[3:5].x |
| 9783 | // |
| 9784 | // but these would be valid: |
| 9785 | // r.ArrS[3].Arr[6:7] |
| 9786 | // |
| 9787 | // r.ArrS[3].x |
| 9788 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9789 | bool AllowUnitySizeArraySection = true; |
| 9790 | bool AllowWholeSizeArraySection = true; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9791 | |
Dmitry Polukhin | 644a925 | 2016-03-11 07:58:34 +0000 | [diff] [blame] | 9792 | while (!RelevantExpr) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9793 | E = E->IgnoreParenImpCasts(); |
| 9794 | |
| 9795 | if (auto *CurE = dyn_cast<DeclRefExpr>(E)) { |
| 9796 | if (!isa<VarDecl>(CurE->getDecl())) |
| 9797 | break; |
| 9798 | |
| 9799 | RelevantExpr = CurE; |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9800 | |
| 9801 | // If we got a reference to a declaration, we should not expect any array |
| 9802 | // section before that. |
| 9803 | AllowUnitySizeArraySection = false; |
| 9804 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9805 | |
| 9806 | // Record the component. |
| 9807 | CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 9808 | CurE, CurE->getDecl())); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9809 | continue; |
| 9810 | } |
| 9811 | |
| 9812 | if (auto *CurE = dyn_cast<MemberExpr>(E)) { |
| 9813 | auto *BaseE = CurE->getBase()->IgnoreParenImpCasts(); |
| 9814 | |
| 9815 | if (isa<CXXThisExpr>(BaseE)) |
| 9816 | // We found a base expression: this->Val. |
| 9817 | RelevantExpr = CurE; |
| 9818 | else |
| 9819 | E = BaseE; |
| 9820 | |
| 9821 | if (!isa<FieldDecl>(CurE->getMemberDecl())) { |
| 9822 | SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field) |
| 9823 | << CurE->getSourceRange(); |
| 9824 | break; |
| 9825 | } |
| 9826 | |
| 9827 | auto *FD = cast<FieldDecl>(CurE->getMemberDecl()); |
| 9828 | |
| 9829 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.3] |
| 9830 | // A bit-field cannot appear in a map clause. |
| 9831 | // |
| 9832 | if (FD->isBitField()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9833 | SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause) |
| 9834 | << CurE->getSourceRange() << getOpenMPClauseName(CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9835 | break; |
| 9836 | } |
| 9837 | |
| 9838 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9839 | // If the type of a list item is a reference to a type T then the type |
| 9840 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9841 | QualType CurType = BaseE->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9842 | |
| 9843 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.2] |
| 9844 | // A list item cannot be a variable that is a member of a structure with |
| 9845 | // a union type. |
| 9846 | // |
| 9847 | if (auto *RT = CurType->getAs<RecordType>()) |
| 9848 | if (RT->isUnionType()) { |
| 9849 | SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed) |
| 9850 | << CurE->getSourceRange(); |
| 9851 | break; |
| 9852 | } |
| 9853 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9854 | // If we got a member expression, we should not expect any array section |
| 9855 | // before that: |
| 9856 | // |
| 9857 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.7] |
| 9858 | // If a list item is an element of a structure, only the rightmost symbol |
| 9859 | // of the variable reference can be an array section. |
| 9860 | // |
| 9861 | AllowUnitySizeArraySection = false; |
| 9862 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9863 | |
| 9864 | // Record the component. |
| 9865 | CurComponents.push_back( |
| 9866 | OMPClauseMappableExprCommon::MappableComponent(CurE, FD)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9867 | continue; |
| 9868 | } |
| 9869 | |
| 9870 | if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) { |
| 9871 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9872 | |
| 9873 | if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) { |
| 9874 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9875 | << 0 << CurE->getSourceRange(); |
| 9876 | break; |
| 9877 | } |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9878 | |
| 9879 | // If we got an array subscript that express the whole dimension we |
| 9880 | // can have any array expressions before. If it only expressing part of |
| 9881 | // the dimension, we can only have unitary-size array expressions. |
| 9882 | if (CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, |
| 9883 | E->getType())) |
| 9884 | AllowWholeSizeArraySection = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9885 | |
| 9886 | // Record the component - we don't have any declaration associated. |
| 9887 | CurComponents.push_back( |
| 9888 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9889 | continue; |
| 9890 | } |
| 9891 | |
| 9892 | if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9893 | E = CurE->getBase()->IgnoreParenImpCasts(); |
| 9894 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9895 | auto CurType = |
| 9896 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 9897 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9898 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 9899 | // If the type of a list item is a reference to a type T then the type |
| 9900 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9901 | if (CurType->isReferenceType()) |
| 9902 | CurType = CurType->getPointeeType(); |
| 9903 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9904 | bool IsPointer = CurType->isAnyPointerType(); |
| 9905 | |
| 9906 | if (!IsPointer && !CurType->isArrayType()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9907 | SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name) |
| 9908 | << 0 << CurE->getSourceRange(); |
| 9909 | break; |
| 9910 | } |
| 9911 | |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9912 | bool NotWhole = |
| 9913 | CheckArrayExpressionDoesNotReferToWholeSize(SemaRef, CurE, CurType); |
| 9914 | bool NotUnity = |
| 9915 | CheckArrayExpressionDoesNotReferToUnitySize(SemaRef, CurE, CurType); |
| 9916 | |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 9917 | if (AllowWholeSizeArraySection) { |
| 9918 | // Any array section is currently allowed. Allowing a whole size array |
| 9919 | // section implies allowing a unity array section as well. |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9920 | // |
| 9921 | // If this array section refers to the whole dimension we can still |
| 9922 | // accept other array sections before this one, except if the base is a |
| 9923 | // pointer. Otherwise, only unitary sections are accepted. |
| 9924 | if (NotWhole || IsPointer) |
| 9925 | AllowWholeSizeArraySection = false; |
Samuel Antao | dab51bb | 2016-07-18 23:22:11 +0000 | [diff] [blame] | 9926 | } else if (AllowUnitySizeArraySection && NotUnity) { |
Samuel Antao | a9f35cb | 2016-03-09 15:46:05 +0000 | [diff] [blame] | 9927 | // A unity or whole array section is not allowed and that is not |
| 9928 | // compatible with the properties of the current array section. |
| 9929 | SemaRef.Diag( |
| 9930 | ELoc, diag::err_array_section_does_not_specify_contiguous_storage) |
| 9931 | << CurE->getSourceRange(); |
| 9932 | break; |
| 9933 | } |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9934 | |
| 9935 | // Record the component - we don't have any declaration associated. |
| 9936 | CurComponents.push_back( |
| 9937 | OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr)); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9938 | continue; |
| 9939 | } |
| 9940 | |
| 9941 | // If nothing else worked, this is not a valid map clause expression. |
| 9942 | SemaRef.Diag(ELoc, |
| 9943 | diag::err_omp_expected_named_var_member_or_array_expression) |
| 9944 | << ERange; |
| 9945 | break; |
| 9946 | } |
| 9947 | |
| 9948 | return RelevantExpr; |
| 9949 | } |
| 9950 | |
| 9951 | // Return true if expression E associated with value VD has conflicts with other |
| 9952 | // map information. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9953 | static bool CheckMapConflicts( |
| 9954 | Sema &SemaRef, DSAStackTy *DSAS, ValueDecl *VD, Expr *E, |
| 9955 | bool CurrentRegionOnly, |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 9956 | OMPClauseMappableExprCommon::MappableExprComponentListRef CurComponents, |
| 9957 | OpenMPClauseKind CKind) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9958 | assert(VD && E); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9959 | SourceLocation ELoc = E->getExprLoc(); |
| 9960 | SourceRange ERange = E->getSourceRange(); |
| 9961 | |
| 9962 | // In order to easily check the conflicts we need to match each component of |
| 9963 | // the expression under test with the components of the expressions that are |
| 9964 | // already in the stack. |
| 9965 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9966 | assert(!CurComponents.empty() && "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9967 | assert(CurComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9968 | "Map clause expression with unexpected base!"); |
| 9969 | |
| 9970 | // Variables to help detecting enclosing problems in data environment nests. |
| 9971 | bool IsEnclosedByDataEnvironmentExpr = false; |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9972 | const Expr *EnclosingExpr = nullptr; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9973 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9974 | bool FoundError = DSAS->checkMappableExprComponentListsForDecl( |
| 9975 | VD, CurrentRegionOnly, |
| 9976 | [&](OMPClauseMappableExprCommon::MappableExprComponentListRef |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 9977 | StackComponents, |
| 9978 | OpenMPClauseKind) -> bool { |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9979 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9980 | assert(!StackComponents.empty() && |
| 9981 | "Map clause expression with no components!"); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9982 | assert(StackComponents.back().getAssociatedDeclaration() == VD && |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9983 | "Map clause expression with unexpected base!"); |
| 9984 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 9985 | // The whole expression in the stack. |
| 9986 | auto *RE = StackComponents.front().getAssociatedExpression(); |
| 9987 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 9988 | // Expressions must start from the same base. Here we detect at which |
| 9989 | // point both expressions diverge from each other and see if we can |
| 9990 | // detect if the memory referred to both expressions is contiguous and |
| 9991 | // do not overlap. |
| 9992 | auto CI = CurComponents.rbegin(); |
| 9993 | auto CE = CurComponents.rend(); |
| 9994 | auto SI = StackComponents.rbegin(); |
| 9995 | auto SE = StackComponents.rend(); |
| 9996 | for (; CI != CE && SI != SE; ++CI, ++SI) { |
| 9997 | |
| 9998 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.3] |
| 9999 | // At most one list item can be an array item derived from a given |
| 10000 | // variable in map clauses of the same construct. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10001 | if (CurrentRegionOnly && |
| 10002 | (isa<ArraySubscriptExpr>(CI->getAssociatedExpression()) || |
| 10003 | isa<OMPArraySectionExpr>(CI->getAssociatedExpression())) && |
| 10004 | (isa<ArraySubscriptExpr>(SI->getAssociatedExpression()) || |
| 10005 | isa<OMPArraySectionExpr>(SI->getAssociatedExpression()))) { |
| 10006 | SemaRef.Diag(CI->getAssociatedExpression()->getExprLoc(), |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10007 | diag::err_omp_multiple_array_items_in_map_clause) |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10008 | << CI->getAssociatedExpression()->getSourceRange(); |
| 10009 | SemaRef.Diag(SI->getAssociatedExpression()->getExprLoc(), |
| 10010 | diag::note_used_here) |
| 10011 | << SI->getAssociatedExpression()->getSourceRange(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10012 | return true; |
| 10013 | } |
| 10014 | |
| 10015 | // Do both expressions have the same kind? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10016 | if (CI->getAssociatedExpression()->getStmtClass() != |
| 10017 | SI->getAssociatedExpression()->getStmtClass()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10018 | break; |
| 10019 | |
| 10020 | // Are we dealing with different variables/fields? |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10021 | if (CI->getAssociatedDeclaration() != SI->getAssociatedDeclaration()) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10022 | break; |
| 10023 | } |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10024 | // Check if the extra components of the expressions in the enclosing |
| 10025 | // data environment are redundant for the current base declaration. |
| 10026 | // If they are, the maps completely overlap, which is legal. |
| 10027 | for (; SI != SE; ++SI) { |
| 10028 | QualType Type; |
| 10029 | if (auto *ASE = |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10030 | dyn_cast<ArraySubscriptExpr>(SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10031 | Type = ASE->getBase()->IgnoreParenImpCasts()->getType(); |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10032 | } else if (auto *OASE = dyn_cast<OMPArraySectionExpr>( |
| 10033 | SI->getAssociatedExpression())) { |
Kelvin Li | 9f645ae | 2016-07-18 22:49:16 +0000 | [diff] [blame] | 10034 | auto *E = OASE->getBase()->IgnoreParenImpCasts(); |
| 10035 | Type = |
| 10036 | OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType(); |
| 10037 | } |
| 10038 | if (Type.isNull() || Type->isAnyPointerType() || |
| 10039 | CheckArrayExpressionDoesNotReferToWholeSize( |
| 10040 | SemaRef, SI->getAssociatedExpression(), Type)) |
| 10041 | break; |
| 10042 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10043 | |
| 10044 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10045 | // List items of map clauses in the same construct must not share |
| 10046 | // original storage. |
| 10047 | // |
| 10048 | // If the expressions are exactly the same or one is a subset of the |
| 10049 | // other, it means they are sharing storage. |
| 10050 | if (CI == CE && SI == SE) { |
| 10051 | if (CurrentRegionOnly) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10052 | if (CKind == OMPC_map) |
| 10053 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10054 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10055 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10056 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10057 | << ERange; |
| 10058 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10059 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10060 | << RE->getSourceRange(); |
| 10061 | return true; |
| 10062 | } else { |
| 10063 | // If we find the same expression in the enclosing data environment, |
| 10064 | // that is legal. |
| 10065 | IsEnclosedByDataEnvironmentExpr = true; |
| 10066 | return false; |
| 10067 | } |
| 10068 | } |
| 10069 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10070 | QualType DerivedType = |
| 10071 | std::prev(CI)->getAssociatedDeclaration()->getType(); |
| 10072 | SourceLocation DerivedLoc = |
| 10073 | std::prev(CI)->getAssociatedExpression()->getExprLoc(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10074 | |
| 10075 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10076 | // If the type of a list item is a reference to a type T then the type |
| 10077 | // will be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10078 | DerivedType = DerivedType.getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10079 | |
| 10080 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C/C++, p.1] |
| 10081 | // A variable for which the type is pointer and an array section |
| 10082 | // derived from that variable must not appear as list items of map |
| 10083 | // clauses of the same construct. |
| 10084 | // |
| 10085 | // Also, cover one of the cases in: |
| 10086 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10087 | // If any part of the original storage of a list item has corresponding |
| 10088 | // storage in the device data environment, all of the original storage |
| 10089 | // must have corresponding storage in the device data environment. |
| 10090 | // |
| 10091 | if (DerivedType->isAnyPointerType()) { |
| 10092 | if (CI == CE || SI == SE) { |
| 10093 | SemaRef.Diag( |
| 10094 | DerivedLoc, |
| 10095 | diag::err_omp_pointer_mapped_along_with_derived_section) |
| 10096 | << DerivedLoc; |
| 10097 | } else { |
| 10098 | assert(CI != CE && SI != SE); |
| 10099 | SemaRef.Diag(DerivedLoc, diag::err_omp_same_pointer_derreferenced) |
| 10100 | << DerivedLoc; |
| 10101 | } |
| 10102 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10103 | << RE->getSourceRange(); |
| 10104 | return true; |
| 10105 | } |
| 10106 | |
| 10107 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.4] |
| 10108 | // List items of map clauses in the same construct must not share |
| 10109 | // original storage. |
| 10110 | // |
| 10111 | // An expression is a subset of the other. |
| 10112 | if (CurrentRegionOnly && (CI == CE || SI == SE)) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10113 | if (CKind == OMPC_map) |
| 10114 | SemaRef.Diag(ELoc, diag::err_omp_map_shared_storage) << ERange; |
| 10115 | else { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10116 | assert(CKind == OMPC_to || CKind == OMPC_from); |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10117 | SemaRef.Diag(ELoc, diag::err_omp_once_referenced_in_target_update) |
| 10118 | << ERange; |
| 10119 | } |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10120 | SemaRef.Diag(RE->getExprLoc(), diag::note_used_here) |
| 10121 | << RE->getSourceRange(); |
| 10122 | return true; |
| 10123 | } |
| 10124 | |
| 10125 | // The current expression uses the same base as other expression in the |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10126 | // data environment but does not contain it completely. |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10127 | if (!CurrentRegionOnly && SI != SE) |
| 10128 | EnclosingExpr = RE; |
| 10129 | |
| 10130 | // The current expression is a subset of the expression in the data |
| 10131 | // environment. |
| 10132 | IsEnclosedByDataEnvironmentExpr |= |
| 10133 | (!CurrentRegionOnly && CI != CE && SI == SE); |
| 10134 | |
| 10135 | return false; |
| 10136 | }); |
| 10137 | |
| 10138 | if (CurrentRegionOnly) |
| 10139 | return FoundError; |
| 10140 | |
| 10141 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.5] |
| 10142 | // If any part of the original storage of a list item has corresponding |
| 10143 | // storage in the device data environment, all of the original storage must |
| 10144 | // have corresponding storage in the device data environment. |
| 10145 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.6] |
| 10146 | // If a list item is an element of a structure, and a different element of |
| 10147 | // the structure has a corresponding list item in the device data environment |
| 10148 | // prior to a task encountering the construct associated with the map clause, |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10149 | // 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] | 10150 | // data environment prior to the task encountering the construct. |
| 10151 | // |
| 10152 | if (EnclosingExpr && !IsEnclosedByDataEnvironmentExpr) { |
| 10153 | SemaRef.Diag(ELoc, |
| 10154 | diag::err_omp_original_storage_is_shared_and_does_not_contain) |
| 10155 | << ERange; |
| 10156 | SemaRef.Diag(EnclosingExpr->getExprLoc(), diag::note_used_here) |
| 10157 | << EnclosingExpr->getSourceRange(); |
| 10158 | return true; |
| 10159 | } |
| 10160 | |
| 10161 | return FoundError; |
| 10162 | } |
| 10163 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10164 | namespace { |
| 10165 | // Utility struct that gathers all the related lists associated with a mappable |
| 10166 | // expression. |
| 10167 | struct MappableVarListInfo final { |
| 10168 | // The list of expressions. |
| 10169 | ArrayRef<Expr *> VarList; |
| 10170 | // The list of processed expressions. |
| 10171 | SmallVector<Expr *, 16> ProcessedVarList; |
| 10172 | // The mappble components for each expression. |
| 10173 | OMPClauseMappableExprCommon::MappableExprComponentLists VarComponents; |
| 10174 | // The base declaration of the variable. |
| 10175 | SmallVector<ValueDecl *, 16> VarBaseDeclarations; |
| 10176 | |
| 10177 | MappableVarListInfo(ArrayRef<Expr *> VarList) : VarList(VarList) { |
| 10178 | // We have a list of components and base declarations for each entry in the |
| 10179 | // variable list. |
| 10180 | VarComponents.reserve(VarList.size()); |
| 10181 | VarBaseDeclarations.reserve(VarList.size()); |
| 10182 | } |
| 10183 | }; |
| 10184 | } |
| 10185 | |
| 10186 | // Check the validity of the provided variable list for the provided clause kind |
| 10187 | // \a CKind. In the check process the valid expressions, and mappable expression |
| 10188 | // components and variables are extracted and used to fill \a Vars, |
| 10189 | // \a ClauseComponents, and \a ClauseBaseDeclarations. \a MapType and |
| 10190 | // \a IsMapTypeImplicit are expected to be valid if the clause kind is 'map'. |
| 10191 | static void |
| 10192 | checkMappableExpressionList(Sema &SemaRef, DSAStackTy *DSAS, |
| 10193 | OpenMPClauseKind CKind, MappableVarListInfo &MVLI, |
| 10194 | SourceLocation StartLoc, |
| 10195 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown, |
| 10196 | bool IsMapTypeImplicit = false) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10197 | // We only expect mappable expressions in 'to', 'from', and 'map' clauses. |
| 10198 | assert((CKind == OMPC_map || CKind == OMPC_to || CKind == OMPC_from) && |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10199 | "Unexpected clause kind with mappable expressions!"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10200 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10201 | // Keep track of the mappable components and base declarations in this clause. |
| 10202 | // Each entry in the list is going to have a list of components associated. We |
| 10203 | // record each set of the components so that we can build the clause later on. |
| 10204 | // In the end we should have the same amount of declarations and component |
| 10205 | // lists. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10206 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10207 | for (auto &RE : MVLI.VarList) { |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 10208 | assert(RE && "Null expr in omp to/from/map clause"); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10209 | SourceLocation ELoc = RE->getExprLoc(); |
| 10210 | |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10211 | auto *VE = RE->IgnoreParenLValueCasts(); |
| 10212 | |
| 10213 | if (VE->isValueDependent() || VE->isTypeDependent() || |
| 10214 | VE->isInstantiationDependent() || |
| 10215 | VE->containsUnexpandedParameterPack()) { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10216 | // We can only analyze this information once the missing information is |
| 10217 | // resolved. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10218 | MVLI.ProcessedVarList.push_back(RE); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10219 | continue; |
| 10220 | } |
| 10221 | |
| 10222 | auto *SimpleExpr = RE->IgnoreParenCasts(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10223 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10224 | if (!RE->IgnoreParenImpCasts()->isLValue()) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10225 | SemaRef.Diag(ELoc, |
| 10226 | diag::err_omp_expected_named_var_member_or_array_expression) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10227 | << RE->getSourceRange(); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10228 | continue; |
| 10229 | } |
| 10230 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10231 | OMPClauseMappableExprCommon::MappableExprComponentList CurComponents; |
| 10232 | ValueDecl *CurDeclaration = nullptr; |
| 10233 | |
| 10234 | // Obtain the array or member expression bases if required. Also, fill the |
| 10235 | // components array with all the components identified in the process. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10236 | auto *BE = |
| 10237 | CheckMapClauseExpressionBase(SemaRef, SimpleExpr, CurComponents, CKind); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10238 | if (!BE) |
| 10239 | continue; |
| 10240 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10241 | assert(!CurComponents.empty() && |
| 10242 | "Invalid mappable expression information."); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10243 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10244 | // For the following checks, we rely on the base declaration which is |
| 10245 | // expected to be associated with the last component. The declaration is |
| 10246 | // expected to be a variable or a field (if 'this' is being mapped). |
| 10247 | CurDeclaration = CurComponents.back().getAssociatedDeclaration(); |
| 10248 | assert(CurDeclaration && "Null decl on map clause."); |
| 10249 | assert( |
| 10250 | CurDeclaration->isCanonicalDecl() && |
| 10251 | "Expecting components to have associated only canonical declarations."); |
| 10252 | |
| 10253 | auto *VD = dyn_cast<VarDecl>(CurDeclaration); |
| 10254 | auto *FD = dyn_cast<FieldDecl>(CurDeclaration); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10255 | |
| 10256 | assert((VD || FD) && "Only variables or fields are expected here!"); |
NAKAMURA Takumi | 6dcb814 | 2016-01-23 01:38:20 +0000 | [diff] [blame] | 10257 | (void)FD; |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10258 | |
| 10259 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.10] |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10260 | // threadprivate variables cannot appear in a map clause. |
| 10261 | // OpenMP 4.5 [2.10.5, target update Construct] |
| 10262 | // threadprivate variables cannot appear in a from clause. |
| 10263 | if (VD && DSAS->isThreadPrivate(VD)) { |
| 10264 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10265 | SemaRef.Diag(ELoc, diag::err_omp_threadprivate_in_clause) |
| 10266 | << getOpenMPClauseName(CKind); |
| 10267 | ReportOriginalDSA(SemaRef, DSAS, VD, DVar); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10268 | continue; |
| 10269 | } |
| 10270 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10271 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
| 10272 | // A list item cannot appear in both a map clause and a data-sharing |
| 10273 | // attribute clause on the same construct. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10274 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10275 | // Check conflicts with other map clause expressions. We check the conflicts |
| 10276 | // with the current construct separately from the enclosing data |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10277 | // environment, because the restrictions are different. We only have to |
| 10278 | // check conflicts across regions for the map clauses. |
| 10279 | if (CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10280 | /*CurrentRegionOnly=*/true, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10281 | break; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10282 | if (CKind == OMPC_map && |
| 10283 | CheckMapConflicts(SemaRef, DSAS, CurDeclaration, SimpleExpr, |
| 10284 | /*CurrentRegionOnly=*/false, CurComponents, CKind)) |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10285 | break; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10286 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10287 | // OpenMP 4.5 [2.10.5, target update Construct] |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10288 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1] |
| 10289 | // If the type of a list item is a reference to a type T then the type will |
| 10290 | // be considered to be T for all purposes of this clause. |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10291 | QualType Type = CurDeclaration->getType().getNonReferenceType(); |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10292 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10293 | // OpenMP 4.5 [2.10.5, target update Construct, Restrictions, p.4] |
| 10294 | // 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] | 10295 | // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, p.9] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10296 | // A list item must have a mappable type. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10297 | if (!CheckTypeMappable(VE->getExprLoc(), VE->getSourceRange(), SemaRef, |
| 10298 | DSAS, Type)) |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10299 | continue; |
| 10300 | |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10301 | if (CKind == OMPC_map) { |
| 10302 | // target enter data |
| 10303 | // OpenMP [2.10.2, Restrictions, p. 99] |
| 10304 | // A map-type must be specified in all map clauses and must be either |
| 10305 | // to or alloc. |
| 10306 | OpenMPDirectiveKind DKind = DSAS->getCurrentDirective(); |
| 10307 | if (DKind == OMPD_target_enter_data && |
| 10308 | !(MapType == OMPC_MAP_to || MapType == OMPC_MAP_alloc)) { |
| 10309 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10310 | << (IsMapTypeImplicit ? 1 : 0) |
| 10311 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10312 | << getOpenMPDirectiveName(DKind); |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10313 | continue; |
| 10314 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10315 | |
| 10316 | // target exit_data |
| 10317 | // OpenMP [2.10.3, Restrictions, p. 102] |
| 10318 | // A map-type must be specified in all map clauses and must be either |
| 10319 | // from, release, or delete. |
| 10320 | if (DKind == OMPD_target_exit_data && |
| 10321 | !(MapType == OMPC_MAP_from || MapType == OMPC_MAP_release || |
| 10322 | MapType == OMPC_MAP_delete)) { |
| 10323 | SemaRef.Diag(StartLoc, diag::err_omp_invalid_map_type_for_directive) |
| 10324 | << (IsMapTypeImplicit ? 1 : 0) |
| 10325 | << getOpenMPSimpleClauseTypeName(OMPC_map, MapType) |
| 10326 | << getOpenMPDirectiveName(DKind); |
| 10327 | continue; |
| 10328 | } |
| 10329 | |
| 10330 | // OpenMP 4.5 [2.15.5.1, Restrictions, p.3] |
| 10331 | // A list item cannot appear in both a map clause and a data-sharing |
| 10332 | // attribute clause on the same construct |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 10333 | if ((DKind == OMPD_target || DKind == OMPD_target_teams || |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 10334 | DKind == OMPD_target_teams_distribute || |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 10335 | DKind == OMPD_target_teams_distribute_parallel_for || |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 10336 | DKind == OMPD_target_teams_distribute_parallel_for_simd || |
| 10337 | DKind == OMPD_target_teams_distribute_simd) && VD) { |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10338 | auto DVar = DSAS->getTopDSA(VD, false); |
| 10339 | if (isOpenMPPrivate(DVar.CKind)) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10340 | SemaRef.Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10341 | << getOpenMPClauseName(DVar.CKind) |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10342 | << getOpenMPClauseName(OMPC_map) |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10343 | << getOpenMPDirectiveName(DSAS->getCurrentDirective()); |
| 10344 | ReportOriginalDSA(SemaRef, DSAS, CurDeclaration, DVar); |
| 10345 | continue; |
| 10346 | } |
| 10347 | } |
Carlo Bertolli | b74bfc8 | 2016-03-18 21:43:32 +0000 | [diff] [blame] | 10348 | } |
| 10349 | |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10350 | // Save the current expression. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10351 | MVLI.ProcessedVarList.push_back(RE); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10352 | |
| 10353 | // Store the components in the stack so that they can be used to check |
| 10354 | // against other clauses later on. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 10355 | DSAS->addMappableExpressionComponents(CurDeclaration, CurComponents, |
| 10356 | /*WhereFoundClauseKind=*/OMPC_map); |
Samuel Antao | 9092700 | 2016-04-26 14:54:23 +0000 | [diff] [blame] | 10357 | |
| 10358 | // Save the components and declaration to create the clause. For purposes of |
| 10359 | // the clause creation, any component list that has has base 'this' uses |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 10360 | // null as base declaration. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10361 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 10362 | MVLI.VarComponents.back().append(CurComponents.begin(), |
| 10363 | CurComponents.end()); |
| 10364 | MVLI.VarBaseDeclarations.push_back(isa<MemberExpr>(BE) ? nullptr |
| 10365 | : CurDeclaration); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10366 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10367 | } |
| 10368 | |
| 10369 | OMPClause * |
| 10370 | Sema::ActOnOpenMPMapClause(OpenMPMapClauseKind MapTypeModifier, |
| 10371 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 10372 | SourceLocation MapLoc, SourceLocation ColonLoc, |
| 10373 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 10374 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 10375 | MappableVarListInfo MVLI(VarList); |
| 10376 | checkMappableExpressionList(*this, DSAStack, OMPC_map, MVLI, StartLoc, |
| 10377 | MapType, IsMapTypeImplicit); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10378 | |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 10379 | // We need to produce a map clause even if we don't have variables so that |
| 10380 | // other diagnostics related with non-existing map clauses are accurate. |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10381 | return OMPMapClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10382 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10383 | MVLI.VarComponents, MapTypeModifier, MapType, |
| 10384 | IsMapTypeImplicit, MapLoc); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 10385 | } |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10386 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10387 | QualType Sema::ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 10388 | TypeResult ParsedType) { |
| 10389 | assert(ParsedType.isUsable()); |
| 10390 | |
| 10391 | QualType ReductionType = GetTypeFromParser(ParsedType.get()); |
| 10392 | if (ReductionType.isNull()) |
| 10393 | return QualType(); |
| 10394 | |
| 10395 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions, C\C++ |
| 10396 | // A type name in a declare reduction directive cannot be a function type, an |
| 10397 | // array type, a reference type, or a type qualified with const, volatile or |
| 10398 | // restrict. |
| 10399 | if (ReductionType.hasQualifiers()) { |
| 10400 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 0; |
| 10401 | return QualType(); |
| 10402 | } |
| 10403 | |
| 10404 | if (ReductionType->isFunctionType()) { |
| 10405 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 1; |
| 10406 | return QualType(); |
| 10407 | } |
| 10408 | if (ReductionType->isReferenceType()) { |
| 10409 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 2; |
| 10410 | return QualType(); |
| 10411 | } |
| 10412 | if (ReductionType->isArrayType()) { |
| 10413 | Diag(TyLoc, diag::err_omp_reduction_wrong_type) << 3; |
| 10414 | return QualType(); |
| 10415 | } |
| 10416 | return ReductionType; |
| 10417 | } |
| 10418 | |
| 10419 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveStart( |
| 10420 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 10421 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 10422 | AccessSpecifier AS, Decl *PrevDeclInScope) { |
| 10423 | SmallVector<Decl *, 8> Decls; |
| 10424 | Decls.reserve(ReductionTypes.size()); |
| 10425 | |
| 10426 | LookupResult Lookup(*this, Name, SourceLocation(), LookupOMPReductionName, |
| 10427 | ForRedeclaration); |
| 10428 | // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions |
| 10429 | // A reduction-identifier may not be re-declared in the current scope for the |
| 10430 | // same type or for a type that is compatible according to the base language |
| 10431 | // rules. |
| 10432 | llvm::DenseMap<QualType, SourceLocation> PreviousRedeclTypes; |
| 10433 | OMPDeclareReductionDecl *PrevDRD = nullptr; |
| 10434 | bool InCompoundScope = true; |
| 10435 | if (S != nullptr) { |
| 10436 | // Find previous declaration with the same name not referenced in other |
| 10437 | // declarations. |
| 10438 | FunctionScopeInfo *ParentFn = getEnclosingFunction(); |
| 10439 | InCompoundScope = |
| 10440 | (ParentFn != nullptr) && !ParentFn->CompoundScopes.empty(); |
| 10441 | LookupName(Lookup, S); |
| 10442 | FilterLookupForScope(Lookup, DC, S, /*ConsiderLinkage=*/false, |
| 10443 | /*AllowInlineNamespace=*/false); |
| 10444 | llvm::DenseMap<OMPDeclareReductionDecl *, bool> UsedAsPrevious; |
| 10445 | auto Filter = Lookup.makeFilter(); |
| 10446 | while (Filter.hasNext()) { |
| 10447 | auto *PrevDecl = cast<OMPDeclareReductionDecl>(Filter.next()); |
| 10448 | if (InCompoundScope) { |
| 10449 | auto I = UsedAsPrevious.find(PrevDecl); |
| 10450 | if (I == UsedAsPrevious.end()) |
| 10451 | UsedAsPrevious[PrevDecl] = false; |
| 10452 | if (auto *D = PrevDecl->getPrevDeclInScope()) |
| 10453 | UsedAsPrevious[D] = true; |
| 10454 | } |
| 10455 | PreviousRedeclTypes[PrevDecl->getType().getCanonicalType()] = |
| 10456 | PrevDecl->getLocation(); |
| 10457 | } |
| 10458 | Filter.done(); |
| 10459 | if (InCompoundScope) { |
| 10460 | for (auto &PrevData : UsedAsPrevious) { |
| 10461 | if (!PrevData.second) { |
| 10462 | PrevDRD = PrevData.first; |
| 10463 | break; |
| 10464 | } |
| 10465 | } |
| 10466 | } |
| 10467 | } else if (PrevDeclInScope != nullptr) { |
| 10468 | auto *PrevDRDInScope = PrevDRD = |
| 10469 | cast<OMPDeclareReductionDecl>(PrevDeclInScope); |
| 10470 | do { |
| 10471 | PreviousRedeclTypes[PrevDRDInScope->getType().getCanonicalType()] = |
| 10472 | PrevDRDInScope->getLocation(); |
| 10473 | PrevDRDInScope = PrevDRDInScope->getPrevDeclInScope(); |
| 10474 | } while (PrevDRDInScope != nullptr); |
| 10475 | } |
| 10476 | for (auto &TyData : ReductionTypes) { |
| 10477 | auto I = PreviousRedeclTypes.find(TyData.first.getCanonicalType()); |
| 10478 | bool Invalid = false; |
| 10479 | if (I != PreviousRedeclTypes.end()) { |
| 10480 | Diag(TyData.second, diag::err_omp_declare_reduction_redefinition) |
| 10481 | << TyData.first; |
| 10482 | Diag(I->second, diag::note_previous_definition); |
| 10483 | Invalid = true; |
| 10484 | } |
| 10485 | PreviousRedeclTypes[TyData.first.getCanonicalType()] = TyData.second; |
| 10486 | auto *DRD = OMPDeclareReductionDecl::Create(Context, DC, TyData.second, |
| 10487 | Name, TyData.first, PrevDRD); |
| 10488 | DC->addDecl(DRD); |
| 10489 | DRD->setAccess(AS); |
| 10490 | Decls.push_back(DRD); |
| 10491 | if (Invalid) |
| 10492 | DRD->setInvalidDecl(); |
| 10493 | else |
| 10494 | PrevDRD = DRD; |
| 10495 | } |
| 10496 | |
| 10497 | return DeclGroupPtrTy::make( |
| 10498 | DeclGroupRef::Create(Context, Decls.begin(), Decls.size())); |
| 10499 | } |
| 10500 | |
| 10501 | void Sema::ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D) { |
| 10502 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10503 | |
| 10504 | // Enter new function scope. |
| 10505 | PushFunctionScope(); |
| 10506 | getCurFunction()->setHasBranchProtectedScope(); |
| 10507 | getCurFunction()->setHasOMPDeclareReductionCombiner(); |
| 10508 | |
| 10509 | if (S != nullptr) |
| 10510 | PushDeclContext(S, DRD); |
| 10511 | else |
| 10512 | CurContext = DRD; |
| 10513 | |
| 10514 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10515 | |
| 10516 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10517 | // Create 'T* omp_parm;T omp_in;'. All references to 'omp_in' will |
| 10518 | // be replaced by '*omp_parm' during codegen. This required because 'omp_in' |
| 10519 | // uses semantics of argument handles by value, but it should be passed by |
| 10520 | // reference. C lang does not support references, so pass all parameters as |
| 10521 | // pointers. |
| 10522 | // Create 'T omp_in;' variable. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10523 | auto *OmpInParm = |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10524 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_in"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10525 | // Create 'T* omp_parm;T omp_out;'. All references to 'omp_out' will |
| 10526 | // be replaced by '*omp_parm' during codegen. This required because 'omp_out' |
| 10527 | // uses semantics of argument handles by value, but it should be passed by |
| 10528 | // reference. C lang does not support references, so pass all parameters as |
| 10529 | // pointers. |
| 10530 | // Create 'T omp_out;' variable. |
| 10531 | auto *OmpOutParm = |
| 10532 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_out"); |
| 10533 | if (S != nullptr) { |
| 10534 | PushOnScopeChains(OmpInParm, S); |
| 10535 | PushOnScopeChains(OmpOutParm, S); |
| 10536 | } else { |
| 10537 | DRD->addDecl(OmpInParm); |
| 10538 | DRD->addDecl(OmpOutParm); |
| 10539 | } |
| 10540 | } |
| 10541 | |
| 10542 | void Sema::ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner) { |
| 10543 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10544 | DiscardCleanupsInEvaluationContext(); |
| 10545 | PopExpressionEvaluationContext(); |
| 10546 | |
| 10547 | PopDeclContext(); |
| 10548 | PopFunctionScopeInfo(); |
| 10549 | |
| 10550 | if (Combiner != nullptr) |
| 10551 | DRD->setCombiner(Combiner); |
| 10552 | else |
| 10553 | DRD->setInvalidDecl(); |
| 10554 | } |
| 10555 | |
| 10556 | void Sema::ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D) { |
| 10557 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10558 | |
| 10559 | // Enter new function scope. |
| 10560 | PushFunctionScope(); |
| 10561 | getCurFunction()->setHasBranchProtectedScope(); |
| 10562 | |
| 10563 | if (S != nullptr) |
| 10564 | PushDeclContext(S, DRD); |
| 10565 | else |
| 10566 | CurContext = DRD; |
| 10567 | |
| 10568 | PushExpressionEvaluationContext(PotentiallyEvaluated); |
| 10569 | |
| 10570 | QualType ReductionType = DRD->getType(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10571 | // Create 'T* omp_parm;T omp_priv;'. All references to 'omp_priv' will |
| 10572 | // be replaced by '*omp_parm' during codegen. This required because 'omp_priv' |
| 10573 | // uses semantics of argument handles by value, but it should be passed by |
| 10574 | // reference. C lang does not support references, so pass all parameters as |
| 10575 | // pointers. |
| 10576 | // Create 'T omp_priv;' variable. |
| 10577 | auto *OmpPrivParm = |
| 10578 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_priv"); |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 10579 | // Create 'T* omp_parm;T omp_orig;'. All references to 'omp_orig' will |
| 10580 | // be replaced by '*omp_parm' during codegen. This required because 'omp_orig' |
| 10581 | // uses semantics of argument handles by value, but it should be passed by |
| 10582 | // reference. C lang does not support references, so pass all parameters as |
| 10583 | // pointers. |
| 10584 | // Create 'T omp_orig;' variable. |
| 10585 | auto *OmpOrigParm = |
| 10586 | buildVarDecl(*this, D->getLocation(), ReductionType, "omp_orig"); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 10587 | if (S != nullptr) { |
| 10588 | PushOnScopeChains(OmpPrivParm, S); |
| 10589 | PushOnScopeChains(OmpOrigParm, S); |
| 10590 | } else { |
| 10591 | DRD->addDecl(OmpPrivParm); |
| 10592 | DRD->addDecl(OmpOrigParm); |
| 10593 | } |
| 10594 | } |
| 10595 | |
| 10596 | void Sema::ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, |
| 10597 | Expr *Initializer) { |
| 10598 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10599 | DiscardCleanupsInEvaluationContext(); |
| 10600 | PopExpressionEvaluationContext(); |
| 10601 | |
| 10602 | PopDeclContext(); |
| 10603 | PopFunctionScopeInfo(); |
| 10604 | |
| 10605 | if (Initializer != nullptr) |
| 10606 | DRD->setInitializer(Initializer); |
| 10607 | else |
| 10608 | DRD->setInvalidDecl(); |
| 10609 | } |
| 10610 | |
| 10611 | Sema::DeclGroupPtrTy Sema::ActOnOpenMPDeclareReductionDirectiveEnd( |
| 10612 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid) { |
| 10613 | for (auto *D : DeclReductions.get()) { |
| 10614 | if (IsValid) { |
| 10615 | auto *DRD = cast<OMPDeclareReductionDecl>(D); |
| 10616 | if (S != nullptr) |
| 10617 | PushOnScopeChains(DRD, S, /*AddToContext=*/false); |
| 10618 | } else |
| 10619 | D->setInvalidDecl(); |
| 10620 | } |
| 10621 | return DeclReductions; |
| 10622 | } |
| 10623 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10624 | OMPClause *Sema::ActOnOpenMPNumTeamsClause(Expr *NumTeams, |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10625 | SourceLocation StartLoc, |
| 10626 | SourceLocation LParenLoc, |
| 10627 | SourceLocation EndLoc) { |
| 10628 | Expr *ValExpr = NumTeams; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10629 | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10630 | // OpenMP [teams Constrcut, Restrictions] |
| 10631 | // The num_teams expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10632 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_teams, |
| 10633 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10634 | return nullptr; |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 10635 | |
| 10636 | return new (Context) OMPNumTeamsClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10637 | } |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10638 | |
| 10639 | OMPClause *Sema::ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 10640 | SourceLocation StartLoc, |
| 10641 | SourceLocation LParenLoc, |
| 10642 | SourceLocation EndLoc) { |
| 10643 | Expr *ValExpr = ThreadLimit; |
| 10644 | |
| 10645 | // OpenMP [teams Constrcut, Restrictions] |
| 10646 | // The thread_limit expression must evaluate to a positive integer value. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10647 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_thread_limit, |
| 10648 | /*StrictlyPositive=*/true)) |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10649 | return nullptr; |
| 10650 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10651 | return new (Context) |
| 10652 | OMPThreadLimitClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 10653 | } |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 10654 | |
| 10655 | OMPClause *Sema::ActOnOpenMPPriorityClause(Expr *Priority, |
| 10656 | SourceLocation StartLoc, |
| 10657 | SourceLocation LParenLoc, |
| 10658 | SourceLocation EndLoc) { |
| 10659 | Expr *ValExpr = Priority; |
| 10660 | |
| 10661 | // OpenMP [2.9.1, task Constrcut] |
| 10662 | // The priority-value is a non-negative numerical scalar expression. |
| 10663 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_priority, |
| 10664 | /*StrictlyPositive=*/false)) |
| 10665 | return nullptr; |
| 10666 | |
| 10667 | return new (Context) OMPPriorityClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10668 | } |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 10669 | |
| 10670 | OMPClause *Sema::ActOnOpenMPGrainsizeClause(Expr *Grainsize, |
| 10671 | SourceLocation StartLoc, |
| 10672 | SourceLocation LParenLoc, |
| 10673 | SourceLocation EndLoc) { |
| 10674 | Expr *ValExpr = Grainsize; |
| 10675 | |
| 10676 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10677 | // The parameter of the grainsize clause must be a positive integer |
| 10678 | // expression. |
| 10679 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_grainsize, |
| 10680 | /*StrictlyPositive=*/true)) |
| 10681 | return nullptr; |
| 10682 | |
| 10683 | return new (Context) OMPGrainsizeClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10684 | } |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 10685 | |
| 10686 | OMPClause *Sema::ActOnOpenMPNumTasksClause(Expr *NumTasks, |
| 10687 | SourceLocation StartLoc, |
| 10688 | SourceLocation LParenLoc, |
| 10689 | SourceLocation EndLoc) { |
| 10690 | Expr *ValExpr = NumTasks; |
| 10691 | |
| 10692 | // OpenMP [2.9.2, taskloop Constrcut] |
| 10693 | // The parameter of the num_tasks clause must be a positive integer |
| 10694 | // expression. |
| 10695 | if (!IsNonNegativeIntegerValue(ValExpr, *this, OMPC_num_tasks, |
| 10696 | /*StrictlyPositive=*/true)) |
| 10697 | return nullptr; |
| 10698 | |
| 10699 | return new (Context) OMPNumTasksClause(ValExpr, StartLoc, LParenLoc, EndLoc); |
| 10700 | } |
| 10701 | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 10702 | OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 10703 | SourceLocation LParenLoc, |
| 10704 | SourceLocation EndLoc) { |
| 10705 | // OpenMP [2.13.2, critical construct, Description] |
| 10706 | // ... where hint-expression is an integer constant expression that evaluates |
| 10707 | // to a valid lock hint. |
| 10708 | ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint); |
| 10709 | if (HintExpr.isInvalid()) |
| 10710 | return nullptr; |
| 10711 | return new (Context) |
| 10712 | OMPHintClause(HintExpr.get(), StartLoc, LParenLoc, EndLoc); |
| 10713 | } |
| 10714 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10715 | OMPClause *Sema::ActOnOpenMPDistScheduleClause( |
| 10716 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 10717 | SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, |
| 10718 | SourceLocation EndLoc) { |
| 10719 | if (Kind == OMPC_DIST_SCHEDULE_unknown) { |
| 10720 | std::string Values; |
| 10721 | Values += "'"; |
| 10722 | Values += getOpenMPSimpleClauseTypeName(OMPC_dist_schedule, 0); |
| 10723 | Values += "'"; |
| 10724 | Diag(KindLoc, diag::err_omp_unexpected_clause_value) |
| 10725 | << Values << getOpenMPClauseName(OMPC_dist_schedule); |
| 10726 | return nullptr; |
| 10727 | } |
| 10728 | Expr *ValExpr = ChunkSize; |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10729 | Stmt *HelperValStmt = nullptr; |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10730 | if (ChunkSize) { |
| 10731 | if (!ChunkSize->isValueDependent() && !ChunkSize->isTypeDependent() && |
| 10732 | !ChunkSize->isInstantiationDependent() && |
| 10733 | !ChunkSize->containsUnexpandedParameterPack()) { |
| 10734 | SourceLocation ChunkSizeLoc = ChunkSize->getLocStart(); |
| 10735 | ExprResult Val = |
| 10736 | PerformOpenMPImplicitIntegerConversion(ChunkSizeLoc, ChunkSize); |
| 10737 | if (Val.isInvalid()) |
| 10738 | return nullptr; |
| 10739 | |
| 10740 | ValExpr = Val.get(); |
| 10741 | |
| 10742 | // OpenMP [2.7.1, Restrictions] |
| 10743 | // chunk_size must be a loop invariant integer expression with a positive |
| 10744 | // value. |
| 10745 | llvm::APSInt Result; |
| 10746 | if (ValExpr->isIntegerConstantExpr(Result, Context)) { |
| 10747 | if (Result.isSigned() && !Result.isStrictlyPositive()) { |
| 10748 | Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause) |
| 10749 | << "dist_schedule" << ChunkSize->getSourceRange(); |
| 10750 | return nullptr; |
| 10751 | } |
Alexey Bataev | b46cdea | 2016-06-15 11:20:48 +0000 | [diff] [blame] | 10752 | } else if (isParallelOrTaskRegion(DSAStack->getCurrentDirective()) && |
| 10753 | !CurContext->isDependentContext()) { |
Alexey Bataev | 5a3af13 | 2016-03-29 08:58:54 +0000 | [diff] [blame] | 10754 | llvm::MapVector<Expr *, DeclRefExpr *> Captures; |
| 10755 | ValExpr = tryBuildCapture(*this, ValExpr, Captures).get(); |
| 10756 | HelperValStmt = buildPreInits(Context, Captures); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10757 | } |
| 10758 | } |
| 10759 | } |
| 10760 | |
| 10761 | return new (Context) |
| 10762 | OMPDistScheduleClause(StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc, |
Alexey Bataev | 3392d76 | 2016-02-16 11:18:12 +0000 | [diff] [blame] | 10763 | Kind, ValExpr, HelperValStmt); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 10764 | } |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10765 | |
| 10766 | OMPClause *Sema::ActOnOpenMPDefaultmapClause( |
| 10767 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 10768 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 10769 | SourceLocation KindLoc, SourceLocation EndLoc) { |
| 10770 | // OpenMP 4.5 only supports 'defaultmap(tofrom: scalar)' |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10771 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom || Kind != OMPC_DEFAULTMAP_scalar) { |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10772 | std::string Value; |
| 10773 | SourceLocation Loc; |
| 10774 | Value += "'"; |
| 10775 | if (M != OMPC_DEFAULTMAP_MODIFIER_tofrom) { |
| 10776 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10777 | OMPC_DEFAULTMAP_MODIFIER_tofrom); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10778 | Loc = MLoc; |
| 10779 | } else { |
| 10780 | Value += getOpenMPSimpleClauseTypeName(OMPC_defaultmap, |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10781 | OMPC_DEFAULTMAP_scalar); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 10782 | Loc = KindLoc; |
| 10783 | } |
| 10784 | Value += "'"; |
| 10785 | Diag(Loc, diag::err_omp_unexpected_clause_value) |
| 10786 | << Value << getOpenMPClauseName(OMPC_defaultmap); |
| 10787 | return nullptr; |
| 10788 | } |
| 10789 | |
| 10790 | return new (Context) |
| 10791 | OMPDefaultmapClause(StartLoc, LParenLoc, MLoc, KindLoc, EndLoc, Kind, M); |
| 10792 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10793 | |
| 10794 | bool Sema::ActOnStartOpenMPDeclareTargetDirective(SourceLocation Loc) { |
| 10795 | DeclContext *CurLexicalContext = getCurLexicalContext(); |
| 10796 | if (!CurLexicalContext->isFileContext() && |
| 10797 | !CurLexicalContext->isExternCContext() && |
| 10798 | !CurLexicalContext->isExternCXXContext()) { |
| 10799 | Diag(Loc, diag::err_omp_region_not_file_context); |
| 10800 | return false; |
| 10801 | } |
| 10802 | if (IsInOpenMPDeclareTargetContext) { |
| 10803 | Diag(Loc, diag::err_omp_enclosed_declare_target); |
| 10804 | return false; |
| 10805 | } |
| 10806 | |
| 10807 | IsInOpenMPDeclareTargetContext = true; |
| 10808 | return true; |
| 10809 | } |
| 10810 | |
| 10811 | void Sema::ActOnFinishOpenMPDeclareTargetDirective() { |
| 10812 | assert(IsInOpenMPDeclareTargetContext && |
| 10813 | "Unexpected ActOnFinishOpenMPDeclareTargetDirective"); |
| 10814 | |
| 10815 | IsInOpenMPDeclareTargetContext = false; |
| 10816 | } |
| 10817 | |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 10818 | void Sema::ActOnOpenMPDeclareTargetName(Scope *CurScope, |
| 10819 | CXXScopeSpec &ScopeSpec, |
| 10820 | const DeclarationNameInfo &Id, |
| 10821 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 10822 | NamedDeclSetType &SameDirectiveDecls) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10823 | LookupResult Lookup(*this, Id, LookupOrdinaryName); |
| 10824 | LookupParsedName(Lookup, CurScope, &ScopeSpec, true); |
| 10825 | |
| 10826 | if (Lookup.isAmbiguous()) |
| 10827 | return; |
| 10828 | Lookup.suppressDiagnostics(); |
| 10829 | |
| 10830 | if (!Lookup.isSingleResult()) { |
| 10831 | if (TypoCorrection Corrected = |
| 10832 | CorrectTypo(Id, LookupOrdinaryName, CurScope, nullptr, |
| 10833 | llvm::make_unique<VarOrFuncDeclFilterCCC>(*this), |
| 10834 | CTK_ErrorRecovery)) { |
| 10835 | diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest) |
| 10836 | << Id.getName()); |
| 10837 | checkDeclIsAllowedInOpenMPTarget(nullptr, Corrected.getCorrectionDecl()); |
| 10838 | return; |
| 10839 | } |
| 10840 | |
| 10841 | Diag(Id.getLoc(), diag::err_undeclared_var_use) << Id.getName(); |
| 10842 | return; |
| 10843 | } |
| 10844 | |
| 10845 | NamedDecl *ND = Lookup.getAsSingle<NamedDecl>(); |
| 10846 | if (isa<VarDecl>(ND) || isa<FunctionDecl>(ND)) { |
| 10847 | if (!SameDirectiveDecls.insert(cast<NamedDecl>(ND->getCanonicalDecl()))) |
| 10848 | Diag(Id.getLoc(), diag::err_omp_declare_target_multiple) << Id.getName(); |
| 10849 | |
| 10850 | if (!ND->hasAttr<OMPDeclareTargetDeclAttr>()) { |
| 10851 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit(Context, MT); |
| 10852 | ND->addAttr(A); |
| 10853 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
| 10854 | ML->DeclarationMarkedOpenMPDeclareTarget(ND, A); |
| 10855 | checkDeclIsAllowedInOpenMPTarget(nullptr, ND); |
| 10856 | } else if (ND->getAttr<OMPDeclareTargetDeclAttr>()->getMapType() != MT) { |
| 10857 | Diag(Id.getLoc(), diag::err_omp_declare_target_to_and_link) |
| 10858 | << Id.getName(); |
| 10859 | } |
| 10860 | } else |
| 10861 | Diag(Id.getLoc(), diag::err_omp_invalid_target_decl) << Id.getName(); |
| 10862 | } |
| 10863 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10864 | static void checkDeclInTargetContext(SourceLocation SL, SourceRange SR, |
| 10865 | Sema &SemaRef, Decl *D) { |
| 10866 | if (!D) |
| 10867 | return; |
| 10868 | Decl *LD = nullptr; |
| 10869 | if (isa<TagDecl>(D)) { |
| 10870 | LD = cast<TagDecl>(D)->getDefinition(); |
| 10871 | } else if (isa<VarDecl>(D)) { |
| 10872 | LD = cast<VarDecl>(D)->getDefinition(); |
| 10873 | |
| 10874 | // If this is an implicit variable that is legal and we do not need to do |
| 10875 | // anything. |
| 10876 | if (cast<VarDecl>(D)->isImplicit()) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10877 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10878 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10879 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10880 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10881 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10882 | return; |
| 10883 | } |
| 10884 | |
| 10885 | } else if (isa<FunctionDecl>(D)) { |
| 10886 | const FunctionDecl *FD = nullptr; |
| 10887 | if (cast<FunctionDecl>(D)->hasBody(FD)) |
| 10888 | LD = const_cast<FunctionDecl *>(FD); |
| 10889 | |
| 10890 | // If the definition is associated with the current declaration in the |
| 10891 | // target region (it can be e.g. a lambda) that is legal and we do not need |
| 10892 | // to do anything else. |
| 10893 | if (LD == D) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10894 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10895 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10896 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10897 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10898 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10899 | return; |
| 10900 | } |
| 10901 | } |
| 10902 | if (!LD) |
| 10903 | LD = D; |
| 10904 | if (LD && !LD->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 10905 | (isa<VarDecl>(LD) || isa<FunctionDecl>(LD))) { |
| 10906 | // Outlined declaration is not declared target. |
| 10907 | if (LD->isOutOfLine()) { |
| 10908 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 10909 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 10910 | } else { |
| 10911 | DeclContext *DC = LD->getDeclContext(); |
| 10912 | while (DC) { |
| 10913 | if (isa<FunctionDecl>(DC) && |
| 10914 | cast<FunctionDecl>(DC)->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 10915 | break; |
| 10916 | DC = DC->getParent(); |
| 10917 | } |
| 10918 | if (DC) |
| 10919 | return; |
| 10920 | |
| 10921 | // Is not declared in target context. |
| 10922 | SemaRef.Diag(LD->getLocation(), diag::warn_omp_not_in_target_context); |
| 10923 | SemaRef.Diag(SL, diag::note_used_here) << SR; |
| 10924 | } |
| 10925 | // Mark decl as declared target to prevent further diagnostic. |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10926 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10927 | SemaRef.Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10928 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10929 | if (ASTMutationListener *ML = SemaRef.Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10930 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10931 | } |
| 10932 | } |
| 10933 | |
| 10934 | static bool checkValueDeclInTarget(SourceLocation SL, SourceRange SR, |
| 10935 | Sema &SemaRef, DSAStackTy *Stack, |
| 10936 | ValueDecl *VD) { |
| 10937 | if (VD->hasAttr<OMPDeclareTargetDeclAttr>()) |
| 10938 | return true; |
| 10939 | if (!CheckTypeMappable(SL, SR, SemaRef, Stack, VD->getType())) |
| 10940 | return false; |
| 10941 | return true; |
| 10942 | } |
| 10943 | |
| 10944 | void Sema::checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D) { |
| 10945 | if (!D || D->isInvalidDecl()) |
| 10946 | return; |
| 10947 | SourceRange SR = E ? E->getSourceRange() : D->getSourceRange(); |
| 10948 | SourceLocation SL = E ? E->getLocStart() : D->getLocation(); |
| 10949 | // 2.10.6: threadprivate variable cannot appear in a declare target directive. |
| 10950 | if (VarDecl *VD = dyn_cast<VarDecl>(D)) { |
| 10951 | if (DSAStack->isThreadPrivate(VD)) { |
| 10952 | Diag(SL, diag::err_omp_threadprivate_in_target); |
| 10953 | ReportOriginalDSA(*this, DSAStack, VD, DSAStack->getTopDSA(VD, false)); |
| 10954 | return; |
| 10955 | } |
| 10956 | } |
| 10957 | if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) { |
| 10958 | // Problem if any with var declared with incomplete type will be reported |
| 10959 | // as normal, so no need to check it here. |
| 10960 | if ((E || !VD->getType()->isIncompleteType()) && |
| 10961 | !checkValueDeclInTarget(SL, SR, *this, DSAStack, VD)) { |
| 10962 | // Mark decl as declared target to prevent further diagnostic. |
| 10963 | if (isa<VarDecl>(VD) || isa<FunctionDecl>(VD)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10964 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10965 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10966 | VD->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10967 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10968 | ML->DeclarationMarkedOpenMPDeclareTarget(VD, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10969 | } |
| 10970 | return; |
| 10971 | } |
| 10972 | } |
| 10973 | if (!E) { |
| 10974 | // Checking declaration inside declare target region. |
| 10975 | if (!D->hasAttr<OMPDeclareTargetDeclAttr>() && |
| 10976 | (isa<VarDecl>(D) || isa<FunctionDecl>(D))) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10977 | Attr *A = OMPDeclareTargetDeclAttr::CreateImplicit( |
| 10978 | Context, OMPDeclareTargetDeclAttr::MT_To); |
| 10979 | D->addAttr(A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10980 | if (ASTMutationListener *ML = Context.getASTMutationListener()) |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 10981 | ML->DeclarationMarkedOpenMPDeclareTarget(D, A); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 10982 | } |
| 10983 | return; |
| 10984 | } |
| 10985 | checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); |
| 10986 | } |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 10987 | |
| 10988 | OMPClause *Sema::ActOnOpenMPToClause(ArrayRef<Expr *> VarList, |
| 10989 | SourceLocation StartLoc, |
| 10990 | SourceLocation LParenLoc, |
| 10991 | SourceLocation EndLoc) { |
| 10992 | MappableVarListInfo MVLI(VarList); |
| 10993 | checkMappableExpressionList(*this, DSAStack, OMPC_to, MVLI, StartLoc); |
| 10994 | if (MVLI.ProcessedVarList.empty()) |
| 10995 | return nullptr; |
| 10996 | |
| 10997 | return OMPToClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 10998 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 10999 | MVLI.VarComponents); |
| 11000 | } |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 11001 | |
| 11002 | OMPClause *Sema::ActOnOpenMPFromClause(ArrayRef<Expr *> VarList, |
| 11003 | SourceLocation StartLoc, |
| 11004 | SourceLocation LParenLoc, |
| 11005 | SourceLocation EndLoc) { |
| 11006 | MappableVarListInfo MVLI(VarList); |
| 11007 | checkMappableExpressionList(*this, DSAStack, OMPC_from, MVLI, StartLoc); |
| 11008 | if (MVLI.ProcessedVarList.empty()) |
| 11009 | return nullptr; |
| 11010 | |
| 11011 | return OMPFromClause::Create(Context, StartLoc, LParenLoc, EndLoc, |
| 11012 | MVLI.ProcessedVarList, MVLI.VarBaseDeclarations, |
| 11013 | MVLI.VarComponents); |
| 11014 | } |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11015 | |
| 11016 | OMPClause *Sema::ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11017 | SourceLocation StartLoc, |
| 11018 | SourceLocation LParenLoc, |
| 11019 | SourceLocation EndLoc) { |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11020 | MappableVarListInfo MVLI(VarList); |
| 11021 | SmallVector<Expr *, 8> PrivateCopies; |
| 11022 | SmallVector<Expr *, 8> Inits; |
| 11023 | |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11024 | for (auto &RefExpr : VarList) { |
| 11025 | assert(RefExpr && "NULL expr in OpenMP use_device_ptr clause."); |
| 11026 | SourceLocation ELoc; |
| 11027 | SourceRange ERange; |
| 11028 | Expr *SimpleRefExpr = RefExpr; |
| 11029 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11030 | if (Res.second) { |
| 11031 | // It will be analyzed later. |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11032 | MVLI.ProcessedVarList.push_back(RefExpr); |
| 11033 | PrivateCopies.push_back(nullptr); |
| 11034 | Inits.push_back(nullptr); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11035 | } |
| 11036 | ValueDecl *D = Res.first; |
| 11037 | if (!D) |
| 11038 | continue; |
| 11039 | |
| 11040 | QualType Type = D->getType(); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11041 | Type = Type.getNonReferenceType().getUnqualifiedType(); |
| 11042 | |
| 11043 | auto *VD = dyn_cast<VarDecl>(D); |
| 11044 | |
| 11045 | // Item should be a pointer or reference to pointer. |
| 11046 | if (!Type->isPointerType()) { |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11047 | Diag(ELoc, diag::err_omp_usedeviceptr_not_a_pointer) |
| 11048 | << 0 << RefExpr->getSourceRange(); |
| 11049 | continue; |
| 11050 | } |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11051 | |
| 11052 | // Build the private variable and the expression that refers to it. |
| 11053 | auto VDPrivate = buildVarDecl(*this, ELoc, Type, D->getName(), |
| 11054 | D->hasAttrs() ? &D->getAttrs() : nullptr); |
| 11055 | if (VDPrivate->isInvalidDecl()) |
| 11056 | continue; |
| 11057 | |
| 11058 | CurContext->addDecl(VDPrivate); |
| 11059 | auto VDPrivateRefExpr = buildDeclRefExpr( |
| 11060 | *this, VDPrivate, RefExpr->getType().getUnqualifiedType(), ELoc); |
| 11061 | |
| 11062 | // Add temporary variable to initialize the private copy of the pointer. |
| 11063 | auto *VDInit = |
| 11064 | buildVarDecl(*this, RefExpr->getExprLoc(), Type, ".devptr.temp"); |
| 11065 | auto *VDInitRefExpr = buildDeclRefExpr(*this, VDInit, RefExpr->getType(), |
| 11066 | RefExpr->getExprLoc()); |
| 11067 | AddInitializerToDecl(VDPrivate, |
| 11068 | DefaultLvalueConversion(VDInitRefExpr).get(), |
Richard Smith | 3beb7c6 | 2017-01-12 02:27:38 +0000 | [diff] [blame] | 11069 | /*DirectInit=*/false); |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11070 | |
| 11071 | // If required, build a capture to implement the privatization initialized |
| 11072 | // with the current list item value. |
| 11073 | DeclRefExpr *Ref = nullptr; |
| 11074 | if (!VD) |
| 11075 | Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/true); |
| 11076 | MVLI.ProcessedVarList.push_back(VD ? RefExpr->IgnoreParens() : Ref); |
| 11077 | PrivateCopies.push_back(VDPrivateRefExpr); |
| 11078 | Inits.push_back(VDInitRefExpr); |
| 11079 | |
| 11080 | // We need to add a data sharing attribute for this variable to make sure it |
| 11081 | // is correctly captured. A variable that shows up in a use_device_ptr has |
| 11082 | // similar properties of a first private variable. |
| 11083 | DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_firstprivate, Ref); |
| 11084 | |
| 11085 | // Create a mappable component for the list item. List items in this clause |
| 11086 | // only need a component. |
| 11087 | MVLI.VarBaseDeclarations.push_back(D); |
| 11088 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11089 | MVLI.VarComponents.back().push_back( |
| 11090 | OMPClauseMappableExprCommon::MappableComponent(SimpleRefExpr, D)); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11091 | } |
| 11092 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11093 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11094 | return nullptr; |
| 11095 | |
Samuel Antao | cc10b85 | 2016-07-28 14:23:26 +0000 | [diff] [blame] | 11096 | return OMPUseDevicePtrClause::Create( |
| 11097 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11098 | PrivateCopies, Inits, MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 11099 | } |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11100 | |
| 11101 | OMPClause *Sema::ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 11102 | SourceLocation StartLoc, |
| 11103 | SourceLocation LParenLoc, |
| 11104 | SourceLocation EndLoc) { |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11105 | MappableVarListInfo MVLI(VarList); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11106 | for (auto &RefExpr : VarList) { |
Kelvin Li | 8437625 | 2016-12-14 15:39:58 +0000 | [diff] [blame] | 11107 | assert(RefExpr && "NULL expr in OpenMP is_device_ptr clause."); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11108 | SourceLocation ELoc; |
| 11109 | SourceRange ERange; |
| 11110 | Expr *SimpleRefExpr = RefExpr; |
| 11111 | auto Res = getPrivateItem(*this, SimpleRefExpr, ELoc, ERange); |
| 11112 | if (Res.second) { |
| 11113 | // It will be analyzed later. |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11114 | MVLI.ProcessedVarList.push_back(RefExpr); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11115 | } |
| 11116 | ValueDecl *D = Res.first; |
| 11117 | if (!D) |
| 11118 | continue; |
| 11119 | |
| 11120 | QualType Type = D->getType(); |
| 11121 | // item should be a pointer or array or reference to pointer or array |
| 11122 | if (!Type.getNonReferenceType()->isPointerType() && |
| 11123 | !Type.getNonReferenceType()->isArrayType()) { |
| 11124 | Diag(ELoc, diag::err_omp_argument_type_isdeviceptr) |
| 11125 | << 0 << RefExpr->getSourceRange(); |
| 11126 | continue; |
| 11127 | } |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11128 | |
| 11129 | // Check if the declaration in the clause does not show up in any data |
| 11130 | // sharing attribute. |
| 11131 | auto DVar = DSAStack->getTopDSA(D, false); |
| 11132 | if (isOpenMPPrivate(DVar.CKind)) { |
| 11133 | Diag(ELoc, diag::err_omp_variable_in_given_clause_and_dsa) |
| 11134 | << getOpenMPClauseName(DVar.CKind) |
| 11135 | << getOpenMPClauseName(OMPC_is_device_ptr) |
| 11136 | << getOpenMPDirectiveName(DSAStack->getCurrentDirective()); |
| 11137 | ReportOriginalDSA(*this, DSAStack, D, DVar); |
| 11138 | continue; |
| 11139 | } |
| 11140 | |
| 11141 | Expr *ConflictExpr; |
| 11142 | if (DSAStack->checkMappableExprComponentListsForDecl( |
David Majnemer | 9d16822 | 2016-08-05 17:44:54 +0000 | [diff] [blame] | 11143 | D, /*CurrentRegionOnly=*/true, |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11144 | [&ConflictExpr]( |
| 11145 | OMPClauseMappableExprCommon::MappableExprComponentListRef R, |
| 11146 | OpenMPClauseKind) -> bool { |
| 11147 | ConflictExpr = R.front().getAssociatedExpression(); |
| 11148 | return true; |
| 11149 | })) { |
| 11150 | Diag(ELoc, diag::err_omp_map_shared_storage) << RefExpr->getSourceRange(); |
| 11151 | Diag(ConflictExpr->getExprLoc(), diag::note_used_here) |
| 11152 | << ConflictExpr->getSourceRange(); |
| 11153 | continue; |
| 11154 | } |
| 11155 | |
| 11156 | // Store the components in the stack so that they can be used to check |
| 11157 | // against other clauses later on. |
| 11158 | OMPClauseMappableExprCommon::MappableComponent MC(SimpleRefExpr, D); |
| 11159 | DSAStack->addMappableExpressionComponents( |
| 11160 | D, MC, /*WhereFoundClauseKind=*/OMPC_is_device_ptr); |
| 11161 | |
| 11162 | // Record the expression we've just processed. |
| 11163 | MVLI.ProcessedVarList.push_back(SimpleRefExpr); |
| 11164 | |
| 11165 | // Create a mappable component for the list item. List items in this clause |
| 11166 | // only need a component. We use a null declaration to signal fields in |
| 11167 | // 'this'. |
| 11168 | assert((isa<DeclRefExpr>(SimpleRefExpr) || |
| 11169 | isa<CXXThisExpr>(cast<MemberExpr>(SimpleRefExpr)->getBase())) && |
| 11170 | "Unexpected device pointer expression!"); |
| 11171 | MVLI.VarBaseDeclarations.push_back( |
| 11172 | isa<DeclRefExpr>(SimpleRefExpr) ? D : nullptr); |
| 11173 | MVLI.VarComponents.resize(MVLI.VarComponents.size() + 1); |
| 11174 | MVLI.VarComponents.back().push_back(MC); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11175 | } |
| 11176 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11177 | if (MVLI.ProcessedVarList.empty()) |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11178 | return nullptr; |
| 11179 | |
Samuel Antao | 6890b09 | 2016-07-28 14:25:09 +0000 | [diff] [blame] | 11180 | return OMPIsDevicePtrClause::Create( |
| 11181 | Context, StartLoc, LParenLoc, EndLoc, MVLI.ProcessedVarList, |
| 11182 | MVLI.VarBaseDeclarations, MVLI.VarComponents); |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 11183 | } |