int pluto_constraints_are_equal(const PlutoConstraints *cst1, const PlutoConstraints *cst2) { PlutoConstraints *diff = pluto_constraints_difference(cst1,cst2); int are_constraints_equal = pluto_constraints_is_empty(diff); pluto_constraints_free(diff); if (are_constraints_equal) { diff = pluto_constraints_difference(cst2, cst1); are_constraints_equal = pluto_constraints_is_empty(diff); pluto_constraints_free(diff); } return are_constraints_equal; }
/* * Project out from a single element list of constraints * start: 0-indexed * */ void pluto_constraints_project_out_single( PlutoConstraints *cst, int start, int num) { int i, end; assert(num>= 0); if (num == 0) return; end = start + num - 1; assert(start >= 0 && end <= cst->ncols-2); PlutoMatrix *func = pluto_matrix_alloc(cst->ncols-num, cst->ncols); pluto_matrix_initialize(func, 0); for (i=0; i<start; i++) { func->val[i][i] = 1; } for (i=end+1; i<cst->ncols; i++) { func->val[i-num][i] = 1; } PlutoConstraints *img = pluto_constraints_image(cst, func); pluto_constraints_copy_single(cst, img); pluto_constraints_free(img); pluto_matrix_free(func); }
/* Get upper bound for the pos^th variable if it's a (single) constant: return * 0 if not constant, 1 otherwise */ int pluto_constraints_get_const_ub(const PlutoConstraints *cnst, int pos, int *ub) { int i, retval; PlutoConstraints *cst = pluto_constraints_dup(cnst); pluto_constraints_project_out_single(cst, 0, pos); pluto_constraints_project_out_single(cst, 1, cst->ncols-2); //pluto_constraints_project_out_single_isl(cst, 0, pos); //pluto_constraints_project_out_single_isl(cst, 1, cst->ncols-2); retval = 0; *ub = INT_MAX; for (i=0; i<cst->nrows; i++) { if (cst->is_eq[i]) { *ub = cst->val[i][cst->ncols-1]; retval = 1; break; } if (!cst->is_eq[i] && cst->val[i][0] <= -1) { *ub = PLMIN(*ub,cst->val[i][cst->ncols-1]); retval = 1; } } pluto_constraints_free(cst); if (retval && cnst->next != NULL) { int next_ub; retval = pluto_constraints_get_const_ub(cnst->next, pos, &next_ub); if (*ub != next_ub) retval = 0; } return retval; }
/* Get lower bound for pos^th variable if it's a (single) constant: return 0 * if not constant, 1 otherwise */ int pluto_constraints_get_const_lb(const PlutoConstraints *cnst, int pos, int *lb) { int i, retval; PlutoConstraints *cst = pluto_constraints_dup(cnst); pluto_constraints_project_out_single(cst, 0, pos); pluto_constraints_project_out_single(cst, 1, cst->ncols-2); retval = 0; *lb = INT_MIN; for (i=0; i<cst->nrows; i++) { if (cst->is_eq[i]) { *lb = cst->val[i][cst->ncols-1]; retval = 1; break; } if (!cst->is_eq[i] && cst->val[i][0] >= 1) { retval = 1; *lb = PLMAX(*lb,-cst->val[i][cst->ncols-1]); } } pluto_constraints_free(cst); if (retval && cnst->next != NULL) { int next_lb; retval = pluto_constraints_get_const_lb(cnst->next, pos, &next_lb); if (*lb != next_lb) retval = 0; } return retval; }
/* In-place union: first argument is modified */ PlutoConstraints *pluto_constraints_unionize(PlutoConstraints *cst1, const PlutoConstraints *cst2) { PlutoConstraints *ucst = pluto_constraints_union(cst1, cst2); pluto_constraints_copy(cst1, ucst); pluto_constraints_free(ucst); return cst1; }
/* In-place difference: Like difference, but first argument is modified */ PlutoConstraints *pluto_constraints_subtract(PlutoConstraints *cst1, const PlutoConstraints *cst2) { PlutoConstraints *dcst = pluto_constraints_difference(cst1,cst2); pluto_constraints_copy(cst1,dcst); pluto_constraints_free(dcst); return cst1; }
/* In-place intersection: first argument is modified */ PlutoConstraints *pluto_constraints_intersect(PlutoConstraints *cst1, const PlutoConstraints *cst2) { PlutoConstraints *icst = pluto_constraints_intersection(cst1, cst2); pluto_constraints_copy(cst1, icst); pluto_constraints_free(icst); return cst1; }
static int extract_basic_set(__isl_take isl_basic_set *bset, void *user) { Stmt **stmts; Stmt *stmt; PlutoConstraints *bcst; struct pluto_extra_stmt_info *info; info = (struct pluto_extra_stmt_info *)user; stmts = info->stmts; stmt = stmts[info->index]; bcst = isl_basic_set_to_pluto_constraints(bset); if (stmt->domain) { stmt->domain = pluto_constraints_unionize_simple(stmt->domain, bcst); pluto_constraints_free(bcst); }else{ stmt->domain = bcst; } isl_basic_set_free(bset); return 0; }
/* Generate and print .cloog file from the transformations computed */ void pluto_gen_cloog_file(FILE *fp, const PlutoProg *prog) { int i; Stmt **stmts = prog->stmts; int nstmts = prog->nstmts; int npar = prog->npar; IF_DEBUG(printf("[pluto] generating Cloog file...\n")); fprintf(fp, "# CLooG script generated automatically by PLUTO %s\n", PLUTO_VERSION); fprintf(fp, "# language: C\n"); fprintf(fp, "c\n\n"); /* Context: setting conditions on parameters */ PlutoConstraints *ctx = pluto_constraints_dup(prog->context); // TODO disabled because prog->codegen_context is not set //pluto_constraints_intersect_isl(ctx, prog->codegen_context); pluto_constraints_print_polylib(fp, ctx); pluto_constraints_free(ctx); fprintf(fp, "# parameter names \n\n"); /* Setting parameter names */ fprintf(fp, "\n1\n"); for (i=0; i<npar; i++) { fprintf(fp, "%s ", prog->params[i]); } fprintf(fp, "\n\n"); fprintf(fp, "# Number of statements\n"); fprintf(fp, "%d\n\n", nstmts); /* Print statement domains */ for (i=0; i<nstmts; i++) { fprintf(fp, "# S%d (%s)\n", stmts[i]->id+1, stmts[i]->text); pluto_constraints_print_polylib(fp, stmts[i]->domain); fprintf(fp, "0 0 0\n\n"); } fprintf(fp, "# we want cloog to set the iterator names\n"); fprintf(fp, "0\n\n"); fprintf(fp, "# Number of scattering functions\n"); if (nstmts >= 1 && stmts[0]->trans != NULL) { fprintf(fp, "%d\n\n", nstmts); /* Print scattering functions */ for (i=0; i<nstmts; i++) { fprintf(fp, "# T(S%d)\n", i+1); PlutoConstraints *sched = pluto_stmt_get_schedule(stmts[i]); pluto_constraints_print_polylib(fp, sched); fprintf(fp, "\n"); pluto_constraints_free(sched); } /* Setting target loop names (all stmts have same number of hyperplanes */ fprintf(fp, "# we will set the scattering dimension names\n"); fprintf(fp, "%d\n", stmts[0]->trans->nrows); for (i=0; i<stmts[0]->trans->nrows; i++) { fprintf(fp, "t%d ", i+1); } fprintf(fp, "\n"); }else{ fprintf(fp, "0\n\n"); } }