diff options
Diffstat (limited to 'src/loop_unroll.cc')
-rw-r--r-- | src/loop_unroll.cc | 118 |
1 files changed, 97 insertions, 21 deletions
diff --git a/src/loop_unroll.cc b/src/loop_unroll.cc index 911d900..86ffd84 100644 --- a/src/loop_unroll.cc +++ b/src/loop_unroll.cc @@ -20,6 +20,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, std::vector<std::vector<std::string> > idxNames, int cleanup_split_level) { // check for sanity of parameters + // check for sanity of parameters if (unroll_amount < 0) throw std::invalid_argument( "invalid unroll amount " + to_string(unroll_amount)); @@ -70,6 +71,16 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, } dim2 = stmt[*i].loop_level[dim2].payload; + /*if (dv.isCarried(dim2) + && (dv.hasNegative(dim2) && !dv.quasi)) + throw loop_error( + "loop error: Unrolling is illegal, dependence violation!"); + + if (dv.isCarried(dim2) + && (dv.hasPositive(dim2) && dv.quasi)) + throw loop_error( + "loop error: Unrolling is illegal, dependence violation!"); + */ bool safe = false; if (dv.isCarried(dim2) && dv.hasPositive(dim2)) { @@ -78,11 +89,20 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, "loop error: a quasi dependence with a positive carried distance"); if (!dv.quasi) { if (dv.lbounds[dim2] != posInfinity) { + //if (dv.lbounds[dim2] != negInfinity) if (dv.lbounds[dim2] > unroll_amount) safe = true; } else safe = true; - } + }/* else { + if (dv.ubounds[dim2] != negInfinity) { + if (dv.ubounds[dim2] != posInfinity) + if ((-(dv.ubounds[dim2])) > unroll_amount) + safe = true; + } else + safe = true; + }*/ + if (!safe) { for (int l = level + 1; l <= (n - 1) / 2; l++) { int dim3 = l - 1; @@ -131,7 +151,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, h.update_coef(mapping.output_var(j), -1); } hull = Intersection(hull, - Range(Restrict_Domain(mapping, copy(stmt[*i].IS)))); + omega::Range(Restrict_Domain(mapping, copy(stmt[*i].IS)))); hull.simplify(2, 4); } @@ -288,7 +308,8 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, overflow_table[i][j][NULL] = int_mod_hat( overflow_table[i][j][NULL], unroll_amount); - // Since we don't have MODULO instruction in SUIF yet (only MOD), make all coef positive in the final formula + // Since we don't have MODULO instruction in SUIF yet (only MOD), + // make all coef positive in the final formula for (std::map<Variable_ID, int>::iterator k = overflow_table[i][j].begin(); k != overflow_table[i][j].end(); k++) @@ -437,14 +458,16 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, std::vector<CG_outputRepr *> lb_repr_list, ub_repr_list; for (int i = 0; i < lb_list.size(); i++) { lb_repr_list.push_back( - output_lower_bound_repr(ocg, lb_list[i], + output_lower_bound_repr(ocg, + lb_list[i], bound.set_var(dim + 1), result.first, result.second, bound, Relation::True(bound.n_set()), std::vector<std::pair<CG_outputRepr *, int> >( bound.n_set(), std::make_pair( static_cast<CG_outputRepr *>(NULL), - 0)))); + 0)), + uninterpreted_symbols[stmt_num])); GEQ_Handle h = cond_lower.and_with_GEQ(lb_list[i]); } for (int i = 0; i < ub_list.size(); i++) { @@ -455,21 +478,28 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, bound.n_set(), std::make_pair( static_cast<CG_outputRepr *>(NULL), - 0)))); + 0)), + uninterpreted_symbols[stmt_num])); GEQ_Handle h = cond_upper.and_with_GEQ(ub_list[i]); h.update_coef(cond_upper.get_local(over_free_var), -stride); } - CG_outputRepr *lbRepr, *ubRepr; - if (lb_repr_list.size() > 1) + CG_outputRepr *lbRepr, *ubRepr; + if (lb_repr_list.size() > 1) { + //fprintf(stderr, "loop_unroll.cc createInvoke( max )\n"); lbRepr = ocg->CreateInvoke("max", lb_repr_list); - else if (lb_repr_list.size() == 1) + } + else if (lb_repr_list.size() == 1) { lbRepr = lb_repr_list[0]; + } - if (ub_repr_list.size() > 1) + if (ub_repr_list.size() > 1) { + //fprintf(stderr, "loop_unroll.cc createInvoke( min )\n"); ubRepr = ocg->CreateInvoke("min", ub_repr_list); - else if (ub_repr_list.size() == 1) + } + else if (ub_repr_list.size() == 1) { ubRepr = ub_repr_list[0]; + } // create overflow assignment CG_outputRepr *rhs = ocg->CreatePlus(ocg->CreateMinus(ubRepr, lbRepr), @@ -503,7 +533,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, h.update_coef(mapping.output_var(i), 1); h.update_coef(mapping.input_var(i), -1); } - Relation overflow_IS = Range(Restrict_Domain(mapping, copy(hull))); + Relation overflow_IS = omega::Range(Restrict_Domain(mapping, copy(hull))); for (int i = 1; i < cleanup_split_level; i++) overflow_IS.name_set_var(i, hull.set_var(i)->name()); overflow_IS.setup_names(); @@ -548,7 +578,11 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, stmt[stmt_num].loop_level[i].parallel_level; } + fprintf(stderr, "loop_unroll.cc L581 adding stmt %d\n", stmt.size()); stmt.push_back(overflow_stmt); + + uninterpreted_symbols.push_back(uninterpreted_symbols[stmt_num]); + uninterpreted_symbols_stringrepr.push_back(uninterpreted_symbols_stringrepr[stmt_num]); dep.insert(); overflow_stmt_num = stmt.size() - 1; overflow[overflow_stmt_num] = over_var_list; @@ -567,8 +601,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, dv.type = DEP_W2W; { IR_ScalarSymbol *overflow_sym = NULL; - std::vector<IR_ScalarRef *> scalars = ir->FindScalarRef( - overflow_code); + std::vector<IR_ScalarRef *> scalars = ir->FindScalarRef(overflow_code); for (int i = scalars.size() - 1; i >= 0; i--) if (scalars[i]->is_write()) { overflow_sym = scalars[i]->symbol(); @@ -703,7 +736,12 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, new_stmt.loop_level = stmt[*i].loop_level; new_stmt.ir_stmt_node = NULL; + + fprintf(stderr, "loop_unroll.cc L740 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(); what_stmt_num[*i].push_back(stmt.size() - 1); } @@ -990,33 +1028,70 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, Statement new_stmt; new_stmt.code = NULL; - for (int j = 1; j < unroll_amount; j++) + for (int j = 1; j < unroll_amount; j++) { for (int i = 0; i < stmt_order.size(); i++) { std::vector<std::string> loop_vars; std::vector<CG_outputRepr *> subs; + + //fprintf(stderr, "loop_unroll.cc, will replace '%s with '%s+%d' ??\n", + // stmt[stmt_order[i].second].IS.set_var(level)->name().c_str(), + // stmt[stmt_order[i].second].IS.set_var(level)->name().c_str(), j * stride); + loop_vars.push_back( stmt[stmt_order[i].second].IS.set_var(level)->name()); subs.push_back( - ocg->CreatePlus( - ocg->CreateIdent( - stmt[stmt_order[i].second].IS.set_var( - level)->name()), - ocg->CreateInt(j * stride))); + ocg->CreatePlus(ocg->CreateIdent(stmt[stmt_order[i].second].IS.set_var(level)->name()), + ocg->CreateInt(j * stride))); // BUG HERE + //fprintf(stderr, "loop_unroll.cc subs now has %d parts\n", subs.size()); + //for (int k=0; k< subs.size(); k++) //fprintf(stderr, "subs[%d] = 0x%x\n", k, subs[k]); + + //fprintf(stderr, "ij %d %d ", i, j); + //fprintf(stderr, "old src was =\n"); + //stmt[stmt_order[i].second].code->dump(); fflush(stdout); //fprintf(stderr, "\n"); + + + CG_outputRepr *code = ocg->CreateSubstitutedStmt(0, - stmt[stmt_order[i].second].code->clone(), loop_vars, + stmt[stmt_order[i].second].code->clone(), + loop_vars, subs); + + //fprintf(stderr, "old src is =\n"); + //stmt[stmt_order[i].second].code->dump(); fflush(stdout); //fprintf(stderr, "\n"); + + //fprintf(stderr, "substituted copy is =\n"); + //code->dump(); //fprintf(stderr, "\n\n"); + + new_stmt.code = ocg->StmtListAppend(new_stmt.code, code); + //fprintf(stderr, "appended code =\n"); + //new_stmt.code->dump(); + } + } + + + //fprintf(stderr, "new_stmt.IS = \n"); new_stmt.IS = copy(stmt[stmt_num].IS); new_stmt.xform = copy(stmt[stmt_num].xform); assign_const(new_stmt.xform, 2 * max_level, stmt_order[stmt_order.size() - 1].first + 1); new_stmt.loop_level = stmt[stmt_num].loop_level; new_stmt.ir_stmt_node = NULL; + + new_stmt.has_inspector = false; // ?? or from copied stmt? + if (stmt[stmt_num].has_inspector) fprintf(stderr, "OLD STMT HAS INSPECTOR\n"); + else fprintf(stderr, "OLD STMT DOES NOT HAVE INSPECTOR\n"); + + fprintf(stderr, "loop_unroll.cc L1083 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(); + //fprintf(stderr, "update dependence graph\n"); // update dependence graph if (stmt[stmt_num].loop_level[level - 1].type == LoopLevelOriginal) { int dep_dim = stmt[stmt_num].loop_level[level - 1].payload; @@ -1140,6 +1215,7 @@ std::set<int> Loop::unroll(int stmt_num, int level, int unroll_amount, } } + //fprintf(stderr, " loop_unroll.cc returning new_stmts\n"); return new_stmts; } |