Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 1 | //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 5b12ab8 | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Stmt class and statement subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTDiagnostic.h" |
Chris Lattner | 2937565 | 2006-12-04 18:06:35 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprCXX.h" |
Steve Naroff | 021ca18 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprObjC.h" |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame^] | 18 | #include "clang/AST/ExprOpenMP.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 19 | #include "clang/AST/Stmt.h" |
Chris Lattner | f0b64d7 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 20 | #include "clang/AST/StmtCXX.h" |
| 21 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 22 | #include "clang/AST/StmtOpenMP.h" |
Sebastian Redl | 54c04d4 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 23 | #include "clang/AST/Type.h" |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 24 | #include "clang/Basic/CharInfo.h" |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 25 | #include "clang/Basic/TargetInfo.h" |
Benjamin Kramer | 444a130 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 26 | #include "clang/Lex/Token.h" |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 27 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | f42cce7 | 2006-10-25 04:09:21 +0000 | [diff] [blame] | 29 | using namespace clang; |
| 30 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 31 | static struct StmtClassNameTable { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 32 | const char *Name; |
| 33 | unsigned Counter; |
| 34 | unsigned Size; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 35 | } StmtClassInfo[Stmt::lastStmtConstant+1]; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 36 | |
| 37 | static StmtClassNameTable &getStmtInfoTableEntry(Stmt::StmtClass E) { |
| 38 | static bool Initialized = false; |
| 39 | if (Initialized) |
| 40 | return StmtClassInfo[E]; |
| 41 | |
| 42 | // Intialize the table on the first use. |
| 43 | Initialized = true; |
Alexis Hunt | abb2ac8 | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 44 | #define ABSTRACT_STMT(STMT) |
Douglas Gregor | be35ce9 | 2008-11-14 12:46:07 +0000 | [diff] [blame] | 45 | #define STMT(CLASS, PARENT) \ |
| 46 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Name = #CLASS; \ |
| 47 | StmtClassInfo[(unsigned)Stmt::CLASS##Class].Size = sizeof(CLASS); |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 48 | #include "clang/AST/StmtNodes.inc" |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 49 | |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 50 | return StmtClassInfo[E]; |
| 51 | } |
| 52 | |
Craig Topper | 3793291 | 2013-08-18 10:09:15 +0000 | [diff] [blame] | 53 | void *Stmt::operator new(size_t bytes, const ASTContext& C, |
Craig Topper | 5a05001 | 2013-08-18 17:45:38 +0000 | [diff] [blame] | 54 | unsigned alignment) { |
Benjamin Kramer | ea70eb3 | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 55 | return ::operator new(bytes, C, alignment); |
| 56 | } |
| 57 | |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 58 | const char *Stmt::getStmtClassName() const { |
John McCall | 925b1662 | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 59 | return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; |
Steve Naroff | f1e5369 | 2007-03-23 22:27:02 +0000 | [diff] [blame] | 60 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 61 | |
| 62 | void Stmt::PrintStats() { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 63 | // Ensure the table is primed. |
| 64 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 65 | |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 66 | unsigned sum = 0; |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 67 | llvm::errs() << "\n*** Stmt/Expr Stats:\n"; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 68 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 69 | if (StmtClassInfo[i].Name == nullptr) continue; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 70 | sum += StmtClassInfo[i].Counter; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 71 | } |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 72 | llvm::errs() << " " << sum << " stmts/exprs total.\n"; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 73 | sum = 0; |
Alexis Hunt | 656bb31 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 74 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 75 | if (StmtClassInfo[i].Name == nullptr) continue; |
Douglas Gregor | a30d046 | 2009-05-26 14:40:08 +0000 | [diff] [blame] | 76 | if (StmtClassInfo[i].Counter == 0) continue; |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 77 | llvm::errs() << " " << StmtClassInfo[i].Counter << " " |
| 78 | << StmtClassInfo[i].Name << ", " << StmtClassInfo[i].Size |
| 79 | << " each (" << StmtClassInfo[i].Counter*StmtClassInfo[i].Size |
| 80 | << " bytes)\n"; |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 81 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 82 | } |
Chandler Carruth | bfb154a | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 83 | |
| 84 | llvm::errs() << "Total bytes = " << sum << "\n"; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 4d15a0d | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 88 | ++getStmtInfoTableEntry(s).Counter; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Daniel Dunbar | 6290557 | 2012-03-05 21:42:49 +0000 | [diff] [blame] | 91 | bool Stmt::StatisticsEnabled = false; |
| 92 | void Stmt::EnableStatistics() { |
| 93 | StatisticsEnabled = true; |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 94 | } |
| 95 | |
John McCall | 4db5c3c | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 96 | Stmt *Stmt::IgnoreImplicit() { |
| 97 | Stmt *s = this; |
| 98 | |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 99 | if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) |
John McCall | 4db5c3c | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 100 | s = ewc->getSubExpr(); |
| 101 | |
Richard Smith | 520449d | 2015-02-05 06:15:50 +0000 | [diff] [blame] | 102 | if (auto *mte = dyn_cast<MaterializeTemporaryExpr>(s)) |
| 103 | s = mte->GetTemporaryExpr(); |
| 104 | |
| 105 | if (auto *bte = dyn_cast<CXXBindTemporaryExpr>(s)) |
| 106 | s = bte->getSubExpr(); |
| 107 | |
| 108 | while (auto *ice = dyn_cast<ImplicitCastExpr>(s)) |
John McCall | 4db5c3c | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 109 | s = ice->getSubExpr(); |
| 110 | |
| 111 | return s; |
| 112 | } |
| 113 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 114 | /// \brief Skip no-op (attributed, compound) container stmts and skip captured |
| 115 | /// stmt at the top, if \a IgnoreCaptured is true. |
| 116 | Stmt *Stmt::IgnoreContainers(bool IgnoreCaptured) { |
| 117 | Stmt *S = this; |
| 118 | if (IgnoreCaptured) |
| 119 | if (auto CapS = dyn_cast_or_null<CapturedStmt>(S)) |
| 120 | S = CapS->getCapturedStmt(); |
| 121 | while (true) { |
| 122 | if (auto AS = dyn_cast_or_null<AttributedStmt>(S)) |
| 123 | S = AS->getSubStmt(); |
| 124 | else if (auto CS = dyn_cast_or_null<CompoundStmt>(S)) { |
| 125 | if (CS->size() != 1) |
| 126 | break; |
| 127 | S = CS->body_back(); |
| 128 | } else |
| 129 | break; |
| 130 | } |
| 131 | return S; |
| 132 | } |
| 133 | |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 134 | /// \brief Strip off all label-like statements. |
| 135 | /// |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 136 | /// This will strip off label statements, case statements, attributed |
| 137 | /// statements and default statements recursively. |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 138 | const Stmt *Stmt::stripLabelLikeStatements() const { |
| 139 | const Stmt *S = this; |
| 140 | while (true) { |
| 141 | if (const LabelStmt *LS = dyn_cast<LabelStmt>(S)) |
| 142 | S = LS->getSubStmt(); |
| 143 | else if (const SwitchCase *SC = dyn_cast<SwitchCase>(S)) |
| 144 | S = SC->getSubStmt(); |
Richard Smith | c202b28 | 2012-04-14 00:33:13 +0000 | [diff] [blame] | 145 | else if (const AttributedStmt *AS = dyn_cast<AttributedStmt>(S)) |
| 146 | S = AS->getSubStmt(); |
Chandler Carruth | a626d64 | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 147 | else |
| 148 | return S; |
| 149 | } |
| 150 | } |
| 151 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 152 | namespace { |
| 153 | struct good {}; |
| 154 | struct bad {}; |
John McCall | f75152f | 2011-02-09 08:31:17 +0000 | [diff] [blame] | 155 | |
| 156 | // These silly little functions have to be static inline to suppress |
| 157 | // unused warnings, and they have to be defined to suppress other |
| 158 | // warnings. |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 159 | static inline good is_good(good) { return good(); } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 160 | |
| 161 | typedef Stmt::child_range children_t(); |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 162 | template <class T> good implements_children(children_t T::*) { |
| 163 | return good(); |
| 164 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 165 | LLVM_ATTRIBUTE_UNUSED |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 166 | static inline bad implements_children(children_t Stmt::*) { |
| 167 | return bad(); |
| 168 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 169 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 170 | typedef SourceLocation getLocStart_t() const; |
| 171 | template <class T> good implements_getLocStart(getLocStart_t T::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 172 | return good(); |
| 173 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 174 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 175 | static inline bad implements_getLocStart(getLocStart_t Stmt::*) { |
| 176 | return bad(); |
| 177 | } |
| 178 | |
| 179 | typedef SourceLocation getLocEnd_t() const; |
| 180 | template <class T> good implements_getLocEnd(getLocEnd_t T::*) { |
| 181 | return good(); |
| 182 | } |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 183 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 184 | static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { |
Nick Lewycky | bae992f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 185 | return bad(); |
| 186 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 187 | |
| 188 | #define ASSERT_IMPLEMENTS_children(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 189 | (void) is_good(implements_children(&type::children)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 190 | #define ASSERT_IMPLEMENTS_getLocStart(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 191 | (void) is_good(implements_getLocStart(&type::getLocStart)) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 192 | #define ASSERT_IMPLEMENTS_getLocEnd(type) \ |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 193 | (void) is_good(implements_getLocEnd(&type::getLocEnd)) |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 194 | } |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 195 | |
| 196 | /// Check whether the various Stmt classes implement their member |
| 197 | /// functions. |
Eli Friedman | dc41d79 | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 198 | LLVM_ATTRIBUTE_UNUSED |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 199 | static inline void check_implementations() { |
| 200 | #define ABSTRACT_STMT(type) |
| 201 | #define STMT(type, base) \ |
| 202 | ASSERT_IMPLEMENTS_children(type); \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 203 | ASSERT_IMPLEMENTS_getLocStart(type); \ |
| 204 | ASSERT_IMPLEMENTS_getLocEnd(type); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 205 | #include "clang/AST/StmtNodes.inc" |
| 206 | } |
| 207 | |
| 208 | Stmt::child_range Stmt::children() { |
| 209 | switch (getStmtClass()) { |
| 210 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 211 | #define ABSTRACT_STMT(type) |
| 212 | #define STMT(type, base) \ |
| 213 | case Stmt::type##Class: \ |
| 214 | return static_cast<type*>(this)->children(); |
| 215 | #include "clang/AST/StmtNodes.inc" |
| 216 | } |
| 217 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 218 | } |
| 219 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 220 | // Amusing macro metaprogramming hack: check whether a class provides |
| 221 | // a more specific implementation of getSourceRange. |
| 222 | // |
| 223 | // See also Expr.cpp:getExprLoc(). |
| 224 | namespace { |
| 225 | /// This implementation is used when a class provides a custom |
| 226 | /// implementation of getSourceRange. |
| 227 | template <class S, class T> |
| 228 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 229 | SourceRange (T::*v)() const) { |
| 230 | return static_cast<const S*>(stmt)->getSourceRange(); |
| 231 | } |
| 232 | |
| 233 | /// This implementation is used when a class doesn't provide a custom |
| 234 | /// implementation of getSourceRange. Overload resolution should pick it over |
| 235 | /// the implementation above because it's more specialized according to |
| 236 | /// function template partial ordering. |
| 237 | template <class S> |
| 238 | SourceRange getSourceRangeImpl(const Stmt *stmt, |
| 239 | SourceRange (Stmt::*v)() const) { |
| 240 | return SourceRange(static_cast<const S*>(stmt)->getLocStart(), |
| 241 | static_cast<const S*>(stmt)->getLocEnd()); |
| 242 | } |
Alexander Kornienko | ab9db51 | 2015-06-22 23:07:51 +0000 | [diff] [blame] | 243 | } |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 244 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 245 | SourceRange Stmt::getSourceRange() const { |
| 246 | switch (getStmtClass()) { |
| 247 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 248 | #define ABSTRACT_STMT(type) |
| 249 | #define STMT(type, base) \ |
| 250 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 251 | return getSourceRangeImpl<type>(this, &type::getSourceRange); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 252 | #include "clang/AST/StmtNodes.inc" |
| 253 | } |
| 254 | llvm_unreachable("unknown statement kind!"); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 255 | } |
| 256 | |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 257 | SourceLocation Stmt::getLocStart() const { |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 258 | // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 259 | switch (getStmtClass()) { |
| 260 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 261 | #define ABSTRACT_STMT(type) |
| 262 | #define STMT(type, base) \ |
| 263 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 264 | return static_cast<const type*>(this)->getLocStart(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 265 | #include "clang/AST/StmtNodes.inc" |
| 266 | } |
| 267 | llvm_unreachable("unknown statement kind"); |
| 268 | } |
| 269 | |
| 270 | SourceLocation Stmt::getLocEnd() const { |
| 271 | switch (getStmtClass()) { |
| 272 | case Stmt::NoStmtClass: llvm_unreachable("statement without class"); |
| 273 | #define ABSTRACT_STMT(type) |
| 274 | #define STMT(type, base) \ |
| 275 | case Stmt::type##Class: \ |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 276 | return static_cast<const type*>(this)->getLocEnd(); |
Daniel Dunbar | b0ab5e9 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 277 | #include "clang/AST/StmtNodes.inc" |
| 278 | } |
| 279 | llvm_unreachable("unknown statement kind"); |
| 280 | } |
| 281 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 282 | CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 283 | SourceLocation LB, SourceLocation RB) |
Aaron Ballman | ce6c67e | 2014-10-22 21:06:18 +0000 | [diff] [blame] | 284 | : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) { |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 285 | CompoundStmtBits.NumStmts = Stmts.size(); |
| 286 | assert(CompoundStmtBits.NumStmts == Stmts.size() && |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 287 | "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); |
| 288 | |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 289 | if (Stmts.size() == 0) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 290 | Body = nullptr; |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 291 | return; |
| 292 | } |
| 293 | |
Nico Weber | a2a0eb9 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 294 | Body = new (C) Stmt*[Stmts.size()]; |
| 295 | std::copy(Stmts.begin(), Stmts.end(), Body); |
Benjamin Kramer | e2a929d | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 298 | void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, |
| 299 | unsigned NumStmts) { |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 300 | if (this->Body) |
| 301 | C.Deallocate(Body); |
John McCall | 925b1662 | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 302 | this->CompoundStmtBits.NumStmts = NumStmts; |
Douglas Gregor | a9af1d1 | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 303 | |
| 304 | Body = new (C) Stmt*[NumStmts]; |
| 305 | memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); |
| 306 | } |
Steve Naroff | f84d11f | 2007-05-23 21:48:04 +0000 | [diff] [blame] | 307 | |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 308 | const char *LabelStmt::getName() const { |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 309 | return getDecl()->getIdentifier()->getNameStart(); |
Chris Lattner | eefa10e | 2007-05-28 06:56:27 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 312 | AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 313 | ArrayRef<const Attr*> Attrs, |
| 314 | Stmt *SubStmt) { |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 315 | assert(!Attrs.empty() && "Attrs should not be empty"); |
| 316 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 317 | llvm::alignOf<AttributedStmt>()); |
| 318 | return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); |
| 319 | } |
| 320 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 321 | AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, |
| 322 | unsigned NumAttrs) { |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 323 | assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); |
Aaron Ballman | f3d9b09 | 2014-05-13 14:55:01 +0000 | [diff] [blame] | 324 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, |
Alexander Kornienko | 20f6fc6 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 325 | llvm::alignOf<AttributedStmt>()); |
| 326 | return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); |
| 327 | } |
| 328 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 329 | std::string AsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 330 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 331 | return gccAsmStmt->generateAsmString(C); |
| 332 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 333 | return msAsmStmt->generateAsmString(C); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 334 | llvm_unreachable("unknown asm statement kind!"); |
| 335 | } |
| 336 | |
| 337 | StringRef AsmStmt::getOutputConstraint(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 338 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 339 | return gccAsmStmt->getOutputConstraint(i); |
| 340 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 341 | return msAsmStmt->getOutputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 342 | llvm_unreachable("unknown asm statement kind!"); |
| 343 | } |
| 344 | |
| 345 | const Expr *AsmStmt::getOutputExpr(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 346 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 347 | return gccAsmStmt->getOutputExpr(i); |
| 348 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 349 | return msAsmStmt->getOutputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 350 | llvm_unreachable("unknown asm statement kind!"); |
| 351 | } |
| 352 | |
| 353 | StringRef AsmStmt::getInputConstraint(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 354 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 355 | return gccAsmStmt->getInputConstraint(i); |
| 356 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 357 | return msAsmStmt->getInputConstraint(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 358 | llvm_unreachable("unknown asm statement kind!"); |
| 359 | } |
| 360 | |
| 361 | const Expr *AsmStmt::getInputExpr(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 362 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 363 | return gccAsmStmt->getInputExpr(i); |
| 364 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 365 | return msAsmStmt->getInputExpr(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 366 | llvm_unreachable("unknown asm statement kind!"); |
| 367 | } |
| 368 | |
| 369 | StringRef AsmStmt::getClobber(unsigned i) const { |
Chad Rosier | f70b7e2 | 2012-08-28 18:21:14 +0000 | [diff] [blame] | 370 | if (const GCCAsmStmt *gccAsmStmt = dyn_cast<GCCAsmStmt>(this)) |
| 371 | return gccAsmStmt->getClobber(i); |
| 372 | if (const MSAsmStmt *msAsmStmt = dyn_cast<MSAsmStmt>(this)) |
| 373 | return msAsmStmt->getClobber(i); |
Chad Rosier | bbbe9ab | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 374 | llvm_unreachable("unknown asm statement kind!"); |
| 375 | } |
| 376 | |
Chad Rosier | a1b5c8c | 2012-08-28 00:24:05 +0000 | [diff] [blame] | 377 | /// getNumPlusOperands - Return the number of output operands that have a "+" |
| 378 | /// constraint. |
| 379 | unsigned AsmStmt::getNumPlusOperands() const { |
| 380 | unsigned Res = 0; |
| 381 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) |
| 382 | if (isOutputPlusConstraint(i)) |
| 383 | ++Res; |
| 384 | return Res; |
| 385 | } |
| 386 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 387 | char GCCAsmStmt::AsmStringPiece::getModifier() const { |
| 388 | assert(isOperand() && "Only Operands can have modifiers."); |
| 389 | return isLetter(Str[0]) ? Str[0] : '\0'; |
| 390 | } |
| 391 | |
Chad Rosier | 6100ae1 | 2012-08-27 23:47:56 +0000 | [diff] [blame] | 392 | StringRef GCCAsmStmt::getClobber(unsigned i) const { |
| 393 | return getClobberStringLiteral(i)->getString(); |
| 394 | } |
| 395 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 396 | Expr *GCCAsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 397 | return cast<Expr>(Exprs[i]); |
| 398 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 399 | |
| 400 | /// getOutputConstraint - Return the constraint string for the specified |
| 401 | /// output operand. All output constraints are known to be non-empty (either |
| 402 | /// '=' or '+'). |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 403 | StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 404 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 405 | } |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 406 | |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 407 | Expr *GCCAsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 408 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 409 | } |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 410 | void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { |
Chris Lattner | 93ede02 | 2011-02-21 22:09:29 +0000 | [diff] [blame] | 411 | Exprs[i + NumOutputs] = E; |
| 412 | } |
| 413 | |
Chris Lattner | 72bbf17 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 414 | /// getInputConstraint - Return the specified input constraint. Unlike output |
| 415 | /// constraints, these can be empty. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 416 | StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { |
Anders Carlsson | 66de081 | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 417 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | 5778acf | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 420 | void GCCAsmStmt::setOutputsAndInputsAndClobbers(const ASTContext &C, |
| 421 | IdentifierInfo **Names, |
| 422 | StringLiteral **Constraints, |
| 423 | Stmt **Exprs, |
| 424 | unsigned NumOutputs, |
| 425 | unsigned NumInputs, |
| 426 | StringLiteral **Clobbers, |
| 427 | unsigned NumClobbers) { |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 428 | this->NumOutputs = NumOutputs; |
| 429 | this->NumInputs = NumInputs; |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 430 | this->NumClobbers = NumClobbers; |
| 431 | |
| 432 | unsigned NumExprs = NumOutputs + NumInputs; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 433 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 434 | C.Deallocate(this->Names); |
| 435 | this->Names = new (C) IdentifierInfo*[NumExprs]; |
| 436 | std::copy(Names, Names + NumExprs, this->Names); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 437 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 438 | C.Deallocate(this->Exprs); |
| 439 | this->Exprs = new (C) Stmt*[NumExprs]; |
| 440 | std::copy(Exprs, Exprs + NumExprs, this->Exprs); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 441 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 442 | C.Deallocate(this->Constraints); |
| 443 | this->Constraints = new (C) StringLiteral*[NumExprs]; |
| 444 | std::copy(Constraints, Constraints + NumExprs, this->Constraints); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 445 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 446 | C.Deallocate(this->Clobbers); |
| 447 | this->Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 448 | std::copy(Clobbers, Clobbers + NumClobbers, this->Clobbers); |
Douglas Gregor | f994f06 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 451 | /// getNamedOperand - Given a symbolic operand reference like %[foo], |
| 452 | /// translate this into a numeric value needed to reference the same operand. |
| 453 | /// This returns -1 if the operand name is invalid. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 454 | int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 455 | unsigned NumPlusOperands = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 456 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 457 | // Check if this is an output operand. |
| 458 | for (unsigned i = 0, e = getNumOutputs(); i != e; ++i) { |
| 459 | if (getOutputName(i) == SymbolicName) |
| 460 | return i; |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 461 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 462 | |
Chris Lattner | d7d5fdf | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 463 | for (unsigned i = 0, e = getNumInputs(); i != e; ++i) |
| 464 | if (getInputName(i) == SymbolicName) |
| 465 | return getNumOutputs() + NumPlusOperands + i; |
| 466 | |
| 467 | // Not found. |
| 468 | return -1; |
| 469 | } |
| 470 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 471 | /// AnalyzeAsmString - Analyze the asm string of the current asm, decomposing |
| 472 | /// it into pieces. If the asm string is erroneous, emit errors and return |
| 473 | /// true, otherwise return false. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 474 | unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 475 | const ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 476 | StringRef Str = getAsmString()->getString(); |
Benjamin Kramer | 35b077e | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 477 | const char *StrStart = Str.begin(); |
| 478 | const char *StrEnd = Str.end(); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 479 | const char *CurPtr = StrStart; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 481 | // "Simple" inline asms have no constraints or operands, just convert the asm |
| 482 | // string to escape $'s. |
| 483 | if (isSimple()) { |
| 484 | std::string Result; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 485 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 486 | switch (*CurPtr) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 487 | case '$': |
| 488 | Result += "$$"; |
| 489 | break; |
| 490 | default: |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 491 | Result += *CurPtr; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 492 | break; |
| 493 | } |
| 494 | } |
| 495 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 496 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | // CurStringPiece - The current string that we are building up as we scan the |
| 500 | // asm string. |
| 501 | std::string CurStringPiece; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 502 | |
Douglas Gregor | e8bbc12 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 503 | bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 504 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 505 | while (1) { |
| 506 | // Done with the string? |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 507 | if (CurPtr == StrEnd) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 508 | if (!CurStringPiece.empty()) |
| 509 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 510 | return 0; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 511 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 512 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 513 | char CurChar = *CurPtr++; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 514 | switch (CurChar) { |
| 515 | case '$': CurStringPiece += "$$"; continue; |
Chris Lattner | 1a8f394 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 516 | case '{': CurStringPiece += (HasVariants ? "$(" : "{"); continue; |
| 517 | case '|': CurStringPiece += (HasVariants ? "$|" : "|"); continue; |
| 518 | case '}': CurStringPiece += (HasVariants ? "$)" : "}"); continue; |
Chris Lattner | da081a8 | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 519 | case '%': |
| 520 | break; |
| 521 | default: |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 522 | CurStringPiece += CurChar; |
| 523 | continue; |
| 524 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 525 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 526 | // Escaped "%" character in asm string. |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 527 | if (CurPtr == StrEnd) { |
| 528 | // % at end of string is invalid (no escape). |
| 529 | DiagOffs = CurPtr-StrStart-1; |
| 530 | return diag::err_asm_invalid_escape; |
| 531 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 532 | |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 533 | char EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 534 | if (EscapedChar == '%') { // %% -> % |
| 535 | // Escaped percentage sign. |
| 536 | CurStringPiece += '%'; |
| 537 | continue; |
| 538 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 539 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 540 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 541 | CurStringPiece += "${:uid}"; |
| 542 | continue; |
| 543 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 544 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 545 | // Otherwise, we have an operand. If we have accumulated a string so far, |
| 546 | // add it to the Pieces list. |
| 547 | if (!CurStringPiece.empty()) { |
| 548 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
| 549 | CurStringPiece.clear(); |
| 550 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 552 | // Handle operands that have asmSymbolicName (e.g., %x[foo]) and those that |
| 553 | // don't (e.g., %x4). 'x' following the '%' is the constraint modifier. |
| 554 | |
| 555 | const char *Begin = CurPtr - 1; // Points to the character following '%'. |
| 556 | const char *Percent = Begin - 1; // Points to '%'. |
| 557 | |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 558 | if (isLetter(EscapedChar)) { |
Benjamin Kramer | e87c38b | 2011-07-05 11:13:37 +0000 | [diff] [blame] | 559 | if (CurPtr == StrEnd) { // Premature end. |
| 560 | DiagOffs = CurPtr-StrStart-1; |
| 561 | return diag::err_asm_invalid_escape; |
| 562 | } |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 563 | EscapedChar = *CurPtr++; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 564 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 565 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 566 | const TargetInfo &TI = C.getTargetInfo(); |
| 567 | const SourceManager &SM = C.getSourceManager(); |
| 568 | const LangOptions &LO = C.getLangOpts(); |
| 569 | |
| 570 | // Handle operands that don't have asmSymbolicName (e.g., %x4). |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 571 | if (isDigit(EscapedChar)) { |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 572 | // %n - Assembler operand n |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 573 | unsigned N = 0; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 574 | |
Chris Lattner | 99d892b | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 575 | --CurPtr; |
Jordan Rose | a7d0384 | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 576 | while (CurPtr != StrEnd && isDigit(*CurPtr)) |
Chris Lattner | 84f3afa | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 577 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 578 | |
Chris Lattner | 1431192 | 2009-03-11 00:23:13 +0000 | [diff] [blame] | 579 | unsigned NumOperands = |
| 580 | getNumOutputs() + getNumPlusOperands() + getNumInputs(); |
| 581 | if (N >= NumOperands) { |
| 582 | DiagOffs = CurPtr-StrStart-1; |
| 583 | return diag::err_asm_invalid_operand_number; |
| 584 | } |
| 585 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 586 | // Str contains "x4" (Operand without the leading %). |
| 587 | std::string Str(Begin, CurPtr - Begin); |
| 588 | |
| 589 | // (BeginLoc, EndLoc) represents the range of the operand we are currently |
| 590 | // processing. Unlike Str, the range includes the leading '%'. |
| 591 | SourceLocation BeginLoc = |
| 592 | getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); |
| 593 | SourceLocation EndLoc = |
| 594 | getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI); |
| 595 | |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 596 | Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 597 | continue; |
| 598 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 599 | |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 600 | // Handle operands that have asmSymbolicName (e.g., %x[foo]). |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 601 | if (EscapedChar == '[') { |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 602 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 603 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 604 | // Find the ']'. |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 605 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 606 | if (NameEnd == nullptr) |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 607 | return diag::err_asm_unterminated_symbolic_operand_name; |
| 608 | if (NameEnd == CurPtr) |
| 609 | return diag::err_asm_empty_symbolic_operand_name; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 610 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 611 | StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 612 | |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 613 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 614 | if (N == -1) { |
| 615 | // Verify that an operand with that name exists. |
| 616 | DiagOffs = CurPtr-StrStart; |
| 617 | return diag::err_asm_unknown_symbolic_operand_name; |
| 618 | } |
Akira Hatanaka | 987f186 | 2014-08-22 06:05:21 +0000 | [diff] [blame] | 619 | |
| 620 | // Str contains "x[foo]" (Operand without the leading %). |
| 621 | std::string Str(Begin, NameEnd + 1 - Begin); |
| 622 | |
| 623 | // (BeginLoc, EndLoc) represents the range of the operand we are currently |
| 624 | // processing. Unlike Str, the range includes the leading '%'. |
| 625 | SourceLocation BeginLoc = |
| 626 | getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); |
| 627 | SourceLocation EndLoc = |
| 628 | getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI); |
| 629 | |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 630 | Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 631 | |
Chris Lattner | 3fa25c6 | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 632 | CurPtr = NameEnd+1; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 633 | continue; |
| 634 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 635 | |
Chris Lattner | 0cdaa2e | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 636 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | a41b847 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 637 | return diag::err_asm_invalid_escape; |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 640 | |
| 641 | /// Assemble final IR asm string (GCC-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 642 | std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 643 | // Analyze the asm string to decompose it into its pieces. We know that Sema |
| 644 | // has already done this, so it is guaranteed to be successful. |
Chad Rosier | de70e0e | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 645 | SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; |
Chad Rosier | 14836ba | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 646 | unsigned DiagOffs; |
| 647 | AnalyzeAsmString(Pieces, C, DiagOffs); |
| 648 | |
| 649 | std::string AsmString; |
| 650 | for (unsigned i = 0, e = Pieces.size(); i != e; ++i) { |
| 651 | if (Pieces[i].isString()) |
| 652 | AsmString += Pieces[i].getString(); |
| 653 | else if (Pieces[i].getModifier() == '\0') |
| 654 | AsmString += '$' + llvm::utostr(Pieces[i].getOperandNo()); |
| 655 | else |
| 656 | AsmString += "${" + llvm::utostr(Pieces[i].getOperandNo()) + ':' + |
| 657 | Pieces[i].getModifier() + '}'; |
| 658 | } |
| 659 | return AsmString; |
| 660 | } |
Chris Lattner | 35b5836 | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 661 | |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 662 | /// Assemble final IR asm string (MS-style). |
Craig Topper | c571c81 | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 663 | std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 664 | // FIXME: This needs to be translated into the IR string representation. |
Chad Rosier | 0bca469 | 2012-08-28 20:33:49 +0000 | [diff] [blame] | 665 | return AsmStr; |
Chad Rosier | 3b0c260 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 668 | Expr *MSAsmStmt::getOutputExpr(unsigned i) { |
| 669 | return cast<Expr>(Exprs[i]); |
| 670 | } |
| 671 | |
| 672 | Expr *MSAsmStmt::getInputExpr(unsigned i) { |
| 673 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 674 | } |
| 675 | void MSAsmStmt::setInputExpr(unsigned i, Expr *E) { |
| 676 | Exprs[i + NumOutputs] = E; |
| 677 | } |
| 678 | |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 679 | QualType CXXCatchStmt::getCaughtType() const { |
| 680 | if (ExceptionDecl) |
| 681 | return ExceptionDecl->getType(); |
| 682 | return QualType(); |
| 683 | } |
| 684 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 685 | //===----------------------------------------------------------------------===// |
| 686 | // Constructors |
| 687 | //===----------------------------------------------------------------------===// |
| 688 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 689 | GCCAsmStmt::GCCAsmStmt(const ASTContext &C, SourceLocation asmloc, |
| 690 | bool issimple, bool isvolatile, unsigned numoutputs, |
| 691 | unsigned numinputs, IdentifierInfo **names, |
| 692 | StringLiteral **constraints, Expr **exprs, |
| 693 | StringLiteral *asmstr, unsigned numclobbers, |
| 694 | StringLiteral **clobbers, SourceLocation rparenloc) |
Chad Rosier | fe3352e | 2012-08-27 19:38:01 +0000 | [diff] [blame] | 695 | : AsmStmt(GCCAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 696 | numinputs, numclobbers), RParenLoc(rparenloc), AsmStr(asmstr) { |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 697 | |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 698 | unsigned NumExprs = NumOutputs + NumInputs; |
| 699 | |
Anders Carlsson | 98323d2 | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 700 | Names = new (C) IdentifierInfo*[NumExprs]; |
| 701 | std::copy(names, names + NumExprs, Names); |
| 702 | |
| 703 | Exprs = new (C) Stmt*[NumExprs]; |
| 704 | std::copy(exprs, exprs + NumExprs, Exprs); |
| 705 | |
| 706 | Constraints = new (C) StringLiteral*[NumExprs]; |
| 707 | std::copy(constraints, constraints + NumExprs, Constraints); |
| 708 | |
| 709 | Clobbers = new (C) StringLiteral*[NumClobbers]; |
| 710 | std::copy(clobbers, clobbers + NumClobbers, Clobbers); |
Anders Carlsson | 94ea8aa | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 711 | } |
| 712 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 713 | MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 714 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 715 | ArrayRef<Token> asmtoks, unsigned numoutputs, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 716 | unsigned numinputs, |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 717 | ArrayRef<StringRef> constraints, ArrayRef<Expr*> exprs, |
| 718 | StringRef asmstr, ArrayRef<StringRef> clobbers, |
| 719 | SourceLocation endloc) |
| 720 | : AsmStmt(MSAsmStmtClass, asmloc, issimple, isvolatile, numoutputs, |
| 721 | numinputs, clobbers.size()), LBraceLoc(lbraceloc), |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 722 | EndLoc(endloc), NumAsmToks(asmtoks.size()) { |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 723 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 724 | initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); |
| 725 | } |
Chad Rosier | 7dbef3e | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 726 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 727 | static StringRef copyIntoContext(const ASTContext &C, StringRef str) { |
Benjamin Kramer | 2ab0d88 | 2015-08-04 12:34:23 +0000 | [diff] [blame] | 728 | return str.copy(C); |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 731 | void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 732 | ArrayRef<Token> asmtoks, |
| 733 | ArrayRef<StringRef> constraints, |
| 734 | ArrayRef<Expr*> exprs, |
| 735 | ArrayRef<StringRef> clobbers) { |
| 736 | assert(NumAsmToks == asmtoks.size()); |
| 737 | assert(NumClobbers == clobbers.size()); |
| 738 | |
| 739 | unsigned NumExprs = exprs.size(); |
| 740 | assert(NumExprs == NumOutputs + NumInputs); |
| 741 | assert(NumExprs == constraints.size()); |
| 742 | |
| 743 | AsmStr = copyIntoContext(C, asmstr); |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 744 | |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 745 | Exprs = new (C) Stmt*[NumExprs]; |
Chad Rosier | f8037a1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 746 | for (unsigned i = 0, e = NumExprs; i != e; ++i) |
| 747 | Exprs[i] = exprs[i]; |
Chad Rosier | fe31e62 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 748 | |
Chad Rosier | 99fc381 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 749 | AsmToks = new (C) Token[NumAsmToks]; |
| 750 | for (unsigned i = 0, e = NumAsmToks; i != e; ++i) |
| 751 | AsmToks[i] = asmtoks[i]; |
Chad Rosier | 3ed0bd9 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 752 | |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 753 | Constraints = new (C) StringRef[NumExprs]; |
| 754 | for (unsigned i = 0, e = NumExprs; i != e; ++i) { |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 755 | Constraints[i] = copyIntoContext(C, constraints[i]); |
Chad Rosier | 3dd7bf2 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Chad Rosier | baf53f9 | 2012-08-10 21:36:25 +0000 | [diff] [blame] | 758 | Clobbers = new (C) StringRef[NumClobbers]; |
Chad Rosier | d6ef704 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 759 | for (unsigned i = 0, e = NumClobbers; i != e; ++i) { |
| 760 | // FIXME: Avoid the allocation/copy if at all possible. |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 761 | Clobbers[i] = copyIntoContext(C, clobbers[i]); |
Chad Rosier | d6ef704 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 762 | } |
Chad Rosier | 3250302 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 765 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 766 | Stmt *Body, SourceLocation FCL, |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 767 | SourceLocation RPL) |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 768 | : Stmt(ObjCForCollectionStmtClass) { |
| 769 | SubExprs[ELEM] = Elem; |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 770 | SubExprs[COLLECTION] = Collect; |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 771 | SubExprs[BODY] = Body; |
| 772 | ForLoc = FCL; |
| 773 | RParenLoc = RPL; |
| 774 | } |
| 775 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 776 | ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, |
| 777 | Stmt **CatchStmts, unsigned NumCatchStmts, |
| 778 | Stmt *atFinallyStmt) |
| 779 | : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 780 | NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 781 | Stmt **Stmts = getStmts(); |
| 782 | Stmts[0] = atTryStmt; |
| 783 | for (unsigned I = 0; I != NumCatchStmts; ++I) |
| 784 | Stmts[I + 1] = CatchStmts[I]; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 785 | |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 786 | if (HasFinally) |
| 787 | Stmts[NumCatchStmts + 1] = atFinallyStmt; |
| 788 | } |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 789 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 790 | ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 791 | SourceLocation atTryLoc, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 792 | Stmt *atTryStmt, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 793 | Stmt **CatchStmts, |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 794 | unsigned NumCatchStmts, |
| 795 | Stmt *atFinallyStmt) { |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 796 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 797 | (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 798 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 799 | return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, |
| 800 | atFinallyStmt); |
| 801 | } |
Ted Kremenek | a496584 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 802 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 803 | ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, |
| 804 | unsigned NumCatchStmts, |
| 805 | bool HasFinally) { |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 806 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 807 | (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 808 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 809 | return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 810 | } |
Nico Weber | de565e3 | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 811 | |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 812 | SourceLocation ObjCAtTryStmt::getLocEnd() const { |
Douglas Gregor | 96c7949 | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 813 | if (HasFinally) |
Erik Verbruggen | 11a2ecc | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 814 | return getFinallyStmt()->getLocEnd(); |
| 815 | if (NumCatchStmts) |
| 816 | return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); |
| 817 | return getTryBody()->getLocEnd(); |
Chris Lattner | 86f5e13 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 820 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 821 | Stmt *tryBlock, ArrayRef<Stmt*> handlers) { |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 822 | std::size_t Size = sizeof(CXXTryStmt); |
James Y Knight | 53c7616 | 2015-07-17 18:21:37 +0000 | [diff] [blame] | 823 | Size += ((handlers.size() + 1) * sizeof(Stmt *)); |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 824 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 825 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 826 | return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 827 | } |
| 828 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 829 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 830 | unsigned numHandlers) { |
| 831 | std::size_t Size = sizeof(CXXTryStmt); |
James Y Knight | 53c7616 | 2015-07-17 18:21:37 +0000 | [diff] [blame] | 832 | Size += ((numHandlers + 1) * sizeof(Stmt *)); |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 833 | |
Chris Lattner | 5c0b405 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 834 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Argyrios Kyrtzidis | 47cd7a9 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 835 | return new (Mem) CXXTryStmt(Empty, numHandlers); |
| 836 | } |
| 837 | |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 838 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 839 | ArrayRef<Stmt*> handlers) |
| 840 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { |
Sam Weinig | a16b0dd | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 841 | Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 842 | Stmts[0] = tryBlock; |
Nico Weber | 9dff378 | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 843 | std::copy(handlers.begin(), handlers.end(), Stmts + 1); |
Sam Weinig | ebcea98 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 846 | CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, |
| 847 | Expr *Cond, Expr *Inc, DeclStmt *LoopVar, |
| 848 | Stmt *Body, SourceLocation FL, |
| 849 | SourceLocation CL, SourceLocation RPL) |
| 850 | : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { |
| 851 | SubExprs[RANGE] = Range; |
| 852 | SubExprs[BEGINEND] = BeginEndStmt; |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 853 | SubExprs[COND] = Cond; |
| 854 | SubExprs[INC] = Inc; |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 855 | SubExprs[LOOPVAR] = LoopVar; |
| 856 | SubExprs[BODY] = Body; |
| 857 | } |
| 858 | |
| 859 | Expr *CXXForRangeStmt::getRangeInit() { |
| 860 | DeclStmt *RangeStmt = getRangeStmt(); |
| 861 | VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); |
Richard Trieu | 8673869 | 2014-02-27 23:59:14 +0000 | [diff] [blame] | 862 | assert(RangeDecl && "for-range should have a single var decl"); |
Richard Smith | 02e85f3 | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 863 | return RangeDecl->getInit(); |
| 864 | } |
| 865 | |
| 866 | const Expr *CXXForRangeStmt::getRangeInit() const { |
| 867 | return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); |
| 868 | } |
| 869 | |
| 870 | VarDecl *CXXForRangeStmt::getLoopVariable() { |
| 871 | Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); |
| 872 | assert(LV && "No loop variable in CXXForRangeStmt"); |
| 873 | return cast<VarDecl>(LV); |
| 874 | } |
| 875 | |
| 876 | const VarDecl *CXXForRangeStmt::getLoopVariable() const { |
| 877 | return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); |
| 878 | } |
| 879 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 880 | IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, |
Argyrios Kyrtzidis | de2bdf6 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 881 | Stmt *then, SourceLocation EL, Stmt *elsev) |
| 882 | : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 883 | { |
| 884 | setConditionVariable(C, var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 885 | SubExprs[COND] = cond; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 886 | SubExprs[THEN] = then; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 887 | SubExprs[ELSE] = elsev; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | VarDecl *IfStmt::getConditionVariable() const { |
| 891 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 892 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 893 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 894 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 895 | return cast<VarDecl>(DS->getSingleDecl()); |
| 896 | } |
| 897 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 898 | void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 899 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 900 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 901 | return; |
| 902 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 903 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 904 | SourceRange VarRange = V->getSourceRange(); |
| 905 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 906 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 909 | ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 910 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 911 | SourceLocation RP) |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 912 | : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 913 | { |
| 914 | SubExprs[INIT] = Init; |
| 915 | setConditionVariable(C, condVar); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 916 | SubExprs[COND] = Cond; |
| 917 | SubExprs[INC] = Inc; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 918 | SubExprs[BODY] = Body; |
| 919 | } |
| 920 | |
| 921 | VarDecl *ForStmt::getConditionVariable() const { |
| 922 | if (!SubExprs[CONDVAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 923 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 925 | DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); |
| 926 | return cast<VarDecl>(DS->getSingleDecl()); |
| 927 | } |
| 928 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 929 | void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 930 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 931 | SubExprs[CONDVAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 932 | return; |
| 933 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 934 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 935 | SourceRange VarRange = V->getSourceRange(); |
| 936 | SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 937 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 940 | SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) |
Benjamin Kramer | 475386d | 2015-04-02 15:29:07 +0000 | [diff] [blame] | 941 | : Stmt(SwitchStmtClass), FirstCase(nullptr, false) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 942 | setConditionVariable(C, Var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 943 | SubExprs[COND] = cond; |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 944 | SubExprs[BODY] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | VarDecl *SwitchStmt::getConditionVariable() const { |
| 948 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 949 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 950 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 951 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 952 | return cast<VarDecl>(DS->getSingleDecl()); |
| 953 | } |
| 954 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 955 | void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 956 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 957 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 958 | return; |
| 959 | } |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 960 | |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 961 | SourceRange VarRange = V->getSourceRange(); |
| 962 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 963 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 964 | } |
| 965 | |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 966 | Stmt *SwitchCase::getSubStmt() { |
Chris Lattner | 80d51eb | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 967 | if (isa<CaseStmt>(this)) |
| 968 | return cast<CaseStmt>(this)->getSubStmt(); |
John McCall | bd06678 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 969 | return cast<DefaultStmt>(this)->getSubStmt(); |
| 970 | } |
| 971 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 972 | WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 973 | SourceLocation WL) |
Chris Lattner | 80d51eb | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 974 | : Stmt(WhileStmtClass) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 975 | setConditionVariable(C, Var); |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 976 | SubExprs[COND] = cond; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 977 | SubExprs[BODY] = body; |
| 978 | WhileLoc = WL; |
| 979 | } |
| 980 | |
| 981 | VarDecl *WhileStmt::getConditionVariable() const { |
| 982 | if (!SubExprs[VAR]) |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 983 | return nullptr; |
Chad Rosier | 42032fa | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 984 | |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 985 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 986 | return cast<VarDecl>(DS->getSingleDecl()); |
| 987 | } |
| 988 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 989 | void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 990 | if (!V) { |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 991 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 992 | return; |
| 993 | } |
Daniel Dunbar | 62ee641 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 994 | |
| 995 | SourceRange VarRange = V->getSourceRange(); |
| 996 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 997 | VarRange.getEnd()); |
Douglas Gregor | 27b98ea | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 998 | } |
| 999 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1000 | // IndirectGotoStmt |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1001 | LabelDecl *IndirectGotoStmt::getConstantTarget() { |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1002 | if (AddrLabelExpr *E = |
| 1003 | dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) |
| 1004 | return E->getLabel(); |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1005 | return nullptr; |
John McCall | 9de9160 | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1006 | } |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1007 | |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1008 | // ReturnStmt |
Ted Kremenek | c6501db | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 1009 | const Expr* ReturnStmt::getRetValue() const { |
| 1010 | return cast_or_null<Expr>(RetExpr); |
| 1011 | } |
| 1012 | Expr* ReturnStmt::getRetValue() { |
| 1013 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 066dd93 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1014 | } |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1015 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1016 | SEHTryStmt::SEHTryStmt(bool IsCXXTry, |
| 1017 | SourceLocation TryLoc, |
| 1018 | Stmt *TryBlock, |
| 1019 | Stmt *Handler) |
| 1020 | : Stmt(SEHTryStmtClass), |
| 1021 | IsCXXTry(IsCXXTry), |
| 1022 | TryLoc(TryLoc) |
| 1023 | { |
| 1024 | Children[TRY] = TryBlock; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1025 | Children[HANDLER] = Handler; |
| 1026 | } |
| 1027 | |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1028 | SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1029 | SourceLocation TryLoc, Stmt *TryBlock, |
Warren Hunt | f6be4cb | 2014-07-25 20:52:51 +0000 | [diff] [blame] | 1030 | Stmt *Handler) { |
| 1031 | return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | SEHExceptStmt* SEHTryStmt::getExceptHandler() const { |
| 1035 | return dyn_cast<SEHExceptStmt>(getHandler()); |
| 1036 | } |
| 1037 | |
| 1038 | SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { |
| 1039 | return dyn_cast<SEHFinallyStmt>(getHandler()); |
| 1040 | } |
| 1041 | |
| 1042 | SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, |
| 1043 | Expr *FilterExpr, |
| 1044 | Stmt *Block) |
| 1045 | : Stmt(SEHExceptStmtClass), |
| 1046 | Loc(Loc) |
| 1047 | { |
Pavel Labath | 515f4db | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 1048 | Children[FILTER_EXPR] = FilterExpr; |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1049 | Children[BLOCK] = Block; |
| 1050 | } |
| 1051 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1052 | SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, |
| 1053 | Expr *FilterExpr, Stmt *Block) { |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1054 | return new(C) SEHExceptStmt(Loc,FilterExpr,Block); |
| 1055 | } |
| 1056 | |
| 1057 | SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, |
| 1058 | Stmt *Block) |
| 1059 | : Stmt(SEHFinallyStmtClass), |
| 1060 | Loc(Loc), |
| 1061 | Block(Block) |
| 1062 | {} |
| 1063 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1064 | SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, |
John Wiegley | 1c0675e | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1065 | Stmt *Block) { |
| 1066 | return new(C)SEHFinallyStmt(Loc,Block); |
| 1067 | } |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1068 | |
| 1069 | CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { |
| 1070 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1071 | |
| 1072 | // Offset of the first Capture object. |
| 1073 | unsigned FirstCaptureOffset = |
| 1074 | llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1075 | |
| 1076 | return reinterpret_cast<Capture *>( |
| 1077 | reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) |
| 1078 | + FirstCaptureOffset); |
| 1079 | } |
| 1080 | |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1081 | CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, |
| 1082 | ArrayRef<Capture> Captures, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1083 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1084 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1085 | RecordDecl *RD) |
| 1086 | : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1087 | CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1088 | assert( S && "null captured statement"); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1089 | assert(CD && "null captured declaration for captured statement"); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1090 | assert(RD && "null record declaration for captured statement"); |
| 1091 | |
| 1092 | // Copy initialization expressions. |
| 1093 | Stmt **Stored = getStoredStmts(); |
| 1094 | for (unsigned I = 0, N = NumCaptures; I != N; ++I) |
| 1095 | *Stored++ = CaptureInits[I]; |
| 1096 | |
| 1097 | // Copy the statement being captured. |
| 1098 | *Stored = S; |
| 1099 | |
| 1100 | // Copy all Capture objects. |
| 1101 | Capture *Buffer = getStoredCaptures(); |
| 1102 | std::copy(Captures.begin(), Captures.end(), Buffer); |
| 1103 | } |
| 1104 | |
| 1105 | CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) |
| 1106 | : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), |
Craig Topper | 36250ad | 2014-05-12 05:36:57 +0000 | [diff] [blame] | 1107 | CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) { |
| 1108 | getStoredStmts()[NumCaptures] = nullptr; |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1111 | CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1112 | CapturedRegionKind Kind, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1113 | ArrayRef<Capture> Captures, |
| 1114 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1115 | CapturedDecl *CD, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1116 | RecordDecl *RD) { |
| 1117 | // The layout is |
| 1118 | // |
| 1119 | // ----------------------------------------------------------- |
| 1120 | // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | |
| 1121 | // ----------------^-------------------^---------------------- |
| 1122 | // getStoredStmts() getStoredCaptures() |
| 1123 | // |
| 1124 | // where S is the statement being captured. |
| 1125 | // |
| 1126 | assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); |
| 1127 | |
| 1128 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); |
| 1129 | if (!Captures.empty()) { |
| 1130 | // Realign for the following Capture array. |
| 1131 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1132 | Size += sizeof(Capture) * Captures.size(); |
| 1133 | } |
| 1134 | |
| 1135 | void *Mem = Context.Allocate(Size); |
Wei Pan | 17fbf6e | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1136 | return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1137 | } |
| 1138 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1139 | CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1140 | unsigned NumCaptures) { |
| 1141 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1142 | if (NumCaptures > 0) { |
| 1143 | // Realign for the following Capture array. |
| 1144 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1145 | Size += sizeof(Capture) * NumCaptures; |
| 1146 | } |
| 1147 | |
| 1148 | void *Mem = Context.Allocate(Size); |
| 1149 | return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); |
| 1150 | } |
| 1151 | |
| 1152 | Stmt::child_range CapturedStmt::children() { |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1153 | // Children are captured field initilizers. |
| 1154 | return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | bool CapturedStmt::capturesVariable(const VarDecl *Var) const { |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1158 | for (const auto &I : captures()) { |
| 1159 | if (!I.capturesVariable()) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1160 | continue; |
| 1161 | |
| 1162 | // This does not handle variable redeclarations. This should be |
| 1163 | // extended to capture variables with redeclarations, for example |
| 1164 | // a thread-private variable in OpenMP. |
Aaron Ballman | c656303a | 2014-03-14 18:08:33 +0000 | [diff] [blame] | 1165 | if (I.getCapturedVar() == Var) |
Tareq A. Siraj | 24110cc | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1166 | return true; |
| 1167 | } |
| 1168 | |
| 1169 | return false; |
| 1170 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1171 | |
Benjamin Kramer | 5733e35 | 2015-07-18 17:09:36 +0000 | [diff] [blame] | 1172 | OMPClause::child_range OMPClause::children() { |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1173 | switch(getClauseKind()) { |
| 1174 | default : break; |
| 1175 | #define OPENMP_CLAUSE(Name, Class) \ |
| 1176 | case OMPC_ ## Name : return static_cast<Class *>(this)->children(); |
| 1177 | #include "clang/Basic/OpenMPKinds.def" |
| 1178 | } |
| 1179 | llvm_unreachable("unknown OMPClause"); |
| 1180 | } |
| 1181 | |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1182 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1183 | assert(VL.size() == varlist_size() && |
| 1184 | "Number of private copies is not the same as the preallocated buffer"); |
| 1185 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1186 | } |
| 1187 | |
| 1188 | OMPPrivateClause * |
| 1189 | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1190 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1191 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
| 1192 | // Allocate space for private variables and initializer expressions. |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1193 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1194 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1195 | 2 * sizeof(Expr *) * VL.size()); |
| 1196 | OMPPrivateClause *Clause = |
| 1197 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1198 | Clause->setVarRefs(VL); |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1199 | Clause->setPrivateCopies(PrivateVL); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1200 | return Clause; |
| 1201 | } |
| 1202 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1203 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1204 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1205 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1206 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 03b340a | 2014-10-21 03:16:40 +0000 | [diff] [blame] | 1207 | 2 * sizeof(Expr *) * N); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1208 | return new (Mem) OMPPrivateClause(N); |
| 1209 | } |
| 1210 | |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1211 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1212 | assert(VL.size() == varlist_size() && |
| 1213 | "Number of private copies is not the same as the preallocated buffer"); |
| 1214 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1215 | } |
| 1216 | |
| 1217 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
| 1218 | assert(VL.size() == varlist_size() && |
| 1219 | "Number of inits is not the same as the preallocated buffer"); |
| 1220 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 1221 | } |
| 1222 | |
| 1223 | OMPFirstprivateClause * |
| 1224 | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1225 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1226 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
| 1227 | ArrayRef<Expr *> InitVL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1228 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1229 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1230 | 3 * sizeof(Expr *) * VL.size()); |
| 1231 | OMPFirstprivateClause *Clause = |
| 1232 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1233 | Clause->setVarRefs(VL); |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1234 | Clause->setPrivateCopies(PrivateVL); |
| 1235 | Clause->setInits(InitVL); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1236 | return Clause; |
| 1237 | } |
| 1238 | |
| 1239 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 1240 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1241 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1242 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 4a5bb77 | 2014-10-08 14:01:46 +0000 | [diff] [blame] | 1243 | 3 * sizeof(Expr *) * N); |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1244 | return new (Mem) OMPFirstprivateClause(N); |
| 1245 | } |
| 1246 | |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1247 | void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { |
| 1248 | assert(PrivateCopies.size() == varlist_size() && |
| 1249 | "Number of private copies is not the same as the preallocated buffer"); |
| 1250 | std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); |
| 1251 | } |
| 1252 | |
| 1253 | void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 1254 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 1255 | "not the same as the " |
| 1256 | "preallocated buffer"); |
| 1257 | std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); |
| 1258 | } |
| 1259 | |
| 1260 | void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 1261 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 1262 | "expressions is not the same as " |
| 1263 | "the preallocated buffer"); |
| 1264 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 1265 | } |
| 1266 | |
| 1267 | void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 1268 | assert(AssignmentOps.size() == varlist_size() && |
| 1269 | "Number of assignment expressions is not the same as the preallocated " |
| 1270 | "buffer"); |
| 1271 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 1272 | getDestinationExprs().end()); |
| 1273 | } |
| 1274 | |
| 1275 | OMPLastprivateClause *OMPLastprivateClause::Create( |
| 1276 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1277 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 1278 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1279 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1280 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1281 | 5 * sizeof(Expr *) * VL.size()); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1282 | OMPLastprivateClause *Clause = |
| 1283 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1284 | Clause->setVarRefs(VL); |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1285 | Clause->setSourceExprs(SrcExprs); |
| 1286 | Clause->setDestinationExprs(DstExprs); |
| 1287 | Clause->setAssignmentOps(AssignmentOps); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1288 | return Clause; |
| 1289 | } |
| 1290 | |
| 1291 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 1292 | unsigned N) { |
| 1293 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1294 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 38e8953 | 2015-04-16 04:54:05 +0000 | [diff] [blame] | 1295 | 5 * sizeof(Expr *) * N); |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1296 | return new (Mem) OMPLastprivateClause(N); |
| 1297 | } |
| 1298 | |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1299 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 1300 | SourceLocation StartLoc, |
| 1301 | SourceLocation LParenLoc, |
| 1302 | SourceLocation EndLoc, |
| 1303 | ArrayRef<Expr *> VL) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1304 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1305 | llvm::alignOf<Expr *>()) + |
| 1306 | sizeof(Expr *) * VL.size()); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1307 | OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, |
| 1308 | EndLoc, VL.size()); |
| 1309 | Clause->setVarRefs(VL); |
| 1310 | return Clause; |
| 1311 | } |
| 1312 | |
| 1313 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, |
| 1314 | unsigned N) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1315 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1316 | llvm::alignOf<Expr *>()) + |
| 1317 | sizeof(Expr *) * N); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1318 | return new (Mem) OMPSharedClause(N); |
| 1319 | } |
| 1320 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1321 | void OMPLinearClause::setPrivates(ArrayRef<Expr *> PL) { |
| 1322 | assert(PL.size() == varlist_size() && |
| 1323 | "Number of privates is not the same as the preallocated buffer"); |
| 1324 | std::copy(PL.begin(), PL.end(), varlist_end()); |
| 1325 | } |
| 1326 | |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1327 | void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { |
| 1328 | assert(IL.size() == varlist_size() && |
| 1329 | "Number of inits is not the same as the preallocated buffer"); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1330 | std::copy(IL.begin(), IL.end(), getPrivates().end()); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { |
| 1334 | assert(UL.size() == varlist_size() && |
| 1335 | "Number of updates is not the same as the preallocated buffer"); |
| 1336 | std::copy(UL.begin(), UL.end(), getInits().end()); |
| 1337 | } |
| 1338 | |
| 1339 | void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { |
| 1340 | assert(FL.size() == varlist_size() && |
| 1341 | "Number of final updates is not the same as the preallocated buffer"); |
| 1342 | std::copy(FL.begin(), FL.end(), getUpdates().end()); |
| 1343 | } |
| 1344 | |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1345 | OMPLinearClause *OMPLinearClause::Create( |
| 1346 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1347 | OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1348 | SourceLocation ColonLoc, SourceLocation EndLoc, ArrayRef<Expr *> VL, |
| 1349 | ArrayRef<Expr *> PL, ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1350 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 1351 | // (Step and CalcStep). |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1352 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1353 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1354 | (5 * VL.size() + 2) * sizeof(Expr *)); |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1355 | OMPLinearClause *Clause = new (Mem) OMPLinearClause( |
| 1356 | StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc, EndLoc, VL.size()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1357 | Clause->setVarRefs(VL); |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1358 | Clause->setPrivates(PL); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1359 | Clause->setInits(IL); |
| 1360 | // Fill update and final expressions with zeroes, they are provided later, |
| 1361 | // after the directive construction. |
| 1362 | std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), |
| 1363 | nullptr); |
| 1364 | std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), |
| 1365 | nullptr); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1366 | Clause->setStep(Step); |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1367 | Clause->setCalcStep(CalcStep); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1368 | return Clause; |
| 1369 | } |
| 1370 | |
| 1371 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 1372 | unsigned NumVars) { |
Alexander Musman | 3276a27 | 2015-03-21 10:12:56 +0000 | [diff] [blame] | 1373 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 1374 | // (Step and CalcStep). |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1375 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1376 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | bd9fec1 | 2015-08-18 06:47:21 +0000 | [diff] [blame] | 1377 | (5 * NumVars + 2) * sizeof(Expr *)); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1378 | return new (Mem) OMPLinearClause(NumVars); |
| 1379 | } |
| 1380 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1381 | OMPAlignedClause * |
| 1382 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1383 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1384 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
| 1385 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1386 | llvm::alignOf<Expr *>()) + |
| 1387 | sizeof(Expr *) * (VL.size() + 1)); |
| 1388 | OMPAlignedClause *Clause = new (Mem) |
| 1389 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1390 | Clause->setVarRefs(VL); |
| 1391 | Clause->setAlignment(A); |
| 1392 | return Clause; |
| 1393 | } |
| 1394 | |
| 1395 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 1396 | unsigned NumVars) { |
| 1397 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1398 | llvm::alignOf<Expr *>()) + |
| 1399 | sizeof(Expr *) * (NumVars + 1)); |
| 1400 | return new (Mem) OMPAlignedClause(NumVars); |
| 1401 | } |
| 1402 | |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1403 | void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 1404 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 1405 | "not the same as the " |
| 1406 | "preallocated buffer"); |
| 1407 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 1408 | } |
| 1409 | |
| 1410 | void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 1411 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 1412 | "expressions is not the same as " |
| 1413 | "the preallocated buffer"); |
| 1414 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 1415 | } |
| 1416 | |
| 1417 | void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 1418 | assert(AssignmentOps.size() == varlist_size() && |
| 1419 | "Number of assignment expressions is not the same as the preallocated " |
| 1420 | "buffer"); |
| 1421 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 1422 | getDestinationExprs().end()); |
| 1423 | } |
| 1424 | |
| 1425 | OMPCopyinClause *OMPCopyinClause::Create( |
| 1426 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1427 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 1428 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1429 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1430 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1431 | 4 * sizeof(Expr *) * VL.size()); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1432 | OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, |
| 1433 | EndLoc, VL.size()); |
| 1434 | Clause->setVarRefs(VL); |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1435 | Clause->setSourceExprs(SrcExprs); |
| 1436 | Clause->setDestinationExprs(DstExprs); |
| 1437 | Clause->setAssignmentOps(AssignmentOps); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1438 | return Clause; |
| 1439 | } |
| 1440 | |
| 1441 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, |
| 1442 | unsigned N) { |
| 1443 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1444 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | f56f98c | 2015-04-16 05:39:01 +0000 | [diff] [blame] | 1445 | 4 * sizeof(Expr *) * N); |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1446 | return new (Mem) OMPCopyinClause(N); |
| 1447 | } |
| 1448 | |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 1449 | void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 1450 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 1451 | "not the same as the " |
| 1452 | "preallocated buffer"); |
| 1453 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 1454 | } |
| 1455 | |
| 1456 | void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 1457 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 1458 | "expressions is not the same as " |
| 1459 | "the preallocated buffer"); |
| 1460 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 1461 | } |
| 1462 | |
| 1463 | void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 1464 | assert(AssignmentOps.size() == varlist_size() && |
| 1465 | "Number of assignment expressions is not the same as the preallocated " |
| 1466 | "buffer"); |
| 1467 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 1468 | getDestinationExprs().end()); |
| 1469 | } |
| 1470 | |
| 1471 | OMPCopyprivateClause *OMPCopyprivateClause::Create( |
| 1472 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1473 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 1474 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1475 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), |
| 1476 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 1477 | 4 * sizeof(Expr *) * VL.size()); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1478 | OMPCopyprivateClause *Clause = |
| 1479 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1480 | Clause->setVarRefs(VL); |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 1481 | Clause->setSourceExprs(SrcExprs); |
| 1482 | Clause->setDestinationExprs(DstExprs); |
| 1483 | Clause->setAssignmentOps(AssignmentOps); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1484 | return Clause; |
| 1485 | } |
| 1486 | |
| 1487 | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
| 1488 | unsigned N) { |
| 1489 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), |
| 1490 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | a63048e | 2015-03-23 06:18:07 +0000 | [diff] [blame] | 1491 | 4 * sizeof(Expr *) * N); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1492 | return new (Mem) OMPCopyprivateClause(N); |
| 1493 | } |
| 1494 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1495 | void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { |
Alexander Musman | fd2b759 | 2014-03-27 15:14:18 +0000 | [diff] [blame] | 1496 | assert(Clauses.size() == getNumClauses() && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1497 | "Number of clauses is not the same as the preallocated buffer"); |
Alexander Musman | fd2b759 | 2014-03-27 15:14:18 +0000 | [diff] [blame] | 1498 | std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1501 | void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) { |
| 1502 | assert(A.size() == getCollapsedNumber() && |
| 1503 | "Number of loop counters is not the same as the collapsed number"); |
| 1504 | std::copy(A.begin(), A.end(), getCounters().begin()); |
| 1505 | } |
| 1506 | |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 1507 | void OMPLoopDirective::setPrivateCounters(ArrayRef<Expr *> A) { |
| 1508 | assert(A.size() == getCollapsedNumber() && "Number of loop private counters " |
| 1509 | "is not the same as the collapsed " |
| 1510 | "number"); |
| 1511 | std::copy(A.begin(), A.end(), getPrivateCounters().begin()); |
| 1512 | } |
| 1513 | |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 1514 | void OMPLoopDirective::setInits(ArrayRef<Expr *> A) { |
| 1515 | assert(A.size() == getCollapsedNumber() && |
| 1516 | "Number of counter inits is not the same as the collapsed number"); |
| 1517 | std::copy(A.begin(), A.end(), getInits().begin()); |
| 1518 | } |
| 1519 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1520 | void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) { |
| 1521 | assert(A.size() == getCollapsedNumber() && |
| 1522 | "Number of counter updates is not the same as the collapsed number"); |
| 1523 | std::copy(A.begin(), A.end(), getUpdates().begin()); |
| 1524 | } |
| 1525 | |
| 1526 | void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) { |
| 1527 | assert(A.size() == getCollapsedNumber() && |
| 1528 | "Number of counter finals is not the same as the collapsed number"); |
| 1529 | std::copy(A.begin(), A.end(), getFinals().begin()); |
| 1530 | } |
| 1531 | |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1532 | void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 1533 | assert( |
| 1534 | LHSExprs.size() == varlist_size() && |
| 1535 | "Number of LHS expressions is not the same as the preallocated buffer"); |
| 1536 | std::copy(LHSExprs.begin(), LHSExprs.end(), varlist_end()); |
| 1537 | } |
| 1538 | |
| 1539 | void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 1540 | assert( |
| 1541 | RHSExprs.size() == varlist_size() && |
| 1542 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 1543 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 1544 | } |
| 1545 | |
| 1546 | void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 1547 | assert(ReductionOps.size() == varlist_size() && "Number of reduction " |
| 1548 | "expressions is not the same " |
| 1549 | "as the preallocated buffer"); |
| 1550 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 1551 | } |
| 1552 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1553 | OMPReductionClause *OMPReductionClause::Create( |
| 1554 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1555 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1556 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
| 1557 | ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, |
| 1558 | ArrayRef<Expr *> ReductionOps) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1559 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1560 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1561 | 4 * sizeof(Expr *) * VL.size()); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1562 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 1563 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 1564 | Clause->setVarRefs(VL); |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1565 | Clause->setLHSExprs(LHSExprs); |
| 1566 | Clause->setRHSExprs(RHSExprs); |
| 1567 | Clause->setReductionOps(ReductionOps); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1568 | return Clause; |
| 1569 | } |
| 1570 | |
| 1571 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 1572 | unsigned N) { |
| 1573 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1574 | llvm::alignOf<Expr *>()) + |
Alexey Bataev | 794ba0d | 2015-04-10 10:43:45 +0000 | [diff] [blame] | 1575 | 4 * sizeof(Expr *) * N); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1576 | return new (Mem) OMPReductionClause(N); |
| 1577 | } |
| 1578 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1579 | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
| 1580 | SourceLocation StartLoc, |
| 1581 | SourceLocation LParenLoc, |
| 1582 | SourceLocation EndLoc, |
| 1583 | ArrayRef<Expr *> VL) { |
| 1584 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), |
| 1585 | llvm::alignOf<Expr *>()) + |
| 1586 | sizeof(Expr *) * VL.size()); |
| 1587 | OMPFlushClause *Clause = |
| 1588 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1589 | Clause->setVarRefs(VL); |
| 1590 | return Clause; |
| 1591 | } |
| 1592 | |
| 1593 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| 1594 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), |
| 1595 | llvm::alignOf<Expr *>()) + |
| 1596 | sizeof(Expr *) * N); |
| 1597 | return new (Mem) OMPFlushClause(N); |
| 1598 | } |
| 1599 | |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1600 | OMPDependClause * |
| 1601 | OMPDependClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1602 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1603 | OpenMPDependClauseKind DepKind, SourceLocation DepLoc, |
| 1604 | SourceLocation ColonLoc, ArrayRef<Expr *> VL) { |
| 1605 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause), |
| 1606 | llvm::alignOf<Expr *>()) + |
| 1607 | sizeof(Expr *) * VL.size()); |
| 1608 | OMPDependClause *Clause = |
| 1609 | new (Mem) OMPDependClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1610 | Clause->setVarRefs(VL); |
| 1611 | Clause->setDependencyKind(DepKind); |
| 1612 | Clause->setDependencyLoc(DepLoc); |
| 1613 | Clause->setColonLoc(ColonLoc); |
| 1614 | return Clause; |
| 1615 | } |
| 1616 | |
| 1617 | OMPDependClause *OMPDependClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| 1618 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPDependClause), |
| 1619 | llvm::alignOf<Expr *>()) + |
| 1620 | sizeof(Expr *) * N); |
| 1621 | return new (Mem) OMPDependClause(N); |
| 1622 | } |
| 1623 | |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 1624 | const OMPClause * |
| 1625 | OMPExecutableDirective::getSingleClause(OpenMPClauseKind K) const { |
Alexey Bataev | c925aa3 | 2015-04-27 08:00:32 +0000 | [diff] [blame] | 1626 | auto &&I = getClausesOfKind(K); |
Alexey Bataev | d74d060 | 2014-10-13 06:02:40 +0000 | [diff] [blame] | 1627 | |
| 1628 | if (I) { |
| 1629 | auto *Clause = *I; |
| 1630 | assert(!++I && "There are at least 2 clauses of the specified kind"); |
| 1631 | return Clause; |
| 1632 | } |
| 1633 | return nullptr; |
| 1634 | } |
| 1635 | |
Craig Topper | cee6133 | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1636 | OMPParallelDirective *OMPParallelDirective::Create( |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1637 | const ASTContext &C, |
Craig Topper | cee6133 | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1638 | SourceLocation StartLoc, |
| 1639 | SourceLocation EndLoc, |
| 1640 | ArrayRef<OMPClause *> Clauses, |
| 1641 | Stmt *AssociatedStmt) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1642 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1643 | llvm::alignOf<OMPClause *>()); |
| 1644 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1645 | sizeof(Stmt *)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1646 | OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, |
| 1647 | Clauses.size()); |
| 1648 | Dir->setClauses(Clauses); |
| 1649 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1650 | return Dir; |
| 1651 | } |
| 1652 | |
Craig Topper | e6960e2 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1653 | OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1654 | unsigned NumClauses, |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1655 | EmptyShell) { |
Alexey Bataev | 1319381 | 2014-02-25 11:25:38 +0000 | [diff] [blame] | 1656 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1657 | llvm::alignOf<OMPClause *>()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1658 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1659 | sizeof(Stmt *)); |
| 1660 | return new (Mem) OMPParallelDirective(NumClauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1661 | } |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1662 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1663 | OMPSimdDirective * |
| 1664 | OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1665 | SourceLocation EndLoc, unsigned CollapsedNum, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1666 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1667 | const HelperExprs &Exprs) { |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1668 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1669 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1670 | void *Mem = |
| 1671 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1672 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1673 | OMPSimdDirective *Dir = new (Mem) |
| 1674 | OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1675 | Dir->setClauses(Clauses); |
| 1676 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1677 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1678 | Dir->setLastIteration(Exprs.LastIteration); |
| 1679 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1680 | Dir->setPreCond(Exprs.PreCond); |
Alexey Bataev | ae05c29 | 2015-06-16 11:59:36 +0000 | [diff] [blame] | 1681 | Dir->setCond(Exprs.Cond); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1682 | Dir->setInit(Exprs.Init); |
| 1683 | Dir->setInc(Exprs.Inc); |
| 1684 | Dir->setCounters(Exprs.Counters); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 1685 | Dir->setPrivateCounters(Exprs.PrivateCounters); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 1686 | Dir->setInits(Exprs.Inits); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1687 | Dir->setUpdates(Exprs.Updates); |
| 1688 | Dir->setFinals(Exprs.Finals); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1689 | return Dir; |
| 1690 | } |
| 1691 | |
| 1692 | OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, |
| 1693 | unsigned NumClauses, |
| 1694 | unsigned CollapsedNum, |
| 1695 | EmptyShell) { |
| 1696 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1697 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1698 | void *Mem = |
| 1699 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1700 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1701 | return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); |
| 1702 | } |
| 1703 | |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1704 | OMPForDirective * |
| 1705 | OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1706 | SourceLocation EndLoc, unsigned CollapsedNum, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1707 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1708 | const HelperExprs &Exprs) { |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1709 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1710 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1711 | void *Mem = |
| 1712 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1713 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1714 | OMPForDirective *Dir = |
Alexey Bataev | abfc069 | 2014-06-25 06:52:00 +0000 | [diff] [blame] | 1715 | new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1716 | Dir->setClauses(Clauses); |
| 1717 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1718 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1719 | Dir->setLastIteration(Exprs.LastIteration); |
| 1720 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1721 | Dir->setPreCond(Exprs.PreCond); |
Alexey Bataev | ae05c29 | 2015-06-16 11:59:36 +0000 | [diff] [blame] | 1722 | Dir->setCond(Exprs.Cond); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1723 | Dir->setInit(Exprs.Init); |
| 1724 | Dir->setInc(Exprs.Inc); |
| 1725 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1726 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1727 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1728 | Dir->setStrideVariable(Exprs.ST); |
| 1729 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1730 | Dir->setNextLowerBound(Exprs.NLB); |
| 1731 | Dir->setNextUpperBound(Exprs.NUB); |
| 1732 | Dir->setCounters(Exprs.Counters); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 1733 | Dir->setPrivateCounters(Exprs.PrivateCounters); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 1734 | Dir->setInits(Exprs.Inits); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1735 | Dir->setUpdates(Exprs.Updates); |
| 1736 | Dir->setFinals(Exprs.Finals); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1737 | return Dir; |
| 1738 | } |
| 1739 | |
| 1740 | OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C, |
| 1741 | unsigned NumClauses, |
| 1742 | unsigned CollapsedNum, |
| 1743 | EmptyShell) { |
| 1744 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1745 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1746 | void *Mem = |
| 1747 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1748 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1749 | return new (Mem) OMPForDirective(CollapsedNum, NumClauses); |
| 1750 | } |
| 1751 | |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1752 | OMPForSimdDirective * |
| 1753 | OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1754 | SourceLocation EndLoc, unsigned CollapsedNum, |
| 1755 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1756 | const HelperExprs &Exprs) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1757 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), |
| 1758 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1759 | void *Mem = |
| 1760 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1761 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1762 | OMPForSimdDirective *Dir = new (Mem) |
| 1763 | OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1764 | Dir->setClauses(Clauses); |
| 1765 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1766 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1767 | Dir->setLastIteration(Exprs.LastIteration); |
| 1768 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1769 | Dir->setPreCond(Exprs.PreCond); |
Alexey Bataev | ae05c29 | 2015-06-16 11:59:36 +0000 | [diff] [blame] | 1770 | Dir->setCond(Exprs.Cond); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1771 | Dir->setInit(Exprs.Init); |
| 1772 | Dir->setInc(Exprs.Inc); |
| 1773 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1774 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1775 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1776 | Dir->setStrideVariable(Exprs.ST); |
| 1777 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1778 | Dir->setNextLowerBound(Exprs.NLB); |
| 1779 | Dir->setNextUpperBound(Exprs.NUB); |
| 1780 | Dir->setCounters(Exprs.Counters); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 1781 | Dir->setPrivateCounters(Exprs.PrivateCounters); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 1782 | Dir->setInits(Exprs.Inits); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1783 | Dir->setUpdates(Exprs.Updates); |
| 1784 | Dir->setFinals(Exprs.Finals); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1785 | return Dir; |
| 1786 | } |
| 1787 | |
| 1788 | OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C, |
| 1789 | unsigned NumClauses, |
| 1790 | unsigned CollapsedNum, |
| 1791 | EmptyShell) { |
| 1792 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), |
| 1793 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1794 | void *Mem = |
| 1795 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1796 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1797 | return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses); |
| 1798 | } |
| 1799 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1800 | OMPSectionsDirective *OMPSectionsDirective::Create( |
| 1801 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1802 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 1803 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1804 | llvm::alignOf<OMPClause *>()); |
| 1805 | void *Mem = |
| 1806 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1807 | OMPSectionsDirective *Dir = |
| 1808 | new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1809 | Dir->setClauses(Clauses); |
| 1810 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1811 | return Dir; |
| 1812 | } |
| 1813 | |
| 1814 | OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, |
| 1815 | unsigned NumClauses, |
| 1816 | EmptyShell) { |
| 1817 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1818 | llvm::alignOf<OMPClause *>()); |
| 1819 | void *Mem = |
| 1820 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1821 | return new (Mem) OMPSectionsDirective(NumClauses); |
| 1822 | } |
| 1823 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1824 | OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, |
| 1825 | SourceLocation StartLoc, |
| 1826 | SourceLocation EndLoc, |
| 1827 | Stmt *AssociatedStmt) { |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1828 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1829 | llvm::alignOf<Stmt *>()); |
| 1830 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1831 | OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); |
| 1832 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1833 | return Dir; |
| 1834 | } |
| 1835 | |
| 1836 | OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, |
| 1837 | EmptyShell) { |
| 1838 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), |
| 1839 | llvm::alignOf<Stmt *>()); |
| 1840 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1841 | return new (Mem) OMPSectionDirective(); |
| 1842 | } |
| 1843 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1844 | OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, |
| 1845 | SourceLocation StartLoc, |
| 1846 | SourceLocation EndLoc, |
| 1847 | ArrayRef<OMPClause *> Clauses, |
| 1848 | Stmt *AssociatedStmt) { |
| 1849 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), |
| 1850 | llvm::alignOf<OMPClause *>()); |
| 1851 | void *Mem = |
| 1852 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1853 | OMPSingleDirective *Dir = |
| 1854 | new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); |
| 1855 | Dir->setClauses(Clauses); |
| 1856 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1857 | return Dir; |
| 1858 | } |
| 1859 | |
| 1860 | OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, |
| 1861 | unsigned NumClauses, |
| 1862 | EmptyShell) { |
| 1863 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), |
| 1864 | llvm::alignOf<OMPClause *>()); |
| 1865 | void *Mem = |
| 1866 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1867 | return new (Mem) OMPSingleDirective(NumClauses); |
| 1868 | } |
| 1869 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1870 | OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C, |
| 1871 | SourceLocation StartLoc, |
| 1872 | SourceLocation EndLoc, |
| 1873 | Stmt *AssociatedStmt) { |
| 1874 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), |
| 1875 | llvm::alignOf<Stmt *>()); |
| 1876 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1877 | OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); |
| 1878 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1879 | return Dir; |
| 1880 | } |
| 1881 | |
| 1882 | OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C, |
| 1883 | EmptyShell) { |
| 1884 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), |
| 1885 | llvm::alignOf<Stmt *>()); |
| 1886 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1887 | return new (Mem) OMPMasterDirective(); |
| 1888 | } |
| 1889 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1890 | OMPCriticalDirective *OMPCriticalDirective::Create( |
| 1891 | const ASTContext &C, const DeclarationNameInfo &Name, |
| 1892 | SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) { |
| 1893 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), |
| 1894 | llvm::alignOf<Stmt *>()); |
| 1895 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1896 | OMPCriticalDirective *Dir = |
| 1897 | new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc); |
| 1898 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1899 | return Dir; |
| 1900 | } |
| 1901 | |
| 1902 | OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C, |
| 1903 | EmptyShell) { |
| 1904 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), |
| 1905 | llvm::alignOf<Stmt *>()); |
| 1906 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1907 | return new (Mem) OMPCriticalDirective(); |
| 1908 | } |
| 1909 | |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1910 | OMPParallelForDirective *OMPParallelForDirective::Create( |
| 1911 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1912 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1913 | const HelperExprs &Exprs) { |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1914 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), |
| 1915 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1916 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1917 | sizeof(Stmt *) * |
| 1918 | numLoopChildren(CollapsedNum, OMPD_parallel_for)); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1919 | OMPParallelForDirective *Dir = new (Mem) |
| 1920 | OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1921 | Dir->setClauses(Clauses); |
| 1922 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1923 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1924 | Dir->setLastIteration(Exprs.LastIteration); |
| 1925 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1926 | Dir->setPreCond(Exprs.PreCond); |
Alexey Bataev | ae05c29 | 2015-06-16 11:59:36 +0000 | [diff] [blame] | 1927 | Dir->setCond(Exprs.Cond); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1928 | Dir->setInit(Exprs.Init); |
| 1929 | Dir->setInc(Exprs.Inc); |
| 1930 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1931 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1932 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1933 | Dir->setStrideVariable(Exprs.ST); |
| 1934 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1935 | Dir->setNextLowerBound(Exprs.NLB); |
| 1936 | Dir->setNextUpperBound(Exprs.NUB); |
| 1937 | Dir->setCounters(Exprs.Counters); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 1938 | Dir->setPrivateCounters(Exprs.PrivateCounters); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 1939 | Dir->setInits(Exprs.Inits); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1940 | Dir->setUpdates(Exprs.Updates); |
| 1941 | Dir->setFinals(Exprs.Finals); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1942 | return Dir; |
| 1943 | } |
| 1944 | |
| 1945 | OMPParallelForDirective * |
| 1946 | OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, |
| 1947 | unsigned CollapsedNum, EmptyShell) { |
| 1948 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), |
| 1949 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1950 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1951 | sizeof(Stmt *) * |
| 1952 | numLoopChildren(CollapsedNum, OMPD_parallel_for)); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1953 | return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses); |
| 1954 | } |
| 1955 | |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1956 | OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create( |
| 1957 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
Alexander Musman | a5f070a | 2014-10-01 06:03:56 +0000 | [diff] [blame] | 1958 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1959 | const HelperExprs &Exprs) { |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1960 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), |
| 1961 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1962 | void *Mem = C.Allocate( |
| 1963 | Size + sizeof(OMPClause *) * Clauses.size() + |
| 1964 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1965 | OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective( |
| 1966 | StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1967 | Dir->setClauses(Clauses); |
| 1968 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1969 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1970 | Dir->setLastIteration(Exprs.LastIteration); |
| 1971 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1972 | Dir->setPreCond(Exprs.PreCond); |
Alexey Bataev | ae05c29 | 2015-06-16 11:59:36 +0000 | [diff] [blame] | 1973 | Dir->setCond(Exprs.Cond); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1974 | Dir->setInit(Exprs.Init); |
| 1975 | Dir->setInc(Exprs.Inc); |
| 1976 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1977 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1978 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1979 | Dir->setStrideVariable(Exprs.ST); |
| 1980 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1981 | Dir->setNextLowerBound(Exprs.NLB); |
| 1982 | Dir->setNextUpperBound(Exprs.NUB); |
| 1983 | Dir->setCounters(Exprs.Counters); |
Alexey Bataev | a889917 | 2015-08-06 12:30:57 +0000 | [diff] [blame] | 1984 | Dir->setPrivateCounters(Exprs.PrivateCounters); |
Alexey Bataev | b08f89f | 2015-08-14 12:25:37 +0000 | [diff] [blame] | 1985 | Dir->setInits(Exprs.Inits); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1986 | Dir->setUpdates(Exprs.Updates); |
| 1987 | Dir->setFinals(Exprs.Finals); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1988 | return Dir; |
| 1989 | } |
| 1990 | |
| 1991 | OMPParallelForSimdDirective * |
| 1992 | OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C, |
| 1993 | unsigned NumClauses, |
| 1994 | unsigned CollapsedNum, EmptyShell) { |
| 1995 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), |
| 1996 | llvm::alignOf<OMPClause *>()); |
Alexander Musman | c638868 | 2014-12-15 07:07:06 +0000 | [diff] [blame] | 1997 | void *Mem = C.Allocate( |
| 1998 | Size + sizeof(OMPClause *) * NumClauses + |
| 1999 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 2000 | return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses); |
| 2001 | } |
| 2002 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 2003 | OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( |
| 2004 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 2005 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 2006 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), |
| 2007 | llvm::alignOf<OMPClause *>()); |
| 2008 | void *Mem = |
| 2009 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2010 | OMPParallelSectionsDirective *Dir = |
| 2011 | new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 2012 | Dir->setClauses(Clauses); |
| 2013 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2014 | return Dir; |
| 2015 | } |
| 2016 | |
| 2017 | OMPParallelSectionsDirective * |
| 2018 | OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C, |
| 2019 | unsigned NumClauses, EmptyShell) { |
| 2020 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), |
| 2021 | llvm::alignOf<OMPClause *>()); |
| 2022 | void *Mem = |
| 2023 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2024 | return new (Mem) OMPParallelSectionsDirective(NumClauses); |
| 2025 | } |
| 2026 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 2027 | OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C, |
| 2028 | SourceLocation StartLoc, |
| 2029 | SourceLocation EndLoc, |
| 2030 | ArrayRef<OMPClause *> Clauses, |
| 2031 | Stmt *AssociatedStmt) { |
| 2032 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), |
| 2033 | llvm::alignOf<OMPClause *>()); |
| 2034 | void *Mem = |
| 2035 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2036 | OMPTaskDirective *Dir = |
| 2037 | new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); |
| 2038 | Dir->setClauses(Clauses); |
| 2039 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2040 | return Dir; |
| 2041 | } |
| 2042 | |
| 2043 | OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C, |
| 2044 | unsigned NumClauses, |
| 2045 | EmptyShell) { |
| 2046 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), |
| 2047 | llvm::alignOf<OMPClause *>()); |
| 2048 | void *Mem = |
| 2049 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2050 | return new (Mem) OMPTaskDirective(NumClauses); |
| 2051 | } |
| 2052 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 2053 | OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C, |
| 2054 | SourceLocation StartLoc, |
| 2055 | SourceLocation EndLoc) { |
| 2056 | void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); |
| 2057 | OMPTaskyieldDirective *Dir = |
| 2058 | new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); |
| 2059 | return Dir; |
| 2060 | } |
| 2061 | |
| 2062 | OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C, |
| 2063 | EmptyShell) { |
| 2064 | void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); |
| 2065 | return new (Mem) OMPTaskyieldDirective(); |
| 2066 | } |
| 2067 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 2068 | OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C, |
| 2069 | SourceLocation StartLoc, |
| 2070 | SourceLocation EndLoc) { |
| 2071 | void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); |
| 2072 | OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); |
| 2073 | return Dir; |
| 2074 | } |
| 2075 | |
| 2076 | OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, |
| 2077 | EmptyShell) { |
| 2078 | void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); |
| 2079 | return new (Mem) OMPBarrierDirective(); |
| 2080 | } |
| 2081 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 2082 | OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, |
| 2083 | SourceLocation StartLoc, |
| 2084 | SourceLocation EndLoc) { |
| 2085 | void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); |
| 2086 | OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); |
| 2087 | return Dir; |
| 2088 | } |
| 2089 | |
| 2090 | OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, |
| 2091 | EmptyShell) { |
| 2092 | void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); |
| 2093 | return new (Mem) OMPTaskwaitDirective(); |
| 2094 | } |
| 2095 | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 2096 | OMPTaskgroupDirective *OMPTaskgroupDirective::Create(const ASTContext &C, |
| 2097 | SourceLocation StartLoc, |
| 2098 | SourceLocation EndLoc, |
| 2099 | Stmt *AssociatedStmt) { |
| 2100 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective), |
| 2101 | llvm::alignOf<Stmt *>()); |
| 2102 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 2103 | OMPTaskgroupDirective *Dir = |
| 2104 | new (Mem) OMPTaskgroupDirective(StartLoc, EndLoc); |
| 2105 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2106 | return Dir; |
| 2107 | } |
| 2108 | |
| 2109 | OMPTaskgroupDirective *OMPTaskgroupDirective::CreateEmpty(const ASTContext &C, |
| 2110 | EmptyShell) { |
| 2111 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskgroupDirective), |
| 2112 | llvm::alignOf<Stmt *>()); |
| 2113 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 2114 | return new (Mem) OMPTaskgroupDirective(); |
| 2115 | } |
| 2116 | |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 2117 | OMPCancellationPointDirective *OMPCancellationPointDirective::Create( |
| 2118 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 2119 | OpenMPDirectiveKind CancelRegion) { |
| 2120 | unsigned Size = llvm::RoundUpToAlignment( |
| 2121 | sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>()); |
| 2122 | void *Mem = C.Allocate(Size); |
| 2123 | OMPCancellationPointDirective *Dir = |
| 2124 | new (Mem) OMPCancellationPointDirective(StartLoc, EndLoc); |
| 2125 | Dir->setCancelRegion(CancelRegion); |
| 2126 | return Dir; |
| 2127 | } |
| 2128 | |
| 2129 | OMPCancellationPointDirective * |
| 2130 | OMPCancellationPointDirective::CreateEmpty(const ASTContext &C, EmptyShell) { |
| 2131 | unsigned Size = llvm::RoundUpToAlignment( |
| 2132 | sizeof(OMPCancellationPointDirective), llvm::alignOf<Stmt *>()); |
| 2133 | void *Mem = C.Allocate(Size); |
| 2134 | return new (Mem) OMPCancellationPointDirective(); |
| 2135 | } |
| 2136 | |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 2137 | OMPCancelDirective * |
| 2138 | OMPCancelDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 2139 | SourceLocation EndLoc, |
| 2140 | OpenMPDirectiveKind CancelRegion) { |
| 2141 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective), |
| 2142 | llvm::alignOf<Stmt *>()); |
| 2143 | void *Mem = C.Allocate(Size); |
| 2144 | OMPCancelDirective *Dir = new (Mem) OMPCancelDirective(StartLoc, EndLoc); |
| 2145 | Dir->setCancelRegion(CancelRegion); |
| 2146 | return Dir; |
| 2147 | } |
| 2148 | |
| 2149 | OMPCancelDirective *OMPCancelDirective::CreateEmpty(const ASTContext &C, |
| 2150 | EmptyShell) { |
| 2151 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCancelDirective), |
| 2152 | llvm::alignOf<Stmt *>()); |
| 2153 | void *Mem = C.Allocate(Size); |
| 2154 | return new (Mem) OMPCancelDirective(); |
| 2155 | } |
| 2156 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2157 | OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C, |
| 2158 | SourceLocation StartLoc, |
| 2159 | SourceLocation EndLoc, |
| 2160 | ArrayRef<OMPClause *> Clauses) { |
| 2161 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), |
| 2162 | llvm::alignOf<OMPClause *>()); |
| 2163 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); |
| 2164 | OMPFlushDirective *Dir = |
| 2165 | new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); |
| 2166 | Dir->setClauses(Clauses); |
| 2167 | return Dir; |
| 2168 | } |
| 2169 | |
| 2170 | OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C, |
| 2171 | unsigned NumClauses, |
| 2172 | EmptyShell) { |
| 2173 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), |
| 2174 | llvm::alignOf<OMPClause *>()); |
| 2175 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses); |
| 2176 | return new (Mem) OMPFlushDirective(NumClauses); |
| 2177 | } |
| 2178 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 2179 | OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C, |
| 2180 | SourceLocation StartLoc, |
| 2181 | SourceLocation EndLoc, |
| 2182 | Stmt *AssociatedStmt) { |
| 2183 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), |
| 2184 | llvm::alignOf<Stmt *>()); |
| 2185 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 2186 | OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc); |
| 2187 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2188 | return Dir; |
| 2189 | } |
| 2190 | |
| 2191 | OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C, |
| 2192 | EmptyShell) { |
| 2193 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), |
| 2194 | llvm::alignOf<Stmt *>()); |
| 2195 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 2196 | return new (Mem) OMPOrderedDirective(); |
| 2197 | } |
| 2198 | |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 2199 | OMPAtomicDirective *OMPAtomicDirective::Create( |
| 2200 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 2201 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V, |
| 2202 | Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) { |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2203 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), |
| 2204 | llvm::alignOf<OMPClause *>()); |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 2205 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 2206 | 5 * sizeof(Stmt *)); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2207 | OMPAtomicDirective *Dir = |
| 2208 | new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); |
| 2209 | Dir->setClauses(Clauses); |
| 2210 | Dir->setAssociatedStmt(AssociatedStmt); |
Alexey Bataev | 62cec44 | 2014-11-18 10:14:22 +0000 | [diff] [blame] | 2211 | Dir->setX(X); |
| 2212 | Dir->setV(V); |
| 2213 | Dir->setExpr(E); |
Alexey Bataev | b4505a7 | 2015-03-30 05:20:59 +0000 | [diff] [blame] | 2214 | Dir->setUpdateExpr(UE); |
| 2215 | Dir->IsXLHSInRHSPart = IsXLHSInRHSPart; |
Alexey Bataev | b78ca83 | 2015-04-01 03:33:17 +0000 | [diff] [blame] | 2216 | Dir->IsPostfixUpdate = IsPostfixUpdate; |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2217 | return Dir; |
| 2218 | } |
| 2219 | |
| 2220 | OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C, |
| 2221 | unsigned NumClauses, |
| 2222 | EmptyShell) { |
| 2223 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), |
| 2224 | llvm::alignOf<OMPClause *>()); |
| 2225 | void *Mem = |
Alexey Bataev | 1d160b1 | 2015-03-13 12:27:31 +0000 | [diff] [blame] | 2226 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *)); |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 2227 | return new (Mem) OMPAtomicDirective(NumClauses); |
| 2228 | } |
| 2229 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 2230 | OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C, |
| 2231 | SourceLocation StartLoc, |
| 2232 | SourceLocation EndLoc, |
| 2233 | ArrayRef<OMPClause *> Clauses, |
| 2234 | Stmt *AssociatedStmt) { |
| 2235 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), |
| 2236 | llvm::alignOf<OMPClause *>()); |
| 2237 | void *Mem = |
| 2238 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2239 | OMPTargetDirective *Dir = |
| 2240 | new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); |
| 2241 | Dir->setClauses(Clauses); |
| 2242 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2243 | return Dir; |
| 2244 | } |
| 2245 | |
| 2246 | OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C, |
| 2247 | unsigned NumClauses, |
| 2248 | EmptyShell) { |
| 2249 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), |
| 2250 | llvm::alignOf<OMPClause *>()); |
| 2251 | void *Mem = |
| 2252 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2253 | return new (Mem) OMPTargetDirective(NumClauses); |
| 2254 | } |
| 2255 | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 2256 | OMPTargetDataDirective *OMPTargetDataDirective::Create( |
| 2257 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 2258 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 2259 | void *Mem = |
| 2260 | C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPTargetDataDirective), |
| 2261 | llvm::alignOf<OMPClause *>()) + |
| 2262 | sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2263 | OMPTargetDataDirective *Dir = |
| 2264 | new (Mem) OMPTargetDataDirective(StartLoc, EndLoc, Clauses.size()); |
| 2265 | Dir->setClauses(Clauses); |
| 2266 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2267 | return Dir; |
| 2268 | } |
| 2269 | |
| 2270 | OMPTargetDataDirective *OMPTargetDataDirective::CreateEmpty(const ASTContext &C, |
| 2271 | unsigned N, |
| 2272 | EmptyShell) { |
| 2273 | void *Mem = |
| 2274 | C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPTargetDataDirective), |
| 2275 | llvm::alignOf<OMPClause *>()) + |
| 2276 | sizeof(OMPClause *) * N + sizeof(Stmt *)); |
| 2277 | return new (Mem) OMPTargetDataDirective(N); |
| 2278 | } |
| 2279 | |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 2280 | OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C, |
| 2281 | SourceLocation StartLoc, |
| 2282 | SourceLocation EndLoc, |
| 2283 | ArrayRef<OMPClause *> Clauses, |
| 2284 | Stmt *AssociatedStmt) { |
| 2285 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), |
| 2286 | llvm::alignOf<OMPClause *>()); |
| 2287 | void *Mem = |
| 2288 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2289 | OMPTeamsDirective *Dir = |
| 2290 | new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); |
| 2291 | Dir->setClauses(Clauses); |
| 2292 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2293 | return Dir; |
| 2294 | } |
| 2295 | |
| 2296 | OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, |
| 2297 | unsigned NumClauses, |
| 2298 | EmptyShell) { |
| 2299 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), |
| 2300 | llvm::alignOf<OMPClause *>()); |
| 2301 | void *Mem = |
| 2302 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2303 | return new (Mem) OMPTeamsDirective(NumClauses); |
| 2304 | } |