diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-10-09 17:22:46 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-10-09 17:22:46 -0600 |
commit | 5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc (patch) | |
tree | 91e2305b1a295e13d23798de0ded8882212bd67d /src | |
parent | 340f3d1a30449912d73a49cba41be76d29ace36b (diff) | |
download | chill-5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc.tar.gz chill-5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc.tar.bz2 chill-5b5d1934d8870f49cbb1b8f45f228baa5f76d2bc.zip |
recovered branch
Diffstat (limited to 'src')
-rw-r--r-- | src/chillmodule.cc | 15 | ||||
-rwxr-xr-x | src/ir_clang.cc | 73 | ||||
-rw-r--r-- | src/printer/cfamily.cpp | 2 | ||||
-rw-r--r-- | src/transformations/loop.cc | 3 |
4 files changed, 71 insertions, 22 deletions
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()); |