diff --git a/Makefile b/Makefile index b551a49a..5698fd42 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 @@ -194,7 +194,7 @@ YACC=bison -d -v -t ########################################################################### -CXX_SRC=ast.cpp builtins.cpp cbackend.cpp ctx.cpp decl.cpp expr.cpp func.cpp \ +CXX_SRC=ast.cpp builtins.cpp cbackend.cpp ctx.cpp decl.cpp expr.cpp func.cpp test_class_of.cpp \ ispc.cpp llvmutil.cpp main.cpp module.cpp opt.cpp stmt.cpp sym.cpp \ type.cpp util.cpp HEADERS=ast.h builtins.h ctx.h decl.h expr.h func.h ispc.h llvmutil.h module.h \ @@ -262,6 +262,8 @@ doxygen: ispc: print_llvm_src dirs $(OBJS) @echo Creating ispc executable @$(CXX) $(OPT) $(LDFLAGS) -o $@ $(OBJS) $(ISPC_LIBS) + @echo Creating test_class_of executable + @$(CXX) $(OPT) $(LDFLAGS) -o tcexe $(OBJS) $(ISPC_LIBS) # Use clang as a default compiler, instead of gcc # This is default now. 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..e4a5d73f 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,24 @@ 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 { + ExprID, + StmtID + }; + + /** 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..24e86a69 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,7 +1108,7 @@ 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; } @@ -1184,7 +1184,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 +1359,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 +1666,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 +1990,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 +2002,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 +2330,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 +2357,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 +2823,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 +2945,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 +3170,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 +3404,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 +3431,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 +3555,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 +3728,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 +3740,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 +3785,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 +4012,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 +4121,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 +4294,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 +4404,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; @@ -4737,7 +4737,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) { } @@ -4908,7 +4908,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 +5166,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 +5340,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 +5349,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 +5360,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 +5369,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 +5380,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 +5389,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 +5400,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 +5409,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 +5420,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 +5429,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 +5440,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 +5451,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 +5463,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 +5472,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 +5483,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 +5492,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 +5503,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 +5512,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 +5523,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 +5532,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 +5543,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 +5552,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 +5563,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 +5617,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 +6223,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 +7229,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 +7315,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 +7392,7 @@ TypeCastExpr::GetConstant(const Type *constType) const { // ReferenceExpr ReferenceExpr::ReferenceExpr(Expr *e, SourcePos p) - : Expr(p) { + : Expr(p, ReferenceExprID) { expr = e; } @@ -7500,8 +7500,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 +7563,7 @@ DerefExpr::Optimize() { // PtrDerefExpr PtrDerefExpr::PtrDerefExpr(Expr *e, SourcePos p) - : DerefExpr(e, p) { + : DerefExpr(e, p, PtrDerefExprID) { } @@ -7641,7 +7641,7 @@ PtrDerefExpr::Print() const { // RefDerefExpr RefDerefExpr::RefDerefExpr(Expr *e, SourcePos p) - : DerefExpr(e, p) { + : DerefExpr(e, p, RefDerefExprID) { } @@ -7700,7 +7700,7 @@ RefDerefExpr::Print() const { // AddressOfExpr AddressOfExpr::AddressOfExpr(Expr *e, SourcePos p) - : Expr(p), expr(e) { + : Expr(p, AddressOfExprID), expr(e) { } @@ -7832,12 +7832,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 +7914,7 @@ SizeOfExpr::EstimateCost() const { // SymbolExpr SymbolExpr::SymbolExpr(Symbol *s, SourcePos p) - : Expr(p) { + : Expr(p, SymbolExprID) { symbol = s; } @@ -8008,7 +8008,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 +8555,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..89b987f5 100644 --- a/expr.h +++ b/expr.h @@ -47,7 +47,7 @@ */ class Expr : public ASTNode { public: - Expr(SourcePos p) : ASTNode(p) { } + Expr(SourcePos p, unsigned scid) : ASTNode(p, scid) { } /** This is the main method for Expr implementations to implement. It should call methods in the FunctionEmitContext to emit LLVM IR @@ -322,7 +322,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 '->' @@ -498,7 +498,7 @@ public: PtrDerefExpr and RefDerefExpr. */ class DerefExpr : public Expr { public: - DerefExpr(Expr *e, SourcePos p); + DerefExpr(Expr *e, SourcePos p, unsigned scid = DerefExprID); llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const; 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 84a0d140..d54ff6c8 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\" " @@ -1906,7 +1906,7 @@ std::string emitOffloadParamStruct(const std::string ¶mStructName, Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); } const ReferenceType *refType - = dynamic_cast(orgParamType); + = llvm::dyn_cast(orgParamType); paramType = refType->GetReferenceTarget()->GetAsNonConstType(); } else { paramType = orgParamType->GetAsNonConstType(); @@ -2025,7 +2025,7 @@ Module::writeDevStub(const char *fn) Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); } const ReferenceType *refType - = dynamic_cast(orgParamType); + = llvm::dyn_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..224646e4 100644 --- a/stmt.cpp +++ b/stmt.cpp @@ -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) @@ -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; @@ -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. @@ -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 @@ -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; @@ -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 diff --git a/test_class_of.cpp b/test_class_of.cpp new file mode 100644 index 00000000..58812229 --- /dev/null +++ b/test_class_of.cpp @@ -0,0 +1,8 @@ +#include "ispc.h" + +int main() { + + + + return 0; +}; diff --git a/type.cpp b/type.cpp index 9785d532..e70dd312 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(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(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(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 "