diff options
Diffstat (limited to 'src')
-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 |
7 files changed, 83 insertions, 547 deletions
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 |