Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- Stmt.cpp - Statement AST Node Implementation ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the Stmt class and statement subclasses. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 14 | #include "clang/AST/ASTContext.h" |
| 15 | #include "clang/AST/ASTDiagnostic.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 16 | #include "clang/AST/ExprCXX.h" |
Steve Naroff | f494b57 | 2008-05-29 21:12:08 +0000 | [diff] [blame] | 17 | #include "clang/AST/ExprObjC.h" |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 18 | #include "clang/AST/Stmt.h" |
Chris Lattner | 16f0049 | 2009-04-26 01:32:48 +0000 | [diff] [blame] | 19 | #include "clang/AST/StmtCXX.h" |
| 20 | #include "clang/AST/StmtObjC.h" |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 21 | #include "clang/AST/StmtOpenMP.h" |
Sebastian Redl | 4b07b29 | 2008-12-22 19:15:10 +0000 | [diff] [blame] | 22 | #include "clang/AST/Type.h" |
Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 23 | #include "clang/Basic/CharInfo.h" |
Chris Lattner | 9bffb07 | 2010-04-23 16:29:58 +0000 | [diff] [blame] | 24 | #include "clang/Basic/TargetInfo.h" |
Benjamin Kramer | a93d0f2 | 2012-12-01 17:12:56 +0000 | [diff] [blame] | 25 | #include "clang/Lex/Token.h" |
Chad Rosier | be3ace8 | 2012-08-24 17:05:45 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 28 | using namespace clang; |
| 29 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 30 | static struct StmtClassNameTable { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 31 | const char *Name; |
| 32 | unsigned Counter; |
| 33 | unsigned Size; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 34 | } StmtClassInfo[Stmt::lastStmtConstant+1]; |
Chris Lattner | 6338135 | 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; |
Sean Hunt | 7381d5c | 2010-05-18 06:22:21 +0000 | [diff] [blame] | 43 | #define ABSTRACT_STMT(STMT) |
Douglas Gregor | f2cad86 | 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); |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 47 | #include "clang/AST/StmtNodes.inc" |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 49 | return StmtClassInfo[E]; |
| 50 | } |
| 51 | |
Craig Topper | 05ed1a0 | 2013-08-18 10:09:15 +0000 | [diff] [blame] | 52 | void *Stmt::operator new(size_t bytes, const ASTContext& C, |
Craig Topper | 5b3ebb4 | 2013-08-18 17:45:38 +0000 | [diff] [blame] | 53 | unsigned alignment) { |
Benjamin Kramer | 2fa67ef | 2012-12-01 15:09:41 +0000 | [diff] [blame] | 54 | return ::operator new(bytes, C, alignment); |
| 55 | } |
| 56 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 57 | const char *Stmt::getStmtClassName() const { |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 58 | return getStmtInfoTableEntry((StmtClass) StmtBits.sClass).Name; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | void Stmt::PrintStats() { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 62 | // Ensure the table is primed. |
| 63 | getStmtInfoTableEntry(Stmt::NullStmtClass); |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 64 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 65 | unsigned sum = 0; |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 66 | llvm::errs() << "\n*** Stmt/Expr Stats:\n"; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 67 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 68 | if (StmtClassInfo[i].Name == nullptr) continue; |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 69 | sum += StmtClassInfo[i].Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 70 | } |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 71 | llvm::errs() << " " << sum << " stmts/exprs total.\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 72 | sum = 0; |
Sean Hunt | 4bfe196 | 2010-05-05 15:24:00 +0000 | [diff] [blame] | 73 | for (int i = 0; i != Stmt::lastStmtConstant+1; i++) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 74 | if (StmtClassInfo[i].Name == nullptr) continue; |
Douglas Gregor | dbe833d | 2009-05-26 14:40:08 +0000 | [diff] [blame] | 75 | if (StmtClassInfo[i].Counter == 0) continue; |
Chandler Carruth | b43c8ec | 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 | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 80 | sum += StmtClassInfo[i].Counter*StmtClassInfo[i].Size; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 81 | } |
Chandler Carruth | b43c8ec | 2011-07-04 06:13:27 +0000 | [diff] [blame] | 82 | |
| 83 | llvm::errs() << "Total bytes = " << sum << "\n"; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void Stmt::addStmtClass(StmtClass s) { |
Chris Lattner | 6338135 | 2007-08-25 01:42:24 +0000 | [diff] [blame] | 87 | ++getStmtInfoTableEntry(s).Counter; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Daniel Dunbar | 02892a6 | 2012-03-05 21:42:49 +0000 | [diff] [blame] | 90 | bool Stmt::StatisticsEnabled = false; |
| 91 | void Stmt::EnableStatistics() { |
| 92 | StatisticsEnabled = true; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 93 | } |
| 94 | |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 95 | Stmt *Stmt::IgnoreImplicit() { |
| 96 | Stmt *s = this; |
| 97 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 98 | if (auto *ewc = dyn_cast<ExprWithCleanups>(s)) |
John McCall | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 99 | s = ewc->getSubExpr(); |
| 100 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [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 | 7e5e5f4 | 2011-07-07 06:58:02 +0000 | [diff] [blame] | 108 | s = ice->getSubExpr(); |
| 109 | |
| 110 | return s; |
| 111 | } |
| 112 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [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 | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 133 | /// \brief Strip off all label-like statements. |
| 134 | /// |
Richard Smith | 534986f | 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 | a1364be | 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 | 534986f | 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 | a1364be | 2011-09-10 00:02:34 +0000 | [diff] [blame] | 146 | else |
| 147 | return S; |
| 148 | } |
| 149 | } |
| 150 | |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 151 | namespace { |
| 152 | struct good {}; |
| 153 | struct bad {}; |
John McCall | f8c7fdb | 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 | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 158 | static inline good is_good(good) { return good(); } |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 159 | |
| 160 | typedef Stmt::child_range children_t(); |
Nick Lewycky | 086eb9f | 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 | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 164 | LLVM_ATTRIBUTE_UNUSED |
Nick Lewycky | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 165 | static inline bad implements_children(children_t Stmt::*) { |
| 166 | return bad(); |
| 167 | } |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 168 | |
Erik Verbruggen | 65d7831 | 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 | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 171 | return good(); |
| 172 | } |
Eli Friedman | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 173 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 65d7831 | 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 | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 182 | LLVM_ATTRIBUTE_UNUSED |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 183 | static inline bad implements_getLocEnd(getLocEnd_t Stmt::*) { |
Nick Lewycky | 086eb9f | 2011-02-09 08:42:57 +0000 | [diff] [blame] | 184 | return bad(); |
| 185 | } |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 186 | |
| 187 | #define ASSERT_IMPLEMENTS_children(type) \ |
Eli Friedman | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 188 | (void) is_good(implements_children(&type::children)) |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 189 | #define ASSERT_IMPLEMENTS_getLocStart(type) \ |
Eli Friedman | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 190 | (void) is_good(implements_getLocStart(&type::getLocStart)) |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 191 | #define ASSERT_IMPLEMENTS_getLocEnd(type) \ |
Eli Friedman | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 192 | (void) is_good(implements_getLocEnd(&type::getLocEnd)) |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | /// Check whether the various Stmt classes implement their member |
| 196 | /// functions. |
Eli Friedman | bafe46f | 2013-09-10 22:57:15 +0000 | [diff] [blame] | 197 | LLVM_ATTRIBUTE_UNUSED |
John McCall | 63c00d7 | 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 | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 202 | ASSERT_IMPLEMENTS_getLocStart(type); \ |
| 203 | ASSERT_IMPLEMENTS_getLocEnd(type); |
John McCall | 63c00d7 | 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 | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 217 | } |
| 218 | |
Erik Verbruggen | 65d7831 | 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 | } |
| 242 | } |
| 243 | |
John McCall | 63c00d7 | 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 | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 250 | return getSourceRangeImpl<type>(this, &type::getSourceRange); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 251 | #include "clang/AST/StmtNodes.inc" |
| 252 | } |
| 253 | llvm_unreachable("unknown statement kind!"); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 254 | } |
| 255 | |
Daniel Dunbar | 90e25a8 | 2012-03-09 15:39:19 +0000 | [diff] [blame] | 256 | SourceLocation Stmt::getLocStart() const { |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 257 | // llvm::errs() << "getLocStart() for " << getStmtClassName() << "\n"; |
Daniel Dunbar | 90e25a8 | 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 | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 263 | return static_cast<const type*>(this)->getLocStart(); |
Daniel Dunbar | 90e25a8 | 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 | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 275 | return static_cast<const type*>(this)->getLocEnd(); |
Daniel Dunbar | 90e25a8 | 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 | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 281 | CompoundStmt::CompoundStmt(const ASTContext &C, ArrayRef<Stmt*> Stmts, |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 282 | SourceLocation LB, SourceLocation RB) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 283 | : Stmt(CompoundStmtClass), LBraceLoc(LB), RBraceLoc(RB) { |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 284 | CompoundStmtBits.NumStmts = Stmts.size(); |
| 285 | assert(CompoundStmtBits.NumStmts == Stmts.size() && |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 286 | "NumStmts doesn't fit in bits of CompoundStmtBits.NumStmts!"); |
| 287 | |
Nico Weber | d36aa35 | 2012-12-29 20:03:39 +0000 | [diff] [blame] | 288 | if (Stmts.size() == 0) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 289 | Body = nullptr; |
Benjamin Kramer | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 290 | return; |
| 291 | } |
| 292 | |
Nico Weber | d36aa35 | 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 | 3a2d0fb | 2012-07-04 17:03:41 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Craig Topper | 8b4b98b | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 297 | void CompoundStmt::setStmts(const ASTContext &C, Stmt **Stmts, |
| 298 | unsigned NumStmts) { |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 299 | if (this->Body) |
| 300 | C.Deallocate(Body); |
John McCall | 8e6285a | 2010-10-26 08:39:16 +0000 | [diff] [blame] | 301 | this->CompoundStmtBits.NumStmts = NumStmts; |
Douglas Gregor | 025452f | 2009-04-17 00:04:06 +0000 | [diff] [blame] | 302 | |
| 303 | Body = new (C) Stmt*[NumStmts]; |
| 304 | memcpy(Body, Stmts, sizeof(Stmt *) * NumStmts); |
| 305 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 306 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 307 | const char *LabelStmt::getName() const { |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 308 | return getDecl()->getIdentifier()->getNameStart(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 311 | AttributedStmt *AttributedStmt::Create(const ASTContext &C, SourceLocation Loc, |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 312 | ArrayRef<const Attr*> Attrs, |
| 313 | Stmt *SubStmt) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 314 | assert(!Attrs.empty() && "Attrs should not be empty"); |
| 315 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * Attrs.size(), |
Alexander Kornienko | 4990890 | 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 | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 320 | AttributedStmt *AttributedStmt::CreateEmpty(const ASTContext &C, |
| 321 | unsigned NumAttrs) { |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 322 | assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 323 | void *Mem = C.Allocate(sizeof(AttributedStmt) + sizeof(Attr *) * NumAttrs, |
Alexander Kornienko | 4990890 | 2012-07-09 10:04:07 +0000 | [diff] [blame] | 324 | llvm::alignOf<AttributedStmt>()); |
| 325 | return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); |
| 326 | } |
| 327 | |
Craig Topper | 8b4b98b | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 328 | std::string AsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | 9252701 | 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 | aba59aa | 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 | 9252701 | 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 | aba59aa | 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 | 9252701 | 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 | aba59aa | 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 | 9252701 | 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 | aba59aa | 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 | 9252701 | 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 | aba59aa | 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 | 9252701 | 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 | aba59aa | 2012-08-28 17:43:23 +0000 | [diff] [blame] | 373 | llvm_unreachable("unknown asm statement kind!"); |
| 374 | } |
| 375 | |
Chad Rosier | c4fb221 | 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 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [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 | 33f0558 | 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 | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 395 | Expr *GCCAsmStmt::getOutputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 396 | return cast<Expr>(Exprs[i]); |
| 397 | } |
Chris Lattner | b327793 | 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 | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 402 | StringRef GCCAsmStmt::getOutputConstraint(unsigned i) const { |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 403 | return getOutputConstraintLiteral(i)->getString(); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 404 | } |
Chris Lattner | b327793 | 2009-03-10 04:59:06 +0000 | [diff] [blame] | 405 | |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 406 | Expr *GCCAsmStmt::getInputExpr(unsigned i) { |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 407 | return cast<Expr>(Exprs[i + NumOutputs]); |
| 408 | } |
Chad Rosier | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 409 | void GCCAsmStmt::setInputExpr(unsigned i, Expr *E) { |
Chris Lattner | 935f0f0 | 2011-02-21 22:09:29 +0000 | [diff] [blame] | 410 | Exprs[i + NumOutputs] = E; |
| 411 | } |
| 412 | |
Chris Lattner | b327793 | 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 | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 415 | StringRef GCCAsmStmt::getInputConstraint(unsigned i) const { |
Anders Carlsson | acb6bcb | 2010-01-30 20:38:10 +0000 | [diff] [blame] | 416 | return getInputConstraintLiteral(i)->getString(); |
Ted Kremenek | ce2fc3a | 2008-10-27 18:40:21 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Craig Topper | 8b4b98b | 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 | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 427 | this->NumOutputs = NumOutputs; |
| 428 | this->NumInputs = NumInputs; |
Anders Carlsson | 966146e | 2010-01-30 23:19:41 +0000 | [diff] [blame] | 429 | this->NumClobbers = NumClobbers; |
| 430 | |
| 431 | unsigned NumExprs = NumOutputs + NumInputs; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 432 | |
Anders Carlsson | 966146e | 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 | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 436 | |
Anders Carlsson | 966146e | 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 | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 440 | |
Anders Carlsson | 966146e | 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 | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 444 | |
Anders Carlsson | 966146e | 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 | cd7d5a9 | 2009-04-17 20:57:14 +0000 | [diff] [blame] | 448 | } |
| 449 | |
Chris Lattner | 10ca96a | 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 | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 453 | int GCCAsmStmt::getNamedOperand(StringRef SymbolicName) const { |
Chris Lattner | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 454 | unsigned NumPlusOperands = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 455 | |
Chris Lattner | 10ca96a | 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 | 10ca96a | 2009-03-10 06:33:24 +0000 | [diff] [blame] | 460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | |
Chris Lattner | 10ca96a | 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 | 458cd9c | 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 | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 473 | unsigned GCCAsmStmt::AnalyzeAsmString(SmallVectorImpl<AsmStringPiece>&Pieces, |
Craig Topper | 8b4b98b | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 474 | const ASTContext &C, unsigned &DiagOffs) const { |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 475 | StringRef Str = getAsmString()->getString(); |
Benjamin Kramer | 2f4eaef | 2010-08-17 12:54:38 +0000 | [diff] [blame] | 476 | const char *StrStart = Str.begin(); |
| 477 | const char *StrEnd = Str.end(); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 478 | const char *CurPtr = StrStart; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 479 | |
Chris Lattner | 458cd9c | 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 | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 484 | for (; CurPtr != StrEnd; ++CurPtr) { |
| 485 | switch (*CurPtr) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 486 | case '$': |
| 487 | Result += "$$"; |
| 488 | break; |
| 489 | default: |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 490 | Result += *CurPtr; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 491 | break; |
| 492 | } |
| 493 | } |
| 494 | Pieces.push_back(AsmStringPiece(Result)); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 495 | return 0; |
Chris Lattner | 458cd9c | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 501 | |
Douglas Gregor | bcfd1f5 | 2011-09-02 00:18:52 +0000 | [diff] [blame] | 502 | bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 503 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 504 | while (1) { |
| 505 | // Done with the string? |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 506 | if (CurPtr == StrEnd) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 507 | if (!CurStringPiece.empty()) |
| 508 | Pieces.push_back(AsmStringPiece(CurStringPiece)); |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 509 | return 0; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 510 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 511 | |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 512 | char CurChar = *CurPtr++; |
Chris Lattner | 018b54e | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 513 | switch (CurChar) { |
| 514 | case '$': CurStringPiece += "$$"; continue; |
Chris Lattner | 9bffb07 | 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 | 018b54e | 2010-04-05 18:44:00 +0000 | [diff] [blame] | 518 | case '%': |
| 519 | break; |
| 520 | default: |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 521 | CurStringPiece += CurChar; |
| 522 | continue; |
| 523 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 524 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 525 | // Escaped "%" character in asm string. |
Chris Lattner | eab8cfb | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 531 | |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 532 | char EscapedChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 533 | if (EscapedChar == '%') { // %% -> % |
| 534 | // Escaped percentage sign. |
| 535 | CurStringPiece += '%'; |
| 536 | continue; |
| 537 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 538 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 539 | if (EscapedChar == '=') { // %= -> Generate an unique ID. |
| 540 | CurStringPiece += "${:uid}"; |
| 541 | continue; |
| 542 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 543 | |
Chris Lattner | 458cd9c | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [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 | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 557 | if (isLetter(EscapedChar)) { |
Benjamin Kramer | bc57f3c | 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 | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 562 | EscapedChar = *CurPtr++; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 563 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 564 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [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 | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 570 | if (isDigit(EscapedChar)) { |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 571 | // %n - Assembler operand n |
Chris Lattner | cafc222 | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 572 | unsigned N = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | |
Chris Lattner | cafc222 | 2009-03-11 22:52:17 +0000 | [diff] [blame] | 574 | --CurPtr; |
Jordan Rose | 3f6f51e | 2013-02-08 22:30:41 +0000 | [diff] [blame] | 575 | while (CurPtr != StrEnd && isDigit(*CurPtr)) |
Chris Lattner | 32a47ed | 2009-03-11 23:09:16 +0000 | [diff] [blame] | 576 | N = N*10 + ((*CurPtr++)-'0'); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 577 | |
Chris Lattner | 8575927 | 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 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [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 | |
| 595 | Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc)); |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 596 | continue; |
| 597 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 598 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 599 | // Handle operands that have asmSymbolicName (e.g., %x[foo]). |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 600 | if (EscapedChar == '[') { |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 601 | DiagOffs = CurPtr-StrStart-1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 602 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 603 | // Find the ']'. |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 604 | const char *NameEnd = (const char*)memchr(CurPtr, ']', StrEnd-CurPtr); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 605 | if (NameEnd == nullptr) |
Chris Lattner | eab8cfb | 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 | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 609 | |
Chris Lattner | 5f9e272 | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 610 | StringRef SymbolicName(CurPtr, NameEnd - CurPtr); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 611 | |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 612 | int N = getNamedOperand(SymbolicName); |
Chris Lattner | eab8cfb | 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 | } |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [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 | |
| 629 | Pieces.push_back(AsmStringPiece(N, Str, BeginLoc, EndLoc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 630 | |
Chris Lattner | eab8cfb | 2009-03-11 00:06:36 +0000 | [diff] [blame] | 631 | CurPtr = NameEnd+1; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 632 | continue; |
| 633 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 634 | |
Chris Lattner | 2ff0f42 | 2009-03-10 23:57:07 +0000 | [diff] [blame] | 635 | DiagOffs = CurPtr-StrStart-1; |
Chris Lattner | 3182db1 | 2009-03-10 23:51:40 +0000 | [diff] [blame] | 636 | return diag::err_asm_invalid_escape; |
Chris Lattner | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 637 | } |
| 638 | } |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 639 | |
| 640 | /// Assemble final IR asm string (GCC-style). |
Craig Topper | 8b4b98b | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 641 | std::string GCCAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | be3ace8 | 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 | df5faf5 | 2012-08-25 00:11:56 +0000 | [diff] [blame] | 644 | SmallVector<GCCAsmStmt::AsmStringPiece, 4> Pieces; |
Chad Rosier | be3ace8 | 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 | 458cd9c | 2009-03-10 23:21:44 +0000 | [diff] [blame] | 660 | |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 661 | /// Assemble final IR asm string (MS-style). |
Craig Topper | 8b4b98b | 2013-08-22 06:02:26 +0000 | [diff] [blame] | 662 | std::string MSAsmStmt::generateAsmString(const ASTContext &C) const { |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 663 | // FIXME: This needs to be translated into the IR string representation. |
Chad Rosier | 00d1637 | 2012-08-28 20:33:49 +0000 | [diff] [blame] | 664 | return AsmStr; |
Chad Rosier | da083b2 | 2012-08-27 20:23:31 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Chad Rosier | 633abb0 | 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 | b0e4cb6 | 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 | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 684 | //===----------------------------------------------------------------------===// |
| 685 | // Constructors |
| 686 | //===----------------------------------------------------------------------===// |
| 687 | |
Craig Topper | 0b86156 | 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 | 066ef86 | 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 | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 696 | |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 697 | unsigned NumExprs = NumOutputs + NumInputs; |
| 698 | |
Anders Carlsson | 966146e | 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 | b235fc2 | 2007-11-22 01:36:19 +0000 | [diff] [blame] | 710 | } |
| 711 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 712 | MSAsmStmt::MSAsmStmt(const ASTContext &C, SourceLocation asmloc, |
Chad Rosier | 058ab17 | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 713 | SourceLocation lbraceloc, bool issimple, bool isvolatile, |
Chad Rosier | e54cba1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 714 | ArrayRef<Token> asmtoks, unsigned numoutputs, |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 715 | unsigned numinputs, |
Chad Rosier | e54cba1 | 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 | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 721 | EndLoc(endloc), NumAsmToks(asmtoks.size()) { |
Chad Rosier | 058ab17 | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 722 | |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 723 | initialize(C, asmstr, asmtoks, constraints, exprs, clobbers); |
| 724 | } |
Chad Rosier | 058ab17 | 2012-08-16 00:06:53 +0000 | [diff] [blame] | 725 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 726 | static StringRef copyIntoContext(const ASTContext &C, StringRef str) { |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 727 | size_t size = str.size(); |
| 728 | char *buffer = new (C) char[size]; |
| 729 | memcpy(buffer, str.data(), size); |
| 730 | return StringRef(buffer, size); |
| 731 | } |
| 732 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 733 | void MSAsmStmt::initialize(const ASTContext &C, StringRef asmstr, |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 734 | ArrayRef<Token> asmtoks, |
| 735 | ArrayRef<StringRef> constraints, |
| 736 | ArrayRef<Expr*> exprs, |
| 737 | ArrayRef<StringRef> clobbers) { |
| 738 | assert(NumAsmToks == asmtoks.size()); |
| 739 | assert(NumClobbers == clobbers.size()); |
| 740 | |
| 741 | unsigned NumExprs = exprs.size(); |
| 742 | assert(NumExprs == NumOutputs + NumInputs); |
| 743 | assert(NumExprs == constraints.size()); |
| 744 | |
| 745 | AsmStr = copyIntoContext(C, asmstr); |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 746 | |
Chad Rosier | 633abb0 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 747 | Exprs = new (C) Stmt*[NumExprs]; |
Chad Rosier | e54cba1 | 2012-10-16 21:55:39 +0000 | [diff] [blame] | 748 | for (unsigned i = 0, e = NumExprs; i != e; ++i) |
| 749 | Exprs[i] = exprs[i]; |
Chad Rosier | 633abb0 | 2012-08-24 00:07:09 +0000 | [diff] [blame] | 750 | |
Chad Rosier | 79efe24 | 2012-08-07 00:29:06 +0000 | [diff] [blame] | 751 | AsmToks = new (C) Token[NumAsmToks]; |
| 752 | for (unsigned i = 0, e = NumAsmToks; i != e; ++i) |
| 753 | AsmToks[i] = asmtoks[i]; |
Chad Rosier | 62f22b8 | 2012-08-08 19:48:07 +0000 | [diff] [blame] | 754 | |
Chad Rosier | 89fb6d7 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 755 | Constraints = new (C) StringRef[NumExprs]; |
| 756 | for (unsigned i = 0, e = NumExprs; i != e; ++i) { |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 757 | Constraints[i] = copyIntoContext(C, constraints[i]); |
Chad Rosier | 89fb6d7 | 2012-08-28 20:28:20 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Chad Rosier | 33c72e1 | 2012-08-10 21:36:25 +0000 | [diff] [blame] | 760 | Clobbers = new (C) StringRef[NumClobbers]; |
Chad Rosier | e790bc3 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 761 | for (unsigned i = 0, e = NumClobbers; i != e; ++i) { |
| 762 | // FIXME: Avoid the allocation/copy if at all possible. |
John McCall | aeeacf7 | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 763 | Clobbers[i] = copyIntoContext(C, clobbers[i]); |
Chad Rosier | e790bc3 | 2012-08-10 21:06:19 +0000 | [diff] [blame] | 764 | } |
Chad Rosier | 8cd64b4 | 2012-06-11 20:47:18 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 767 | ObjCForCollectionStmt::ObjCForCollectionStmt(Stmt *Elem, Expr *Collect, |
| 768 | Stmt *Body, SourceLocation FCL, |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 769 | SourceLocation RPL) |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 770 | : Stmt(ObjCForCollectionStmtClass) { |
| 771 | SubExprs[ELEM] = Elem; |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 772 | SubExprs[COLLECTION] = Collect; |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 773 | SubExprs[BODY] = Body; |
| 774 | ForLoc = FCL; |
| 775 | RParenLoc = RPL; |
| 776 | } |
| 777 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 778 | ObjCAtTryStmt::ObjCAtTryStmt(SourceLocation atTryLoc, Stmt *atTryStmt, |
| 779 | Stmt **CatchStmts, unsigned NumCatchStmts, |
| 780 | Stmt *atFinallyStmt) |
| 781 | : Stmt(ObjCAtTryStmtClass), AtTryLoc(atTryLoc), |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 782 | NumCatchStmts(NumCatchStmts), HasFinally(atFinallyStmt != nullptr) { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 783 | Stmt **Stmts = getStmts(); |
| 784 | Stmts[0] = atTryStmt; |
| 785 | for (unsigned I = 0; I != NumCatchStmts; ++I) |
| 786 | Stmts[I + 1] = CatchStmts[I]; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 787 | |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 788 | if (HasFinally) |
| 789 | Stmts[NumCatchStmts + 1] = atFinallyStmt; |
| 790 | } |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 791 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 792 | ObjCAtTryStmt *ObjCAtTryStmt::Create(const ASTContext &Context, |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 793 | SourceLocation atTryLoc, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 794 | Stmt *atTryStmt, |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 795 | Stmt **CatchStmts, |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 796 | unsigned NumCatchStmts, |
| 797 | Stmt *atFinallyStmt) { |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 798 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 799 | (1 + NumCatchStmts + (atFinallyStmt != nullptr)) * sizeof(Stmt *); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 800 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 801 | return new (Mem) ObjCAtTryStmt(atTryLoc, atTryStmt, CatchStmts, NumCatchStmts, |
| 802 | atFinallyStmt); |
| 803 | } |
Ted Kremenek | ff98102 | 2008-02-01 21:28:59 +0000 | [diff] [blame] | 804 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 805 | ObjCAtTryStmt *ObjCAtTryStmt::CreateEmpty(const ASTContext &Context, |
| 806 | unsigned NumCatchStmts, |
| 807 | bool HasFinally) { |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 808 | unsigned Size = sizeof(ObjCAtTryStmt) + |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 809 | (1 + NumCatchStmts + HasFinally) * sizeof(Stmt *); |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 810 | void *Mem = Context.Allocate(Size, llvm::alignOf<ObjCAtTryStmt>()); |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 811 | return new (Mem) ObjCAtTryStmt(EmptyShell(), NumCatchStmts, HasFinally); |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 812 | } |
Nico Weber | 608b17f | 2008-08-05 23:15:29 +0000 | [diff] [blame] | 813 | |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 814 | SourceLocation ObjCAtTryStmt::getLocEnd() const { |
Douglas Gregor | 8f5e3dd | 2010-04-23 22:50:49 +0000 | [diff] [blame] | 815 | if (HasFinally) |
Erik Verbruggen | 65d7831 | 2012-12-25 14:51:39 +0000 | [diff] [blame] | 816 | return getFinallyStmt()->getLocEnd(); |
| 817 | if (NumCatchStmts) |
| 818 | return getCatchStmt(NumCatchStmts - 1)->getLocEnd(); |
| 819 | return getTryBody()->getLocEnd(); |
Chris Lattner | db6ed17 | 2008-01-30 05:01:46 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 822 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, SourceLocation tryLoc, |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 823 | Stmt *tryBlock, ArrayRef<Stmt*> handlers) { |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 824 | std::size_t Size = sizeof(CXXTryStmt); |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 825 | Size += ((handlers.size() + 1) * sizeof(Stmt)); |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 826 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 827 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 828 | return new (Mem) CXXTryStmt(tryLoc, tryBlock, handlers); |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 831 | CXXTryStmt *CXXTryStmt::Create(const ASTContext &C, EmptyShell Empty, |
Argyrios Kyrtzidis | 7cb45e3 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 832 | unsigned numHandlers) { |
| 833 | std::size_t Size = sizeof(CXXTryStmt); |
| 834 | Size += ((numHandlers + 1) * sizeof(Stmt)); |
| 835 | |
Chris Lattner | 3248854 | 2010-10-30 05:14:06 +0000 | [diff] [blame] | 836 | void *Mem = C.Allocate(Size, llvm::alignOf<CXXTryStmt>()); |
Argyrios Kyrtzidis | 7cb45e3 | 2010-07-22 16:03:56 +0000 | [diff] [blame] | 837 | return new (Mem) CXXTryStmt(Empty, numHandlers); |
| 838 | } |
| 839 | |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 840 | CXXTryStmt::CXXTryStmt(SourceLocation tryLoc, Stmt *tryBlock, |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 841 | ArrayRef<Stmt*> handlers) |
| 842 | : Stmt(CXXTryStmtClass), TryLoc(tryLoc), NumHandlers(handlers.size()) { |
Sam Weinig | a1a396d | 2010-02-03 03:56:39 +0000 | [diff] [blame] | 843 | Stmt **Stmts = reinterpret_cast<Stmt **>(this + 1); |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 844 | Stmts[0] = tryBlock; |
Nico Weber | 07cf58c | 2012-12-29 20:13:03 +0000 | [diff] [blame] | 845 | std::copy(handlers.begin(), handlers.end(), Stmts + 1); |
Sam Weinig | b0e4cb6 | 2010-02-03 02:09:59 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 848 | CXXForRangeStmt::CXXForRangeStmt(DeclStmt *Range, DeclStmt *BeginEndStmt, |
| 849 | Expr *Cond, Expr *Inc, DeclStmt *LoopVar, |
| 850 | Stmt *Body, SourceLocation FL, |
| 851 | SourceLocation CL, SourceLocation RPL) |
| 852 | : Stmt(CXXForRangeStmtClass), ForLoc(FL), ColonLoc(CL), RParenLoc(RPL) { |
| 853 | SubExprs[RANGE] = Range; |
| 854 | SubExprs[BEGINEND] = BeginEndStmt; |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 855 | SubExprs[COND] = Cond; |
| 856 | SubExprs[INC] = Inc; |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 857 | SubExprs[LOOPVAR] = LoopVar; |
| 858 | SubExprs[BODY] = Body; |
| 859 | } |
| 860 | |
| 861 | Expr *CXXForRangeStmt::getRangeInit() { |
| 862 | DeclStmt *RangeStmt = getRangeStmt(); |
| 863 | VarDecl *RangeDecl = dyn_cast_or_null<VarDecl>(RangeStmt->getSingleDecl()); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 864 | assert(RangeDecl && "for-range should have a single var decl"); |
Richard Smith | ad762fc | 2011-04-14 22:09:26 +0000 | [diff] [blame] | 865 | return RangeDecl->getInit(); |
| 866 | } |
| 867 | |
| 868 | const Expr *CXXForRangeStmt::getRangeInit() const { |
| 869 | return const_cast<CXXForRangeStmt*>(this)->getRangeInit(); |
| 870 | } |
| 871 | |
| 872 | VarDecl *CXXForRangeStmt::getLoopVariable() { |
| 873 | Decl *LV = cast<DeclStmt>(getLoopVarStmt())->getSingleDecl(); |
| 874 | assert(LV && "No loop variable in CXXForRangeStmt"); |
| 875 | return cast<VarDecl>(LV); |
| 876 | } |
| 877 | |
| 878 | const VarDecl *CXXForRangeStmt::getLoopVariable() const { |
| 879 | return const_cast<CXXForRangeStmt*>(this)->getLoopVariable(); |
| 880 | } |
| 881 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 882 | IfStmt::IfStmt(const ASTContext &C, SourceLocation IL, VarDecl *var, Expr *cond, |
Argyrios Kyrtzidis | 44aa1f3 | 2010-11-20 02:04:01 +0000 | [diff] [blame] | 883 | Stmt *then, SourceLocation EL, Stmt *elsev) |
| 884 | : Stmt(IfStmtClass), IfLoc(IL), ElseLoc(EL) |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 885 | { |
| 886 | setConditionVariable(C, var); |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 887 | SubExprs[COND] = cond; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 888 | SubExprs[THEN] = then; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 889 | SubExprs[ELSE] = elsev; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | VarDecl *IfStmt::getConditionVariable() const { |
| 893 | if (!SubExprs[VAR]) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 894 | return nullptr; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 895 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 896 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 897 | return cast<VarDecl>(DS->getSingleDecl()); |
| 898 | } |
| 899 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 900 | void IfStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 901 | if (!V) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 902 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 903 | return; |
| 904 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 905 | |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 906 | SourceRange VarRange = V->getSourceRange(); |
| 907 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 908 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 911 | ForStmt::ForStmt(const ASTContext &C, Stmt *Init, Expr *Cond, VarDecl *condVar, |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 912 | Expr *Inc, Stmt *Body, SourceLocation FL, SourceLocation LP, |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 913 | SourceLocation RP) |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 914 | : Stmt(ForStmtClass), ForLoc(FL), LParenLoc(LP), RParenLoc(RP) |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 915 | { |
| 916 | SubExprs[INIT] = Init; |
| 917 | setConditionVariable(C, condVar); |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 918 | SubExprs[COND] = Cond; |
| 919 | SubExprs[INC] = Inc; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 920 | SubExprs[BODY] = Body; |
| 921 | } |
| 922 | |
| 923 | VarDecl *ForStmt::getConditionVariable() const { |
| 924 | if (!SubExprs[CONDVAR]) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 925 | return nullptr; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 926 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 927 | DeclStmt *DS = cast<DeclStmt>(SubExprs[CONDVAR]); |
| 928 | return cast<VarDecl>(DS->getSingleDecl()); |
| 929 | } |
| 930 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 931 | void ForStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 932 | if (!V) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 933 | SubExprs[CONDVAR] = nullptr; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 934 | return; |
| 935 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 936 | |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 937 | SourceRange VarRange = V->getSourceRange(); |
| 938 | SubExprs[CONDVAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 939 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 940 | } |
| 941 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 942 | SwitchStmt::SwitchStmt(const ASTContext &C, VarDecl *Var, Expr *cond) |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 943 | : Stmt(SwitchStmtClass), FirstCase(nullptr, false) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 944 | setConditionVariable(C, Var); |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 945 | SubExprs[COND] = cond; |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 946 | SubExprs[BODY] = nullptr; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | VarDecl *SwitchStmt::getConditionVariable() const { |
| 950 | if (!SubExprs[VAR]) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 951 | return nullptr; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 952 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 953 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 954 | return cast<VarDecl>(DS->getSingleDecl()); |
| 955 | } |
| 956 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 957 | void SwitchStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 958 | if (!V) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 959 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 960 | return; |
| 961 | } |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 962 | |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 963 | SourceRange VarRange = V->getSourceRange(); |
| 964 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 965 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 966 | } |
| 967 | |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 968 | Stmt *SwitchCase::getSubStmt() { |
Chris Lattner | c4002c7 | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 969 | if (isa<CaseStmt>(this)) |
| 970 | return cast<CaseStmt>(this)->getSubStmt(); |
John McCall | 63c00d7 | 2011-02-09 08:16:59 +0000 | [diff] [blame] | 971 | return cast<DefaultStmt>(this)->getSubStmt(); |
| 972 | } |
| 973 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 974 | WhileStmt::WhileStmt(const ASTContext &C, VarDecl *Var, Expr *cond, Stmt *body, |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 975 | SourceLocation WL) |
Chris Lattner | c4002c7 | 2011-02-28 00:18:06 +0000 | [diff] [blame] | 976 | : Stmt(WhileStmtClass) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 977 | setConditionVariable(C, Var); |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 978 | SubExprs[COND] = cond; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 979 | SubExprs[BODY] = body; |
| 980 | WhileLoc = WL; |
| 981 | } |
| 982 | |
| 983 | VarDecl *WhileStmt::getConditionVariable() const { |
| 984 | if (!SubExprs[VAR]) |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 985 | return nullptr; |
Chad Rosier | 0e2a868 | 2012-08-07 23:12:23 +0000 | [diff] [blame] | 986 | |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 987 | DeclStmt *DS = cast<DeclStmt>(SubExprs[VAR]); |
| 988 | return cast<VarDecl>(DS->getSingleDecl()); |
| 989 | } |
| 990 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 991 | void WhileStmt::setConditionVariable(const ASTContext &C, VarDecl *V) { |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 992 | if (!V) { |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 993 | SubExprs[VAR] = nullptr; |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 994 | return; |
| 995 | } |
Daniel Dunbar | 96a0014 | 2012-03-09 18:35:03 +0000 | [diff] [blame] | 996 | |
| 997 | SourceRange VarRange = V->getSourceRange(); |
| 998 | SubExprs[VAR] = new (C) DeclStmt(DeclGroupRef(V), VarRange.getBegin(), |
| 999 | VarRange.getEnd()); |
Douglas Gregor | 43dec6b | 2010-06-21 23:44:13 +0000 | [diff] [blame] | 1000 | } |
| 1001 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1002 | // IndirectGotoStmt |
Chris Lattner | ad8dcf4 | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1003 | LabelDecl *IndirectGotoStmt::getConstantTarget() { |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1004 | if (AddrLabelExpr *E = |
| 1005 | dyn_cast<AddrLabelExpr>(getTarget()->IgnoreParenImpCasts())) |
| 1006 | return E->getLabel(); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1007 | return nullptr; |
John McCall | 95c225d | 2010-10-28 08:53:48 +0000 | [diff] [blame] | 1008 | } |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1009 | |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1010 | // ReturnStmt |
Ted Kremenek | 1060aff | 2008-06-17 03:11:08 +0000 | [diff] [blame] | 1011 | const Expr* ReturnStmt::getRetValue() const { |
| 1012 | return cast_or_null<Expr>(RetExpr); |
| 1013 | } |
| 1014 | Expr* ReturnStmt::getRetValue() { |
| 1015 | return cast_or_null<Expr>(RetExpr); |
Ted Kremenek | 8297777 | 2007-08-24 21:09:09 +0000 | [diff] [blame] | 1016 | } |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1017 | |
| 1018 | SEHTryStmt::SEHTryStmt(bool IsCXXTry, |
| 1019 | SourceLocation TryLoc, |
| 1020 | Stmt *TryBlock, |
| 1021 | Stmt *Handler) |
| 1022 | : Stmt(SEHTryStmtClass), |
| 1023 | IsCXXTry(IsCXXTry), |
| 1024 | TryLoc(TryLoc) |
| 1025 | { |
| 1026 | Children[TRY] = TryBlock; |
| 1027 | Children[HANDLER] = Handler; |
| 1028 | } |
| 1029 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1030 | SEHTryStmt* SEHTryStmt::Create(const ASTContext &C, bool IsCXXTry, |
| 1031 | SourceLocation TryLoc, Stmt *TryBlock, |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1032 | Stmt *Handler) { |
| 1033 | return new(C) SEHTryStmt(IsCXXTry,TryLoc,TryBlock,Handler); |
| 1034 | } |
| 1035 | |
| 1036 | SEHExceptStmt* SEHTryStmt::getExceptHandler() const { |
| 1037 | return dyn_cast<SEHExceptStmt>(getHandler()); |
| 1038 | } |
| 1039 | |
| 1040 | SEHFinallyStmt* SEHTryStmt::getFinallyHandler() const { |
| 1041 | return dyn_cast<SEHFinallyStmt>(getHandler()); |
| 1042 | } |
| 1043 | |
| 1044 | SEHExceptStmt::SEHExceptStmt(SourceLocation Loc, |
| 1045 | Expr *FilterExpr, |
| 1046 | Stmt *Block) |
| 1047 | : Stmt(SEHExceptStmtClass), |
| 1048 | Loc(Loc) |
| 1049 | { |
Pavel Labath | b2b169a | 2013-09-03 14:41:16 +0000 | [diff] [blame] | 1050 | Children[FILTER_EXPR] = FilterExpr; |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1051 | Children[BLOCK] = Block; |
| 1052 | } |
| 1053 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1054 | SEHExceptStmt* SEHExceptStmt::Create(const ASTContext &C, SourceLocation Loc, |
| 1055 | Expr *FilterExpr, Stmt *Block) { |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1056 | return new(C) SEHExceptStmt(Loc,FilterExpr,Block); |
| 1057 | } |
| 1058 | |
| 1059 | SEHFinallyStmt::SEHFinallyStmt(SourceLocation Loc, |
| 1060 | Stmt *Block) |
| 1061 | : Stmt(SEHFinallyStmtClass), |
| 1062 | Loc(Loc), |
| 1063 | Block(Block) |
| 1064 | {} |
| 1065 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1066 | SEHFinallyStmt* SEHFinallyStmt::Create(const ASTContext &C, SourceLocation Loc, |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 1067 | Stmt *Block) { |
| 1068 | return new(C)SEHFinallyStmt(Loc,Block); |
| 1069 | } |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1070 | |
| 1071 | CapturedStmt::Capture *CapturedStmt::getStoredCaptures() const { |
| 1072 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1073 | |
| 1074 | // Offset of the first Capture object. |
| 1075 | unsigned FirstCaptureOffset = |
| 1076 | llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1077 | |
| 1078 | return reinterpret_cast<Capture *>( |
| 1079 | reinterpret_cast<char *>(const_cast<CapturedStmt *>(this)) |
| 1080 | + FirstCaptureOffset); |
| 1081 | } |
| 1082 | |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1083 | CapturedStmt::CapturedStmt(Stmt *S, CapturedRegionKind Kind, |
| 1084 | ArrayRef<Capture> Captures, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1085 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1086 | CapturedDecl *CD, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1087 | RecordDecl *RD) |
| 1088 | : Stmt(CapturedStmtClass), NumCaptures(Captures.size()), |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1089 | CapDeclAndKind(CD, Kind), TheRecordDecl(RD) { |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1090 | assert( S && "null captured statement"); |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1091 | assert(CD && "null captured declaration for captured statement"); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1092 | assert(RD && "null record declaration for captured statement"); |
| 1093 | |
| 1094 | // Copy initialization expressions. |
| 1095 | Stmt **Stored = getStoredStmts(); |
| 1096 | for (unsigned I = 0, N = NumCaptures; I != N; ++I) |
| 1097 | *Stored++ = CaptureInits[I]; |
| 1098 | |
| 1099 | // Copy the statement being captured. |
| 1100 | *Stored = S; |
| 1101 | |
| 1102 | // Copy all Capture objects. |
| 1103 | Capture *Buffer = getStoredCaptures(); |
| 1104 | std::copy(Captures.begin(), Captures.end(), Buffer); |
| 1105 | } |
| 1106 | |
| 1107 | CapturedStmt::CapturedStmt(EmptyShell Empty, unsigned NumCaptures) |
| 1108 | : Stmt(CapturedStmtClass, Empty), NumCaptures(NumCaptures), |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1109 | CapDeclAndKind(nullptr, CR_Default), TheRecordDecl(nullptr) { |
| 1110 | getStoredStmts()[NumCaptures] = nullptr; |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1113 | CapturedStmt *CapturedStmt::Create(const ASTContext &Context, Stmt *S, |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1114 | CapturedRegionKind Kind, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1115 | ArrayRef<Capture> Captures, |
| 1116 | ArrayRef<Expr *> CaptureInits, |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1117 | CapturedDecl *CD, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1118 | RecordDecl *RD) { |
| 1119 | // The layout is |
| 1120 | // |
| 1121 | // ----------------------------------------------------------- |
| 1122 | // | CapturedStmt, Init, ..., Init, S, Capture, ..., Capture | |
| 1123 | // ----------------^-------------------^---------------------- |
| 1124 | // getStoredStmts() getStoredCaptures() |
| 1125 | // |
| 1126 | // where S is the statement being captured. |
| 1127 | // |
| 1128 | assert(CaptureInits.size() == Captures.size() && "wrong number of arguments"); |
| 1129 | |
| 1130 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (Captures.size() + 1); |
| 1131 | if (!Captures.empty()) { |
| 1132 | // Realign for the following Capture array. |
| 1133 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1134 | Size += sizeof(Capture) * Captures.size(); |
| 1135 | } |
| 1136 | |
| 1137 | void *Mem = Context.Allocate(Size); |
Wei Pan | 9fd6b8f | 2013-05-04 03:59:06 +0000 | [diff] [blame] | 1138 | return new (Mem) CapturedStmt(S, Kind, Captures, CaptureInits, CD, RD); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1141 | CapturedStmt *CapturedStmt::CreateDeserialized(const ASTContext &Context, |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1142 | unsigned NumCaptures) { |
| 1143 | unsigned Size = sizeof(CapturedStmt) + sizeof(Stmt *) * (NumCaptures + 1); |
| 1144 | if (NumCaptures > 0) { |
| 1145 | // Realign for the following Capture array. |
| 1146 | Size = llvm::RoundUpToAlignment(Size, llvm::alignOf<Capture>()); |
| 1147 | Size += sizeof(Capture) * NumCaptures; |
| 1148 | } |
| 1149 | |
| 1150 | void *Mem = Context.Allocate(Size); |
| 1151 | return new (Mem) CapturedStmt(EmptyShell(), NumCaptures); |
| 1152 | } |
| 1153 | |
| 1154 | Stmt::child_range CapturedStmt::children() { |
Tareq A. Siraj | 6afcf88 | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1155 | // Children are captured field initilizers. |
| 1156 | return child_range(getStoredStmts(), getStoredStmts() + NumCaptures); |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | bool CapturedStmt::capturesVariable(const VarDecl *Var) const { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1160 | for (const auto &I : captures()) { |
| 1161 | if (!I.capturesVariable()) |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1162 | continue; |
| 1163 | |
| 1164 | // This does not handle variable redeclarations. This should be |
| 1165 | // extended to capture variables with redeclarations, for example |
| 1166 | // a thread-private variable in OpenMP. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1167 | if (I.getCapturedVar() == Var) |
Tareq A. Siraj | 051303c | 2013-04-16 18:53:08 +0000 | [diff] [blame] | 1168 | return true; |
| 1169 | } |
| 1170 | |
| 1171 | return false; |
| 1172 | } |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1173 | |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1174 | StmtRange OMPClause::children() { |
| 1175 | switch(getClauseKind()) { |
| 1176 | default : break; |
| 1177 | #define OPENMP_CLAUSE(Name, Class) \ |
| 1178 | case OMPC_ ## Name : return static_cast<Class *>(this)->children(); |
| 1179 | #include "clang/Basic/OpenMPKinds.def" |
| 1180 | } |
| 1181 | llvm_unreachable("unknown OMPClause"); |
| 1182 | } |
| 1183 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1184 | void OMPPrivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1185 | assert(VL.size() == varlist_size() && |
| 1186 | "Number of private copies is not the same as the preallocated buffer"); |
| 1187 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1188 | } |
| 1189 | |
| 1190 | OMPPrivateClause * |
| 1191 | OMPPrivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1192 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1193 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL) { |
| 1194 | // Allocate space for private variables and initializer expressions. |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1195 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1196 | llvm::alignOf<Expr *>()) + |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1197 | 2 * sizeof(Expr *) * VL.size()); |
| 1198 | OMPPrivateClause *Clause = |
| 1199 | new (Mem) OMPPrivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1200 | Clause->setVarRefs(VL); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1201 | Clause->setPrivateCopies(PrivateVL); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1202 | return Clause; |
| 1203 | } |
| 1204 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1205 | OMPPrivateClause *OMPPrivateClause::CreateEmpty(const ASTContext &C, |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1206 | unsigned N) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1207 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPPrivateClause), |
| 1208 | llvm::alignOf<Expr *>()) + |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1209 | 2 * sizeof(Expr *) * N); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1210 | return new (Mem) OMPPrivateClause(N); |
| 1211 | } |
| 1212 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1213 | void OMPFirstprivateClause::setPrivateCopies(ArrayRef<Expr *> VL) { |
| 1214 | assert(VL.size() == varlist_size() && |
| 1215 | "Number of private copies is not the same as the preallocated buffer"); |
| 1216 | std::copy(VL.begin(), VL.end(), varlist_end()); |
| 1217 | } |
| 1218 | |
| 1219 | void OMPFirstprivateClause::setInits(ArrayRef<Expr *> VL) { |
| 1220 | assert(VL.size() == varlist_size() && |
| 1221 | "Number of inits is not the same as the preallocated buffer"); |
| 1222 | std::copy(VL.begin(), VL.end(), getPrivateCopies().end()); |
| 1223 | } |
| 1224 | |
| 1225 | OMPFirstprivateClause * |
| 1226 | OMPFirstprivateClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1227 | SourceLocation LParenLoc, SourceLocation EndLoc, |
| 1228 | ArrayRef<Expr *> VL, ArrayRef<Expr *> PrivateVL, |
| 1229 | ArrayRef<Expr *> InitVL) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1230 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1231 | llvm::alignOf<Expr *>()) + |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1232 | 3 * sizeof(Expr *) * VL.size()); |
| 1233 | OMPFirstprivateClause *Clause = |
| 1234 | new (Mem) OMPFirstprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
Alexey Bataev | d195bc3 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1235 | Clause->setVarRefs(VL); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1236 | Clause->setPrivateCopies(PrivateVL); |
| 1237 | Clause->setInits(InitVL); |
Alexey Bataev | d195bc3 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1238 | return Clause; |
| 1239 | } |
| 1240 | |
| 1241 | OMPFirstprivateClause *OMPFirstprivateClause::CreateEmpty(const ASTContext &C, |
| 1242 | unsigned N) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1243 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFirstprivateClause), |
| 1244 | llvm::alignOf<Expr *>()) + |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1245 | 3 * sizeof(Expr *) * N); |
Alexey Bataev | d195bc3 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1246 | return new (Mem) OMPFirstprivateClause(N); |
| 1247 | } |
| 1248 | |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1249 | void OMPLastprivateClause::setPrivateCopies(ArrayRef<Expr *> PrivateCopies) { |
| 1250 | assert(PrivateCopies.size() == varlist_size() && |
| 1251 | "Number of private copies is not the same as the preallocated buffer"); |
| 1252 | std::copy(PrivateCopies.begin(), PrivateCopies.end(), varlist_end()); |
| 1253 | } |
| 1254 | |
| 1255 | void OMPLastprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 1256 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 1257 | "not the same as the " |
| 1258 | "preallocated buffer"); |
| 1259 | std::copy(SrcExprs.begin(), SrcExprs.end(), getPrivateCopies().end()); |
| 1260 | } |
| 1261 | |
| 1262 | void OMPLastprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 1263 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 1264 | "expressions is not the same as " |
| 1265 | "the preallocated buffer"); |
| 1266 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 1267 | } |
| 1268 | |
| 1269 | void OMPLastprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 1270 | assert(AssignmentOps.size() == varlist_size() && |
| 1271 | "Number of assignment expressions is not the same as the preallocated " |
| 1272 | "buffer"); |
| 1273 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 1274 | getDestinationExprs().end()); |
| 1275 | } |
| 1276 | |
| 1277 | OMPLastprivateClause *OMPLastprivateClause::Create( |
| 1278 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1279 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 1280 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1281 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1282 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1283 | 5 * sizeof(Expr *) * VL.size()); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1284 | OMPLastprivateClause *Clause = |
| 1285 | new (Mem) OMPLastprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1286 | Clause->setVarRefs(VL); |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1287 | Clause->setSourceExprs(SrcExprs); |
| 1288 | Clause->setDestinationExprs(DstExprs); |
| 1289 | Clause->setAssignmentOps(AssignmentOps); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1290 | return Clause; |
| 1291 | } |
| 1292 | |
| 1293 | OMPLastprivateClause *OMPLastprivateClause::CreateEmpty(const ASTContext &C, |
| 1294 | unsigned N) { |
| 1295 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLastprivateClause), |
| 1296 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1297 | 5 * sizeof(Expr *) * N); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1298 | return new (Mem) OMPLastprivateClause(N); |
| 1299 | } |
| 1300 | |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1301 | OMPSharedClause *OMPSharedClause::Create(const ASTContext &C, |
| 1302 | SourceLocation StartLoc, |
| 1303 | SourceLocation LParenLoc, |
| 1304 | SourceLocation EndLoc, |
| 1305 | ArrayRef<Expr *> VL) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1306 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1307 | llvm::alignOf<Expr *>()) + |
| 1308 | sizeof(Expr *) * VL.size()); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1309 | OMPSharedClause *Clause = new (Mem) OMPSharedClause(StartLoc, LParenLoc, |
| 1310 | EndLoc, VL.size()); |
| 1311 | Clause->setVarRefs(VL); |
| 1312 | return Clause; |
| 1313 | } |
| 1314 | |
| 1315 | OMPSharedClause *OMPSharedClause::CreateEmpty(const ASTContext &C, |
| 1316 | unsigned N) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1317 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPSharedClause), |
| 1318 | llvm::alignOf<Expr *>()) + |
| 1319 | sizeof(Expr *) * N); |
Alexey Bataev | 0c01835 | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1320 | return new (Mem) OMPSharedClause(N); |
| 1321 | } |
| 1322 | |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1323 | void OMPLinearClause::setInits(ArrayRef<Expr *> IL) { |
| 1324 | assert(IL.size() == varlist_size() && |
| 1325 | "Number of inits is not the same as the preallocated buffer"); |
| 1326 | std::copy(IL.begin(), IL.end(), varlist_end()); |
| 1327 | } |
| 1328 | |
| 1329 | void OMPLinearClause::setUpdates(ArrayRef<Expr *> UL) { |
| 1330 | assert(UL.size() == varlist_size() && |
| 1331 | "Number of updates is not the same as the preallocated buffer"); |
| 1332 | std::copy(UL.begin(), UL.end(), getInits().end()); |
| 1333 | } |
| 1334 | |
| 1335 | void OMPLinearClause::setFinals(ArrayRef<Expr *> FL) { |
| 1336 | assert(FL.size() == varlist_size() && |
| 1337 | "Number of final updates is not the same as the preallocated buffer"); |
| 1338 | std::copy(FL.begin(), FL.end(), getUpdates().end()); |
| 1339 | } |
| 1340 | |
| 1341 | OMPLinearClause * |
| 1342 | OMPLinearClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1343 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1344 | SourceLocation EndLoc, ArrayRef<Expr *> VL, |
| 1345 | ArrayRef<Expr *> IL, Expr *Step, Expr *CalcStep) { |
| 1346 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 1347 | // (Step and CalcStep). |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1348 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1349 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1350 | (4 * VL.size() + 2) * sizeof(Expr *)); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1351 | OMPLinearClause *Clause = new (Mem) |
| 1352 | OMPLinearClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1353 | Clause->setVarRefs(VL); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1354 | Clause->setInits(IL); |
| 1355 | // Fill update and final expressions with zeroes, they are provided later, |
| 1356 | // after the directive construction. |
| 1357 | std::fill(Clause->getInits().end(), Clause->getInits().end() + VL.size(), |
| 1358 | nullptr); |
| 1359 | std::fill(Clause->getUpdates().end(), Clause->getUpdates().end() + VL.size(), |
| 1360 | nullptr); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1361 | Clause->setStep(Step); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1362 | Clause->setCalcStep(CalcStep); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1363 | return Clause; |
| 1364 | } |
| 1365 | |
| 1366 | OMPLinearClause *OMPLinearClause::CreateEmpty(const ASTContext &C, |
| 1367 | unsigned NumVars) { |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1368 | // Allocate space for 4 lists (Vars, Inits, Updates, Finals) and 2 expressions |
| 1369 | // (Step and CalcStep). |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1370 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPLinearClause), |
| 1371 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1372 | (4 * NumVars + 2) * sizeof(Expr *)); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 1373 | return new (Mem) OMPLinearClause(NumVars); |
| 1374 | } |
| 1375 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1376 | OMPAlignedClause * |
| 1377 | OMPAlignedClause::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1378 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1379 | SourceLocation EndLoc, ArrayRef<Expr *> VL, Expr *A) { |
| 1380 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1381 | llvm::alignOf<Expr *>()) + |
| 1382 | sizeof(Expr *) * (VL.size() + 1)); |
| 1383 | OMPAlignedClause *Clause = new (Mem) |
| 1384 | OMPAlignedClause(StartLoc, LParenLoc, ColonLoc, EndLoc, VL.size()); |
| 1385 | Clause->setVarRefs(VL); |
| 1386 | Clause->setAlignment(A); |
| 1387 | return Clause; |
| 1388 | } |
| 1389 | |
| 1390 | OMPAlignedClause *OMPAlignedClause::CreateEmpty(const ASTContext &C, |
| 1391 | unsigned NumVars) { |
| 1392 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPAlignedClause), |
| 1393 | llvm::alignOf<Expr *>()) + |
| 1394 | sizeof(Expr *) * (NumVars + 1)); |
| 1395 | return new (Mem) OMPAlignedClause(NumVars); |
| 1396 | } |
| 1397 | |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1398 | void OMPCopyinClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 1399 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 1400 | "not the same as the " |
| 1401 | "preallocated buffer"); |
| 1402 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 1403 | } |
| 1404 | |
| 1405 | void OMPCopyinClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 1406 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 1407 | "expressions is not the same as " |
| 1408 | "the preallocated buffer"); |
| 1409 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 1410 | } |
| 1411 | |
| 1412 | void OMPCopyinClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 1413 | assert(AssignmentOps.size() == varlist_size() && |
| 1414 | "Number of assignment expressions is not the same as the preallocated " |
| 1415 | "buffer"); |
| 1416 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 1417 | getDestinationExprs().end()); |
| 1418 | } |
| 1419 | |
| 1420 | OMPCopyinClause *OMPCopyinClause::Create( |
| 1421 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1422 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 1423 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1424 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1425 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1426 | 4 * sizeof(Expr *) * VL.size()); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1427 | OMPCopyinClause *Clause = new (Mem) OMPCopyinClause(StartLoc, LParenLoc, |
| 1428 | EndLoc, VL.size()); |
| 1429 | Clause->setVarRefs(VL); |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1430 | Clause->setSourceExprs(SrcExprs); |
| 1431 | Clause->setDestinationExprs(DstExprs); |
| 1432 | Clause->setAssignmentOps(AssignmentOps); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1433 | return Clause; |
| 1434 | } |
| 1435 | |
| 1436 | OMPCopyinClause *OMPCopyinClause::CreateEmpty(const ASTContext &C, |
| 1437 | unsigned N) { |
| 1438 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyinClause), |
| 1439 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1440 | 4 * sizeof(Expr *) * N); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1441 | return new (Mem) OMPCopyinClause(N); |
| 1442 | } |
| 1443 | |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1444 | void OMPCopyprivateClause::setSourceExprs(ArrayRef<Expr *> SrcExprs) { |
| 1445 | assert(SrcExprs.size() == varlist_size() && "Number of source expressions is " |
| 1446 | "not the same as the " |
| 1447 | "preallocated buffer"); |
| 1448 | std::copy(SrcExprs.begin(), SrcExprs.end(), varlist_end()); |
| 1449 | } |
| 1450 | |
| 1451 | void OMPCopyprivateClause::setDestinationExprs(ArrayRef<Expr *> DstExprs) { |
| 1452 | assert(DstExprs.size() == varlist_size() && "Number of destination " |
| 1453 | "expressions is not the same as " |
| 1454 | "the preallocated buffer"); |
| 1455 | std::copy(DstExprs.begin(), DstExprs.end(), getSourceExprs().end()); |
| 1456 | } |
| 1457 | |
| 1458 | void OMPCopyprivateClause::setAssignmentOps(ArrayRef<Expr *> AssignmentOps) { |
| 1459 | assert(AssignmentOps.size() == varlist_size() && |
| 1460 | "Number of assignment expressions is not the same as the preallocated " |
| 1461 | "buffer"); |
| 1462 | std::copy(AssignmentOps.begin(), AssignmentOps.end(), |
| 1463 | getDestinationExprs().end()); |
| 1464 | } |
| 1465 | |
| 1466 | OMPCopyprivateClause *OMPCopyprivateClause::Create( |
| 1467 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1468 | SourceLocation EndLoc, ArrayRef<Expr *> VL, ArrayRef<Expr *> SrcExprs, |
| 1469 | ArrayRef<Expr *> DstExprs, ArrayRef<Expr *> AssignmentOps) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1470 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), |
| 1471 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1472 | 4 * sizeof(Expr *) * VL.size()); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1473 | OMPCopyprivateClause *Clause = |
| 1474 | new (Mem) OMPCopyprivateClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1475 | Clause->setVarRefs(VL); |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1476 | Clause->setSourceExprs(SrcExprs); |
| 1477 | Clause->setDestinationExprs(DstExprs); |
| 1478 | Clause->setAssignmentOps(AssignmentOps); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1479 | return Clause; |
| 1480 | } |
| 1481 | |
| 1482 | OMPCopyprivateClause *OMPCopyprivateClause::CreateEmpty(const ASTContext &C, |
| 1483 | unsigned N) { |
| 1484 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPCopyprivateClause), |
| 1485 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 1486 | 4 * sizeof(Expr *) * N); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1487 | return new (Mem) OMPCopyprivateClause(N); |
| 1488 | } |
| 1489 | |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1490 | void OMPExecutableDirective::setClauses(ArrayRef<OMPClause *> Clauses) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1491 | assert(Clauses.size() == getNumClauses() && |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1492 | "Number of clauses is not the same as the preallocated buffer"); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1493 | std::copy(Clauses.begin(), Clauses.end(), getClauses().begin()); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1496 | void OMPLoopDirective::setCounters(ArrayRef<Expr *> A) { |
| 1497 | assert(A.size() == getCollapsedNumber() && |
| 1498 | "Number of loop counters is not the same as the collapsed number"); |
| 1499 | std::copy(A.begin(), A.end(), getCounters().begin()); |
| 1500 | } |
| 1501 | |
| 1502 | void OMPLoopDirective::setUpdates(ArrayRef<Expr *> A) { |
| 1503 | assert(A.size() == getCollapsedNumber() && |
| 1504 | "Number of counter updates is not the same as the collapsed number"); |
| 1505 | std::copy(A.begin(), A.end(), getUpdates().begin()); |
| 1506 | } |
| 1507 | |
| 1508 | void OMPLoopDirective::setFinals(ArrayRef<Expr *> A) { |
| 1509 | assert(A.size() == getCollapsedNumber() && |
| 1510 | "Number of counter finals is not the same as the collapsed number"); |
| 1511 | std::copy(A.begin(), A.end(), getFinals().begin()); |
| 1512 | } |
| 1513 | |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1514 | void OMPReductionClause::setLHSExprs(ArrayRef<Expr *> LHSExprs) { |
| 1515 | assert( |
| 1516 | LHSExprs.size() == varlist_size() && |
| 1517 | "Number of LHS expressions is not the same as the preallocated buffer"); |
| 1518 | std::copy(LHSExprs.begin(), LHSExprs.end(), varlist_end()); |
| 1519 | } |
| 1520 | |
| 1521 | void OMPReductionClause::setRHSExprs(ArrayRef<Expr *> RHSExprs) { |
| 1522 | assert( |
| 1523 | RHSExprs.size() == varlist_size() && |
| 1524 | "Number of RHS expressions is not the same as the preallocated buffer"); |
| 1525 | std::copy(RHSExprs.begin(), RHSExprs.end(), getLHSExprs().end()); |
| 1526 | } |
| 1527 | |
| 1528 | void OMPReductionClause::setReductionOps(ArrayRef<Expr *> ReductionOps) { |
| 1529 | assert(ReductionOps.size() == varlist_size() && "Number of reduction " |
| 1530 | "expressions is not the same " |
| 1531 | "as the preallocated buffer"); |
| 1532 | std::copy(ReductionOps.begin(), ReductionOps.end(), getRHSExprs().end()); |
| 1533 | } |
| 1534 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1535 | OMPReductionClause *OMPReductionClause::Create( |
| 1536 | const ASTContext &C, SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1537 | SourceLocation EndLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VL, |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1538 | NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, |
| 1539 | ArrayRef<Expr *> LHSExprs, ArrayRef<Expr *> RHSExprs, |
| 1540 | ArrayRef<Expr *> ReductionOps) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1541 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1542 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1543 | 4 * sizeof(Expr *) * VL.size()); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1544 | OMPReductionClause *Clause = new (Mem) OMPReductionClause( |
| 1545 | StartLoc, LParenLoc, EndLoc, ColonLoc, VL.size(), QualifierLoc, NameInfo); |
| 1546 | Clause->setVarRefs(VL); |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1547 | Clause->setLHSExprs(LHSExprs); |
| 1548 | Clause->setRHSExprs(RHSExprs); |
| 1549 | Clause->setReductionOps(ReductionOps); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1550 | return Clause; |
| 1551 | } |
| 1552 | |
| 1553 | OMPReductionClause *OMPReductionClause::CreateEmpty(const ASTContext &C, |
| 1554 | unsigned N) { |
| 1555 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPReductionClause), |
| 1556 | llvm::alignOf<Expr *>()) + |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 1557 | 4 * sizeof(Expr *) * N); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1558 | return new (Mem) OMPReductionClause(N); |
| 1559 | } |
| 1560 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1561 | OMPFlushClause *OMPFlushClause::Create(const ASTContext &C, |
| 1562 | SourceLocation StartLoc, |
| 1563 | SourceLocation LParenLoc, |
| 1564 | SourceLocation EndLoc, |
| 1565 | ArrayRef<Expr *> VL) { |
| 1566 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), |
| 1567 | llvm::alignOf<Expr *>()) + |
| 1568 | sizeof(Expr *) * VL.size()); |
| 1569 | OMPFlushClause *Clause = |
| 1570 | new (Mem) OMPFlushClause(StartLoc, LParenLoc, EndLoc, VL.size()); |
| 1571 | Clause->setVarRefs(VL); |
| 1572 | return Clause; |
| 1573 | } |
| 1574 | |
| 1575 | OMPFlushClause *OMPFlushClause::CreateEmpty(const ASTContext &C, unsigned N) { |
| 1576 | void *Mem = C.Allocate(llvm::RoundUpToAlignment(sizeof(OMPFlushClause), |
| 1577 | llvm::alignOf<Expr *>()) + |
| 1578 | sizeof(Expr *) * N); |
| 1579 | return new (Mem) OMPFlushClause(N); |
| 1580 | } |
| 1581 | |
| 1582 | const OMPClause * |
| 1583 | OMPExecutableDirective::getSingleClause(OpenMPClauseKind K) const { |
| 1584 | auto ClauseFilter = |
| 1585 | [=](const OMPClause *C) -> bool { return C->getClauseKind() == K; }; |
| 1586 | OMPExecutableDirective::filtered_clause_iterator<decltype(ClauseFilter)> I( |
| 1587 | clauses(), ClauseFilter); |
| 1588 | |
| 1589 | if (I) { |
| 1590 | auto *Clause = *I; |
| 1591 | assert(!++I && "There are at least 2 clauses of the specified kind"); |
| 1592 | return Clause; |
| 1593 | } |
| 1594 | return nullptr; |
| 1595 | } |
| 1596 | |
Craig Topper | 9b9a5bf | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1597 | OMPParallelDirective *OMPParallelDirective::Create( |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1598 | const ASTContext &C, |
Craig Topper | 9b9a5bf | 2013-08-21 04:01:01 +0000 | [diff] [blame] | 1599 | SourceLocation StartLoc, |
| 1600 | SourceLocation EndLoc, |
| 1601 | ArrayRef<OMPClause *> Clauses, |
| 1602 | Stmt *AssociatedStmt) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1603 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1604 | llvm::alignOf<OMPClause *>()); |
| 1605 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1606 | sizeof(Stmt *)); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1607 | OMPParallelDirective *Dir = new (Mem) OMPParallelDirective(StartLoc, EndLoc, |
| 1608 | Clauses.size()); |
| 1609 | Dir->setClauses(Clauses); |
| 1610 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1611 | return Dir; |
| 1612 | } |
| 1613 | |
Craig Topper | 0b86156 | 2013-08-22 05:28:54 +0000 | [diff] [blame] | 1614 | OMPParallelDirective *OMPParallelDirective::CreateEmpty(const ASTContext &C, |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1615 | unsigned NumClauses, |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1616 | EmptyShell) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1617 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelDirective), |
| 1618 | llvm::alignOf<OMPClause *>()); |
| 1619 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1620 | sizeof(Stmt *)); |
| 1621 | return new (Mem) OMPParallelDirective(NumClauses); |
Alexey Bataev | 4fa7eab | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1622 | } |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1623 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1624 | OMPSimdDirective * |
| 1625 | OMPSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1626 | SourceLocation EndLoc, unsigned CollapsedNum, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1627 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1628 | const HelperExprs &Exprs) { |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1629 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1630 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1631 | void *Mem = |
| 1632 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1633 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1634 | OMPSimdDirective *Dir = new (Mem) |
| 1635 | OMPSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1636 | Dir->setClauses(Clauses); |
| 1637 | Dir->setAssociatedStmt(AssociatedStmt); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1638 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1639 | Dir->setLastIteration(Exprs.LastIteration); |
| 1640 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1641 | Dir->setPreCond(Exprs.PreCond); |
| 1642 | Dir->setCond(Exprs.Cond, Exprs.SeparatedCond); |
| 1643 | Dir->setInit(Exprs.Init); |
| 1644 | Dir->setInc(Exprs.Inc); |
| 1645 | Dir->setCounters(Exprs.Counters); |
| 1646 | Dir->setUpdates(Exprs.Updates); |
| 1647 | Dir->setFinals(Exprs.Finals); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1648 | return Dir; |
| 1649 | } |
| 1650 | |
| 1651 | OMPSimdDirective *OMPSimdDirective::CreateEmpty(const ASTContext &C, |
| 1652 | unsigned NumClauses, |
| 1653 | unsigned CollapsedNum, |
| 1654 | EmptyShell) { |
| 1655 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSimdDirective), |
| 1656 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1657 | void *Mem = |
| 1658 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1659 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_simd)); |
Stephen Hines | 651f13c | 2014-04-23 16:59:28 -0700 | [diff] [blame] | 1660 | return new (Mem) OMPSimdDirective(CollapsedNum, NumClauses); |
| 1661 | } |
| 1662 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1663 | OMPForDirective * |
| 1664 | OMPForDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1665 | SourceLocation EndLoc, unsigned CollapsedNum, |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1666 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1667 | const HelperExprs &Exprs) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1668 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1669 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1670 | void *Mem = |
| 1671 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1672 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1673 | OMPForDirective *Dir = |
| 1674 | new (Mem) OMPForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1675 | Dir->setClauses(Clauses); |
| 1676 | Dir->setAssociatedStmt(AssociatedStmt); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1677 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1678 | Dir->setLastIteration(Exprs.LastIteration); |
| 1679 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1680 | Dir->setPreCond(Exprs.PreCond); |
| 1681 | Dir->setCond(Exprs.Cond, Exprs.SeparatedCond); |
| 1682 | Dir->setInit(Exprs.Init); |
| 1683 | Dir->setInc(Exprs.Inc); |
| 1684 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1685 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1686 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1687 | Dir->setStrideVariable(Exprs.ST); |
| 1688 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1689 | Dir->setNextLowerBound(Exprs.NLB); |
| 1690 | Dir->setNextUpperBound(Exprs.NUB); |
| 1691 | Dir->setCounters(Exprs.Counters); |
| 1692 | Dir->setUpdates(Exprs.Updates); |
| 1693 | Dir->setFinals(Exprs.Finals); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1694 | return Dir; |
| 1695 | } |
| 1696 | |
| 1697 | OMPForDirective *OMPForDirective::CreateEmpty(const ASTContext &C, |
| 1698 | unsigned NumClauses, |
| 1699 | unsigned CollapsedNum, |
| 1700 | EmptyShell) { |
| 1701 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForDirective), |
| 1702 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1703 | void *Mem = |
| 1704 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1705 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for)); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1706 | return new (Mem) OMPForDirective(CollapsedNum, NumClauses); |
| 1707 | } |
| 1708 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1709 | OMPForSimdDirective * |
| 1710 | OMPForSimdDirective::Create(const ASTContext &C, SourceLocation StartLoc, |
| 1711 | SourceLocation EndLoc, unsigned CollapsedNum, |
| 1712 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
| 1713 | const HelperExprs &Exprs) { |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1714 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), |
| 1715 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1716 | void *Mem = |
| 1717 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
| 1718 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1719 | OMPForSimdDirective *Dir = new (Mem) |
| 1720 | OMPForSimdDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1721 | Dir->setClauses(Clauses); |
| 1722 | Dir->setAssociatedStmt(AssociatedStmt); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1723 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1724 | Dir->setLastIteration(Exprs.LastIteration); |
| 1725 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1726 | Dir->setPreCond(Exprs.PreCond); |
| 1727 | Dir->setCond(Exprs.Cond, Exprs.SeparatedCond); |
| 1728 | Dir->setInit(Exprs.Init); |
| 1729 | Dir->setInc(Exprs.Inc); |
| 1730 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1731 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1732 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1733 | Dir->setStrideVariable(Exprs.ST); |
| 1734 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1735 | Dir->setNextLowerBound(Exprs.NLB); |
| 1736 | Dir->setNextUpperBound(Exprs.NUB); |
| 1737 | Dir->setCounters(Exprs.Counters); |
| 1738 | Dir->setUpdates(Exprs.Updates); |
| 1739 | Dir->setFinals(Exprs.Finals); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1740 | return Dir; |
| 1741 | } |
| 1742 | |
| 1743 | OMPForSimdDirective *OMPForSimdDirective::CreateEmpty(const ASTContext &C, |
| 1744 | unsigned NumClauses, |
| 1745 | unsigned CollapsedNum, |
| 1746 | EmptyShell) { |
| 1747 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPForSimdDirective), |
| 1748 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1749 | void *Mem = |
| 1750 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
| 1751 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_for_simd)); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1752 | return new (Mem) OMPForSimdDirective(CollapsedNum, NumClauses); |
| 1753 | } |
| 1754 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1755 | OMPSectionsDirective *OMPSectionsDirective::Create( |
| 1756 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1757 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 1758 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1759 | llvm::alignOf<OMPClause *>()); |
| 1760 | void *Mem = |
| 1761 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1762 | OMPSectionsDirective *Dir = |
| 1763 | new (Mem) OMPSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1764 | Dir->setClauses(Clauses); |
| 1765 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1766 | return Dir; |
| 1767 | } |
| 1768 | |
| 1769 | OMPSectionsDirective *OMPSectionsDirective::CreateEmpty(const ASTContext &C, |
| 1770 | unsigned NumClauses, |
| 1771 | EmptyShell) { |
| 1772 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1773 | llvm::alignOf<OMPClause *>()); |
| 1774 | void *Mem = |
| 1775 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1776 | return new (Mem) OMPSectionsDirective(NumClauses); |
| 1777 | } |
| 1778 | |
| 1779 | OMPSectionDirective *OMPSectionDirective::Create(const ASTContext &C, |
| 1780 | SourceLocation StartLoc, |
| 1781 | SourceLocation EndLoc, |
| 1782 | Stmt *AssociatedStmt) { |
| 1783 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionsDirective), |
| 1784 | llvm::alignOf<Stmt *>()); |
| 1785 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1786 | OMPSectionDirective *Dir = new (Mem) OMPSectionDirective(StartLoc, EndLoc); |
| 1787 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1788 | return Dir; |
| 1789 | } |
| 1790 | |
| 1791 | OMPSectionDirective *OMPSectionDirective::CreateEmpty(const ASTContext &C, |
| 1792 | EmptyShell) { |
| 1793 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSectionDirective), |
| 1794 | llvm::alignOf<Stmt *>()); |
| 1795 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1796 | return new (Mem) OMPSectionDirective(); |
| 1797 | } |
| 1798 | |
| 1799 | OMPSingleDirective *OMPSingleDirective::Create(const ASTContext &C, |
| 1800 | SourceLocation StartLoc, |
| 1801 | SourceLocation EndLoc, |
| 1802 | ArrayRef<OMPClause *> Clauses, |
| 1803 | Stmt *AssociatedStmt) { |
| 1804 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), |
| 1805 | llvm::alignOf<OMPClause *>()); |
| 1806 | void *Mem = |
| 1807 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1808 | OMPSingleDirective *Dir = |
| 1809 | new (Mem) OMPSingleDirective(StartLoc, EndLoc, Clauses.size()); |
| 1810 | Dir->setClauses(Clauses); |
| 1811 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1812 | return Dir; |
| 1813 | } |
| 1814 | |
| 1815 | OMPSingleDirective *OMPSingleDirective::CreateEmpty(const ASTContext &C, |
| 1816 | unsigned NumClauses, |
| 1817 | EmptyShell) { |
| 1818 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPSingleDirective), |
| 1819 | llvm::alignOf<OMPClause *>()); |
| 1820 | void *Mem = |
| 1821 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1822 | return new (Mem) OMPSingleDirective(NumClauses); |
| 1823 | } |
| 1824 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1825 | OMPMasterDirective *OMPMasterDirective::Create(const ASTContext &C, |
| 1826 | SourceLocation StartLoc, |
| 1827 | SourceLocation EndLoc, |
| 1828 | Stmt *AssociatedStmt) { |
| 1829 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), |
| 1830 | llvm::alignOf<Stmt *>()); |
| 1831 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1832 | OMPMasterDirective *Dir = new (Mem) OMPMasterDirective(StartLoc, EndLoc); |
| 1833 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1834 | return Dir; |
| 1835 | } |
| 1836 | |
| 1837 | OMPMasterDirective *OMPMasterDirective::CreateEmpty(const ASTContext &C, |
| 1838 | EmptyShell) { |
| 1839 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPMasterDirective), |
| 1840 | llvm::alignOf<Stmt *>()); |
| 1841 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1842 | return new (Mem) OMPMasterDirective(); |
| 1843 | } |
| 1844 | |
| 1845 | OMPCriticalDirective *OMPCriticalDirective::Create( |
| 1846 | const ASTContext &C, const DeclarationNameInfo &Name, |
| 1847 | SourceLocation StartLoc, SourceLocation EndLoc, Stmt *AssociatedStmt) { |
| 1848 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), |
| 1849 | llvm::alignOf<Stmt *>()); |
| 1850 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1851 | OMPCriticalDirective *Dir = |
| 1852 | new (Mem) OMPCriticalDirective(Name, StartLoc, EndLoc); |
| 1853 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1854 | return Dir; |
| 1855 | } |
| 1856 | |
| 1857 | OMPCriticalDirective *OMPCriticalDirective::CreateEmpty(const ASTContext &C, |
| 1858 | EmptyShell) { |
| 1859 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPCriticalDirective), |
| 1860 | llvm::alignOf<Stmt *>()); |
| 1861 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 1862 | return new (Mem) OMPCriticalDirective(); |
| 1863 | } |
| 1864 | |
| 1865 | OMPParallelForDirective *OMPParallelForDirective::Create( |
| 1866 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1867 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1868 | const HelperExprs &Exprs) { |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1869 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), |
| 1870 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1871 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1872 | sizeof(Stmt *) * |
| 1873 | numLoopChildren(CollapsedNum, OMPD_parallel_for)); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1874 | OMPParallelForDirective *Dir = new (Mem) |
| 1875 | OMPParallelForDirective(StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1876 | Dir->setClauses(Clauses); |
| 1877 | Dir->setAssociatedStmt(AssociatedStmt); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1878 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1879 | Dir->setLastIteration(Exprs.LastIteration); |
| 1880 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1881 | Dir->setPreCond(Exprs.PreCond); |
| 1882 | Dir->setCond(Exprs.Cond, Exprs.SeparatedCond); |
| 1883 | Dir->setInit(Exprs.Init); |
| 1884 | Dir->setInc(Exprs.Inc); |
| 1885 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1886 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1887 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1888 | Dir->setStrideVariable(Exprs.ST); |
| 1889 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1890 | Dir->setNextLowerBound(Exprs.NLB); |
| 1891 | Dir->setNextUpperBound(Exprs.NUB); |
| 1892 | Dir->setCounters(Exprs.Counters); |
| 1893 | Dir->setUpdates(Exprs.Updates); |
| 1894 | Dir->setFinals(Exprs.Finals); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1895 | return Dir; |
| 1896 | } |
| 1897 | |
| 1898 | OMPParallelForDirective * |
| 1899 | OMPParallelForDirective::CreateEmpty(const ASTContext &C, unsigned NumClauses, |
| 1900 | unsigned CollapsedNum, EmptyShell) { |
| 1901 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForDirective), |
| 1902 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1903 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses + |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1904 | sizeof(Stmt *) * |
| 1905 | numLoopChildren(CollapsedNum, OMPD_parallel_for)); |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1906 | return new (Mem) OMPParallelForDirective(CollapsedNum, NumClauses); |
| 1907 | } |
| 1908 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1909 | OMPParallelForSimdDirective *OMPParallelForSimdDirective::Create( |
| 1910 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1911 | unsigned CollapsedNum, ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1912 | const HelperExprs &Exprs) { |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1913 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), |
| 1914 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1915 | void *Mem = C.Allocate( |
| 1916 | Size + sizeof(OMPClause *) * Clauses.size() + |
| 1917 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1918 | OMPParallelForSimdDirective *Dir = new (Mem) OMPParallelForSimdDirective( |
| 1919 | StartLoc, EndLoc, CollapsedNum, Clauses.size()); |
| 1920 | Dir->setClauses(Clauses); |
| 1921 | Dir->setAssociatedStmt(AssociatedStmt); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1922 | Dir->setIterationVariable(Exprs.IterationVarRef); |
| 1923 | Dir->setLastIteration(Exprs.LastIteration); |
| 1924 | Dir->setCalcLastIteration(Exprs.CalcLastIteration); |
| 1925 | Dir->setPreCond(Exprs.PreCond); |
| 1926 | Dir->setCond(Exprs.Cond, Exprs.SeparatedCond); |
| 1927 | Dir->setInit(Exprs.Init); |
| 1928 | Dir->setInc(Exprs.Inc); |
| 1929 | Dir->setIsLastIterVariable(Exprs.IL); |
| 1930 | Dir->setLowerBoundVariable(Exprs.LB); |
| 1931 | Dir->setUpperBoundVariable(Exprs.UB); |
| 1932 | Dir->setStrideVariable(Exprs.ST); |
| 1933 | Dir->setEnsureUpperBound(Exprs.EUB); |
| 1934 | Dir->setNextLowerBound(Exprs.NLB); |
| 1935 | Dir->setNextUpperBound(Exprs.NUB); |
| 1936 | Dir->setCounters(Exprs.Counters); |
| 1937 | Dir->setUpdates(Exprs.Updates); |
| 1938 | Dir->setFinals(Exprs.Finals); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1939 | return Dir; |
| 1940 | } |
| 1941 | |
| 1942 | OMPParallelForSimdDirective * |
| 1943 | OMPParallelForSimdDirective::CreateEmpty(const ASTContext &C, |
| 1944 | unsigned NumClauses, |
| 1945 | unsigned CollapsedNum, EmptyShell) { |
| 1946 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelForSimdDirective), |
| 1947 | llvm::alignOf<OMPClause *>()); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame] | 1948 | void *Mem = C.Allocate( |
| 1949 | Size + sizeof(OMPClause *) * NumClauses + |
| 1950 | sizeof(Stmt *) * numLoopChildren(CollapsedNum, OMPD_parallel_for_simd)); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1951 | return new (Mem) OMPParallelForSimdDirective(CollapsedNum, NumClauses); |
| 1952 | } |
| 1953 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 1954 | OMPParallelSectionsDirective *OMPParallelSectionsDirective::Create( |
| 1955 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 1956 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt) { |
| 1957 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), |
| 1958 | llvm::alignOf<OMPClause *>()); |
| 1959 | void *Mem = |
| 1960 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1961 | OMPParallelSectionsDirective *Dir = |
| 1962 | new (Mem) OMPParallelSectionsDirective(StartLoc, EndLoc, Clauses.size()); |
| 1963 | Dir->setClauses(Clauses); |
| 1964 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1965 | return Dir; |
| 1966 | } |
| 1967 | |
| 1968 | OMPParallelSectionsDirective * |
| 1969 | OMPParallelSectionsDirective::CreateEmpty(const ASTContext &C, |
| 1970 | unsigned NumClauses, EmptyShell) { |
| 1971 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPParallelSectionsDirective), |
| 1972 | llvm::alignOf<OMPClause *>()); |
| 1973 | void *Mem = |
| 1974 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 1975 | return new (Mem) OMPParallelSectionsDirective(NumClauses); |
| 1976 | } |
| 1977 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 1978 | OMPTaskDirective *OMPTaskDirective::Create(const ASTContext &C, |
| 1979 | SourceLocation StartLoc, |
| 1980 | SourceLocation EndLoc, |
| 1981 | ArrayRef<OMPClause *> Clauses, |
| 1982 | Stmt *AssociatedStmt) { |
| 1983 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), |
| 1984 | llvm::alignOf<OMPClause *>()); |
| 1985 | void *Mem = |
| 1986 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 1987 | OMPTaskDirective *Dir = |
| 1988 | new (Mem) OMPTaskDirective(StartLoc, EndLoc, Clauses.size()); |
| 1989 | Dir->setClauses(Clauses); |
| 1990 | Dir->setAssociatedStmt(AssociatedStmt); |
| 1991 | return Dir; |
| 1992 | } |
| 1993 | |
| 1994 | OMPTaskDirective *OMPTaskDirective::CreateEmpty(const ASTContext &C, |
| 1995 | unsigned NumClauses, |
| 1996 | EmptyShell) { |
| 1997 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTaskDirective), |
| 1998 | llvm::alignOf<OMPClause *>()); |
| 1999 | void *Mem = |
| 2000 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2001 | return new (Mem) OMPTaskDirective(NumClauses); |
| 2002 | } |
| 2003 | |
| 2004 | OMPTaskyieldDirective *OMPTaskyieldDirective::Create(const ASTContext &C, |
| 2005 | SourceLocation StartLoc, |
| 2006 | SourceLocation EndLoc) { |
| 2007 | void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); |
| 2008 | OMPTaskyieldDirective *Dir = |
| 2009 | new (Mem) OMPTaskyieldDirective(StartLoc, EndLoc); |
| 2010 | return Dir; |
| 2011 | } |
| 2012 | |
| 2013 | OMPTaskyieldDirective *OMPTaskyieldDirective::CreateEmpty(const ASTContext &C, |
| 2014 | EmptyShell) { |
| 2015 | void *Mem = C.Allocate(sizeof(OMPTaskyieldDirective)); |
| 2016 | return new (Mem) OMPTaskyieldDirective(); |
| 2017 | } |
| 2018 | |
| 2019 | OMPBarrierDirective *OMPBarrierDirective::Create(const ASTContext &C, |
| 2020 | SourceLocation StartLoc, |
| 2021 | SourceLocation EndLoc) { |
| 2022 | void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); |
| 2023 | OMPBarrierDirective *Dir = new (Mem) OMPBarrierDirective(StartLoc, EndLoc); |
| 2024 | return Dir; |
| 2025 | } |
| 2026 | |
| 2027 | OMPBarrierDirective *OMPBarrierDirective::CreateEmpty(const ASTContext &C, |
| 2028 | EmptyShell) { |
| 2029 | void *Mem = C.Allocate(sizeof(OMPBarrierDirective)); |
| 2030 | return new (Mem) OMPBarrierDirective(); |
| 2031 | } |
| 2032 | |
| 2033 | OMPTaskwaitDirective *OMPTaskwaitDirective::Create(const ASTContext &C, |
| 2034 | SourceLocation StartLoc, |
| 2035 | SourceLocation EndLoc) { |
| 2036 | void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); |
| 2037 | OMPTaskwaitDirective *Dir = new (Mem) OMPTaskwaitDirective(StartLoc, EndLoc); |
| 2038 | return Dir; |
| 2039 | } |
| 2040 | |
| 2041 | OMPTaskwaitDirective *OMPTaskwaitDirective::CreateEmpty(const ASTContext &C, |
| 2042 | EmptyShell) { |
| 2043 | void *Mem = C.Allocate(sizeof(OMPTaskwaitDirective)); |
| 2044 | return new (Mem) OMPTaskwaitDirective(); |
| 2045 | } |
| 2046 | |
| 2047 | OMPFlushDirective *OMPFlushDirective::Create(const ASTContext &C, |
| 2048 | SourceLocation StartLoc, |
| 2049 | SourceLocation EndLoc, |
| 2050 | ArrayRef<OMPClause *> Clauses) { |
| 2051 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), |
| 2052 | llvm::alignOf<OMPClause *>()); |
| 2053 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size()); |
| 2054 | OMPFlushDirective *Dir = |
| 2055 | new (Mem) OMPFlushDirective(StartLoc, EndLoc, Clauses.size()); |
| 2056 | Dir->setClauses(Clauses); |
| 2057 | return Dir; |
| 2058 | } |
| 2059 | |
| 2060 | OMPFlushDirective *OMPFlushDirective::CreateEmpty(const ASTContext &C, |
| 2061 | unsigned NumClauses, |
| 2062 | EmptyShell) { |
| 2063 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPFlushDirective), |
| 2064 | llvm::alignOf<OMPClause *>()); |
| 2065 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * NumClauses); |
| 2066 | return new (Mem) OMPFlushDirective(NumClauses); |
| 2067 | } |
| 2068 | |
| 2069 | OMPOrderedDirective *OMPOrderedDirective::Create(const ASTContext &C, |
| 2070 | SourceLocation StartLoc, |
| 2071 | SourceLocation EndLoc, |
| 2072 | Stmt *AssociatedStmt) { |
| 2073 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), |
| 2074 | llvm::alignOf<Stmt *>()); |
| 2075 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 2076 | OMPOrderedDirective *Dir = new (Mem) OMPOrderedDirective(StartLoc, EndLoc); |
| 2077 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2078 | return Dir; |
| 2079 | } |
| 2080 | |
| 2081 | OMPOrderedDirective *OMPOrderedDirective::CreateEmpty(const ASTContext &C, |
| 2082 | EmptyShell) { |
| 2083 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPOrderedDirective), |
| 2084 | llvm::alignOf<Stmt *>()); |
| 2085 | void *Mem = C.Allocate(Size + sizeof(Stmt *)); |
| 2086 | return new (Mem) OMPOrderedDirective(); |
| 2087 | } |
| 2088 | |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 2089 | OMPAtomicDirective *OMPAtomicDirective::Create( |
| 2090 | const ASTContext &C, SourceLocation StartLoc, SourceLocation EndLoc, |
| 2091 | ArrayRef<OMPClause *> Clauses, Stmt *AssociatedStmt, Expr *X, Expr *V, |
| 2092 | Expr *E, Expr *UE, bool IsXLHSInRHSPart, bool IsPostfixUpdate) { |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2093 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), |
| 2094 | llvm::alignOf<OMPClause *>()); |
| 2095 | void *Mem = C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 2096 | 5 * sizeof(Stmt *)); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2097 | OMPAtomicDirective *Dir = |
| 2098 | new (Mem) OMPAtomicDirective(StartLoc, EndLoc, Clauses.size()); |
| 2099 | Dir->setClauses(Clauses); |
| 2100 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2101 | Dir->setX(X); |
| 2102 | Dir->setV(V); |
| 2103 | Dir->setExpr(E); |
Pirama Arumuga Nainar | 33337ca | 2015-05-06 11:48:57 -0700 | [diff] [blame^] | 2104 | Dir->setUpdateExpr(UE); |
| 2105 | Dir->IsXLHSInRHSPart = IsXLHSInRHSPart; |
| 2106 | Dir->IsPostfixUpdate = IsPostfixUpdate; |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2107 | return Dir; |
| 2108 | } |
| 2109 | |
| 2110 | OMPAtomicDirective *OMPAtomicDirective::CreateEmpty(const ASTContext &C, |
| 2111 | unsigned NumClauses, |
| 2112 | EmptyShell) { |
| 2113 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPAtomicDirective), |
| 2114 | llvm::alignOf<OMPClause *>()); |
| 2115 | void *Mem = |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 2116 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + 5 * sizeof(Stmt *)); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 2117 | return new (Mem) OMPAtomicDirective(NumClauses); |
| 2118 | } |
| 2119 | |
| 2120 | OMPTargetDirective *OMPTargetDirective::Create(const ASTContext &C, |
| 2121 | SourceLocation StartLoc, |
| 2122 | SourceLocation EndLoc, |
| 2123 | ArrayRef<OMPClause *> Clauses, |
| 2124 | Stmt *AssociatedStmt) { |
| 2125 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), |
| 2126 | llvm::alignOf<OMPClause *>()); |
| 2127 | void *Mem = |
| 2128 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2129 | OMPTargetDirective *Dir = |
| 2130 | new (Mem) OMPTargetDirective(StartLoc, EndLoc, Clauses.size()); |
| 2131 | Dir->setClauses(Clauses); |
| 2132 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2133 | return Dir; |
| 2134 | } |
| 2135 | |
| 2136 | OMPTargetDirective *OMPTargetDirective::CreateEmpty(const ASTContext &C, |
| 2137 | unsigned NumClauses, |
| 2138 | EmptyShell) { |
| 2139 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTargetDirective), |
| 2140 | llvm::alignOf<OMPClause *>()); |
| 2141 | void *Mem = |
| 2142 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2143 | return new (Mem) OMPTargetDirective(NumClauses); |
| 2144 | } |
| 2145 | |
| 2146 | OMPTeamsDirective *OMPTeamsDirective::Create(const ASTContext &C, |
| 2147 | SourceLocation StartLoc, |
| 2148 | SourceLocation EndLoc, |
| 2149 | ArrayRef<OMPClause *> Clauses, |
| 2150 | Stmt *AssociatedStmt) { |
| 2151 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), |
| 2152 | llvm::alignOf<OMPClause *>()); |
| 2153 | void *Mem = |
| 2154 | C.Allocate(Size + sizeof(OMPClause *) * Clauses.size() + sizeof(Stmt *)); |
| 2155 | OMPTeamsDirective *Dir = |
| 2156 | new (Mem) OMPTeamsDirective(StartLoc, EndLoc, Clauses.size()); |
| 2157 | Dir->setClauses(Clauses); |
| 2158 | Dir->setAssociatedStmt(AssociatedStmt); |
| 2159 | return Dir; |
| 2160 | } |
| 2161 | |
| 2162 | OMPTeamsDirective *OMPTeamsDirective::CreateEmpty(const ASTContext &C, |
| 2163 | unsigned NumClauses, |
| 2164 | EmptyShell) { |
| 2165 | unsigned Size = llvm::RoundUpToAlignment(sizeof(OMPTeamsDirective), |
| 2166 | llvm::alignOf<OMPClause *>()); |
| 2167 | void *Mem = |
| 2168 | C.Allocate(Size + sizeof(OMPClause *) * NumClauses + sizeof(Stmt *)); |
| 2169 | return new (Mem) OMPTeamsDirective(NumClauses); |
| 2170 | } |
| 2171 | |