From 1f3891e201b5f9666fcd383d6b22a9bdd926f7f4 Mon Sep 17 00:00:00 2001 From: Oleksandr Zinenko Date: Thu, 5 Feb 2015 13:44:50 +0100 Subject: [PATCH] Prevent iterator redefinition Do not generate scattering iterators that have the same names as the original iterators. --- source/program.c | 43 ++++++++++++++----- test/Makefile.am | 8 +++- test/openscop/clay.c | 20 +++++++++ test/openscop/clay.scop | 89 ++++++++++++++++++++++++++++++++++++++++ test/openscop/clay_orig.c | 9 ++++ test/openscop/coordinates.c | 16 ++++++++ test/openscop/coordinates.scop | 86 ++++++++++++++++++++++++++++++++++++++ test/openscop/coordinates_orig.c | 5 +++ 8 files changed, 264 insertions(+), 12 deletions(-) create mode 100644 test/openscop/clay.c create mode 100644 test/openscop/clay.scop create mode 100644 test/openscop/clay_orig.c create mode 100644 test/openscop/coordinates.c create mode 100644 test/openscop/coordinates.scop create mode 100644 test/openscop/coordinates_orig.c diff --git a/source/program.c b/source/program.c index aea15fd..9606de2 100644 --- a/source/program.c +++ b/source/program.c @@ -306,15 +306,43 @@ static void print_declarations(FILE *file, int n, char **names, int indentation) fprintf(file, ";\n"); } +static void print_scattering_declarations(FILE *file, CloogProgram *program, + int indentation) +{ + int i, j, found; + int nb_scatnames = 0; + CloogNames *names = program->names; + + // Copy pointer only to those scatering names that do not duplicate + // iterator names. + char **scatnames = (char **) malloc(sizeof(char *) * names->nb_scattering); + for (i = 0; i < names->nb_scattering; ++i) { + for (j = 0; j < names->nb_iterators; ++j) { + found = 0; + if (strcmp(names->scattering[i], names->iterators[j]) == 0) { + found = 1; + } + } + if (!found) { + // Save a pointer (intentional!) to the names in the new array. + scatnames[nb_scatnames++] = names->scattering[i]; + } + } + + if (nb_scatnames) { + for (i = 0; i < indentation; i++) + fprintf(file, " "); + fprintf(file, "/* Scattering iterators. */\n"); + print_declarations(file, nb_scatnames, scatnames, indentation); + } +} + static void print_iterator_declarations(FILE *file, CloogProgram *program, CloogOptions *options) { CloogNames *names = program->names; - if (names->nb_scattering) { - fprintf(file, " /* Scattering iterators. */\n"); - print_declarations(file, names->nb_scattering, names->scattering, 2); - } + print_scattering_declarations(file, program, 2); if (names->nb_iterators) { fprintf(file, " /* Original iterators. */\n"); print_declarations(file, names->nb_iterators, names->iterators, 2); @@ -387,12 +415,7 @@ static void print_iterator_declarations_osl(FILE *file, CloogProgram *program, osl_scop_p scop = options->scop; CloogNames *names = program->names; - if (names->nb_scattering) { - for (i = 0; i < indent; i++) - fprintf(file, " "); - fprintf(file, "/* Scattering iterators. */\n"); - print_declarations(file, names->nb_scattering, names->scattering, indent); - } + print_scattering_declarations(file, program, indent); co = osl_generic_lookup(scop->extension, OSL_URI_COORDINATES); if (co==NULL //if coordinates exist then iterators already declared in file diff --git a/test/Makefile.am b/test/Makefile.am index 693030f..09bc606 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -211,7 +211,9 @@ CLOOGTEST_OPENSCOP = \ openscop/matmult \ openscop/empty \ openscop/loops \ - openscop/union + openscop/union \ + openscop/coordinates \ + openscop/clay endif SPECIAL_TESTS = \ @@ -345,4 +347,6 @@ EXTRA_DIST = \ $(CLOOGTEST_OPENSCOP:%=%.c) \ $(SPECIAL_TESTS:%=%.cloog) \ $(SPECIAL_TESTS:%=%.c) \ - $(SPECIAL_TESTS:%=%.good.c) + $(SPECIAL_TESTS:%=%.good.c) \ + openscop/clay_orig.c \ + openscop/coordinates_orig.c diff --git a/test/openscop/clay.c b/test/openscop/clay.c new file mode 100644 index 0000000..bfb1419 --- /dev/null +++ b/test/openscop/clay.c @@ -0,0 +1,20 @@ +/* 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 + + /* Scattering iterators. */ + int __ii0; + +for (__ii0=0;__ii0<=10;__ii0++) { + for (i=4*__ii0;i<=min(41,4*__ii0+3);i++) { + S(i); + } +} diff --git a/test/openscop/clay.scop b/test/openscop/clay.scop new file mode 100644 index 0000000..967d93e --- /dev/null +++ b/test/openscop/clay.scop @@ -0,0 +1,89 @@ +# [File generated by the OpenScop Library 0.9.0] + + + +# =============================================== 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 +2 3 1 0 0 0 +# e/i| i | 1 + 1 1 0 ## i >= 0 + 1 -1 41 ## -i+41 >= 0 + +# ---------------------------------------------- 1.2 Scattering +SCATTERING +6 8 5 1 0 0 +# e/i| c1 c2 c3 c4 c5 | i | 1 + 0 -1 0 0 0 0 0 0 ## c1 == 0 + 1 0 -4 0 1 0 0 0 ## -4*c2+c4 >= 0 + 1 0 4 0 -1 0 0 3 ## 4*c2-c4+3 >= 0 + 0 0 0 -1 0 0 0 0 ## c3 == 0 + 0 0 0 0 -1 0 1 0 ## c4 == i + 0 0 0 0 0 -1 0 0 ## c5 == 0 + +# ---------------------------------------------- 1.3 Access +READ +1 4 1 1 0 0 +# e/i| Arr| i | 1 + 0 -1 0 1 ## Arr == i + +# ---------------------------------------------- 1.4 Statement Extensions +# Number of Statement Extensions +2 + +1 + + + +# Number of original iterators +1 +# List of original iterators +i +# Statement body expression +S(i); + + +# =============================================== Extensions + +__b0 __ii0 b0 i b1 + + + +# Number of arrays +2 +# Mapping array-identifiers/array-names +1 i +2 S + + + +# File name +clay_orig.c +# Starting line and column +3 0 +# Ending line and column +9 0 +# Indentation +0 + + + + diff --git a/test/openscop/clay_orig.c b/test/openscop/clay_orig.c new file mode 100644 index 0000000..f1ca5e9 --- /dev/null +++ b/test/openscop/clay_orig.c @@ -0,0 +1,9 @@ +int i; +#pragma scop +/* Clay + stripmine([0,0],1,4,1); + */ +for (i = 0; i < 42; i++) { + S(i); +} +#pragma endscop diff --git a/test/openscop/coordinates.c b/test/openscop/coordinates.c new file mode 100644 index 0000000..a584f04 --- /dev/null +++ b/test/openscop/coordinates.c @@ -0,0 +1,16 @@ +/* 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 + + +for (i=0;i<=41;i++) { + S1(i); +} diff --git a/test/openscop/coordinates.scop b/test/openscop/coordinates.scop new file mode 100644 index 0000000..f40cd02 --- /dev/null +++ b/test/openscop/coordinates.scop @@ -0,0 +1,86 @@ +# [File generated by the OpenScop Library 0.9.0] + + + +# =============================================== 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 +2 3 1 0 0 0 +# e/i| i | 1 + 1 1 0 ## i >= 0 + 1 -1 41 ## -i+41 >= 0 + +# ---------------------------------------------- 1.2 Scattering +SCATTERING +3 6 3 1 0 0 +# e/i| c1 c2 c3 | i | 1 + 0 -1 0 0 0 0 ## c1 == 0 + 0 0 -1 0 1 0 ## c2 == i + 0 0 0 -1 0 0 ## c3 == 0 + +# ---------------------------------------------- 1.3 Access +READ +1 4 1 1 0 0 +# e/i| Arr| i | 1 + 0 -1 0 1 ## Arr == i + +# ---------------------------------------------- 1.4 Statement Extensions +# Number of Statement Extensions +2 + +# Number of original iterators +1 +# List of original iterators +i +# Statement body expression +S1(i); + + + +1 + + +# =============================================== Extensions + +b0 i b1 + + + +# Number of arrays +2 +# Mapping array-identifiers/array-names +1 i +2 S1 + + + +# File name +coordinates_orig.c +# Starting line and column +2 0 +# Ending line and column +5 0 +# Indentation +0 + + + + diff --git a/test/openscop/coordinates_orig.c b/test/openscop/coordinates_orig.c new file mode 100644 index 0000000..86c7464 --- /dev/null +++ b/test/openscop/coordinates_orig.c @@ -0,0 +1,5 @@ +#pragma scop +for (i = 0; i < 42; i++) { + S1(i); +} +#pragma endscop -- 2.11.4.GIT