forked from periscop/cloog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
5a7c17d
commit 029edd0
Showing
5 changed files
with
204 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |