From cdbafa13f1527dbca78af9e59c9026d47032692d Mon Sep 17 00:00:00 2001 From: Taj Muhammad Khan Date: Wed, 12 Feb 2014 18:55:15 +0100 Subject: [PATCH 1/3] Added multi-scop support in osl mode --- include/cloog/input.h | 4 +- include/cloog/options.h | 5 +- include/cloog/program.h | 3 + source/cloog.c | 2 + source/input.c | 40 +- source/options.c | 99 ++- source/program.c | 1142 +++++++++++++++++++++++++--------- test/Makefile.am | 1 + test/openscop/multiscop.c | 30 + test/openscop/multiscop.scop | 392 ++++++++++++ 10 files changed, 1410 insertions(+), 308 deletions(-) create mode 100644 test/openscop/multiscop.c create mode 100644 test/openscop/multiscop.scop diff --git a/include/cloog/input.h b/include/cloog/input.h index b3d3c53..ce8dc2b 100644 --- a/include/cloog/input.h +++ b/include/cloog/input.h @@ -6,14 +6,16 @@ extern "C" { #endif struct osl_scop; +struct clooginput; struct clooginput { CloogDomain *context; CloogUnionDomain *ud; + struct clooginput* next; }; typedef struct clooginput CloogInput; -CloogInput *cloog_input_from_osl_scop(CloogState *, struct osl_scop *); +CloogInput *cloog_input_from_osl_scop(CloogState *state, struct osl_scop *scop); CloogInput *cloog_input_read(FILE *file, CloogOptions *options); CloogInput *cloog_input_alloc(CloogDomain *context, CloogUnionDomain *ud); void cloog_input_free(CloogInput *input); diff --git a/include/cloog/options.h b/include/cloog/options.h index f4dd70e..1319cfa 100644 --- a/include/cloog/options.h +++ b/include/cloog/options.h @@ -123,6 +123,7 @@ struct cloogoptions int noblocks ; /* 1 if I don't want to make statement blocks, 0 otherwise. */ int noscalars ; /* 1 if I don't want to use scalar dimensions, 0 otherwise. */ int nosimplify; /* 1 if I don't want to simplify polyhedra, 0 otherwise. */ + CloogOptions* next;/* Pointer to the next CloogOptions */ } ; @@ -160,7 +161,9 @@ void cloog_options_read(CloogState *state, int argc, char **argv, * Processing functions * ******************************************************************************/ CloogOptions *cloog_options_malloc(CloogState *state); -void cloog_options_copy_from_osl_scop(struct osl_scop *, CloogOptions *); +void cloog_options_copy_from_osl_scop(struct osl_scop *scop, + CloogOptions *options); +CloogOptions* cloog_options_clone(CloogOptions *options); #if defined(__cplusplus) diff --git a/include/cloog/program.h b/include/cloog/program.h index 530d21f..6bba0fc 100644 --- a/include/cloog/program.h +++ b/include/cloog/program.h @@ -65,6 +65,7 @@ struct cloogprogram int * scaldims ; /**< Boolean array saying whether a given * scattering dimension is scalar or not. */ + struct cloogprogram * next ; /**< Pointer to next program */ /* Library user reserved field. */ void * usr; /**< User field, for library user convenience. * This pointer is not freed when the @@ -108,6 +109,8 @@ void cloog_program_extract_scalars(CloogProgram *program, CloogScatteringList *scattering, CloogOptions *options); void cloog_program_scatter(CloogProgram *program, CloogScatteringList *scattering, CloogOptions *options); +void cloog_program_sort_ascending(CloogProgram **program, CloogOptions **ops); +int cloog_program_verify_coordinates(CloogProgram *program, CloogOptions *ops); #if defined(__cplusplus) } diff --git a/source/cloog.c b/source/cloog.c index 0a42a67..437de56 100644 --- a/source/cloog.c +++ b/source/cloog.c @@ -59,6 +59,8 @@ int main(int argv, char * argc[]) program = cloog_program_generate(program,options) ; if (options->structure) cloog_program_print(stdout,program) ; + /* Sort the program in ascending order of coordinates*/ + cloog_program_sort_ascending(&program, &options); cloog_program_pprint(output,program,options) ; cloog_program_free(program) ; diff --git a/source/input.c b/source/input.c index 8195392..b129558 100644 --- a/source/input.c +++ b/source/input.c @@ -65,10 +65,29 @@ CloogInput *cloog_input_read(FILE *file, CloogOptions *options) #ifdef OSL_SUPPORT if (options->openscop) { - osl_scop_p scop = osl_scop_read(file); - CloogInput * input = cloog_input_from_osl_scop(options->state, - scop); - cloog_options_copy_from_osl_scop(scop, options); + osl_scop_p scop = NULL; + CloogInput * input = NULL; + CloogOptions **newops = &options; + CloogInput ** iptr_addr = &input; + + scop = osl_scop_read(file); + + int first = 1; + //convert SCoPs to inputs one-by-one + while (scop) { + *iptr_addr = cloog_input_from_osl_scop(options->state, scop); + if(!first) *newops = cloog_options_clone(options); + cloog_options_copy_from_osl_scop(scop, *newops); + first = 0; + + scop = scop->next; + //de-link the scop saved in options from the list + //To be sandwiched b/w 2 stmts (above and below) + (*newops)->scop->next = NULL; + newops = &(*newops)->next; + iptr_addr = &(*iptr_addr)->next; + } + return input; } #endif @@ -106,15 +125,22 @@ CloogInput *cloog_input_alloc(CloogDomain *context, CloogUnionDomain *ud) input->context = context; input->ud = ud; + input->next = NULL; return input; } void cloog_input_free(CloogInput *input) { - cloog_domain_free(input->context); - cloog_union_domain_free(input->ud); - free(input); + while (input) { + CloogInput* tmp = input; + + cloog_domain_free(input->context); + cloog_union_domain_free(input->ud); + + input = input->next; + free(tmp); + } } static void print_names(FILE *file, CloogUnionDomain *ud, diff --git a/source/options.c b/source/options.c index 3689c0c..708cb81 100644 --- a/source/options.c +++ b/source/options.c @@ -175,14 +175,22 @@ void cloog_options_print(FILE * foo, CloogOptions * options) */ void cloog_options_free(CloogOptions *options) { + if (options==NULL) + return; + + while(options){ + CloogOptions* tmp = options; #ifdef OSL_SUPPORT - if (options->scop != NULL) { - osl_scop_free(options->scop); - } + if (options->scop != NULL) { + osl_scop_free(options->scop); + } #endif - free(options->fs); - free(options->ls); - free(options); + free(options->fs); + free(options->ls); + free(options->name); + options = options->next; + free(tmp); + } } @@ -341,7 +349,7 @@ CloogOptions *cloog_options_malloc(CloogState *state) options->strides = 0 ; /* Generate a code with unit strides. */ options->sh = 0; /* Compute actual convex hull. */ options->first_unroll = -1; /* First level to unroll: none. */ - options->name = ""; + options->name = NULL; /* OPTIONS FOR PRETTY PRINTING */ options->esp = 1 ; /* We want Equality SPreading.*/ options->fsp = 1 ; /* The First level to SPread is the first. */ @@ -363,6 +371,7 @@ CloogOptions *cloog_options_malloc(CloogState *state) options->noblocks = 0 ; /* I do want to make statement blocks.*/ options->noscalars = 0 ; /* I do want to use scalar dimensions.*/ options->nosimplify = 0 ; /* I do want to simplify polyhedra.*/ + options->next = NULL ; /* NULL by default.*/ return options ; } @@ -494,7 +503,7 @@ void cloog_options_read(CloogState *state, int argc, char **argv, else { if (!input_is_set) { input_is_set = 1 ; - (*options)->name = argv[i] ; + (*options)->name = strdup(argv[i]); /* stdin is a special value, when used, we set input to standard input. */ if (strcmp(argv[i],"stdin") == 0) *input = stdin ; @@ -515,6 +524,78 @@ void cloog_options_read(CloogState *state, int argc, char **argv, } #ifdef OSL_SUPPORT + + +/** + * This function clones a hard copy of CloogOptions structure + * except the "scop" pointer. + * + * \param[in] ops pointer to CloogOptions struct to clone + * \return cloned CloogOptions pointer + */ +CloogOptions* cloog_options_clone(CloogOptions *ops){ + int j = 0; + CloogOptions* cops = NULL; + + if(ops==NULL) return NULL; + + /* keep the state */ + cops = cloog_options_malloc(ops->state); + + /* We set the various fields with default values. */ + /* OPTIONS FOR LOOP GENERATION */ + cops->l = ops->l ; + cops->f = ops->f ; + cops->fs_ls_size = ops->fs_ls_size; + + + if (cops->fs_ls_size) { //without this if(), malloc(0) returns non-NULL ptr + //that messes up a lot of things + cops->ls = (int*) malloc( ops->fs_ls_size*sizeof(int) ); + cops->fs = (int*) malloc( ops->fs_ls_size*sizeof(int) ); + if (cops->ls==NULL || cops->fs==NULL) + cloog_die("memory overflow.\n"); + } + + for (j=0; j< cops->fs_ls_size; j++) { + cops->ls[j] = ops->ls[j]; + cops->fs[j] = ops->fs[j]; + } + cops->stop = ops->stop ; + cops->strides = ops->strides; + cops->sh = ops->sh; + cops->first_unroll = ops->first_unroll; + cops->name = strdup(ops->name); + /* OPTIONS FOR PRETTY PRINTING */ + cops->esp = ops->esp; + cops->fsp = ops->fsp; + cops->otl = ops->otl; + cops->block = ops->block; + cops->compilable = ops->compilable; + cops->callable = ops->callable; + cops->quiet = ops->quiet; + cops->save_domains = ops->save_domains; + /* MISC OPTIONS */ + cops->language = ops->language; + cops->time = ops->time; + cops->openscop = ops->openscop; + cops->scop = NULL; +#ifdef CLOOG_MEMORY + cops->memory = ops->memory; +#endif + /* UNDOCUMENTED OPTIONS FOR THE AUTHOR ONLY */ + cops->leaks = ops->leaks; + cops->backtrack = ops->backtrack; + cops->override = ops->override; + cops->structure = ops->structure; + cops->noblocks = ops->noblocks; + cops->noscalars = ops->noscalars; + cops->nosimplify = ops->nosimplify; + + return cops; +} + + /** * This function extracts CLooG option values from an OpenScop scop and * updates an existing CloogOption structure with those values. If the @@ -535,6 +616,8 @@ void cloog_options_copy_from_osl_scop(osl_scop_p scop, options->language = CLOOG_LANGUAGE_C; /* Store the input SCoP in the option structure. */ + if(options->scop) + osl_scop_free(options->scop); options->scop = scop; } } diff --git a/source/program.c b/source/program.c index 40ae449..17a183a 100644 --- a/source/program.c +++ b/source/program.c @@ -55,6 +55,7 @@ #ifdef OSL_SUPPORT #include +#include #include #endif @@ -66,7 +67,7 @@ /** * cloog_program_print function: * this function is a human-friendly way to display the CloogProgram data - * structure, it shows all the different fields and includes an indentation + * structure list, it shows all the different fields and includes an indentation * level (level) in order to work with others print_structure functions. * - July 1st 2005: first version based on the old cloog_program_print function. */ @@ -76,73 +77,91 @@ CloogProgram * program ; int level ; { int i, j ; - /* Go to the right level. */ - for (i=0; ilanguage) ; - - /* A blank line. */ - for (i=0; i<=level+1; i++) - fprintf(file,"|\t") ; - fprintf(file,"\n") ; - - /* Print the scattering dimension number. */ - for (i=0; i<=level; i++) - fprintf(file,"|\t") ; - fprintf(file,"Scattering dimension number: %d\n",program->nb_scattdims) ; - - /* A blank line. */ - for (i=0; i<=level+1; i++) - fprintf(file,"|\t") ; - fprintf(file,"\n") ; - - /* Print the scalar scattering dimension informations. */ - for (i=0; i<=level; i++) - fprintf(file,"|\t") ; - if (program->scaldims != NULL) - { fprintf(file,"Scalar dimensions:") ; - for (i=0;inb_scattdims;i++) - fprintf(file," %d:%d ",i,program->scaldims[i]) ; + while (program) { + /* Go to the right level. */ + for (i=0; inames,level+1) ; - - /* A blank line. */ - for (i=0; i<=level+1; i++) - fprintf(file,"|\t") ; - fprintf(file,"\n") ; - - /* Print the context. */ - cloog_domain_print_structure(file, program->context, level+1, "Context"); - - /* Print the loop. */ - cloog_loop_print_structure(file,program->loop,level+1) ; + /* Print the language. */ + for (i=0; i<=level; i++) + fprintf(file,"|\t") ; + fprintf(file, "Language: %c\n",program->language) ; + + /* A blank line. */ + for (i=0; i<=level+1; i++) + fprintf(file,"|\t") ; + fprintf(file,"\n") ; + + /* Print the scattering dimension number. */ + for (i=0; i<=level; i++) + fprintf(file,"|\t") ; + fprintf(file,"Scattering dimension number: %d\n",program->nb_scattdims) ; + + /* A blank line. */ + for (i=0; i<=level+1; i++) + fprintf(file,"|\t") ; + fprintf(file,"\n") ; + + /* Print the scalar scattering dimension informations. */ + for (i=0; i<=level; i++) + fprintf(file,"|\t") ; + if (program->scaldims != NULL) + { fprintf(file,"Scalar dimensions:") ; + for (i=0;inb_scattdims;i++) + fprintf(file," %d:%d ",i,program->scaldims[i]) ; + fprintf(file,"\n") ; + } + else + fprintf(file,"No scalar scattering dimensions\n") ; + + /* A blank line. */ + for (i=0; i<=level+1; i++) + fprintf(file,"|\t") ; + fprintf(file,"\n") ; + + /* Print the parameter and the iterator names. */ + cloog_names_print_structure(file,program->names,level+1) ; + + /* A blank line. */ + for (i=0; i<=level+1; i++) + fprintf(file,"|\t") ; + fprintf(file,"\n") ; + + /* Print the context. */ + cloog_domain_print_structure(file, program->context, level+1, "Context"); + + /* Print the loop. */ + cloog_loop_print_structure(file,program->loop,level+1) ; + + /* One more time something that is here only for a better look. */ + for (j=0; j<2; j++) + { for (i=0; i<=level+1; i++) + fprintf(file,"|\t") ; + + fprintf(file,"\n") ; + } + + program = program->next; + if (program != NULL) { + for (i=0; i<=level; i++) + fprintf(file,"|\t") ; + + fprintf(file,"V\n") ; + } + } // end of while(program) /* One more time something that is here only for a better look. */ for (j=0; j<2; j++) { for (i=0; i<=level; i++) fprintf(file,"|\t") ; - + fprintf(file,"\n") ; } } @@ -361,92 +380,568 @@ static void print_callable_postamble(FILE *file, CloogProgram *program) fprintf(file, "}\n"); } +/** + * cloog_program_sort_ascending function: + * this function bubble sorts a list of CloogPrograms in ascending order + * based on their Coordinates + * Nodes with missing coodinates, they are always swapped with + * their predecessors. After sorting they'll be at the head of the list + * + * \param[in] program address of a pointer to a list of CloogPrograms + */ +void cloog_program_sort_ascending(CloogProgram **program, + CloogOptions **options) { +#ifdef OSL_SUPPORT + if (*program==NULL || (*program)->next==NULL) + return; + + osl_coordinates_p co = NULL; + osl_coordinates_p nco = NULL; + + CloogProgram *head = *program; + CloogOptions *ops = *options; + + //start from head + CloogProgram *listend = NULL; //last element in correct position + while (listend != head) { + CloogProgram *node = head; //start from beginning each time + CloogProgram *prev = head; + CloogOptions *node_ops = ops; //start from beginning each time + CloogOptions *prev_ops = ops; + + //push this element as far in the list as it could go + while (node->next != listend) { + + co = osl_generic_lookup(node_ops->scop->extension, + OSL_URI_COORDINATES); + nco = osl_generic_lookup(node_ops->next->scop->extension, + OSL_URI_COORDINATES); + if ( co && + ( !nco //missin next coordinates, swap. next is smaller! + || (strcmp(co->name, nco->name)>0) //next filename smaller, swap. + || ((strcmp(co->name, nco->name)==0) && (co->line_start > nco->line_start)) + ) + ) { + //swap programs + CloogProgram* next = node->next; + node->next = next->next; + next->next = node; + + //swap options + CloogOptions* nextops = node_ops->next; + node_ops->next = nextops->next; + nextops->next = node_ops; + + + if (node==head) { + node = next; + head = next; + + node_ops = nextops; + ops = nextops; + } + else { + node = next; + prev->next = next; + + node_ops = nextops; + prev_ops->next = nextops; + } + } + + prev = node; + node = node->next; + + prev_ops = node_ops; + node_ops = node_ops->next; + } + + //update listend to the last sorted element + //bring it one step closer to head + listend = node; + } + + *program = head; + *options = ops; +#endif +} + + +#ifdef OSL_SUPPORT +/** + * cloog_program_verify_coordinates function: + * Takes as input a list of CloogPrograms and a list of CLoogOptions. + * There is a one-to-one relation between the program and options lists. + * This function verifies that there exists a CloogOptions for each + * CloogProgram and that the CloogOptions contains a pointer to osl_scop_p + * which, in turn, contains the coordinates of the SCoP. + * + * \param[in] program address of a pointer to a list of CloogPrograms + * \param[in] options address of a pointer to a list of CloogOptions + * \return 1 if CloogPrograms in order, 0 otherise + */ +int cloog_program_verify_coordinates(CloogProgram * program, + CloogOptions * options) { + osl_scop_p scop = NULL; + osl_coordinates_p coordinates = NULL; + + while (program) { + if(options==NULL) //Program with no Options + return 0; + + scop = options->scop; + if (scop==NULL) { + cloog_msg(options, CLOOG_WARNING, + "Missing SCoP in program Options\n"); + return 0; + } + + coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); + if (coordinates == NULL) { + return 0; + } + + program = program->next; + options = options->next; + } + + return 1; +} +#endif + +/** + * cloog_program_count function: + * this function returns the number of programs in the list + */ +int cloog_program_count( CloogProgram *program ) { + int nprog = 0; + while(program){ + nprog++; + program = program->next; + } + + return nprog; +} + + +/** + * cloog_program_count_filename function: + * this function returns the number of programs comming from + * the file whose name is given in input + */ +int cloog_program_count_filename( CloogProgram *program, CloogOptions * options, + const char * const filename) +{ +#ifdef OSL_SUPPORT + int nprog = 0; + osl_scop_p scop = NULL; + osl_coordinates_p coordinates = NULL; + + while(program){ + if(options==NULL) //Program with no Options + return 0; + + scop = options->scop; + if (scop==NULL) { + cloog_msg(options, CLOOG_WARNING, + "Missing SCoP in program Options\n"); + return 0; + } + + coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); + + if (coordinates && !strcmp(coordinates->name, filename)) + nprog++; + + program = program->next; + options = options->next; + } + + return nprog; +#endif + return 0; +} + + +/** + * cloog_program_count_no_coordinates function: + * this function returns the number of programs for which we + * are unable to find the corresponding Coordinates extensions. + */ +int cloog_program_count_no_coordinates( CloogProgram *program, + CloogOptions * options) +{ +#ifdef OSL_SUPPORT + int nprog = 0; + osl_scop_p scop = NULL; + osl_coordinates_p coordinates = NULL; + + while(program){ + if(options==NULL) //Program with no Options + return 0; + + scop = options->scop; + if (scop==NULL) { + cloog_msg(options, CLOOG_WARNING, + "Missing SCoP in program Options\n"); + return 0; + } + + coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); + + if (!coordinates) + nprog++; + + program = program->next; + options = options->next; + } + + return nprog; +#endif + return 0; +} + /** * cloog_program_osl_pprint function: * this function pretty-prints the C or FORTRAN code generated from an - * OpenScop specification by overwriting SCoP in a given code, if the + * OpenScop specification by overwriting SCoP in a given file, if the * options -compilable or -callable are not set. The SCoP coordinates are - * provided through the OpenScop "Coordinates" extension. It returns 1 if - * it succeeds to find an OpenScop coordinates information - * to pretty-print the generated code, 0 otherwise. - * \param[in] file The output stream (possibly stdout). - * \param[in] program The generated pseudo-AST to pretty-print. - * \param[in] options CLooG options (contains the OpenSCop specification). + * provided through the OpenScop "Coordinates" extension. The infilename + * arguments specifies scops pertaining to which file are to be replaced. + * It returns 1 if it succeeds to find an OpenScop coordinates information and + * pretty-print the generated code, 0 otherwise. + * Note: This function assumes that the programs have already been sorted + * in ascending order of their filenames and coordinates. + * + * \param[in] file The output stream (possibly stdout). + * \param[in] program The generated pseudo-AST to pretty-print. + * \param[in] infilename The original file containing SCoP code + * \param[in] options CLooG options (contains the OpenSCop specification). * \return 1 on success to pretty-print at the place of a SCoP, 0 otherwise. */ int cloog_program_osl_pprint(FILE * file, CloogProgram * program, - CloogOptions * options) { + char* infilename, CloogOptions * options) { #ifdef OSL_SUPPORT int lines = 0; int columns = 0; int read = 1; + int macros_printed=0; char c; osl_scop_p scop = options->scop; - osl_coordinates_p coordinates; + osl_coordinates_p coordinates = NULL; + osl_coordinates_p print_coordinates = NULL; struct clast_stmt *root; - FILE * original; + FILE * original = NULL; + int orig_file_open = 0; + int scop_num = 0; + int nprog = 0; + + nprog = cloog_program_count_filename(program, options, infilename); + + while (program) { - if (scop && !options->compilable && !options->callable) { + scop = options->scop; + + //get coordinates and filename coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); - if (coordinates) { - original = fopen(coordinates->name, "r"); - if (!original) { - cloog_msg(options, CLOOG_WARNING, - "unable to open the file specified in the SCoP " - "coordinates\n"); - return 0; - } - /* Print the macros the generated code may need. */ - print_macros(file); - - /* Print what was before the SCoP in the original file. */ - while (((lines < coordinates->line_start - 1) || - (columns < coordinates->column_start - 1)) && (read != EOF)) { - read = fscanf(original, "%c", &c); - columns++; - if (read != EOF) { - if (c == '\n') { - lines++; - columns = 0; - } - fprintf(file, "%c", c); + if (coordinates && !strcmp(infilename, coordinates->name)) { + + //memorize the coordinates for last SCoP printed + print_coordinates = coordinates; + if (!orig_file_open) { + original = fopen(print_coordinates->name, "r"); + if (!original) { + cloog_msg(options, CLOOG_ERROR, + "unable to open the file %s specified in the SCoP " + "coordinates\n", print_coordinates->name); + return 0; + } + else { + orig_file_open = 1; } } - /* Carriage return to preserve indentation if necessary. */ - if (coordinates->column_start > 0) - fprintf(file, "\n"); - - /* Generate the clast from the pseudo-AST then pretty-print it. */ - root = cloog_clast_create(program, options); - clast_pprint(file, root, coordinates->indent, options); - cloog_clast_free(root); - - /* Print what was after the SCoP in the original file. */ - while (read != EOF) { - read = fscanf(original, "%c", &c); - columns++; - if (read != EOF) { - if (((lines == coordinates->line_end - 1) && - (columns > coordinates->column_end)) || - (lines > coordinates->line_end - 1)) + if (!options->compilable && !options->callable){ + + /* Print the macros the generated code may need. */ + if (!macros_printed) { + print_macros(file); + macros_printed=1; + } + + /* Print what was before the SCoP in the original file. */ + while (((lines < print_coordinates->line_start - 1) || + (columns < print_coordinates->column_start - 1)) && + (read != EOF)) { + read = fscanf(original, "%c", &c); + columns++; + if (read != EOF) { + if (c == '\n') { + lines++; + columns = 0; + } fprintf(file, "%c", c); - if (c == '\n') { - lines++; - columns = 0; } } + + /* Carriage return to preserve indentation if necessary. */ + if (print_coordinates->column_start > 0) + fprintf(file, "\n"); + + /* Generate the clast from the pseudo-AST then pretty-print it. */ + root = cloog_clast_create(program, options); + if(nprog!=1) fprintf(file, "/* */\n", scop_num); + clast_pprint(file, root, print_coordinates->indent, options); + if(nprog!=1) fprintf(file, "/* */\n", scop_num); + cloog_clast_free(root); + scop_num++; + + /* Skip the SCoP in the original file. */ + while (read != EOF) { + read = fscanf(original, "%c", &c); + columns++; + if (read != EOF) { + + if (((lines == print_coordinates->line_end - 1) && + (columns > print_coordinates->column_end)) || + (lines > print_coordinates->line_end - 1)) { + + fprintf(file, "%c", c); // + break; // go to next SCoP to dump + } + + if (c == '\n') { + lines++; + columns = 0; + } + + } + } + + } + else { //callable or !scop + cloog_msg(options, CLOOG_ERROR, + "\"-callable\" option incompatible with \"-openscop\"!\n"); + if (orig_file_open) + fclose(original); + + return 0; + } + + } //if filename== + + program = program->next; + options = options->next; + } + + /* Print what was after the last SCoP in the original file. */ + while (read != EOF) { + read = fscanf(original, "%c", &c); + columns++; + if (read != EOF) { + + if (((lines == print_coordinates->line_end - 1) && + (columns > print_coordinates->column_end)) || + (lines > print_coordinates->line_end - 1)) { + + fprintf(file, "%c", c); //copy the tail } - fclose(original); - return 1; + if (c == '\n') { + lines++; + columns = 0; + } } } + + if (orig_file_open) + fclose(original); + + return 1; + #endif return 0; } + +/** + * cloog_program_osl_pprint_no_coordinates function: + * this function pretty-prints the C or FORTRAN code generated from an + * OpenScop specification, if the options -compilable or -callable are not set. + * This function will generate code only for SCoPs which are missing the + * Coordinates extension. It'll write the generated code on standard output. + * It returns 1 if it succeeds to find an OpenScop coordinates information and + * pretty-print the generated code, 0 otherwise. + * Note: This function assumes that the programs have already been sorted + * in ascending order of their filenames and coordinates. + * + * \param[in] file The output stream (normally stdout). + * \param[in] program The generated pseudo-AST to pretty-print. + * \param[in] options CLooG options (contains the OpenSCop specification). + * \return 1 on success to pretty-print at the place of a SCoP, 0 otherwise. + */ +int cloog_program_osl_pprint_no_coordinates(FILE * file, CloogProgram * program, + CloogOptions * options) { +#ifdef OSL_SUPPORT + osl_scop_p scop = options->scop; + osl_coordinates_p coordinates = NULL; + struct clast_stmt *root; + int scop_num = 0; + int nprog = 0; + + nprog = cloog_program_count_no_coordinates(program, options); + + while (program) { + + scop = options->scop; + + //get coordinates and filename + coordinates = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); + + if(!coordinates) { + + if (!options->compilable && !options->callable){ + + /* Generate the clast from the pseudo-AST then pretty-print it. */ + root = cloog_clast_create(program, options); + if(nprog!=1) fprintf(file, "/* */\n", scop_num); + clast_pprint(file , root, 0, options); + if(nprog!=1) fprintf(file , "/* */\n", scop_num); + cloog_clast_free(root); + scop_num++; + + } + else { //callable or !scop + //cleanup + printf("\"-callable\" option incompatible with \"-openscop\"!\n"); + return 0; + } + + } //if filename== + + program = program->next; + options = options->next; + } + + return 1; + +#endif + return 0; +} + +/** + * cloog_get_scop_filenames fucntion: + * this function will search in the Coordinats extensions of all scops + * and return all the unique input filenames that it could find. + * + * \param[in] options List of CloogOptions containing pointers to SCoPs + * \param[out] filenames Pointer to 2D character array for filenames + * \return Returns the number of unique filenames found + */ +int cloog_get_scop_filenames(CloogOptions *options, char ***filenames){ + +#ifdef OSL_SUPPORT + int nfiles = 0; + int found = 0; + int i = 0; + char ** names = NULL; + char *name = NULL; + osl_scop_p scop = NULL; + osl_coordinates_p co = NULL; + + while(options){ + + scop = options->scop; + //get coordinates extension + co = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); + + if(co){ + //get filename + name = co->name; + if(name==NULL){ + fprintf(stderr, "Error: No filename in coordinates.\n"); + return 0; + } + + //see if filename already retrieved + found = 0; + for(i=0; i< nfiles; i++) + if(!strcmp(names[i], name)) + found = 1; + + //save filename + if(!found){ + OSL_realloc(names, char**, ++nfiles); + names[nfiles-1] = strdup(name); + } + } + + options = options->next; + } + + *filenames = names; + return nfiles; +#endif + return 0; +} + + +/* + * cloog_program_osl_pprint_all_files function: + * This function will look for unique filenames in the list of SCoPs. + * The for each input file, it'll create a corresponding output file by + * replacing the original SCoPs by code generated by CLooG. + * In the end, if there are any SCoPs without the Coordinates extensions, + * it'll output their corresponding code on standard output. + * + */ +int cloog_program_osl_pprint_all_files(program, options) +CloogProgram * program ; +CloogOptions * options ; +{ +#ifdef OSL_SUPPORT + int nfiles = 0; + int i = 0; + int success = 0; + char **filenames = NULL; + char *ext = ".cloog"; + + //get all filenames + nfiles = cloog_get_scop_filenames(options, &filenames); + + //for each file + for(i=0; i< nfiles; i++){ + char *outfilename = strdup(filenames[i]); + OSL_realloc(outfilename, char*, strlen(outfilename)+strlen(ext)+1); + strcat(outfilename, ext); + FILE *outfile = fopen(outfilename, "w"); + // print all scops in that file + success = cloog_program_osl_pprint(outfile, program, filenames[i], options); + + fclose(outfile); + if(!success) //failed to write output_file + remove(outfilename); + else + cloog_msg(options, CLOOG_INFO, "Code generated in file %s\n", outfilename); + } + + if(!cloog_program_verify_coordinates(program, options)){ + cloog_msg(options, CLOOG_WARNING, "Missing Coordinates in SCoPs\n"); + cloog_program_osl_pprint_no_coordinates(stdout, program, options); + } + + //free memory + for(i=0; i< nfiles; i++) + free(filenames[i]); + free(filenames); + + return 1; +#endif + return 0; +} + + /** * cloog_program_pprint function: * This function prints the content of a CloogProgram structure (program) into a @@ -459,117 +954,147 @@ CloogProgram * program ; CloogOptions * options ; { int i, j, indentation = 0; + int print_headers = 0; + int print_main = 0; CloogStatement * statement ; CloogBlockList * blocklist ; CloogBlock * block ; struct clast_stmt *root; + int scop_num = 0; - if (cloog_program_osl_pprint(file, program, options)) + if (options->openscop){ + cloog_program_osl_pprint_all_files(program, options); return; + } - if (program->language == 'f') - options->language = CLOOG_LANGUAGE_FORTRAN ; - else - options->language = CLOOG_LANGUAGE_C ; + int nprog = cloog_program_count(program); + + while (program) { + if (program->language == 'f') + options->language = CLOOG_LANGUAGE_FORTRAN ; + else + options->language = CLOOG_LANGUAGE_C ; #ifdef CLOOG_RUSAGE - print_comment(file, options, "Generated from %s by %s in %.2fs.", - options->name, cloog_version(), options->time); + print_comment(file, options, "Generated from %s by %s in %.2fs.", + options->name, cloog_version(), options->time); #else - print_comment(file, options, "Generated from %s by %s.", - options->name, cloog_version()); + print_comment(file, options, "Generated from %s by %s.", + options->name, cloog_version()); #endif #ifdef CLOOG_MEMORY - print_comment(file, options, "CLooG asked for %d KBytes.", options->memory); - cloog_msg(CLOOG_INFO, "%.2fs and %dKB used for code generation.\n", - options->time,options->memory); + print_comment(file, options, "CLooG asked for %d KBytes.", + options->memory); + cloog_msg(CLOOG_INFO, "%.2fs and %dKB used for code generation.\n", + options->time,options->memory); #endif - - /* If the option "compilable" is set, we provide the whole stuff to generate - * a compilable code. This code just do nothing, but now the user can edit - * the source and set the statement macros and parameters values. - */ - if (options->compilable && (program->language == 'c')) - { /* The headers. */ - fprintf(file,"/* DON'T FORGET TO USE -lm OPTION TO COMPILE. */\n\n") ; - fprintf(file,"/* Useful headers. */\n") ; - fprintf(file,"#include \n") ; - fprintf(file,"#include \n") ; - fprintf(file,"#include \n\n") ; - - /* The value of parameters. */ - fprintf(file,"/* Parameter value. */\n") ; - for (i = 1; i <= program->names->nb_parameters; i++) - fprintf(file, "#define PARVAL%d %d\n", i, options->compilable); - /* The macros. */ - print_macros(file); - - /* The statement macros. */ - fprintf(file,"/* Statement macros (please set). */\n") ; - blocklist = program->blocklist ; - while (blocklist != NULL) - { block = blocklist->block ; - statement = block->statement ; - while (statement != NULL) - { fprintf(file,"#define S%d(",statement->number) ; - if (block->depth > 0) - { fprintf(file,"%s",program->names->iterators[0]) ; - for(j=1;jdepth;j++) - fprintf(file,",%s",program->names->iterators[j]) ; + /* If the option "compilable" is set, we provide the whole stuff to generate + * a compilable code. This code just do nothing, but now the user can edit + * the source and set the statement macros and parameters values. + */ + if (options->compilable && (program->language == 'c')) + { /* The headers. */ + if(!print_headers){ + fprintf(file,"/* DON'T FORGET TO USE -lm OPTION TO COMPILE. */\n\n") ; + fprintf(file,"/* Useful headers. */\n") ; + fprintf(file,"#include \n") ; + fprintf(file,"#include \n") ; + fprintf(file,"#include \n\n") ; + + /* The value of parameters. */ + fprintf(file,"/* Parameter value. */\n") ; + for (i = 1; i <= program->names->nb_parameters; i++) + fprintf(file, "#define PARVAL%d %d\n", i, options->compilable); + + /* The macros. */ + print_macros(file); + print_headers = 1; + } + + /* The statement macros. */ + //don't need macros when using openscop + if (options->openscop==0) { + fprintf(file,"/* Statement macros (please set). */\n") ; + blocklist = program->blocklist ; + while (blocklist != NULL) + { block = blocklist->block ; + statement = block->statement ; + while (statement != NULL) + { fprintf(file,"#define S%d(", statement->number) ; + if (block->depth > 0) + { fprintf(file,"%s",program->names->iterators[0]) ; + for(j=1;jdepth;j++) + fprintf(file,",%s",program->names->iterators[j]) ; + } + fprintf(file,") {total++;") ; + if (block->depth > 0) { + fprintf(file, " printf(\"S%d %%d", statement->number); + for (j=1;jdepth;j++) + fprintf(file, " %%d"); + + fprintf(file,"\\n\",%s",program->names->iterators[0]) ; + for (j=1;jdepth;j++) + fprintf(file,",%s",program->names->iterators[j]) ; + fprintf(file,");") ; + } + fprintf(file,"}\n") ; + + statement = statement->next ; + } + blocklist = blocklist->next ; } - fprintf(file,") {total++;") ; - if (block->depth > 0) { - fprintf(file, " printf(\"S%d %%d", statement->number); - for(j=1;jdepth;j++) - fprintf(file, " %%d"); + } + + /* The iterator and parameter declaration. */ + if (!print_main) + fprintf(file,"\nint main() {\n") ; + + print_iterator_declarations(file, program, options); + + if (!print_main) { + if (program->names->nb_parameters > 0) + { fprintf(file," /* Parameters. */\n") ; + fprintf(file, " int %s=PARVAL1",program->names->parameters[0]); + for(i=2;i<=program->names->nb_parameters;i++) + fprintf(file, ", %s=PARVAL%d", program->names->parameters[i-1], i); - fprintf(file,"\\n\",%s",program->names->iterators[0]) ; - for(j=1;jdepth;j++) - fprintf(file,",%s",program->names->iterators[j]) ; - fprintf(file,");") ; + fprintf(file,";\n"); } - fprintf(file,"}\n") ; - - statement = statement->next ; + fprintf(file," int total=0;\n"); + fprintf(file,"\n") ; + print_main= 1; } - blocklist = blocklist->next ; - } - - /* The iterator and parameter declaration. */ - fprintf(file,"\nint main() {\n") ; - print_iterator_declarations(file, program, options); - if (program->names->nb_parameters > 0) - { fprintf(file," /* Parameters. */\n") ; - fprintf(file, " int %s=PARVAL1",program->names->parameters[0]); - for(i=2;i<=program->names->nb_parameters;i++) - fprintf(file, ", %s=PARVAL%d", program->names->parameters[i-1], i); - fprintf(file,";\n"); + /* And we adapt the identation. */ + indentation += 2 ; + } else if (options->callable && program->language == 'c') { + print_callable_preamble(file, program, options); + indentation += 2; } - fprintf(file," int total=0;\n"); - fprintf(file,"\n") ; - /* And we adapt the identation. */ - indentation += 2 ; - } else if (options->callable && program->language == 'c') { - print_callable_preamble(file, program, options); - indentation += 2; + root = cloog_clast_create(program, options); + if(nprog!=1) fprintf(file, "/* */\n", scop_num); + clast_pprint(file, root, indentation, options); + if(nprog!=1) fprintf(file, "/* */\n", scop_num); + cloog_clast_free(root); + + /* The end of the compilable code in case of 'compilable' option. */ + if (options->compilable && (program->language == 'c') + && (program->next==NULL)) + { + fprintf(file, "\n printf(\"Number of integral points: %%d.\\n\",total);"); + fprintf(file, "\n return 0;\n}\n"); + } else if (options->callable && program->language == 'c') { + print_callable_postamble(file, program); + } + + program = program->next; + scop_num++; + options = options->next; } - - root = cloog_clast_create(program, options); - clast_pprint(file, root, indentation, options); - cloog_clast_free(root); - - /* The end of the compilable code in case of 'compilable' option. */ - if (options->compilable && (program->language == 'c')) - { - fprintf(file, "\n printf(\"Number of integral points: %%d.\\n\",total);"); - fprintf(file, "\n return 0;\n}\n"); - } else if (options->callable && program->language == 'c') - print_callable_postamble(file, program); -} +} /****************************************************************************** * Memory deallocation function * @@ -581,14 +1106,21 @@ CloogOptions * options ; * This function frees the allocated memory for a CloogProgram structure. */ void cloog_program_free(CloogProgram * program) -{ cloog_names_free(program->names) ; - cloog_loop_free(program->loop) ; - cloog_domain_free(program->context) ; - cloog_block_list_free(program->blocklist) ; - if (program->scaldims != NULL) - free(program->scaldims) ; - - free(program) ; +{ + while(program){ + CloogProgram *temp = program; + + cloog_names_free(program->names) ; + cloog_loop_free(program->loop) ; + cloog_domain_free(program->context) ; + cloog_block_list_free(program->blocklist) ; + + if (program->scaldims != NULL) + free(program->scaldims) ; + + program = program->next; + free(temp) ; + } } @@ -739,12 +1271,28 @@ CloogProgram *cloog_program_alloc(CloogDomain *context, CloogUnionDomain *ud, */ CloogProgram *cloog_program_read(FILE *file, CloogOptions *options) { - CloogInput *input; - CloogProgram *p; + CloogInput *input, *ihead; + CloogProgram *p = NULL; + CloogProgram **p_ptr = &p; + + ihead = input = cloog_input_read(file, options); - input = cloog_input_read(file, options); - p = cloog_program_alloc(input->context, input->ud, options); - free(input); + CloogOptions* ops = options; + + //generate a list of cloog_programs from cloog_inputs + while (input) { + *p_ptr = cloog_program_alloc(input->context, input->ud, ops); + + input = input->next; + ops = ops->next; + p_ptr = &(*p_ptr)->next; + } + + //free the inputs + while (ihead) { + input = ihead; ihead=ihead->next; + free(input); + } return p; } @@ -779,6 +1327,7 @@ CloogProgram * cloog_program_malloc() program->blocklist = NULL ; program->scaldims = NULL ; program->usr = NULL; + program->next = NULL; return program ; } @@ -800,97 +1349,108 @@ CloogProgram * cloog_program_generate(program, options) CloogProgram * program ; CloogOptions * options ; { + CloogLoop * loop ; + CloogProgram *original = program; + + while (program) { + #ifdef CLOOG_RUSAGE - float time; - struct rusage start, end ; + float time; + struct rusage start, end ; #endif - CloogLoop * loop ; + #ifdef CLOOG_MEMORY - char status_path[MAX_STRING_VAL] ; - FILE * status ; + char status_path[MAX_STRING_VAL] ; + FILE * status ; - /* We initialize the memory need to 0. */ - options->memory = 0 ; + /* We initialize the memory need to 0. */ + options->memory = 0 ; #endif - if (options->override) - { - cloog_msg(options, CLOOG_WARNING, - "you are using -override option, be aware that the " - "generated\n code may be incorrect.\n") ; - } - else - { /* Playing with options may be dangerous, here are two possible issues : - * 1. Using -l option less than scattering dimension number may lead to - * an illegal target code (since the scattering is not respected), if - * it is the case, we set -l depth to the first acceptable value. - */ - if ((program->nb_scattdims > options->l) && (options->l >= 0)) + if (options->override) { cloog_msg(options, CLOOG_WARNING, - "-l depth is less than the scattering dimension number " - "(the \n generated code may be incorrect), it has been " - "automaticaly set\n to this value (use option -override " - "to override).\n") ; - options->l = program->nb_scattdims ; + "you are using -override option, be aware that the " + "generated\n code may be incorrect.\n") ; } - - /* 2. Using -f option greater than one while -l depth is greater than the - * scattering dimension number may lead to iteration duplication (try - * test/daegon_lu_osp.cloog with '-f 3' to test) because of the step 4b - * of the cloog_loop_generate function, if it is the case, we set -l to - * the first acceptable value. - */ - if (((options->f > 1) || (options->f < 0)) && - ((options->l > program->nb_scattdims) || (options->l < 0))) - { - cloog_msg(options, CLOOG_WARNING, - "-f depth is more than one, -l depth has been " - "automaticaly set\n to the scattering dimension number " - "(target code may have\n duplicated iterations), -l depth " - "has been automaticaly set to\n this value (use option " - "-override to override).\n") ; - options->l = program->nb_scattdims ; + else + { /* Playing with options may be dangerous, here are two possible issues : + * 1. Using -l option less than scattering dimension number may lead to + * an illegal target code (since the scattering is not respected), if + * it is the case, we set -l depth to the first acceptable value. + */ + if ((program->nb_scattdims > options->l) + && (options->l >= 0)) + { + cloog_msg(options, CLOOG_WARNING, + "-l depth is less than the scattering dimension number " + "(the \n generated code may be incorrect), it has been " + "automaticaly set\n to this value (use option -override " + "to override).\n") ; + options->l = program->nb_scattdims ; + } + + /* 2. Using -f option greater than one while -l depth is greater than the + * scattering dimension number may lead to iteration duplication (try + * test/daegon_lu_osp.cloog with '-f 3' to test) because of the step 4b + * of the cloog_loop_generate function, if it is the case, we set -l to + * the first acceptable value. + */ + if (((options->f > 1) || (options->f < 0)) && + ((options->l > program->nb_scattdims) || + (options->l < 0))) + { + cloog_msg(options, CLOOG_WARNING, + "-f depth is more than one, -l depth has been " + "automaticaly set\n to the scattering dimension number " + "(target code may have\n duplicated iterations), -l depth " + "has been automaticaly set to\n this value (use option " + "-override to override).\n") ; + options->l = program->nb_scattdims ; + } } - } - + #ifdef CLOOG_RUSAGE - getrusage(RUSAGE_SELF, &start) ; + getrusage(RUSAGE_SELF, &start) ; #endif - if (program->loop != NULL) - { loop = program->loop ; - - /* Here we go ! */ - loop = cloog_loop_generate(loop, program->context, 0, 0, - program->scaldims, - program->nb_scattdims, - options); - + if (program->loop != NULL) + { loop = program->loop ; + + /* Here we go ! */ + loop = cloog_loop_generate(loop, program->context, 0, 0, + program->scaldims, + program->nb_scattdims, + options); + #ifdef CLOOG_MEMORY - /* We read into the status file of the process how many memory it uses. */ - sprintf(status_path,"/proc/%d/status",getpid()) ; - status = fopen(status_path, "r") ; - while (fscanf(status,"%s",status_path) && strcmp(status_path,"VmData:")!=0); - fscanf(status,"%d",&(options->memory)) ; - fclose(status) ; + /* We read into the status file of the process how many memory it uses. */ + sprintf(status_path,"/proc/%d/status",getpid()) ; + status = fopen(status_path, "r") ; + while (fscanf(status,"%s",status_path) && strcmp(status_path,"VmData:")!=0); + fscanf(status,"%d",&(options->memory)) ; + fclose(status) ; #endif - - if ((!options->nosimplify) && (program->loop != NULL)) - loop = cloog_loop_simplify(loop, program->context, 0, - program->nb_scattdims, options); - - program->loop = loop ; - } - + + if ((!options->nosimplify) && (program->loop != NULL)) + loop = cloog_loop_simplify(loop, program->context, 0, + program->nb_scattdims, options); + + program->loop = loop ; + } + #ifdef CLOOG_RUSAGE - getrusage(RUSAGE_SELF, &end) ; - /* We calculate the time spent in code generation. */ - time = (end.ru_utime.tv_usec - start.ru_utime.tv_usec)/(float)(MEGA) ; - time += (float)(end.ru_utime.tv_sec - start.ru_utime.tv_sec) ; - options->time = time ; + getrusage(RUSAGE_SELF, &end) ; + /* We calculate the time spent in code generation. */ + time = (end.ru_utime.tv_usec - start.ru_utime.tv_usec)/(float)(MEGA) ; + time += (float)(end.ru_utime.tv_sec - start.ru_utime.tv_sec) ; + options->time = time ; #endif - return program ; + program = program->next; + options = options->next; + } + + return original ; } diff --git a/test/Makefile.am b/test/Makefile.am index c333554..924bbfc 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -210,6 +210,7 @@ else CLOOGTEST_OPENSCOP = \ openscop/matmult \ openscop/empty \ + openscop/multiscop \ openscop/union endif diff --git a/test/openscop/multiscop.c b/test/openscop/multiscop.c new file mode 100644 index 0000000..2d5f910 --- /dev/null +++ b/test/openscop/multiscop.c @@ -0,0 +1,30 @@ +/* Generated from ./openscop/multiscop.scop by CLooG gmp bits in 0.00s. */ +/* */ +if (N >= 1) { + for (i=0;i<=N-1;i++) { + for (j=0;j<=N-1;j++) { + c[i][j] = 0.0; + for (k=0;k<=N-1;k++) { + c[i][j] = c[i][j] + a[i][k]*b[k][j]; + } + } + } +} +/* */ +/* Generated from ./openscop/multiscop.scop by CLooG gmp bits in 0.00s. */ +/* */ +if (N >= 1) { + for (i=0;i<=N-1;i++) { + for (j=0;j<=N-1;j++) { + c[i][j] = 0.0; + for (k=0;k<=N-1;k++) { + c[i][j] = c[i][j] + a[i][k]*b[k][j]; + } + } + } +} +/* */ +/* Generated from ./openscop/multiscop.scop by CLooG gmp bits in 0.00s. */ +/* */ +i = 0; +/* */ diff --git a/test/openscop/multiscop.scop b/test/openscop/multiscop.scop new file mode 100644 index 0000000..5753a35 --- /dev/null +++ b/test/openscop/multiscop.scop @@ -0,0 +1,392 @@ +# +# <| +# A +# /.\ +# <| [""M# +# A | # Clan McCloog Castle +# /.\ [""M# [Generated by Clan 0.7.1] +# [""M# | # U"U#U +# | # | # \ .:/ +# | # | #___| # +# | "--' .-" +# |"-"-"-"-"-#-#-## +# | # ## ###### +# \ .::::'/ +# \ ::::'/ +# :8a| # # ## +# ::88a ### +# ::::888a 8a ##::. +# ::::::888a88a[]:::: +# :::::::::SUNDOGa8a::::. .. +# :::::8::::888:Y8888:::::::::... +#::':::88::::888::Y88a______________________________________________________ +#:: ::::88a::::88a:Y88a __---__-- __ +#' .: ::Y88a:::::8a:Y88a __----_-- -------_-__ +# :' ::::8P::::::::::88aa. _ _- -- --_ --- __ --- __-- +#.:: :::::::::::::::::::Y88as88a...s88aa. +# +# [File generated by the OpenScop Library 0.8.4] + + + +# =============================================== Global +# Language +C + +# Context +CONTEXT +0 3 0 0 0 1 + +# Parameters are provided +1 + +N + + +# Number of statements +2 + +# =============================================== Statement 1 +# Number of relations describing the statement: +3 + +# ---------------------------------------------- 1.1 Domain +DOMAIN +5 5 2 0 0 1 +# e/i| i j | N | 1 + 1 1 0 0 0 ## i >= 0 + 1 -1 0 1 -1 ## -i+N-1 >= 0 + 1 0 0 1 -1 ## N-1 >= 0 + 1 0 1 0 0 ## j >= 0 + 1 0 -1 1 -1 ## -j+N-1 >= 0 + +# ---------------------------------------------- 1.2 Scattering +SCATTERING +5 10 5 2 0 1 +# e/i| c1 c2 c3 c4 c5 | i j | N | 1 + 0 -1 0 0 0 0 0 0 0 0 ## c1 == 0 + 0 0 -1 0 0 0 1 0 0 0 ## c2 == i + 0 0 0 -1 0 0 0 0 0 0 ## c3 == 0 + 0 0 0 0 -1 0 0 1 0 0 ## c4 == j + 0 0 0 0 0 -1 0 0 0 0 ## c5 == 0 + +# ---------------------------------------------- 1.3 Access +WRITE +3 8 3 2 0 1 +# e/i| Arr [1] [2]| i j | N | 1 + 0 -1 0 0 0 0 0 4 ## Arr == c + 0 0 -1 0 1 0 0 0 ## [1] == i + 0 0 0 -1 0 1 0 0 ## [2] == j + +# ---------------------------------------------- 1.4 Body +# Statement body is provided +1 + +# Number of original iterators +2 +# List of original iterators +i j +# Statement body expression +c[i][j] = 0.0; + + +# =============================================== Statement 2 +# Number of relations describing the statement: +6 + +# ---------------------------------------------- 2.1 Domain +DOMAIN +7 6 3 0 0 1 +# e/i| i j k | N | 1 + 1 1 0 0 0 0 ## i >= 0 + 1 -1 0 0 1 -1 ## -i+N-1 >= 0 + 1 0 0 0 1 -1 ## N-1 >= 0 + 1 0 1 0 0 0 ## j >= 0 + 1 0 -1 0 1 -1 ## -j+N-1 >= 0 + 1 0 0 1 0 0 ## k >= 0 + 1 0 0 -1 1 -1 ## -k+N-1 >= 0 + +# ---------------------------------------------- 2.2 Scattering +SCATTERING +7 13 7 3 0 1 +# e/i| c1 c2 c3 c4 c5 c6 c7 | i j k | N | 1 + 0 -1 0 0 0 0 0 0 0 0 0 0 0 ## c1 == 0 + 0 0 -1 0 0 0 0 0 1 0 0 0 0 ## c2 == i + 0 0 0 -1 0 0 0 0 0 0 0 0 0 ## c3 == 0 + 0 0 0 0 -1 0 0 0 0 1 0 0 0 ## c4 == j + 0 0 0 0 0 -1 0 0 0 0 0 0 1 ## c5 == 1 + 0 0 0 0 0 0 -1 0 0 0 1 0 0 ## c6 == k + 0 0 0 0 0 0 0 -1 0 0 0 0 0 ## c7 == 0 + +# ---------------------------------------------- 2.3 Access +WRITE +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 4 ## Arr == c + 0 0 -1 0 1 0 0 0 0 ## [1] == i + 0 0 0 -1 0 1 0 0 0 ## [2] == j + +READ +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 4 ## Arr == c + 0 0 -1 0 1 0 0 0 0 ## [1] == i + 0 0 0 -1 0 1 0 0 0 ## [2] == j + +READ +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 6 ## Arr == a + 0 0 -1 0 1 0 0 0 0 ## [1] == i + 0 0 0 -1 0 0 1 0 0 ## [2] == k + +READ +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 7 ## Arr == b + 0 0 -1 0 0 0 1 0 0 ## [1] == k + 0 0 0 -1 0 1 0 0 0 ## [2] == j + +# ---------------------------------------------- 2.4 Body +# Statement body is provided +1 + +# Number of original iterators +3 +# List of original iterators +i j k +# Statement body expression +c[i][j] = c[i][j] + a[i][k]*b[k][j]; + + +# =============================================== Extensions + +b0 i b1 j b2 k b3 + + + +# Number of arrays +7 +# Mapping array-identifiers/array-names +1 i +2 N +3 j +4 c +5 k +6 a +7 b + + + + + + + +# =============================================== Global +# Language +C + +# Context +CONTEXT +0 3 0 0 0 1 + +# Parameters are provided +1 + +N + + +# Number of statements +2 + +# =============================================== Statement 1 +# Number of relations describing the statement: +3 + +# ---------------------------------------------- 1.1 Domain +DOMAIN +5 5 2 0 0 1 +# e/i| i j | N | 1 + 1 1 0 0 0 ## i >= 0 + 1 -1 0 1 -1 ## -i+N-1 >= 0 + 1 0 0 1 -1 ## N-1 >= 0 + 1 0 1 0 0 ## j >= 0 + 1 0 -1 1 -1 ## -j+N-1 >= 0 + +# ---------------------------------------------- 1.2 Scattering +SCATTERING +5 10 5 2 0 1 +# e/i| c1 c2 c3 c4 c5 | i j | N | 1 + 0 -1 0 0 0 0 0 0 0 0 ## c1 == 0 + 0 0 -1 0 0 0 1 0 0 0 ## c2 == i + 0 0 0 -1 0 0 0 0 0 0 ## c3 == 0 + 0 0 0 0 -1 0 0 1 0 0 ## c4 == j + 0 0 0 0 0 -1 0 0 0 0 ## c5 == 0 + +# ---------------------------------------------- 1.3 Access +WRITE +3 8 3 2 0 1 +# e/i| Arr [1] [2]| i j | N | 1 + 0 -1 0 0 0 0 0 4 ## Arr == c + 0 0 -1 0 1 0 0 0 ## [1] == i + 0 0 0 -1 0 1 0 0 ## [2] == j + +# ---------------------------------------------- 1.4 Body +# Statement body is provided +1 + +# Number of original iterators +2 +# List of original iterators +i j +# Statement body expression +c[i][j] = 0.0; + + +# =============================================== Statement 2 +# Number of relations describing the statement: +6 + +# ---------------------------------------------- 2.1 Domain +DOMAIN +7 6 3 0 0 1 +# e/i| i j k | N | 1 + 1 1 0 0 0 0 ## i >= 0 + 1 -1 0 0 1 -1 ## -i+N-1 >= 0 + 1 0 0 0 1 -1 ## N-1 >= 0 + 1 0 1 0 0 0 ## j >= 0 + 1 0 -1 0 1 -1 ## -j+N-1 >= 0 + 1 0 0 1 0 0 ## k >= 0 + 1 0 0 -1 1 -1 ## -k+N-1 >= 0 + +# ---------------------------------------------- 2.2 Scattering +SCATTERING +7 13 7 3 0 1 +# e/i| c1 c2 c3 c4 c5 c6 c7 | i j k | N | 1 + 0 -1 0 0 0 0 0 0 0 0 0 0 0 ## c1 == 0 + 0 0 -1 0 0 0 0 0 1 0 0 0 0 ## c2 == i + 0 0 0 -1 0 0 0 0 0 0 0 0 0 ## c3 == 0 + 0 0 0 0 -1 0 0 0 0 1 0 0 0 ## c4 == j + 0 0 0 0 0 -1 0 0 0 0 0 0 1 ## c5 == 1 + 0 0 0 0 0 0 -1 0 0 0 1 0 0 ## c6 == k + 0 0 0 0 0 0 0 -1 0 0 0 0 0 ## c7 == 0 + +# ---------------------------------------------- 2.3 Access +WRITE +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 4 ## Arr == c + 0 0 -1 0 1 0 0 0 0 ## [1] == i + 0 0 0 -1 0 1 0 0 0 ## [2] == j + +READ +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 4 ## Arr == c + 0 0 -1 0 1 0 0 0 0 ## [1] == i + 0 0 0 -1 0 1 0 0 0 ## [2] == j + +READ +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 6 ## Arr == a + 0 0 -1 0 1 0 0 0 0 ## [1] == i + 0 0 0 -1 0 0 1 0 0 ## [2] == k + +READ +3 9 3 3 0 1 +# e/i| Arr [1] [2]| i j k | N | 1 + 0 -1 0 0 0 0 0 0 7 ## Arr == b + 0 0 -1 0 0 0 1 0 0 ## [1] == k + 0 0 0 -1 0 1 0 0 0 ## [2] == j + +# ---------------------------------------------- 2.4 Body +# Statement body is provided +1 + +# Number of original iterators +3 +# List of original iterators +i j k +# Statement body expression +c[i][j] = c[i][j] + a[i][k]*b[k][j]; + + +# =============================================== Extensions + +b0 i b1 j b2 k b3 + + + +# Number of arrays +7 +# Mapping array-identifiers/array-names +1 i +2 N +3 j +4 c +5 k +6 a +7 b + + + + + + + +# =============================================== Global +# Language +C + +# Context +CONTEXT +0 2 0 0 0 0 + +# Parameters are not provided +0 + + +# Number of statements +1 + +# =============================================== Statement 1 +# Number of relations describing the statement: +3 + +# ---------------------------------------------- 1.1 Domain +DOMAIN +0 2 0 0 0 0 + +# ---------------------------------------------- 1.2 Scattering +SCATTERING +1 3 1 0 0 0 +# e/i| c1 | 1 + 0 -1 0 ## c1 == 0 + +# ---------------------------------------------- 1.3 Access +WRITE +1 3 1 0 0 0 +# e/i| Arr| 1 + 0 -1 1 ## Arr == i + +# ---------------------------------------------- 1.4 Body +# Statement body is provided +1 + +# Number of original iterators +0 +# Statement body expression +i = 0; + + +# =============================================== Extensions + +# Number of arrays +1 +# Mapping array-identifiers/array-names +1 i + + + + From cf3c61434c89f661c04e302f93e90934c51e9dfa Mon Sep 17 00:00:00 2001 From: Taj Muhammad Khan Date: Fri, 27 Jun 2014 16:56:13 +0200 Subject: [PATCH 2/3] Modified openscop loop test to work with multiscop changes --- test/openscop/loops.c | 18 ------------------ test/openscop/loops.scop | 11 ----------- 2 files changed, 29 deletions(-) diff --git a/test/openscop/loops.c b/test/openscop/loops.c index fb9cf44..e1bf250 100644 --- a/test/openscop/loops.c +++ b/test/openscop/loops.c @@ -1,20 +1,3 @@ -/* Useful macros. */ -#define floord(n,d) (((n)<0) ? -((-(n)+(d)-1)/(d)) : (n)/(d)) -#define ceild(n,d) (((n)<0) ? -((-(n))/(d)) : ((n)+(d)-1)/(d)) -#define max(x,y) ((x) > (y) ? (x) : (y)) -#define min(x,y) ((x) < (y) ? (x) : (y)) - -#ifdef TIME -#define IF_TIME(foo) foo; -#else -#define IF_TIME(foo) -#endif -/* matmul.c 128*128 matrix multiply */ -#pragma scop - /* Scattering iterators. */ - int t2, t3, t4, t5, t6, t9; - int lbp, ubp; - int lbv, ubv; if (N >= 1) { lbp=0; ubp=floord(N-1,32); @@ -53,4 +36,3 @@ } } } -#pragma endscop diff --git a/test/openscop/loops.scop b/test/openscop/loops.scop index 9a7f178..0ee7904 100644 --- a/test/openscop/loops.scop +++ b/test/openscop/loops.scop @@ -163,17 +163,6 @@ c[i][j] = c[i][j] + a[i][k]*b[k][j]; 7 b - -# File name -openscop/loops.orig.c -# Starting line and column -3 0 -# Ending line and column -10 0 -# Indentation -2 - - t1 t2 t3 t4 t5 t6 t7 t8 t9 From 2700cb8a08d6fc6cd7484f7a29f845954235dc84 Mon Sep 17 00:00:00 2001 From: Taj Muhammad Khan Date: Fri, 27 Jun 2014 17:23:13 +0200 Subject: [PATCH 3/3] removed test/openscop/loop.orig.c file --- test/openscop/loops.orig.c | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 test/openscop/loops.orig.c diff --git a/test/openscop/loops.orig.c b/test/openscop/loops.orig.c deleted file mode 100644 index ca97caf..0000000 --- a/test/openscop/loops.orig.c +++ /dev/null @@ -1,10 +0,0 @@ -/* matmul.c 128*128 matrix multiply */ -#pragma scop - for(i=0; i