osl_scop_p cseed_scop_read_from_c(FILE* input, char* input_name) { clan_options_p clanoptions; osl_scop_p scop; clanoptions = clan_options_malloc(); clanoptions->precision = OSL_PRECISION_MP; CLAN_strdup(clanoptions->name, input_name); scop = clan_scop_extract(input, clanoptions); clan_options_free(clanoptions); return scop; }
int main(int argc, char *argv[]) { int i; FILE *src_fp; int option; int option_index = 0; char *srcFileName; FILE *cloogfp, *outfp; if (argc <= 1) { usage_message(); return 1; } options = pluto_options_alloc(); const struct option pluto_options[] = { {"tile", no_argument, &options->tile, 1}, {"notile", no_argument, &options->tile, 0}, {"intratileopt", no_argument, &options->intratileopt, 1}, {"debug", no_argument, &options->debug, true}, {"moredebug", no_argument, &options->moredebug, true}, {"rar", no_argument, &options->rar, 1}, {"identity", no_argument, &options->identity, 1}, {"nofuse", no_argument, &options->fuse, NO_FUSE}, {"maxfuse", no_argument, &options->fuse, MAXIMAL_FUSE}, {"smartfuse", no_argument, &options->fuse, SMART_FUSE}, {"parallel", no_argument, &options->parallel, 1}, {"parallelize", no_argument, &options->parallel, 1}, {"innerpar", no_argument, &options->innerpar, 1}, {"unroll", no_argument, &options->unroll, 1}, {"nounroll", no_argument, &options->unroll, 0}, {"polyunroll", no_argument, &options->polyunroll, 1}, {"bee", no_argument, &options->bee, 1}, {"ufactor", required_argument, 0, 'u'}, {"prevector", no_argument, &options->prevector, 1}, {"noprevector", no_argument, &options->prevector, 0}, {"context", required_argument, 0, 'c'}, {"cloogf", required_argument, 0, 'F'}, {"cloogl", required_argument, 0, 'L'}, {"cloogsh", no_argument, &options->cloogsh, 1}, {"nocloogbacktrack", no_argument, &options->cloogbacktrack, 0}, {"forceparallel", required_argument, 0, 'p'}, {"ft", required_argument, 0, 'f'}, {"lt", required_argument, 0, 'l'}, {"multipipe", no_argument, &options->multipipe, 1}, {"l2tile", no_argument, &options->l2tile, 1}, {"version", no_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"indent", no_argument, 0, 'i'}, {"silent", no_argument, &options->silent, 1}, {"lastwriter", no_argument, &options->lastwriter, 1}, {"nobound", no_argument, &options->nobound, 1}, {"scalpriv", no_argument, &options->scalpriv, 1}, {"isldep", no_argument, &options->isldep, 1}, {"isldepcompact", no_argument, &options->isldepcompact, 1}, {"readscoplib", no_argument, &options->readscoplib, 1}, {"islsolve", no_argument, &options->islsolve, 1}, {0, 0, 0, 0} }; /* Read command-line options */ while (1) { option = getopt_long(argc, argv, "bhiqvf:l:F:L:c:o:", pluto_options, &option_index); if (option == -1) { break; } switch (option) { case 0: break; case 'F': options->cloogf = atoi(optarg); break; case 'L': options->cloogl = atoi(optarg); break; case 'b': options->bee = 1; break; case 'c': options->context = atoi(optarg); break; case 'd': break; case 'f': options->ft = atoi(optarg); break; case 'g': break; case 'h': usage_message(); return 2; case 'i': /* Handled in polycc */ break; case 'l': options->lt = atoi(optarg); break; case 'm': break; case 'n': break; case 'o': options->out_file = strdup(optarg); break; case 'p': options->forceparallel = atoi(optarg); break; case 'q': options->silent = 1; break; case 's': break; case 'u': options->ufactor = atoi(optarg); break; case 'v': printf("PLUTO %s - An automatic parallelizer and locality optimizer\n\ Copyright (C) 2007--2008 Uday Kumar Bondhugula\n\ This is free software; see the source for copying conditions. There is NO\n\ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n", PLUTO_VERSION); pluto_options_free(options); return 3; default: usage_message(); pluto_options_free(options); return 4; } } if (optind <= argc-1) { srcFileName = alloca(strlen(argv[optind])+1); strcpy(srcFileName, argv[optind]); }else{ /* No non-option argument was specified */ usage_message(); pluto_options_free(options); return 5; } src_fp = fopen(srcFileName, "r"); if (!src_fp) { fprintf(stderr, "pluto: error opening source file: '%s'\n", srcFileName); pluto_options_free(options); return 6; } /* Extract polyhedral representation from input program */ scoplib_scop_p scop; clan_options_p clanOptions = clan_options_malloc(); if (options->readscoplib) scop = scoplib_scop_read(src_fp); else scop = clan_scop_extract(src_fp, clanOptions); if (!scop || !scop->statement) { fprintf(stderr, "Error extracting polyhedra from source file: \'%s'\n", srcFileName); pluto_options_free(options); return 7; } FILE *srcfp = fopen(".srcfilename", "w"); if (srcfp) { fprintf(srcfp, "%s\n", srcFileName); fclose(srcfp); } /* IF_DEBUG(clan_scop_print_dot_scop(stdout, scop, clanOptions)); */ /* Convert clan scop to Pluto program */ PlutoProg *prog = scop_to_pluto_prog(scop, options); clan_options_free(clanOptions); /* Backup irregular program portion in .scop. */ char* irroption = scoplib_scop_tag_content(scop, "<irregular>", "</irregular>"); IF_DEBUG2(pluto_deps_print(stdout, prog)); IF_DEBUG2(pluto_stmts_print(stdout, prog->stmts, prog->nstmts)); int dim_sum=0; for (i=0; i<prog->nstmts; i++) { dim_sum += prog->stmts[i]->dim; } /* Make options consistent */ if (options->multipipe == 1 && options->parallel == 0) { fprintf(stdout, "Warning: multipipe needs parallel to be on; turning on parallel\n"); options->parallel = 1; } /* Disable pre-vectorization if tile is not on */ if (options->tile == 0 && options->prevector == 1) { /* If code will not be tiled, pre-vectorization does not make * sense */ if (!options->silent) { fprintf(stdout, "[Pluto] Warning: pre-vectorization does not fit (--tile is off)\n"); } options->prevector = 0; } if (!options->silent) { fprintf(stdout, "[Pluto] Number of statements: %d\n", prog->nstmts); fprintf(stdout, "[Pluto] Total number of loops: %d\n", dim_sum); fprintf(stdout, "[Pluto] Number of deps: %d\n", prog->ndeps); fprintf(stdout, "[Pluto] Maximum domain dimensionality: %d\n", prog->nvar); fprintf(stdout, "[Pluto] Number of parameters: %d\n", prog->npar); } /* Auto transformation */ if (!options->identity) { pluto_auto_transform(prog); } pluto_detect_transformation_properties(prog); if (!options->silent) { fprintf(stdout, "[Pluto] Affine transformations [<iter coeff's> <const>]\n\n"); /* Print out transformations */ pluto_transformations_pretty_print(prog); pluto_print_hyperplane_properties(prog); } if (options->tile) { pluto_tile(prog); }else{ if (options->intratileopt) { int retval = pluto_intra_tile_optimize(prog, 0); if (retval) { /* Detect properties again */ pluto_detect_transformation_properties(prog); if (!options->silent) { printf("[Pluto] after intra tile opt\n"); pluto_transformations_pretty_print(prog); } } } } if (options->parallel && !options->tile && !options->identity) { /* Obtain wavefront/pipelined parallelization by skewing if * necessary */ int nbands; Band **bands; bands = pluto_get_outermost_permutable_bands(prog, &nbands); bool retval = create_tile_schedule(prog, bands, nbands); pluto_bands_free(bands, nbands); /* If the user hasn't supplied --tile and there is only pipelined * parallelism, we will warn the user */ if (retval) { printf("[Pluto] WARNING: pipelined parallelism exists and --tile is not used.\n"); printf("use --tile for better parallelization \n"); IF_DEBUG(fprintf(stdout, "[Pluto] After skewing:\n");); IF_DEBUG(pluto_transformations_pretty_print(prog););
int main(int argc, char * argv[]) { osl_scop_p scop = NULL; osl_generic_p x, last; osl_clay_p clay_tag; clay_options_p options; int parsing_result = 0; // Read command line parameters options = clay_options_read(argc, argv); if (options->print_infos) { clay_options_free(options); exit(0); } // Open the scop file #ifdef CLAN_LINKED if (options->readc) { clan_options_p clan_opt = clan_options_malloc(); clan_opt->precision = OSL_PRECISION_MP; clan_opt->name = options->input_name; clan_opt->extbody = 1; scop = clan_scop_extract(options->input, clan_opt); //clan_options_free(clan_opt); // bug, the name is also freed free(clan_opt); fclose(options->input); } else #endif { scop = osl_scop_read(options->input); if (options->input != stdin) fclose(options->input); } if (options->normalize) { clay_beta_normalize(scop); } #if defined(CANDL_LINKED) osl_scop_p orig_scop = NULL; if (!options->nocandl && scop != NULL) { orig_scop = osl_scop_clone(scop); } #endif // Execute the script ... // do nothing if the scop is NULL if (scop != NULL) { // Read the script file if (!options->from_tag) { parsing_result = clay_parser_file(scop, options->script, options); if (parsing_result != 0) { fprintf(stderr, "[Clay] %s\n", clay_get_error_message()); } fclose(options->script); // Read the script from the extension clay } else { // equivalent to osl_generic_lookup, but we need the last extension // to remove the clay extension in the list x = scop->extension; last = NULL; while (x != NULL) { if (osl_generic_has_URI(x, OSL_URI_CLAY)) break; last = x; x = x->next; } if (x != NULL) { // parse the clay string clay_tag = x->data; parsing_result = clay_parser_string(scop, clay_tag->script, options); if (parsing_result != 0) { fprintf(stderr, "[Clay] %s\n", clay_get_error_message()); } // remove the extension clay osl_generic_remove(&scop->extension, OSL_URI_CLAY); } } } #ifdef CANDL_LINKED int is_violated = 0; // Check dependencies if (!options->nocandl && scop != NULL && parsing_result == 0) { candl_options_p candl_opt = candl_options_malloc(); if (options->candl_fullcheck) candl_opt->fullcheck = 1; candl_scop_usr_init(orig_scop); candl_violation_p violation = candl_violation(orig_scop, scop, 0, candl_opt); is_violated = (violation != NULL); if (is_violated) { candl_violation_pprint(stdout, violation); if (options->candl_structure) candl_violation_dump(stdout, violation); } candl_scop_usr_cleanup(orig_scop); candl_options_free(candl_opt); candl_violation_free(violation); osl_scop_free(orig_scop); } if (!is_violated) // print the scop or the .c file by cloog #endif { #ifdef CLOOG_LINKED if (options->printc && scop != NULL && parsing_result == 0) { clay_util_scop_export_body(scop); CloogState *state = cloog_state_malloc(); CloogOptions *cloogoptions = cloog_options_malloc(state); cloogoptions->openscop = 1; CloogInput *clooginput = cloog_input_from_osl_scop(cloogoptions->state, scop); cloog_options_copy_from_osl_scop(scop, cloogoptions); CloogProgram *program = cloog_program_alloc(clooginput->context, clooginput->ud, cloogoptions); free(clooginput); cloog_program_generate(program, cloogoptions); cloog_program_pprint(stdout, program, cloogoptions); cloog_program_free(program); cloogoptions->scop = NULL; // don't free the scop cloog_options_free(cloogoptions); cloog_state_free(state); } else #endif { if (parsing_result == 0) { if (!options->keep_extbody) clay_util_scop_export_body(scop); osl_scop_print(stdout, scop); } } } osl_scop_free(scop); clay_options_free(options); return parsing_result; }