summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2016-10-09 17:22:46 -0600
committerTuowen Zhao <ztuowen@gmail.com>2016-10-09 17:22:46 -0600
commit5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc (patch)
tree91e2305b1a295e13d23798de0ded8882212bd67d
parent340f3d1a30449912d73a49cba41be76d29ace36b (diff)
downloadchill-5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc.tar.gz
chill-5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc.tar.bz2
chill-5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc.zip
recovered branch
-rwxr-xr-xinclude/ir_clang.hh14
-rwxr-xr-xlib/chillcg/src/CG_chillBuilder.cc4
-rwxr-xr-xlib/codegen/src/CG_utils.cc5
-rw-r--r--src/chillmodule.cc15
-rwxr-xr-xsrc/ir_clang.cc73
-rw-r--r--src/printer/cfamily.cpp2
-rw-r--r--src/transformations/loop.cc3
7 files changed, 78 insertions, 38 deletions
diff --git a/include/ir_clang.hh b/include/ir_clang.hh
index 3e4e7d6..94fbc95 100755
--- a/include/ir_clang.hh
+++ b/include/ir_clang.hh
@@ -336,16 +336,14 @@ public:
void dump() const;
};
+struct IR_chillIf: public IR_If {
+ chillAST_Node *code;
-#ifdef NOTYET
-struct IR_clangIf: public IR_If {
- SgNode *ti_;
-
- IR_clangIf(const IR_Code *ir, SgNode *ti) {
+ IR_chillIf(const IR_Code *ir, chillAST_Node *ti) {
ir_ = ir;
- ti_ = ti;
+ code = ti;
}
- ~IR_clangIf() {
+ ~IR_chillIf() {
}
omega::CG_outputRepr *condition() const;
IR_Block *then_body() const;
@@ -353,8 +351,6 @@ struct IR_clangIf: public IR_If {
IR_Block *convert();
IR_Control *clone() const;
};
-#endif
-
class aClangCompiler {
private:
diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc
index 74622d7..2613910 100755
--- a/lib/chillcg/src/CG_chillBuilder.cc
+++ b/lib/chillcg/src/CG_chillBuilder.cc
@@ -60,7 +60,7 @@ namespace omega {
// No op
break;
default:
- CHILL_ERROR("UNHANDLED statement of type %s %s\n",n->getTypeString());
+ CG_ERROR("UNHANDLED statement of type %s %s\n",n->getTypeString());
exit(-1);
}
return r;
@@ -213,7 +213,7 @@ namespace omega {
CG_outputRepr *lhs,
CG_outputRepr *rhs) const {
if(lhs == NULL || rhs == NULL) {
- CHILL_ERROR("Code generation: Missing lhs or rhs\n");
+ CG_ERROR("Code generation: Missing lhs or rhs\n");
return NULL;
}
diff --git a/lib/codegen/src/CG_utils.cc b/lib/codegen/src/CG_utils.cc
index 95f94ec..839343f 100755
--- a/lib/codegen/src/CG_utils.cc
+++ b/lib/codegen/src/CG_utils.cc
@@ -2607,7 +2607,6 @@ namespace omega {
}
Relation then_cond = find_best_guard(R, loops, start, end);
- fprintf(stderr, "then_cond "); then_cond.print(stderr);
assert(!then_cond.is_obvious_tautology());
Relation else_cond = Complement(copy(then_cond));
else_cond.simplify();
@@ -2640,11 +2639,7 @@ namespace omega {
else if (j == i && end > j) {
int new_indent = (guard_repr==NULL)?indent:indent+1;
Relation new_guard = Intersection(copy(guard), copy(then_cond));
- new_guard.print(stderr);
- new_guard.print_with_subs(stderr);
new_guard.simplify();
- new_guard.print(stderr);
- new_guard.print_with_subs(stderr);
CG_outputRepr *stmt_list = loop_print_repr(active,
loops,
start,
diff --git a/src/chillmodule.cc b/src/chillmodule.cc
index e59fc79..552eda8 100644
--- a/src/chillmodule.cc
+++ b/src/chillmodule.cc
@@ -25,6 +25,7 @@ std::string dest_filename;
int loop_start_num;
int loop_end_num;
+int effort;
extern std::vector<IR_Control *> ir_controls;
extern std::vector<int> loops;
@@ -52,14 +53,14 @@ static void set_loop_num_end(int end_num) {
void finalize_loop(int loop_num_start, int loop_num_end) {
if (loop_num_start == loop_num_end) {
- ir_code->ReplaceCode(ir_controls[loops[loop_num_start]], myloop->getCode());
+ ir_code->ReplaceCode(ir_controls[loops[loop_num_start]], myloop->getCode(effort));
ir_controls[loops[loop_num_start]] = NULL;
} else {
std::vector<IR_Control *> parm;
for (int i = loops[loop_num_start]; i <= loops[loop_num_end]; i++)
parm.push_back(ir_controls[i]);
IR_Block *block = ir_code->MergeNeighboringControlStructures(parm);
- ir_code->ReplaceCode(block, myloop->getCode());
+ ir_code->ReplaceCode(block, myloop->getCode(effort));
for (int i = loops[loop_num_start]; i <= loops[loop_num_end]; i++) {
delete ir_controls[i];
ir_controls[i] = NULL;
@@ -279,6 +280,12 @@ chill_dest(PyObject *self, PyObject* args) {
Py_RETURN_NONE;
}
+static PyObject *chill_effort(PyObject *self, PyObject *args) {
+ strict_arg_num(args, 1, "effort");
+ source_filename = intArg(args, 0);
+ Py_RETURN_NONE;
+}
+
static PyObject *chill_procedure(PyObject *self, PyObject *args) {
if (!procedure_name.empty()) {
CHILL_ERROR("only one procedure can be handled in a script");
@@ -315,7 +322,7 @@ static PyObject *chill_loop(PyObject *self, PyObject *args) {
static PyObject *chill_print_code(PyObject *self, PyObject *args) {
strict_arg_num(args, 0, "print_code");
- myloop->printCode();
+ myloop->printCode(effort);
printf("\n");
Py_RETURN_NONE;
}
@@ -726,6 +733,7 @@ static PyMethodDef ChillMethods[] = {
//python name C routine parameter passing comment
{"source", chill_source, METH_VARARGS, "set source file for chill script"},
{"destination", chill_dest, METH_VARARGS, "set destination file for generated source"},
+ {"effort", chill_effort, METH_VARARGS, "set the effort to remove loop overhead"},
{"procedure", chill_procedure, METH_VARARGS, "set the name of the procedure"},
{"loop", chill_loop, METH_VARARGS, "indicate which loop to optimize"},
{"print_code", chill_print_code, METH_VARARGS, "print generated code"},
@@ -778,5 +786,6 @@ initchill(void) // pass C methods to python
CHILL_DEBUG_PRINT("set up C methods to be called from python\n");
PyObject *m = Py_InitModule("chill", ChillMethods);
dest_filename = "";
+ effort = 1;
register_globals(m);
}
diff --git a/src/ir_clang.cc b/src/ir_clang.cc
index b5db954..77e8d45 100755
--- a/src/ir_clang.cc
+++ b/src/ir_clang.cc
@@ -442,9 +442,23 @@ chillAST_NodeList* ConvertIfStmt(IfStmt *clangIS) {
chillAST_Node *con = unwrap(ConvertGenericClangAST(cond));
chillAST_Node *thn = NULL;
- if (thenpart) thn = unwrap(ConvertGenericClangAST(thenpart));
+ if (thenpart) {
+ thn = unwrap(ConvertGenericClangAST(thenpart));
+ if (!thn->isCompoundStmt()) {
+ chillAST_Node* tmp=new chillAST_CompoundStmt();
+ tmp->addChild(thn);
+ thn = tmp;
+ }
+ }
chillAST_Node *els = NULL;
- if (elsepart) els = unwrap(ConvertGenericClangAST(elsepart));
+ if (elsepart) {
+ els = unwrap(ConvertGenericClangAST(elsepart));
+ if (!els->isCompoundStmt()) {
+ chillAST_Node* tmp=new chillAST_CompoundStmt();
+ tmp->addChild(els);
+ els = tmp;
+ }
+ }
chillAST_IfStmt *ifstmt = new chillAST_IfStmt(con, thn, els);
NL_RET(ifstmt);
@@ -1988,8 +2002,6 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
for (int i = 0; i < numchildren; i++) {
CHILLAST_NODE_TYPE typ = (*children)[i]->getType();
if (typ == CHILLAST_NODE_LOOP) {
- CHILL_DEBUG_PRINT("found a For statement (Loop) at %d within a Basic Block\n", i);
-
ns = basicblock->numstatements();
if (ns) {
CHILL_DEBUG_PRINT("pushing a run of statements as a block\n");
@@ -1999,18 +2011,17 @@ std::vector<IR_Control *> IR_clangCode::FindOneLevelControlStructure(const IR_Bl
CHILL_DEBUG_PRINT("pushing the loop at %d\n", i);
controls.push_back(new IR_chillLoop(this, (chillAST_ForStmt *) (*children)[i]));
-
- }
- //else if (typ == CHILLAST_NODE_IFSTMT ) // TODO
- else { // straight line code
+ } else if (typ == CHILLAST_NODE_IFSTMT ) {
+ ns = basicblock->numstatements();
+ if (ns) {
+ CHILL_DEBUG_PRINT("pushing a run of statements as a block\n");
+ controls.push_back(basicblock);
+ basicblock = new IR_chillBlock(this); // start a new one
+ }
+ CHILL_DEBUG_PRINT("pushing the if at %d\n", i);
+ controls.push_back(new IR_chillIf(this, (chillAST_IfStmt *) (*children)[i]));
+ } else
basicblock->addStatement((*children)[i]);
- CHILL_DEBUG_BEGIN
- fprintf(stderr, "straight line code\n");
- fprintf(stderr, "child %d = \n", i);
- (*children)[i]->print();
- fprintf(stderr, "child %d is part of a basic block\n", i);
- CHILL_DEBUG_END
- }
} // for each child
ns = basicblock->numstatements();
if (ns != 0 && (unwrap || ns != numchildren))
@@ -2475,4 +2486,34 @@ chillAST_NodeList* ConvertMemberExpr(clang::MemberExpr *clangME) {
NL_RET(ME);
-}
+}
+
+omega::CG_outputRepr *IR_chillIf::condition() const {
+ assert( code->isIfStmt() && "If statement's code is not if statement");
+ return new omega::CG_chillRepr(((chillAST_IfStmt*)code) -> getCond());
+}
+
+IR_Block *IR_chillIf::then_body() const {
+ assert( code->isIfStmt() && "If statement's code is not if statement");
+ chillAST_Node* thenPart = ((chillAST_IfStmt*)code) -> getThen();
+ if (thenPart) return new IR_chillBlock(ir_,thenPart);
+ return NULL;
+}
+
+IR_Block *IR_chillIf::else_body() const {
+ assert( code->isIfStmt() && "If statement's code is not if statement");
+ chillAST_Node* elsePart = ((chillAST_IfStmt*)code) -> getElse();
+ if (elsePart) return new IR_chillBlock(ir_,elsePart);
+ return NULL;
+}
+
+IR_Block *IR_chillIf::convert() {
+ const IR_Code *ir = ir_;
+ chillAST_Node *code = this->code;
+ delete this;
+ return new IR_chillBlock(ir,code);
+}
+
+IR_Control *IR_chillIf::clone() const {
+ return new IR_chillIf(ir_,code);
+}
diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp
index 37c3dd4..1e79fa9 100644
--- a/src/printer/cfamily.cpp
+++ b/src/printer/cfamily.cpp
@@ -37,7 +37,7 @@ const char *binaryPrec[] = {
" * / % ",
" + - ",
" << >> ",
- " < <= > >=",
+ " < <= > >= ",
" == != ",
" & ",
" ^ ",
diff --git a/src/transformations/loop.cc b/src/transformations/loop.cc
index 026794f..409ece9 100644
--- a/src/transformations/loop.cc
+++ b/src/transformations/loop.cc
@@ -1058,8 +1058,7 @@ CG_outputRepr *Loop::getCode(int effort) const {
xforms[i] = stmt[i].xform;
}
- debugRelations();
-
+ //debugRelations();
Relation known = Extend_Set(copy(this->known), n - this->known.n_set());