From 567e8fa62abe8317148b545527c416253ca75ba1 Mon Sep 17 00:00:00 2001 From: Lnc Date: Thu, 27 Mar 2014 12:29:19 +0100 Subject: [PATCH] Add osl_pluto_unroll extension --- Makefile.am | 4 +- include/osl/extensions/pluto_unroll.h | 139 +++++++++++ source/extensions/pluto_unroll.c | 422 ++++++++++++++++++++++++++++++++++ source/interface.c | 2 + tests/Makefile.am | 19 +- tests/osl_pluto_unroll.c | 192 ++++++++++++++++ 6 files changed, 769 insertions(+), 9 deletions(-) create mode 100644 include/osl/extensions/pluto_unroll.h create mode 100644 source/extensions/pluto_unroll.c create mode 100644 tests/osl_pluto_unroll.c diff --git a/Makefile.am b/Makefile.am index e356e74..a0ec1bb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -108,7 +108,8 @@ pkgextensionsinclude_HEADERS = \ include/osl/extensions/irregular.h \ include/osl/extensions/symbols.h \ include/osl/extensions/loop.h \ - include/osl/extensions/extbody.h + include/osl/extensions/extbody.h \ + include/osl/extensions/pluto_unroll.h AM_CPPFLAGS = -I. -I$(top_builddir)/include -I$(top_srcdir)/include AM_CFLAGS = $(CFLAGS_WARN) @@ -131,6 +132,7 @@ libosl_la_SOURCES = \ source/extensions/symbols.c \ source/extensions/extbody.c \ source/extensions/loop.c \ + source/extensions/pluto_unroll.c \ source/interface.c \ source/generic.c \ source/relation.c \ diff --git a/include/osl/extensions/pluto_unroll.h b/include/osl/extensions/pluto_unroll.h new file mode 100644 index 0000000..ff75295 --- /dev/null +++ b/include/osl/extensions/pluto_unroll.h @@ -0,0 +1,139 @@ + + /*+-----------------------------------------------------------------** + ** OpenScop Library ** + **-----------------------------------------------------------------** + ** extensions/pluto_unroll.h ** + **-----------------------------------------------------------------** + ** First version: 26/06/2014 ** + **-----------------------------------------------------------------** + + + ***************************************************************************** + * OpenScop: Structures and formats for polyhedral tools to talk together * + ***************************************************************************** + * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, * + * / / / // // // // / / / // // / / // / /|,_, * + * / / / // // // // / / / // // / / // / / / /\ * + * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ * + * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ * + * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ * + * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ * + * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ * + * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ * + * | I | | | | e | | | | | | | | | | | | | \ \ \ * + * | T | | | | | | | | | | | | | | | | | \ \ \ * + * | E | | | | | | | | | | | | | | | | | \ \ \ * + * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ * + * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / * + * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' * + * * + * Copyright (C) 2014 Inria * + * * + * (3-clause BSD license) * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright notice, * + * this list of conditions and the following disclaimer. * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the following disclaimer in the * + * documentation and/or other materials provided with the distribution. * + * 3. The name of the author may not be used to endorse or promote products * + * derived from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + * * + * OpenScop Library, a library to manipulate OpenScop formats and data * + * structures. Written by: * + * Cedric Bastoul and * + * Louis-Noel Pouchet * + * * + *****************************************************************************/ + + +#ifndef OSL_PLUTO_UNROLL_H +#define OSL_PLUTO_UNROLL_H + + +#include +#include + +#include "../strings.h" +#include "../interface.h" + + +#if defined(__cplusplus) +extern "C" + { +#endif + + +#define OSL_URI_PLUTO_UNROLL "pluto_unroll" + + +/** + * The osl_pluto_unroll_t structure stores the pluto_unroll + * that Pluto wants to unroll + */ +struct osl_pluto_unroll { + char* iter; /**< \brief \0 terminated iterator name */ + bool jam; /**< \brief true if jam, false otherwise */ + unsigned int factor ; /**< \brief unroll factor */ + struct osl_pluto_unroll * next; /**< \brief next { iter, jam, factor } */ +}; +typedef struct osl_pluto_unroll osl_pluto_unroll_t; +typedef struct osl_pluto_unroll * osl_pluto_unroll_p; + + +/*+*************************************************************************** + * Structure display function * + *****************************************************************************/ +void osl_pluto_unroll_idump(FILE *, osl_pluto_unroll_p, int); +void osl_pluto_unroll_dump(FILE *, osl_pluto_unroll_p); +char * osl_pluto_unroll_sprint(osl_pluto_unroll_p); + + +/***************************************************************************** + * Reading function * + *****************************************************************************/ +osl_pluto_unroll_p osl_pluto_unroll_sread(char**); + + +/*+*************************************************************************** + * Memory allocation/deallocation function * + *****************************************************************************/ +osl_pluto_unroll_p osl_pluto_unroll_malloc(); +void osl_pluto_unroll_free(osl_pluto_unroll_p); + + +/*+*************************************************************************** + * Processing functions * + *****************************************************************************/ +void osl_pluto_unroll_fill(osl_pluto_unroll_p, + char const * const, + bool const, int const); +osl_pluto_unroll_p osl_pluto_unroll_clone(osl_pluto_unroll_p); +int osl_pluto_unroll_equal_one(osl_pluto_unroll_p, + osl_pluto_unroll_p); +int osl_pluto_unroll_equal(osl_pluto_unroll_p, + osl_pluto_unroll_p); +osl_strings_p osl_pluto_unroll_to_strings(osl_pluto_unroll_p); +osl_interface_p osl_pluto_unroll_interface(); + + +#if defined(__cplusplus) + } +#endif + + +#endif /* define OSL_PLUTO_UNROLL_H */ diff --git a/source/extensions/pluto_unroll.c b/source/extensions/pluto_unroll.c new file mode 100644 index 0000000..b46a423 --- /dev/null +++ b/source/extensions/pluto_unroll.c @@ -0,0 +1,422 @@ + + /*+-----------------------------------------------------------------** + ** OpenScop Library ** + **-----------------------------------------------------------------** + ** extensions/pluto_unroll.c ** + **-----------------------------------------------------------------** + ** First version: 26/06/2014 ** + **-----------------------------------------------------------------** + + + ***************************************************************************** + * OpenScop: Structures and formats for polyhedral tools to talk together * + ***************************************************************************** + * ,___,,_,__,,__,,__,,__,,_,__,,_,__,,__,,___,_,__,,_,__, * + * / / / // // // // / / / // // / / // / /|,_, * + * / / / // // // // / / / // // / / // / / / /\ * + * |~~~|~|~~~|~~~|~~~|~~~|~|~~~|~|~~~|~~~|~~~|~|~~~|~|~~~|/_/ \ * + * | G |C| P | = | L | P |=| = |C| = | = | = |=| = |=| C |\ \ /\ * + * | R |l| o | = | e | l |=| = |a| = | = | = |=| = |=| L | \# \ /\ * + * | A |a| l | = | t | u |=| = |n| = | = | = |=| = |=| o | |\# \ \ * + * | P |n| l | = | s | t |=| = |d| = | = | = | | |=| o | | \# \ \ * + * | H | | y | | e | o | | = |l| | | = | | | | G | | \ \ \ * + * | I | | | | e | | | | | | | | | | | | | \ \ \ * + * | T | | | | | | | | | | | | | | | | | \ \ \ * + * | E | | | | | | | | | | | | | | | | | \ \ \ * + * | * |*| * | * | * | * |*| * |*| * | * | * |*| * |*| * | / \* \ \ * + * | O |p| e | n | S | c |o| p |-| L | i | b |r| a |r| y |/ \ \ / * + * '---'-'---'---'---'---'-'---'-'---'---'---'-'---'-'---' '--' * + * * + * Copyright (C) 2014 Inria * + * * + * (3-clause BSD license) * + * Redistribution and use in source and binary forms, with or without * + * modification, are permitted provided that the following conditions * + * are met: * + * * + * 1. Redistributions of source code must retain the above copyright notice, * + * this list of conditions and the following disclaimer. * + * 2. Redistributions in binary form must reproduce the above copyright * + * notice, this list of conditions and the following disclaimer in the * + * documentation and/or other materials provided with the distribution. * + * 3. The name of the author may not be used to endorse or promote products * + * derived from this software without specific prior written permission. * + * * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + * * + * OpenScop Library, a library to manipulate OpenScop formats and data * + * structures. Written by: * + * Cedric Bastoul and * + * Louis-Noel Pouchet * + * * + *****************************************************************************/ + + +#include +#include + +#include "../include/osl/extensions/pluto_unroll.h" +#include "../include/osl/macros.h" + + +/*+*************************************************************************** + * Structure display function * + *****************************************************************************/ + + +/** + * osl_loop_idump function: + * this function displays an osl_pluto_unroll_t structure (pluto_unroll) into a + * file (file, possibly stdout) in a way that trends to be understandable. It + * includes an indentation level (level) in order to work with others + * idump functions. + * + * \param[in] file The file where the information has to be printed. + * \param[in] pluto_unroll The pluto_unroll structure to print. + * \param[in] level Number of spaces before printing, for each line. + */ +void osl_pluto_unroll_idump(FILE * file, + osl_pluto_unroll_p pluto_unroll, int level) { + int j, first = 1, number=1; + + // Go to the right level. + for (j = 0; j < level; j++) + fprintf(file, "|\t"); + + if (pluto_unroll != NULL) + fprintf(file, "+-- osl_pluto_unroll_t\n"); + else + fprintf(file, "+-- NULL pluto_unroll\n"); + + while (pluto_unroll != NULL) { + // Go to the right level. + if (!first) { + // Go to the right level. + for (j = 0; j < level; j++) + fprintf(file, "|\t"); + + fprintf(file, "| osl_pluto_unroll_t (node %d)\n", number); + } else { + first = 0; + } + + // A blank line. + for (j = 0; j <= level+1; j++) + fprintf(file, "|\t"); + fprintf(file, "\n"); + + // Display the names of iterators. + for (j = 0; j <= level; j++) + fprintf(file, "|\t"); + fprintf(file, "+--iterator: %s\n", pluto_unroll->iter); + + // Display the names of iterators. + for (j = 0; j <= level; j++) + fprintf(file, "|\t"); + fprintf(file, "+--jam: %i\n", pluto_unroll->jam); + + // Display the names of iterators. + for (j = 0; j <= level; j++) + fprintf(file, "|\t"); + fprintf(file, "+--factor: %i\n", pluto_unroll->factor); + + pluto_unroll = pluto_unroll->next; + + // Next line. + if (pluto_unroll != NULL) { + for (j = 0; j <= level; j++) + fprintf(file, "|\t"); + fprintf(file, "V\n"); + } + } + + // The last line. + for (j = 0; j <= level; j++) + fprintf(file, "|\t"); + fprintf(file, "\n"); +} + + +/** + * osl_pluto_unroll_dump function: + * this function prints the content of an osl_pluto_unroll_t structure + * (*pluto_unroll) into a file (file, possibly stdout). + * + * \param[in] file The file where the information has to be printed. + * \param[in] pluto_unroll The pluto_unroll structure to print. + */ +void osl_pluto_unroll_dump(FILE * file, osl_pluto_unroll_p pluto_unroll) { + osl_pluto_unroll_idump(file, pluto_unroll, 0); +} + + +/** + * osl_pluto_unroll_sprint function: + * this function prints the content of an osl_pluto_unroll_t structure + * (*pluto_unroll) into a string (returned) in the OpenScop textual format. + * + * \param[in] pluto_unroll The loop structure to print. + * + * \return a string containing the OpenScop dump of the loop structure. + */ +char * osl_pluto_unroll_sprint(osl_pluto_unroll_p pluto_unroll) { + + char* string = NULL; + char buffer[OSL_MAX_STRING] = { 0 }; + + strcat(buffer, "# Pluto unroll\n"); + if (pluto_unroll != NULL) { + strcat(buffer, "1\n"); + } else { + strcat(buffer, "0\n"); + } + + while (pluto_unroll != NULL) + { + strcat(buffer, "# Iterator name\n"); + sprintf(buffer + strlen(buffer), "%s\n", pluto_unroll->iter); + + strcat(buffer, "# Jam\n"); + sprintf(buffer + strlen(buffer), "%i\n", pluto_unroll->jam); + + strcat(buffer, "# Factor\n"); + sprintf(buffer + strlen(buffer), "%i\n", pluto_unroll->factor); + + pluto_unroll = pluto_unroll->next; + + strcat(buffer, "# Next\n"); + if (pluto_unroll != NULL) { + strcat(buffer, "1\n"); + } else { + strcat(buffer, "0\n"); + } + } + + OSL_realloc(string, char*, (strlen(buffer) + 1) * sizeof(char)); + strcpy(string, buffer); + + return string; +} + + +/***************************************************************************** + * Reading function * + *****************************************************************************/ + + +/** + * osl_pluto_unroll_sread function: + * this function reads a pluto_unroll structure from a string complying to the + * OpenScop textual format and returns a pointer to this pluto_unroll structure. + * The input parameter is updated to the position in the input string this + * function reaches right after reading the comment structure. + * + * \param[in,out] input The input string where to find an pluto_unroll + * structure. + * Updated to the position after what has been read. + * + * \return a pointer to the pluto_unroll structure that has been read. + */ +osl_pluto_unroll_p osl_pluto_unroll_sread(char** input) { + osl_pluto_unroll_p p = NULL; + if (osl_util_read_int(NULL, input) == 1) { p = osl_pluto_unroll_malloc(); } + osl_pluto_unroll_p r = p; + + while (p != NULL) + { + // iter + p->iter = osl_util_read_line(NULL, input); + // jam + p->jam = osl_util_read_int(NULL, input); + // factor + p->factor = osl_util_read_int(NULL, input); + // Next + if (osl_util_read_int(NULL, input) == 1) { + p->next = osl_pluto_unroll_malloc(); + } + p = p->next; + } + + return r; +} + + +/*+*************************************************************************** + * Memory allocation/deallocation function * + *****************************************************************************/ + + +/** + * osl_pluto_unroll_malloc function: + * this function allocates the memory space for an osl_pluto_unroll_t + * structure and sets its fields with default values. Then it returns a + * pointer to the allocated space. + * + * \return a pointer to an empty pluto_unroll structure with fields set to + * default values. + */ +osl_pluto_unroll_p osl_pluto_unroll_malloc() { + osl_pluto_unroll_p pluto_unroll = NULL; + + OSL_malloc(pluto_unroll, osl_pluto_unroll_p, sizeof(osl_pluto_unroll_t)); + pluto_unroll->iter = NULL; + pluto_unroll->jam = false; + pluto_unroll->factor = 0; + pluto_unroll->next = NULL; + + return pluto_unroll; +} + + +/** + * osl_pluto_unroll_free function: + * this function frees the allocated memory for an pluto_unroll structure. + * + * \param[in,out] pluto_unroll The pointer to the pluto_unroll structure + * we want to free. + */ +void osl_pluto_unroll_free(osl_pluto_unroll_p pluto_unroll) { + if (pluto_unroll != NULL) { + osl_pluto_unroll_free(pluto_unroll->next); + + free(pluto_unroll->iter); + free(pluto_unroll); pluto_unroll = NULL; + } +} + + +/*+*************************************************************************** + * Processing functions * + *****************************************************************************/ + +/** + * osl_pluto_unroll_fill function: + * this function fill the osl_pluto_unroll_t with the iterator name, + * if jam or not and the unroll factor + * + * \param[in] pluto_unroll The pointer to the osl_pluto_unroll_t + * \param[in] jam true if jam, falsee otherwise + * \param[in] factor Unroll factor + */ +void osl_pluto_unroll_fill(osl_pluto_unroll_p pluto_unroll, + char const * const iterator_name, + bool const jam, int const factor) { + if (pluto_unroll != NULL) { + // iter + if (iterator_name != NULL) { + OSL_realloc(pluto_unroll->iter, + char*, (strlen(iterator_name) + 1) * sizeof(char)); + strcpy(pluto_unroll->iter, iterator_name); + } + // jam + pluto_unroll->jam = jam; + // factor + pluto_unroll->factor = factor; + } else { + OSL_warning("osl_pluto_unroll_fill can not fill NULL osl_pluto_unroll_p"); + } +} + +/** + * osl_pluto_unroll_clone function: + * this function builds and returns a "hard copy" (not a pointer copy) of a + * list of osl_pluto_unroll_t data structures. + * + * \param[in] pluto_unroll The pointer to the list of pluto_unroll structure to + * clone. + * + * \return a pointer to the clone of list of the pluto_unroll structure. + */ +osl_pluto_unroll_p osl_pluto_unroll_clone(osl_pluto_unroll_p pluto_unroll) { + osl_pluto_unroll_p p = NULL; + if (pluto_unroll != NULL) { p = osl_pluto_unroll_malloc(); } + osl_pluto_unroll_p r = p; + + while (pluto_unroll != NULL) + { + osl_pluto_unroll_fill(p, pluto_unroll->iter, + pluto_unroll->jam, + pluto_unroll->factor); + + pluto_unroll = pluto_unroll->next; + + if (pluto_unroll != NULL) { p->next = osl_pluto_unroll_malloc(); } + p = p->next; + } + + return r; +} + +/** + * osl_pluto_unroll_equal function: + * this function returns true if the two pluto_unroll lists are the same + * (content-wise), false otherwise. Two lists are equal if one contains + * all the elements of the other and vice versa. The exact order of the + * nodes is not taken into account by this function. + * + * \param[in] a The first pluto_unroll list. + * \param[in] b The second pluto_unroll list. + * + * \return 1 if a and b are the same (content-wise), 0 otherwise. + */ +int osl_pluto_unroll_equal(osl_pluto_unroll_p a, osl_pluto_unroll_p b) { + + if (a == b) { return 1; } + + if (a == NULL && b != NULL) { return 0; } + if (a != NULL && b == NULL) { return 0; } + + while (a != NULL) { + // Iter + if (a->iter == NULL && b->iter != NULL) { return 0; } + if (a->iter != NULL && b->iter == NULL) { return 0; } + if (a->iter != NULL) { + if (strcmp(a->iter, b->iter) != 0) { return 0; } + + } + // Jam + if (a->jam != b->jam) { return 0; } + // Factor + if (a->factor != b->factor) { return 0; } + // Next + if (a->next == b->next) { return 1; } + if (a->next == NULL && b->next != NULL) { return 0; } + if (a->next != NULL && b->next == NULL) { return 0; } + a = a->next; + b = b->next; + } + + return 1; +} + + +/** + * osl_pluto_unroll_interface function: + * this function creates an interface structure corresponding to the + * pluto_unroll extension and returns it. + * + * \return an interface structure for the pluto_unroll extension. + */ +osl_interface_p osl_pluto_unroll_interface() { + osl_interface_p interface = osl_interface_malloc(); + + OSL_strdup(interface->URI, OSL_URI_PLUTO_UNROLL); + interface->idump = (osl_idump_f)osl_pluto_unroll_idump; + interface->sprint = (osl_sprint_f)osl_pluto_unroll_sprint; + interface->sread = (osl_sread_f)osl_pluto_unroll_sread; + interface->malloc = (osl_malloc_f)osl_pluto_unroll_malloc; + interface->free = (osl_free_f)osl_pluto_unroll_free; + interface->clone = (osl_clone_f)osl_pluto_unroll_clone; + interface->equal = (osl_equal_f)osl_pluto_unroll_equal; + + return interface; +} diff --git a/source/interface.c b/source/interface.c index 3b0846d..ea0987a 100644 --- a/source/interface.c +++ b/source/interface.c @@ -75,6 +75,7 @@ #include #include #include +#include #include #include #include @@ -402,6 +403,7 @@ osl_interface_p osl_interface_get_default_registry() { osl_interface_add(®istry, osl_symbols_interface()); osl_interface_add(®istry, osl_extbody_interface()); osl_interface_add(®istry, osl_loop_interface()); + osl_interface_add(®istry, osl_pluto_unroll_interface()); //osl_interface_add(®istry, osl_irregular_interface()); return registry; diff --git a/tests/Makefile.am b/tests/Makefile.am index 9b7c38b..6a7dd8f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -75,17 +75,19 @@ MAINTAINERCLEANFILES = Makefile.in ############################################################################# -noinst_PROGRAMS = osl_test osl_int +noinst_PROGRAMS = osl_test osl_int osl_pluto_unroll -TESTS = osl_test osl_int +TESTS = osl_test osl_int osl_pluto_unroll -osl_test_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static -osl_int_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_test_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_int_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static +osl_pluto_unroll_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include -static -osl_test_LDADD = ../libosl.la -osl_int_LDADD = ../libosl.la +osl_test_LDADD = ../libosl.la +osl_int_LDADD = ../libosl.la +osl_pluto_unroll_LDADD = ../libosl.la -osl_test_SOURCES = \ +osl_test_SOURCES = \ osl_test.c \ polynom.scop \ test_empty_statement.scop \ @@ -99,6 +101,7 @@ osl_test_SOURCES = \ test_clay.scop \ test_no_statement.scop \ test_scop_list.scop -osl_int_SOURCES = osl_int.c +osl_int_SOURCES = osl_int.c +osl_pluto_unroll_SOURCES = osl_pluto_unroll.c MAINTAINERCLEANFILE = ../autoconf/texinfo.tex diff --git a/tests/osl_pluto_unroll.c b/tests/osl_pluto_unroll.c new file mode 100644 index 0000000..f9cfd7c --- /dev/null +++ b/tests/osl_pluto_unroll.c @@ -0,0 +1,192 @@ +// Copyright © 2014 Inria, Written by Lénaïc Bagnères, lenaic.bagneres@inria.fr + +// (3-clause BSD license) +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// 3. The name of the author may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +#include +#include + +#include + + +int main(int argc, char * * argv) +{ + if (argc > 1) { printf("argv are ignored\n"); } + + int nb_fail = 0; + + osl_pluto_unroll_p p0 = NULL; + osl_pluto_unroll_p p1 = NULL; + osl_pluto_unroll_p pc = NULL; + + // Free without malloc + printf("// Free without malloc\n"); + osl_pluto_unroll_p p = NULL; + osl_pluto_unroll_free(p); + if (p != NULL) { nb_fail++; } + printf("\n"); + + // Malloc and free + printf("// Malloc and free\n"); + p = osl_pluto_unroll_malloc(); + osl_pluto_unroll_dump(stdout, p); + { + char * s = osl_pluto_unroll_sprint(p); + printf("%s\n", s); + free(s); s = NULL; + } + osl_pluto_unroll_free(p); p = NULL; + printf("\n"); + + // Malloc, malloc and free + printf("// Malloc, malloc and free\n"); + p = osl_pluto_unroll_malloc(); + p->next = osl_pluto_unroll_malloc(); + osl_pluto_unroll_dump(stdout, p); + { + char * s = osl_pluto_unroll_sprint(p); + printf("%s\n", s); + free(s); s = NULL; + } + osl_pluto_unroll_free(p); p = NULL; + printf("\n"); + + // osl_pluto_unroll_fill + printf("// osl_pluto_unroll_fill\n"); + p = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p, "iterator_name_0", true, 4); + p->next = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p->next, "iterator_name_1", false, 4); + osl_pluto_unroll_dump(stdout, p); + { + char * s = osl_pluto_unroll_sprint(p); + printf("%s\n", s); + free(s); s = NULL; + } + osl_pluto_unroll_free(p); p = NULL; + printf("\n"); + + // osl_pluto_unroll_fill with NULL + printf("// osl_pluto_unroll_fill with NULL\n"); + p = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p, NULL, true, 4); + p->next = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p->next, "iterator_name_1", false, 4); + osl_pluto_unroll_dump(stdout, p); + { + char * s = osl_pluto_unroll_sprint(p); + printf("%s\n", s); + free(s); s = NULL; + } + osl_pluto_unroll_free(p); p = NULL; + printf("\n"); + + // != + printf("// !=\n"); + p0 = osl_pluto_unroll_malloc(); + p0->next = osl_pluto_unroll_malloc(); + p0->next->next = osl_pluto_unroll_malloc(); + p1 = osl_pluto_unroll_malloc(); + p1->next = osl_pluto_unroll_malloc(); + if (osl_pluto_unroll_equal(p0, p1) == 1) { nb_fail++; } + if (osl_pluto_unroll_equal(p0, p0) == 0) { nb_fail++; } + if (osl_pluto_unroll_equal(p1, p1) == 0) { nb_fail++; } + osl_pluto_unroll_free(p0); p0 = NULL; + osl_pluto_unroll_free(p1); p1 = NULL; + printf("\n"); + + // == + printf("// ==\n"); + p0 = osl_pluto_unroll_malloc(); + p1 = osl_pluto_unroll_malloc(); + if (osl_pluto_unroll_equal(p0, p1) == 0) { nb_fail++; } + if (osl_pluto_unroll_equal(p1, p0) == 0) { nb_fail++; } + p0->next = osl_pluto_unroll_malloc(); + p1->next = osl_pluto_unroll_malloc(); + if (osl_pluto_unroll_equal(p0, p1) == 0) { nb_fail++; } + if (osl_pluto_unroll_equal(p1, p0) == 0) { nb_fail++; } + osl_pluto_unroll_fill(p0->next, "iterator_name_1", false, 4); + if (osl_pluto_unroll_equal(p0, p1) == 1) { nb_fail++; } + osl_pluto_unroll_fill(p1->next, "iterator_name_1", false, 4); + if (osl_pluto_unroll_equal(p0, p1) == 0) { nb_fail++; } + osl_pluto_unroll_fill(p0->next, "iterator_name_2", false, 4); + if (osl_pluto_unroll_equal(p0, p1) == 1) { nb_fail++; } + osl_pluto_unroll_fill(p1->next, "iterator_name_2", false, 4); + if (osl_pluto_unroll_equal(p0, p1) == 0) { nb_fail++; } + osl_pluto_unroll_fill(p1->next, "iterator_name_2", false, 8); + if (osl_pluto_unroll_equal(p0, p1) == 1) { nb_fail++; } + osl_pluto_unroll_fill(p0->next, "iterator_name_2", false, 8); + if (osl_pluto_unroll_equal(p0, p1) == 0) { nb_fail++; } + osl_pluto_unroll_fill(p0->next, "iterator_name_2", true, 8); + if (osl_pluto_unroll_equal(p0, p1) == 1) { nb_fail++; } + osl_pluto_unroll_free(p0); p0 = NULL; + osl_pluto_unroll_free(p1); p1 = NULL; + printf("\n"); + + // Clone NULL + printf("// Clone NULL\n"); + pc = osl_pluto_unroll_clone(p); + printf("\n"); + + // Clone + printf("// Clone\n"); + p = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p, "iterator_name_0", true, 4); + p->next = osl_pluto_unroll_malloc(); + p->next->next = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p->next->next, "iterator_name_2", false, 2); + pc = osl_pluto_unroll_clone(p); + osl_pluto_unroll_dump(stdout, p); + osl_pluto_unroll_dump(stdout, pc); + if (osl_pluto_unroll_equal(p, pc) == 0) { nb_fail++; } + osl_pluto_unroll_free(p); p = NULL; + osl_pluto_unroll_free(pc); pc = NULL; + printf("\n"); + + // osl_pluto_unroll_sread + printf("// osl_pluto_unroll_sread\n"); + p = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p, "iterator_name_0", true, 4); + p->next = osl_pluto_unroll_malloc(); + osl_pluto_unroll_fill(p->next, "iterator_name_1", false, 4); + osl_pluto_unroll_dump(stdout, p); + { + char * s = osl_pluto_unroll_sprint(p); + char * f = s; + pc = osl_pluto_unroll_sread(&s); + free(f); f = NULL; f = NULL; + } + osl_pluto_unroll_dump(stdout, pc); + if (osl_pluto_unroll_equal(p, pc) == 0) { nb_fail++; } + osl_pluto_unroll_free(p); p = NULL; + osl_pluto_unroll_free(pc); pc = NULL; + printf("\n"); + + printf("%s ", argv[0]); + printf("fails = %d\n", nb_fail); + printf("\n"); + + return nb_fail; +} -- 2.11.4.GIT