diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2016-10-06 23:41:15 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2016-10-06 23:41:15 -0600 |
commit | 7414769da6aaff79887b5ba53406f442df9da33f (patch) | |
tree | 949765e0a6884d25c044cc2bf6313321ada5890c | |
parent | f329ee2b4cfdde656d2fe30f2a2789d8a3774203 (diff) | |
download | chill-7414769da6aaff79887b5ba53406f442df9da33f.tar.gz chill-7414769da6aaff79887b5ba53406f442df9da33f.tar.bz2 chill-7414769da6aaff79887b5ba53406f442df9da33f.zip |
further cleanup
-rwxr-xr-x | include/ir_clang.hh | 1 | ||||
-rwxr-xr-x | lib/chillcg/src/CG_chillBuilder.cc | 259 | ||||
-rwxr-xr-x | lib/codegen/src/CG.cc | 205 | ||||
-rwxr-xr-x | lib/codegen/src/CG_utils.cc | 99 | ||||
-rw-r--r-- | src/chillASTs.cc | 3 | ||||
-rwxr-xr-x | src/ir_clang.cc | 147 | ||||
-rw-r--r-- | src/irtools.cc | 52 | ||||
-rw-r--r-- | src/omegatools.cc | 117 | ||||
-rw-r--r-- | src/printer/cfamily.cpp | 7 | ||||
-rw-r--r-- | src/transformations/loop.cc | 296 | ||||
-rw-r--r-- | src/transformations/loop_basic.cc | 8 |
11 files changed, 177 insertions, 1017 deletions
diff --git a/include/ir_clang.hh b/include/ir_clang.hh index 4344f68..14def21 100755 --- a/include/ir_clang.hh +++ b/include/ir_clang.hh @@ -39,7 +39,6 @@ struct IR_chillScalarSymbol : public IR_ScalarSymbol { chillAST_VarDecl *chillvd; IR_chillScalarSymbol(const IR_Code *ir, chillAST_VarDecl *vd) { - fprintf(stderr, "making scalar symbol %s\n", vd->varname); ir_ = ir; chillvd = vd; } diff --git a/lib/chillcg/src/CG_chillBuilder.cc b/lib/chillcg/src/CG_chillBuilder.cc index dc02447..966c20f 100755 --- a/lib/chillcg/src/CG_chillBuilder.cc +++ b/lib/chillcg/src/CG_chillBuilder.cc @@ -384,29 +384,21 @@ namespace omega { CG_outputRepr *lower, CG_outputRepr *upper, CG_outputRepr *step) const { - fprintf(stderr, "\nCG_chillBuilder::CreateInductive()\n"); if (index == NULL || lower == NULL || upper == NULL) { - fprintf(stderr, "Code generation: invalid arguments to CreateInductive\n"); + CG_ERROR("Code generation: invalid arguments to CreateInductive\n"); return NULL; } - - if (step == NULL) { - //IntegerLiteral *ilit = new (astContext_)IntegerLiteral(*astContext_, llvm::APInt(32, 1), bint->desugar(), SourceLocation()); - //step = new CG_chillRepr(ilit); - chillAST_IntegerLiteral *intlit = new chillAST_IntegerLiteral(1); step = new CG_chillRepr(intlit); } - - //static_cast<CG_chillRepr*>(index)->printChillNodes(); + //static_cast<CG_chillRepr*>(index)->printChillNodes(); //static_cast<CG_chillRepr*>(lower)->printChillNodes(); //static_cast<CG_chillRepr*>(upper)->printChillNodes(); //static_cast<CG_chillRepr*>(step )->printChillNodes(); // index should be a DeclRefExpr std::vector<chillAST_Node*> nodes = static_cast<CG_chillRepr*>(index)->getChillCode(); - //fprintf(stderr, "%d index nodes\n", nodes.size()); chillAST_Node *indexnode = nodes[0]; if (strcmp("DeclRefExpr", indexnode->getTypeString())) { fprintf(stderr, "CG_chillBuilder::CreateInductive index is not a DeclRefExpr\n"); @@ -420,20 +412,14 @@ namespace omega { } nodes = static_cast<CG_chillRepr*>(lower)->getChillCode(); - //fprintf(stderr, "%d lower nodes\n", nodes.size()); chillAST_Node *lowernode = nodes[0]; - //fprintf(stderr, "lower node is %s\n", lowernode->getTypeString()); - + nodes = static_cast<CG_chillRepr*>(upper)->getChillCode(); - //fprintf(stderr, "%d upper nodes\n", nodes.size()); chillAST_Node *uppernode = nodes[0]; - //fprintf(stderr, "upper node is %s\n", uppernode->getTypeString()); - + nodes = static_cast<CG_chillRepr*>(step)->getChillCode(); - //fprintf(stderr, "%d step nodes\n", nodes.size()); chillAST_Node *stepnode = nodes[0]; - //fprintf(stderr, "step node is %s\n", stepnode->getTypeString()); - + // unclear is this will always be the same // TODO error checking && incr vs decr chillAST_BinaryOperator *init = new chillAST_BinaryOperator( indexnode, "=", lowernode); @@ -569,18 +555,15 @@ namespace omega { // basic int, identifier gen operations //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateInt(int i) const { - fprintf(stderr, "CG_chillBuilder::CreateInt( %d )\n",i); - chillAST_IntegerLiteral *il = new chillAST_IntegerLiteral(i); // parent not available + chillAST_IntegerLiteral *il = new chillAST_IntegerLiteral(i); return new CG_chillRepr(il); } CG_outputRepr* CG_chillBuilder::CreateFloat(float f) const { - //fprintf(stderr, "CG_chillBuilder::CreateFloat( %f )\n", f); - chillAST_FloatingLiteral *fl = new chillAST_FloatingLiteral(f, 1, NULL); // parent not available + chillAST_FloatingLiteral *fl = new chillAST_FloatingLiteral(f, 1, NULL); return new CG_chillRepr(fl); } CG_outputRepr* CG_chillBuilder::CreateDouble(double d) const { - //fprintf(stderr, "CG_chillBuilder::CreateInt( %f )\n",d); - chillAST_FloatingLiteral *dl = new chillAST_FloatingLiteral(d, 1, NULL); // parent not available + chillAST_FloatingLiteral *dl = new chillAST_FloatingLiteral(d, 2, NULL); return new CG_chillRepr(dl); } @@ -594,41 +577,25 @@ namespace omega { //---------------------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateIdent(const std::string &_s) const { - fprintf(stderr, "CG_chillBuilder::CreateIdent( %s )\n", _s.c_str()); - chillAST_VarDecl* already_parameter = symbolTableFindName(symtab_, _s.c_str()); chillAST_VarDecl* already_internal = symbolTableFindName(symtab2_, _s.c_str()); - if ( already_parameter ) { - fprintf(stderr, "%s was already a parameter??\n", _s.c_str()); - } - if ( already_internal ) { - //fprintf(stderr, "%s was already defined in the function body\n", _s.c_str()); - //printSymbolTable(symtab2_); printf("dammit\n"); fflush(stdout); - } + if ( already_parameter ) + CG_DEBUG_PRINT("%s was already a parameter??\n", _s.c_str()); + if ( already_internal ) + CG_DEBUG_PRINT("%s was already defined in the function body\n", _s.c_str()); if ( (!already_parameter) && (! already_internal)) { - fprintf(stderr, "CG_roseBuilder.cc L919 adding symbol %s to symtab2_ because it was not already there\n", _s.c_str()); - - //fprintf(stderr, "parameters were: %p\n", symtab_); - //printSymbolTable( symtab_ ); - //fprintf(stderr, "\nbody symbols were: %p\n", symtab2_); - //printSymbolTable( symtab2_ ); - //fprintf(stderr, "\n\n"); - //fprintf(stderr, "there were already %d entries in body\n", symtab2_->size()); - - // this is copying roseBuilder, but is probably wrong. it is assuming + CG_DEBUG_PRINT("adding symbol %s to symtab2_ because it was not already there\n", _s.c_str()); + // this is copying roseBuilder, but is probably wrong. it is assuming // that the ident is a direct child of the current function - chillAST_VarDecl *vd = new chillAST_VarDecl( "int", _s.c_str(), "", currentfunction->getBody()); // parent not available TODO + chillAST_VarDecl *vd = new chillAST_VarDecl( "int", _s.c_str(), "", currentfunction->getBody()); currentfunction->addVariableToScope( vd ); // use symtab2_ ? chillAST_DeclRefExpr *dre = new chillAST_DeclRefExpr( "int", _s.c_str(), (chillAST_Node*)vd); // parent not available - //fprintf(stderr, "made a new chillRepr from "); dre->dump(); fflush(stdout); return new CG_chillRepr( dre ); } - - // variable was already defined as either a parameter or internal variable to the function. // NOW WHAT?? gotta return something @@ -648,72 +615,38 @@ namespace omega { //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreatePlus(CG_outputRepr *lop, CG_outputRepr *rop) const { - fprintf(stderr, "CG_chillBuilder::CreatePlus()\n"); - - - if(rop == NULL) return lop; // ?? + if (rop == NULL) return lop; else if(lop == NULL) return rop; chillAST_Node *left = ((CG_chillRepr*)lop)->chillnodes[0]; chillAST_Node *right = ((CG_chillRepr*)rop)->chillnodes[0]; - chillAST_BinaryOperator *bop = new chillAST_BinaryOperator( left, "+", right); // parent not available + chillAST_BinaryOperator *bop = new chillAST_BinaryOperator( left, "+", right); return new CG_chillRepr( bop ); - /* - Expr *lhs = static_cast<CG_chillRepr*>(lop)->GetExpression(); - Expr *rhs = static_cast<CG_chillRepr*>(rop)->GetExpression(); - - // Not sure about type!! - fprintf(stderr, "about to die in CG_chillBuilder ~line 628 CREATE PLUS\n"); - BinaryOperator *ins = new (astContext_)BinaryOperator(lhs, - rhs, - BO_Add, - lhs->getType(), // qualifyier type - VK_LValue, //Expression Value Kind, following the C++11 scheme - OK_Ordinary, // expression object kind, A further classification of the kind of object referenced by an l-value or x-value. - SourceLocation(), - false ); // fpContractable ?? - - delete lop; delete rop; - - //fprintf(stderr, " NEW binary operator 0x%x\n", ins); - fprintf(stderr, "CG_chillBuilder::CreatePlus ins 0x%x\n", ins); - return new CG_chillRepr(ins); - */ } //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateMinus(CG_outputRepr *lop, CG_outputRepr *rop) const { - //fprintf(stderr, "CG_chillBuilder::CreateMinus( lop %p rop %p)\n", lop, rop); - fprintf(stderr, "CG_chillBuilder::CreateMinus()\n"); - if(rop == NULL) { - fprintf(stderr, "CG_chillBuilder::CreateMinus(), right side is NULL\n"); - return lop; // from protonu's version. - - int *i = 0; - int j = i[0]; // segfault + CG_ERROR("right side is NULL\n"); + return lop; } CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - if(clop == NULL) { // this is really a unary operator ??? - //fprintf(stderr, "CG_chillBuilder::CreateMinus() unary\n"); - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - chillAST_UnaryOperator *ins = new chillAST_UnaryOperator("-", true, rAST->clone()); // clone? - delete crop; // ?? note: the chillRepr, not the chillAST_Node + if(clop == NULL) { + chillAST_Node *rAST = crop->chillnodes[0]; + chillAST_UnaryOperator *ins = new chillAST_UnaryOperator("-", true, rAST->clone()); + delete crop; return new CG_chillRepr(ins); } else { - //fprintf(stderr, "binary\n"); - chillAST_Node *lAST = clop->chillnodes[0]; // always just one? - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - //lAST->print(); printf(" - "); - //rAST->print(); printf("\n"); fflush(stdout); - - chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "-", rAST->clone()); // clone?? + chillAST_Node *lAST = clop->chillnodes[0]; + chillAST_Node *rAST = crop->chillnodes[0]; + + chillAST_BinaryOperator *bop = new chillAST_BinaryOperator(lAST->clone(), "-", rAST->clone()); - delete clop; delete crop; // ?? note: the chillReprs, not the chillAST_Nodes + delete clop; delete crop; return new CG_chillRepr(bop); } } @@ -722,8 +655,8 @@ namespace omega { //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateTimes(CG_outputRepr *lop, CG_outputRepr *rop) const { - fprintf(stderr, "CG_chillBuilder::CreateTimes()\n"); if (rop == NULL || lop == NULL) { + CG_ERROR("Operand for times is null\n"); if (rop != NULL) { rop->clear(); delete rop; @@ -738,18 +671,11 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_Node *lAST = clop->chillnodes[0]; // always just one? - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - - fprintf(stderr, "building "); - lAST->print(0, stderr); - fprintf(stderr, " * "); - rAST->print(0, stderr); - fprintf(stderr, "\n"); - + chillAST_Node *lAST = clop->chillnodes[0]; + chillAST_Node *rAST = crop->chillnodes[0]; + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "*", rAST); - delete lop; delete rop; // ?? - //fprintf(stderr, "CG_chillBuilder::CreateTimes() returning a CG_chillRepr with a binop inside\n"); + delete lop; delete rop; return new CG_chillRepr( binop ); } @@ -765,9 +691,8 @@ namespace omega { //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateIntegerDivide(CG_outputRepr *lop, CG_outputRepr *rop) const { - //fprintf(stderr, "CG_chillBuilder::CreatIntegerDivide()\n"); if (rop == NULL) { - fprintf(stderr, "Code generation: divide by NULL\n"); + CG_ERROR("divide by NULL\n"); return NULL; } else if ( lop == NULL ) { @@ -778,15 +703,9 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_Node *lAST = clop->chillnodes[0]; // always just one? - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - - //fprintf(stderr, "building "); - //lAST->print(0, stderr); - //fprintf(stderr, " / "); - //rAST->print(0, stderr); - //fprintf(stderr, " ??\n"); - + chillAST_Node *lAST = clop->chillnodes[0]; + chillAST_Node *rAST = crop->chillnodes[0]; + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "/", rAST); delete lop; delete rop; // ?? return new CG_chillRepr( binop ); @@ -795,20 +714,12 @@ namespace omega { //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateIntegerFloor(CG_outputRepr* lop, CG_outputRepr* rop) const { - //fprintf(stderr, "CG_chillBuilder::CreateIntegerFloor()\n"); - CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_Node *lAST = clop->chillnodes[0]; // always just one? - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - - //fprintf(stderr, "building "); - //lAST->print(0, stderr); - //fprintf(stderr, " / "); - //rAST->print(0, stderr); - //fprintf(stderr, " ??\n"); - + chillAST_Node *lAST = clop->chillnodes[0]; + chillAST_Node *rAST = crop->chillnodes[0]; + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "/", rAST); return new CG_chillRepr( binop ); } @@ -818,11 +729,7 @@ namespace omega { //----------------------------------------------------------------------------- CG_outputRepr* CG_chillBuilder::CreateIntegerMod(CG_outputRepr *lop, CG_outputRepr *rop) const { - //fprintf(stderr, "CG_chillBuilder::CreateIntegerMod() NEEDS WORK\n"); - //fprintf(stderr, "LHS "); lop->dump(); - //fprintf(stderr, "RHS "); rop->dump(); - - CG_chillRepr *l = (CG_chillRepr *) lop; + CG_chillRepr *l = (CG_chillRepr *) lop; CG_chillRepr *r = (CG_chillRepr *) rop; chillAST_Node *lhs = l->GetCode(); @@ -830,89 +737,31 @@ namespace omega { chillAST_BinaryOperator *BO = new chillAST_BinaryOperator(lhs, "%", rhs ); return new CG_chillRepr(BO); - - /* - if (rop == NULL || lop == NULL) { - return NULL; - } - - Expr *op1 = static_cast<CG_chillRepr*>(lop)->GetExpression(); - Expr *op2 = static_cast<CG_chillRepr*>(rop)->GetExpression(); - - // Not sure about type!! - fprintf(stderr, "gonna die in CG_chillBuilder.cc ~line 394\n"); - BinaryOperator *ins = NULL; // new (astContext_)BinaryOperator(op1, op2, BO_Rem, op1->getType(), SourceLocation()); - - delete lop; delete rop; - return new CG_chillRepr(ins); - */ } - - - - //----------------------------------------------------------------------------- + CG_outputRepr *CG_chillBuilder::CreateIntegerCeil(CG_outputRepr *lop, CG_outputRepr *rop) const { return CreateMinus(NULL, CreateIntegerFloor(CreateMinus(NULL, lop), rop)); } - - - - //----------------------------------------------------------------------------- - // binary logical operations - //----------------------------------------------------------------------------- + CG_outputRepr* CG_chillBuilder::CreateAnd(CG_outputRepr *lop, CG_outputRepr *rop) const { - fprintf(stderr, "CG_chillBuilder::CreateAnd()\n"); if (rop == NULL) return lop; else if (lop == NULL) return rop; - - /* if (rop == NULL || lop == NULL ) { - fprintf(stderr, "returning NULL!\n"); - return NULL; - }*/ - + CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_Node *lAST = clop->chillnodes[0]; // always just one? - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - - //fprintf(stderr, "building "); - //lAST->print(0, stderr); - //fprintf(stderr, " && "); - //rAST->print(0, stderr); - //fprintf(stderr, " ??\n"); - + chillAST_Node *lAST = clop->chillnodes[0]; + chillAST_Node *rAST = crop->chillnodes[0]; + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "&&", rAST); return new CG_chillRepr( binop ); } - - - //----------------------------------------------------------------------------- - // binary relational operations - //----------------------------------------------------------------------------- - // CG_outputRepr* CG_chillBuilder::CreateGE(CG_outputRepr *lop, // use the outputBuilder version - // CG_outputRepr *rop) const { - // - // Expr *op1 = static_cast<CG_chillRepr*>(lop)->GetExpression(); - // Expr *op2 = static_cast<CG_chillRepr*>(rop)->GetExpression(); - - // Not sure about type!! - // fprintf(stderr, "about to die in CG_chillBuilder ~line 480\n"); - - // BinaryOperator *ins = NULL; // new (astContext_)BinaryOperator(op1, op2, BO_GE, op1->getType(), SourceLocation()); - - // delete lop; delete rop; - // return new CG_chillRepr(ins); - // } - - - //----------------------------------------------------------------------------- + CG_outputRepr* CG_chillBuilder::CreateLE(CG_outputRepr *lop, CG_outputRepr *rop) const { - //fprintf(stderr, "CG_chillBuilder::CreateLE()\n"); if (rop == NULL || lop == NULL) { return NULL; } @@ -920,15 +769,9 @@ namespace omega { CG_chillRepr *clop = (CG_chillRepr *) lop; CG_chillRepr *crop = (CG_chillRepr *) rop; - chillAST_Node *lAST = clop->chillnodes[0]; // always just one? - chillAST_Node *rAST = crop->chillnodes[0]; // always just one? - - //fprintf(stderr, "building "); - //lAST->print(0, stderr); - //fprintf(stderr, " <= "); - //rAST->print(0, stderr); - //fprintf(stderr, " ??\n"); - + chillAST_Node *lAST = clop->chillnodes[0]; + chillAST_Node *rAST = crop->chillnodes[0]; + chillAST_BinaryOperator *binop = new chillAST_BinaryOperator( lAST, "<=", rAST); delete lop; delete rop; // ?? return new CG_chillRepr( binop ); diff --git a/lib/codegen/src/CG.cc b/lib/codegen/src/CG.cc index 5d903c4..3b46c72 100755 --- a/lib/codegen/src/CG.cc +++ b/lib/codegen/src/CG.cc @@ -34,6 +34,7 @@ #include <code_gen/codegen_error.h> #include <stack> #include <string.h> +#include <code_gen/CGdebug.h> namespace omega { @@ -55,7 +56,6 @@ namespace omega { const std::vector<CG_outputRepr *> &stmts, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > uninterpreted_symbols, bool printString) const { - fprintf(stderr, "\nCG_result::printRepr(ocg, stmts) \n"); //Anand: making a tweak to allocate twice the original number of dynamically allocated variables //for use with Uninterpreted function symbols @@ -67,7 +67,7 @@ namespace omega { int num_unin = uninterpreted_symbols.size(); int num_active = active_.size(); if (num_unin < num_active) { - fprintf(stderr, "CG.cc CG_result::printRepr(), not enough uninterpreted symbols (%d) for active statements (5d)\n", num_unin, num_active); + CG_ERROR("not enough uninterpreted symbols (%d) for active statements (%d)\n", num_unin, num_active); exit(-1); } @@ -80,7 +80,6 @@ namespace omega { int num_levels = num_level(); for (int s = 0; s < active_.size(); s++) { - fprintf(stderr, "\ns %d\n", s); std::vector<std::string> loop_vars; if (active_.get(s)) { @@ -166,8 +165,6 @@ namespace omega { //--end #endif - - fprintf(stderr, "\n\n\n\nprintRepr recursing ??? return printRepr( ... )\n"); return printRepr(1, ocg, stmts, aotf, uninterpreted_symbols, printString); } @@ -176,11 +173,9 @@ namespace omega { std::string CG_result::printString( std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > uninterpreted_symbols) const { - fprintf(stderr, "CG.cc line 164, CG_result::printString()\n"); CG_stringBuilder ocg; std::vector<CG_outputRepr *> stmts(codegen_->xforms_.size()); - fprintf(stderr, "stmts.size() %d\n", stmts.size()); for (int i = 0; i < stmts.size(); i++) stmts[i] = new CG_stringRepr("s" + to_string(i)); @@ -194,7 +189,6 @@ namespace omega { if (repr != NULL) { std::string s = repr->GetString(); - //fprintf(stderr, "\nCG.cc L197 repr->GetString() = '%s'\n\n\n", s.c_str()); delete repr; return s; } else @@ -313,7 +307,7 @@ namespace omega { std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString) const { - fprintf(stderr, "CG_split::printRepr()\n"); + CG_DEBUG_PRINT("CG_split::printRepr()\n"); int numfly = assigned_on_the_fly.size(); //fprintf(stderr, "assigned on the fly %d\n", numfly ); //for (int i=0; i<numfly; i++) { @@ -377,7 +371,6 @@ namespace omega { } CG_result *CG_split::clone() const { - //fprintf(stderr, "CG_split::clone()\n"); std::vector<CG_result *> clauses(clauses_.size()); for (int i = 0; i < clauses_.size(); i++) clauses[i] = clauses_[i]->clone(); @@ -478,7 +471,7 @@ namespace omega { } // loop iterates more than once, extract bounds now else { - fprintf(stderr, "loop iterates more than once, extract bounds now\n"); + CG_DEBUG_PRINT("loop iterates more than once, extract bounds now\n"); needLoop_ = true; bounds_ = Relation(hull.n_set()); @@ -1100,8 +1093,6 @@ namespace omega { const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString) const { - - fprintf(stderr, "CG_loop::printRepr() w assigned_on_the_fly gonna call printRepr with more arguments\n"); //int numfly = assigned_on_the_fly.size(); //fprintf(stderr, "assigned on the fly %d\n", numfly ); //for (int i=0; i<numfly; i++) { @@ -1112,7 +1103,6 @@ namespace omega { // int val = p.second; // //fprintf(stderr, "0x%x %d\n", tr, val); //} - return printRepr(true, indent, ocg, stmts, assigned_on_the_fly, unin, printString); } @@ -1125,19 +1115,12 @@ namespace omega { CG_outputBuilder *ocg, const std::vector<CG_outputRepr *> &stmts, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString) const { - fprintf(stderr, "\n*** CG.cc CG_loop printrepr with more arguments\n"); - - - // debugging output - int numfly = assigned_on_the_fly.size(); - fprintf(stderr, "assigned on the fly %d\n", numfly ); // Anand makes twice as many - for (int i=0; i<numfly; i++) { - //fprintf(stderr, "i %d\n", i); + int numfly = assigned_on_the_fly.size(); // Anand makes twice as many + for (int i=0; i<numfly; i++) { std::pair<CG_outputRepr *, int>p = assigned_on_the_fly[i]; CG_outputRepr *tr = NULL; if (p.first != NULL) tr = p.first->clone(); int val = p.second; - //fprintf(stderr, "0x%x %d\n", tr, val); } //Anand: adding support for Replacing substituted variables within @@ -1157,36 +1140,24 @@ namespace omega { else guardRepr = NULL; - fprintf(stderr, "after guard assigned on the fly %d\n", numfly ); - for (int i=0; i<numfly; i++) { - //fprintf(stderr, "i %d\n", i); + for (int i=0; i<numfly; i++) { std::pair<CG_outputRepr *, int>p = assigned_on_the_fly[i]; CG_outputRepr *tr = NULL; if (p.first != NULL) tr = p.first->clone(); int val = p.second; - //fprintf(stderr, "0x%x %d\n", tr, val); } - fprintf(stderr, "done flying\n"); Relation cur_known = Intersection(copy(known_), copy(guard_)); cur_known.simplify(); - fprintf(stderr, "checking needloop\n"); if (needLoop_) { - fprintf(stderr, "needLoop_\n"); - if (checkLoopLevel) if (level_ == checkLoopLevel) if (active_.get(stmtForLoopCheck)) fillInBounds = true; - - fprintf(stderr, "ctrlRepr = output_loop()\n"); CG_outputRepr *ctrlRepr = output_loop(ocg, bounds_, level_, cur_known, aotf, unin[stmt_num]); - fillInBounds = false; - - fprintf(stderr, "in needLoop_ bodyrepr = \n"); int ind = (guardRepr == NULL) ? indent + 1 : indent + 2; CG_outputRepr *bodyRepr = body_->printRepr(ind, ocg, @@ -1203,7 +1174,6 @@ namespace omega { if (!smtNonSplitLevels.empty()) { - fprintf(stderr, "!smtNonSplitLevels.empty()\n"); bool blockLoop = false; bool threadLoop = false; bool sync = false; @@ -1231,24 +1201,24 @@ namespace omega { } } if (blockLoop && threadLoop) { - fprintf(stderr, - "Warning, have %d level more than once in smtNonSplitLevels\n", - level_); + CG_DEBUG_PRINT("Warning, have %d level more than once in smtNonSplitLevels\n", level_); threadLoop = false; } std::string preferredIdx; - fprintf(stderr, "loopIdxNames.size() %d\n", loopIdxNames.size()); - for (int i=0; i<loopIdxNames.size(); i++) { - fprintf(stderr, "\n"); - for (int j=0; j<loopIdxNames[i].size(); j++) { - fprintf(stderr, "i %d j %d %s\n", i, j,loopIdxNames[i][j].c_str() ); + CG_DEBUG_BEGIN + fprintf(stderr, "loopIdxNames.size() %d\n", loopIdxNames.size()); + for (int i=0; i<loopIdxNames.size(); i++) { + fprintf(stderr, "\n"); + for (int j=0; j<loopIdxNames[i].size(); j++) { + fprintf(stderr, "i %d j %d %s\n", i, j,loopIdxNames[i][j].c_str() ); + } } - } - fprintf(stderr, "firstActiveStmt %d\n", firstActiveStmt); - fprintf(stderr, "loopIdxNames[firstActiveStmt].size() %d\n", loopIdxNames[firstActiveStmt].size()); - fprintf(stderr, "level_ %d /2 %d\n", level_, level_/2); + fprintf(stderr, "firstActiveStmt %d\n", firstActiveStmt); + fprintf(stderr, "loopIdxNames[firstActiveStmt].size() %d\n", loopIdxNames[firstActiveStmt].size()); + fprintf(stderr, "level_ %d /2 %d\n", level_, level_/2); + CG_DEBUG_END if (loopIdxNames.size() && (level_ / 2) - 1 < loopIdxNames[firstActiveStmt].size()) { @@ -1306,40 +1276,23 @@ namespace omega { return ocg->CreateIf(indent, guardRepr, loopRepr, NULL); } else { - fprintf(stderr, "NOT needloop_\n"); - + CG_DEBUG_PRINT("NOT needloop_\n"); std::pair<CG_outputRepr *, std::pair<CG_outputRepr *, int> > result = output_assignment(ocg, bounds_, level_, cur_known, aotf, unin[stmt_num]); - - //fprintf(stderr, "RESULT 0x%x 0x%x %d\n", result.first, result.second.first, result.second.second ); - - guardRepr = ocg->CreateAnd(guardRepr, result.first); - //fprintf(stderr, "RESULT 0x%x 0x%x %d\n", result.first, result.second.first, result.second.second ); - - //fprintf(stderr, "after guardRepr assigned on the fly %d\n", numfly ); - for (int i=0; i<numfly; i++) { - //fprintf(stderr, "i %d\n", i); + for (int i=0; i<numfly; i++) { std::pair<CG_outputRepr *, int>p = assigned_on_the_fly[i]; CG_outputRepr *tr = NULL; if (p.first != NULL) tr = p.first->clone(); int val = p.second; - //fprintf(stderr, "0x%x %d\n", tr, val); - } - - + } if (result.second.second < CodeGen::var_substitution_threshold) { - //fprintf(stderr, "var_substitution_threshold %d < %d level_ = %d\n", result.second.second, CodeGen::var_substitution_threshold, level_); std::vector<std::pair<CG_outputRepr *, int> > aotf = assigned_on_the_fly; aotf[level_ - 1] = result.second; - //fprintf(stderr, "RESULT 0x%x second 0x%x %d\n", result.first, result.second.first, result.second.second ); - if(!printString) { for (std::map<std::string, std::vector<CG_outputRepr *> >::iterator i = unin[stmt_num].begin(); i != unin[stmt_num].end(); i++) { - - std::vector<CG_outputRepr *> to_push; for (int j = 0; j < i->second.size(); j++) { std::string index = @@ -1356,18 +1309,13 @@ namespace omega { } // for } // if - //fprintf(stderr, "aotf !!\n"); - for (int i=0; i<numfly; i++) { - //fprintf(stderr, "i %d\n", i); + for (int i=0; i<numfly; i++) { std::pair<CG_outputRepr *, int>p = aotf[i]; CG_outputRepr *tr = NULL; if (p.first != NULL) { tr = p.first->clone(); } int val = p.second; } - - //fprintf(stderr, "\nbodyRepr =\n"); - //body_->dump(); // this dies - int ind = (guardRepr == NULL) ? indent : indent + 1; + int ind = (guardRepr == NULL) ? indent : indent + 1; CG_outputRepr *bodyRepr = body_->printRepr(ind, ocg, stmts, aotf, unin, printString); @@ -1377,7 +1325,6 @@ namespace omega { else return ocg->CreateIf(indent, guardRepr, bodyRepr, NULL); } else { - //fprintf(stderr, "NOT var_substitution_threshold gonna call output_ident()\n"); int ind = (guardRepr == NULL) ? indent : indent + 1; CG_outputRepr *assignRepr = ocg->CreateAssignment( ind, @@ -1394,102 +1341,6 @@ namespace omega { else return ocg->CreateIf(indent, guardRepr, ocg->StmtListAppend(assignRepr, bodyRepr), NULL); - - /* DEAD CODE - std::pair<EQ_Handle, int> result_ = find_simplest_assignment( - copy(bounds_), copy(bounds_).set_var(level_), - assigned_on_the_fly); - bool found_func = false; - Variable_ID v2; - int arity; - for (Constr_Vars_Iter cvi(result_.first); cvi; cvi++) - if (cvi.curr_var()->kind() == Global_Var) { - Global_Var_ID g = cvi.curr_var()->get_global_var(); - if ((g->arity() > 0)) { - - found_func = true; - arity = g->arity(); - //copy(R).print(); - v2 = copy(bounds_).get_local(g, - cvi.curr_var()->function_of()); - - break; - } - } - - bool is_array = false; - if (found_func) { - - is_array = ocg->QueryInspectorType( - v2->get_global_var()->base_name()); - - } - if (!found_func || !is_array) { - - CG_outputRepr *assignRepr = ocg->CreateAssignment( - (guardRepr == NULL) ? indent : indent + 1, - output_ident(ocg, bounds_, - const_cast<CG_loop *>(this)->bounds_.set_var( - level_), assigned_on_the_fly), - result.second.first); - - CG_outputRepr *bodyRepr = body_->printRepr( - (guardRepr == NULL) ? indent : indent + 1, ocg, stmts, - assigned_on_the_fly); - if (guardRepr == NULL) - return ocg->StmtListAppend(assignRepr, bodyRepr); - else - return ocg->CreateIf(indent, guardRepr, - ocg->StmtListAppend(assignRepr, bodyRepr), NULL); - - } else { - - std::vector<CG_outputRepr *> index_expr; - - CG_outputRepr* lb = ocg->CreateArrayRefExpression( - v2->get_global_var()->base_name(), - output_ident(ocg, bounds_, - const_cast<CG_loop *>(this)->bounds_.set_var(2), - assigned_on_the_fly)); - - for (int i = arity; i > 1; i--) { - - index_expr.push_back( - ocg->CreateArrayRefExpression( - v2->get_global_var()->base_name(), - output_ident(ocg, bounds_, - const_cast<CG_loop *>(this)->bounds_.set_var( - 2 * i), - assigned_on_the_fly))); - - //} - - } - - CG_outputRepr *ub; - if (index_expr.size() > 1) - ub = ocg->CreateInvoke("max", index_expr); - else - ub = index_expr[0]; - CG_outputRepr *le = ocg->CreateMinus(ub, ocg->CreateInt(1)); - CG_outputRepr *inductive = ocg->CreateInductive( - output_ident(ocg, bounds_, - const_cast<CG_loop *>(this)->bounds_.set_var( - level_), assigned_on_the_fly), lb, le, - NULL); - - CG_outputRepr *bodyRepr = body_->printRepr( - (guardRepr == NULL) ? indent : indent + 1, ocg, stmts, - assigned_on_the_fly); - - if (guardRepr == NULL) { - return ocg->CreateLoop(indent, inductive, bodyRepr); - } else - return ocg->CreateIf(indent, guardRepr, - ocg->CreateLoop(indent + 1, inductive, bodyRepr), - NULL); - } - */ } } } @@ -1531,7 +1382,6 @@ namespace omega { CG_result *CG_loop::clone() const { - //fprintf(stderr, "CG_loop::clone()\n"); return new CG_loop(codegen_, active_, level_, body_->clone()); } @@ -1658,16 +1508,12 @@ namespace omega { const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin, bool printString) const { - fprintf(stderr, "CG_leaf::printRepr()\n"); int numfly = assigned_on_the_fly.size(); - //fprintf(stderr, "assigned on the fly %d\n", numfly ); - for (int i=0; i<numfly; i++) { - //fprintf(stderr, "i %d\n", i); + for (int i=0; i<numfly; i++) { std::pair<CG_outputRepr *, int>p = assigned_on_the_fly[i]; CG_outputRepr *tr = NULL; if (p.first != NULL) tr = p.first->clone(); int val = p.second; - //fprintf(stderr, "0x%x %d\n", tr, val); } return leaf_print_repr(active_, guards_, NULL, known_, indent, ocg, @@ -1678,7 +1524,6 @@ namespace omega { CG_result *CG_leaf::clone() const { - //fprintf(stderr, "CG_leaf::clone()\n"); return new CG_leaf(codegen_, active_); } diff --git a/lib/codegen/src/CG_utils.cc b/lib/codegen/src/CG_utils.cc index 19bb6c9..95f94ec 100755 --- a/lib/codegen/src/CG_utils.cc +++ b/lib/codegen/src/CG_utils.cc @@ -22,6 +22,7 @@ #include <code_gen/codegen_error.h> #include <math.h> #include <stack> +#include <code_gen/CGdebug.h> namespace omega { @@ -274,36 +275,29 @@ namespace omega { Variable_ID v, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin) { - fprintf(stderr, "output_ident( %s )\n", v->name().c_str()); + CG_DEBUG_PRINT("output_ident( %s )\n", v->name().c_str()); const_cast<Relation &>(R).setup_names(); // hack if (v->kind() == Input_Var) { int pos = v->get_position(); if (assigned_on_the_fly[pos - 1].first != NULL) { - //fprintf(stderr, "on the fly pos=%d\n", pos); CG_outputRepr *tmp = assigned_on_the_fly[pos-1].first->clone(); - //fprintf(stderr, "tmp on the fly (0x%x)\n", tmp); return tmp; } else { - //fprintf(stderr, "creating Ident for %s\n", v->name().c_str()); CG_outputRepr *tmp = ocg->CreateIdent(v->name()); - //fprintf(stderr, "ident created for %s\n", v->name().c_str()); return tmp; } } else if (v->kind() == Global_Var) { - //fprintf(stderr, "CG_utils.cc output_ident() Global_Var\n"); if (v->get_global_var()->arity() == 0) { - //fprintf(stderr, "arity 0\n"); return ocg->CreateIdent(v->name()); } else { /* This should be improved to take into account the possible elimination of the set variables. */ int arity = v->get_global_var()->arity(); - //fprintf(stderr, "arity %dn", arity ); std::vector<CG_outputRepr *> argList; if (unin.find(v->get_global_var()->base_name()) != unin.end()) { @@ -363,19 +357,14 @@ namespace omega { const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin) { - //fprintf(stderr, "output_assignment( )\n"); int numfly = assigned_on_the_fly.size(); - //fprintf(stderr, "assigned on the fly %d\n", numfly ); - for (int i=0; i<numfly; i++) { - //fprintf(stderr, "i %d\n", i); + for (int i=0; i<numfly; i++) { std::pair<CG_outputRepr *, int>p = assigned_on_the_fly[i]; CG_outputRepr *tr = NULL; if (p.first != NULL) tr = p.first->clone(); int val = p.second; - //fprintf(stderr, "0x%x %d\n", tr, val); } - - + Variable_ID v = const_cast<Relation &>(R).set_var(level); Conjunct *c = const_cast<Relation &>(R).single_conjunct(); @@ -650,9 +639,6 @@ namespace omega { const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin) { std::vector<CG_outputRepr *> subs; - - fprintf(stderr, "CG_utils.cc output_substitutions()\n"); - for (int i = 1; i <= R.n_out(); i++) { Relation mapping(R.n_out(), 1); F_And *f_root = mapping.add_and(); @@ -665,16 +651,13 @@ namespace omega { Variable_ID v = r.output_var(1); CG_outputRepr *repr = NULL; - fprintf(stderr, "v %s\n", v->char_name()); std::pair<EQ_Handle, int> result = find_simplest_assignment(r, v, assigned_on_the_fly); if (result.second < INT_MAX) { - //fprintf(stderr, "output_substitutions() calling output_substitution_repr()\n"); - repr = output_substitution_repr(ocg, result.first, v, true, r, + repr = output_substitution_repr(ocg, result.first, v, true, r, assigned_on_the_fly, unin); - if (repr == NULL) fprintf(stderr, "IN IF, repr for %s assigned NULL\n", v->char_name()); + if (repr == NULL) CG_ERROR("IN IF, repr for %s assigned NULL\n", v->char_name()); } else { - //fprintf(stderr, "else\n"); std::pair<bool, GEQ_Handle> result = find_floor_definition(R, v); if (result.first) try { @@ -685,7 +668,7 @@ namespace omega { } } - if (repr == NULL) fprintf(stderr, "repr NULL\n"); + if (repr == NULL) CG_ERROR("repr NULL\n"); if (repr != NULL) { subs.push_back(repr); } @@ -699,7 +682,7 @@ namespace omega { //h.update_coef(mapping1.input_var(i), -1); //Relation r = Composition(mapping1, copy(mapping)); //r.simplify(); - + Relation r = copy(R); Variable_ID v = r.output_var(k); @@ -718,7 +701,7 @@ namespace omega { Variable_ID v1 = cvi.curr_var(); if (v1->kind() == Input_Var) variables.push_back(v1); - + } */ repr_ = output_substitution_repr(ocg, result.first, v, true, @@ -839,8 +822,6 @@ namespace omega { } // for int k } } - - fprintf(stderr, "CG_utils.cc output_substitutions() DONE\n\n"); return subs; } @@ -1195,7 +1176,6 @@ namespace omega { const Relation &R, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin) { - fprintf(stderr, "output_guard()\n"); assert(R.n_out()==0); CG_outputRepr *result = NULL; @@ -1204,7 +1184,6 @@ namespace omega { // e.g. 4i=5*j for (EQ_Iterator e = c->EQs(); e; e++) if (!(*e).has_wildcards()) { - //fprintf(stderr, "EQ\n"); CG_outputRepr *lhs = NULL; CG_outputRepr *rhs = NULL; for (Constr_Vars_Iter cvi(*e); cvi; cvi++) { @@ -1509,8 +1488,6 @@ namespace omega { const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin, std::set<Variable_ID> excluded_floor_vars) { - fprintf(stderr, "output_inequality_repr() v %s\n", v->name().c_str()); - const_cast<Relation &>(R).setup_names(); // hack coef_t a = inequality.get_coef(v); @@ -1527,12 +1504,9 @@ namespace omega { cvi.curr_var(), excluded_floor_vars); if (!result.first) { - fprintf(stderr, "\n\n*** heading into NEW CODE\n"); - coef_t coef_ = cvi.curr_coef(); result2 = find_floor_definition_temp(R, cvi.curr_var(), excluded_floor_vars); - for (Constr_Vars_Iter cvi_( result2[result2.size() - 1].second); cvi_; cvi_++) { if (cvi_.curr_var()->kind() != Wildcard_Var @@ -1545,8 +1519,6 @@ namespace omega { ocg->CreateInt(-coef_)); repr = ocg->CreateTimes(ocg->CreateInt(-coef_), repr); - - fprintf(stderr, "returning a TIMES\n"); return repr; } @@ -1667,8 +1639,6 @@ namespace omega { const Relation &known, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin) { - - fprintf(stderr, "output_lower_bound_repr()\n"); assert(inequality.get_coef(v) > 0); CG_outputRepr* zero_; if (wc == NULL @@ -1772,11 +1742,7 @@ namespace omega { const Relation &known, const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::map<std::string, std::vector<CG_outputRepr *> > unin) { - - fprintf(stderr, "CG_utils.cc output_loop()\n"); std::pair<EQ_Handle, Variable_ID> result = find_simplest_stride(R, const_cast<Relation &>(R).set_var(level)); - fprintf(stderr, "found stride\n"); - if (result.second != NULL) assert(abs(result.first.get_coef(const_cast<Relation &>(R).set_var(level))) == 1); @@ -1788,19 +1754,14 @@ namespace omega { for (GEQ_Iterator e(const_cast<Relation &>(R).single_conjunct()->GEQs()); e; e++) { - fprintf(stderr, "new e\n"); coef_t coef = (*e).get_coef(const_cast<Relation &>(R).set_var(level)); - - fprintf(stderr, "coef %d\n", coef); if (coef > 0) { CG_outputRepr *repr = output_lower_bound_repr(ocg, *e, const_cast<Relation &>(R).set_var(level), result.first, result.second, R, known, assigned_on_the_fly, unin); - fprintf(stderr, "got a repr\n"); - if (repr == NULL) fprintf(stderr, "repr NULL\n"); - - if (repr == NULL) + if (repr == NULL) { + CG_ERROR("NULL lowerbound, assumed zero\n"); repr = ocg->CreateInt(0); + } lbList.push_back(repr); - if ((*e).is_const(const_cast<Relation &>(R).set_var(level))){ if(!result.second) { @@ -2604,10 +2565,6 @@ namespace omega { const std::vector<std::pair<CG_outputRepr *, int> > &assigned_on_the_fly, std::vector<std::map<std::string, std::vector<CG_outputRepr *> > > unin) { - fprintf(stderr, "loop_print_repr() guard_repr "); - if (guard_repr == NULL) fprintf(stderr, "NULL\n"); - else fprintf(stderr, "NOT NULL\n"); - if (start >= end) return NULL; @@ -2628,9 +2585,7 @@ namespace omega { stmts, assigned_on_the_fly, unin)); - - fprintf(stderr,"CG_utils.cc loop_print_repr recursive\n"); - stmt_list = ocg->StmtListAppend(stmt_list, + stmt_list = ocg->StmtListAppend(stmt_list, loop_print_repr(active, loops, i, @@ -2644,12 +2599,9 @@ namespace omega { stmts, assigned_on_the_fly, unin)); - - //fprintf(stderr, "guard_repr 0x%x\n", guard_repr); if (guard_repr == NULL) return stmt_list; else { - fprintf(stderr, "CG_utils.cc loop_print_repr() CreateIf()\n"); return ocg->CreateIf(indent, guard_repr, stmt_list, NULL); } } @@ -2682,8 +2634,7 @@ namespace omega { guard_repr = ocg->CreateAnd(guard_repr, new_guard_repr); Relation new_guard = Intersection(copy(guard), copy(then_cond)); new_guard.simplify(); - fprintf(stderr,"CG_utils.cc loop_print_repr recursive 2\n"); - return loop_print_repr(active, loops, start, end, new_guard, guard_repr, + return loop_print_repr(active, loops, start, end, new_guard, guard_repr, indent, remap, xforms, ocg, stmts, aotf, unin); } else if (j == i && end > j) { @@ -2694,9 +2645,7 @@ namespace omega { new_guard.simplify(); new_guard.print(stderr); new_guard.print_with_subs(stderr); - - fprintf(stderr,"CG_utils.cc loop_print_repr recursive 3\n"); - CG_outputRepr *stmt_list = loop_print_repr(active, + CG_outputRepr *stmt_list = loop_print_repr(active, loops, start, i, @@ -2709,9 +2658,7 @@ namespace omega { stmts, aotf, unin); - - fprintf(stderr,"CG_utils.cc loop_print_repr recursive 4\n"); - stmt_list = ocg->StmtListAppend(stmt_list, + stmt_list = ocg->StmtListAppend(stmt_list, loop_print_repr(active, loops, j, @@ -2729,7 +2676,6 @@ namespace omega { if (guard_repr == NULL) return stmt_list; else { - fprintf(stderr, "CG_utils.cc loop_print_repr() CreateIf() 2\n"); return ocg->CreateIf(indent, guard_repr, stmt_list, NULL); } } @@ -2737,8 +2683,6 @@ namespace omega { int new_indent = (guard_repr==NULL)?indent:indent+1; Relation then_new_guard = Intersection(copy(guard), copy(then_cond)); then_new_guard.simplify(); - - fprintf(stderr,"CG_utils.cc loop_print_repr recursive 5\n"); CG_outputRepr *then_stmt_list = loop_print_repr(active, loops, start, @@ -2755,8 +2699,6 @@ namespace omega { Relation else_new_guard = Intersection(copy(guard), copy(else_cond)); else_new_guard.simplify(); - - fprintf(stderr,"CG_utils.cc loop_print_repr recursive 6\n"); CG_outputRepr *else_stmt_list = loop_print_repr(active, loops, i, @@ -2770,15 +2712,11 @@ namespace omega { stmts, aotf, unin); - - fprintf(stderr, "CG_utils.cc loop_print_repr() CreateIf() 3\n"); - CG_outputRepr *stmt_list = ocg->CreateIf(new_indent, + CG_outputRepr *stmt_list = ocg->CreateIf(new_indent, new_guard_repr, then_stmt_list, else_stmt_list); - - fprintf(stderr,"CG_utils.cc loop_print_repr recursive 7\n"); - stmt_list = ocg->StmtListAppend(stmt_list, + stmt_list = ocg->StmtListAppend(stmt_list, loop_print_repr(active, loops, j, @@ -2797,7 +2735,6 @@ namespace omega { if (guard_repr == NULL) return stmt_list; else { - fprintf(stderr, "CG_utils.cc loop_print_repr() CreateIf() 4\n"); return ocg->CreateIf(indent, guard_repr, stmt_list, NULL); } } diff --git a/src/chillASTs.cc b/src/chillASTs.cc index 5eed0fe..2711bb0 100644 --- a/src/chillASTs.cc +++ b/src/chillASTs.cc @@ -1,6 +1,3 @@ - - - #include <chilldebug.h> #include <stack> #include <fstream> diff --git a/src/ir_clang.cc b/src/ir_clang.cc index 671f195..5a14a63 100755 --- a/src/ir_clang.cc +++ b/src/ir_clang.cc @@ -1041,41 +1041,28 @@ bool IR_chillArrayRef::is_write() const { // TODO omega::CG_outputRepr *IR_chillArrayRef::index(int dim) const { - fprintf(stderr, "IR_xxxxArrayRef::index( %d ) \n", dim); - //chillASE->print(); printf("\n"); fflush(stdout); - //chillASE->getIndex(dim)->print(); printf("\n"); fflush(stdout); return new omega::CG_chillRepr(chillASE->getIndex(dim)); } IR_ArraySymbol *IR_chillArrayRef::symbol() const { - //fprintf(stderr, "IR_chillArrayRef::symbol()\n"); - //chillASE->print(); printf("\n"); fflush(stdout); - //fprintf(stderr, "base: "); chillASE->base->print(); printf("\n"); fflush(stdout); - - chillAST_Node *mb = chillASE->multibase(); chillAST_VarDecl *vd = (chillAST_VarDecl *) mb; - //fprintf(stderr, "symbol: '%s'\n", vd->varname); - - //fprintf(stderr, "IR_chillArrayRef symbol: '%s%s'\n", vd->varname, vd->arraypart); - //fprintf(stderr, "numdimensions %d\n", vd->numdimensions); IR_ArraySymbol *AS = new IR_chillArraySymbol(ir_, vd); - //fprintf(stderr, "ir_clang.cc returning IR_chillArraySymbol 0x%x\n", AS); return AS; /* chillAST_Node *b = chillASE->base; - fprintf(stderr, "base of type %s\n", b->getTypeString()); - //b->print(); printf("\n"); fflush(stdout); + fprintf(stderr, "base of type %s\n", b->getTypeString()); + //b->print(); printf("\n"); fflush(stdout); if (b->getType() == CHILLAST_NODE_IMPLICITCASTEXPR) { b = ((chillAST_ImplicitCastExpr*)b)->subexpr; - fprintf(stderr, "base of type %s\n", b->getTypeString()); + fprintf(stderr, "base of type %s\n", b->getTypeString()); } - + if (b->getType() == CHILLAST_NODE_DECLREFEXPR) { - if (NULL == ((chillAST_DeclRefExpr*)b)->decl) { - fprintf(stderr, "IR_chillArrayRef::symbol() var decl = 0x%x\n", ((chillAST_DeclRefExpr*)b)->decl); - exit(-1); + if (NULL == ((chillAST_DeclRefExpr*)b)->decl) { + fprintf(stderr, "IR_chillArrayRef::symbol() var decl = 0x%x\n", ((chillAST_DeclRefExpr*)b)->decl); + exit(-1); } return new IR_chillArraySymbol(ir_, ((chillAST_DeclRefExpr*)b)->decl); // -> decl? } @@ -1083,26 +1070,21 @@ IR_ArraySymbol *IR_chillArrayRef::symbol() const { return ( } fprintf(stderr, "IR_chillArrayRef::symbol() can't handle\n"); - fprintf(stderr, "base of type %s\n", b->getTypeString()); - exit(-1); - return NULL; + fprintf(stderr, "base of type %s\n", b->getTypeString()); + exit(-1); + return NULL; */ } bool IR_chillArrayRef::operator!=(const IR_Ref &that) const { - //fprintf(stderr, "IR_xxxxArrayRef::operator!=\n"); bool op = (*this) == that; // opposite return !op; } bool IR_chillArrayRef::operator==(const IR_Ref &that) const { - //fprintf(stderr, "IR_xxxxArrayRef::operator==\n"); - //printf("I am\n"); chillASE->print(); printf("\n"); const IR_chillArrayRef *l_that = static_cast<const IR_chillArrayRef *>(&that); const chillAST_ArraySubscriptExpr *thatASE = l_that->chillASE; - //printf("other is:\n"); thatASE->print(); printf("\n"); fflush(stdout); - //fprintf(stderr, "addresses are 0x%x 0x%x\n", chillASE, thatASE ); return (*chillASE) == (*thatASE); /* @@ -1117,7 +1099,6 @@ bool IR_chillArrayRef::operator==(const IR_Ref &that) const { omega::CG_outputRepr *IR_chillArrayRef::convert() { - //fprintf(stderr, "IR_chillArrayRef::convert()\n"); CG_chillRepr *result = new CG_chillRepr(chillASE->clone()); // omega::CG_chillRepr *temp = new omega::CG_chillRepr(static_cast<Expr*>(this->as_)); // omega::CG_outputRepr *result = temp->clone(); @@ -1163,9 +1144,6 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { chillAST_Node *inc = chillforstmt->getInc(); // check the increment - //fprintf(stderr, "increment is of type %s\n", inc->getTypeString()); - //inc->print(); printf("\n"); fflush(stdout); - if (inc->getType() == CHILLAST_NODE_UNARYOPERATOR) { if (!strcmp(((chillAST_UnaryOperator *) inc)->op, "++")) step_size_ = 1; else step_size_ = -1; @@ -1177,7 +1155,6 @@ IR_chillLoop::IR_chillLoop(const IR_Code *ir, chillAST_ForStmt *achillforstmt) { // TODO looks like this will fail for I=1+I or I=J+1 etc. do more checking char *assop = bop->getOp(); - //fprintf(stderr, "'%s' is an assignment op\n", bop->getOp()); if (!strcmp(assop, "+=") || !strcmp(assop, "-=")) { chillAST_Node *stride = rhs; //fprintf(stderr, "stride is of type %s\n", stride->getTypeString()); @@ -1286,16 +1263,8 @@ omega::CG_outputRepr *IR_chillBlock::original() const { omega::CG_outputRepr *IR_chillBlock::extract() const { - fflush(stdout); - fprintf(stderr, "IR_xxxxBlock::extract()\n"); - //omega::CG_chillRepr *tnl = new omega::CG_chillRepr(getStmtList()); - // if the block refers to a compound statement, return the next level // of statements ; otherwise just return a repr of the statements - - //if (chillAST != NULL) fprintf(stderr, "block has chillAST of type %s\n",code->getTypeString()); - //fprintf(stderr, "block has %d exploded statements\n", statements.size()); - omega::CG_chillRepr *OR; CHILL_DEBUG_PRINT("adding a statement from IR_chillBlock::extract()\n"); OR = new omega::CG_chillRepr(); // empty of statements @@ -1306,18 +1275,17 @@ omega::CG_outputRepr *IR_chillBlock::extract() const { IR_Control *IR_chillBlock::clone() const { CHILL_DEBUG_PRINT("IR_xxxxBlock::clone()\n"); - //fprintf(stderr, "IR_xxxxBlock::clone() %d statements\n", statements.size()); return new IR_chillBlock(this); // shallow copy ? } void IR_chillBlock::dump() const { - fprintf(stderr, "IR_chillBlock::dump() TODO\n"); + CHILL_DEBUG_PRINT("IR_chillBlock::dump() TODO\n"); return; } //StmtList vector<chillAST_Node *> IR_chillBlock::getStmtList() const { - fprintf(stderr, "IR_xxxxBlock::getStmtList()\n"); + CHILL_DEBUG_PRINT("IR_xxxxBlock::getStmtList()\n"); return statements; // ?? } @@ -1326,52 +1294,19 @@ void IR_chillBlock::addStatement(chillAST_Node *s) { statements.push_back(s); } - -void PrintTranslationUnit(TranslationUnitDecl *TUD) { // , ASTContext &CTX ) { - fprintf(stderr, "MY PrintTranslationUnit()\n"); - // TUD derived from Decl and DeclContext - static DeclContext *DC = TUD->castToDeclContext(TUD); - //SourceManager SM = CTX.getSourceManager(); - - for (DeclContext::decl_iterator DI = DC->decls_begin(), DE = DC->decls_end(); DI != DE; ++DI) { - Decl *D = *DI; - fprintf(stderr, "D\n"); - if (isa<FunctionDecl>(D)) { - fprintf(stderr, "FunctionDecl\n"); - //PrintFunctionDecl( dyn_cast<FunctionDecl>(D), CTX.getSourceManager(), 0); - } else if (isa<VarDecl>(D)) { - fprintf(stderr, "VarDecl\n"); - //PrintVarDecl( dyn_cast<VarDecl>(D), CTX.getSourceManager(), 0 ); - } else if (isa<TypedefDecl>(D)) { - fprintf(stderr, "TypedefDecl\n"); - //PrintTypeDefDecl( dyn_cast<TypedefDecl>(D), CTX.getSourceManager(), 0 ); - } else if (isa<TypeAliasDecl>(D)) { - fprintf(stderr, "TypeAliasDecl\n"); - } else fprintf(stderr, "\na declaration of type %s (%d)\n", D->getDeclKindName(), D->getKind()); - //else if (isa<TypedefNameDecl>(D)) { fprintf(stderr, "TypedefNameDecl\n");} - } -} - class NULLASTConsumer : public ASTConsumer { }; void findmanually(chillAST_Node *node, char *procname, std::vector<chillAST_Node *> &procs) { - //fprintf(stderr, "findmanually() CHILL AST node of type %s\n", node->getTypeString()); if (node->getType() == CHILLAST_NODE_FUNCTIONDECL) { char *name = ((chillAST_FunctionDecl *) node)->functionName; - //fprintf(stderr, "node name 0x%x ", name); - //fprintf(stderr, "%s procname ", name); - //fprintf(stderr, "0x%x ", procname); - //fprintf(stderr, "%s\n", procname); if (!strcmp(name, procname)) { - //fprintf(stderr, "found procedure %s\n", procname ); procs.push_back(node); // quit recursing. probably not correct in some horrible case return; } - //else fprintf(stderr, "this is not the function we're looking for\n"); } @@ -1380,10 +1315,8 @@ void findmanually(chillAST_Node *node, char *procname, std::vector<chillAST_Node // and then its children is needed. int numc = node->children.size(); - //fprintf(stderr, "%d children\n", numc); for (int i = 0; i < numc; i++) { - //fprintf(stderr, "node of type %s is recursing to child %d\n", node->getTypeString(), i); findmanually(node->children[i], procname, procs); } return; @@ -2188,68 +2121,29 @@ IR_Block *IR_clangCode::GetCode() const { // return IR_Block corresponding to void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { - fflush(stdout); - fprintf(stderr, "IR_xxxxCode::ReplaceCode( old, *repr)\n"); - CG_chillRepr *chillrepr = (CG_chillRepr *) repr; std::vector<chillAST_Node *> newcode = chillrepr->getChillCode(); int numnew = newcode.size(); - - //fprintf(stderr, "new code (%d) is\n", numnew); - //for (int i=0; i<numnew; i++) { - // newcode[i]->print(0, stderr); - // fprintf(stderr, "\n"); - //} - struct IR_chillLoop *cloop; - std::vector<chillAST_VarDecl *> olddecls; chillfunc->gatherVarDecls(olddecls); - //fprintf(stderr, "\n%d old decls they are:\n", olddecls.size()); - //for (int i=0; i<olddecls.size(); i++) { - // fprintf(stderr, "olddecl[%d] ox%x ",i, olddecls[i]); - // olddecls[i]->print(); printf("\n"); fflush(stdout); - //} - - - //fprintf(stderr, "num new stmts %d\n", numnew); - //fprintf(stderr, "new code we're look for decls in:\n"); std::vector<chillAST_VarDecl *> decls; - for (int i = 0; i < numnew; i++) { - //newcode[i]->print(0,stderr); - //fprintf(stderr, "\n"); + for (int i = 0; i < numnew; i++) newcode[i]->gatherVarUsage(decls); - } - - //fprintf(stderr, "\n%d new vars used they are:\n", decls.size()); - //for (int i=0; i<decls.size(); i++) { - // fprintf(stderr, "decl[%d] ox%x ",i, decls[i]); - // decls[i]->print(); printf("\n"); fflush(stdout); - //} - for (int i = 0; i < decls.size(); i++) { - //fprintf(stderr, "\nchecking "); decls[i]->print(); printf("\n"); fflush(stdout); int inthere = 0; - for (int j = 0; j < VariableDeclarations.size(); j++) { - if (VariableDeclarations[j] == decls[i]) { - //fprintf(stderr, "it's in the Variable Declarations()\n"); - } - } + for (int j = 0; j < VariableDeclarations.size(); j++) + if (VariableDeclarations[j] == decls[i]) + inthere = 1; for (int j = 0; j < olddecls.size(); j++) { - if (decls[i] == olddecls[j]) { - //fprintf(stderr, "it's in the olddecls (exactly)\n"); + if (decls[i] == olddecls[j]) inthere = 1; - } - if (!strcmp(decls[i]->varname, olddecls[j]->varname)) { - if (!strcmp(decls[i]->arraypart, olddecls[j]->arraypart)) { - //fprintf(stderr, "it's in the olddecls (INEXACTLY)\n"); + if (!strcmp(decls[i]->varname, olddecls[j]->varname)) + if (!strcmp(decls[i]->arraypart, olddecls[j]->arraypart)) inthere = 1; - } - } } if (!inthere) { - //fprintf(stderr, "inserting decl[%d] for ",i); decls[i]->print(); printf("\n");fflush(stdout); chillfunc->getBody()->insertChild(0, decls[i]); olddecls.push_back(decls[i]); } @@ -2281,7 +2175,7 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { int numstatements = oldparentcode->size(); for (int i = 0; i < numstatements; i++) if ((*oldparentcode)[i] == forstmt) { index = i; } if (index == -1) { - fprintf(stderr, "ir_clang.cc can't find the loop in its parent\n"); + CHILL_ERROR("can't find the loop in its parent\n"); exit(-1); } // insert the new code @@ -2309,7 +2203,6 @@ void IR_clangCode::ReplaceCode(IR_Control *old, omega::CG_outputRepr *repr) { case IR_CONTROL_BLOCK: CHILL_ERROR("old is IR_CONTROL_BLOCK\n"); exit(-1); - //tf_old = static_cast<IR_chillBlock *>(old)->getStmtList()[0]; break; default: throw chill::error::ir("control structure to be replaced not supported"); diff --git a/src/irtools.cc b/src/irtools.cc index 31747a1..abe6c43 100644 --- a/src/irtools.cc +++ b/src/irtools.cc @@ -364,26 +364,11 @@ test_data_dependences(IR_Code *ir, //------------------------------------------------------------- for (int i = 0; i < access.size(); i++) { - fprintf(stderr, "i %d\n", i); IR_ArrayRef *a = access[i]; IR_ArraySymbol *sym_a = a->symbol(); - fprintf(stderr, "sym_a = %s\n", a->name().c_str()); for (int j = i; j < access.size(); j++) { - fprintf(stderr, "irtools.cc j %d\n", j); IR_ArrayRef *b = access[j]; IR_ArraySymbol *sym_b = b->symbol(); - fprintf(stderr, "sym_b = %s\n", b->name().c_str()); - - fprintf(stderr, "irtools.cc ij %d %d\n", i, j); - - if (*sym_a == *sym_b) fprintf(stderr, "*sym_a == *sym_b\n"); - else fprintf(stderr, "*sym_a NOT == *sym_b\n"); - - if (a->is_write()) fprintf(stderr, "%d a->is_write()\n", i); - else fprintf(stderr, "%d a->is_NOT_write()\n", i); - if (b->is_write()) fprintf(stderr, "%d b->is_write()\n", j); - else fprintf(stderr, "%d b->is_NOT_write()\n", j); - if (*sym_a == *sym_b && (a->is_write() || b->is_write())) { Relation r = arrays2relation(ir, freevar, a, IS1, b, IS2, uninterpreted_symbols, uninterpreted_symbols_stringrepr); @@ -394,24 +379,15 @@ test_data_dependences(IR_Code *ir, helper->print(); fflush(stdout); CHILL_DEBUG_END - - fprintf(stderr, "1\n"); std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > dv = relation2dependences(a, b, r); - fprintf(stderr, "\nirtools.cc ij %d %d dv.first %d dv.second %d\n", i, j, dv.first.size(), - dv.second.size()); - fprintf(stderr, "2"); result.first.insert(result.first.end(), dv.first.begin(), dv.first.end()); - fprintf(stderr, "3"); result.second.insert(result.second.end(), dv.second.begin(), dv.second.end()); - fprintf(stderr, "4"); - // Manu:: check if the array references belong to the same statement // If yes, set the flag in the dependence vector - //---------------------------------------------- CHILL_DEBUG_BEGIN std::cout << "Size of the dependence vector '" << a->name().c_str() << "' -- " << dv.first.size() << "\n"; std::cout << "------------ Printing dependence vector START ---------------\n"; @@ -448,9 +424,7 @@ test_data_dependences(IR_Code *ir, std::cout << "------------ Printing dependence vector END---------------\n"; CHILL_DEBUG_END checkReductionDependence(i, j, nestLeveli, lbound, ubound, ref2Stmt, rMap, dv, trMap, nrStmts); - //---------------------------------------------- - -// // Manu:: original code without the condition + // Manu:: original code without the condition if (((rMap.find(ref2Stmt[i])->second).size() != 3) || (lbound[0] != lbound[1]) || (lbound[1] != lbound[2]) || (lbound[0] != lbound[2]) || (ubound[0] != ubound[1]) || (ubound[1] != ubound[2]) || (ubound[0] != ubound[2])) { // Manu:: original code without the condition @@ -459,8 +433,6 @@ test_data_dependences(IR_Code *ir, result.second.insert(result.second.end(), dv.second.begin(), dv.second.end()); } - - } delete sym_b; } @@ -479,13 +451,12 @@ test_data_dependences(IR_Code *ir, for (int i = 0; i < access.size(); i++) delete access[i]; } else { - fprintf(stderr, "\nrepr1 != repr2\n"); + CHILL_DEBUG_PRINT("repr1 != repr2\n"); std::vector<IR_ArrayRef *> access1 = ir->FindArrayRef(repr1); std::vector<IR_ArrayRef *> access2 = ir->FindArrayRef(repr2); for (int i = 0; i < access1.size(); i++) { - fprintf(stderr, "i %d\n", i); IR_ArrayRef *a = access1[i]; IR_ArraySymbol *sym_a = a->symbol(); @@ -514,23 +485,6 @@ test_data_dependences(IR_Code *ir, for (int i = 0; i < access2.size(); i++) delete access2[i]; } - /*std::pair<std::vector<DependenceVector>, - std::vector<DependenceVector> > dv = - ir->FindScalarDeps(repr1, repr2, index, i, j); - - - result.first.insert(result.first.end(), dv.first.begin(), - dv.first.end()); - result.second.insert(result.second.end(), dv.second.begin(), - dv.second.end());*/ - /*result.first.insert(result.first.end(), dv.first.begin(), - dv.first.end()); - result.second.insert(result.second.end(), dv.second.begin(), - dv.second.end()); - */ - - fprintf(stderr, "LEAVING test_data_dependences() first size %d second size %d\n\n", result.first.size(), - result.second.size()); return result; } @@ -542,7 +496,7 @@ bool from_same_statement(IR_Code *ir, IR_ArrayRef *a, IR_ArrayRef *b) { // Manu int stmtType(IR_Code *ir, const CG_outputRepr *repr) { - fprintf(stderr, "stmtType() DIE \n"); + CHILL_ERROR("stmtType() DIE \n"); exit(-1); return (ir->getStmtType(repr)); /// AIEEE returns a meaningless number encoding rose internals. } diff --git a/src/omegatools.cc b/src/omegatools.cc index 6d54591..33bf6e5 100644 --- a/src/omegatools.cc +++ b/src/omegatools.cc @@ -63,21 +63,19 @@ void exp2formula(IR_Code *ir, std::map<std::string, std::vector<omega::CG_outputRepr *> > &uninterpreted_symbols_stringrepr ) { - fprintf(stderr, "\n*** exp2formula()\n"); - //repr->dump(); /* printf("\n"); */fflush(stdout); - fprintf(stderr, "repr "); - r.print(); - printf("\n"); - fflush(stdout); - + CHILL_DEBUG_BEGIN + fprintf(stderr, "\n*** exp2formula()\n"); + repr->dump(); + fprintf(stderr, "repr "); + r.print(stderr); + fflush(stdout); + CHILL_DEBUG_END IR_OPERATION_TYPE optype = ir->QueryExpOperation(repr); switch (optype) { - - case IR_OP_CONSTANT: { - fprintf(stderr, "IR_OP_CONSTANT\n"); + CHILL_DEBUG_PRINT("IR_OP_CONSTANT\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); IR_ConstantRef *ref = static_cast<IR_ConstantRef *>(ir->Repr2Ref(v[0])); if (!ref->is_integer()) @@ -114,17 +112,11 @@ void exp2formula(IR_Code *ir, } case IR_OP_VARIABLE: { - fprintf(stderr, "IR_OP_VARIABLE\n"); - //fprintf(stderr, "repr "); repr->dump(); fflush(stdout); + CHILL_DEBUG_PRINT("IR_OP_VARIABLE\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); - //fprintf(stderr, "v "); v[0]->dump(); fflush(stdout); IR_ScalarRef *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0])); - - //fprintf(stderr, "omegatools.cc calling ref->name()\n"); std::string s = ref->name(); Variable_ID e = find_index(r, s, side); - //fprintf(stderr, "s %s\n", s.c_str()); - if (e == NULL) { // must be free variable Free_Var_Decl *t = NULL; @@ -171,7 +163,7 @@ void exp2formula(IR_Code *ir, } case IR_OP_ASSIGNMENT: { - fprintf(stderr, "IR_OP_ASSIGNMENT\n"); + CHILL_DEBUG_PRINT("IR_OP_ASSIGNMENT\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); exp2formula(ir, r, f_root, freevars, v[0], lhs, side, rel, true, uninterpreted_symbols, uninterpreted_symbols_stringrepr); @@ -181,7 +173,7 @@ void exp2formula(IR_Code *ir, } case IR_OP_PLUS: { - fprintf(stderr, "IR_OP_PLUS\n"); + CHILL_DEBUG_PRINT("IR_OP_PLUS\n"); F_Exists *f_exists = f_root->add_exists(); Variable_ID e1 = f_exists->declare(tmp_e()); Variable_ID e2 = f_exists->declare(tmp_e()); @@ -219,7 +211,7 @@ void exp2formula(IR_Code *ir, break; } case IR_OP_MINUS: { - fprintf(stderr, "IR_OP_MINUS\n"); + CHILL_DEBUG_PRINT("IR_OP_MINUS\n"); F_Exists *f_exists = f_root->add_exists(); Variable_ID e1 = f_exists->declare(tmp_e()); Variable_ID e2 = f_exists->declare(tmp_e()); @@ -248,13 +240,11 @@ void exp2formula(IR_Code *ir, throw std::invalid_argument("unsupported condition type"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); - fprintf(stderr, "IR_OP_MINUS v has %d parts\n", (int) v.size()); - fprintf(stderr, "IR_OP_MINUS recursing 1\n"); + CHILL_DEBUG_PRINT("IR_OP_MINUS v has %d parts\n", (int) v.size()); exp2formula(ir, r, f_and, freevars, v[0], e1, side, IR_COND_EQ, true, uninterpreted_symbols, uninterpreted_symbols_stringrepr); if (v.size() > 1) { - fprintf(stderr, "IR_OP_MINUS recursing 2\n"); // dies here because it's unary minus? exp2formula(ir, r, f_and, freevars, v[1], e2, side, IR_COND_EQ, true, uninterpreted_symbols, uninterpreted_symbols_stringrepr); } @@ -267,7 +257,7 @@ void exp2formula(IR_Code *ir, case IR_OP_MULTIPLY: { - fprintf(stderr, "IR_OP_MULTIPLY\n"); + CHILL_DEBUG_PRINT("IR_OP_MULTIPLY\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); coef_t coef; @@ -318,7 +308,7 @@ void exp2formula(IR_Code *ir, } case IR_OP_DIVIDE: { - fprintf(stderr, "IR_OP_DIVIDE\n"); + CHILL_DEBUG_PRINT("IR_OP_DIVIDE\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); assert(ir->QueryExpOperation(v[1]) == IR_OP_CONSTANT); @@ -358,7 +348,7 @@ void exp2formula(IR_Code *ir, } case IR_OP_MOD: { - fprintf(stderr, "IR_OP_MOD\n"); + CHILL_DEBUG_PRINT("IR_OP_MOD\n"); /* the left hand of a mod can be a var but the right must be a const */ std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); @@ -412,7 +402,7 @@ void exp2formula(IR_Code *ir, case IR_OP_POSITIVE: { - fprintf(stderr, "IR_OP_POSITIVE\n"); + CHILL_DEBUG_PRINT("IR_OP_POSITIVE\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); exp2formula(ir, r, f_root, freevars, v[0], lhs, side, rel, true, @@ -425,7 +415,7 @@ void exp2formula(IR_Code *ir, case IR_OP_NEGATIVE: { - fprintf(stderr, "IR_OP_NEGATIVE\n"); + CHILL_DEBUG_PRINT("IR_OP_NEGATIVE\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); F_Exists *f_exists = f_root->add_exists(); @@ -460,7 +450,7 @@ void exp2formula(IR_Code *ir, case IR_OP_MIN: { - fprintf(stderr, "IR_OP_MIN\n"); + CHILL_DEBUG_PRINT("IR_OP_MIN\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); F_Exists *f_exists = f_root->add_exists(); @@ -529,7 +519,7 @@ void exp2formula(IR_Code *ir, } case IR_OP_MAX: { - fprintf(stderr, "IR_OP_MAX\n"); + CHILL_DEBUG_PRINT("IR_OP_MAX\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); F_Exists *f_exists = f_root->add_exists(); @@ -598,39 +588,19 @@ void exp2formula(IR_Code *ir, } case IR_OP_ARRAY_VARIABLE: { // ***** - fprintf(stderr, "\nomegatools.cc IR_OP_ARRAY_VARIABLE ARRAY! \n"); - - // temp for printing - //CG_chillRepr *CR = (CG_chillRepr *)repr; - //fprintf(stderr, "repr "); CR->dump(); fflush(stdout); - - //fprintf(stderr, "repr "); repr->dump(); /* printf("\n"); */fflush(stdout); - + CHILL_DEBUG_PRINT("IR_OP_ARRAY_VARIABLE\n"); std::vector<CG_outputRepr *> v = ir->QueryExpOperand(repr); IR_Ref *ref = static_cast<IR_ScalarRef *>(ir->Repr2Ref(v[0])); CG_chillRepr *CR = (CG_chillRepr *) v[0]; // cheat for now. we should not know this is a chillRepr - //fprintf(stderr, "v "); CR->dump(); fflush(stdout); - //fprintf(stderr, "v "); v[0]->dump(); /* printf("\n"); */ fflush(stdout); chillAST_Node *node = CR->GetCode(); - - - //fprintf(stderr, "\n**** walking parents!\n"); - //std::vector<chillAST_VarDecl*> loopvars; - //node->gatherLoopIndeces( loopvars ); - //fprintf(stderr, "in omegatools, %d loop vars\n", (int)loopvars.size()); - - std::string s = ref->name(); - //fprintf(stderr, "array variable s is %s\n", s.c_str()); int max_dim = 0; bool need_new_fsymbol = false; std::set<std::string> vars; - //fprintf(stderr, "ref->n_dim %d\n", ref->n_dim()); for (int i = 0; i < ref->n_dim(); i++) { - //fprintf(stderr, "dimension %d\n", i); Relation temp(r.n_inp()); // r is enclosing relation, we build another that will include this @@ -657,11 +627,9 @@ void exp2formula(IR_Code *ir, Variable_ID e = temp.get_local(t); freevars.insert(freevars.end(), t); - fprintf(stderr, "exp2formula recursing? \n"); exp2formula(ir, temp, temp_root, freevars, repr, e, side, IR_COND_EQ, false, uninterpreted_symbols, uninterpreted_symbols_stringrepr); - fprintf(stderr, "BACK FROM exp2formula recursing? \n"); // temp is relation for the index of the array ?? for (DNF_Iterator di(temp.query_DNF()); di; di++) { @@ -684,14 +652,6 @@ void exp2formula(IR_Code *ir, if (max_dim != ref->n_dim()) need_new_fsymbol = true; } - - //fprintf(stderr, "%d vars: ", (int)vars.size()); - //for (int i=0; i<vars.size(); i++) fprintf(stderr, "%s", vars[i].c_str()); - //for (std::set<std::string>::iterator it = vars.begin(); it != vars.end(); it++) { - // fprintf(stderr, "%s ", (*it).c_str()); - //} - //fprintf(stderr, "\n"); - // r is enclosing relation, we build another that will include Variable_ID e = find_index(r, s, side); // s is the array named "index" @@ -703,21 +663,7 @@ void exp2formula(IR_Code *ir, for (int i = 0; i < numnodes; i++) { internals[i]->gatherScalarVarDecls(sdecls); // vardecls for scalars } - - //fprintf(stderr, "%d scalar var decls()\n", sdecls.size()); - //for (int i=0; i<sdecls.size(); i++) { - // fprintf(stderr, "vardecl %2d: ", i); - // sdecls[i]->print(); printf("\n"); fflush(stdout); - //} - - - //fprintf(stderr, "omegatools.cc, exp2formula() NOW WHAT\n"); - //exit(0); - if (e == NULL) { // s must be a free variable - //fprintf(stderr, "'%s' must be free variable\n\n", s.c_str()); - //fprintf(stderr, "SO WE WILL CREATE A MACRO ???\n"); - Free_Var_Decl *t = NULL; // keep adding underscores until we have created a unique name based on the original @@ -752,29 +698,13 @@ void exp2formula(IR_Code *ir, else args += ","; args += *it; - //fprintf(stderr, "an argument to the macro: %s\n", it->c_str()); Vargs.push_back((*it)); reprs.push_back(ir->builder()->CreateIdent(*it)); reprs2.push_back(ir->builder()->CreateIdent(*it)); } args += ")"; - - //fprintf(stderr, "args '%s'\n", args.c_str()); - //fprintf(stderr, "Vargs "); - //for (int i=0; i<Vargs.size(); i++) fprintf(stderr, "%s ",Vargs[i].c_str()); - //fprintf(stderr, "\n"); - - //fprintf(stderr, "omegatools.cc ir->CreateDefineMacro( s (%s), args(%s), repr)\n", s.c_str(), args.c_str()); - // TODO repr, the rhs of the macro, needs to NOT refer to an actual variable ??? - - ir->CreateDefineMacro(s, Vargs, repr); - - - - // index_(i) uses i outputrepr - //fprintf(stderr,"omegatools.cc making uninterpreted symbol %s\n",s.c_str()); uninterpreted_symbols.insert( // adding to uninterpreted_symbols std::pair<std::string, std::vector<omega::CG_outputRepr *> >( s, reprs)); @@ -803,17 +733,14 @@ void exp2formula(IR_Code *ir, } else throw std::invalid_argument("unsupported condition type"); } - // delete v[0]; delete ref; if (destroy) delete repr; - - //fprintf(stderr, "FINALLY DONE with IR_OP_ARRAY_VARIABLE\n\n"); break; } case IR_OP_NULL: - fprintf(stderr, "IR_OP_NULL\n"); + CHILL_DEBUG_PRINT("IR_OP_NULL\n"); break; diff --git a/src/printer/cfamily.cpp b/src/printer/cfamily.cpp index d0f8030..552947a 100644 --- a/src/printer/cfamily.cpp +++ b/src/printer/cfamily.cpp @@ -180,9 +180,9 @@ void CFamily::printS(std::string ident, chillAST_ForStmt *n, std::ostream &o) { o << "// " << n->metacomment << "\n"; o << "for ("; print(ident, n->getInit(), o); - o << ";"; + o << "; "; print(ident, n->getCond(), o); - o << ";"; + o << "; "; print(ident, n->getInc(), o); o << ") "; if (n->getBody()->isCompoundStmt()) { @@ -232,6 +232,9 @@ void CFamily::printS(std::string ident, chillAST_IfStmt *n, std::ostream &o) { if (!(n->getThen()->isCompoundStmt())) CHILL_ERROR("Then part is not a CompoundStmt!\n"); if (n->getElse()) { + if (n->getThen()->getNumChildren() == 1) + o<<std::endl<<ident; + else o<<" "; o << "else "; print(ident, n->getElse(), o); } diff --git a/src/transformations/loop.cc b/src/transformations/loop.cc index 53bbf67..0b9603e 100644 --- a/src/transformations/loop.cc +++ b/src/transformations/loop.cc @@ -317,7 +317,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, // find out how deeply nested each statement is. (how can these be different?) for (int i = 0; i < ir_stmt.size(); i++) { - fprintf(stderr, "i %d\n", i); ir_stmt[i]->payload = i; int t = 0; ir_tree_node *itn = ir_stmt[i]; @@ -343,7 +342,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, int n_dim = -1; int max_loc; - //std::vector<std::string> index; for (int i = 0; i < ir_stmt.size(); i++) { int max_nesting_level = -1; int loc; @@ -436,29 +434,13 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, itn = itn->parent; if (itn->content->type() == IR_CONTROL_LOOP) { - fprintf(stderr, "it's a loop. temp_depth %d\n", temp_depth); - fprintf(stderr, "r.name_set_var( %d, %s )\n", itn->payload + 1, index[temp_depth].c_str()); + CHILL_DEBUG_PRINT("it's a loop. temp_depth %d\n", temp_depth); + CHILL_DEBUG_PRINT("r.name_set_var( %d, %s )\n", itn->payload + 1, index[temp_depth].c_str()); r.name_set_var(itn->payload + 1, index[temp_depth]); - temp_depth--; } - //static_cast<IR_Loop *>(itn->content)->index()->name()); } - fprintf(stderr, "Relation r "); - r.print(); - fflush(stdout); - //fprintf(stderr, "f_root "); f_root->print(stderr); fprintf(stderr, "\n"); - - /*while (itn->parent != NULL) { - itn = itn->parent; - if (itn->content->type() == IR_CONTROL_LOOP) - r.name_set_var(itn->payload+1, static_cast<IR_Loop *>(itn->content)->index()->name()); - }*/ - - - - - fprintf(stderr, "extract information from loop/if structures\n"); + CHILL_DEBUG_PRINT("extract information from loop/if structures\n"); // extract information from loop/if structures std::vector<bool> processed(n_dim, false); std::vector<std::string> vars_to_be_reversed; @@ -472,29 +454,27 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, switch (itn->content->type()) { case IR_CONTROL_LOOP: { - fprintf(stderr, "loop.cc l 462 IR_CONTROL_LOOP\n"); + CHILL_DEBUG_PRINT("IR_CONTROL_LOOP\n"); IR_Loop *lp = static_cast<IR_Loop *>(itn->content); Variable_ID v = r.set_var(itn->payload + 1); int c; try { c = lp->step_size(); - //fprintf(stderr, "step size %d\n", c); if (c > 0) { CG_outputRepr *lb = lp->lower_bound(); - fprintf(stderr, "loop.cc, got the lower bound. it is:\n"); - lb->dump(); - printf("\n"); - fflush(stdout); - + CHILL_DEBUG_BEGIN + fprintf(stderr, "got the lower bound. it is:\n"); + lb->dump(); + CHILL_DEBUG_END exp2formula(ir, r, f_root, freevar, lb, v, 's', IR_COND_GE, true, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]); CG_outputRepr *ub = lp->upper_bound(); - //fprintf(stderr, "loop.cc, got the upper bound. it is:\n"); - //ub->dump(); printf("\n"); fflush(stdout); - - + CHILL_DEBUG_BEGIN + fprintf(stderr, "got the upper bound. it is:\n"); + ub->dump(); + CHILL_DEBUG_END IR_CONDITION_TYPE cond = lp->stop_cond(); if (cond == IR_COND_LT || cond == IR_COND_LE) @@ -509,9 +489,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, && (ir->QueryExpOperation(lp->lower_bound()) == ir->QueryExpOperation( lp->upper_bound()))) { - - fprintf(stderr, "loop.cc lower and upper are both IR_OP_ARRAY_VARIABLE?\n"); - std::vector<CG_outputRepr *> v = ir->QueryExpOperand(lp->lower_bound()); IR_ArrayRef *ref = @@ -566,7 +543,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, } // check for loop increment or decrement that is not 1 - //fprintf(stderr, "abs(c)\n"); if (abs(c) != 1) { F_Exists *f_exists = f_root->add_exists(); Variable_ID e = f_exists->declare(); @@ -588,7 +564,7 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, case IR_CONTROL_IF: { - fprintf(stderr, "IR_CONTROL_IF\n"); + CHILL_DEBUG_PRINT("IR_CONTROL_IF\n"); IR_If *theif = static_cast<IR_If *>(itn->content); CG_outputRepr *cond = @@ -630,7 +606,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, break; } default: - //fprintf(stderr, "default?\n"); for (int i = 0; i < itn->children.size(); i++) delete itn->children[i]; itn->children = std::vector<ir_tree_node *>(); @@ -639,8 +614,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, } } - - //fprintf(stderr, "add information for missing loops n_dim(%d)\n", n_dim); // add information for missing loops for (int j = 0; j < n_dim; j++) if (!processed[j]) { @@ -662,35 +635,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, exp2formula(ir, r, f_root, freevar, lb, v, 's', IR_COND_EQ, false, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]); - - /* if (ir->QueryExpOperation( - static_cast<IR_Loop *>(itn->content)->lower_bound()) - == IR_OP_VARIABLE) { - IR_ScalarRef *ref = - static_cast<IR_ScalarRef *>(ir->Repr2Ref( - static_cast<IR_Loop *>(itn->content)->lower_bound())); - std::string name_ = ref->name(); - - for (int i = 0; i < index.size(); i++) - if (index[i] == name_) { - exp2formula(ir, r, f_root, freevar, lb, v, 's', - IR_COND_GE, false); - - CG_outputRepr *ub = - static_cast<IR_Loop *>(itn->content)->upper_bound(); - IR_CONDITION_TYPE cond = - static_cast<IR_Loop *>(itn->content)->stop_cond(); - if (cond == IR_COND_LT || cond == IR_COND_LE) - exp2formula(ir, r, f_root, freevar, ub, v, - 's', cond, false); - - - - } - - } - */ - } else { // loc > max_loc CG_outputBuilder *ocg = ir->builder(); @@ -699,35 +643,6 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, exp2formula(ir, r, f_root, freevar, ub, v, 's', IR_COND_EQ, false, uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]); - /*if (ir->QueryExpOperation( - static_cast<IR_Loop *>(itn->content)->upper_bound()) - == IR_OP_VARIABLE) { - IR_ScalarRef *ref = - static_cast<IR_ScalarRef *>(ir->Repr2Ref( - static_cast<IR_Loop *>(itn->content)->upper_bound())); - std::string name_ = ref->name(); - - for (int i = 0; i < index.size(); i++) - if (index[i] == name_) { - - CG_outputRepr *lb = - static_cast<IR_Loop *>(itn->content)->lower_bound(); - - exp2formula(ir, r, f_root, freevar, lb, v, 's', - IR_COND_GE, false); - - CG_outputRepr *ub = - static_cast<IR_Loop *>(itn->content)->upper_bound(); - IR_CONDITION_TYPE cond = - static_cast<IR_Loop *>(itn->content)->stop_cond(); - if (cond == IR_COND_LT || cond == IR_COND_LE) - exp2formula(ir, r, f_root, freevar, ub, v, - 's', cond, false); - - - } - } - */ } } @@ -776,13 +691,8 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, g.update_coef(index_lb, -1); g.update_const(-1); addKnown(known_); - } - } - - - fprintf(stderr, "loop.cc L441 insert the statement\n"); // insert the statement CG_outputBuilder *ocg = ir->builder(); std::vector<CG_outputRepr *> reverse_expr; @@ -791,43 +701,28 @@ bool Loop::init_loop(std::vector<ir_tree_node *> &ir_tree, repl = ocg->CreateMinus(NULL, repl); reverse_expr.push_back(repl); } - fprintf(stderr, "loop.cc before extract\n"); CG_outputRepr *code = static_cast<IR_Block *>(ir_stmt[loc]->content)->extract(); - fprintf(stderr, "code = ocg->CreateSubstitutedStmt(...)\n"); - ((CG_chillRepr *) code)->dump(); - fflush(stdout); - code = ocg->CreateSubstitutedStmt(0, code, vars_to_be_reversed, reverse_expr); - fprintf(stderr, "stmt\n"); - ((CG_chillRepr *) code)->dump(); - fflush(stdout); - stmt[loc].code = code; stmt[loc].IS = r; //Anand: Add Information on uninterpreted function constraints to //Known relation - fprintf(stderr, "loop.cc stmt[%d].loop_level has size n_dim %d\n", loc, n_dim); + CHILL_DEBUG_PRINT("stmt[%d].loop_level has size n_dim %d\n", loc, n_dim); stmt[loc].loop_level = std::vector<LoopLevel>(n_dim); stmt[loc].ir_stmt_node = ir_stmt[loc]; stmt[loc].has_inspector = false; - fprintf(stderr, "for int i < n_dim(%d)\n", n_dim); for (int ii = 0; ii < n_dim; ii++) { stmt[loc].loop_level[ii].type = LoopLevelOriginal; stmt[loc].loop_level[ii].payload = ii; stmt[loc].loop_level[ii].parallel_level = 0; } - fprintf(stderr, "whew\n"); - stmt_nesting_level[loc] = -1; } - dump(); - fprintf(stderr, " loop.cc Loop::init_loop() END\n\n"); - return true; } @@ -856,25 +751,15 @@ Loop::Loop(const IR_Control *control) { CHILL_DEBUG_PRINT("calling build_ir_tree()\n"); CHILL_DEBUG_PRINT("about to clone control\n"); ir_tree = build_ir_tree(control->clone(), NULL); - //fprintf(stderr,"in Loop::Loop. ir_tree has %ld parts\n", ir_tree.size()); - - // std::vector<ir_tree_node *> ir_stmt; - //fprintf(stderr, "loop.cc after build_ir_tree() %ld statements\n", stmt.size()); int count = 0; - //fprintf(stderr, "before init_loops, %d freevar\n", freevar.size()); - //fprintf(stderr, "count %d\n", count++); - //fprintf(stderr, "loop.cc before init_loop, %ld statements\n", stmt.size()); - while (!init_loop(ir_tree, ir_stmt)) { - //fprintf(stderr, "count %d\n", count++); - } - fprintf(stderr, "after init_loop, %d freevar\n", (int) freevar.size()); + while (!init_loop(ir_tree, ir_stmt)); + CHILL_DEBUG_PRINT("after init_loop, %d freevar\n", (int) freevar.size()); - fprintf(stderr, "loop.cc after init_loop, %d statements\n", (int) stmt.size()); + CHILL_DEBUG_PRINT("after init_loop, %d statements\n", (int) stmt.size()); for (int i = 0; i < stmt.size(); i++) { std::map<int, CG_outputRepr *>::iterator it = replace.find(i); - if (it != replace.end()) stmt[i].code = it->second; else @@ -889,13 +774,10 @@ Loop::Loop(const IR_Control *control) { for (int i = 0; i < stmt.size(); i++) dep.insert(); - fprintf(stderr, "this really REALLY needs some comments\n"); - // this really REALLY needs some comments + // TODO this really REALLY needs some comments for (int i = 0; i < stmt.size(); i++) { - fprintf(stderr, "i %d\n", i); stmt[i].reduction = 0; // Manu -- initialization for (int j = i; j < stmt.size(); j++) { - fprintf(stderr, "j %d\n", j); std::pair<std::vector<DependenceVector>, std::vector<DependenceVector> > dv = test_data_dependences( ir, @@ -909,10 +791,7 @@ Loop::Loop(const IR_Control *control) { stmt_nesting_level_[j], uninterpreted_symbols[i], uninterpreted_symbols_stringrepr[i]); - - fprintf(stderr, "dv.first.size() %d\n", (int) dv.first.size()); for (int k = 0; k < dv.first.size(); k++) { - fprintf(stderr, "k1 %d\n", k); if (is_dependence_valid(ir_stmt[i], ir_stmt[j], dv.first[k], true)) dep.connect(i, j, dv.first[k]); @@ -923,7 +802,6 @@ Loop::Loop(const IR_Control *control) { } for (int k = 0; k < dv.second.size(); k++) { - fprintf(stderr, "k2 %d\n", k); if (is_dependence_valid(ir_stmt[j], ir_stmt[i], dv.second[k], false)) dep.connect(j, i, dv.second[k]); @@ -934,63 +812,47 @@ Loop::Loop(const IR_Control *control) { } } - fprintf(stderr, "\n\n*** LOTS OF REDUCTIONS ***\n\n"); + CHILL_DEBUG_PRINT("*** LOTS OF REDUCTIONS ***\n"); // TODO: Reduction check // Manu:: Initial implementation / algorithm std::set<int> reducCand = std::set<int>(); std::vector<int> canReduce = std::vector<int>(); - fprintf(stderr, "\ni range %d\n", stmt.size()); for (int i = 0; i < stmt.size(); i++) { - fprintf(stderr, "i %d\n", i); if (!dep.hasEdge(i, i)) { continue; } - fprintf(stderr, "dep.hasEdge(%d, %d)\n", i, i); - // for each statement check if it has all the three dependences (RAW, WAR, WAW) // If there is such a statement, it is a reduction candidate. Mark all reduction candidates. std::vector<DependenceVector> tdv = dep.getEdge(i, i); - fprintf(stderr, "tdv size %d\n", tdv.size()); for (int j = 0; j < tdv.size(); j++) { - fprintf(stderr, "ij %d %d\n", i, j); if (tdv[j].is_reduction_cand) { - fprintf(stderr, "reducCand.insert( %d )\n", i); reducCand.insert(i); } } } - - fprintf(stderr, "loop.cc reducCand.size() %d\n", reducCand.size()); bool reduc; std::set<int>::iterator it; int counter = 0; for (it = reducCand.begin(); it != reducCand.end(); it++) { - fprintf(stderr, "counter %d\n", counter); reduc = true; for (int j = 0; j < stmt.size(); j++) { - fprintf(stderr, "j %d\n", j); if ((*it != j) && (stmt_nesting_level_[*it] < stmt_nesting_level_[j])) { if (dep.hasEdge(*it, j) || dep.hasEdge(j, *it)) { - fprintf(stderr, "counter %d j %d reduc = false\n", counter, j); reduc = false; break; } } counter += 1; } - if (reduc) { - fprintf(stderr, "canReduce.push_back()\n"); canReduce.push_back(*it); stmt[*it].reduction = 2; // First, assume that reduction is possible with some processing } } - - // If reduction is possible without processing, update the value of the reduction variable to 1 - fprintf(stderr, "loop.cc canReduce.size() %d\n", canReduce.size()); + CHILL_DEBUG_PRINT("canReduce.size() %d\n", canReduce.size()); for (int i = 0; i < canReduce.size(); i++) { // Here, assuming that stmtType returns 1 when there is a single statement within stmt[i] if (stmtType(ir, stmt[canReduce[i]].code) == 1) { @@ -1022,7 +884,7 @@ Loop::Loop(const IR_Control *control) { CHILL_DEBUG_END // cleanup the IR tree - fprintf(stderr, "init dumb transformation relations\n"); + CHILL_DEBUG_PRINT("init dumb transformation relations\n"); // init dumb transformation relations e.g. [i, j] -> [ 0, i, 0, j, 0] for (int i = 0; i < stmt.size(); i++) { @@ -1042,23 +904,12 @@ Loop::Loop(const IR_Control *control) { } stmt[i].xform.simplify(); } - //fprintf(stderr, "done with dumb\n"); + CHILL_DEBUG_PRINT("done with dumb\n"); if (stmt.size() != 0) num_dep_dim = stmt[0].IS.n_set(); else num_dep_dim = 0; - // debug - /*for (int i = 0; i < stmt.size(); i++) { - std::cout << i << ": "; - //stmt[i].xform.print(); - stmt[i].IS.print(); - std::cout << std::endl; - - }*/ - //end debug - fprintf(stderr, " at bottom of Loop::Loop, printCode\n"); - printCode(); // this dies TODO figure out why } Loop::~Loop() { @@ -1190,7 +1041,7 @@ void Loop::debugRelations() const { CG_outputRepr *Loop::getCode(int effort) const { - fprintf(stderr, "\nloop.cc Loop::getCode( effort %d )\n", effort); + CHILL_DEBUG_PRINT("effort %d\n", effort); const int m = stmt.size(); if (m == 0) @@ -1198,7 +1049,7 @@ CG_outputRepr *Loop::getCode(int effort) const { const int n = stmt[0].xform.n_out(); if (last_compute_cg_ == NULL) { - fprintf(stderr, "Loop::getCode() last_compute_cg_ == NULL\n"); + CHILL_DEBUG_PRINT("last_compute_cg_ == NULL\n"); std::vector<Relation> IS(m); std::vector<Relation> xforms(m); @@ -1211,18 +1062,12 @@ CG_outputRepr *Loop::getCode(int effort) const { Relation known = Extend_Set(copy(this->known), n - this->known.n_set()); - printf("\nknown:\n"); - known.print(); - printf("\n\n"); - fflush(stdout); last_compute_cg_ = new CodeGen(xforms, IS, known); delete last_compute_cgr_; last_compute_cgr_ = NULL; - } else { - fprintf(stderr, "Loop::getCode() last_compute_cg_ NOT NULL\n"); - } - + } else + CHILL_DEBUG_PRINT("last_compute_cg_ NOT NULL\n"); if (last_compute_cgr_ == NULL || last_compute_effort_ != effort) { delete last_compute_cgr_; @@ -1231,12 +1076,11 @@ CG_outputRepr *Loop::getCode(int effort) const { } std::vector<CG_outputRepr *> stmts(m); - fprintf(stderr, "%d stmts\n", m); for (int i = 0; i < m; i++) stmts[i] = stmt[i].code; CG_outputBuilder *ocg = ir->builder(); - fprintf(stderr, "calling last_compute_cgr_->printRepr()\n"); + CHILL_DEBUG_PRINT("calling last_compute_cgr_->printRepr()\n"); CG_outputRepr *repr = last_compute_cgr_->printRepr(ocg, stmts, uninterpreted_symbols); @@ -1245,20 +1089,19 @@ CG_outputRepr *Loop::getCode(int effort) const { if (cleanup_code != NULL) repr = ocg->StmtListAppend(repr, cleanup_code->clone()); - fprintf(stderr, "\nloop.cc Loop::getCode( effort %d ) DONE\n", effort); return repr; } void Loop::printCode(int effort) const { - fprintf(stderr, "\nloop.cc Loop::printCode( effort %d )\n", effort); + CHILL_DEBUG_PRINT("effort %d\n", effort); const int m = stmt.size(); if (m == 0) return; const int n = stmt[0].xform.n_out(); if (last_compute_cg_ == NULL) { - fprintf(stderr, "Loop::printCode(), last_compute_cg_ == NULL\n"); + CHILL_DEBUG_PRINT("last_compute_cg_ == NULL\n"); std::vector<Relation> IS(m); std::vector<Relation> xforms(m); for (int i = 0; i < m; i++) { @@ -1270,7 +1113,7 @@ void Loop::printCode(int effort) const { last_compute_cg_ = new CodeGen(xforms, IS, known); delete last_compute_cgr_; last_compute_cgr_ = NULL; - } else fprintf(stderr, "Loop::printCode(), last_compute_cg_ NOT NULL\n"); + } else CHILL_DEBUG_PRINT("last_compute_cg_ NOT NULL\n"); if (last_compute_cgr_ == NULL || last_compute_effort_ != effort) { delete last_compute_cgr_; @@ -1280,7 +1123,6 @@ void Loop::printCode(int effort) const { std::string repr = last_compute_cgr_->printString( uninterpreted_symbols_stringrepr); - fprintf(stderr, "leaving Loop::printCode()\n"); std::cout << repr << std::endl; } @@ -1325,19 +1167,6 @@ void Loop::pragma(int stmt_num, int level, const std::string &pragmaText) { ocg->CreatePragmaAttribute(code, level, pragmaText); } - -/* - void Loop::prefetch(int stmt_num, int level, const std::string &arrName, const std::string &indexName, int offset, int hint) { - // check sanity of parameters - if(stmt_num < 0) - throw std::invalid_argument("invalid statement " + to_string(stmt_num)); - - CG_outputBuilder *ocg = ir->builder(); - CG_outputRepr *code = stmt[stmt_num].code; - ocg->CreatePrefetchAttribute(code, level, arrName, indexName, int offset, hint); - } -*/ - void Loop::prefetch(int stmt_num, int level, const std::string &arrName, int hint) { // check sanity of parameters if (stmt_num < 0) @@ -2289,9 +2118,6 @@ void Loop::apply_xform(int stmt_num) { } void Loop::apply_xform(std::set<int> &active) { - fflush(stdout); - fprintf(stderr, "loop.cc apply_xform( set )\n"); - int max_n = 0; omega::CG_outputBuilder *ocg = ir->builder(); @@ -2321,18 +2147,10 @@ void Loop::apply_xform(std::set<int> &active) { + omega::to_string( tmp_loop_var_name_counter + j - 1)); mapping.setup_names(); - mapping.print(); // "{[I] -> [_t1] : I = _t1 } - fflush(stdout); - omega::Relation known = Extend_Set(copy(this->known), mapping.n_out() - this->known.n_set()); - //stmt[*i].code = outputStatement(ocg, stmt[*i].code, 0, mapping, known, std::vector<CG_outputRepr *>(mapping.n_out(), NULL)); - omega::CG_outputBuilder *ocgr = ir->builder(); - - - //this is probably CG_chillBuilder; - + //this is probably CG_chillBuilder; omega::CG_stringBuilder *ocgs = new omega::CG_stringBuilder; if (uninterpreted_symbols[*i].size() == 0) { @@ -2381,9 +2199,6 @@ void Loop::apply_xform(std::set<int> &active) { for (int j = 1; j <= stmt[*i].IS.n_set(); j++) { loop_vars.push_back(stmt[*i].IS.set_var(j)->name()); } - for (int j = 0; j < loop_vars.size(); j++) { - fprintf(stderr, "loop vars %d %s\n", j, loop_vars[j].c_str()); - } std::vector<CG_outputRepr *> subs = output_substitutions(ocg, Inverse(copy(mapping)), std::vector<std::pair<CG_outputRepr *, int> >( @@ -2396,47 +2211,24 @@ void Loop::apply_xform(std::set<int> &active) { for (int l = 0; l < subs.size(); l++) subs2.push_back(subs[l]->clone()); - fprintf(stderr, "%d uninterpreted symbols\n", (int) uninterpreted_symbols.size()); - for (int j = 0; j < loop_vars.size(); j++) { - fprintf(stderr, "loop vars %d %s\n", j, loop_vars[j].c_str()); - } - - int count = 0; for (std::map<std::string, std::vector<CG_outputRepr *> >::iterator it = uninterpreted_symbols[*i].begin(); it != uninterpreted_symbols[*i].end(); it++) { - fprintf(stderr, "\ncount %d\n", count); - std::vector<CG_outputRepr *> reprs_ = it->second; - fprintf(stderr, "%d reprs_\n", (int) reprs_.size()); - std::vector<CG_outputRepr *> reprs_2; for (int k = 0; k < reprs_.size(); k++) { - fprintf(stderr, "k %d\n", k); std::vector<CG_outputRepr *> subs; for (int l = 0; l < subs2.size(); l++) { - fprintf(stderr, "l %d\n", l); subs.push_back(subs2[l]->clone()); } - - fprintf(stderr, "clone\n"); CG_outputRepr *c = reprs_[k]->clone(); - c->dump(); - fflush(stdout); - - fprintf(stderr, "createsub\n"); CG_outputRepr *s = ocgr->CreateSubstitutedStmt(0, c, loop_vars, subs, true); - - fprintf(stderr, "push back\n"); reprs_2.push_back(s); - } - it->second = reprs_2; count++; - fprintf(stderr, "bottom\n"); } std::vector<CG_outputRepr *> subs3 = output_substitutions( @@ -2467,22 +2259,12 @@ void Loop::apply_xform(std::set<int> &active) { it->second = reprs_2; } - - - fprintf(stderr, "loop.cc stmt[*i].code =\n"); - //stmt[*i].code->dump(); - //fprintf(stderr, "\n"); stmt[*i].code = ocg->CreateSubstitutedStmt(0, stmt[*i].code, loop_vars, subs); - //fprintf(stderr, "loop.cc substituted code =\n"); - //stmt[*i].code->dump(); - //fprintf(stderr, "\n"); - stmt[*i].IS = omega::Range(Restrict_Domain(mapping, stmt[*i].IS)); stmt[*i].IS.simplify(); // replace original transformation relation with straight 1-1 mapping - //fprintf(stderr, "replace original transformation relation with straight 1-1 mapping\n"); mapping = Relation(n, 2 * n + 1); f_root = mapping.add_and(); for (int j = 1; j <= n; j++) { @@ -2496,22 +2278,8 @@ void Loop::apply_xform(std::set<int> &active) { h.update_const(-lex[j - 1]); } stmt[*i].xform = mapping; - - //fprintf(stderr, "\ncode is: \n"); - //stmt[*i].code->dump(); - //fprintf(stderr, "\n\n"); - } - tmp_loop_var_name_counter += max_n; - fflush(stdout); - fprintf(stderr, "loop.cc LEAVING apply_xform( set )\n\n"); - //for (std::set<int>::iterator i = active.begin(); i != active.end(); i++) { - // fprintf(stderr, "\nloop.cc stmt[i].code =\n"); - // stmt[*i].code->dump(); - // fprintf(stderr, "\n\n"); - //} - } @@ -2522,7 +2290,7 @@ void Loop::addKnown(const Relation &cond) { last_compute_cgr_ = NULL; delete last_compute_cg_; last_compute_cg_ = NULL; - fprintf(stderr, "Loop::addKnown(), SETTING last_compute_cg_ = NULL\n"); + CHILL_DEBUG_PRINT("Loop::addKnown(), SETTING last_compute_cg_ = NULL\n"); int n1 = this->known.n_set(); diff --git a/src/transformations/loop_basic.cc b/src/transformations/loop_basic.cc index 1afb9be..e0ebfdf 100644 --- a/src/transformations/loop_basic.cc +++ b/src/transformations/loop_basic.cc @@ -815,18 +815,12 @@ std::set<int> Loop::split(int stmt_num, int level, const Relation &cond) { new_stmt.has_inspector = stmt[*i].has_inspector; new_stmt.reduction = stmt[*i].reduction; new_stmt.reductionOp = stmt[*i].reductionOp; - stmt_nesting_level_.push_back(stmt_nesting_level_[*i]); - - if (place_after) assign_const(new_stmt.xform, dim - 1, cur_lex + 1); else assign_const(new_stmt.xform, dim - 1, cur_lex - 1); - - fprintf(stderr, "loop_basic.cc L828 adding stmt %d\n", stmt.size()); stmt.push_back(new_stmt); - uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]); uninterpreted_symbols_stringrepr.push_back(uninterpreted_symbols_stringrepr[stmt_num]); dep.insert(); @@ -1425,7 +1419,7 @@ void Loop::fuse(const std::set<int> &stmt_nums, int level) { void Loop::distribute(const std::set<int> &stmt_nums, int level) { if (stmt_nums.size() == 0 || stmt_nums.size() == 1) return; - fprintf(stderr, "Loop::distribute()\n"); + CHILL_DEBUG_PRINT("Loop::distribute()\n"); // invalidate saved codegen computation |