/* 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; }
/* * Output schedules are isl relations that have dims in the order * isl_dim_out, isl_dim_in, div, param, const */ __isl_give isl_union_map *pluto_schedule(isl_union_set *domains, isl_union_map *dependences, PlutoOptions *options_l) { int i, j, nbands, n_ibands, retval; isl_ctx *ctx; isl_space *space; ctx = isl_union_set_get_ctx(domains); space = isl_union_set_get_space(domains); // isl_union_set_dump(domains); // isl_union_map_dump(dependences); options = options_l; PlutoProg *prog = pluto_prog_alloc(); prog->nvar = -1; prog->nstmts = isl_union_set_n_set(domains); if (prog->nstmts >= 1) { prog->stmts = (Stmt **)malloc(prog->nstmts * sizeof(Stmt *)); }else{ prog->stmts = NULL; } for (i=0; i<prog->nstmts; i++) { prog->stmts[i] = NULL; } extract_stmts(domains, prog->stmts); for (i=0; i<prog->nstmts; i++) { prog->nvar = PLMAX(prog->nvar, prog->stmts[i]->dim); } if (prog->nstmts >= 1) { Stmt *stmt = prog->stmts[0]; prog->npar = stmt->domain->ncols - stmt->dim - 1; prog->params = (char **) malloc(sizeof(char *)*prog->npar); }else prog->npar = 0; for (i=0; i<prog->npar; i++) { prog->params[i] = NULL; } prog->ndeps = 0; isl_union_map_foreach_map(dependences, &isl_map_count, &prog->ndeps); prog->deps = (Dep **)malloc(prog->ndeps * sizeof(Dep *)); for (i=0; i<prog->ndeps; i++) { prog->deps[i] = pluto_dep_alloc(); } extract_deps(prog->deps, 0, prog->stmts, dependences, OSL_DEPENDENCE_RAW); IF_DEBUG(pluto_prog_print(prog););
/* Non-destructive resize */ void pluto_matrix_resize(PlutoMatrix *mat, int nrows, int ncols) { int i; int alloc_nrows = PLMAX(nrows,mat->alloc_nrows); int alloc_ncols = PLMAX(ncols,mat->alloc_ncols); mat->val = (int64 **) realloc(mat->val, alloc_nrows*sizeof(int64 *)); for (i=mat->alloc_nrows; i<alloc_nrows; i++) { mat->val[i] = NULL; } for (i=0; i<alloc_nrows; i++) { mat->val[i] = (int64 *) realloc(mat->val[i], alloc_ncols*sizeof(int64)); } mat->alloc_nrows = alloc_nrows; mat->alloc_ncols = alloc_ncols; mat->nrows = nrows; mat->ncols = ncols; }
/* * Allocated; not initialized * * nrows and ncols initialized to allocated number of rows and cols */ PlutoMatrix *pluto_matrix_alloc(int alloc_nrows, int alloc_ncols) { int i; PlutoMatrix *mat; assert(alloc_nrows >= 0); assert(alloc_ncols >= 0); mat = (PlutoMatrix *) malloc(sizeof(PlutoMatrix)); mat->val = (int64 **) malloc(PLMAX(alloc_nrows,1)*sizeof(int64 *)); mat->alloc_nrows = PLMAX(alloc_nrows,1); mat->alloc_ncols = PLMAX(alloc_ncols,1); for (i=0; i<mat->alloc_nrows; i++) { mat->val[i] = (int64 *) malloc(mat->alloc_ncols*sizeof(int64)); } mat->nrows = alloc_nrows; mat->ncols = alloc_ncols; return mat; }