isl_set *nfm_constraint_from_set(isl_ctx *ctx, nfm_constraint *constraints) { isl_printer *p; assert(ctx); assert(constraints); IF_DEBUG(fprintf(stdout, " Transforming a constraint into ISL set.\n")); p = isl_printer_to_str(ctx); p = isl_printer_print_pw_qpolynomial(p, constraints->constraint); char *str = isl_printer_get_str(p); IF_DEBUG(fprintf(stdout, " The input Qpolynomianl constraint: %s\n", str)); assert(str); /* Translate the qpolynomial into a map. */ char *set_str = (char *) malloc((strlen(str)+10)*sizeof(char)); strcpy(set_str, str); IF_DEBUG2(fprintf(stdout, " set_str=%s\n", set_str)); size_t pos_arrow = strcspn(str, ">"); set_str[pos_arrow-1] = ' '; set_str[pos_arrow] = ':'; IF_DEBUG2(fprintf(stdout, " set_str=%s\n", set_str)); size_t pos_colon = strcspn(&(str[pos_arrow+1]), ":"); if (strchr(&(str[pos_arrow+1]), ':') != NULL) { set_str[pos_arrow+1+pos_colon] = ' '; IF_DEBUG2(fprintf(stdout, " set_str=%s\n", set_str)); if (constraints->eq == 1) strcpy(&(set_str[pos_arrow+1+pos_colon]), " = 0 and "); else strcpy(&(set_str[pos_arrow+1+pos_colon]), " >= 0 and "); IF_DEBUG2(fprintf(stdout, " set_str=%s\n", set_str)); strncpy(&(set_str[pos_arrow+pos_colon+10]), &(str[pos_arrow+1+pos_colon+1]), strlen(str) - pos_arrow - pos_colon); IF_DEBUG2(fprintf(stdout, " set_str=%s\n", set_str)); } else { size_t pos_bracket = strcspn(str, "}"); set_str[pos_bracket] = ' '; if (constraints->eq == 1) strcat(&(set_str[pos_bracket]), " = 0 }"); else strcat(&(set_str[pos_bracket]), " >= 0 }"); } IF_DEBUG(fprintf(stdout, " The Qpolynomial translated into a set is: %s\n", set_str)); isl_set *set = isl_set_read_from_str(ctx, set_str); isl_printer_free(p); return set; }
/* Transform the code in the file called "input" by replacing * all scops by corresponding OpenCL code. * The host code is written to "output" or a name derived from * "input" if "output" is NULL. * The kernel code is placed in separate files with names * derived from "output" or "input". * * We let generate_gpu do all the hard work and then let it call * us back for printing the AST in print_opencl. * * To prepare for this printing, we first open the output files * and we close them after generate_gpu has finished. */ int generate_opencl(isl_ctx *ctx, struct ppcg_options *options, const char *input, const char *output) { struct opencl_info opencl = { options, input, output }; int r; opencl.kprinter = isl_printer_to_str(ctx); r = opencl_open_files(&opencl); if (r >= 0) r = generate_gpu(ctx, input, opencl.host_c, options, &print_opencl, &opencl); if (opencl_close_files(&opencl) < 0) r = -1; isl_printer_free(opencl.kprinter); return r; }