From 029edd0fe9d7a63c037a10df1ec61edb160f77b1 Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Tue, 22 Sep 2009 21:20:19 +0200 Subject: [PATCH] Reintroduce CloogMatrix Reintroduce the CloogMatrix data structure found in the CLooG documentation. Also update the documentation to reflect that it is not any more added by polylib, but implements an equivalent data structure in the CLooG header files. Signed-off-by: Tobias Grosser Signed-off-by: Sven Verdoolaege --- Makefile.am | 2 + doc/cloog.texi | 33 +++----- include/cloog/cloog.h | 1 + include/cloog/matrix.h | 54 +++++++++++++ include/cloog/cloog.h => source/matrix.c | 131 +++++++++++++++++++++++++------ 5 files changed, 172 insertions(+), 49 deletions(-) create mode 100644 include/cloog/matrix.h copy include/cloog/cloog.h => source/matrix.c (51%) diff --git a/Makefile.am b/Makefile.am index 61dac7c..0e824c3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -62,6 +62,7 @@ SOURCES_CORE = \ $(GET_MEMORY_FUNCTIONS) \ source/block.c \ source/clast.c \ + source/matrix.c \ source/state.c \ source/int.c \ source/loop.c \ @@ -100,6 +101,7 @@ pkginclude_HEADERS = \ include/cloog/block.h \ include/cloog/clast.h \ include/cloog/cloog.h \ + include/cloog/matrix.h \ include/cloog/state.h \ include/cloog/domain.h \ include/cloog/loop.h \ diff --git a/doc/cloog.texi b/doc/cloog.texi index 2cba0a4..82e6ff8 100644 --- a/doc/cloog.texi +++ b/doc/cloog.texi @@ -1495,27 +1495,20 @@ created within the state of an other @code{CloogState} structure. @node CloogMatrix @subsection CloogMatrix -@example -@group -#define CloogMatrix Matrix -@end group -@end example -@noindent The @code{CloogMatrix} structure is directly the PolyLib +@noindent The @code{CloogMatrix} structure is equivalent to the PolyLib @code{Matrix} data structure (@pxref{Wil93}). This structure is devoted to -represent a set of constraints. It is -defined in @code{polylib/types.h} as the following: +represent a set of constraints. @example @group -struct matrix +struct cloogmatrix @{ unsigned NbRows ; /* Number of rows. */ unsigned NbColumns ; /* Number of columns. */ - Value ** p ; /* Array of pointers to the matrix rows. */ - Value * p_Init ; /* Matrix rows contiguously in memory. */ - int p_Init_size ; /* For internal use. */ -@} -typedef struct matrix Matrix; + cloog_int_t **p; /* Array of pointers to the matrix rows. */ + cloog_int_t *p_Init; /* Matrix rows contiguously in memory. */ +@}; +typedef struct cloogmatrix CloogMatrix; @end group @end example @@ -1528,8 +1521,8 @@ Each row corresponds to a constraint. The first element of each row is an equality/inequality tag. The constraint is an equality @math{p(x) = 0} if the first element is 0, but it is an inequality @math{p(x) \geq 0} if the first element is 1. -The next elements are the unknown coefficients, followed by the parameter -coefficients, then the scalar coefficient. +The next elements are the coefficients of the unknowns, +followed by the coefficients of the parameters, and finally the constant term. For instance, the following three constraints: @tex @@ -1563,15 +1556,9 @@ $$ @noindent To be able to provide different precision version (CLooG supports 32 bits, 64 bits and arbitrary precision through the GMP library), -the @code{Value} type depends on the configuration options (it may be +the @code{cloog_int_t} type depends on the configuration options (it may be @code{long int} for 32 bits version, @code{long long int} for 64 bits version, and @code{mpz_t} for multiple precision version). -The @code{p_Init_size} field is needed by the PolyLib to free -the memory allocated by @code{mpz_init} in the multiple precision release. -Set this field to 0 if you are @emph{not} using multiple precision. -Set this field to the size of the @code{p_Init} array if you -initialized it yourself and if you are using the multiple precision version. - @node CloogDomain @subsection CloogDomain diff --git a/include/cloog/cloog.h b/include/cloog/cloog.h index 905997f..f49a102 100644 --- a/include/cloog/cloog.h +++ b/include/cloog/cloog.h @@ -43,6 +43,7 @@ #include #include +#include #include #include #include diff --git a/include/cloog/matrix.h b/include/cloog/matrix.h new file mode 100644 index 0000000..669e1e7 --- /dev/null +++ b/include/cloog/matrix.h @@ -0,0 +1,54 @@ +#ifndef CLOOG_MATRIX_H +#define CLOOG_MATRIX_H +#if defined(__cplusplus) +extern "C" + { +#endif + +/* The CloogMatrix structure is equivalent to the PolyLib Matrix data structure + * (see Wil93). This structure is devoted to represent a set of constraints. + * + * The whole matrix is stored in memory row after row at the p_Init address. p + * is an array of pointers where p[i] points to the first element of the i^{th + * row. NbRows and NbColumns are respectively the number of rows and columns of + * the matrix. Each row corresponds to a constraint. The first element of each + * row is an equality/inequality tag. The constraint is an equality p(x) = 0 if + * the first element is 0, but it is an inequality p(x) \geq 0 if the first + * element is 1. The next elements are the unknown coefficients, followed by + * the parameter coefficients, then the constant term. For instance, the + * following three constraints: + * + * -i + m = 0 + * -j + n >= 0 + * i + j - k >= 0 + * + * would be represented by the following rows: + * + * # eq/in i j k m n cst + * 0 0 -1 0 1 0 0 + * 1 -1 0 0 0 1 0 + * 1 1 1 -1 0 0 0 + * + * To be able to provide different precision version (CLooG supports 32 bits, + * 64 bits and arbitrary precision through the GMP library), the cloog_int_t + * type depends on the configuration options (it may be long int for 32 bits + * version, long long int for 64 bits version, and mpz_t for multiple precision + * version). */ + +struct cloogmatrix +{ unsigned NbRows; /* Number of rows. */ + unsigned NbColumns; /* Number of columns. */ + cloog_int_t ** p; /* Array of pointers to the matrix rows. */ + cloog_int_t * p_Init; /* Matrix rows contiguously in memory. */ +}; + +typedef struct cloogmatrix CloogMatrix; + +CloogMatrix *cloog_matrix_alloc (unsigned, unsigned); +void cloog_matrix_free (CloogMatrix *); +void cloog_matrix_print(FILE*, CloogMatrix*); + +#if defined(__cplusplus) + } +#endif +#endif /* define _H */ diff --git a/include/cloog/cloog.h b/source/matrix.c similarity index 51% copy from include/cloog/cloog.h copy to source/matrix.c index 905997f..85a0cb3 100644 --- a/include/cloog/cloog.h +++ b/source/matrix.c @@ -1,10 +1,7 @@ - /**-------------------------------------------------------------------** - ** CLooG ** - **-------------------------------------------------------------------** - ** cloog.h ** + ** CLooG ** **-------------------------------------------------------------------** - ** First version: july 25th 2002 ** + ** cloogmatrix.c ** **-------------------------------------------------------------------**/ @@ -34,25 +31,107 @@ * * ******************************************************************************/ -/****************************************************************************** - * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM clooh.h.in BY configure * - ******************************************************************************/ +#include +#include +#include "../include/cloog/cloog.h" + +/** + * cloog_matrix_alloc: + * Allocate a CloogMatrix data structure with NbRows rows and NbColumns columns. + * All values are initialized to 0. + * This method returns a pointer to the data structure if successful or a NULL + * pointer otherwise. + */ +CloogMatrix *cloog_matrix_alloc(unsigned NbRows, unsigned NbColumns) +{ + CloogMatrix *matrix; + cloog_int_t **p, *q; + int i, j; + + matrix = (CloogMatrix *)malloc(sizeof(CloogMatrix)); + + if (!matrix) + return NULL; + + matrix->NbRows = NbRows; + matrix->NbColumns = NbColumns; + + if (!NbRows || !NbColumns) { + matrix->p = NULL; + matrix->p_Init = NULL; + return matrix; + } + + p = (cloog_int_t **)malloc(NbRows * sizeof(cloog_int_t *)); + + if (p == NULL) { + free (matrix); + return NULL; + } + + q = (cloog_int_t *)malloc(NbRows * NbColumns * sizeof(cloog_int_t)); + + if (q == NULL) { + free (matrix); + free (p); + return NULL; + } + + matrix->p = p; + matrix->p_Init = q; + + for (i = 0; i < NbRows; i++) { + *p++ = q; + for (j = 0; j < NbColumns; j++) { + cloog_int_init(*(q+j)); + cloog_int_set_si(*(q+j), 0); + } + q += NbColumns; + } + + return matrix; +} + +/** + * cloog_matrix_free: + * Free matrix. + */ +void cloog_matrix_free(CloogMatrix * matrix) +{ + int i; + cloog_int_t *p; + int size = matrix->NbRows * matrix->NbColumns; + + p = matrix->p_Init; + + for (i = 0; i < size; i++) + cloog_int_clear(*p++); + + if (matrix) { + free(matrix->p_Init); + free(matrix->p); + free(matrix); + } +} + +/** + * cloog_matrix_print function: + * This function prints the content of a CloogMatrix structure (matrix) into a + * file (foo, possibly stdout). + */ +void cloog_matrix_print(FILE* foo, CloogMatrix* m) +{ + int i, j; + + if (!m) + fprintf(foo, "(null)\n"); -#ifndef CLOOG_H -#define CLOOG_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif /* !CLOOG_H */ + for (i = 0; i < m->NbRows; ++i) { + for (j = 0; j < m->NbColumns; ++j) { + cloog_int_print(foo, m->p[i][j]); + fprintf(foo, " "); + } + fprintf(foo, "\n"); + } + fflush(foo); +} -- 2.11.4.GIT