Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Review: Multiscop support in CLooG #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion include/cloog/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion include/cloog/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
} ;


Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions include/cloog/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion isl
Submodule isl updated from 14d794 to 0e737e
2 changes: 2 additions & 0 deletions source/cloog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;

Expand Down
40 changes: 33 additions & 7 deletions source/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
#else
Expand Down Expand Up @@ -110,15 +129,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,
Expand Down
99 changes: 91 additions & 8 deletions source/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}


Expand Down Expand Up @@ -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. */
Expand All @@ -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 ;
}
Expand Down Expand Up @@ -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 ;
Expand All @@ -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
Expand All @@ -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;
}
}
Expand Down
Loading