/* 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; }
PlutoMatrix *phi; Stmt **stmts; nvar = prog->nvar; npar = prog->npar; stmts = prog->stmts; nstmts = prog->nstmts; /* IMPORTANT: It's assumed that all statements are of dimensionality nvar */ IF_DEBUG(printf("[pluto] compute permutability constraints: Dep %d\n", dep->id+1);); dest_stmt = dep->dest; src_stmt = dep->src; PlutoConstraints *dpoly = pluto_constraints_dup(dep->dpolytope); if (src_stmt != dest_stmt) { phi = pluto_matrix_alloc(2*nvar+npar+1, 2*(nvar+1)+1); pluto_matrix_set(phi, 0); for (r=0; r<nvar; r++) { /* Source stmt */ phi->val[r][r] = -1; } for (r=nvar; r<2*nvar; r++) { /* Dest stmt */ phi->val[r][(nvar+1)+(r-nvar)] = 1; } /* No parametric shifts: all zero for 2*nvar to 2*nvar+npar */
/* 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"); } }