Id's fo Expr-inherited classes

This commit is contained in:
Anton Mitrokhin
2015-07-09 12:38:58 +03:00
parent 3ec674a820
commit 26a93bc733
13 changed files with 205 additions and 182 deletions

View File

@@ -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)) # 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)) 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 endif
ifneq ($(ARM_ENABLED), 0) ifneq ($(ARM_ENABLED), 0)
CXXFLAGS+=-DISPC_ARM_ENABLED 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 \ ispc.cpp llvmutil.cpp main.cpp module.cpp opt.cpp stmt.cpp sym.cpp \
type.cpp util.cpp type.cpp util.cpp
HEADERS=ast.h builtins.h ctx.h decl.h expr.h func.h ispc.h llvmutil.h module.h \ 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) ispc: print_llvm_src dirs $(OBJS)
@echo Creating ispc executable @echo Creating ispc executable
@$(CXX) $(OPT) $(LDFLAGS) -o $@ $(OBJS) $(ISPC_LIBS) @$(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 # Use clang as a default compiler, instead of gcc
# This is default now. # This is default now.

118
ast.cpp
View File

@@ -85,7 +85,7 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc,
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// Handle Statements // Handle Statements
if (dynamic_cast<Stmt *>(node) != NULL) { if (llvm::dyn_cast<Stmt>(node) != NULL) {
ExprStmt *es; ExprStmt *es;
DeclStmt *ds; DeclStmt *ds;
IfStmt *is; IfStmt *is;
@@ -105,33 +105,33 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc,
DeleteStmt *dels; DeleteStmt *dels;
UnmaskedStmt *ums; UnmaskedStmt *ums;
if ((es = dynamic_cast<ExprStmt *>(node)) != NULL) if ((es = llvm::dyn_cast<ExprStmt>(node)) != NULL)
es->expr = (Expr *)WalkAST(es->expr, preFunc, postFunc, data); es->expr = (Expr *)WalkAST(es->expr, preFunc, postFunc, data);
else if ((ds = dynamic_cast<DeclStmt *>(node)) != NULL) { else if ((ds = llvm::dyn_cast<DeclStmt>(node)) != NULL) {
for (unsigned int i = 0; i < ds->vars.size(); ++i) for (unsigned int i = 0; i < ds->vars.size(); ++i)
ds->vars[i].init = (Expr *)WalkAST(ds->vars[i].init, preFunc, ds->vars[i].init = (Expr *)WalkAST(ds->vars[i].init, preFunc,
postFunc, data); postFunc, data);
} }
else if ((is = dynamic_cast<IfStmt *>(node)) != NULL) { else if ((is = llvm::dyn_cast<IfStmt>(node)) != NULL) {
is->test = (Expr *)WalkAST(is->test, preFunc, postFunc, data); is->test = (Expr *)WalkAST(is->test, preFunc, postFunc, data);
is->trueStmts = (Stmt *)WalkAST(is->trueStmts, preFunc, is->trueStmts = (Stmt *)WalkAST(is->trueStmts, preFunc,
postFunc, data); postFunc, data);
is->falseStmts = (Stmt *)WalkAST(is->falseStmts, preFunc, is->falseStmts = (Stmt *)WalkAST(is->falseStmts, preFunc,
postFunc, data); postFunc, data);
} }
else if ((dos = dynamic_cast<DoStmt *>(node)) != NULL) { else if ((dos = llvm::dyn_cast<DoStmt>(node)) != NULL) {
dos->testExpr = (Expr *)WalkAST(dos->testExpr, preFunc, dos->testExpr = (Expr *)WalkAST(dos->testExpr, preFunc,
postFunc, data); postFunc, data);
dos->bodyStmts = (Stmt *)WalkAST(dos->bodyStmts, preFunc, dos->bodyStmts = (Stmt *)WalkAST(dos->bodyStmts, preFunc,
postFunc, data); postFunc, data);
} }
else if ((fs = dynamic_cast<ForStmt *>(node)) != NULL) { else if ((fs = llvm::dyn_cast<ForStmt>(node)) != NULL) {
fs->init = (Stmt *)WalkAST(fs->init, preFunc, postFunc, data); fs->init = (Stmt *)WalkAST(fs->init, preFunc, postFunc, data);
fs->test = (Expr *)WalkAST(fs->test, preFunc, postFunc, data); fs->test = (Expr *)WalkAST(fs->test, preFunc, postFunc, data);
fs->step = (Stmt *)WalkAST(fs->step, preFunc, postFunc, data); fs->step = (Stmt *)WalkAST(fs->step, preFunc, postFunc, data);
fs->stmts = (Stmt *)WalkAST(fs->stmts, preFunc, postFunc, data); fs->stmts = (Stmt *)WalkAST(fs->stmts, preFunc, postFunc, data);
} }
else if ((fes = dynamic_cast<ForeachStmt *>(node)) != NULL) { else if ((fes = llvm::dyn_cast<ForeachStmt>(node)) != NULL) {
for (unsigned int i = 0; i < fes->startExprs.size(); ++i) for (unsigned int i = 0; i < fes->startExprs.size(); ++i)
fes->startExprs[i] = (Expr *)WalkAST(fes->startExprs[i], preFunc, fes->startExprs[i] = (Expr *)WalkAST(fes->startExprs[i], preFunc,
postFunc, data); postFunc, data);
@@ -140,42 +140,42 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc,
postFunc, data); postFunc, data);
fes->stmts = (Stmt *)WalkAST(fes->stmts, preFunc, postFunc, data); fes->stmts = (Stmt *)WalkAST(fes->stmts, preFunc, postFunc, data);
} }
else if ((fas = dynamic_cast<ForeachActiveStmt *>(node)) != NULL) { else if ((fas = llvm::dyn_cast<ForeachActiveStmt>(node)) != NULL) {
fas->stmts = (Stmt *)WalkAST(fas->stmts, preFunc, postFunc, data); fas->stmts = (Stmt *)WalkAST(fas->stmts, preFunc, postFunc, data);
} }
else if ((fus = dynamic_cast<ForeachUniqueStmt *>(node)) != NULL) { else if ((fus = llvm::dyn_cast<ForeachUniqueStmt>(node)) != NULL) {
fus->expr = (Expr *)WalkAST(fus->expr, preFunc, postFunc, data); fus->expr = (Expr *)WalkAST(fus->expr, preFunc, postFunc, data);
fus->stmts = (Stmt *)WalkAST(fus->stmts, preFunc, postFunc, data); fus->stmts = (Stmt *)WalkAST(fus->stmts, preFunc, postFunc, data);
} }
else if ((cs = dynamic_cast<CaseStmt *>(node)) != NULL) else if ((cs = llvm::dyn_cast<CaseStmt>(node)) != NULL)
cs->stmts = (Stmt *)WalkAST(cs->stmts, preFunc, postFunc, data); cs->stmts = (Stmt *)WalkAST(cs->stmts, preFunc, postFunc, data);
else if ((defs = dynamic_cast<DefaultStmt *>(node)) != NULL) else if ((defs = llvm::dyn_cast<DefaultStmt>(node)) != NULL)
defs->stmts = (Stmt *)WalkAST(defs->stmts, preFunc, postFunc, data); defs->stmts = (Stmt *)WalkAST(defs->stmts, preFunc, postFunc, data);
else if ((ss = dynamic_cast<SwitchStmt *>(node)) != NULL) { else if ((ss = llvm::dyn_cast<SwitchStmt>(node)) != NULL) {
ss->expr = (Expr *)WalkAST(ss->expr, preFunc, postFunc, data); ss->expr = (Expr *)WalkAST(ss->expr, preFunc, postFunc, data);
ss->stmts = (Stmt *)WalkAST(ss->stmts, preFunc, postFunc, data); ss->stmts = (Stmt *)WalkAST(ss->stmts, preFunc, postFunc, data);
} }
else if (dynamic_cast<BreakStmt *>(node) != NULL || else if (llvm::dyn_cast<BreakStmt>(node) != NULL ||
dynamic_cast<ContinueStmt *>(node) != NULL || llvm::dyn_cast<ContinueStmt>(node) != NULL ||
dynamic_cast<GotoStmt *>(node) != NULL) { llvm::dyn_cast<GotoStmt>(node) != NULL) {
// nothing // nothing
} }
else if ((ls = dynamic_cast<LabeledStmt *>(node)) != NULL) else if ((ls = llvm::dyn_cast<LabeledStmt>(node)) != NULL)
ls->stmt = (Stmt *)WalkAST(ls->stmt, preFunc, postFunc, data); ls->stmt = (Stmt *)WalkAST(ls->stmt, preFunc, postFunc, data);
else if ((rs = dynamic_cast<ReturnStmt *>(node)) != NULL) else if ((rs = llvm::dyn_cast<ReturnStmt>(node)) != NULL)
rs->expr = (Expr *)WalkAST(rs->expr, preFunc, postFunc, data); rs->expr = (Expr *)WalkAST(rs->expr, preFunc, postFunc, data);
else if ((sl = dynamic_cast<StmtList *>(node)) != NULL) { else if ((sl = llvm::dyn_cast<StmtList>(node)) != NULL) {
std::vector<Stmt *> &sls = sl->stmts; std::vector<Stmt *> &sls = sl->stmts;
for (unsigned int i = 0; i < sls.size(); ++i) for (unsigned int i = 0; i < sls.size(); ++i)
sls[i] = (Stmt *)WalkAST(sls[i], preFunc, postFunc, data); sls[i] = (Stmt *)WalkAST(sls[i], preFunc, postFunc, data);
} }
else if ((ps = dynamic_cast<PrintStmt *>(node)) != NULL) else if ((ps = llvm::dyn_cast<PrintStmt>(node)) != NULL)
ps->values = (Expr *)WalkAST(ps->values, preFunc, postFunc, data); ps->values = (Expr *)WalkAST(ps->values, preFunc, postFunc, data);
else if ((as = dynamic_cast<AssertStmt *>(node)) != NULL) else if ((as = llvm::dyn_cast<AssertStmt>(node)) != NULL)
as->expr = (Expr *)WalkAST(as->expr, preFunc, postFunc, data); as->expr = (Expr *)WalkAST(as->expr, preFunc, postFunc, data);
else if ((dels = dynamic_cast<DeleteStmt *>(node)) != NULL) else if ((dels = llvm::dyn_cast<DeleteStmt>(node)) != NULL)
dels->expr = (Expr *)WalkAST(dels->expr, preFunc, postFunc, data); dels->expr = (Expr *)WalkAST(dels->expr, preFunc, postFunc, data);
else if ((ums = dynamic_cast<UnmaskedStmt *>(node)) != NULL) else if ((ums = llvm::dyn_cast<UnmaskedStmt>(node)) != NULL)
ums->stmts = (Stmt *)WalkAST(ums->stmts, preFunc, postFunc, data); ums->stmts = (Stmt *)WalkAST(ums->stmts, preFunc, postFunc, data);
else else
FATAL("Unhandled statement type in WalkAST()"); FATAL("Unhandled statement type in WalkAST()");
@@ -183,7 +183,7 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc,
else { else {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Handle expressions // Handle expressions
Assert(dynamic_cast<Expr *>(node) != NULL); Assert(llvm::dyn_cast<Expr>(node) != NULL);
UnaryExpr *ue; UnaryExpr *ue;
BinaryExpr *be; BinaryExpr *be;
AssignExpr *ae; AssignExpr *ae;
@@ -200,64 +200,64 @@ WalkAST(ASTNode *node, ASTPreCallBackFunc preFunc, ASTPostCallBackFunc postFunc,
AddressOfExpr *aoe; AddressOfExpr *aoe;
NewExpr *newe; NewExpr *newe;
if ((ue = dynamic_cast<UnaryExpr *>(node)) != NULL) if ((ue = llvm::dyn_cast<UnaryExpr>(node)) != NULL)
ue->expr = (Expr *)WalkAST(ue->expr, preFunc, postFunc, data); ue->expr = (Expr *)WalkAST(ue->expr, preFunc, postFunc, data);
else if ((be = dynamic_cast<BinaryExpr *>(node)) != NULL) { else if ((be = llvm::dyn_cast<BinaryExpr>(node)) != NULL) {
be->arg0 = (Expr *)WalkAST(be->arg0, preFunc, postFunc, data); be->arg0 = (Expr *)WalkAST(be->arg0, preFunc, postFunc, data);
be->arg1 = (Expr *)WalkAST(be->arg1, preFunc, postFunc, data); be->arg1 = (Expr *)WalkAST(be->arg1, preFunc, postFunc, data);
} }
else if ((ae = dynamic_cast<AssignExpr *>(node)) != NULL) { else if ((ae = llvm::dyn_cast<AssignExpr>(node)) != NULL) {
ae->lvalue = (Expr *)WalkAST(ae->lvalue, preFunc, postFunc, data); ae->lvalue = (Expr *)WalkAST(ae->lvalue, preFunc, postFunc, data);
ae->rvalue = (Expr *)WalkAST(ae->rvalue, preFunc, postFunc, data); ae->rvalue = (Expr *)WalkAST(ae->rvalue, preFunc, postFunc, data);
} }
else if ((se = dynamic_cast<SelectExpr *>(node)) != NULL) { else if ((se = llvm::dyn_cast<SelectExpr>(node)) != NULL) {
se->test = (Expr *)WalkAST(se->test, preFunc, postFunc, data); se->test = (Expr *)WalkAST(se->test, preFunc, postFunc, data);
se->expr1 = (Expr *)WalkAST(se->expr1, preFunc, postFunc, data); se->expr1 = (Expr *)WalkAST(se->expr1, preFunc, postFunc, data);
se->expr2 = (Expr *)WalkAST(se->expr2, preFunc, postFunc, data); se->expr2 = (Expr *)WalkAST(se->expr2, preFunc, postFunc, data);
} }
else if ((el = dynamic_cast<ExprList *>(node)) != NULL) { else if ((el = llvm::dyn_cast<ExprList>(node)) != NULL) {
for (unsigned int i = 0; i < el->exprs.size(); ++i) for (unsigned int i = 0; i < el->exprs.size(); ++i)
el->exprs[i] = (Expr *)WalkAST(el->exprs[i], preFunc, el->exprs[i] = (Expr *)WalkAST(el->exprs[i], preFunc,
postFunc, data); postFunc, data);
} }
else if ((fce = dynamic_cast<FunctionCallExpr *>(node)) != NULL) { else if ((fce = llvm::dyn_cast<FunctionCallExpr>(node)) != NULL) {
fce->func = (Expr *)WalkAST(fce->func, preFunc, postFunc, data); fce->func = (Expr *)WalkAST(fce->func, preFunc, postFunc, data);
fce->args = (ExprList *)WalkAST(fce->args, preFunc, postFunc, data); fce->args = (ExprList *)WalkAST(fce->args, preFunc, postFunc, data);
for (int k = 0; k < 3; k++) for (int k = 0; k < 3; k++)
fce->launchCountExpr[0] = (Expr *)WalkAST(fce->launchCountExpr[0], preFunc, fce->launchCountExpr[0] = (Expr *)WalkAST(fce->launchCountExpr[0], preFunc,
postFunc, data); postFunc, data);
} }
else if ((ie = dynamic_cast<IndexExpr *>(node)) != NULL) { else if ((ie = llvm::dyn_cast<IndexExpr>(node)) != NULL) {
ie->baseExpr = (Expr *)WalkAST(ie->baseExpr, preFunc, postFunc, data); ie->baseExpr = (Expr *)WalkAST(ie->baseExpr, preFunc, postFunc, data);
ie->index = (Expr *)WalkAST(ie->index, preFunc, postFunc, data); ie->index = (Expr *)WalkAST(ie->index, preFunc, postFunc, data);
} }
else if ((me = dynamic_cast<MemberExpr *>(node)) != NULL) else if ((me = llvm::dyn_cast<MemberExpr>(node)) != NULL)
me->expr = (Expr *)WalkAST(me->expr, preFunc, postFunc, data); me->expr = (Expr *)WalkAST(me->expr, preFunc, postFunc, data);
else if ((tce = dynamic_cast<TypeCastExpr *>(node)) != NULL) else if ((tce = llvm::dyn_cast<TypeCastExpr>(node)) != NULL)
tce->expr = (Expr *)WalkAST(tce->expr, preFunc, postFunc, data); tce->expr = (Expr *)WalkAST(tce->expr, preFunc, postFunc, data);
else if ((re = dynamic_cast<ReferenceExpr *>(node)) != NULL) else if ((re = llvm::dyn_cast<ReferenceExpr>(node)) != NULL)
re->expr = (Expr *)WalkAST(re->expr, preFunc, postFunc, data); re->expr = (Expr *)WalkAST(re->expr, preFunc, postFunc, data);
else if ((ptrderef = dynamic_cast<PtrDerefExpr *>(node)) != NULL) else if ((ptrderef = llvm::dyn_cast<PtrDerefExpr>(node)) != NULL)
ptrderef->expr = (Expr *)WalkAST(ptrderef->expr, preFunc, postFunc, ptrderef->expr = (Expr *)WalkAST(ptrderef->expr, preFunc, postFunc,
data); data);
else if ((refderef = dynamic_cast<RefDerefExpr *>(node)) != NULL) else if ((refderef = llvm::dyn_cast<RefDerefExpr>(node)) != NULL)
refderef->expr = (Expr *)WalkAST(refderef->expr, preFunc, postFunc, refderef->expr = (Expr *)WalkAST(refderef->expr, preFunc, postFunc,
data); data);
else if ((soe = dynamic_cast<SizeOfExpr *>(node)) != NULL) else if ((soe = llvm::dyn_cast<SizeOfExpr>(node)) != NULL)
soe->expr = (Expr *)WalkAST(soe->expr, preFunc, postFunc, data); soe->expr = (Expr *)WalkAST(soe->expr, preFunc, postFunc, data);
else if ((aoe = dynamic_cast<AddressOfExpr *>(node)) != NULL) else if ((aoe = llvm::dyn_cast<AddressOfExpr>(node)) != NULL)
aoe->expr = (Expr *)WalkAST(aoe->expr, preFunc, postFunc, data); aoe->expr = (Expr *)WalkAST(aoe->expr, preFunc, postFunc, data);
else if ((newe = dynamic_cast<NewExpr *>(node)) != NULL) { else if ((newe = llvm::dyn_cast<NewExpr>(node)) != NULL) {
newe->countExpr = (Expr *)WalkAST(newe->countExpr, preFunc, newe->countExpr = (Expr *)WalkAST(newe->countExpr, preFunc,
postFunc, data); postFunc, data);
newe->initExpr = (Expr *)WalkAST(newe->initExpr, preFunc, newe->initExpr = (Expr *)WalkAST(newe->initExpr, preFunc,
postFunc, data); postFunc, data);
} }
else if (dynamic_cast<SymbolExpr *>(node) != NULL || else if (llvm::dyn_cast<SymbolExpr>(node) != NULL ||
dynamic_cast<ConstExpr *>(node) != NULL || llvm::dyn_cast<ConstExpr>(node) != NULL ||
dynamic_cast<FunctionSymbolExpr *>(node) != NULL || llvm::dyn_cast<FunctionSymbolExpr>(node) != NULL ||
dynamic_cast<SyncExpr *>(node) != NULL || llvm::dyn_cast<SyncExpr>(node) != NULL ||
dynamic_cast<NullPointerExpr *>(node) != NULL) { llvm::dyn_cast<NullPointerExpr>(node) != NULL) {
// nothing to do // nothing to do
} }
else else
@@ -331,7 +331,7 @@ struct CostData {
static bool static bool
lCostCallbackPre(ASTNode *node, void *d) { lCostCallbackPre(ASTNode *node, void *d) {
CostData *data = (CostData *)d; CostData *data = (CostData *)d;
if (dynamic_cast<ForeachStmt *>(node) != NULL) if (llvm::dyn_cast<ForeachStmt>(node) != NULL)
++data->foreachDepth; ++data->foreachDepth;
if (data->foreachDepth == 0) if (data->foreachDepth == 0)
data->cost += node->EstimateCost(); data->cost += node->EstimateCost();
@@ -342,7 +342,7 @@ lCostCallbackPre(ASTNode *node, void *d) {
static ASTNode * static ASTNode *
lCostCallbackPost(ASTNode *node, void *d) { lCostCallbackPost(ASTNode *node, void *d) {
CostData *data = (CostData *)d; CostData *data = (CostData *)d;
if (dynamic_cast<ForeachStmt *>(node) != NULL) if (llvm::dyn_cast<ForeachStmt>(node) != NULL)
--data->foreachDepth; --data->foreachDepth;
return node; return node;
} }
@@ -364,7 +364,7 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
bool *okPtr = (bool *)data; bool *okPtr = (bool *)data;
FunctionCallExpr *fce; FunctionCallExpr *fce;
if ((fce = dynamic_cast<FunctionCallExpr *>(node)) != NULL) { if ((fce = llvm::dyn_cast<FunctionCallExpr>(node)) != NULL) {
if (fce->func == NULL) if (fce->func == NULL)
return false; return false;
@@ -381,7 +381,7 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
} }
} }
if (dynamic_cast<AssertStmt *>(node) != NULL) { if (llvm::dyn_cast<AssertStmt>(node) != NULL) {
// While it's fine to run the assert for varying tests, it's not // 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 // desirable to check an assert on a uniform variable if all of the
// lanes are off. // lanes are off.
@@ -389,13 +389,13 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
return false; return false;
} }
if (dynamic_cast<PrintStmt *>(node) != NULL) { if (llvm::dyn_cast<PrintStmt>(node) != NULL) {
*okPtr = false; *okPtr = false;
return false; return false;
} }
if (dynamic_cast<NewExpr *>(node) != NULL || if (llvm::dyn_cast<NewExpr>(node) != NULL ||
dynamic_cast<DeleteStmt *>(node) != NULL) { llvm::dyn_cast<DeleteStmt>(node) != NULL) {
// We definitely don't want to run the uniform variants of these if // 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 // 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. // executing the varying versions of them in the all-off mask case.
@@ -403,10 +403,10 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
return false; return false;
} }
if (dynamic_cast<ForeachStmt *>(node) != NULL || if (llvm::dyn_cast<ForeachStmt>(node) != NULL ||
dynamic_cast<ForeachActiveStmt *>(node) != NULL || llvm::dyn_cast<ForeachActiveStmt>(node) != NULL ||
dynamic_cast<ForeachUniqueStmt *>(node) != NULL || llvm::dyn_cast<ForeachUniqueStmt>(node) != NULL ||
dynamic_cast<UnmaskedStmt *>(node) != NULL) { llvm::dyn_cast<UnmaskedStmt>(node) != NULL) {
// The various foreach statements also shouldn't be run with an // The various foreach statements also shouldn't be run with an
// all-off mask. Since they can re-establish an 'all on' mask, // all-off mask. Since they can re-establish an 'all on' mask,
// this would be pretty unintuitive. (More generally, it's // this would be pretty unintuitive. (More generally, it's
@@ -421,14 +421,14 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
} }
IndexExpr *ie; IndexExpr *ie;
if ((ie = dynamic_cast<IndexExpr *>(node)) != NULL && ie->baseExpr != NULL) { if ((ie = llvm::dyn_cast<IndexExpr>(node)) != NULL && ie->baseExpr != NULL) {
const Type *type = ie->baseExpr->GetType(); const Type *type = ie->baseExpr->GetType();
if (type == NULL) if (type == NULL)
return true; return true;
if (CastType<ReferenceType>(type) != NULL) if (CastType<ReferenceType>(type) != NULL)
type = type->GetReferenceTarget(); type = type->GetReferenceTarget();
ConstExpr *ce = dynamic_cast<ConstExpr *>(ie->index); ConstExpr *ce = llvm::dyn_cast<ConstExpr>(ie->index);
if (ce == NULL) { if (ce == NULL) {
// indexing with a variable... -> not safe // indexing with a variable... -> not safe
*okPtr = false; *okPtr = false;
@@ -466,13 +466,13 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
} }
MemberExpr *me; MemberExpr *me;
if ((me = dynamic_cast<MemberExpr *>(node)) != NULL && if ((me = llvm::dyn_cast<MemberExpr>(node)) != NULL &&
me->dereferenceExpr) { me->dereferenceExpr) {
*okPtr = false; *okPtr = false;
return false; return false;
} }
if (dynamic_cast<PtrDerefExpr *>(node) != NULL) { if (llvm::dyn_cast<PtrDerefExpr>(node) != NULL) {
*okPtr = false; *okPtr = false;
return false; return false;
} }
@@ -482,7 +482,7 @@ lCheckAllOffSafety(ASTNode *node, void *data) {
assign to a uniform. assign to a uniform.
*/ */
AssignExpr *ae; AssignExpr *ae;
if ((ae = dynamic_cast<AssignExpr *>(node)) != NULL) { if ((ae = llvm::dyn_cast<AssignExpr>(node)) != NULL) {
if (ae->GetType()) { if (ae->GetType()) {
if (ae->GetType()->IsUniformType()) { if (ae->GetType()->IsUniformType()) {
*okPtr = false; *okPtr = false;

23
ast.h
View File

@@ -48,8 +48,9 @@
(Expr) and statements (Stmt) inherit from this class. (Expr) and statements (Stmt) inherit from this class.
*/ */
class ASTNode { class ASTNode {
const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast)
public: public:
ASTNode(SourcePos p) : pos(p) { } ASTNode(SourcePos p, unsigned scid) : SubclassID(scid), pos(p) { }
virtual ~ASTNode(); virtual ~ASTNode();
/** The Optimize() method should perform any appropriate early-stage /** 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 /** All AST nodes must track the file position where they are
defined. */ defined. */
SourcePos pos; 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 { class AST {
public: public:
/** Add the AST for a function described by the given declaration /** Add the AST for a function described by the given declaration

View File

@@ -1241,7 +1241,7 @@ FunctionEmitContext::EnableGatherScatterWarnings() {
bool bool
FunctionEmitContext::initLabelBBlocks(ASTNode *node, void *data) { FunctionEmitContext::initLabelBBlocks(ASTNode *node, void *data) {
LabeledStmt *ls = dynamic_cast<LabeledStmt *>(node); LabeledStmt *ls = llvm::dyn_cast<LabeledStmt>(node);
if (ls == NULL) if (ls == NULL)
return true; return true;

View File

@@ -519,9 +519,9 @@ Declarator::InitFromType(const Type *baseType, DeclSpecs *ds) {
decl->initExpr = TypeCheck(decl->initExpr); decl->initExpr = TypeCheck(decl->initExpr);
decl->initExpr = Optimize(decl->initExpr); decl->initExpr = Optimize(decl->initExpr);
if (decl->initExpr != NULL) { if (decl->initExpr != NULL) {
init = dynamic_cast<ConstExpr *>(decl->initExpr); init = llvm::dyn_cast<ConstExpr>(decl->initExpr);
if (init == NULL) if (init == NULL)
init = dynamic_cast<NullPointerExpr *>(decl->initExpr); init = llvm::dyn_cast<NullPointerExpr>(decl->initExpr);
if (init == NULL) if (init == NULL)
Error(decl->initExpr->pos, "Default value for parameter " Error(decl->initExpr->pos, "Default value for parameter "
"\"%s\" must be a compile-time constant.", "\"%s\" must be a compile-time constant.",

148
expr.cpp
View File

@@ -178,7 +178,7 @@ lIsAllIntZeros(Expr *expr) {
if (type == NULL || type->IsIntType() == false) if (type == NULL || type->IsIntType() == false)
return false; return false;
ConstExpr *ce = dynamic_cast<ConstExpr *>(expr); ConstExpr *ce = llvm::dyn_cast<ConstExpr>(expr);
if (ce == NULL) if (ce == NULL)
return false; return false;
@@ -355,7 +355,7 @@ lDoTypeConv(const Type *fromType, const Type *toType, Expr **expr,
} }
else if (PointerType::IsVoidPointer(fromPointerType) && else if (PointerType::IsVoidPointer(fromPointerType) &&
expr != NULL && expr != NULL &&
dynamic_cast<NullPointerExpr *>(*expr) != NULL) { llvm::dyn_cast<NullPointerExpr>(*expr) != NULL) {
// and a NULL convert to any other pointer type // and a NULL convert to any other pointer type
goto typecast_ok; goto typecast_ok;
} }
@@ -617,7 +617,7 @@ PossiblyResolveFunctionOverloads(Expr *expr, const Type *type) {
const FunctionType *funcType = NULL; const FunctionType *funcType = NULL;
if (CastType<PointerType>(type) != NULL && if (CastType<PointerType>(type) != NULL &&
(funcType = CastType<FunctionType>(type->GetBaseType())) && (funcType = CastType<FunctionType>(type->GetBaseType())) &&
(fse = dynamic_cast<FunctionSymbolExpr *>(expr)) != NULL) { (fse = llvm::dyn_cast<FunctionSymbolExpr>(expr)) != NULL) {
// We're initializing a function pointer with a function symbol, // We're initializing a function pointer with a function symbol,
// which in turn may represent an overloaded function. So we need // which in turn may represent an overloaded function. So we need
// to try to resolve the overload based on the type of the symbol // 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 // 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 // ExprList, then we'll see if we can type convert it to the type of
// the variable. // the variable.
if (dynamic_cast<ExprList *>(initExpr) == NULL) { if (llvm::dyn_cast<ExprList>(initExpr) == NULL) {
if (PossiblyResolveFunctionOverloads(initExpr, symType) == false) if (PossiblyResolveFunctionOverloads(initExpr, symType) == false)
return; return;
initExpr = TypeConvertExpr(initExpr, symType, "initializer"); 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, // expressions if they have a single element (except for SOA types,
// which are handled below). // which are handled below).
if (symType->IsSOAType() == false && Type::IsBasicType(symType)) { if (symType->IsSOAType() == false && Type::IsBasicType(symType)) {
ExprList *elist = dynamic_cast<ExprList *>(initExpr); ExprList *elist = llvm::dyn_cast<ExprList>(initExpr);
if (elist != NULL) { if (elist != NULL) {
if (elist->exprs.size() == 1) if (elist->exprs.size() == 1)
InitSymbol(ptr, symType, elist->exprs[0], ctx, pos); 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 }), // an initializer list may be provided (float foo[3] = { 1,2,3 }),
// in which case the elements are initialized with the // in which case the elements are initialized with the
// corresponding values. // corresponding values.
ExprList *exprList = dynamic_cast<ExprList *>(initExpr); ExprList *exprList = llvm::dyn_cast<ExprList>(initExpr);
if (exprList != NULL) { if (exprList != NULL) {
// The { ... } case; make sure we have the no more expressions // The { ... } case; make sure we have the no more expressions
// in the ExprList as we have struct members // 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) UnaryExpr::UnaryExpr(Op o, Expr *e, SourcePos p)
: Expr(p), op(o) { : Expr(p, UnaryExprID), op(o) {
expr = e; expr = e;
} }
@@ -1184,7 +1184,7 @@ lOptimizeBitNot(ConstExpr *constExpr, const Type *type, SourcePos pos) {
Expr * Expr *
UnaryExpr::Optimize() { UnaryExpr::Optimize() {
ConstExpr *constExpr = dynamic_cast<ConstExpr *>(expr); ConstExpr *constExpr = llvm::dyn_cast<ConstExpr>(expr);
// If the operand isn't a constant, then we can't do any optimization // If the operand isn't a constant, then we can't do any optimization
// here... // here...
if (constExpr == NULL) if (constExpr == NULL)
@@ -1359,7 +1359,7 @@ UnaryExpr::TypeCheck() {
int int
UnaryExpr::EstimateCost() const { UnaryExpr::EstimateCost() const {
if (dynamic_cast<ConstExpr *>(expr) != NULL) if (llvm::dyn_cast<ConstExpr>(expr) != NULL)
return 0; return 0;
return COST_SIMPLE_ARITH_LOGIC_OP; 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) BinaryExpr::BinaryExpr(Op o, Expr *a, Expr *b, SourcePos p)
: Expr(p), op(o) { : Expr(p, BinaryExprID), op(o) {
arg0 = a; arg0 = a;
arg1 = b; arg1 = b;
} }
@@ -1990,7 +1990,7 @@ lIsDifficultShiftAmount(Expr *expr) {
if (expr->GetType()->IsVaryingType() == false) if (expr->GetType()->IsVaryingType() == false)
return false; return false;
ConstExpr *ce = dynamic_cast<ConstExpr *>(expr); ConstExpr *ce = llvm::dyn_cast<ConstExpr>(expr);
if (ce) { if (ce) {
// If the shift is by a constant amount, *and* it's the same amount // If the shift is by a constant amount, *and* it's the same amount
// in all vector lanes, we're in good shape. // in all vector lanes, we're in good shape.
@@ -2002,7 +2002,7 @@ lIsDifficultShiftAmount(Expr *expr) {
return false; return false;
} }
TypeCastExpr *tce = dynamic_cast<TypeCastExpr *>(expr); TypeCastExpr *tce = llvm::dyn_cast<TypeCastExpr>(expr);
if (tce && tce->expr) { if (tce && tce->expr) {
// Finally, if the shift amount is given by a uniform value that's // 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 // 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 divisor must be the same compile-time constant value for all of
// the vector lanes. // the vector lanes.
ConstExpr *ce = dynamic_cast<ConstExpr *>(arg1); ConstExpr *ce = llvm::dyn_cast<ConstExpr>(arg1);
if (!ce) if (!ce)
return false; return false;
int64_t div[ISPC_MAX_NVEC]; int64_t div[ISPC_MAX_NVEC];
@@ -2357,8 +2357,8 @@ BinaryExpr::Optimize() {
if (arg0 == NULL || arg1 == NULL) if (arg0 == NULL || arg1 == NULL)
return NULL; return NULL;
ConstExpr *constArg0 = dynamic_cast<ConstExpr *>(arg0); ConstExpr *constArg0 = llvm::dyn_cast<ConstExpr>(arg0);
ConstExpr *constArg1 = dynamic_cast<ConstExpr *>(arg1); ConstExpr *constArg1 = llvm::dyn_cast<ConstExpr>(arg1);
if (g->opt.fastMath) { if (g->opt.fastMath) {
// optimizations related to division by floats.. // optimizations related to division by floats..
@@ -2823,8 +2823,8 @@ BinaryExpr::GetLValueType() const {
int int
BinaryExpr::EstimateCost() const { BinaryExpr::EstimateCost() const {
if (dynamic_cast<ConstExpr *>(arg0) != NULL && if (llvm::dyn_cast<ConstExpr>(arg0) != NULL &&
dynamic_cast<ConstExpr *>(arg1) != NULL) llvm::dyn_cast<ConstExpr>(arg1) != NULL)
return 0; return 0;
return (op == Div || op == Mod) ? COST_COMPLEX_ARITH_OP : 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) AssignExpr::AssignExpr(AssignExpr::Op o, Expr *a, Expr *b, SourcePos p)
: Expr(p), op(o) { : Expr(p, AssignExprID), op(o) {
lvalue = a; lvalue = a;
rvalue = b; rvalue = b;
} }
@@ -3170,7 +3170,7 @@ AssignExpr::Print() const {
// SelectExpr // SelectExpr
SelectExpr::SelectExpr(Expr *t, Expr *e1, Expr *e2, SourcePos p) SelectExpr::SelectExpr(Expr *t, Expr *e1, Expr *e2, SourcePos p)
: Expr(p) { : Expr(p, SelectExprID) {
test = t; test = t;
expr1 = e1; expr1 = e1;
expr2 = e2; expr2 = e2;
@@ -3404,7 +3404,7 @@ SelectExpr::Optimize() {
if (test == NULL || expr1 == NULL || expr2 == NULL) if (test == NULL || expr1 == NULL || expr2 == NULL)
return NULL; return NULL;
ConstExpr *constTest = dynamic_cast<ConstExpr *>(test); ConstExpr *constTest = llvm::dyn_cast<ConstExpr>(test);
if (constTest == NULL) if (constTest == NULL)
return this; return this;
@@ -3431,8 +3431,8 @@ SelectExpr::Optimize() {
// Last chance: see if the two expressions are constants; if so, // Last chance: see if the two expressions are constants; if so,
// then we can do an element-wise selection based on the constant // then we can do an element-wise selection based on the constant
// condition.. // condition..
ConstExpr *constExpr1 = dynamic_cast<ConstExpr *>(expr1); ConstExpr *constExpr1 = llvm::dyn_cast<ConstExpr>(expr1);
ConstExpr *constExpr2 = dynamic_cast<ConstExpr *>(expr2); ConstExpr *constExpr2 = llvm::dyn_cast<ConstExpr>(expr2);
if (constExpr1 == NULL || constExpr2 == NULL) if (constExpr1 == NULL || constExpr2 == NULL)
return this; return this;
@@ -3555,7 +3555,7 @@ SelectExpr::Print() const {
FunctionCallExpr::FunctionCallExpr(Expr *f, ExprList *a, SourcePos p, FunctionCallExpr::FunctionCallExpr(Expr *f, ExprList *a, SourcePos p,
bool il, Expr *lce[3]) bool il, Expr *lce[3])
: Expr(p), isLaunch(il) { : Expr(p, FunctionCallExprID), isLaunch(il) {
func = f; func = f;
args = a; args = a;
if (lce != NULL) if (lce != NULL)
@@ -3728,8 +3728,8 @@ bool FullResolveOverloads(Expr * func, ExprList * args,
if (t == NULL) if (t == NULL)
return false; return false;
argTypes->push_back(t); argTypes->push_back(t);
argCouldBeNULL->push_back(lIsAllIntZeros(expr) || dynamic_cast<NullPointerExpr *>(expr)); argCouldBeNULL->push_back(lIsAllIntZeros(expr) || llvm::dyn_cast<NullPointerExpr>(expr));
argIsConstant->push_back(dynamic_cast<ConstExpr *>(expr) || dynamic_cast<NullPointerExpr *>(expr)); argIsConstant->push_back(llvm::dyn_cast<ConstExpr>(expr) || llvm::dyn_cast<NullPointerExpr>(expr));
} }
return true; return true;
} }
@@ -3740,7 +3740,7 @@ FunctionCallExpr::GetType() const {
std::vector<const Type *> argTypes; std::vector<const Type *> argTypes;
std::vector<bool> argCouldBeNULL, argIsConstant; std::vector<bool> argCouldBeNULL, argIsConstant;
if (FullResolveOverloads(func, args, &argTypes, &argCouldBeNULL, &argIsConstant) == true) { if (FullResolveOverloads(func, args, &argTypes, &argCouldBeNULL, &argIsConstant) == true) {
FunctionSymbolExpr *fse = dynamic_cast<FunctionSymbolExpr *>(func); FunctionSymbolExpr *fse = llvm::dyn_cast<FunctionSymbolExpr>(func);
if (fse != NULL) { if (fse != NULL) {
fse->ResolveOverloads(args->pos, argTypes, &argCouldBeNULL, &argIsConstant); fse->ResolveOverloads(args->pos, argTypes, &argCouldBeNULL, &argIsConstant);
} }
@@ -3785,7 +3785,7 @@ FunctionCallExpr::TypeCheck() {
return NULL; return NULL;
} }
FunctionSymbolExpr *fse = dynamic_cast<FunctionSymbolExpr *>(func); FunctionSymbolExpr *fse = llvm::dyn_cast<FunctionSymbolExpr>(func);
if (fse != NULL) { if (fse != NULL) {
// Regular function call // Regular function call
if (fse->ResolveOverloads(args->pos, argTypes, &argCouldBeNULL, if (fse->ResolveOverloads(args->pos, argTypes, &argCouldBeNULL,
@@ -4012,7 +4012,7 @@ ExprList::GetConstant(const Type *type) const {
const Type *elementType = collectionType->GetElementType(i); const Type *elementType = collectionType->GetElementType(i);
Expr *expr = exprs[i]; Expr *expr = exprs[i];
if (dynamic_cast<ExprList *>(expr) == NULL) { if (llvm::dyn_cast<ExprList>(expr) == NULL) {
// If there's a simple type conversion from the type of this // If there's a simple type conversion from the type of this
// expression to the type we need, then let the regular type // expression to the type we need, then let the regular type
// conversion machinery handle it. // conversion machinery handle it.
@@ -4121,7 +4121,7 @@ ExprList::Print() const {
// IndexExpr // IndexExpr
IndexExpr::IndexExpr(Expr *a, Expr *i, SourcePos p) IndexExpr::IndexExpr(Expr *a, Expr *i, SourcePos p)
: Expr(p) { : Expr(p, IndexExprID) {
baseExpr = a; baseExpr = a;
index = i; index = i;
type = lvalueType = NULL; type = lvalueType = NULL;
@@ -4294,8 +4294,8 @@ IndexExpr::GetValue(FunctionEmitContext *ctx) const {
} }
else { else {
Symbol *baseSym = GetBaseSymbol(); Symbol *baseSym = GetBaseSymbol();
if (dynamic_cast<FunctionCallExpr *>(baseExpr) == NULL && if (llvm::dyn_cast<FunctionCallExpr>(baseExpr) == NULL &&
dynamic_cast<BinaryExpr *>(baseExpr) == NULL) { llvm::dyn_cast<BinaryExpr>(baseExpr) == NULL) {
// Don't check if we're doing a function call or pointer arith // Don't check if we're doing a function call or pointer arith
AssertPos(pos, baseSym != NULL); AssertPos(pos, baseSym != NULL);
} }
@@ -4404,7 +4404,7 @@ lCheckIndicesVersusBounds(const Type *baseExprType, Expr *index) {
if (soaWidth > 0) if (soaWidth > 0)
nElements *= soaWidth; nElements *= soaWidth;
ConstExpr *ce = dynamic_cast<ConstExpr *>(index); ConstExpr *ce = llvm::dyn_cast<ConstExpr>(index);
if (ce == NULL) if (ce == NULL)
return; return;
@@ -4737,7 +4737,7 @@ private:
StructMemberExpr::StructMemberExpr(Expr *e, const char *id, SourcePos p, StructMemberExpr::StructMemberExpr(Expr *e, const char *id, SourcePos p,
SourcePos idpos, bool derefLValue) 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, VectorMemberExpr::VectorMemberExpr(Expr *e, const char *id, SourcePos p,
SourcePos idpos, bool derefLValue) SourcePos idpos, bool derefLValue)
: MemberExpr(e, id, p, idpos, derefLValue) { : MemberExpr(e, id, p, idpos, derefLValue, VectorMemberExprID) {
const Type *exprType = e->GetType(); const Type *exprType = e->GetType();
exprVectorType = CastType<VectorType>(exprType); exprVectorType = CastType<VectorType>(exprType);
if (exprVectorType == NULL) { 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, MemberExpr::MemberExpr(Expr *e, const char *id, SourcePos p, SourcePos idpos,
bool derefLValue) bool derefLValue, unsigned scid)
: Expr(p), identifierPos(idpos) { : Expr(p, scid), identifierPos(idpos) {
expr = e; expr = e;
identifier = id; identifier = id;
dereferenceExpr = derefLValue; dereferenceExpr = derefLValue;
@@ -5340,7 +5340,7 @@ MemberExpr::getCandidateNearMatches() const {
// ConstExpr // ConstExpr
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 = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt8->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) ConstExpr::ConstExpr(const Type *t, int8_t *i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt8->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) ConstExpr::ConstExpr(const Type *t, uint8_t u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt8->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) ConstExpr::ConstExpr(const Type *t, uint8_t *u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt8->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) ConstExpr::ConstExpr(const Type *t, int16_t i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt16->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) ConstExpr::ConstExpr(const Type *t, int16_t *i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt16->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) ConstExpr::ConstExpr(const Type *t, uint16_t u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt16->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) ConstExpr::ConstExpr(const Type *t, uint16_t *u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt16->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) ConstExpr::ConstExpr(const Type *t, int32_t i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt32->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) ConstExpr::ConstExpr(const Type *t, int32_t *i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt32->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) ConstExpr::ConstExpr(const Type *t, uint32_t u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt32->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) ConstExpr::ConstExpr(const Type *t, uint32_t *u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt32->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) ConstExpr::ConstExpr(const Type *t, float f, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformFloat->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) ConstExpr::ConstExpr(const Type *t, float *f, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformFloat->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) ConstExpr::ConstExpr(const Type *t, int64_t i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt64->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) ConstExpr::ConstExpr(const Type *t, int64_t *i, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformInt64->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) ConstExpr::ConstExpr(const Type *t, uint64_t u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt64->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) ConstExpr::ConstExpr(const Type *t, uint64_t *u, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformUInt64->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) ConstExpr::ConstExpr(const Type *t, double f, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformDouble->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) ConstExpr::ConstExpr(const Type *t, double *f, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformDouble->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) ConstExpr::ConstExpr(const Type *t, bool b, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformBool->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) ConstExpr::ConstExpr(const Type *t, bool *b, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = t; type = t;
type = type->GetAsConstType(); type = type->GetAsConstType();
AssertPos(pos, Type::Equal(type, AtomicType::UniformBool->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) ConstExpr::ConstExpr(ConstExpr *old, double *v)
: Expr(old->pos) { : Expr(old->pos, ConstExprID) {
type = old->type; type = old->type;
AtomicType::BasicType basicType = getBasicType(); AtomicType::BasicType basicType = getBasicType();
@@ -5617,7 +5617,7 @@ ConstExpr::ConstExpr(ConstExpr *old, double *v)
ConstExpr::ConstExpr(ConstExpr *old, SourcePos p) ConstExpr::ConstExpr(ConstExpr *old, SourcePos p)
: Expr(p) { : Expr(p, ConstExprID) {
type = old->type; type = old->type;
AtomicType::BasicType basicType = getBasicType(); AtomicType::BasicType basicType = getBasicType();
@@ -6223,7 +6223,7 @@ ConstExpr::Print() const {
// TypeCastExpr // TypeCastExpr
TypeCastExpr::TypeCastExpr(const Type *t, Expr *e, SourcePos p) TypeCastExpr::TypeCastExpr(const Type *t, Expr *e, SourcePos p)
: Expr(p) { : Expr(p, TypeCastExprID) {
type = t; type = t;
expr = e; expr = e;
} }
@@ -7229,7 +7229,7 @@ TypeCastExpr::TypeCheck() {
Expr * Expr *
TypeCastExpr::Optimize() { TypeCastExpr::Optimize() {
ConstExpr *constExpr = dynamic_cast<ConstExpr *>(expr); ConstExpr *constExpr = llvm::dyn_cast<ConstExpr>(expr);
if (constExpr == NULL) if (constExpr == NULL)
// We can't do anything if this isn't a const expr // We can't do anything if this isn't a const expr
return this; return this;
@@ -7315,7 +7315,7 @@ TypeCastExpr::Optimize() {
int int
TypeCastExpr::EstimateCost() const { TypeCastExpr::EstimateCost() const {
if (dynamic_cast<ConstExpr *>(expr) != NULL) if (llvm::dyn_cast<ConstExpr>(expr) != NULL)
return 0; return 0;
// FIXME: return COST_TYPECAST_COMPLEX when appropriate // FIXME: return COST_TYPECAST_COMPLEX when appropriate
@@ -7392,7 +7392,7 @@ TypeCastExpr::GetConstant(const Type *constType) const {
// ReferenceExpr // ReferenceExpr
ReferenceExpr::ReferenceExpr(Expr *e, SourcePos p) ReferenceExpr::ReferenceExpr(Expr *e, SourcePos p)
: Expr(p) { : Expr(p, ReferenceExprID) {
expr = e; expr = e;
} }
@@ -7500,8 +7500,8 @@ ReferenceExpr::Print() const {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// DerefExpr // DerefExpr
DerefExpr::DerefExpr(Expr *e, SourcePos p) DerefExpr::DerefExpr(Expr *e, SourcePos p, unsigned scid)
: Expr(p) { : Expr(p, scid) {
expr = e; expr = e;
} }
@@ -7563,7 +7563,7 @@ DerefExpr::Optimize() {
// PtrDerefExpr // PtrDerefExpr
PtrDerefExpr::PtrDerefExpr(Expr *e, SourcePos p) PtrDerefExpr::PtrDerefExpr(Expr *e, SourcePos p)
: DerefExpr(e, p) { : DerefExpr(e, p, PtrDerefExprID) {
} }
@@ -7641,7 +7641,7 @@ PtrDerefExpr::Print() const {
// RefDerefExpr // RefDerefExpr
RefDerefExpr::RefDerefExpr(Expr *e, SourcePos p) RefDerefExpr::RefDerefExpr(Expr *e, SourcePos p)
: DerefExpr(e, p) { : DerefExpr(e, p, RefDerefExprID) {
} }
@@ -7700,7 +7700,7 @@ RefDerefExpr::Print() const {
// AddressOfExpr // AddressOfExpr
AddressOfExpr::AddressOfExpr(Expr *e, SourcePos p) 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::SizeOfExpr(Expr *e, SourcePos p) 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) 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); type = type->ResolveUnboundVariability(Variability::Varying);
} }
@@ -7914,7 +7914,7 @@ SizeOfExpr::EstimateCost() const {
// SymbolExpr // SymbolExpr
SymbolExpr::SymbolExpr(Symbol *s, SourcePos p) SymbolExpr::SymbolExpr(Symbol *s, SourcePos p)
: Expr(p) { : Expr(p, SymbolExprID) {
symbol = s; symbol = s;
} }
@@ -8008,7 +8008,7 @@ SymbolExpr::Print() const {
FunctionSymbolExpr::FunctionSymbolExpr(const char *n, FunctionSymbolExpr::FunctionSymbolExpr(const char *n,
const std::vector<Symbol *> &candidates, const std::vector<Symbol *> &candidates,
SourcePos p) SourcePos p)
: Expr(p) { : Expr(p, FunctionSymbolExprID) {
name = n; name = n;
candidateFunctions = candidates; candidateFunctions = candidates;
matchingFunc = (candidates.size() == 1) ? candidates[0] : NULL; 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, NewExpr::NewExpr(int typeQual, const Type *t, Expr *init, Expr *count,
SourcePos tqPos, SourcePos p) SourcePos tqPos, SourcePos p)
: Expr(p) { : Expr(p, NewExprID) {
allocType = t; allocType = t;
initExpr = init; initExpr = init;

6
expr.h
View File

@@ -47,7 +47,7 @@
*/ */
class Expr : public ASTNode { class Expr : public ASTNode {
public: 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 /** This is the main method for Expr implementations to implement. It
should call methods in the FunctionEmitContext to emit LLVM IR should call methods in the FunctionEmitContext to emit LLVM IR
@@ -322,7 +322,7 @@ public:
const SourcePos identifierPos; const SourcePos identifierPos;
MemberExpr(Expr *expr, const char *identifier, SourcePos pos, 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 /** Indicates whether the expression should be dereferenced before the
member is found. (i.e. this is true if the MemberExpr was a '->' member is found. (i.e. this is true if the MemberExpr was a '->'
@@ -498,7 +498,7 @@ public:
PtrDerefExpr and RefDerefExpr. */ PtrDerefExpr and RefDerefExpr. */
class DerefExpr : public Expr { class DerefExpr : public Expr {
public: public:
DerefExpr(Expr *e, SourcePos p); DerefExpr(Expr *e, SourcePos p, unsigned scid = DerefExprID);
llvm::Value *GetValue(FunctionEmitContext *ctx) const; llvm::Value *GetValue(FunctionEmitContext *ctx) const;
llvm::Value *GetLValue(FunctionEmitContext *ctx) const; llvm::Value *GetLValue(FunctionEmitContext *ctx) const;

View File

@@ -499,7 +499,7 @@ Function::GenerateIR() {
// non-StmtList statment... // non-StmtList statment...
SourcePos firstStmtPos = sym->pos; SourcePos firstStmtPos = sym->pos;
if (code) { if (code) {
StmtList *sl = dynamic_cast<StmtList *>(code); StmtList *sl = llvm::dyn_cast<StmtList>(code);
if (sl && sl->stmts.size() > 0 && sl->stmts[0] != NULL) if (sl && sl->stmts.size() > 0 && sl->stmts[0] != NULL)
firstStmtPos = sl->stmts[0]->pos; firstStmtPos = sl->stmts[0]->pos;
else else

View File

@@ -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 // the same type as the global. (But not if it's an
// ExprList; they don't have types per se / can't type // ExprList; they don't have types per se / can't type
// convert themselves anyway.) // convert themselves anyway.)
if (dynamic_cast<ExprList *>(initExpr) == NULL) if (llvm::dyn_cast<ExprList>(initExpr) == NULL)
initExpr = TypeConvertExpr(initExpr, type, "initializer"); initExpr = TypeConvertExpr(initExpr, type, "initializer");
if (initExpr != NULL) { if (initExpr != NULL) {
@@ -620,11 +620,11 @@ Module::AddGlobalVariable(const std::string &name, const Type *type, Expr *initE
if (llvmInitializer != NULL) { if (llvmInitializer != NULL) {
if (type->IsConstType()) if (type->IsConstType())
// Try to get a ConstExpr associated with // 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 // validly fail, for example for types like
// StructTypes where a ConstExpr can't // StructTypes where a ConstExpr can't
// represent their values. // represent their values.
constValue = dynamic_cast<ConstExpr *>(initExpr); constValue = llvm::dyn_cast<ConstExpr>(initExpr);
} }
else else
Error(initExpr->pos, "Initializer for global variable \"%s\" " Error(initExpr->pos, "Initializer for global variable \"%s\" "
@@ -1906,7 +1906,7 @@ std::string emitOffloadParamStruct(const std::string &paramStructName,
Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n"); Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n");
} }
const ReferenceType *refType const ReferenceType *refType
= dynamic_cast<const ReferenceType*>(orgParamType); = llvm::dyn_cast<const ReferenceType>(orgParamType);
paramType = refType->GetReferenceTarget()->GetAsNonConstType(); paramType = refType->GetReferenceTarget()->GetAsNonConstType();
} else { } else {
paramType = orgParamType->GetAsNonConstType(); 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"); Error(sym->pos,"When emitting offload-stubs, \"export\"ed functions cannot have non-const reference-type parameters.\n");
} }
const ReferenceType *refType const ReferenceType *refType
= dynamic_cast<const ReferenceType*>(orgParamType); = llvm::dyn_cast<const ReferenceType>(orgParamType);
paramType = refType->GetReferenceTarget()->GetAsNonConstType(); paramType = refType->GetReferenceTarget()->GetAsNonConstType();
} else { } else {
paramType = orgParamType->GetAsNonConstType(); paramType = orgParamType->GetAsNonConstType();

View File

@@ -480,7 +480,7 @@ argument_expression_list
: assignment_expression { $$ = new ExprList($1, @1); } : assignment_expression { $$ = new ExprList($1, @1); }
| argument_expression_list ',' assignment_expression | argument_expression_list ',' assignment_expression
{ {
ExprList *argList = dynamic_cast<ExprList *>($1); ExprList *argList = llvm::dyn_cast<ExprList>($1);
if (argList == NULL) { if (argList == NULL) {
AssertPos(@1, m->errorCount > 0); AssertPos(@1, m->errorCount > 0);
argList = new ExprList(@3); argList = new ExprList(@3);
@@ -2422,7 +2422,7 @@ lFinalizeEnumeratorSymbols(std::vector<Symbol *> &enums,
Expr *castExpr = new TypeCastExpr(enumType, enums[i]->constValue, Expr *castExpr = new TypeCastExpr(enumType, enums[i]->constValue,
enums[i]->pos); enums[i]->pos);
castExpr = Optimize(castExpr); castExpr = Optimize(castExpr);
enums[i]->constValue = dynamic_cast<ConstExpr *>(castExpr); enums[i]->constValue = llvm::dyn_cast<ConstExpr>(castExpr);
AssertPos(enums[i]->pos, enums[i]->constValue != NULL); AssertPos(enums[i]->pos, enums[i]->constValue != NULL);
} }
else { else {

View File

@@ -295,7 +295,7 @@ DeclStmt::EmitCode(FunctionEmitContext *ctx) const {
// FIXME: we only need this for function pointers; it was // FIXME: we only need this for function pointers; it was
// already done for atomic types and enums in // already done for atomic types and enums in
// DeclStmt::TypeCheck()... // DeclStmt::TypeCheck()...
if (dynamic_cast<ExprList *>(initExpr) == NULL) { if (llvm::dyn_cast<ExprList>(initExpr) == NULL) {
initExpr = TypeConvertExpr(initExpr, sym->type, initExpr = TypeConvertExpr(initExpr, sym->type,
"initializer"); "initializer");
// FIXME: and this is only needed to re-establish // FIXME: and this is only needed to re-establish
@@ -436,7 +436,7 @@ Stmt *
DeclStmt::Optimize() { DeclStmt::Optimize() {
for (unsigned int i = 0; i < vars.size(); ++i) { for (unsigned int i = 0; i < vars.size(); ++i) {
Expr *init = vars[i].init; Expr *init = vars[i].init;
if (init != NULL && dynamic_cast<ExprList *>(init) == NULL) { if (init != NULL && llvm::dyn_cast<ExprList>(init) == NULL) {
// If the variable is const-qualified, after we've optimized // If the variable is const-qualified, after we've optimized
// the initializer expression, see if we have a ConstExpr. If // the initializer expression, see if we have a ConstExpr. If
// so, save it in Symbol::constValue where it can be used in // so, save it in Symbol::constValue where it can be used in
@@ -455,7 +455,7 @@ DeclStmt::Optimize() {
Symbol *sym = vars[i].sym; Symbol *sym = vars[i].sym;
if (sym->type && sym->type->IsConstType() && if (sym->type && sym->type->IsConstType() &&
Type::Equal(init->GetType(), sym->type)) Type::Equal(init->GetType(), sym->type))
sym->constValue = dynamic_cast<ConstExpr *>(init); sym->constValue = llvm::dyn_cast<ConstExpr>(init);
} }
} }
return this; return this;
@@ -483,7 +483,7 @@ DeclStmt::TypeCheck() {
// If it's an expr list with an atomic type, we'll later issue // 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 // an error. Need to leave vars[i].init as is in that case so
// it is in fact caught later, though. // it is in fact caught later, though.
if (dynamic_cast<ExprList *>(vars[i].init) == NULL) { if (llvm::dyn_cast<ExprList>(vars[i].init) == NULL) {
vars[i].init = TypeConvertExpr(vars[i].init, type, vars[i].init = TypeConvertExpr(vars[i].init, type,
"initializer"); "initializer");
if (vars[i].init == NULL) if (vars[i].init == NULL)
@@ -534,11 +534,11 @@ lEmitIfStatements(FunctionEmitContext *ctx, Stmt *stmts, const char *trueOrFalse
if (!stmts) if (!stmts)
return; return;
if (dynamic_cast<StmtList *>(stmts) == NULL) if (llvm::dyn_cast<StmtList>(stmts) == NULL)
ctx->StartScope(); ctx->StartScope();
ctx->AddInstrumentationPoint(trueOrFalse); ctx->AddInstrumentationPoint(trueOrFalse);
stmts->EmitCode(ctx); stmts->EmitCode(ctx);
if (dynamic_cast<const StmtList *>(stmts) == NULL) if (llvm::dyn_cast<const StmtList>(stmts) == NULL)
ctx->EndScope(); ctx->EndScope();
} }
@@ -549,18 +549,18 @@ lEmitIfStatements(FunctionEmitContext *ctx, Stmt *stmts, const char *trueOrFalse
static bool static bool
lCanApplyBreakOptimization(Stmt *trueStmts, Stmt *falseStmts) { lCanApplyBreakOptimization(Stmt *trueStmts, Stmt *falseStmts) {
if (falseStmts != NULL) { if (falseStmts != NULL) {
if (StmtList *sl = dynamic_cast<StmtList *>(falseStmts)) { if (StmtList *sl = llvm::dyn_cast<StmtList>(falseStmts)) {
return (sl->stmts.size() == 0); return (sl->stmts.size() == 0);
} }
else else
return false; return false;
} }
if (dynamic_cast<BreakStmt *>(trueStmts)) if (llvm::dyn_cast<BreakStmt>(trueStmts))
return true; return true;
else if (StmtList *sl = dynamic_cast<StmtList *>(trueStmts)) else if (StmtList *sl = llvm::dyn_cast<StmtList>(trueStmts))
return (sl->stmts.size() == 1 && return (sl->stmts.size() == 1 &&
dynamic_cast<BreakStmt *>(sl->stmts[0]) != NULL); llvm::dyn_cast<BreakStmt>(sl->stmts[0]) != NULL);
else else
return false; return false;
} }
@@ -949,7 +949,7 @@ struct VaryingBCCheckInfo {
static bool static bool
lIsVaryingFor(ASTNode *node) { lIsVaryingFor(ASTNode *node) {
IfStmt *ifStmt; IfStmt *ifStmt;
if ((ifStmt = dynamic_cast<IfStmt *>(node)) != NULL && if ((ifStmt = llvm::dyn_cast<IfStmt>(node)) != NULL &&
ifStmt->test != NULL) { ifStmt->test != NULL) {
const Type *type = ifStmt->test->GetType(); const Type *type = ifStmt->test->GetType();
return (type != NULL && type->IsVaryingType()); 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 // We found a break or continue statement; if we're under varying
// control flow, then bingo. // control flow, then bingo.
if ((dynamic_cast<BreakStmt *>(node) != NULL || if ((llvm::dyn_cast<BreakStmt>(node) != NULL ||
dynamic_cast<ContinueStmt *>(node) != NULL) && llvm::dyn_cast<ContinueStmt>(node) != NULL) &&
info->varyingControlFlowDepth > 0) { info->varyingControlFlowDepth > 0) {
info->foundVaryingBreakOrContinue = true; info->foundVaryingBreakOrContinue = true;
return false; return false;
@@ -979,9 +979,9 @@ lVaryingBCPreFunc(ASTNode *node, void *d) {
if (lIsVaryingFor(node)) if (lIsVaryingFor(node))
++info->varyingControlFlowDepth; ++info->varyingControlFlowDepth;
if (dynamic_cast<ForStmt *>(node) != NULL || if (llvm::dyn_cast<ForStmt>(node) != NULL ||
dynamic_cast<DoStmt *>(node) != NULL || llvm::dyn_cast<DoStmt>(node) != NULL ||
dynamic_cast<ForeachStmt *>(node) != NULL) llvm::dyn_cast<ForeachStmt>(node) != NULL)
// Don't recurse into these guys, since we don't care about varying // Don't recurse into these guys, since we don't care about varying
// breaks or continues within them... // breaks or continues within them...
return false; 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 // 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 // single statement (and thus not a statement list), we need a new
// scope, but we don't want two scopes in the StmtList case. // scope, but we don't want two scopes in the StmtList case.
if (!dynamic_cast<StmtList *>(bodyStmts)) if (!llvm::dyn_cast<StmtList>(bodyStmts))
ctx->StartScope(); ctx->StartScope();
ctx->AddInstrumentationPoint("do loop body"); ctx->AddInstrumentationPoint("do loop body");
@@ -1094,7 +1094,7 @@ void DoStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->BranchInst(btest); ctx->BranchInst(btest);
} }
// End the scope we started above, if needed. // End the scope we started above, if needed.
if (!dynamic_cast<StmtList *>(bodyStmts)) if (!llvm::dyn_cast<StmtList>(bodyStmts))
ctx->EndScope(); ctx->EndScope();
// Now emit code for the loop test. // 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 // it and then jump into the loop test code. (Also start a new scope
// since the initiailizer may be a declaration statement). // since the initiailizer may be a declaration statement).
if (init) { if (init) {
AssertPos(pos, dynamic_cast<StmtList *>(init) == NULL); AssertPos(pos, llvm::dyn_cast<StmtList>(init) == NULL);
ctx->StartScope(); ctx->StartScope();
init->EmitCode(ctx); init->EmitCode(ctx);
} }
@@ -1261,7 +1261,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const {
ctx->SetCurrentBasicBlock(bloop); ctx->SetCurrentBasicBlock(bloop);
ctx->SetBlockEntryMask(ctx->GetFullMask()); ctx->SetBlockEntryMask(ctx->GetFullMask());
ctx->AddInstrumentationPoint("for loop body"); ctx->AddInstrumentationPoint("for loop body");
if (!dynamic_cast<StmtList *>(stmts)) if (!llvm::dyn_cast<StmtList>(stmts))
ctx->StartScope(); ctx->StartScope();
if (doCoherentCheck && !uniformTest) { if (doCoherentCheck && !uniformTest) {
@@ -1306,7 +1306,7 @@ ForStmt::EmitCode(FunctionEmitContext *ctx) const {
if (ctx->GetCurrentBasicBlock()) if (ctx->GetCurrentBasicBlock())
ctx->BranchInst(bstep); ctx->BranchInst(bstep);
} }
if (!dynamic_cast<StmtList *>(stmts)) if (!llvm::dyn_cast<StmtList>(stmts))
ctx->EndScope(); ctx->EndScope();
// Emit code for the loop step. First, restore the lane mask of any // Emit code for the loop step. First, restore the lane mask of any
@@ -2794,13 +2794,13 @@ struct SwitchVisitInfo {
static bool static bool
lSwitchASTPreVisit(ASTNode *node, void *d) { lSwitchASTPreVisit(ASTNode *node, void *d) {
if (dynamic_cast<SwitchStmt *>(node) != NULL) if (llvm::dyn_cast<SwitchStmt>(node) != NULL)
// don't continue recursively into a nested switch--we only want // don't continue recursively into a nested switch--we only want
// our own case and default statements! // our own case and default statements!
return false; return false;
CaseStmt *cs = dynamic_cast<CaseStmt *>(node); CaseStmt *cs = llvm::dyn_cast<CaseStmt>(node);
DefaultStmt *ds = dynamic_cast<DefaultStmt *>(node); DefaultStmt *ds = llvm::dyn_cast<DefaultStmt>(node);
SwitchVisitInfo *svi = (SwitchVisitInfo *)d; SwitchVisitInfo *svi = (SwitchVisitInfo *)d;
llvm::BasicBlock *bb = NULL; llvm::BasicBlock *bb = NULL;
@@ -3383,7 +3383,7 @@ PrintStmt::EmitCode(FunctionEmitContext *ctx) const {
// Get the values passed to the print() statement evaluated and // Get the values passed to the print() statement evaluated and
// stored in memory so that we set up the array of pointers to them // stored in memory so that we set up the array of pointers to them
// for the 5th __do_print() argument // for the 5th __do_print() argument
ExprList *elist = dynamic_cast<ExprList *>(values); ExprList *elist = llvm::dyn_cast<ExprList>(values);
int nArgs = elist ? elist->exprs.size() : 1; int nArgs = elist ? elist->exprs.size() : 1;
// Allocate space for the array of pointers to values to be printed // Allocate space for the array of pointers to values to be printed

8
test_class_of.cpp Normal file
View File

@@ -0,0 +1,8 @@
#include "ispc.h"
int main() {
return 0;
};

View File

@@ -1603,7 +1603,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) {
if (at == NULL) if (at == NULL)
return type; return type;
ExprList *exprList = dynamic_cast<ExprList *>(initExpr); ExprList *exprList = llvm::dyn_cast<ExprList>(initExpr);
if (exprList == NULL || exprList->exprs.size() == 0) if (exprList == NULL || exprList->exprs.size() == 0)
return type; 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 // 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 // (after checking below that it has the same length as all of the
// other ones. // other ones.
ExprList *nextList = dynamic_cast<ExprList *>(exprList->exprs[0]); ExprList *nextList = llvm::dyn_cast<ExprList>(exprList->exprs[0]);
if (nextList == NULL) if (nextList == NULL)
return type; return type;
@@ -1638,7 +1638,7 @@ ArrayType::SizeUnsizedArrays(const Type *type, Expr *initExpr) {
continue; continue;
} }
ExprList *el = dynamic_cast<ExprList *>(exprList->exprs[i]); ExprList *el = llvm::dyn_cast<ExprList>(exprList->exprs[i]);
if (el == NULL || el->exprs.size() != nextSize) { if (el == NULL || el->exprs.size() != nextSize) {
Error(Union(exprList->exprs[0]->pos, exprList->exprs[i]->pos), Error(Union(exprList->exprs[0]->pos, exprList->exprs[i]->pos),
"Inconsistent initializer expression list lengths " "Inconsistent initializer expression list lengths "