58 functions.push_back(
new Function(sym, code));
62 for (
unsigned int i = 0; i < functions.size(); ++i)
63 functions[i]->GenerateIR();
73 if (preFunc != NULL) {
74 if (preFunc(node, data) ==
false)
81 if (llvm::dyn_cast<Stmt>(node) != NULL) {
101 if ((es = llvm::dyn_cast<ExprStmt>(node)) != NULL)
103 else if ((ds = llvm::dyn_cast<DeclStmt>(node)) != NULL) {
104 for (
unsigned int i = 0; i < ds->
vars.size(); ++i)
106 }
else if ((is = llvm::dyn_cast<IfStmt>(node)) != NULL) {
110 }
else if ((dos = llvm::dyn_cast<DoStmt>(node)) != NULL) {
113 }
else if ((fs = llvm::dyn_cast<ForStmt>(node)) != NULL) {
118 }
else if ((fes = llvm::dyn_cast<ForeachStmt>(node)) != NULL) {
119 for (
unsigned int i = 0; i < fes->
startExprs.size(); ++i)
121 for (
unsigned int i = 0; i < fes->
endExprs.size(); ++i)
124 }
else if ((fas = llvm::dyn_cast<ForeachActiveStmt>(node)) != NULL) {
126 }
else if ((fus = llvm::dyn_cast<ForeachUniqueStmt>(node)) != NULL) {
129 }
else if ((cs = llvm::dyn_cast<CaseStmt>(node)) != NULL)
131 else if ((defs = llvm::dyn_cast<DefaultStmt>(node)) != NULL)
133 else if ((ss = llvm::dyn_cast<SwitchStmt>(node)) != NULL) {
136 }
else if (llvm::dyn_cast<BreakStmt>(node) != NULL || llvm::dyn_cast<
ContinueStmt>(node) != NULL ||
137 llvm::dyn_cast<GotoStmt>(node) != NULL) {
139 }
else if ((ls = llvm::dyn_cast<LabeledStmt>(node)) != NULL)
141 else if ((rs = llvm::dyn_cast<ReturnStmt>(node)) != NULL)
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)
149 else if ((as = llvm::dyn_cast<AssertStmt>(node)) != NULL)
151 else if ((dels = llvm::dyn_cast<DeleteStmt>(node)) != NULL)
153 else if ((ums = llvm::dyn_cast<UnmaskedStmt>(node)) != NULL)
156 FATAL(
"Unhandled statement type in WalkAST()");
160 Assert(llvm::dyn_cast<Expr>(node) != NULL);
177 if ((ue = llvm::dyn_cast<UnaryExpr>(node)) != NULL)
179 else if ((be = llvm::dyn_cast<BinaryExpr>(node)) != NULL) {
182 }
else if ((ae = llvm::dyn_cast<AssignExpr>(node)) != NULL) {
185 }
else if ((se = llvm::dyn_cast<SelectExpr>(node)) != NULL) {
189 }
else if ((el = llvm::dyn_cast<ExprList>(node)) != NULL) {
190 for (
unsigned int i = 0; i < el->
exprs.size(); ++i)
192 }
else if ((fce = llvm::dyn_cast<FunctionCallExpr>(node)) != NULL) {
195 for (
int k = 0; k < 3; k++)
197 }
else if ((ie = llvm::dyn_cast<IndexExpr>(node)) != NULL) {
200 }
else if ((me = llvm::dyn_cast<MemberExpr>(node)) != NULL)
202 else if ((tce = llvm::dyn_cast<TypeCastExpr>(node)) != NULL)
204 else if ((re = llvm::dyn_cast<ReferenceExpr>(node)) != NULL)
206 else if ((ptrderef = llvm::dyn_cast<PtrDerefExpr>(node)) != NULL)
208 else if ((refderef = llvm::dyn_cast<RefDerefExpr>(node)) != NULL)
210 else if ((soe = llvm::dyn_cast<SizeOfExpr>(node)) != NULL)
212 else if ((aoe = llvm::dyn_cast<AddressOfExpr>(node)) != NULL)
214 else if ((newe = llvm::dyn_cast<NewExpr>(node)) != NULL) {
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) {
222 FATAL(
"Unhandled expression type in WalkAST().");
226 if (postFunc != NULL)
227 return postFunc(node, data);
257 if (llvm::dyn_cast<ForeachStmt>(node) != NULL)
266 if (llvm::dyn_cast<ForeachStmt>(node) != NULL)
281 bool *okPtr = (
bool *)data;
284 if ((fce = llvm::dyn_cast<FunctionCallExpr>(node)) != NULL) {
285 if (fce->
func == NULL)
289 const PointerType *pt = CastType<PointerType>(type);
292 const FunctionType *ftype = CastType<FunctionType>(type);
295 if (ftype->
isSafe ==
false) {
301 if (llvm::dyn_cast<AssertStmt>(node) != NULL) {
309 if (llvm::dyn_cast<PrintStmt>(node) != NULL) {
314 if (llvm::dyn_cast<NewExpr>(node) != NULL || llvm::dyn_cast<DeleteStmt>(node) != NULL) {
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) {
338 if ((binaryExpr = llvm::dyn_cast<BinaryExpr>(node)) != NULL) {
345 if ((ie = llvm::dyn_cast<IndexExpr>(node)) != NULL && ie->
baseExpr != NULL) {
349 if (CastType<ReferenceType>(type) != NULL)
359 const PointerType *pointerType = CastType<PointerType>(type);
360 if (pointerType != NULL) {
369 if (nElements == 0) {
377 for (
int i = 0; i < count; ++i) {
378 if (indices[i] < 0 || indices[i] >= nElements) {
390 if ((me = llvm::dyn_cast<MemberExpr>(node)) != NULL && me->
dereferenceExpr) {
395 if (llvm::dyn_cast<PtrDerefExpr>(node) != NULL) {
405 if ((ae = llvm::dyn_cast<AssignExpr>(node)) != NULL) {
bool IsUniformType() const
virtual int EstimateCost() const =0
std::vector< VariableDeclaration > vars
static ASTNode * lCostCallbackPost(ASTNode *node, void *d)
ASTNode * WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, void *data)
virtual ASTNode * TypeCheck()=0
static bool lCheckAllOffSafety(ASTNode *node, void *data)
std::vector< Expr * > endExprs
bool SafeToRunWithMaskAllOff(ASTNode *root)
Representation of a print() statement in the program.
Expression that represents taking a reference of a (non-reference) variable.
Interface class for statements in the ispc language.
Statement representing a single declaration (which in turn may declare a number of variables...
Statement representing a single expression.
Expression representing a compile-time constant value.
Abstract base class for types that represent sequences.
Statement implementation for 'for' loops (as well as for 'while' loops).
static ASTNode * lTypeCheckNode(ASTNode *node, void *)
Representation of an assert statement in the program.
Statement implementation representing a 'do' statement in the program.
Type implementation for pointers to other types.
header file with declarations for symbol and symbol table classes.
virtual const Type * GetReferenceTarget() const
File with declarations for classes related to statements in the language.
Expression representing a type cast of the given expression to a probably-different type...
Statement implementation for a 'return' statement in the program.
Abstract base class for nodes in the abstract syntax tree (AST).
virtual int GetElementCount() const =0
Statement implementation for a continue statement in the program.
int GetValues(bool *, bool forceVarying=false) const
virtual ASTNode * Optimize()=0
virtual const Type * GetType() const =0
A sync statement in the program (waits for all launched tasks before proceeding). ...
bool(* ASTPreCallBackFunc)(ASTNode *node, void *data)
Expr * launchCountExpr[3]
Representation of a function in a source file.
Expression representing member selection ("foo.bar").
std::vector< Expr * > exprs
std::vector< Expr * > startExprs
Expression representing indexing into something with an integer offset.
Type representing a function (return type + argument types)
Representation of a program symbol.
void AddFunction(Symbol *sym, Stmt *code)
ASTNode *(* ASTPostCallBackFunc)(ASTNode *node, void *data)
Interface class that defines the type abstraction.
static bool lCostCallbackPre(ASTNode *node, void *d)
std::vector< Stmt * > stmts
Expression that represents dereferencing a pointer to get its value.
Expr abstract base class and expression implementations.
Statement implementation for parallel 'foreach' loops.
Statement representing a single if statement, possibly with an else clause.
Expr is the abstract base class that defines the interface that all expression types must implement...
Representation of a list of statements in the program.
Expression that represents dereferencing a reference to get its value.
const Type * GetBaseType() const
Selection expression, corresponding to "test ? a : b".
const Type * GetType() const
static ASTNode * lOptimizeNode(ASTNode *node, void *)
Expression representing a function call.