diff --git a/Makefile b/Makefile index b551a49a..5301fab5 100644 --- a/Makefile +++ b/Makefile @@ -169,7 +169,7 @@ CXXFLAGS=$(OPT) $(LLVM_CXXFLAGS) -I. -Iobjs/ -I$(CLANG_INCLUDE) \ # if( !($(LLVM_VERSION) == LLVM_3_2 || $(LLVM_VERSION) == LLVM_3_3 || $(LLVM_VERSION) == LLVM_3_4)) ifeq (,$(filter $(LLVM_VERSION), LLVM_3_2 LLVM_3_3 LLVM_3_4)) - CXXFLAGS+=-std=c++11 -Wno-c99-extensions -Wno-deprecated-register + CXXFLAGS+=-std=c++11 -Wno-c99-extensions -Wno-deprecated-register -fno-rtti endif ifneq ($(ARM_ENABLED), 0) CXXFLAGS+=-DISPC_ARM_ENABLED diff --git a/ast.cpp b/ast.cpp index fa5b8083..ca465571 100644 --- a/ast.cpp +++ b/ast.cpp @@ -85,7 +85,7 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, //////////////////////////////////////////////////////////////////////////// // Handle Statements - if (dynamic_cast(node) != NULL) { + if (llvm::dyn_cast(node) != NULL) { ExprStmt *es; DeclStmt *ds; IfStmt *is; @@ -105,33 +105,33 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, DeleteStmt *dels; UnmaskedStmt *ums; - if ((es = dynamic_cast(node)) != NULL) + if ((es = llvm::dyn_cast(node)) != NULL) es->expr = (Expr *)WalkAST(es->expr, preFunc, postFunc, data); - else if ((ds = dynamic_cast(node)) != NULL) { + else if ((ds = llvm::dyn_cast(node)) != NULL) { for (unsigned int i = 0; i < ds->vars.size(); ++i) ds->vars[i].init = (Expr *)WalkAST(ds->vars[i].init, preFunc, postFunc, data); } - else if ((is = dynamic_cast(node)) != NULL) { + else if ((is = llvm::dyn_cast(node)) != NULL) { is->test = (Expr *)WalkAST(is->test, preFunc, postFunc, data); is->trueStmts = (Stmt *)WalkAST(is->trueStmts, preFunc, postFunc, data); is->falseStmts = (Stmt *)WalkAST(is->falseStmts, preFunc, postFunc, data); } - else if ((dos = dynamic_cast(node)) != NULL) { + else if ((dos = llvm::dyn_cast(node)) != NULL) { dos->testExpr = (Expr *)WalkAST(dos->testExpr, preFunc, postFunc, data); dos->bodyStmts = (Stmt *)WalkAST(dos->bodyStmts, preFunc, postFunc, data); } - else if ((fs = dynamic_cast(node)) != NULL) { + else if ((fs = llvm::dyn_cast(node)) != NULL) { fs->init = (Stmt *)WalkAST(fs->init, preFunc, postFunc, data); fs->test = (Expr *)WalkAST(fs->test, preFunc, postFunc, data); fs->step = (Stmt *)WalkAST(fs->step, preFunc, postFunc, data); fs->stmts = (Stmt *)WalkAST(fs->stmts, preFunc, postFunc, data); } - else if ((fes = dynamic_cast(node)) != NULL) { + else if ((fes = llvm::dyn_cast(node)) != NULL) { for (unsigned int i = 0; i < fes->startExprs.size(); ++i) fes->startExprs[i] = (Expr *)WalkAST(fes->startExprs[i], preFunc, postFunc, data); @@ -140,42 +140,42 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, postFunc, data); fes->stmts = (Stmt *)WalkAST(fes->stmts, preFunc, postFunc, data); } - else if ((fas = dynamic_cast(node)) != NULL) { + else if ((fas = llvm::dyn_cast(node)) != NULL) { fas->stmts = (Stmt *)WalkAST(fas->stmts, preFunc, postFunc, data); } - else if ((fus = dynamic_cast(node)) != NULL) { + else if ((fus = llvm::dyn_cast(node)) != NULL) { fus->expr = (Expr *)WalkAST(fus->expr, preFunc, postFunc, data); fus->stmts = (Stmt *)WalkAST(fus->stmts, preFunc, postFunc, data); } - else if ((cs = dynamic_cast(node)) != NULL) + else if ((cs = llvm::dyn_cast(node)) != NULL) cs->stmts = (Stmt *)WalkAST(cs->stmts, preFunc, postFunc, data); - else if ((defs = dynamic_cast(node)) != NULL) + else if ((defs = llvm::dyn_cast(node)) != NULL) defs->stmts = (Stmt *)WalkAST(defs->stmts, preFunc, postFunc, data); - else if ((ss = dynamic_cast(node)) != NULL) { + else if ((ss = llvm::dyn_cast(node)) != NULL) { ss->expr = (Expr *)WalkAST(ss->expr, preFunc, postFunc, data); ss->stmts = (Stmt *)WalkAST(ss->stmts, preFunc, postFunc, data); } - else if (dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL) { + else if (llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL) { // nothing } - else if ((ls = dynamic_cast(node)) != NULL) + else if ((ls = llvm::dyn_cast(node)) != NULL) ls->stmt = (Stmt *)WalkAST(ls->stmt, preFunc, postFunc, data); - else if ((rs = dynamic_cast(node)) != NULL) + else if ((rs = llvm::dyn_cast(node)) != NULL) rs->expr = (Expr *)WalkAST(rs->expr, preFunc, postFunc, data); - else if ((sl = dynamic_cast(node)) != NULL) { + else if ((sl = llvm::dyn_cast(node)) != NULL) { std::vector &sls = sl->stmts; for (unsigned int i = 0; i < sls.size(); ++i) sls[i] = (Stmt *)WalkAST(sls[i], preFunc, postFunc, data); } - else if ((ps = dynamic_cast(node)) != NULL) + else if ((ps = llvm::dyn_cast(node)) != NULL) ps->values = (Expr *)WalkAST(ps->values, preFunc, postFunc, data); - else if ((as = dynamic_cast(node)) != NULL) + else if ((as = llvm::dyn_cast(node)) != NULL) as->expr = (Expr *)WalkAST(as->expr, preFunc, postFunc, data); - else if ((dels = dynamic_cast(node)) != NULL) + else if ((dels = llvm::dyn_cast(node)) != NULL) dels->expr = (Expr *)WalkAST(dels->expr, preFunc, postFunc, data); - else if ((ums = dynamic_cast(node)) != NULL) + else if ((ums = llvm::dyn_cast(node)) != NULL) ums->stmts = (Stmt *)WalkAST(ums->stmts, preFunc, postFunc, data); else FATAL("Unhandled statement type in WalkAST()"); @@ -183,7 +183,7 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, else { /////////////////////////////////////////////////////////////////////////// // Handle expressions - Assert(dynamic_cast(node) != NULL); + Assert(llvm::dyn_cast(node) != NULL); UnaryExpr *ue; BinaryExpr *be; AssignExpr *ae; @@ -200,64 +200,64 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc, AddressOfExpr *aoe; NewExpr *newe; - if ((ue = dynamic_cast(node)) != NULL) + if ((ue = llvm::dyn_cast(node)) != NULL) ue->expr = (Expr *)WalkAST(ue->expr, preFunc, postFunc, data); - else if ((be = dynamic_cast(node)) != NULL) { + else if ((be = llvm::dyn_cast(node)) != NULL) { be->arg0 = (Expr *)WalkAST(be->arg0, preFunc, postFunc, data); be->arg1 = (Expr *)WalkAST(be->arg1, preFunc, postFunc, data); } - else if ((ae = dynamic_cast(node)) != NULL) { + else if ((ae = llvm::dyn_cast(node)) != NULL) { ae->lvalue = (Expr *)WalkAST(ae->lvalue, preFunc, postFunc, data); ae->rvalue = (Expr *)WalkAST(ae->rvalue, preFunc, postFunc, data); } - else if ((se = dynamic_cast(node)) != NULL) { + else if ((se = llvm::dyn_cast(node)) != NULL) { se->test = (Expr *)WalkAST(se->test, preFunc, postFunc, data); se->expr1 = (Expr *)WalkAST(se->expr1, preFunc, postFunc, data); se->expr2 = (Expr *)WalkAST(se->expr2, preFunc, postFunc, data); } - else if ((el = dynamic_cast(node)) != NULL) { + else if ((el = llvm::dyn_cast(node)) != NULL) { for (unsigned int i = 0; i < el->exprs.size(); ++i) el->exprs[i] = (Expr *)WalkAST(el->exprs[i], preFunc, postFunc, data); } - else if ((fce = dynamic_cast(node)) != NULL) { + else if ((fce = llvm::dyn_cast(node)) != NULL) { fce->func = (Expr *)WalkAST(fce->func, preFunc, postFunc, data); fce->args = (ExprList *)WalkAST(fce->args, preFunc, postFunc, data); for (int k = 0; k < 3; k++) fce->launchCountExpr[0] = (Expr *)WalkAST(fce->launchCountExpr[0], preFunc, postFunc, data); } - else if ((ie = dynamic_cast(node)) != NULL) { + else if ((ie = llvm::dyn_cast(node)) != NULL) { ie->baseExpr = (Expr *)WalkAST(ie->baseExpr, preFunc, postFunc, data); ie->index = (Expr *)WalkAST(ie->index, preFunc, postFunc, data); } - else if ((me = dynamic_cast(node)) != NULL) + else if ((me = llvm::dyn_cast(node)) != NULL) me->expr = (Expr *)WalkAST(me->expr, preFunc, postFunc, data); - else if ((tce = dynamic_cast(node)) != NULL) + else if ((tce = llvm::dyn_cast(node)) != NULL) tce->expr = (Expr *)WalkAST(tce->expr, preFunc, postFunc, data); - else if ((re = dynamic_cast(node)) != NULL) + else if ((re = llvm::dyn_cast(node)) != NULL) re->expr = (Expr *)WalkAST(re->expr, preFunc, postFunc, data); - else if ((ptrderef = dynamic_cast(node)) != NULL) + else if ((ptrderef = llvm::dyn_cast(node)) != NULL) ptrderef->expr = (Expr *)WalkAST(ptrderef->expr, preFunc, postFunc, data); - else if ((refderef = dynamic_cast(node)) != NULL) + else if ((refderef = llvm::dyn_cast(node)) != NULL) refderef->expr = (Expr *)WalkAST(refderef->expr, preFunc, postFunc, data); - else if ((soe = dynamic_cast(node)) != NULL) + else if ((soe = llvm::dyn_cast(node)) != NULL) soe->expr = (Expr *)WalkAST(soe->expr, preFunc, postFunc, data); - else if ((aoe = dynamic_cast(node)) != NULL) + else if ((aoe = llvm::dyn_cast(node)) != NULL) aoe->expr = (Expr *)WalkAST(aoe->expr, preFunc, postFunc, data); - else if ((newe = dynamic_cast(node)) != NULL) { + else if ((newe = llvm::dyn_cast(node)) != NULL) { newe->countExpr = (Expr *)WalkAST(newe->countExpr, preFunc, postFunc, data); newe->initExpr = (Expr *)WalkAST(newe->initExpr, preFunc, postFunc, data); } - else if (dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL) { + else if (llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL) { // nothing to do } else @@ -331,7 +331,7 @@ struct CostData { static bool lCostCallbackPre(ASTNode *node, void *d) { CostData *data = (CostData *)d; - if (dynamic_cast(node) != NULL) + if (llvm::dyn_cast(node) != NULL) ++data->foreachDepth; if (data->foreachDepth == 0) data->cost += node->EstimateCost(); @@ -342,7 +342,7 @@ lCostCallbackPre(ASTNode *node, void *d) { static ASTNode * lCostCallbackPost(ASTNode *node, void *d) { CostData *data = (CostData *)d; - if (dynamic_cast(node) != NULL) + if (llvm::dyn_cast(node) != NULL) --data->foreachDepth; return node; } @@ -364,7 +364,7 @@ lCheckAllOffSafety(ASTNode *node, void *data) { bool *okPtr = (bool *)data; FunctionCallExpr *fce; - if ((fce = dynamic_cast(node)) != NULL) { + if ((fce = llvm::dyn_cast(node)) != NULL) { if (fce->func == NULL) return false; @@ -381,7 +381,7 @@ lCheckAllOffSafety(ASTNode *node, void *data) { } } - if (dynamic_cast(node) != NULL) { + if (llvm::dyn_cast(node) != NULL) { // While it's fine to run the assert for varying tests, it's not // desirable to check an assert on a uniform variable if all of the // lanes are off. @@ -389,13 +389,13 @@ lCheckAllOffSafety(ASTNode *node, void *data) { return false; } - if (dynamic_cast(node) != NULL) { + if (llvm::dyn_cast(node) != NULL) { *okPtr = false; return false; } - if (dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL) { + if (llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL) { // We definitely don't want to run the uniform variants of these if // the mask is all off. It's also worth skipping the overhead of // executing the varying versions of them in the all-off mask case. @@ -403,10 +403,10 @@ lCheckAllOffSafety(ASTNode *node, void *data) { return false; } - if (dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL) { + if (llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL) { // The various foreach statements also shouldn't be run with an // all-off mask. Since they can re-establish an 'all on' mask, // this would be pretty unintuitive. (More generally, it's @@ -421,14 +421,14 @@ lCheckAllOffSafety(ASTNode *node, void *data) { } IndexExpr *ie; - if ((ie = dynamic_cast(node)) != NULL && ie->baseExpr != NULL) { + if ((ie = llvm::dyn_cast(node)) != NULL && ie->baseExpr != NULL) { const Type *type = ie->baseExpr->GetType(); if (type == NULL) return true; if (CastType(type) != NULL) type = type->GetReferenceTarget(); - ConstExpr *ce = dynamic_cast(ie->index); + ConstExpr *ce = llvm::dyn_cast(ie->index); if (ce == NULL) { // indexing with a variable... -> not safe *okPtr = false; @@ -466,13 +466,13 @@ lCheckAllOffSafety(ASTNode *node, void *data) { } MemberExpr *me; - if ((me = dynamic_cast(node)) != NULL && + if ((me = llvm::dyn_cast(node)) != NULL && me->dereferenceExpr) { *okPtr = false; return false; } - if (dynamic_cast(node) != NULL) { + if (llvm::dyn_cast(node) != NULL) { *okPtr = false; return false; } @@ -482,7 +482,7 @@ lCheckAllOffSafety(ASTNode *node, void *data) { assign to a uniform. */ AssignExpr *ae; - if ((ae = dynamic_cast(node)) != NULL) { + if ((ae = llvm::dyn_cast(node)) != NULL) { if (ae->GetType()) { if (ae->GetType()->IsUniformType()) { *okPtr = false; diff --git a/ast.h b/ast.h index e0f864ba..0a2a2edf 100644 --- a/ast.h +++ b/ast.h @@ -48,8 +48,9 @@ (Expr) and statements (Stmt) inherit from this class. */ class ASTNode { + const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast) public: - ASTNode(SourcePos p) : pos(p) { } + ASTNode(SourcePos p, unsigned scid) : SubclassID(scid), pos(p) { } virtual ~ASTNode(); /** The Optimize() method should perform any appropriate early-stage @@ -74,12 +75,72 @@ public: /** All AST nodes must track the file position where they are defined. */ SourcePos pos; + + /** An enumeration for keeping track of the concrete subclass of Value + that is actually instantiated.*/ + enum ASTNodeTy { + /* For classes inherited from Expr */ + AddressOfExprID, + AssignExprID, + BinaryExprID, + ConstExprID, + DerefExprID, + PtrDerefExprID, + RefDerefExprID, + ExprListID, + FunctionCallExprID, + FunctionSymbolExprID, + IndexExprID, + StructMemberExprID, + VectorMemberExprID, + NewExprID, + NullPointerExprID, + ReferenceExprID, + SelectExprID, + SizeOfExprID, + SymbolExprID, + SyncExprID, + TypeCastExprID, + UnaryExprID, + /* This is a convenience separator to shorten classof implementations */ + MaxExprID, + /* For classes inherited from Stmt */ + AssertStmtID, + BreakStmtID, + CaseStmtID, + ContinueStmtID, + DeclStmtID, + DefaultStmtID, + DeleteStmtID, + DoStmtID, + ExprStmtID, + ForeachActiveStmtID, + ForeachStmtID, + ForeachUniqueStmtID, + ForStmtID, + GotoStmtID, + IfStmtID, + LabeledStmtID, + PrintStmtID, + ReturnStmtID, + StmtListID, + SwitchStmtID, + UnmaskedStmtID + }; + + /** Return an ID for the concrete type of this object. This is used to + implement the classof checks. This should not be used for any + other purpose, as the values may change as ISPC evolves */ + unsigned getValueID() const { + return SubclassID; + } + + static inline bool classof(ASTNode const*) { return true; } }; -/** Simple representation of the abstract syntax trees for all of the - functions declared in a compilation unit. - */ + + class AST { public: /** Add the AST for a function described by the given declaration diff --git a/ctx.cpp b/ctx.cpp index e4a20f64..50b03653 100644 --- a/ctx.cpp +++ b/ctx.cpp @@ -1241,7 +1241,7 @@ FunctionEmitContext::EnableGatherScatterWarnings() { bool FunctionEmitContext::initLabelBBlocks(ASTNode *node, void *data) { - LabeledStmt *ls = dynamic_cast(node); + LabeledStmt *ls = llvm::dyn_cast(node); if (ls == NULL) return true; diff --git a/decl.cpp b/decl.cpp index c915d6b8..476407bd 100644 --- a/decl.cpp +++ b/decl.cpp @@ -519,9 +519,9 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) { decl->initExpr = TypeCheck(decl->initExpr); decl->initExpr = Optimize(decl->initExpr); if (decl->initExpr != NULL) { - init = dynamic_cast(decl->initExpr); + init = llvm::dyn_cast(decl->initExpr); if (init == NULL) - init = dynamic_cast(decl->initExpr); + init = llvm::dyn_cast(decl->initExpr); if (init == NULL) Error(decl->initExpr->pos, "Default value for parameter " "\"%s\" must be a compile-time constant.", diff --git a/expr.cpp b/expr.cpp index cf20f202..8c795e3b 100644 --- a/expr.cpp +++ b/expr.cpp @@ -178,7 +178,7 @@ lIsAllIntZeros(Expr *expr) { if (type == NULL || type->IsIntType() == false) return false; - ConstExpr *ce = dynamic_cast(expr); + ConstExpr *ce = llvm::dyn_cast(expr); if (ce == NULL) return false; @@ -355,7 +355,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr, } else if (PointerType::IsVoidPointer(fromPointerType) && expr != NULL && - dynamic_cast(*expr) != NULL) { + llvm::dyn_cast(*expr) != NULL) { // and a NULL convert to any other pointer type goto typecast_ok; } @@ -617,7 +617,7 @@ PossiblyResolveFunctionOverloads(Expr *expr, const Type *type) { const FunctionType *funcType = NULL; if (CastType(type) != NULL && (funcType = CastType(type->GetBaseType())) && - (fse = dynamic_cast(expr)) != NULL) { + (fse = llvm::dyn_cast(expr)) != NULL) { // We're initializing a function pointer with a function symbol, // which in turn may represent an overloaded function. So we need // to try to resolve the overload based on the type of the symbol @@ -684,7 +684,7 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, // If the initializer is a straight up expression that isn't an // ExprList, then we'll see if we can type convert it to the type of // the variable. - if (dynamic_cast(initExpr) == NULL) { + if (llvm::dyn_cast(initExpr) == NULL) { if (PossiblyResolveFunctionOverloads(initExpr, symType) == false) return; initExpr = TypeConvertExpr(initExpr, symType, "initializer"); @@ -703,7 +703,7 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, // expressions if they have a single element (except for SOA types, // which are handled below). if (symType->IsSOAType() == false && Type::IsBasicType(symType)) { - ExprList *elist = dynamic_cast(initExpr); + ExprList *elist = llvm::dyn_cast(initExpr); if (elist != NULL) { if (elist->exprs.size() == 1) InitSymbol(ptr, symType, elist->exprs[0], ctx, pos); @@ -755,7 +755,7 @@ InitSymbol(llvm::Value *ptr, const Type *symType, Expr *initExpr, // an initializer list may be provided (float foo[3] = { 1,2,3 }), // in which case the elements are initialized with the // corresponding values. - ExprList *exprList = dynamic_cast(initExpr); + ExprList *exprList = llvm::dyn_cast(initExpr); if (exprList != NULL) { // The { ... } case; make sure we have the no more expressions // in the ExprList as we have struct members @@ -1108,11 +1108,10 @@ lEmitNegate(Expr *arg, SourcePos pos, FunctionEmitContext *ctx) { UnaryExpr::UnaryExpr(Op o, Expr *e, SourcePos p) - : Expr(p), op(o) { + : Expr(p, UnaryExprID), op(o) { expr = e; } - llvm::Value * UnaryExpr::GetValue(FunctionEmitContext *ctx) const { if (expr == NULL) @@ -1184,7 +1183,7 @@ lOptimizeBitNot(ConstExpr *constExpr, const Type *type, SourcePos pos) { Expr * UnaryExpr::Optimize() { - ConstExpr *constExpr = dynamic_cast(expr); + ConstExpr *constExpr = llvm::dyn_cast(expr); // If the operand isn't a constant, then we can't do any optimization // here... if (constExpr == NULL) @@ -1359,7 +1358,7 @@ UnaryExpr::TypeCheck() { int UnaryExpr::EstimateCost() const { - if (dynamic_cast(expr) != NULL) + if (llvm::dyn_cast(expr) != NULL) return 0; return COST_SIMPLE_ARITH_LOGIC_OP; @@ -1666,7 +1665,7 @@ lEmitBinaryCmp(BinaryExpr::Op op, llvm::Value *e0Val, llvm::Value *e1Val, BinaryExpr::BinaryExpr(Op o, Expr *a, Expr *b, SourcePos p) - : Expr(p), op(o) { + : Expr(p, BinaryExprID), op(o) { arg0 = a; arg1 = b; } @@ -1990,7 +1989,7 @@ lIsDifficultShiftAmount(Expr *expr) { if (expr->GetType()->IsVaryingType() == false) return false; - ConstExpr *ce = dynamic_cast(expr); + ConstExpr *ce = llvm::dyn_cast(expr); if (ce) { // If the shift is by a constant amount, *and* it's the same amount // in all vector lanes, we're in good shape. @@ -2002,7 +2001,7 @@ lIsDifficultShiftAmount(Expr *expr) { return false; } - TypeCastExpr *tce = dynamic_cast(expr); + TypeCastExpr *tce = llvm::dyn_cast(expr); if (tce && tce->expr) { // Finally, if the shift amount is given by a uniform value that's // been smeared out into a varying, we have the same shift for all @@ -2330,7 +2329,7 @@ lCanImproveVectorDivide(Expr *arg0, Expr *arg1, int *divisor) { // The divisor must be the same compile-time constant value for all of // the vector lanes. - ConstExpr *ce = dynamic_cast(arg1); + ConstExpr *ce = llvm::dyn_cast(arg1); if (!ce) return false; int64_t div[ISPC_MAX_NVEC]; @@ -2357,8 +2356,8 @@ BinaryExpr::Optimize() { if (arg0 == NULL || arg1 == NULL) return NULL; - ConstExpr *constArg0 = dynamic_cast(arg0); - ConstExpr *constArg1 = dynamic_cast(arg1); + ConstExpr *constArg0 = llvm::dyn_cast(arg0); + ConstExpr *constArg1 = llvm::dyn_cast(arg1); if (g->opt.fastMath) { // optimizations related to division by floats.. @@ -2823,8 +2822,8 @@ BinaryExpr::GetLValueType() const { int BinaryExpr::EstimateCost() const { - if (dynamic_cast(arg0) != NULL && - dynamic_cast(arg1) != NULL) + if (llvm::dyn_cast(arg0) != NULL && + llvm::dyn_cast(arg1) != NULL) return 0; return (op == Div || op == Mod) ? COST_COMPLEX_ARITH_OP : @@ -2945,7 +2944,7 @@ lEmitOpAssign(AssignExpr::Op op, Expr *arg0, Expr *arg1, const Type *type, AssignExpr::AssignExpr(AssignExpr::Op o, Expr *a, Expr *b, SourcePos p) - : Expr(p), op(o) { + : Expr(p, AssignExprID), op(o) { lvalue = a; rvalue = b; } @@ -3170,7 +3169,7 @@ AssignExpr::Print() const { // SelectExpr SelectExpr::SelectExpr(Expr *t, Expr *e1, Expr *e2, SourcePos p) - : Expr(p) { + : Expr(p, SelectExprID) { test = t; expr1 = e1; expr2 = e2; @@ -3404,7 +3403,7 @@ SelectExpr::Optimize() { if (test == NULL || expr1 == NULL || expr2 == NULL) return NULL; - ConstExpr *constTest = dynamic_cast(test); + ConstExpr *constTest = llvm::dyn_cast(test); if (constTest == NULL) return this; @@ -3431,8 +3430,8 @@ SelectExpr::Optimize() { // Last chance: see if the two expressions are constants; if so, // then we can do an element-wise selection based on the constant // condition.. - ConstExpr *constExpr1 = dynamic_cast(expr1); - ConstExpr *constExpr2 = dynamic_cast(expr2); + ConstExpr *constExpr1 = llvm::dyn_cast(expr1); + ConstExpr *constExpr2 = llvm::dyn_cast(expr2); if (constExpr1 == NULL || constExpr2 == NULL) return this; @@ -3555,7 +3554,7 @@ SelectExpr::Print() const { FunctionCallExpr::FunctionCallExpr(Expr *f, ExprList *a, SourcePos p, bool il, Expr *lce[3]) - : Expr(p), isLaunch(il) { + : Expr(p, FunctionCallExprID), isLaunch(il) { func = f; args = a; if (lce != NULL) @@ -3728,8 +3727,8 @@ bool FullResolveOverloads(Expr * func, ExprList * args, if (t == NULL) return false; argTypes->push_back(t); - argCouldBeNULL->push_back(lIsAllIntZeros(expr) || dynamic_cast(expr)); - argIsConstant->push_back(dynamic_cast(expr) || dynamic_cast(expr)); + argCouldBeNULL->push_back(lIsAllIntZeros(expr) || llvm::dyn_cast(expr)); + argIsConstant->push_back(llvm::dyn_cast(expr) || llvm::dyn_cast(expr)); } return true; } @@ -3740,7 +3739,7 @@ FunctionCallExpr::GetType() const { std::vector argTypes; std::vector argCouldBeNULL, argIsConstant; if (FullResolveOverloads(func, args, &argTypes, &argCouldBeNULL, &argIsConstant) == true) { - FunctionSymbolExpr *fse = dynamic_cast(func); + FunctionSymbolExpr *fse = llvm::dyn_cast(func); if (fse != NULL) { fse->ResolveOverloads(args->pos, argTypes, &argCouldBeNULL, &argIsConstant); } @@ -3785,7 +3784,7 @@ FunctionCallExpr::TypeCheck() { return NULL; } - FunctionSymbolExpr *fse = dynamic_cast(func); + FunctionSymbolExpr *fse = llvm::dyn_cast(func); if (fse != NULL) { // Regular function call if (fse->ResolveOverloads(args->pos, argTypes, &argCouldBeNULL, @@ -4012,7 +4011,7 @@ ExprList::GetConstant(const Type *type) const { const Type *elementType = collectionType->GetElementType(i); Expr *expr = exprs[i]; - if (dynamic_cast(expr) == NULL) { + if (llvm::dyn_cast(expr) == NULL) { // If there's a simple type conversion from the type of this // expression to the type we need, then let the regular type // conversion machinery handle it. @@ -4121,7 +4120,7 @@ ExprList::Print() const { // IndexExpr IndexExpr::IndexExpr(Expr *a, Expr *i, SourcePos p) - : Expr(p) { + : Expr(p, IndexExprID) { baseExpr = a; index = i; type = lvalueType = NULL; @@ -4294,8 +4293,8 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const { } else { Symbol *baseSym = GetBaseSymbol(); - if (dynamic_cast(baseExpr) == NULL && - dynamic_cast(baseExpr) == NULL) { + if (llvm::dyn_cast(baseExpr) == NULL && + llvm::dyn_cast(baseExpr) == NULL) { // Don't check if we're doing a function call or pointer arith AssertPos(pos, baseSym != NULL); } @@ -4404,7 +4403,7 @@ lCheckIndicesVersusBounds(const Type *baseExprType, Expr *index) { if (soaWidth > 0) nElements *= soaWidth; - ConstExpr *ce = dynamic_cast(index); + ConstExpr *ce = llvm::dyn_cast(index); if (ce == NULL) return; @@ -4725,6 +4724,11 @@ public: StructMemberExpr(Expr *e, const char *id, SourcePos p, SourcePos idpos, bool derefLValue); + static inline bool classof(StructMemberExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == StructMemberExprID; + } + const Type *GetType() const; const Type *GetLValueType() const; int getElementNumber() const; @@ -4737,7 +4741,7 @@ private: StructMemberExpr::StructMemberExpr(Expr *e, const char *id, SourcePos p, SourcePos idpos, bool derefLValue) - : MemberExpr(e, id, p, idpos, derefLValue) { + : MemberExpr(e, id, p, idpos, derefLValue, StructMemberExprID) { } @@ -4892,6 +4896,11 @@ public: VectorMemberExpr(Expr *e, const char *id, SourcePos p, SourcePos idpos, bool derefLValue); + static inline bool classof(VectorMemberExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == VectorMemberExprID; + } + llvm::Value *GetValue(FunctionEmitContext* ctx) const; llvm::Value *GetLValue(FunctionEmitContext* ctx) const; const Type *GetType() const; @@ -4908,7 +4917,7 @@ private: VectorMemberExpr::VectorMemberExpr(Expr *e, const char *id, SourcePos p, SourcePos idpos, bool derefLValue) - : MemberExpr(e, id, p, idpos, derefLValue) { + : MemberExpr(e, id, p, idpos, derefLValue, VectorMemberExprID) { const Type *exprType = e->GetType(); exprVectorType = CastType(exprType); if (exprVectorType == NULL) { @@ -5166,8 +5175,8 @@ MemberExpr::create(Expr *e, const char *id, SourcePos p, SourcePos idpos, MemberExpr::MemberExpr(Expr *e, const char *id, SourcePos p, SourcePos idpos, - bool derefLValue) - : Expr(p), identifierPos(idpos) { + bool derefLValue, unsigned scid) + : Expr(p, scid), identifierPos(idpos) { expr = e; identifier = id; dereferenceExpr = derefLValue; @@ -5340,7 +5349,7 @@ MemberExpr::getCandidateNearMatches() const { // ConstExpr ConstExpr::ConstExpr(const Type *t, int8_t i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt8->GetAsConstType())); @@ -5349,7 +5358,7 @@ ConstExpr::ConstExpr(const Type *t, int8_t i, SourcePos p) ConstExpr::ConstExpr(const Type *t, int8_t *i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt8->GetAsConstType()) || @@ -5360,7 +5369,7 @@ ConstExpr::ConstExpr(const Type *t, int8_t *i, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint8_t u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt8->GetAsConstType())); @@ -5369,7 +5378,7 @@ ConstExpr::ConstExpr(const Type *t, uint8_t u, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint8_t *u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt8->GetAsConstType()) || @@ -5380,7 +5389,7 @@ ConstExpr::ConstExpr(const Type *t, uint8_t *u, SourcePos p) ConstExpr::ConstExpr(const Type *t, int16_t i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt16->GetAsConstType())); @@ -5389,7 +5398,7 @@ ConstExpr::ConstExpr(const Type *t, int16_t i, SourcePos p) ConstExpr::ConstExpr(const Type *t, int16_t *i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt16->GetAsConstType()) || @@ -5400,7 +5409,7 @@ ConstExpr::ConstExpr(const Type *t, int16_t *i, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint16_t u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt16->GetAsConstType())); @@ -5409,7 +5418,7 @@ ConstExpr::ConstExpr(const Type *t, uint16_t u, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint16_t *u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt16->GetAsConstType()) || @@ -5420,7 +5429,7 @@ ConstExpr::ConstExpr(const Type *t, uint16_t *u, SourcePos p) ConstExpr::ConstExpr(const Type *t, int32_t i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt32->GetAsConstType())); @@ -5429,7 +5438,7 @@ ConstExpr::ConstExpr(const Type *t, int32_t i, SourcePos p) ConstExpr::ConstExpr(const Type *t, int32_t *i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt32->GetAsConstType()) || @@ -5440,7 +5449,7 @@ ConstExpr::ConstExpr(const Type *t, int32_t *i, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint32_t u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt32->GetAsConstType()) || @@ -5451,7 +5460,7 @@ ConstExpr::ConstExpr(const Type *t, uint32_t u, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint32_t *u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt32->GetAsConstType()) || @@ -5463,7 +5472,7 @@ ConstExpr::ConstExpr(const Type *t, uint32_t *u, SourcePos p) ConstExpr::ConstExpr(const Type *t, float f, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformFloat->GetAsConstType())); @@ -5472,7 +5481,7 @@ ConstExpr::ConstExpr(const Type *t, float f, SourcePos p) ConstExpr::ConstExpr(const Type *t, float *f, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformFloat->GetAsConstType()) || @@ -5483,7 +5492,7 @@ ConstExpr::ConstExpr(const Type *t, float *f, SourcePos p) ConstExpr::ConstExpr(const Type *t, int64_t i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt64->GetAsConstType())); @@ -5492,7 +5501,7 @@ ConstExpr::ConstExpr(const Type *t, int64_t i, SourcePos p) ConstExpr::ConstExpr(const Type *t, int64_t *i, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformInt64->GetAsConstType()) || @@ -5503,7 +5512,7 @@ ConstExpr::ConstExpr(const Type *t, int64_t *i, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint64_t u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt64->GetAsConstType())); @@ -5512,7 +5521,7 @@ ConstExpr::ConstExpr(const Type *t, uint64_t u, SourcePos p) ConstExpr::ConstExpr(const Type *t, uint64_t *u, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt64->GetAsConstType()) || @@ -5523,7 +5532,7 @@ ConstExpr::ConstExpr(const Type *t, uint64_t *u, SourcePos p) ConstExpr::ConstExpr(const Type *t, double f, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformDouble->GetAsConstType())); @@ -5532,7 +5541,7 @@ ConstExpr::ConstExpr(const Type *t, double f, SourcePos p) ConstExpr::ConstExpr(const Type *t, double *f, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformDouble->GetAsConstType()) || @@ -5543,7 +5552,7 @@ ConstExpr::ConstExpr(const Type *t, double *f, SourcePos p) ConstExpr::ConstExpr(const Type *t, bool b, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformBool->GetAsConstType())); @@ -5552,7 +5561,7 @@ ConstExpr::ConstExpr(const Type *t, bool b, SourcePos p) ConstExpr::ConstExpr(const Type *t, bool *b, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = t; type = type->GetAsConstType(); AssertPos(pos, Type::Equal(type, AtomicType::UniformBool->GetAsConstType()) || @@ -5563,7 +5572,7 @@ ConstExpr::ConstExpr(const Type *t, bool *b, SourcePos p) ConstExpr::ConstExpr(ConstExpr *old, double *v) - : Expr(old->pos) { + : Expr(old->pos, ConstExprID) { type = old->type; AtomicType::BasicType basicType = getBasicType(); @@ -5617,7 +5626,7 @@ ConstExpr::ConstExpr(ConstExpr *old, double *v) ConstExpr::ConstExpr(ConstExpr *old, SourcePos p) - : Expr(p) { + : Expr(p, ConstExprID) { type = old->type; AtomicType::BasicType basicType = getBasicType(); @@ -6223,7 +6232,7 @@ ConstExpr::Print() const { // TypeCastExpr TypeCastExpr::TypeCastExpr(const Type *t, Expr *e, SourcePos p) - : Expr(p) { + : Expr(p, TypeCastExprID) { type = t; expr = e; } @@ -7229,7 +7238,7 @@ TypeCastExpr::TypeCheck() { Expr * TypeCastExpr::Optimize() { - ConstExpr *constExpr = dynamic_cast(expr); + ConstExpr *constExpr = llvm::dyn_cast(expr); if (constExpr == NULL) // We can't do anything if this isn't a const expr return this; @@ -7315,7 +7324,7 @@ TypeCastExpr::Optimize() { int TypeCastExpr::EstimateCost() const { - if (dynamic_cast(expr) != NULL) + if (llvm::dyn_cast(expr) != NULL) return 0; // FIXME: return COST_TYPECAST_COMPLEX when appropriate @@ -7392,7 +7401,7 @@ TypeCastExpr::GetConstant(const Type *constType) const { // ReferenceExpr ReferenceExpr::ReferenceExpr(Expr *e, SourcePos p) - : Expr(p) { + : Expr(p, ReferenceExprID) { expr = e; } @@ -7500,8 +7509,8 @@ ReferenceExpr::Print() const { /////////////////////////////////////////////////////////////////////////// // DerefExpr -DerefExpr::DerefExpr(Expr *e, SourcePos p) - : Expr(p) { +DerefExpr::DerefExpr(Expr *e, SourcePos p, unsigned scid) + : Expr(p, scid) { expr = e; } @@ -7563,7 +7572,7 @@ DerefExpr::Optimize() { // PtrDerefExpr PtrDerefExpr::PtrDerefExpr(Expr *e, SourcePos p) - : DerefExpr(e, p) { + : DerefExpr(e, p, PtrDerefExprID) { } @@ -7641,7 +7650,7 @@ PtrDerefExpr::Print() const { // RefDerefExpr RefDerefExpr::RefDerefExpr(Expr *e, SourcePos p) - : DerefExpr(e, p) { + : DerefExpr(e, p, RefDerefExprID) { } @@ -7700,7 +7709,7 @@ RefDerefExpr::Print() const { // AddressOfExpr AddressOfExpr::AddressOfExpr(Expr *e, SourcePos p) - : Expr(p), expr(e) { + : Expr(p, AddressOfExprID), expr(e) { } @@ -7832,12 +7841,12 @@ AddressOfExpr::GetConstant(const Type *type) const { // SizeOfExpr SizeOfExpr::SizeOfExpr(Expr *e, SourcePos p) - : Expr(p), expr(e), type(NULL) { + : Expr(p, SizeOfExprID), expr(e), type(NULL) { } SizeOfExpr::SizeOfExpr(const Type *t, SourcePos p) - : Expr(p), expr(NULL), type(t) { + : Expr(p, SizeOfExprID), expr(NULL), type(t) { type = type->ResolveUnboundVariability(Variability::Varying); } @@ -7914,7 +7923,7 @@ SizeOfExpr::EstimateCost() const { // SymbolExpr SymbolExpr::SymbolExpr(Symbol *s, SourcePos p) - : Expr(p) { + : Expr(p, SymbolExprID) { symbol = s; } @@ -8008,7 +8017,7 @@ SymbolExpr::Print() const { FunctionSymbolExpr::FunctionSymbolExpr(const char *n, const std::vector &candidates, SourcePos p) - : Expr(p) { + : Expr(p, FunctionSymbolExprID) { name = n; candidateFunctions = candidates; matchingFunc = (candidates.size() == 1) ? candidates[0] : NULL; @@ -8555,7 +8564,7 @@ NullPointerExpr::EstimateCost() const { NewExpr::NewExpr(int typeQual, const Type *t, Expr *init, Expr *count, SourcePos tqPos, SourcePos p) - : Expr(p) { + : Expr(p, NewExprID) { allocType = t; initExpr = init; diff --git a/expr.h b/expr.h index c1570412..90bf3db8 100644 --- a/expr.h +++ b/expr.h @@ -47,7 +47,12 @@ */ class Expr : public ASTNode { public: - Expr(SourcePos p) : ASTNode(p) { } + Expr(SourcePos p, unsigned scid) : ASTNode(p, scid) { } + + static inline bool classof(Expr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() < MaxExprID; + } /** This is the main method for Expr implementations to implement. It should call methods in the FunctionEmitContext to emit LLVM IR @@ -111,6 +116,11 @@ public: UnaryExpr(Op op, Expr *expr, SourcePos pos); + static inline bool classof(UnaryExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == UnaryExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; void Print() const; @@ -152,7 +162,12 @@ public: }; BinaryExpr(Op o, Expr *a, Expr *b, SourcePos p); - + + static inline bool classof(BinaryExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == BinaryExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; const Type *GetLValueType() const; @@ -186,6 +201,11 @@ public: AssignExpr(Op o, Expr *a, Expr *b, SourcePos p); + static inline bool classof(AssignExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == AssignExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; void Print() const; @@ -207,6 +227,11 @@ class SelectExpr : public Expr { public: SelectExpr(Expr *test, Expr *a, Expr *b, SourcePos p); + static inline bool classof(SelectExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == SelectExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; void Print() const; @@ -218,7 +243,6 @@ public: Expr *test, *expr1, *expr2; }; - /** @brief A list of expressions. These are mostly used for representing curly-brace delimited @@ -227,9 +251,14 @@ public: */ class ExprList : public Expr { public: - ExprList(SourcePos p) : Expr(p) { } - ExprList(Expr *e, SourcePos p) : Expr(p) { exprs.push_back(e); } + ExprList(SourcePos p) : Expr(p, ExprListID) { } + ExprList(Expr *e, SourcePos p) : Expr(p, ExprListID) { exprs.push_back(e); } + static inline bool classof(ExprList const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ExprListID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; void Print() const; @@ -250,6 +279,11 @@ public: bool isLaunch = false, Expr *launchCountExpr[3] = NULL); + static inline bool classof(FunctionCallExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == FunctionCallExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -276,6 +310,11 @@ class IndexExpr : public Expr { public: IndexExpr(Expr *baseExpr, Expr *index, SourcePos p); + static inline bool classof(IndexExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == IndexExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -304,6 +343,13 @@ public: static MemberExpr *create(Expr *expr, const char *identifier, SourcePos pos, SourcePos identifierPos, bool derefLvalue); + + static inline bool classof(MemberExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return ((N->getValueID() == StructMemberExprID) || + (N->getValueID() == VectorMemberExprID)); + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -322,7 +368,7 @@ public: const SourcePos identifierPos; MemberExpr(Expr *expr, const char *identifier, SourcePos pos, - SourcePos identifierPos, bool derefLValue); + SourcePos identifierPos, bool derefLValue, unsigned scid); /** Indicates whether the expression should be dereferenced before the member is found. (i.e. this is true if the MemberExpr was a '->' @@ -402,6 +448,11 @@ public: but at the given position. */ ConstExpr(ConstExpr *old, SourcePos pos); + static inline bool classof(ConstExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ConstExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; void Print() const; @@ -459,6 +510,11 @@ class TypeCastExpr : public Expr { public: TypeCastExpr(const Type *t, Expr *e, SourcePos p); + static inline bool classof(TypeCastExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == TypeCastExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -481,6 +537,11 @@ class ReferenceExpr : public Expr { public: ReferenceExpr(Expr *e, SourcePos p); + static inline bool classof(ReferenceExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ReferenceExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; const Type *GetLValueType() const; @@ -498,8 +559,15 @@ public: PtrDerefExpr and RefDerefExpr. */ class DerefExpr : public Expr { public: - DerefExpr(Expr *e, SourcePos p); + DerefExpr(Expr *e, SourcePos p, unsigned scid = DerefExprID); + static inline bool classof(DerefExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return ((N->getValueID() == DerefExprID) || + (N->getValueID() == PtrDerefExprID) || + (N->getValueID() == RefDerefExprID)); + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; const Type *GetLValueType() const; @@ -516,6 +584,11 @@ class PtrDerefExpr : public DerefExpr { public: PtrDerefExpr(Expr *e, SourcePos p); + static inline bool classof(PtrDerefExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == PtrDerefExprID; + } + const Type *GetType() const; void Print() const; Expr *TypeCheck(); @@ -529,6 +602,11 @@ class RefDerefExpr : public DerefExpr { public: RefDerefExpr(Expr *e, SourcePos p); + static inline bool classof(RefDerefExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == RefDerefExprID; + } + const Type *GetType() const; void Print() const; Expr *TypeCheck(); @@ -541,6 +619,11 @@ class AddressOfExpr : public Expr { public: AddressOfExpr(Expr *e, SourcePos p); + static inline bool classof(AddressOfExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == AddressOfExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; const Type *GetLValueType() const; @@ -562,6 +645,11 @@ public: SizeOfExpr(Expr *e, SourcePos p); SizeOfExpr(const Type *t, SourcePos p); + static inline bool classof(SizeOfExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == SizeOfExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; void Print() const; @@ -581,6 +669,11 @@ class SymbolExpr : public Expr { public: SymbolExpr(Symbol *s, SourcePos p); + static inline bool classof(SymbolExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == SymbolExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; const Type *GetType() const; @@ -604,6 +697,11 @@ public: FunctionSymbolExpr(const char *name, const std::vector &candFuncs, SourcePos pos); + static inline bool classof(FunctionSymbolExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == FunctionSymbolExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; Symbol *GetBaseSymbol() const; @@ -658,8 +756,13 @@ private: proceeding). */ class SyncExpr : public Expr { public: - SyncExpr(SourcePos p) : Expr(p) { } + SyncExpr(SourcePos p) : Expr(p, SyncExprID) { } + static inline bool classof(SyncExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == SyncExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; Expr *TypeCheck(); @@ -672,8 +775,13 @@ public: /** @brief An expression that represents a NULL pointer. */ class NullPointerExpr : public Expr { public: - NullPointerExpr(SourcePos p) : Expr(p) { } + NullPointerExpr(SourcePos p) : Expr(p, NullPointerExprID) { } + static inline bool classof(NullPointerExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == NullPointerExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; Expr *TypeCheck(); @@ -692,6 +800,11 @@ public: NewExpr(int typeQual, const Type *type, Expr *initializer, Expr *count, SourcePos tqPos, SourcePos p); + static inline bool classof(NewExpr const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == NewExprID; + } + llvm::Value *GetValue(FunctionEmitContext *ctx) const; const Type *GetType() const; Expr *TypeCheck(); diff --git a/func.cpp b/func.cpp index 6529cddb..122f5601 100644 --- a/func.cpp +++ b/func.cpp @@ -499,7 +499,7 @@ Function::GenerateIR() { // non-StmtList statment... SourcePos firstStmtPos = sym->pos; if (code) { - StmtList *sl = dynamic_cast(code); + StmtList *sl = llvm::dyn_cast(code); if (sl && sl->stmts.size() > 0 && sl->stmts[0] != NULL) firstStmtPos = sl->stmts[0]->pos; else diff --git a/module.cpp b/module.cpp index 971b0bf4..3b954787 100644 --- a/module.cpp +++ b/module.cpp @@ -608,7 +608,7 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE // the same type as the global. (But not if it's an // ExprList; they don't have types per se / can't type // convert themselves anyway.) - if (dynamic_cast(initExpr) == NULL) + if (llvm::dyn_cast(initExpr) == NULL) initExpr = TypeConvertExpr(initExpr, type, "initializer"); if (initExpr != NULL) { @@ -620,11 +620,11 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE if (llvmInitializer != NULL) { if (type->IsConstType()) // Try to get a ConstExpr associated with - // the symbol. This dynamic_cast can + // the symbol. This llvm::dyn_cast can // validly fail, for example for types like // StructTypes where a ConstExpr can't // represent their values. - constValue = dynamic_cast(initExpr); + constValue = llvm::dyn_cast(initExpr); } else Error(initExpr->pos, "Initializer for global variable \"%s\" " @@ -1909,8 +1909,7 @@ std::string emitOffloadParamStruct(const std::string ¶mStructName, if (!orgParamType->IsConstType()) { Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); } - const ReferenceType *refType - = dynamic_cast(orgParamType); + const ReferenceType *refType = static_cast(orgParamType); paramType = refType->GetReferenceTarget()->GetAsNonConstType(); } else { paramType = orgParamType->GetAsNonConstType(); @@ -2028,8 +2027,7 @@ Module::writeDevStub(const char *fn) if (!orgParamType->IsConstType()) { Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); } - const ReferenceType *refType - = dynamic_cast(orgParamType); + const ReferenceType *refType = static_cast(orgParamType); paramType = refType->GetReferenceTarget()->GetAsNonConstType(); } else { paramType = orgParamType->GetAsNonConstType(); diff --git a/parse.yy b/parse.yy index 5484ceed..a5a95851 100644 --- a/parse.yy +++ b/parse.yy @@ -480,7 +480,7 @@ argument_expression_list : assignment_expression { $$ = new ExprList($1, @1); } | argument_expression_list ',' assignment_expression { - ExprList *argList = dynamic_cast($1); + ExprList *argList = llvm::dyn_cast($1); if (argList == NULL) { AssertPos(@1, m->errorCount > 0); argList = new ExprList(@3); @@ -2422,7 +2422,7 @@ lFinalizeEnumeratorSymbols(std::vector &enums, Expr *castExpr = new TypeCastExpr(enumType, enums[i]->constValue, enums[i]->pos); castExpr = Optimize(castExpr); - enums[i]->constValue = dynamic_cast(castExpr); + enums[i]->constValue = llvm::dyn_cast(castExpr); AssertPos(enums[i]->pos, enums[i]->constValue != NULL); } else { diff --git a/stmt.cpp b/stmt.cpp index 67553a8d..b96dd55c 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -82,7 +82,7 @@ Stmt::Optimize() { // ExprStmt ExprStmt::ExprStmt(Expr *e, SourcePos p) - : Stmt(p) { + : Stmt(p, ExprStmtID) { expr = e; } @@ -126,7 +126,7 @@ ExprStmt::EstimateCost() const { // DeclStmt DeclStmt::DeclStmt(const std::vector &v, SourcePos p) - : Stmt(p), vars(v) { + : Stmt(p, DeclStmtID), vars(v) { } @@ -295,7 +295,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const { // FIXME: we only need this for function pointers; it was // already done for atomic types and enums in // DeclStmt::TypeCheck()... - if (dynamic_cast(initExpr) == NULL) { + if (llvm::dyn_cast(initExpr) == NULL) { initExpr = TypeConvertExpr(initExpr, sym->type, "initializer"); // FIXME: and this is only needed to re-establish @@ -436,7 +436,7 @@ Stmt * DeclStmt::Optimize() { for (unsigned int i = 0; i < vars.size(); ++i) { Expr *init = vars[i].init; - if (init != NULL && dynamic_cast(init) == NULL) { + if (init != NULL && llvm::dyn_cast(init) == NULL) { // If the variable is const-qualified, after we've optimized // the initializer expression, see if we have a ConstExpr. If // so, save it in Symbol::constValue where it can be used in @@ -455,7 +455,7 @@ DeclStmt::Optimize() { Symbol *sym = vars[i].sym; if (sym->type && sym->type->IsConstType() && Type::Equal(init->GetType(), sym->type)) - sym->constValue = dynamic_cast(init); + sym->constValue = llvm::dyn_cast(init); } } return this; @@ -483,7 +483,7 @@ DeclStmt::TypeCheck() { // If it's an expr list with an atomic type, we'll later issue // an error. Need to leave vars[i].init as is in that case so // it is in fact caught later, though. - if (dynamic_cast(vars[i].init) == NULL) { + if (llvm::dyn_cast(vars[i].init) == NULL) { vars[i].init = TypeConvertExpr(vars[i].init, type, "initializer"); if (vars[i].init == NULL) @@ -523,7 +523,7 @@ DeclStmt::EstimateCost() const { // IfStmt IfStmt::IfStmt(Expr *t, Stmt *ts, Stmt *fs, bool checkCoherence, SourcePos p) - : Stmt(p), test(t), trueStmts(ts), falseStmts(fs), + : Stmt(p, IfStmtID), test(t), trueStmts(ts), falseStmts(fs), doAllCheck(checkCoherence && !g->opt.disableCoherentControlFlow) { } @@ -534,11 +534,11 @@ lEmitIfStatements(FunctionEmitContext *ctx, Stmt *stmts, const char *trueOrFalse if (!stmts) return; - if (dynamic_cast(stmts) == NULL) + if (llvm::dyn_cast(stmts) == NULL) ctx->StartScope(); ctx->AddInstrumentationPoint(trueOrFalse); stmts->EmitCode(ctx); - if (dynamic_cast(stmts) == NULL) + if (llvm::dyn_cast(stmts) == NULL) ctx->EndScope(); } @@ -549,18 +549,18 @@ lEmitIfStatements(FunctionEmitContext *ctx, Stmt *stmts, const char *trueOrFalse static bool lCanApplyBreakOptimization(Stmt *trueStmts, Stmt *falseStmts) { if (falseStmts != NULL) { - if (StmtList *sl = dynamic_cast(falseStmts)) { + if (StmtList *sl = llvm::dyn_cast(falseStmts)) { return (sl->stmts.size() == 0); } else return false; } - if (dynamic_cast(trueStmts)) + if (llvm::dyn_cast(trueStmts)) return true; - else if (StmtList *sl = dynamic_cast(trueStmts)) + else if (StmtList *sl = llvm::dyn_cast(trueStmts)) return (sl->stmts.size() == 1 && - dynamic_cast(sl->stmts[0]) != NULL); + llvm::dyn_cast(sl->stmts[0]) != NULL); else return false; } @@ -949,7 +949,7 @@ struct VaryingBCCheckInfo { static bool lIsVaryingFor(ASTNode *node) { IfStmt *ifStmt; - if ((ifStmt = dynamic_cast(node)) != NULL && + if ((ifStmt = llvm::dyn_cast(node)) != NULL && ifStmt->test != NULL) { const Type *type = ifStmt->test->GetType(); return (type != NULL && type->IsVaryingType()); @@ -967,8 +967,8 @@ lVaryingBCPreFunc(ASTNode *node, void *d) { // We found a break or continue statement; if we're under varying // control flow, then bingo. - if ((dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL) && + if ((llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL) && info->varyingControlFlowDepth > 0) { info->foundVaryingBreakOrContinue = true; return false; @@ -979,9 +979,9 @@ lVaryingBCPreFunc(ASTNode *node, void *d) { if (lIsVaryingFor(node)) ++info->varyingControlFlowDepth; - if (dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL || - dynamic_cast(node) != NULL) + if (llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL || + llvm::dyn_cast(node) != NULL) // Don't recurse into these guys, since we don't care about varying // breaks or continues within them... return false; @@ -1017,7 +1017,7 @@ lHasVaryingBreakOrContinue(Stmt *stmt) { DoStmt::DoStmt(Expr *t, Stmt *s, bool cc, SourcePos p) - : Stmt(p), testExpr(t), bodyStmts(s), + : Stmt(p, DoStmtID), testExpr(t), bodyStmts(s), doCoherentCheck(cc && !g->opt.disableCoherentControlFlow) { } @@ -1052,7 +1052,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const { // scope around the statements in the list. So if the body is just a // single statement (and thus not a statement list), we need a new // scope, but we don't want two scopes in the StmtList case. - if (!dynamic_cast(bodyStmts)) + if (!llvm::dyn_cast(bodyStmts)) ctx->StartScope(); ctx->AddInstrumentationPoint("do loop body"); @@ -1094,7 +1094,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->BranchInst(btest); } // End the scope we started above, if needed. - if (!dynamic_cast(bodyStmts)) + if (!llvm::dyn_cast(bodyStmts)) ctx->EndScope(); // Now emit code for the loop test. @@ -1193,7 +1193,7 @@ DoStmt::Print(int indent) const { // ForStmt ForStmt::ForStmt(Stmt *i, Expr *t, Stmt *s, Stmt *st, bool cc, SourcePos p) - : Stmt(p), init(i), test(t), step(s), stmts(st), + : Stmt(p, ForStmtID), init(i), test(t), step(s), stmts(st), doCoherentCheck(cc && !g->opt.disableCoherentControlFlow) { } @@ -1219,7 +1219,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const { // it and then jump into the loop test code. (Also start a new scope // since the initiailizer may be a declaration statement). if (init) { - AssertPos(pos, dynamic_cast(init) == NULL); + AssertPos(pos, llvm::dyn_cast(init) == NULL); ctx->StartScope(); init->EmitCode(ctx); } @@ -1261,7 +1261,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const { ctx->SetCurrentBasicBlock(bloop); ctx->SetBlockEntryMask(ctx->GetFullMask()); ctx->AddInstrumentationPoint("for loop body"); - if (!dynamic_cast(stmts)) + if (!llvm::dyn_cast(stmts)) ctx->StartScope(); if (doCoherentCheck && !uniformTest) { @@ -1306,7 +1306,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const { if (ctx->GetCurrentBasicBlock()) ctx->BranchInst(bstep); } - if (!dynamic_cast(stmts)) + if (!llvm::dyn_cast(stmts)) ctx->EndScope(); // Emit code for the loop step. First, restore the lane mask of any @@ -1387,7 +1387,7 @@ ForStmt::Print(int indent) const { // BreakStmt BreakStmt::BreakStmt(SourcePos p) - : Stmt(p) { + : Stmt(p, BreakStmtID) { } @@ -1425,7 +1425,7 @@ BreakStmt::Print(int indent) const { // ContinueStmt ContinueStmt::ContinueStmt(SourcePos p) - : Stmt(p) { + : Stmt(p, ContinueStmtID) { } @@ -1466,7 +1466,7 @@ ForeachStmt::ForeachStmt(const std::vector &lvs, const std::vector &se, const std::vector &ee, Stmt *s, bool t, SourcePos pos) - : Stmt(pos), dimVariables(lvs), startExprs(se), endExprs(ee), isTiled(t), + : Stmt(pos, ForeachStmtID), dimVariables(lvs), startExprs(se), endExprs(ee), isTiled(t), stmts(s) { } @@ -2223,7 +2223,7 @@ ForeachStmt::Print(int indent) const { // ForeachActiveStmt ForeachActiveStmt::ForeachActiveStmt(Symbol *s, Stmt *st, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, ForeachActiveStmtID) { sym = s; stmts = st; } @@ -2410,7 +2410,7 @@ ForeachActiveStmt::EstimateCost() const { ForeachUniqueStmt::ForeachUniqueStmt(const char *iterName, Expr *e, Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, ForeachUniqueStmtID) { sym = m->symbolTable->LookupVariable(iterName); expr = e; stmts = s; @@ -2678,7 +2678,7 @@ lCheckMask(Stmt *stmts) { CaseStmt::CaseStmt(int v, Stmt *s, SourcePos pos) - : Stmt(pos), value(v) { + : Stmt(pos, CaseStmtID), value(v) { stmts = s; } @@ -2716,7 +2716,7 @@ CaseStmt::EstimateCost() const { // DefaultStmt DefaultStmt::DefaultStmt(Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, DefaultStmtID) { stmts = s; } @@ -2754,7 +2754,7 @@ DefaultStmt::EstimateCost() const { // SwitchStmt SwitchStmt::SwitchStmt(Expr *e, Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, SwitchStmtID) { expr = e; stmts = s; } @@ -2794,13 +2794,13 @@ struct SwitchVisitInfo { static bool lSwitchASTPreVisit(ASTNode *node, void *d) { - if (dynamic_cast(node) != NULL) + if (llvm::dyn_cast(node) != NULL) // don't continue recursively into a nested switch--we only want // our own case and default statements! return false; - CaseStmt *cs = dynamic_cast(node); - DefaultStmt *ds = dynamic_cast(node); + CaseStmt *cs = llvm::dyn_cast(node); + DefaultStmt *ds = llvm::dyn_cast(node); SwitchVisitInfo *svi = (SwitchVisitInfo *)d; llvm::BasicBlock *bb = NULL; @@ -2954,7 +2954,7 @@ SwitchStmt::EstimateCost() const { // UnmaskedStmt UnmaskedStmt::UnmaskedStmt(Stmt *s, SourcePos pos) - : Stmt(pos) { + : Stmt(pos, UnmaskedStmtID) { stmts = s; } @@ -3008,7 +3008,7 @@ UnmaskedStmt::EstimateCost() const { // ReturnStmt ReturnStmt::ReturnStmt(Expr *e, SourcePos p) - : Stmt(p), expr(e) { + : Stmt(p, ReturnStmtID), expr(e) { } @@ -3075,7 +3075,7 @@ ReturnStmt::Print(int indent) const { // GotoStmt GotoStmt::GotoStmt(const char *l, SourcePos gotoPos, SourcePos ip) - : Stmt(gotoPos) { + : Stmt(gotoPos, GotoStmtID) { label = l; identifierPos = ip; } @@ -3151,7 +3151,7 @@ GotoStmt::EstimateCost() const { // LabeledStmt LabeledStmt::LabeledStmt(const char *n, Stmt *s, SourcePos p) - : Stmt(p) { + : Stmt(p, LabeledStmtID) { name = n; stmt = s; } @@ -3253,7 +3253,7 @@ StmtList::Print(int indent) const { // PrintStmt PrintStmt::PrintStmt(const std::string &f, Expr *v, SourcePos p) - : Stmt(p), format(f), values(v) { + : Stmt(p, PrintStmtID), format(f), values(v) { } /* Because the pointers to values that are passed to __do_print() are all @@ -3383,7 +3383,7 @@ PrintStmt::EmitCode(FunctionEmitContext *ctx) const { // Get the values passed to the print() statement evaluated and // stored in memory so that we set up the array of pointers to them // for the 5th __do_print() argument - ExprList *elist = dynamic_cast(values); + ExprList *elist = llvm::dyn_cast(values); int nArgs = elist ? elist->exprs.size() : 1; // Allocate space for the array of pointers to values to be printed @@ -3463,7 +3463,7 @@ PrintStmt::EstimateCost() const { // AssertStmt AssertStmt::AssertStmt(const std::string &msg, Expr *e, SourcePos p) - : Stmt(p), message(msg), expr(e) { + : Stmt(p, AssertStmtID), message(msg), expr(e) { } @@ -3542,7 +3542,7 @@ AssertStmt::EstimateCost() const { // DeleteStmt DeleteStmt::DeleteStmt(Expr *e, SourcePos p) - : Stmt(p) { + : Stmt(p, DeleteStmtID) { expr = e; } diff --git a/stmt.h b/stmt.h index fb34c801..ab0f666b 100644 --- a/stmt.h +++ b/stmt.h @@ -48,7 +48,12 @@ */ class Stmt : public ASTNode { public: - Stmt(SourcePos p) : ASTNode(p) { } + Stmt(SourcePos p, unsigned scid) : ASTNode(p, scid) { } + + static inline bool classof(Stmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() > MaxExprID; + } /** Emit LLVM IR for the statement, using the FunctionEmitContext to create the necessary instructions. @@ -73,6 +78,11 @@ class ExprStmt : public Stmt { public: ExprStmt(Expr *expr, SourcePos pos); + static inline bool classof(ExprStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ExprStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -97,6 +107,11 @@ class DeclStmt : public Stmt { public: DeclStmt(const std::vector &v, SourcePos pos); + static inline bool classof(DeclStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == DeclStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -115,6 +130,11 @@ public: IfStmt(Expr *testExpr, Stmt *trueStmts, Stmt *falseStmts, bool doAllCheck, SourcePos pos); + static inline bool classof(IfStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == IfStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -155,6 +175,11 @@ public: DoStmt(Expr *testExpr, Stmt *bodyStmts, bool doCoherentCheck, SourcePos pos); + static inline bool classof(DoStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == DoStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -175,6 +200,11 @@ public: ForStmt(Stmt *initializer, Expr *testExpr, Stmt *stepStatements, Stmt *bodyStatements, bool doCoherentCheck, SourcePos pos); + static inline bool classof(ForStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ForStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -201,6 +231,11 @@ class BreakStmt : public Stmt { public: BreakStmt(SourcePos pos); + static inline bool classof(BreakStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == BreakStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -215,6 +250,11 @@ class ContinueStmt : public Stmt { public: ContinueStmt(SourcePos pos); + static inline bool classof(ContinueStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ContinueStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -232,6 +272,11 @@ public: const std::vector &endExprs, Stmt *bodyStatements, bool tiled, SourcePos pos); + static inline bool classof(ForeachStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ForeachStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -252,6 +297,11 @@ class ForeachActiveStmt : public Stmt { public: ForeachActiveStmt(Symbol *iterSym, Stmt *stmts, SourcePos pos); + static inline bool classof(ForeachActiveStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ForeachActiveStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -271,6 +321,11 @@ public: ForeachUniqueStmt(const char *iterName, Expr *expr, Stmt *stmts, SourcePos pos); + static inline bool classof(ForeachUniqueStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ForeachUniqueStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -289,6 +344,11 @@ class UnmaskedStmt : public Stmt { public: UnmaskedStmt(Stmt *stmt, SourcePos pos); + static inline bool classof(UnmaskedStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == UnmaskedStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -306,6 +366,11 @@ class ReturnStmt : public Stmt { public: ReturnStmt(Expr *e, SourcePos p); + static inline bool classof(ReturnStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == ReturnStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -323,6 +388,11 @@ class CaseStmt : public Stmt { public: CaseStmt(int value, Stmt *stmt, SourcePos pos); + static inline bool classof(CaseStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == CaseStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -341,6 +411,11 @@ class DefaultStmt : public Stmt { public: DefaultStmt(Stmt *stmt, SourcePos pos); + static inline bool classof(DefaultStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == DefaultStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -356,6 +431,11 @@ class SwitchStmt : public Stmt { public: SwitchStmt(Expr *expr, Stmt *stmts, SourcePos pos); + static inline bool classof(SwitchStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == SwitchStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -374,6 +454,11 @@ class GotoStmt : public Stmt { public: GotoStmt(const char *label, SourcePos gotoPos, SourcePos idPos); + static inline bool classof(GotoStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == GotoStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -393,6 +478,11 @@ class LabeledStmt : public Stmt { public: LabeledStmt(const char *label, Stmt *stmt, SourcePos p); + static inline bool classof(LabeledStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == LabeledStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -411,7 +501,12 @@ public: */ class StmtList : public Stmt { public: - StmtList(SourcePos p) : Stmt(p) { } + StmtList(SourcePos p) : Stmt(p, StmtListID) { } + + static inline bool classof(StmtList const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == StmtListID; + } void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -438,6 +533,11 @@ class PrintStmt : public Stmt { public: PrintStmt(const std::string &f, Expr *v, SourcePos p); + static inline bool classof(PrintStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == PrintStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -464,6 +564,11 @@ class AssertStmt : public Stmt { public: AssertStmt(const std::string &msg, Expr *e, SourcePos p); + static inline bool classof(AssertStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == AssertStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; @@ -483,6 +588,11 @@ class DeleteStmt : public Stmt { public: DeleteStmt(Expr *e, SourcePos p); + static inline bool classof(DeleteStmt const*) { return true; } + static inline bool classof(ASTNode const* N) { + return N->getValueID() == DeleteStmtID; + } + void EmitCode(FunctionEmitContext *ctx) const; void Print(int indent) const; diff --git a/type.cpp b/type.cpp index 9785d532..b4b739a7 100644 --- a/type.cpp +++ b/type.cpp @@ -1603,7 +1603,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) { if (at == NULL) return type; - ExprList *exprList = dynamic_cast(initExpr); + ExprList *exprList = llvm::dyn_cast_or_null(initExpr); if (exprList == NULL || exprList->exprs.size() == 0) return type; @@ -1618,7 +1618,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) { // now. Otherwise we'll use the first one to size the next dimension // (after checking below that it has the same length as all of the // other ones. - ExprList *nextList = dynamic_cast(exprList->exprs[0]); + ExprList *nextList = llvm::dyn_cast_or_null(exprList->exprs[0]); if (nextList == NULL) return type; @@ -1638,7 +1638,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) { continue; } - ExprList *el = dynamic_cast(exprList->exprs[i]); + ExprList *el = llvm::dyn_cast_or_null(exprList->exprs[i]); if (el == NULL || el->exprs.size() != nextSize) { Error(Union(exprList->exprs[0]->pos, exprList->exprs[i]->pos), "Inconsistent initializer expression list lengths "