Intel® Implicit SPMD Program Compiler (Intel® ISPC)  1.13.0
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

◆ EstimateCost()

int EstimateCost ( ASTNode root)

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

Definition at line 271 of file ast.cpp.

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

Referenced by Function::emitCode().

◆ lCheckAllOffSafety()

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

◆ lCostCallbackPost()

static ASTNode* lCostCallbackPost ( ASTNode node,
void *  d 
)
static

Definition at line 264 of file ast.cpp.

References CostData::foreachDepth.

Referenced by EstimateCost().

◆ lCostCallbackPre()

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

Definition at line 255 of file ast.cpp.

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

Referenced by EstimateCost().

◆ lOptimizeNode()

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

Definition at line 232 of file ast.cpp.

References ASTNode::Optimize().

Referenced by Optimize().

◆ lTypeCheckNode()

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

Definition at line 240 of file ast.cpp.

References ASTNode::TypeCheck().

Referenced by TypeCheck().

◆ Optimize() [1/3]

ASTNode* Optimize ( ASTNode root)

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

Definition at line 234 of file ast.cpp.

References lOptimizeNode(), and WalkAST().

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

◆ Optimize() [2/3]

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 236 of file ast.cpp.

References ASTNode::Optimize().

◆ Optimize() [3/3]

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 238 of file ast.cpp.

References ASTNode::Optimize().

◆ SafeToRunWithMaskAllOff()

bool SafeToRunWithMaskAllOff ( ASTNode root)

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

Definition at line 417 of file ast.cpp.

References lCheckAllOffSafety(), and WalkAST().

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

◆ TypeCheck() [1/3]

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 242 of file ast.cpp.

References lTypeCheckNode(), and WalkAST().

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

◆ TypeCheck() [2/3]

Expr* TypeCheck ( Expr )

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

Definition at line 244 of file ast.cpp.

References ASTNode::TypeCheck().

◆ TypeCheck() [3/3]

Stmt* TypeCheck ( Stmt )

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

Definition at line 246 of file ast.cpp.

References ASTNode::TypeCheck().

◆ WalkAST()

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 68 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, ReturnStmt::expr, MemberExpr::expr, SwitchStmt::expr, TypeCastExpr::expr, AssertStmt::expr, ReferenceExpr::expr, DeleteStmt::expr, DerefExpr::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, DeclStmt::vars, and WalkAST().

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