Intel SPMD Program Compiler  1.11.0
ast.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011-2019, Intel Corporation
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are
7  met:
8 
9  * Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11 
12  * Redistributions in binary form must reproduce the above copyright
13  notice, this list of conditions and the following disclaimer in the
14  documentation and/or other materials provided with the distribution.
15 
16  * Neither the name of Intel Corporation nor the names of its
17  contributors may be used to endorse or promote products derived from
18  this software without specific prior written permission.
19 
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
25  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 
34 /** @file ast.cpp
35 
36  @brief General functionality related to abstract syntax trees and
37  traversal of them.
38  */
39 
40 #include "ast.h"
41 #include "expr.h"
42 #include "func.h"
43 #include "stmt.h"
44 #include "sym.h"
45 #include "util.h"
46 
47 ///////////////////////////////////////////////////////////////////////////
48 // ASTNode
49 
51 
52 ///////////////////////////////////////////////////////////////////////////
53 // AST
54 
55 void AST::AddFunction(Symbol *sym, Stmt *code) {
56  if (sym == NULL)
57  return;
58  functions.push_back(new Function(sym, code));
59 }
60 
62  for (unsigned int i = 0; i < functions.size(); ++i)
63  functions[i]->GenerateIR();
64 }
65 
66 ///////////////////////////////////////////////////////////////////////////
67 
68 ASTNode *WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, void *data) {
69  if (node == NULL)
70  return node;
71 
72  // Call the callback function
73  if (preFunc != NULL) {
74  if (preFunc(node, data) == false)
75  // The function asked us to not continue recursively, so stop.
76  return node;
77  }
78 
79  ////////////////////////////////////////////////////////////////////////////
80  // Handle Statements
81  if (llvm::dyn_cast<Stmt>(node) != NULL) {
82  ExprStmt *es;
83  DeclStmt *ds;
84  IfStmt *is;
85  DoStmt *dos;
86  ForStmt *fs;
87  ForeachStmt *fes;
88  ForeachActiveStmt *fas;
89  ForeachUniqueStmt *fus;
90  CaseStmt *cs;
91  DefaultStmt *defs;
92  SwitchStmt *ss;
93  ReturnStmt *rs;
94  LabeledStmt *ls;
95  StmtList *sl;
96  PrintStmt *ps;
97  AssertStmt *as;
98  DeleteStmt *dels;
99  UnmaskedStmt *ums;
100 
101  if ((es = llvm::dyn_cast<ExprStmt>(node)) != NULL)
102  es->expr = (Expr *)WalkAST(es->expr, preFunc, postFunc, data);
103  else if ((ds = llvm::dyn_cast<DeclStmt>(node)) != NULL) {
104  for (unsigned int i = 0; i < ds->vars.size(); ++i)
105  ds->vars[i].init = (Expr *)WalkAST(ds->vars[i].init, preFunc, postFunc, data);
106  } else if ((is = llvm::dyn_cast<IfStmt>(node)) != NULL) {
107  is->test = (Expr *)WalkAST(is->test, preFunc, postFunc, data);
108  is->trueStmts = (Stmt *)WalkAST(is->trueStmts, preFunc, postFunc, data);
109  is->falseStmts = (Stmt *)WalkAST(is->falseStmts, preFunc, postFunc, data);
110  } else if ((dos = llvm::dyn_cast<DoStmt>(node)) != NULL) {
111  dos->testExpr = (Expr *)WalkAST(dos->testExpr, preFunc, postFunc, data);
112  dos->bodyStmts = (Stmt *)WalkAST(dos->bodyStmts, preFunc, postFunc, data);
113  } else if ((fs = llvm::dyn_cast<ForStmt>(node)) != NULL) {
114  fs->init = (Stmt *)WalkAST(fs->init, preFunc, postFunc, data);
115  fs->test = (Expr *)WalkAST(fs->test, preFunc, postFunc, data);
116  fs->step = (Stmt *)WalkAST(fs->step, preFunc, postFunc, data);
117  fs->stmts = (Stmt *)WalkAST(fs->stmts, preFunc, postFunc, data);
118  } else if ((fes = llvm::dyn_cast<ForeachStmt>(node)) != NULL) {
119  for (unsigned int i = 0; i < fes->startExprs.size(); ++i)
120  fes->startExprs[i] = (Expr *)WalkAST(fes->startExprs[i], preFunc, postFunc, data);
121  for (unsigned int i = 0; i < fes->endExprs.size(); ++i)
122  fes->endExprs[i] = (Expr *)WalkAST(fes->endExprs[i], preFunc, postFunc, data);
123  fes->stmts = (Stmt *)WalkAST(fes->stmts, preFunc, postFunc, data);
124  } else if ((fas = llvm::dyn_cast<ForeachActiveStmt>(node)) != NULL) {
125  fas->stmts = (Stmt *)WalkAST(fas->stmts, preFunc, postFunc, data);
126  } else if ((fus = llvm::dyn_cast<ForeachUniqueStmt>(node)) != NULL) {
127  fus->expr = (Expr *)WalkAST(fus->expr, preFunc, postFunc, data);
128  fus->stmts = (Stmt *)WalkAST(fus->stmts, preFunc, postFunc, data);
129  } else if ((cs = llvm::dyn_cast<CaseStmt>(node)) != NULL)
130  cs->stmts = (Stmt *)WalkAST(cs->stmts, preFunc, postFunc, data);
131  else if ((defs = llvm::dyn_cast<DefaultStmt>(node)) != NULL)
132  defs->stmts = (Stmt *)WalkAST(defs->stmts, preFunc, postFunc, data);
133  else if ((ss = llvm::dyn_cast<SwitchStmt>(node)) != NULL) {
134  ss->expr = (Expr *)WalkAST(ss->expr, preFunc, postFunc, data);
135  ss->stmts = (Stmt *)WalkAST(ss->stmts, preFunc, postFunc, data);
136  } else if (llvm::dyn_cast<BreakStmt>(node) != NULL || llvm::dyn_cast<ContinueStmt>(node) != NULL ||
137  llvm::dyn_cast<GotoStmt>(node) != NULL) {
138  // nothing
139  } else if ((ls = llvm::dyn_cast<LabeledStmt>(node)) != NULL)
140  ls->stmt = (Stmt *)WalkAST(ls->stmt, preFunc, postFunc, data);
141  else if ((rs = llvm::dyn_cast<ReturnStmt>(node)) != NULL)
142  rs->expr = (Expr *)WalkAST(rs->expr, preFunc, postFunc, data);
143  else if ((sl = llvm::dyn_cast<StmtList>(node)) != NULL) {
144  std::vector<Stmt *> &sls = sl->stmts;
145  for (unsigned int i = 0; i < sls.size(); ++i)
146  sls[i] = (Stmt *)WalkAST(sls[i], preFunc, postFunc, data);
147  } else if ((ps = llvm::dyn_cast<PrintStmt>(node)) != NULL)
148  ps->values = (Expr *)WalkAST(ps->values, preFunc, postFunc, data);
149  else if ((as = llvm::dyn_cast<AssertStmt>(node)) != NULL)
150  as->expr = (Expr *)WalkAST(as->expr, preFunc, postFunc, data);
151  else if ((dels = llvm::dyn_cast<DeleteStmt>(node)) != NULL)
152  dels->expr = (Expr *)WalkAST(dels->expr, preFunc, postFunc, data);
153  else if ((ums = llvm::dyn_cast<UnmaskedStmt>(node)) != NULL)
154  ums->stmts = (Stmt *)WalkAST(ums->stmts, preFunc, postFunc, data);
155  else
156  FATAL("Unhandled statement type in WalkAST()");
157  } else {
158  ///////////////////////////////////////////////////////////////////////////
159  // Handle expressions
160  Assert(llvm::dyn_cast<Expr>(node) != NULL);
161  UnaryExpr *ue;
162  BinaryExpr *be;
163  AssignExpr *ae;
164  SelectExpr *se;
165  ExprList *el;
166  FunctionCallExpr *fce;
167  IndexExpr *ie;
168  MemberExpr *me;
169  TypeCastExpr *tce;
170  ReferenceExpr *re;
171  PtrDerefExpr *ptrderef;
172  RefDerefExpr *refderef;
173  SizeOfExpr *soe;
174  AddressOfExpr *aoe;
175  NewExpr *newe;
176 
177  if ((ue = llvm::dyn_cast<UnaryExpr>(node)) != NULL)
178  ue->expr = (Expr *)WalkAST(ue->expr, preFunc, postFunc, data);
179  else if ((be = llvm::dyn_cast<BinaryExpr>(node)) != NULL) {
180  be->arg0 = (Expr *)WalkAST(be->arg0, preFunc, postFunc, data);
181  be->arg1 = (Expr *)WalkAST(be->arg1, preFunc, postFunc, data);
182  } else if ((ae = llvm::dyn_cast<AssignExpr>(node)) != NULL) {
183  ae->lvalue = (Expr *)WalkAST(ae->lvalue, preFunc, postFunc, data);
184  ae->rvalue = (Expr *)WalkAST(ae->rvalue, preFunc, postFunc, data);
185  } else if ((se = llvm::dyn_cast<SelectExpr>(node)) != NULL) {
186  se->test = (Expr *)WalkAST(se->test, preFunc, postFunc, data);
187  se->expr1 = (Expr *)WalkAST(se->expr1, preFunc, postFunc, data);
188  se->expr2 = (Expr *)WalkAST(se->expr2, preFunc, postFunc, data);
189  } else if ((el = llvm::dyn_cast<ExprList>(node)) != NULL) {
190  for (unsigned int i = 0; i < el->exprs.size(); ++i)
191  el->exprs[i] = (Expr *)WalkAST(el->exprs[i], preFunc, postFunc, data);
192  } else if ((fce = llvm::dyn_cast<FunctionCallExpr>(node)) != NULL) {
193  fce->func = (Expr *)WalkAST(fce->func, preFunc, postFunc, data);
194  fce->args = (ExprList *)WalkAST(fce->args, preFunc, postFunc, data);
195  for (int k = 0; k < 3; k++)
196  fce->launchCountExpr[k] = (Expr *)WalkAST(fce->launchCountExpr[k], preFunc, postFunc, data);
197  } else if ((ie = llvm::dyn_cast<IndexExpr>(node)) != NULL) {
198  ie->baseExpr = (Expr *)WalkAST(ie->baseExpr, preFunc, postFunc, data);
199  ie->index = (Expr *)WalkAST(ie->index, preFunc, postFunc, data);
200  } else if ((me = llvm::dyn_cast<MemberExpr>(node)) != NULL)
201  me->expr = (Expr *)WalkAST(me->expr, preFunc, postFunc, data);
202  else if ((tce = llvm::dyn_cast<TypeCastExpr>(node)) != NULL)
203  tce->expr = (Expr *)WalkAST(tce->expr, preFunc, postFunc, data);
204  else if ((re = llvm::dyn_cast<ReferenceExpr>(node)) != NULL)
205  re->expr = (Expr *)WalkAST(re->expr, preFunc, postFunc, data);
206  else if ((ptrderef = llvm::dyn_cast<PtrDerefExpr>(node)) != NULL)
207  ptrderef->expr = (Expr *)WalkAST(ptrderef->expr, preFunc, postFunc, data);
208  else if ((refderef = llvm::dyn_cast<RefDerefExpr>(node)) != NULL)
209  refderef->expr = (Expr *)WalkAST(refderef->expr, preFunc, postFunc, data);
210  else if ((soe = llvm::dyn_cast<SizeOfExpr>(node)) != NULL)
211  soe->expr = (Expr *)WalkAST(soe->expr, preFunc, postFunc, data);
212  else if ((aoe = llvm::dyn_cast<AddressOfExpr>(node)) != NULL)
213  aoe->expr = (Expr *)WalkAST(aoe->expr, preFunc, postFunc, data);
214  else if ((newe = llvm::dyn_cast<NewExpr>(node)) != NULL) {
215  newe->countExpr = (Expr *)WalkAST(newe->countExpr, preFunc, postFunc, data);
216  newe->initExpr = (Expr *)WalkAST(newe->initExpr, preFunc, postFunc, data);
217  } else if (llvm::dyn_cast<SymbolExpr>(node) != NULL || llvm::dyn_cast<ConstExpr>(node) != NULL ||
218  llvm::dyn_cast<FunctionSymbolExpr>(node) != NULL || llvm::dyn_cast<SyncExpr>(node) != NULL ||
219  llvm::dyn_cast<NullPointerExpr>(node) != NULL) {
220  // nothing to do
221  } else
222  FATAL("Unhandled expression type in WalkAST().");
223  }
224 
225  // Call the callback function
226  if (postFunc != NULL)
227  return postFunc(node, data);
228  else
229  return node;
230 }
231 
232 static ASTNode *lOptimizeNode(ASTNode *node, void *) { return node->Optimize(); }
233 
234 ASTNode *Optimize(ASTNode *root) { return WalkAST(root, NULL, lOptimizeNode, NULL); }
235 
236 Expr *Optimize(Expr *expr) { return (Expr *)Optimize((ASTNode *)expr); }
237 
238 Stmt *Optimize(Stmt *stmt) { return (Stmt *)Optimize((ASTNode *)stmt); }
239 
240 static ASTNode *lTypeCheckNode(ASTNode *node, void *) { return node->TypeCheck(); }
241 
242 ASTNode *TypeCheck(ASTNode *root) { return WalkAST(root, NULL, lTypeCheckNode, NULL); }
243 
244 Expr *TypeCheck(Expr *expr) { return (Expr *)TypeCheck((ASTNode *)expr); }
245 
246 Stmt *TypeCheck(Stmt *stmt) { return (Stmt *)TypeCheck((ASTNode *)stmt); }
247 
248 struct CostData {
250 
251  int cost;
253 };
254 
255 static bool lCostCallbackPre(ASTNode *node, void *d) {
256  CostData *data = (CostData *)d;
257  if (llvm::dyn_cast<ForeachStmt>(node) != NULL)
258  ++data->foreachDepth;
259  if (data->foreachDepth == 0)
260  data->cost += node->EstimateCost();
261  return true;
262 }
263 
264 static ASTNode *lCostCallbackPost(ASTNode *node, void *d) {
265  CostData *data = (CostData *)d;
266  if (llvm::dyn_cast<ForeachStmt>(node) != NULL)
267  --data->foreachDepth;
268  return node;
269 }
270 
271 int EstimateCost(ASTNode *root) {
272  CostData data;
274  return data.cost;
275 }
276 
277 /** Given an AST node, check to see if it's safe if we happen to run the
278  code for that node with the execution mask all off.
279  */
280 static bool lCheckAllOffSafety(ASTNode *node, void *data) {
281  bool *okPtr = (bool *)data;
282 
283  FunctionCallExpr *fce;
284  if ((fce = llvm::dyn_cast<FunctionCallExpr>(node)) != NULL) {
285  if (fce->func == NULL)
286  return false;
287 
288  const Type *type = fce->func->GetType();
289  const PointerType *pt = CastType<PointerType>(type);
290  if (pt != NULL)
291  type = pt->GetBaseType();
292  const FunctionType *ftype = CastType<FunctionType>(type);
293  Assert(ftype != NULL);
294 
295  if (ftype->isSafe == false) {
296  *okPtr = false;
297  return false;
298  }
299  }
300 
301  if (llvm::dyn_cast<AssertStmt>(node) != NULL) {
302  // While it's fine to run the assert for varying tests, it's not
303  // desirable to check an assert on a uniform variable if all of the
304  // lanes are off.
305  *okPtr = false;
306  return false;
307  }
308 
309  if (llvm::dyn_cast<PrintStmt>(node) != NULL) {
310  *okPtr = false;
311  return false;
312  }
313 
314  if (llvm::dyn_cast<NewExpr>(node) != NULL || llvm::dyn_cast<DeleteStmt>(node) != NULL) {
315  // We definitely don't want to run the uniform variants of these if
316  // the mask is all off. It's also worth skipping the overhead of
317  // executing the varying versions of them in the all-off mask case.
318  *okPtr = false;
319  return false;
320  }
321 
322  if (llvm::dyn_cast<ForeachStmt>(node) != NULL || llvm::dyn_cast<ForeachActiveStmt>(node) != NULL ||
323  llvm::dyn_cast<ForeachUniqueStmt>(node) != NULL || llvm::dyn_cast<UnmaskedStmt>(node) != NULL) {
324  // The various foreach statements also shouldn't be run with an
325  // all-off mask. Since they can re-establish an 'all on' mask,
326  // this would be pretty unintuitive. (More generally, it's
327  // possibly a little strange to allow foreach in the presence of
328  // any non-uniform control flow...)
329  //
330  // Similarly, the implementation of foreach_unique assumes as a
331  // precondition that the mask won't be all off going into it, so
332  // we'll enforce that here...
333  *okPtr = false;
334  return false;
335  }
336 
337  if (llvm::dyn_cast<BinaryExpr>(node) != NULL) {
338  BinaryExpr *binaryExpr = llvm::dyn_cast<BinaryExpr>(node);
339  if (binaryExpr->op == BinaryExpr::Mod || binaryExpr->op == BinaryExpr::Div) {
340  *okPtr = false;
341  return false;
342  }
343  }
344  IndexExpr *ie;
345  if ((ie = llvm::dyn_cast<IndexExpr>(node)) != NULL && ie->baseExpr != NULL) {
346  const Type *type = ie->baseExpr->GetType();
347  if (type == NULL)
348  return true;
349  if (CastType<ReferenceType>(type) != NULL)
350  type = type->GetReferenceTarget();
351 
352  ConstExpr *ce = llvm::dyn_cast<ConstExpr>(ie->index);
353  if (ce == NULL) {
354  // indexing with a variable... -> not safe
355  *okPtr = false;
356  return false;
357  }
358 
359  const PointerType *pointerType = CastType<PointerType>(type);
360  if (pointerType != NULL) {
361  // pointer[index] -> can't be sure -> not safe
362  *okPtr = false;
363  return false;
364  }
365 
366  const SequentialType *seqType = CastType<SequentialType>(type);
367  Assert(seqType != NULL);
368  int nElements = seqType->GetElementCount();
369  if (nElements == 0) {
370  // Unsized array, so we can't be sure -> not safe
371  *okPtr = false;
372  return false;
373  }
374 
375  int32_t indices[ISPC_MAX_NVEC];
376  int count = ce->GetValues(indices);
377  for (int i = 0; i < count; ++i) {
378  if (indices[i] < 0 || indices[i] >= nElements) {
379  // Index is out of bounds -> not safe
380  *okPtr = false;
381  return false;
382  }
383  }
384 
385  // All indices are in-bounds
386  return true;
387  }
388 
389  MemberExpr *me;
390  if ((me = llvm::dyn_cast<MemberExpr>(node)) != NULL && me->dereferenceExpr) {
391  *okPtr = false;
392  return false;
393  }
394 
395  if (llvm::dyn_cast<PtrDerefExpr>(node) != NULL) {
396  *okPtr = false;
397  return false;
398  }
399 
400  /*
401  Don't allow turning if/else to straight-line-code if we
402  assign to a uniform.
403  */
404  AssignExpr *ae;
405  if ((ae = llvm::dyn_cast<AssignExpr>(node)) != NULL) {
406  if (ae->GetType()) {
407  if (ae->GetType()->IsUniformType()) {
408  *okPtr = false;
409  return false;
410  }
411  }
412  }
413 
414  return true;
415 }
416 
418  bool safe = true;
419  WalkAST(root, lCheckAllOffSafety, NULL, &safe);
420  return safe;
421 }
bool IsUniformType() const
Definition: type.h:139
Expr * expr
Definition: stmt.h:515
virtual int EstimateCost() const =0
Stmt * bodyStmts
Definition: stmt.h:173
std::vector< VariableDeclaration > vars
Definition: stmt.h:115
Expr * countExpr
Definition: expr.h:750
static ASTNode * lCostCallbackPost(ASTNode *node, void *d)
Definition: ast.cpp:264
Definition: func.h:44
Stmt * stmts
Definition: stmt.h:356
ASTNode * WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, void *data)
Definition: ast.cpp:68
Division.
Definition: expr.h:137
virtual ASTNode * TypeCheck()=0
Stmt * trueStmts
Definition: stmt.h:138
static bool lCheckAllOffSafety(ASTNode *node, void *data)
Definition: ast.cpp:280
Expr * expr
Definition: stmt.h:335
std::vector< Expr * > endExprs
Definition: stmt.h:257
bool SafeToRunWithMaskAllOff(ASTNode *root)
Definition: ast.cpp:417
Representation of a print() statement in the program.
Definition: stmt.h:471
Expression that represents taking a reference of a (non-reference) variable.
Definition: expr.h:502
Interface class for statements in the ispc language.
Definition: stmt.h:49
Statement representing a single declaration (which in turn may declare a number of variables...
Definition: stmt.h:101
ASTNode * TypeCheck(ASTNode *root)
Definition: ast.cpp:242
Statement representing a single expression.
Definition: stmt.h:74
Expr * baseExpr
Definition: expr.h:305
Expression representing a compile-time constant value.
Definition: expr.h:362
Abstract base class for types that represent sequences.
Definition: type.h:512
Expr * expr
Definition: expr.h:339
Statement implementation for &#39;for&#39; loops (as well as for &#39;while&#39; loops).
Definition: stmt.h:180
static ASTNode * lTypeCheckNode(ASTNode *node, void *)
Definition: ast.cpp:240
Representation of an assert statement in the program.
Definition: stmt.h:499
A list of expressions.
Definition: expr.h:238
Statement implementation representing a &#39;do&#39; statement in the program.
Definition: stmt.h:159
Type implementation for pointers to other types.
Definition: type.h:430
Expr * expr
Definition: expr.h:497
ExprList * args
Definition: expr.h:277
Expr * arg0
Definition: expr.h:173
#define Assert(expr)
Definition: ispc.h:161
Expr * expr
Definition: expr.h:539
Modulus.
Definition: expr.h:138
header file with declarations for symbol and symbol table classes.
Expr * test
Definition: expr.h:229
Expr * expr
Definition: expr.h:127
int foreachDepth
Definition: ast.cpp:252
virtual const Type * GetReferenceTarget() const
Definition: type.cpp:2825
Binary expression.
Definition: expr.h:131
Expr * test
Definition: stmt.h:136
Stmt * stmts
Definition: stmt.h:394
Definition: expr.h:731
File with declarations for classes related to statements in the language.
Stmt * stmts
Definition: stmt.h:374
Expr * expr
Definition: stmt.h:392
Expression representing a type cast of the given expression to a probably-different type...
Definition: expr.h:478
Statement implementation for a &#39;return&#39; statement in the program.
Definition: stmt.h:322
Abstract base class for nodes in the abstract syntax tree (AST).
Definition: ast.h:50
virtual int GetElementCount() const =0
Expr * func
Definition: expr.h:276
Stmt * stmts
Definition: stmt.h:299
Expr * arg1
Definition: expr.h:173
Stmt * step
Definition: stmt.h:201
Expr * expr
Definition: expr.h:590
Statement implementation for a continue statement in the program.
Definition: stmt.h:225
int GetValues(bool *, bool forceVarying=false) const
Definition: expr.cpp:5370
virtual ASTNode * Optimize()=0
virtual const Type * GetType() const =0
int cost
Definition: ast.cpp:251
Expr * expr
Definition: expr.h:518
A sync statement in the program (waits for all launched tasks before proceeding). ...
Definition: expr.h:696
Expr * index
Definition: expr.h:305
Expr * lvalue
Definition: expr.h:207
Stmt * stmts
Definition: stmt.h:278
Stmt * stmts
Definition: stmt.h:203
CostData()
Definition: ast.cpp:249
bool(* ASTPreCallBackFunc)(ASTNode *node, void *data)
Definition: ast.h:156
const Op op
Definition: expr.h:172
Expr * values
Definition: stmt.h:488
#define FATAL(message)
Definition: util.h:112
Expr * testExpr
Definition: stmt.h:172
Expr * launchCountExpr[3]
Definition: expr.h:279
#define ISPC_MAX_NVEC
Definition: ispc.h:69
Representation of a function in a source file.
Stmt * falseStmts
Definition: stmt.h:140
std::vector< Function * > functions
Definition: ast.h:150
Expr * test
Definition: stmt.h:198
Stmt * init
Definition: stmt.h:195
Expression representing member selection ("foo.bar").
Definition: expr.h:316
Stmt * stmts
Definition: stmt.h:259
Definition: stmt.h:341
std::vector< Expr * > exprs
Definition: expr.h:254
std::vector< Expr * > startExprs
Definition: stmt.h:256
Unary expression.
Definition: expr.h:102
Expr * rvalue
Definition: expr.h:207
Expression representing indexing into something with an integer offset.
Definition: expr.h:287
Type representing a function (return type + argument types)
Definition: type.h:858
Representation of a program symbol.
Definition: sym.h:63
void AddFunction(Symbol *sym, Stmt *code)
Definition: ast.cpp:55
Stmt * stmt
Definition: stmt.h:436
Expr * expr2
Definition: expr.h:229
ASTNode *(* ASTPostCallBackFunc)(ASTNode *node, void *data)
Definition: ast.h:161
void GenerateIR()
Definition: ast.cpp:61
Interface class that defines the type abstraction.
Definition: type.h:95
static bool lCostCallbackPre(ASTNode *node, void *d)
Definition: ast.cpp:255
std::vector< Stmt * > stmts
Definition: stmt.h:459
Expression that represents dereferencing a pointer to get its value.
Definition: expr.h:544
Expr abstract base class and expression implementations.
int EstimateCost(ASTNode *root)
Definition: ast.cpp:271
Expr * expr
Definition: stmt.h:87
Statement implementation for parallel &#39;foreach&#39; loops.
Definition: stmt.h:241
Stmt * stmts
Definition: stmt.h:317
Statement representing a single if statement, possibly with an else clause.
Definition: stmt.h:120
Expr is the abstract base class that defines the interface that all expression types must implement...
Definition: expr.h:48
Expr * expr
Definition: stmt.h:534
Assignment expression.
Definition: expr.h:177
Representation of a list of statements in the program.
Definition: stmt.h:441
ASTNode * Optimize(ASTNode *root)
Definition: ast.cpp:234
Expr * expr
Definition: expr.h:612
Expression that represents dereferencing a reference to get its value.
Definition: expr.h:559
Expr * expr
Definition: stmt.h:298
bool isSafe
Definition: type.h:931
const Type * GetBaseType() const
Definition: type.cpp:923
bool dereferenceExpr
Definition: expr.h:349
Selection expression, corresponding to "test ? a : b".
Definition: expr.h:214
const Type * GetType() const
Definition: expr.cpp:2842
Expr * expr1
Definition: expr.h:229
static ASTNode * lOptimizeNode(ASTNode *node, void *)
Definition: ast.cpp:232
Expr * initExpr
Definition: expr.h:753
Expression representing a function call.
Definition: expr.h:259
virtual ~ASTNode()
Definition: ast.cpp:50