summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-10-11 17:49:01 -0600
committerTuowen Zhao <ztuowen@gmail.com>2016-10-11 17:49:01 -0600
commit6e0af6ef491616b430a419b08ae3f2b6137a8881 (patch)
tree35b23dd6fbbd82d6dda9151efc6aba37cbbf196a
parenta78fdbc93fd8919aacf375cc4d40fdd46a9722a0 (diff)
downloadchill-6e0af6ef491616b430a419b08ae3f2b6137a8881.tar.gz
chill-6e0af6ef491616b430a419b08ae3f2b6137a8881.tar.bz2
chill-6e0af6ef491616b430a419b08ae3f2b6137a8881.zip
fixes
-rw-r--r--include/chillAST/chillASTs.hh1
-rwxr-xr-xlib/codegen/src/CG_stringBuilder.cc9
-rwxr-xr-xlib/codegen/src/CG_utils.cc4
-rw-r--r--src/ast/chillASTs.cc5
-rw-r--r--src/ast/node.cpp2
-rw-r--r--src/frontend/clang.cpp2
-rwxr-xr-xsrc/ir_chill.cc60
-rw-r--r--src/omegatools.cc2
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<CG_outputRepr *> &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 <clang/CodeGen/CodeGenAction.h>
-#include <clang/Frontend/CompilerInstance.h>
-#include <clang/Frontend/CompilerInvocation.h>
-#include <clang/Basic/DiagnosticOptions.h>
-#include <clang/Frontend/TextDiagnosticPrinter.h>
-#include <clang/AST/ASTContext.h>
-#include <clang/AST/RecordLayout.h>
-#include <clang/AST/Decl.h>
-#include <clang/Parse/ParseAST.h>
-#include <clang/Basic/TargetInfo.h>
-
-#include <llvm/ADT/IntrusiveRefCntPtr.h>
-#include <llvm/Support/Host.h>
-
#include "code_gen/CG_chillRepr.h"
#include "code_gen/CG_chillBuilder.h"
#include <vector>
@@ -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<const omega::CG_chillRepr *>(repr)->GetExpression();
- if(isa<IntegerLiteral>(e) || isa<FloatingLiteral>(e)) return IR_OP_CONSTANT;
- else if(isa<DeclRefExpr>(e)) return IR_OP_VARIABLE;
- else if(BinaryOperator *bop = dyn_cast<BinaryOperator>(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<UnaryOperator>(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<ConditionalOperator>(e)) {
- BinaryOperator *bop;
- if(bop = dyn_cast<BinaryOperator>(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<omega::CG_outputRepr *> 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<omega::CG_outputRepr *> op = ir->QueryExpOperand(repr);
exp2constraint(ir, r, fa, freevars, op[0], false, uninterpreted_symbols, uninterpreted_symbols_stringrepr);
+ break;
}
case IR_COND_AND: {
std::vector<omega::CG_outputRepr *> 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();