Пример #1
0
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;
}
Пример #2
0
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););