From 6e0af6ef491616b430a419b08ae3f2b6137a8881 Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Tue, 11 Oct 2016 17:49:01 -0600 Subject: fixes --- include/chillAST/chillASTs.hh | 1 + lib/codegen/src/CG_stringBuilder.cc | 9 ------ lib/codegen/src/CG_utils.cc | 4 +-- src/ast/chillASTs.cc | 5 ++++ src/ast/node.cpp | 2 +- src/frontend/clang.cpp | 2 +- src/ir_chill.cc | 60 ++----------------------------------- src/omegatools.cc | 2 ++ 8 files changed, 15 insertions(+), 70 deletions(-) diff --git a/include/chillAST/chillASTs.hh b/include/chillAST/chillASTs.hh index 4b50479..da4d58f 100644 --- a/include/chillAST/chillASTs.hh +++ b/include/chillAST/chillASTs.hh @@ -1140,6 +1140,7 @@ public: void setSubExpr(chillAST_Node *sub) { setChild(0, sub); } // required methods that I can't seem to get to inherit + chillAST_Node *constantFold(); chillAST_Node *clone(); bool findLoopIndexesToReplace(chillAST_SymbolTable *symtab, diff --git a/lib/codegen/src/CG_stringBuilder.cc b/lib/codegen/src/CG_stringBuilder.cc index 7a19f66..884e52d 100755 --- a/lib/codegen/src/CG_stringBuilder.cc +++ b/lib/codegen/src/CG_stringBuilder.cc @@ -183,22 +183,13 @@ namespace omega { CG_stringRepr *CG_stringBuilder::CreateInvoke(const std::string &funcName, std::vector &list) const { - fprintf(stderr, "CG_stringBuilder::CreateInvoke( %s, ..., is_array ", funcName.c_str()); - fprintf(stderr, " false )\n"); - - std::string listStr = ""; - fprintf(stderr, "list has %d elements\n", list.size()); - for (int i = 0; i < list.size(); i++) { - fprintf(stderr, "accessing list[%d]\n", i); listStr += GetString(list[i]); if ( i < list.size()-1) listStr += ","; } - - fprintf(stderr, "returning %s\n", (funcName + "(" + listStr + ")").c_str()); return new CG_stringRepr(funcName + "(" + listStr + ")"); } diff --git a/lib/codegen/src/CG_utils.cc b/lib/codegen/src/CG_utils.cc index 839343f..87b170c 100755 --- a/lib/codegen/src/CG_utils.cc +++ b/lib/codegen/src/CG_utils.cc @@ -1829,7 +1829,7 @@ namespace omega { CG_outputRepr *lbRepr = NULL; if (lbList.size() > 1) { - fprintf(stderr, "CG_utils.cc output_loop() createInvoke( max )\n"); + CG_DEBUG_PRINT("CG_utils.cc output_loop() createInvoke( max )\n"); lbRepr = ocg->CreateInvoke("max", lbList); } else { // (lbList.size() == 1) @@ -1838,7 +1838,7 @@ namespace omega { CG_outputRepr *ubRepr = NULL; if (ubList.size() > 1) { - fprintf(stderr, "CG_utils.cc output_loop() createInvoke( min )\n"); + CG_DEBUG_PRINT("CG_utils.cc output_loop() createInvoke( min )\n"); ubRepr = ocg->CreateInvoke("min", ubList); } else { // (ubList.size() == 1) diff --git a/src/ast/chillASTs.cc b/src/ast/chillASTs.cc index 60603d2..4181638 100644 --- a/src/ast/chillASTs.cc +++ b/src/ast/chillASTs.cc @@ -1986,6 +1986,11 @@ chillAST_Node *chillAST_ParenExpr::clone() { return PE; } +chillAST_Node *chillAST_ParenExpr::constantFold() { + chillAST_Node::constantFold(); + return getSubExpr(); +} + chillAST_Sizeof::chillAST_Sizeof(char *athing) { thing = strdup(athing); // memory leak } diff --git a/src/ast/node.cpp b/src/ast/node.cpp index 6117f91..cad5f4c 100644 --- a/src/ast/node.cpp +++ b/src/ast/node.cpp @@ -34,7 +34,7 @@ const char *ChillAST_Node_Names[] = { "ImplicitCastExpr", // not sure we need this "ReturnStmt", "CallExpr", - "DeclStmt", +// "DeclStmt", "ParenExpr", "CStyleCastExpr", "CStyleAddressOf", diff --git a/src/frontend/clang.cpp b/src/frontend/clang.cpp index e7b74ed..9324ba8 100644 --- a/src/frontend/clang.cpp +++ b/src/frontend/clang.cpp @@ -378,7 +378,7 @@ chillAST_NodeList* ConvertIfStmt(IfStmt *clangIS) { chillAST_NodeList* ConvertUnaryOperator(UnaryOperator *clangUO) { const char *op = unops[clangUO->getOpcode()].c_str(); - bool pre = clangUO->isPrefix(); + bool pre = !clangUO->isPostfix(); chillAST_Node *sub = unwrap(ConvertGenericClangAST(clangUO->getSubExpr())); chillAST_UnaryOperator *chillUO = new chillAST_UnaryOperator(op, pre, sub); diff --git a/src/ir_chill.cc b/src/ir_chill.cc index 4e37b48..933e59c 100755 --- a/src/ir_chill.cc +++ b/src/ir_chill.cc @@ -19,21 +19,6 @@ History: #include "loop.hh" #include "chill_error.hh" -#include "clang/Frontend/FrontendActions.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - #include "code_gen/CG_chillRepr.h" #include "code_gen/CG_chillBuilder.h" #include @@ -1201,6 +1186,7 @@ void IR_clangCode::ReplaceExpression(IR_Ref *old, omega::CG_outputRepr *repr) { IR_CONDITION_TYPE IR_clangCode::QueryBooleanExpOperation(const omega::CG_outputRepr *repr) const { CG_chillRepr *crepr = (CG_chillRepr *)repr; chillAST_Node *node = crepr->chillnodes[0]; + node = node->constantFold(); if (!node->isBinaryOperator()) { if (node->isUnaryOperator()) { chillAST_UnaryOperator *uop = (chillAST_UnaryOperator*)node; @@ -1225,10 +1211,7 @@ IR_CONDITION_TYPE IR_clangCode::QueryBooleanExpOperation(const omega::CG_outputR IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *repr) const { CG_chillRepr *crepr = (CG_chillRepr *) repr; chillAST_Node *node = crepr->chillnodes[0]; - // really need to be more rigorous than this hack // TODO - if (node->isImplicitCastExpr()) node = ((chillAST_ImplicitCastExpr *) node)->getSubExpr(); - if (node->isCStyleCastExpr()) node = ((chillAST_CStyleCastExpr *) node)->getSubExpr(); - if (node->isParenExpr()) node = ((chillAST_ParenExpr *) node)->getSubExpr(); + node = node->constantFold(); if (node->isIntegerLiteral() || node->isFloatingLiteral()) return IR_OP_CONSTANT; else if (node->isBinaryOperator() || node->isUnaryOperator()) { @@ -1252,39 +1235,6 @@ IR_OPERATION_TYPE IR_clangCode::QueryExpOperation(const omega::CG_outputRepr *re CHILL_ERROR("IR_clangCode::QueryExpOperation() UNHANDLED NODE TYPE %s\n", node->getTypeString()); exit(-1); } - - /* CLANG - Expr *e = static_cast(repr)->GetExpression(); - if(isa(e) || isa(e)) return IR_OP_CONSTANT; - else if(isa(e)) return IR_OP_VARIABLE; - else if(BinaryOperator *bop = dyn_cast(e)) { - switch(bop->getOpcode()) { - case BO_Assign: return IR_OP_ASSIGNMENT; - case BO_Add: return IR_OP_PLUS; - case BO_Sub: return IR_OP_MINUS; - case BO_Mul: return IR_OP_MULTIPLY; - case BO_Div: return IR_OP_DIVIDE; - default: return IR_OP_UNKNOWN; - } - } else if(UnaryOperator *uop = dyn_cast(e)) { - switch(uop->getOpcode()) { - case UO_Minus: return IR_OP_NEGATIVE; - case UO_Plus: return IR_OP_POSITIVE; - default: return IR_OP_UNKNOWN; - } - } else if(ConditionalOperator *cop = dyn_cast(e)) { - BinaryOperator *bop; - if(bop = dyn_cast(cop->getCond())) { - if(bop->getOpcode() == BO_GT) return IR_OP_MAX; - else if(bop->getOpcode() == BO_LT) return IR_OP_MIN; - } else return IR_OP_UNKNOWN; - - } - - else if(e == NULL) return IR_OP_NULL; - else return IR_OP_UNKNOWN; - } - END CLANG */ } @@ -1294,11 +1244,7 @@ std::vector IR_clangCode::QueryExpOperand(const omega::C CG_chillRepr *crepr = (CG_chillRepr *) repr; chillAST_Node *e = crepr->chillnodes[0]; // ?? - // really need to be more rigorous than this hack // TODO - if (e->isImplicitCastExpr()) e = ((chillAST_ImplicitCastExpr *) e)->getSubExpr(); - if (e->isCStyleCastExpr()) e = ((chillAST_CStyleCastExpr *) e)->getSubExpr(); - if (e->isParenExpr()) e = ((chillAST_ParenExpr *) e)->getSubExpr(); - + e = e->constantFold(); if (e->isIntegerLiteral() || e->isFloatingLiteral() || e->isDeclRefExpr()) { omega::CG_chillRepr *repr = new omega::CG_chillRepr(e); diff --git a/src/omegatools.cc b/src/omegatools.cc index 36b0e8d..6d48a3c 100644 --- a/src/omegatools.cc +++ b/src/omegatools.cc @@ -1072,11 +1072,13 @@ void exp2constraint(IR_Code *ir, Relation &r, F_And *f_root, F_And *fa = f_root->add_not()->add_and(); std::vector op = ir->QueryExpOperand(repr); exp2constraint(ir, r, fa, freevars, op[0], false, uninterpreted_symbols, uninterpreted_symbols_stringrepr); + break; } case IR_COND_AND: { std::vector op = ir->QueryExpOperand(repr); exp2constraint(ir, r, f_root, freevars, op[0], false, uninterpreted_symbols, uninterpreted_symbols_stringrepr); exp2constraint(ir, r, f_root, freevars, op[1], false, uninterpreted_symbols, uninterpreted_symbols_stringrepr); + break; } case IR_COND_OR: { F_Or *f_or = f_root->add_or(); -- cgit v1.2.3-70-g09d2