Intel SPMD Program Compiler  1.9.1
Classes | Functions
ast.cpp File Reference

General functionality related to abstract syntax trees and traversal of them. More...

#include "ast.h"
#include "expr.h"
#include "func.h"
#include "stmt.h"
#include "sym.h"
#include "util.h"
Include dependency graph for ast.cpp:

Go to the source code of this file.

Classes

struct  CostData
 

Functions

ASTNodeWalkAST (ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, void *data)
 
static ASTNodelOptimizeNode (ASTNode *node, void *)
 
ASTNodeOptimize (ASTNode *root)
 
ExprOptimize (Expr *expr)
 
StmtOptimize (Stmt *stmt)
 
static ASTNodelTypeCheckNode (ASTNode *node, void *)
 
ASTNodeTypeCheck (ASTNode *root)
 
ExprTypeCheck (Expr *expr)
 
StmtTypeCheck (Stmt *stmt)
 
static bool lCostCallbackPre (ASTNode *node, void *d)
 
static ASTNodelCostCallbackPost (ASTNode *node, void *d)
 
int EstimateCost (ASTNode *root)
 
static bool lCheckAllOffSafety (ASTNode *node, void *data)
 
bool SafeToRunWithMaskAllOff (ASTNode *root)
 

Detailed Description

General functionality related to abstract syntax trees and traversal of them.

Definition in file ast.cpp.

Function Documentation

int EstimateCost ( ASTNode root)

Returns an estimate of the execution cost of the tree starting at the given root.

Definition at line 352 of file ast.cpp.

References CostData::cost, lCostCallbackPost(), lCostCallbackPre(), and WalkAST().

Referenced by Function::emitCode(), lCheckMask(), and lEmitLogicalOp().

static bool lCheckAllOffSafety ( ASTNode node,
void *  data 
)
static
static ASTNode* lCostCallbackPost ( ASTNode node,
void *  d 
)
static

Definition at line 343 of file ast.cpp.

References CostData::foreachDepth.

Referenced by EstimateCost().

static bool lCostCallbackPre ( ASTNode node,
void *  d 
)
static

Definition at line 332 of file ast.cpp.

References CostData::cost, ASTNode::EstimateCost(), and CostData::foreachDepth.

Referenced by EstimateCost().

static ASTNode* lOptimizeNode ( ASTNode node,
void *   
)
static

Definition at line 276 of file ast.cpp.

References ASTNode::Optimize().

Referenced by Optimize().

static ASTNode* lTypeCheckNode ( ASTNode node,
void *   
)
static

Definition at line 300 of file ast.cpp.

References ASTNode::TypeCheck().

Referenced by TypeCheck().

ASTNode* Optimize ( ASTNode root)

Perform simple optimizations on the AST or portion thereof passed to this function, returning the resulting AST.

Definition at line 282 of file ast.cpp.

References lOptimizeNode(), and WalkAST().

Referenced by Module::AddGlobalVariable(), Module::CompileFile(), Function::Function(), Declarator::InitFromType(), lArrayToPointer(), BinaryExpr::Optimize(), and Optimize().

Expr* Optimize ( Expr )

Convenience version of Optimize() for Expr *s that returns an Expr * (rather than an ASTNode *, which would require the caller to cast back to an Expr *).

Definition at line 288 of file ast.cpp.

References Optimize().

Stmt* Optimize ( Stmt )

Convenience version of Optimize() for Expr *s that returns an Stmt * (rather than an ASTNode *, which would require the caller to cast back to a Stmt *).

Definition at line 294 of file ast.cpp.

References Optimize().

bool SafeToRunWithMaskAllOff ( ASTNode root)

Returns true if it would be safe to run the given code with an "all off" mask.

Definition at line 506 of file ast.cpp.

References lCheckAllOffSafety(), and WalkAST().

Referenced by IfStmt::emitVaryingIf(), SelectExpr::GetValue(), lCheckMask(), and lEmitLogicalOp().

ASTNode* TypeCheck ( ASTNode root)

Perform type-checking on the given AST (or portion of one), returning a pointer to the root of the resulting AST.

Definition at line 306 of file ast.cpp.

References lTypeCheckNode(), and WalkAST().

Referenced by Module::AddGlobalVariable(), Function::Function(), Declarator::InitFromType(), lArrayToPointer(), TypeCheck(), and TypeCastExpr::TypeCheck().

Expr* TypeCheck ( Expr )

Convenience version of TypeCheck() for Expr *s that returns an Expr *.

Definition at line 312 of file ast.cpp.

References TypeCheck().

Stmt* TypeCheck ( Stmt )

Convenience version of TypeCheck() for Stmt *s that returns an Stmt *.

Definition at line 318 of file ast.cpp.

References TypeCheck().

ASTNode* WalkAST ( ASTNode root,
ASTPreCallBackFunc  preFunc,
ASTPostCallBackFunc  postFunc,
void *  data 
)

Walk (some portion of) an AST, starting from the given root node. At each node, if preFunc is non-NULL, call it, passing the given void data pointer; if the call to preFunc function returns false, then the children of the node aren't visited. This function then makes recursive calls to WalkAST() to process the node's children; after doing so, calls postFunc, at the node. The return value from the postFunc call is ignored.

Definition at line 74 of file ast.cpp.

References BinaryExpr::arg0, BinaryExpr::arg1, FunctionCallExpr::args, Assert, IndexExpr::baseExpr, DoStmt::bodyStmts, NewExpr::countExpr, ForeachStmt::endExprs, ExprStmt::expr, UnaryExpr::expr, ForeachUniqueStmt::expr, MemberExpr::expr, ReturnStmt::expr, SwitchStmt::expr, TypeCastExpr::expr, ReferenceExpr::expr, DerefExpr::expr, AssertStmt::expr, DeleteStmt::expr, AddressOfExpr::expr, SizeOfExpr::expr, SelectExpr::expr1, SelectExpr::expr2, ExprList::exprs, IfStmt::falseStmts, FATAL, FunctionCallExpr::func, IndexExpr::index, ForStmt::init, NewExpr::initExpr, FunctionCallExpr::launchCountExpr, AssignExpr::lvalue, AssignExpr::rvalue, ForeachStmt::startExprs, ForStmt::step, LabeledStmt::stmt, ForStmt::stmts, ForeachStmt::stmts, ForeachActiveStmt::stmts, ForeachUniqueStmt::stmts, UnmaskedStmt::stmts, CaseStmt::stmts, DefaultStmt::stmts, SwitchStmt::stmts, StmtList::stmts, IfStmt::test, ForStmt::test, SelectExpr::test, DoStmt::testExpr, IfStmt::trueStmts, PrintStmt::values, and DeclStmt::vars.

Referenced by SwitchStmt::EmitCode(), EstimateCost(), FunctionEmitContext::InitializeLabelMap(), lHasVaryingBreakOrContinue(), Optimize(), SafeToRunWithMaskAllOff(), and TypeCheck().