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