Skip to content

Commit

Permalink
Reintroduce CloogMatrix
Browse files Browse the repository at this point in the history
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 <grosser@fim.uni-passau.de>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
  • Loading branch information
tobiasgrosser authored and Sven Verdoolaege committed Sep 24, 2009
1 parent 5a7c17d commit 029edd0
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 23 deletions.
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
33 changes: 10 additions & 23 deletions doc/cloog.texi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions include/cloog/cloog.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

#include <cloog/version.h>
#include <cloog/int.h>
#include <cloog/matrix.h>
#include <cloog/state.h>
#include <cloog/options.h>
#include <cloog/names.h>
Expand Down
54 changes: 54 additions & 0 deletions include/cloog/matrix.h
Original file line number Diff line number Diff line change
@@ -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 */
137 changes: 137 additions & 0 deletions source/matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**-------------------------------------------------------------------**
** CLooG **
**-------------------------------------------------------------------**
** cloogmatrix.c **
**-------------------------------------------------------------------**/


/******************************************************************************
* CLooG : the Chunky Loop Generator (experimental) *
******************************************************************************
* *
* Copyright (C) 2001-2005 Cedric Bastoul *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301 USA *
* *
* CLooG, the Chunky Loop Generator *
* Written by Cedric Bastoul, Cedric.Bastoul@inria.fr *
* *
******************************************************************************/

#include <stdlib.h>
#include <stdio.h>
#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");

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);
}

0 comments on commit 029edd0

Please sign in to comment.