Rewrite AST optimization infrastructure to be built on top of WalkAST().

Specifically, stmts and exprs are no longer responsible for first recursively
optimizing their children before doing their own optimization (this turned
out to be error-prone, with children sometimes being forgotten.)  They now
are just responsible for their own optimization, when appropriate.
This commit is contained in:
Matt Pharr
2011-12-16 11:35:18 -08:00
parent ced3f1f5fc
commit f48a662ed3
9 changed files with 64 additions and 202 deletions

13
ast.h
View File

@@ -53,10 +53,11 @@ public:
virtual ~ASTNode();
/** The Optimize() method should perform any appropriate early-stage
optimizations on the node (e.g. constant folding). The caller
should use the returned ASTNode * in place of the original node.
This method may return NULL if an error is encountered during
optimization. */
optimizations on the node (e.g. constant folding). This method
will be called after the node's children have already been
optimized, and the caller will store the returned ASTNode * in
place of the original node. This method should return NULL if an
error is encountered during optimization. */
virtual ASTNode *Optimize() = 0;
/** Type checking should be performed by the node when this method is
@@ -112,4 +113,8 @@ typedef ASTNode * (* ASTPostCallBackFunc)(ASTNode *node, void *data);
extern ASTNode *WalkAST(ASTNode *root, ASTPreCallBackFunc preFunc,
ASTPostCallBackFunc postFunc, void *data);
extern Expr *Optimize(Expr *);
extern Stmt *Optimize(Stmt *);
extern ASTNode *Optimize(ASTNode *root);
#endif // ISPC_AST_H