From 5a201cdd57796619aede729e7ad29fdd38e81086 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Fri, 5 Sep 2008 22:41:40 +0200 Subject: [PATCH] Replace use of Value in cloog core by new cloog_int_t --- Makefile.am | 3 + autogen.sh | 1 + configure.in | 19 ++ include/cloog/block.h | 4 +- include/cloog/clast.h | 12 +- include/cloog/cloog.h.in | 345 +++++--------------------- include/cloog/constraints.h | 8 +- include/cloog/domain.h | 8 +- include/cloog/int.h.in | 154 ++++++++++++ include/cloog/loop.h | 2 +- include/cloog/{cloog.h.in => polylib/cloog.h} | 63 +---- include/cloog/program.h | 4 +- source/block.c | 10 +- source/clast.c | 328 ++++++++++++------------ source/cloog.c | 12 +- source/int.c | 81 ++++++ source/loop.c | 167 +++++++------ source/pprint.c | 21 +- source/program.c | 29 ++- 19 files changed, 627 insertions(+), 644 deletions(-) rewrite include/cloog/cloog.h.in (79%) create mode 100644 include/cloog/int.h.in copy include/cloog/{cloog.h.in => polylib/cloog.h} (78%) create mode 100644 source/int.c diff --git a/Makefile.am b/Makefile.am index 136343e..91ea058 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ libcloog_la_SOURCES = \ source/block.c \ source/clast.c \ source/polylib/domain.c \ + source/int.c \ source/loop.c \ source/polylib/matrix.c \ source/names.c \ @@ -74,6 +75,8 @@ pkginclude_HEADERS = \ include/cloog/program.h \ include/cloog/statement.h \ include/cloog/version.h +nodist_pkginclude_HEADERS = \ + include/cloog/int.h pkgpolylibincludedir = $(pkgincludedir)/polylib pkgpolylibinclude_HEADERS = \ diff --git a/autogen.sh b/autogen.sh index 58dc490..6db8c55 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,5 +1,6 @@ #!/bin/sh libtoolize -c --force aclocal +autoheader automake -a -c --foreign autoconf diff --git a/configure.in b/configure.in index 870d88c..0cc512b 100644 --- a/configure.in +++ b/configure.in @@ -258,6 +258,23 @@ fi if test "$cl_cv_polylib" = "missing"; then AC_MSG_ERROR(Can't find PolyLib.) fi +case "$BITS" in + gmp) + cl_cv_int_type=gmp + ;; + 32|64) + AC_CHECK_SIZEOF(int,1) + AC_CHECK_SIZEOF(long,1) + AC_CHECK_SIZEOF(long long,1) + for cl_cv_int_type in int long long_long; do + eval "bits=\`expr \$ac_cv_sizeof_$cl_cv_int_type \* 8\`" + if test "$bits" = "$BITS"; then + break + fi + done + ;; +esac +AC_DEFINE_UNQUOTED(AS_TR_CPP(CLOOG_INT_$cl_cv_int_type)) AC_SUBST(GIT_INDEX) if test -f $srcdir/.git/HEAD; then @@ -282,6 +299,8 @@ AC_SUBST(INSTALL) AC_SUBST(BITS) +AC_CONFIG_HEADERS(config.h) +AC_CONFIG_HEADERS(include/cloog/int.h) AC_CONFIG_FILES(Makefile test/Makefile include/cloog/cloog.h autoconf/Doxyfile) AC_CONFIG_FILES(doc/Makefile) AC_CONFIG_FILES(source/version.c) diff --git a/include/cloog/block.h b/include/cloog/block.h index 25cc313..ffbb0c9 100644 --- a/include/cloog/block.h +++ b/include/cloog/block.h @@ -59,7 +59,7 @@ extern "C" struct cloogblock { CloogStatement * statement ; /**< The list of statements in the block. */ int nb_scaldims ; /**< Number of scalar dimensions. */ - Value * scaldims ; /**< Scalar dimension values. */ + cloog_int_t *scaldims; /**< Scalar dimension values. */ int depth ; /**< Original block depth (outer loop number).*/ int references ; /**< Number of references to this structure. */ void * usr; /**< User field, for library user convenience. @@ -101,7 +101,7 @@ void cloog_block_list_free(CloogBlockList *) ; ******************************************************************************/ CloogBlock * cloog_block_malloc(void); CloogBlock * cloog_block_alloc(CloogStatement *statement, int nb_scaldims, - Value *scaldims, int depth); + cloog_int_t *scaldims, int depth); CloogBlockList * cloog_block_list_malloc(void); CloogBlockList * cloog_block_list_alloc(CloogBlock *) ; CloogBlock * cloog_block_copy(CloogBlock * block) ; diff --git a/include/cloog/clast.h b/include/cloog/clast.h index 66882a1..d98bc05 100644 --- a/include/cloog/clast.h +++ b/include/cloog/clast.h @@ -11,7 +11,7 @@ struct clast_expr { struct clast_term { struct clast_expr expr; - Value val; + cloog_int_t val; const char * var; }; @@ -29,7 +29,7 @@ struct clast_binary { struct clast_expr expr; enum clast_bin_type type; struct clast_expr* LHS; - Value RHS; + cloog_int_t RHS; }; struct clast_stmt; @@ -78,7 +78,7 @@ struct clast_for { const char * iterator; struct clast_expr * LB; struct clast_expr * UB; - Value stride; + cloog_int_t stride; struct clast_stmt * body; }; @@ -100,9 +100,9 @@ struct clast_stmt *cloog_clast_create(CloogProgram *program, CloogOptions *options); void cloog_clast_free(struct clast_stmt *s); -struct clast_term *new_clast_term(Value c, const char *v); +struct clast_term *new_clast_term(cloog_int_t c, const char *v); struct clast_binary *new_clast_binary(enum clast_bin_type t, - struct clast_expr *lhs, Value rhs); + struct clast_expr *lhs, cloog_int_t rhs); struct clast_reduction *new_clast_reduction(enum clast_red_type t, int n); struct clast_root *new_clast_root(CloogNames *names); struct clast_assignment *new_clast_assignment(const char *lhs, @@ -111,7 +111,7 @@ struct clast_user_stmt *new_clast_user_stmt(CloogStatement *stmt, struct clast_stmt *subs); struct clast_block *new_clast_block(void); struct clast_for *new_clast_for(const char *it, struct clast_expr *LB, - struct clast_expr *UB, Value stride); + struct clast_expr *UB, cloog_int_t stride); struct clast_guard *new_clast_guard(int n); void free_clast_term(struct clast_term *t); diff --git a/include/cloog/cloog.h.in b/include/cloog/cloog.h.in dissimilarity index 79% index 7616bab..fdaa9e2 100644 --- a/include/cloog/cloog.h.in +++ b/include/cloog/cloog.h.in @@ -1,288 +1,57 @@ - - /**-------------------------------------------------------------------** - ** CLooG ** - **-------------------------------------------------------------------** - ** cloog.h ** - **-------------------------------------------------------------------** - ** First version: july 25th 2002 ** - **-------------------------------------------------------------------**/ - - -/****************************************************************************** - * CLooG : the Chunky Loop Generator (experimental) * - ****************************************************************************** - * * - * Copyright (C) 2001-2005 Cedric Bastoul * - * * - * This is free software; you can redistribute it and/or modify it under the * - * terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 2 of the License, or (at your option) any later * - * version. * - * * - * This software 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 General Public License * - * for more details. * - * * - * You should have received a copy of the GNU General Public License along * - * with software; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - * CLooG, the Chunky Loop Generator * - * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr * - * * - ******************************************************************************/ - -/****************************************************************************** - * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM clooh.h.in BY configure * - ******************************************************************************/ - -#ifndef CLOOG_H -#define CLOOG_H - -# include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -/****************************************************************************** - * CLOOG GMP MACROS * - ******************************************************************************/ -#ifdef GNUMP -#define value_init_c(val) { mpz_init((val)) ; \ - cloog_value_leak_up() ; \ - } -#define value_clear_c(val) { mpz_clear((val)) ; \ - cloog_value_leak_down() ; \ - } -#define value_sprint(Dst,fmt,val) { char * str ; \ - str = mpz_get_str(0,10,(val)) ; \ - sprintf((Dst),(fmt),str) ; \ - free(str) ; \ - } -#define value_eq_si(v1,i2) (mpz_cmp_si((v1),(i2)) == 0) -#define value_ne_si(v1,i2) (mpz_cmp_si((v1),(i2)) != 0) -#define value_gt_si(v1,i2) (mpz_cmp_si((v1),(i2)) > 0) -#define value_lt_si(v1,i2) (mpz_cmp_si((v1),(i2)) < 0) -#define value_multiply_si(ref,v1,i2) (mpz_mul_si((ref),(v1),(i2))) - - -/****************************************************************************** - * CLOOG BASIC TYPES MACROS * - ******************************************************************************/ -#else -#define value_init_c(val) ((val) = 0) -#define value_clear_c(val) ((val) = 0) -#define value_sprint(Dst,fmt,val) (sprintf((Dst),(fmt),(val))) -#define value_eq_si(v1,i2) ((v1) == (i2)) -#define value_ne_si(v1,i2) ((v1) != (i2)) -#define value_gt_si(v1,i2) ((v1) > (i2)) -#define value_lt_si(v1,i2) ((v1) < (i2)) -#define value_multiply_si(ref,v1,i2) ((ref) = value_mult((v1),(i2))) -#endif - -#ifndef value_subtract -#define value_subtract value_substract -#endif - - -/****************************************************************************** - * POLYLIB MACROS * - ****************************************************************************** - * Because I was tired to look in polylib/include/polylib/arithmetique.h for * - * the existing macros, here is a copy ! * - ******************************************************************************/ -#if 0 - -/****************************************************************************** - * POLYLIB GMP MACROS * - ******************************************************************************/ -#if defined(GNUMP) - -/* Basic macros */ - -#define value_init(val) (mpz_init((val))) -#define value_assign(v1,v2) (mpz_set((v1),(v2))) -#define value_set_si(val,i) (mpz_set_si((val),(i))) -#define value_set_double(val,d) (mpz_set_d((val),(d))) -#define value_clear(val) (mpz_clear((val))) -#define value_read(val,str) (mpz_set_str((val),(str),10)) -#define value_print(Dst,fmt,val) {char *str; \ - str = mpz_get_str(0,10,(val)); \ - fprintf((Dst),(fmt),str); free(str); \ - } -#define value_swap(val1,val2) {mpz_t tmp; mpz_init_set(tmp,(val1)); \ - mpz_set((val1),(val2)); \ - mpz_set((val2),tmp); \ - mpz_clear(tmp); \ - } - -/* Boolean operators on 'Value' */ - -#define value_eq(v1,v2) (mpz_cmp((v1),(v2)) == 0) -#define value_ne(v1,v2) (mpz_cmp((v1),(v2)) != 0) -#define value_gt(v1,v2) (mpz_cmp((v1),(v2)) > 0) -#define value_ge(v1,v2) (mpz_cmp((v1),(v2)) >= 0) -#define value_lt(v1,v2) (mpz_cmp((v1),(v2)) < 0) -#define value_le(v1,v2) (mpz_cmp((v1),(v2)) <= 0) - -/* Trian operators on 'Value' */ - -#define value_sign(val) (mpz_sgn(val)) -#define value_compare(v1,v2) (mpz_cmp((v1),(v2))) - -/* Binary operations on 'Value' */ - -#define value_addto(ref,val1,val2) (mpz_add((ref),(val1),(val2))) -#define value_add_int(ref,val,vint) (mpz_add_ui((ref),(val),(long)(vint))) -#define value_increment(ref,val) (mpz_add_ui((ref),(val),1)) -#define value_multiply(ref,val1,val2) (mpz_mul((ref),(val1),(val2))) -#define value_substract(ref,val1,val2) (mpz_sub((ref),(val1),(val2))) -#define value_sub_int(ref,val,vint) (mpz_sub_ui((ref),(val),(long)(vint))) -#define value_decrement(ref,val) (mpz_sub_ui((ref),(val),1)) -#define value_division(ref,val1,val2) (mpz_tdiv_q((ref),(val1),(val2))) -#define value_modulus(ref,val1,val2) (mpz_tdiv_r((ref),(val1),(val2))) -#define value_pdivision(ref,val1,val2) (mpz_fdiv_q((ref),(val1),(val2))) -#define value_oppose(ref,val) (mpz_neg((ref),(val))) -#define value_absolute(ref,val) (mpz_abs((ref),(val))) -#define value_minimum(ref,val1,val2) (value_le((val1),(val2)) ? \ - mpz_set((ref),(val1)) : \ - mpz_set((ref),(val2))) -#define value_maximum(ref,val1,val2) (value_ge((val1),(val2)) ? \ - mpz_set((ref),(val1)) : \ - mpz_set((ref),(val2))) -#define value_orto(ref,val1,val2) (mpz_ior((ref),(val1),(val2))) -#define value_andto(ref,val1,val2) (mpz_and((ref),(val1),(val2))) - -/* Conditional operations on 'Value' */ - -#define value_pos_p(val) (mpz_sgn(val) > 0) -#define value_neg_p(val) (mpz_sgn(val) < 0) -#define value_posz_p(val) (mpz_sgn(val) >= 0) -#define value_negz_p(val) (mpz_sgn(val) <= 0) -#define value_zero_p(val) (mpz_sgn(val) == 0) -#define value_notzero_p(val) (mpz_sgn(val) != 0) -#define value_one_p(val) (mpz_cmp_si(val,1) == 0) -#define value_notone_p(val) (mpz_cmp_si(val,1) != 0) -#define value_mone_p(val) (mpz_cmp_si(val,-1) ==0) -#define value_notmone_p(val) (mpz_cmp_si(val,-1) !=0) - - -/****************************************************************************** - * POLYLIB BASIC TYPES MACROS * - ******************************************************************************/ -#else /* 'Value' set to longlong|long|float|char *|int */ - -/* Basic Macros */ - -#define value_init(val) ((val) = 0) -#define value_assign(v1,v2) ((v1) = (v2)) -#define value_set_si(val,i) ((val) = (Value)(i)) -#define value_set_double(val,d) ((val) = (Value)(d)) -#define value_clear(val) ((val) = 0) -#define value_read(val,str) (sscanf((str),VALUE_FMT,&(val))) -#define value_print(Dst,fmt,val) (fprintf((Dst),(fmt),(val))) -#define value_swap(v1,v2) {Value tmp; tmp = v2; \ - v2 = v1; v1 = tmp; \ - } -/* Cast to 'Value' */ - -#define int_to_value(i) ((Value)(i)) -#define long_to_value(l) ((Value)(l)) -#define float_to_value(f) ((Value)(f)) -#define double_to_value(d) ((Value)(d)) - -/* Boolean operators on 'Value' */ - -#define value_eq(v1,v2) ((v1)==(v2)) -#define value_ne(v1,v2) ((v1)!=(v2)) -#define value_gt(v1,v2) ((v1)>(v2)) -#define value_ge(v1,v2) ((v1)>=(v2)) -#define value_lt(v1,v2) ((v1)<(v2)) -#define value_le(v1,v2) ((v1)<=(v2)) - -/* Trian operators on 'Value' */ - -#define value_sign(v) (value_eq(v,VALUE_ZERO) ? \ - 0: \ - value_lt(v,VALUE_ZERO)?-1:1) -#define value_compare(v1,v2) (value_eq(v1,v2)? \ - 0: \ - value_lt(v1,v2)?-1:1) - -/* Binary operators on 'Value' */ - -#define value_plus(v1,v2) ((v1)+(v2)) -#define value_div(v1,v2) ((v1)/(v2)) -#define value_mod(v1,v2) ((v1)%(v2)) -#define value_direct_multiply(v1,v2) ((v1)*(v2)) /* direct! */ -#define value_minus(v1,v2) ((v1)-(v2)) -#define value_pdiv(v1,v2) (divide((v1),(v2))) -#define value_pmod(v1,v2) (modulo((v1),(v2))) -#define value_min(v1,v2) (value_le((v1),(v2))? (v1): (v2)) -#define value_max(v1,v2) (value_ge((v1),(v2))? (v1): (v2)) -#define value_or(v1,v2) ((v1)|(v2)) -#define value_and(v1,v2) ((v1)&(v2)) -#define value_lshift(v1,v2) ((v1)<<(v2)) -#define value_rshift(v1,v2) ((v1)>>(v2)) - -/* Binary operations on 'Value' */ - -#define value_addto(ref,val1,val2) ((ref) = (val1)+(val2)) -#define value_add_int(ref,val,vint) ((ref) = (val)+(Value)(vint)) -#define value_increment(ref,val) ((ref) = (val)+VALUE_ONE) -#define value_direct_product(ref,val1,val2) ((ref) = (val1)*(val2)) /* direct */ -#define value_multiply(ref,val1,val2) ((ref) = value_mult((val1),(val2))) -#define value_substract(ref,val1,val2) ((ref) = (val1)-(val2)) -#define value_sub_int(ref,val,vint) ((ref) = (val)-(Value)(vint)) -#define value_decrement(ref,val) ((ref) = (val)-VALUE_ONE) -#define value_division(ref,val1,val2) ((ref) = (val1)/(val2)) -#define value_modulus(ref,val1,val2) ((ref) = (val1)%(val2)) -#define value_pdivision(ref,val1,val2) ((ref) = value_pdiv((val1),(val2))) -#define value_oppose(ref,val) ((ref) = value_uminus((val))) -#define value_absolute(ref,val) ((ref) = value_abs((val))) -#define value_minimum(ref,val1,val2) ((ref) = value_min((val1),(val2))) -#define value_maximum(ref,val1,val2) ((ref) = value_max((val1),(val2))) -#define value_orto(ref,val1,val2) ((ref) = (val1)|(val2)) -#define value_andto(ref,val1,val2) ((ref) = (val1)&(val2)) - -/* Unary operators on 'Value' */ - -#define value_uminus(val) (-(val)) -#define value_not(val) (~(val)) -#define value_abs(val) (value_posz_p(val)? \ - (val) : \ - (value_ne((val), VALUE_NAN) ? \ - value_uminus(val) : \ - (THROW (overflow_error), VALUE_NAN ))) - -/* Conditional operations on 'Value' */ - -#define value_pos_p(val) value_gt(val,VALUE_ZERO) -#define value_neg_p(val) value_lt(val,VALUE_ZERO) -#define value_posz_p(val) value_ge(val,VALUE_ZERO) -#define value_negz_p(val) value_le(val,VALUE_ZERO) -#define value_zero_p(val) value_eq(val,VALUE_ZERO) -#define value_notzero_p(val) value_ne(val,VALUE_ZERO) -#define value_one_p(val) value_eq(val,VALUE_ONE) -#define value_notone_p(val) value_ne(val,VALUE_ONE) -#define value_mone_p(val) value_eq(val,VALUE_MONE) -#define value_notmone_p(val) value_ne(val,VALUE_MONE) -#define value_min_p(val) value_eq(val,VALUE_MIN) -#define value_max_p(val) value_eq(val,VALUE_MAX) -#define value_notmin_p(val) value_ne(val,VALUE_MIN) -#define value_notmax_p(val) value_ne(val,VALUE_MAX) - -#endif /* 'Value' set to |longlong|long|float|char *|int */ -#endif - -#endif /* !CLOOG_H */ + + /**-------------------------------------------------------------------** + ** CLooG ** + **-------------------------------------------------------------------** + ** cloog.h ** + **-------------------------------------------------------------------** + ** First version: july 25th 2002 ** + **-------------------------------------------------------------------**/ + + +/****************************************************************************** + * CLooG : the Chunky Loop Generator (experimental) * + ****************************************************************************** + * * + * Copyright (C) 2001-2005 Cedric Bastoul * + * * + * This is free software; you can redistribute it and/or modify it under the * + * terms of the GNU General Public License as published by the Free Software * + * Foundation; either version 2 of the License, or (at your option) any later * + * version. * + * * + * This software 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 General Public License * + * for more details. * + * * + * You should have received a copy of the GNU General Public License along * + * with software; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + * CLooG, the Chunky Loop Generator * + * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr * + * * + ******************************************************************************/ + +/****************************************************************************** + * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM clooh.h.in BY configure * + ******************************************************************************/ + +#ifndef CLOOG_H +#define CLOOG_H + +# include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif /* !CLOOG_H */ diff --git a/include/cloog/constraints.h b/include/cloog/constraints.h index 388db97..6f58e31 100644 --- a/include/cloog/constraints.h +++ b/include/cloog/constraints.h @@ -85,14 +85,14 @@ int cloog_constraint_is_lower_bound(CloogConstraints *constraints, int int cloog_constraint_is_upper_bound(CloogConstraints *constraints, int c, int v); int cloog_constraint_is_equality(CloogConstraints *constraints, int c); void cloog_constraint_constant_get(CloogConstraints *constraints, - int c, Value *val); + int c, cloog_int_t *val); void cloog_constraint_coefficient_get(CloogConstraints *constraints, - int c, int var, Value *val); + int c, int var, cloog_int_t *val); void cloog_constraint_coefficient_set(CloogConstraints *constraints, - int c, int var, Value val); + int c, int var, cloog_int_t val); void cloog_constraint_clear(CloogConstraints *constraints, int c); void cloog_constraint_copy(CloogConstraints *constraints, int c, - Value *dst); + cloog_int_t *dst); #if defined(__cplusplus) } diff --git a/include/cloog/domain.h b/include/cloog/domain.h index fea4afd..ddada63 100644 --- a/include/cloog/domain.h +++ b/include/cloog/domain.h @@ -111,16 +111,16 @@ int cloog_domain_universe(CloogDomain *) ; CloogDomain * cloog_domain_project(CloogDomain *, int, int) ; CloogDomain * cloog_domain_extend(CloogDomain *, int, int) ; int cloog_domain_never_integral(CloogDomain *) ; -void cloog_domain_stride(CloogDomain *, int, int, Value *, Value *) ; -int cloog_domain_integral_lowerbound(CloogDomain *, int, Value *) ; -void cloog_domain_lowerbound_update(CloogDomain *, int, Value) ; +void cloog_domain_stride(CloogDomain *, int, int, cloog_int_t *, cloog_int_t *); +int cloog_domain_integral_lowerbound(CloogDomain *, int, cloog_int_t *); +void cloog_domain_lowerbound_update(CloogDomain *, int, cloog_int_t); int cloog_domain_lazy_disjoint(CloogDomain *, CloogDomain *) ; int cloog_domain_lazy_equal(CloogDomain *, CloogDomain *) ; int cloog_domain_lazy_block(CloogDomain *, CloogDomain *, CloogDomainList *, int) ; int cloog_domain_lazy_isscalar(CloogDomain *, int) ; int cloog_domain_list_lazy_same(CloogDomainList *) ; -void cloog_domain_scalar(CloogDomain *, int, Value *) ; +void cloog_domain_scalar(CloogDomain *, int, cloog_int_t *); CloogDomain * cloog_domain_cut_first(CloogDomain *) ; CloogDomain * cloog_domain_erase_dimension(CloogDomain *, int) ; diff --git a/include/cloog/int.h.in b/include/cloog/int.h.in new file mode 100644 index 0000000..533939c --- /dev/null +++ b/include/cloog/int.h.in @@ -0,0 +1,154 @@ +#ifndef CLOOG_INT_H +#define CLOOG_INT_H + +#undef CLOOG_INT_INT +#undef CLOOG_INT_LONG +#undef CLOOG_INT_LONG_LONG +#undef CLOOG_INT_GMP + +#include +#include +#if defined(CLOOG_INT_GMP) +#include +#include +#endif + +#if defined(__cplusplus) +extern "C" + { +#endif + +#if defined(CLOOG_INT_INT) +typedef int cloog_int_t; +#define CLOOG_INT_FORMAT "%d" +#elif defined(CLOOG_INT_LONG) +typedef long cloog_int_t; +#define CLOOG_INT_FORMAT "%ld" +#elif defined(CLOOG_INT_LONG_LONG) +typedef long long cloog_int_t; +#define CLOOG_INT_FORMAT "%lld" +#elif defined(CLOOG_INT_GMP) +typedef mpz_t cloog_int_t; +#else +#error "No integer type defined" +#endif + +#if defined(CLOOG_INT_GMP) + +#define cloog_int_init(i) do { \ + mpz_init(i); \ + cloog_int_leak_up(); \ + } while (0) +#define cloog_int_clear(i) do { \ + mpz_clear(i); \ + cloog_int_leak_down(); \ + } while (0) + +#define cloog_int_set(r,i) mpz_set(r,i) +#define cloog_int_set_si(r,i) mpz_set_si(r,i) +#define cloog_int_abs(r,i) mpz_abs(r,i) +#define cloog_int_neg(r,i) mpz_neg(r,i) +#define cloog_int_swap(i,j) mpz_swap(i,j) + +#define cloog_int_add(r,i,j) mpz_add(r,i,j) +#define cloog_int_add_ui(r,i,j) mpz_add_ui(r,i,j) +#define cloog_int_sub(r,i,j) mpz_sub(r,i,j) +#define cloog_int_sub_ui(r,i,j) mpz_sub_ui(r,i,j) +#define cloog_int_mul(r,i,j) mpz_mul(r,i,j) +#define cloog_int_addmul(r,i,j) mpz_addmul(r,i,j) +#define cloog_int_divexact(r,i,j) mpz_divexact(r,i,j) +#define cloog_int_tdiv_q(r,i,j) mpz_tdiv_q(r,i,j) +#define cloog_int_fdiv_q(r,i,j) mpz_fdiv_q(r,i,j) +#define cloog_int_fdiv_r(r,i,j) mpz_fdiv_r(r,i,j) +#define cloog_int_gcd(r,i,j) mpz_gcd(r,i,j) + +#define cloog_int_sgn(i) mpz_sgn(i) +#define cloog_int_cmp_si(i,si) mpz_cmp_si(i,si) +#define cloog_int_eq(i,j) (mpz_cmp(i,j) == 0) +#define cloog_int_ne(i,j) (mpz_cmp(i,j) != 0) +#define cloog_int_gt(i,j) (mpz_cmp(i,j) > 0) + +#define cloog_int_is_divisible_by(i,j) mpz_divisible_p(i,j) + +typedef void (*cloog_int_print_gmp_free_t)(void *, size_t); +#define cloog_int_print(out,i) \ + do { \ + char *s; \ + cloog_int_print_gmp_free_t gmp_free; \ + s = mpz_get_str(0, 10, i); \ + fprintf(out, "%s", s); \ + mp_get_memory_functions(NULL, NULL, &gmp_free); \ + (*gmp_free)(s, strlen(s)+1); \ + } while (0) + +#else + +#define cloog_int_init(i) ((i) = 0) +#define cloog_int_clear(i) do { } while (0) + +#define cloog_int_set(r,i) ((r) = (i)) +#define cloog_int_set_si(r,i) ((r) = (i)) +#define cloog_int_abs(r,i) ((r) = (i) > 0 ? (i) : -(i)) +#define cloog_int_neg(r,i) ((r) = -(i)) +#define cloog_int_swap(i,j) do { \ + cloog_int_t _t = i; \ + i = j; \ + j = _t; \ + } while (0) + +#define cloog_int_add(r,i,j) ((r) = (i) + (j)) +#define cloog_int_add_ui(r,i,j) ((r) = (i) + (j)) +#define cloog_int_sub(r,i,j) ((r) = (i) - (j)) +#define cloog_int_sub_ui(r,i,j) ((r) = (i) - (j)) +#define cloog_int_mul(r,i,j) ((r) = (i) * (j)) +#define cloog_int_addmul(r,i,j) ((r) += (i) * (j)) +#define cloog_int_divexact(r,i,j) ((r) = (i) / (j)) +#define cloog_int_tdiv_q(r,i,j) ((r) = (i) / (j)) +#define cloog_int_fdiv_q(r,i,j) do { \ + assert((j) > 0); \ + (r) = (i) >= 0 ? (i) / (j) : \ + -((-(i)+(j)-1)/(j)); \ + } while (0) +#define cloog_int_fdiv_r(r,i,j) do { \ + assert((j) > 0); \ + (r) = (i) >= 0 ? (i) % (j) : \ + (j)-1 - ((-(i)+(j)-1)%(j)); \ + } while (0) +cloog_int_t cloog_gcd(cloog_int_t a, cloog_int_t b); +#define cloog_int_gcd(r,i,j) (r) = cloog_gcd(i,j) + +#define cloog_int_sgn(i) ((i) > 0 ? 1 : (i) < 0 ? -1 : 0) +#define cloog_int_cmp_si(i,si) (i - si) +#define cloog_int_eq(i,j) ((i) == (j)) +#define cloog_int_ne(i,j) ((i) != (j)) +#define cloog_int_gt(i,j) ((i) > (j)) + +#define cloog_int_is_divisible_by(i,j) ((i) % (j) == 0) + +#define cloog_int_print(out,i) fprintf(out, CLOOG_INT_FORMAT, i) + +#endif + +#define cloog_int_is_pos(i) (cloog_int_sgn(i) > 0) +#define cloog_int_is_neg(i) (cloog_int_sgn(i) < 0) +#define cloog_int_is_zero(i) (cloog_int_sgn(i) == 0) +#define cloog_int_is_one(i) (cloog_int_cmp_si(i,1) == 0) +#define cloog_int_is_neg_one(i) (cloog_int_cmp_si(i,-1) == 0) +#define cloog_int_gt_si(i,si) (cloog_int_cmp_si(i,si) > 0) + +struct cloog_vec { + unsigned size; + cloog_int_t *p; +}; + +struct cloog_vec *cloog_vec_alloc(unsigned size); +void cloog_vec_free(struct cloog_vec *vec); +void cloog_seq_neg(cloog_int_t *dst, cloog_int_t *src, unsigned len); +void cloog_seq_combine(cloog_int_t *dst, cloog_int_t m1, cloog_int_t *src1, + cloog_int_t m2, cloog_int_t *src2, unsigned len); + +#if defined(__cplusplus) + } +#endif + +#endif diff --git a/include/cloog/loop.h b/include/cloog/loop.h index a8720b2..b246255 100644 --- a/include/cloog/loop.h +++ b/include/cloog/loop.h @@ -60,7 +60,7 @@ extern "C" */ struct cloogloop { CloogDomain * domain ; /**< The iteration domain. */ - Value stride ; /**< The stride for the corresponding iterator + cloog_int_t stride; /**< The stride for the corresponding iterator * (filled only after loop generation). */ CloogBlock * block ; /**< The included statement block, NULL if none.*/ diff --git a/include/cloog/cloog.h.in b/include/cloog/polylib/cloog.h similarity index 78% copy from include/cloog/cloog.h.in copy to include/cloog/polylib/cloog.h index 7616bab..4bf08b1 100644 --- a/include/cloog/cloog.h.in +++ b/include/cloog/polylib/cloog.h @@ -1,57 +1,8 @@ +#ifndef CLOOG_POLYLIB_H +#define CLOOG_POLYLIB_H - /**-------------------------------------------------------------------** - ** CLooG ** - **-------------------------------------------------------------------** - ** cloog.h ** - **-------------------------------------------------------------------** - ** First version: july 25th 2002 ** - **-------------------------------------------------------------------**/ - - -/****************************************************************************** - * CLooG : the Chunky Loop Generator (experimental) * - ****************************************************************************** - * * - * Copyright (C) 2001-2005 Cedric Bastoul * - * * - * This is free software; you can redistribute it and/or modify it under the * - * terms of the GNU General Public License as published by the Free Software * - * Foundation; either version 2 of the License, or (at your option) any later * - * version. * - * * - * This software 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 General Public License * - * for more details. * - * * - * You should have received a copy of the GNU General Public License along * - * with software; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * * - * CLooG, the Chunky Loop Generator * - * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr * - * * - ******************************************************************************/ - -/****************************************************************************** - * THIS FILE HAS BEEN AUTOMATICALLY GENERATED FROM clooh.h.in BY configure * - ******************************************************************************/ - -#ifndef CLOOG_H -#define CLOOG_H - -# include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#define CLOOG_POLYLIB +#include /****************************************************************************** @@ -59,10 +10,10 @@ ******************************************************************************/ #ifdef GNUMP #define value_init_c(val) { mpz_init((val)) ; \ - cloog_value_leak_up() ; \ + cloog_int_leak_up() ; \ } #define value_clear_c(val) { mpz_clear((val)) ; \ - cloog_value_leak_down() ; \ + cloog_int_leak_down() ; \ } #define value_sprint(Dst,fmt,val) { char * str ; \ str = mpz_get_str(0,10,(val)) ; \ @@ -285,4 +236,4 @@ #endif /* 'Value' set to |longlong|long|float|char *|int */ #endif -#endif /* !CLOOG_H */ +#endif /* define _H */ diff --git a/include/cloog/program.h b/include/cloog/program.h index 17d47f6..0e8648d 100644 --- a/include/cloog/program.h +++ b/include/cloog/program.h @@ -76,8 +76,8 @@ typedef struct cloogprogram CloogProgram ; /****************************************************************************** * Memory leak hunt functions * ******************************************************************************/ -void cloog_value_leak_up(void); -void cloog_value_leak_down(void); +void cloog_int_leak_up(void); +void cloog_int_leak_down(void); /****************************************************************************** diff --git a/source/block.c b/source/block.c index fb4fb26..a816b69 100644 --- a/source/block.c +++ b/source/block.c @@ -130,8 +130,10 @@ void cloog_block_print_structure(FILE * file, CloogBlock * block, int level) fprintf(file,"No scalar dimensions\n") ; else { fprintf(file,"Scalar dimensions (%d):",block->nb_scaldims) ; - for (i=0; inb_scaldims; i++) - value_print(file," "VALUE_FMT,block->scaldims[i]) ; + for (i = 0; i < block->nb_scaldims; i++) { + fprintf(file, " "); + cloog_int_print(file, block->scaldims[i]); + } fprintf(file,"\n") ; } @@ -206,7 +208,7 @@ void cloog_block_free(CloogBlock * block) { cloog_block_leak_down() ; if (block->scaldims != NULL) { for (i=0;inb_scaldims;i++) - value_clear_c(block->scaldims[i]) ; + cloog_int_clear(block->scaldims[i]); free(block->scaldims) ; } @@ -286,7 +288,7 @@ CloogBlock * cloog_block_malloc() * - November 21th 2005: use of cloog_block_malloc. */ CloogBlock *cloog_block_alloc(CloogStatement *statement, int nb_scaldims, - Value *scaldims, int depth) + cloog_int_t *scaldims, int depth) { CloogBlock * block ; /* Block allocation. */ diff --git a/source/clast.c b/source/clast.c index ac2dc0c..021cf48 100644 --- a/source/clast.c +++ b/source/clast.c @@ -13,8 +13,8 @@ * This structure is mainly there to reduce the number of function parameters, * since most pprint.c functions need most of its field. */ -struct clooginfos -{ Value * stride ; /**< The stride for each iterator. */ +struct clooginfos { + cloog_int_t *stride; /**< The stride for each iterator. */ int nb_scattdims ; /**< Scattering dimension number. */ int * scaldims ; /**< Boolean array saying whether a given * scattering dimension is scalar or not. @@ -56,25 +56,25 @@ static void insert_loop(CloogLoop * loop, int level, int scalar, struct clast_stmt ***next, CloogInfos *infos); -struct clast_term *new_clast_term(Value c, const char *v) +struct clast_term *new_clast_term(cloog_int_t c, const char *v) { struct clast_term *t = malloc(sizeof(struct clast_term)); t->expr.type = expr_term; - value_init(t->val); - value_assign(t->val, c); + cloog_int_init(t->val); + cloog_int_set(t->val, c); t->var = v; return t; } struct clast_binary *new_clast_binary(enum clast_bin_type t, - struct clast_expr *lhs, Value rhs) + struct clast_expr *lhs, cloog_int_t rhs) { struct clast_binary *b = malloc(sizeof(struct clast_binary)); b->expr.type = expr_bin; b->type = t; b->LHS = lhs; - value_init(b->RHS); - value_assign(b->RHS, rhs); + cloog_int_init(b->RHS); + cloog_int_set(b->RHS, rhs); return b; } @@ -189,13 +189,13 @@ static void free_clast_for(struct clast_stmt *s) assert(CLAST_STMT_IS_A(s, stmt_for)); free_clast_expr(f->LB); free_clast_expr(f->UB); - value_clear(f->stride); + cloog_int_clear(f->stride); cloog_clast_free(f->body); free(f); } struct clast_for *new_clast_for(const char *it, struct clast_expr *LB, - struct clast_expr *UB, Value stride) + struct clast_expr *UB, cloog_int_t stride) { struct clast_for *f = malloc(sizeof(struct clast_for)); f->stmt.op = &stmt_for; @@ -204,8 +204,8 @@ struct clast_for *new_clast_for(const char *it, struct clast_expr *LB, f->LB = LB; f->UB = UB; f->body = NULL; - value_init(f->stride); - value_assign(f->stride, stride); + cloog_int_init(f->stride); + cloog_int_set(f->stride, stride); return f; } @@ -244,13 +244,13 @@ struct clast_guard *new_clast_guard(int n) void free_clast_term(struct clast_term *t) { - value_clear(t->val); + cloog_int_clear(t->val); free(t); } void free_clast_binary(struct clast_binary *b) { - value_clear(b->RHS); + cloog_int_clear(b->RHS); free_clast_expr(b->LHS); free(b); } @@ -303,14 +303,14 @@ static int clast_term_equal(struct clast_term *t1, struct clast_term *t2) { if (t1->var != t2->var) return 0; - return value_eq(t1->val, t2->val); + return cloog_int_eq(t1->val, t2->val); } static int clast_binary_equal(struct clast_binary *b1, struct clast_binary *b2) { if (b1->type != b2->type) return 0; - if (value_ne(b1->RHS, b2->RHS)) + if (cloog_int_ne(b1->RHS, b2->RHS)) return 0; return clast_expr_equal(b1->LHS, b2->LHS); } @@ -460,27 +460,27 @@ static struct clast_stmt * clast_equal(CloogInfos *infos) static struct clast_stmt * clast_equal_cpp(int level, CloogInfos *infos) { int i ; - Value one; + cloog_int_t one; struct clast_expr *e; struct clast_stmt *a = NULL; struct clast_stmt **next = &a; CloogEqualities *equal = infos->equal; CloogConstraints *constraints = cloog_equal_constraints(equal); - value_init_c(one); + cloog_int_init(one); for (i=infos->names->nb_scattering;inames); } else { - value_set_si(one, 1); + cloog_int_set_si(one, 1); e = &new_clast_term(one, infos->names->iterators[i-infos->names->nb_scattering])->expr; } *next = &new_clast_assignment(NULL, e)->stmt; next = &(*next)->next; } - value_clear_c(one); + cloog_int_clear(one); return a; } @@ -509,25 +509,25 @@ struct clast_expr *clast_bound_from_constraint(CloogConstraints *constraints, { int i, nb_iter, sign, nb_elts=0, len; char * name; - Value * line, numerator, denominator, temp, division ; + cloog_int_t *line, numerator, denominator, temp, division; struct clast_expr *e = NULL; - Vector *line_vector; + struct cloog_vec *line_vector; len = cloog_constraints_total_dimension(constraints) + 2; - line_vector = Vector_Alloc(len); + line_vector = cloog_vec_alloc(len); line = line_vector->p; cloog_constraint_copy(constraints, line_num, line+1); - value_init_c(temp) ; - value_init_c(numerator) ; - value_init_c(denominator) ; + cloog_int_init(temp); + cloog_int_init(numerator); + cloog_int_init(denominator); - if (value_notzero_p(line[level])) { + if (!cloog_int_is_zero(line[level])) { struct clast_reduction *r; /* Maybe we need to invert signs in such a way that the element sign is>0.*/ - sign = value_pos_p(line[level]) ? -1 : 1 ; + sign = -cloog_int_sgn(line[level]); for (i = 1, nb_elts = 0; i <= len - 1; ++i) - if (i != level && value_notzero_p(line[i])) + if (i != level && !cloog_int_is_zero(line[i])) nb_elts++; r = new_clast_reduction(clast_red_sum, nb_elts); nb_elts = 0; @@ -535,50 +535,50 @@ struct clast_expr *clast_bound_from_constraint(CloogConstraints *constraints, /* First, we have to print the iterators. */ nb_iter = len - 2 - names->nb_parameters; for (i=1;i<=nb_iter;i++) - if ((i != level) && value_notzero_p(line[i])) { + if ((i != level) && !cloog_int_is_zero(line[i])) { if (i <= names->nb_scattering) name = names->scattering[i-1]; else name = names->iterators[i-names->nb_scattering-1]; if (sign == -1) - value_oppose(temp,line[i]) ; + cloog_int_neg(temp,line[i]); else - value_assign(temp,line[i]) ; + cloog_int_set(temp,line[i]); r->elts[nb_elts++] = &new_clast_term(temp, name)->expr; } /* Next, the parameters. */ for (i = nb_iter + 1; i <= len - 2; i++) - if ((i != level) && value_notzero_p(line[i])) { + if ((i != level) && !cloog_int_is_zero(line[i])) { name = names->parameters[i-nb_iter-1]; if (sign == -1) - value_oppose(temp,line[i]) ; + cloog_int_neg(temp,line[i]); else - value_assign(temp,line[i]) ; + cloog_int_set(temp,line[i]); r->elts[nb_elts++] = &new_clast_term(temp, name)->expr; } - if (sign == -1) - { value_oppose(numerator, line[len - 1]); - value_assign(denominator,line[level]) ; + if (sign == -1) { + cloog_int_neg(numerator, line[len - 1]); + cloog_int_set(denominator, line[level]); } - else - { value_assign(numerator, line[len - 1]); - value_oppose(denominator,line[level]) ; + else { + cloog_int_set(numerator, line[len - 1]); + cloog_int_neg(denominator, line[level]); } /* Finally, the constant, and the final printing. */ if (nb_elts) { - if (value_notzero_p(numerator)) + if (!cloog_int_is_zero(numerator)) r->elts[nb_elts++] = &new_clast_term(numerator, NULL)->expr; - if (value_notone_p(line[level]) && value_notmone_p(line[level])) + if (!cloog_int_is_one(line[level]) && !cloog_int_is_neg_one(line[level])) { if (!cloog_constraint_is_equality(constraints, line_num)) - { if (value_pos_p(line[level])) + { if (cloog_int_is_pos(line[level])) e = &new_clast_binary(clast_bin_cdiv, &r->expr, denominator)->expr; else e = &new_clast_binary(clast_bin_fdiv, &r->expr, denominator)->expr; @@ -589,40 +589,39 @@ struct clast_expr *clast_bound_from_constraint(CloogConstraints *constraints, e = &r->expr; } else { free_clast_reduction(r); - if (value_zero_p(numerator)) + if (cloog_int_is_zero(numerator)) e = &new_clast_term(numerator, NULL)->expr; else - { if (value_notone_p(denominator)) - { if (!cloog_constraint_is_equality(constraints, line_num)) /* useful? */ - { value_modulus(temp,numerator,denominator) ; - if (value_zero_p(temp)) - { value_division(temp,numerator,denominator) ; + { if (!cloog_int_is_one(denominator)) + { if (!cloog_constraint_is_equality(constraints, line_num)) { /* useful? */ + if (cloog_int_is_divisible_by(numerator, denominator)) { + cloog_int_divexact(temp, numerator, denominator); e = &new_clast_term(temp, NULL)->expr; } - else - { value_init_c(division) ; - value_division(division,numerator,denominator) ; - if (value_neg_p(numerator)) { - if (value_pos_p(line[level])) { + else { + cloog_int_init(division); + cloog_int_tdiv_q(division, numerator, denominator); + if (cloog_int_is_neg(numerator)) { + if (cloog_int_is_pos(line[level])) { /* nb<0 need max */ e = &new_clast_term(division, NULL)->expr; } else { /* nb<0 need min */ - value_decrement(temp,division) ; + cloog_int_sub_ui(temp, division, 1); e = &new_clast_term(temp, NULL)->expr; } } else - { if (value_pos_p(line[level])) + { if (cloog_int_is_pos(line[level])) { /* nb>0 need max */ - value_increment(temp,division) ; + cloog_int_add_ui(temp, division, 1); e = &new_clast_term(temp, NULL)->expr; } else /* nb>0 need min */ e = &new_clast_term(division, NULL)->expr; } - value_clear_c(division) ; + cloog_int_clear(division); } } else @@ -636,11 +635,11 @@ struct clast_expr *clast_bound_from_constraint(CloogConstraints *constraints, } } - Vector_Free(line_vector); + cloog_vec_free(line_vector); - value_clear_c(temp) ; - value_clear_c(numerator) ; - value_clear_c(denominator) ; + cloog_int_clear(temp); + cloog_int_clear(numerator); + cloog_int_clear(denominator); return e; } @@ -731,13 +730,13 @@ static void insert_guard(CloogConstraints *constraints, int level, char * name; CloogConstraints *copy; struct clast_guard *g; - Value one; + cloog_int_t one; if (constraints == NULL) return; - value_init(one); - value_set_si(one, 1); + cloog_int_init(one); + cloog_int_set_si(one, 1); total_dim = cloog_constraints_total_dimension(constraints); g = new_clast_guard(2 * total_dim); @@ -808,53 +807,54 @@ static void insert_guard(CloogConstraints *constraints, int level, } else free_clast_stmt(&g->stmt); - value_clear(one); + cloog_int_clear(one); return; } /* Computes x, y and g such that g = gcd(a,b) and a*x+b*y = g */ -static void Euclid(Value a, Value b, Value *x, Value *y, Value *g) +static void Euclid(cloog_int_t a, cloog_int_t b, + cloog_int_t *x, cloog_int_t *y, cloog_int_t *g) { - Value c, d, e, f, tmp; - - value_init(c); - value_init(d); - value_init(e); - value_init(f); - value_init(tmp); - value_absolute(c, a); - value_absolute(d, b); - value_set_si(e, 1); - value_set_si(f, 0); - while(value_pos_p(d)) { - value_division(tmp, c, d); - value_multiply(tmp, tmp, f); - value_subtract(e, e, tmp); - value_division(tmp, c, d); - value_multiply(tmp, tmp, d); - value_subtract(c, c, tmp); - value_swap(c, d); - value_swap(e, f); + cloog_int_t c, d, e, f, tmp; + + cloog_int_init(c); + cloog_int_init(d); + cloog_int_init(e); + cloog_int_init(f); + cloog_int_init(tmp); + cloog_int_abs(c, a); + cloog_int_abs(d, b); + cloog_int_set_si(e, 1); + cloog_int_set_si(f, 0); + while (cloog_int_is_pos(d)) { + cloog_int_tdiv_q(tmp, c, d); + cloog_int_mul(tmp, tmp, f); + cloog_int_sub(e, e, tmp); + cloog_int_tdiv_q(tmp, c, d); + cloog_int_mul(tmp, tmp, d); + cloog_int_sub(c, c, tmp); + cloog_int_swap(c, d); + cloog_int_swap(e, f); } - value_assign(*g, c); - if (value_zero_p(a)) - value_set_si(*x, 0); - else if (value_pos_p(a)) - value_assign(*x, e); - else value_oppose(*x, e); - if (value_zero_p(b)) - value_set_si(*y, 0); + cloog_int_set(*g, c); + if (cloog_int_is_zero(a)) + cloog_int_set_si(*x, 0); + else if (cloog_int_is_pos(a)) + cloog_int_set(*x, e); + else cloog_int_neg(*x, e); + if (cloog_int_is_zero(b)) + cloog_int_set_si(*y, 0); else { - value_multiply(tmp, a, *x); - value_subtract(tmp, c, tmp); - value_division(*y, tmp, b); + cloog_int_mul(tmp, a, *x); + cloog_int_sub(tmp, c, tmp); + cloog_int_divexact(*y, tmp, b); } - value_clear(c); - value_clear(d); - value_clear(e); - value_clear(f); - value_clear(tmp); + cloog_int_clear(c); + cloog_int_clear(d); + cloog_int_clear(e); + cloog_int_clear(f); + cloog_int_clear(tmp); } @@ -879,14 +879,14 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, struct clast_stmt ***next, CloogInfos *infos) { int i, j, k, nb_elts = 0, len, len2, nb_iter, in_stride = 0, nb_par; - Vector *line_vector, *line_vector2; - Value *line, *line2, val, val2, x, y, g; + struct cloog_vec *line_vector, *line_vector2; + cloog_int_t *line, *line2, val, val2, x, y, g; CloogConstraints *equal_constraints = cloog_equal_constraints(infos->equal); - value_init_c(val); + cloog_int_init(val); cloog_constraint_coefficient_get(constraints, upper, level-1, &val); - if (value_one_p(val) || value_mone_p(val)) { - value_clear_c(val); + if (cloog_int_is_one(val) || cloog_int_is_neg_one(val)) { + cloog_int_clear(val); return; } @@ -895,41 +895,41 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, nb_par = infos->names->nb_parameters; nb_iter = len - 2 - nb_par; - value_init_c(val2); + cloog_int_init(val2); /* Check if would be emitting the redundant constraint mod(e,m) <= m-1 */ if (lower != -1) { cloog_constraint_constant_get(constraints, upper, &val); cloog_constraint_constant_get(constraints, lower, &val2); - value_addto(val, val, val2); - value_add_int(val, val, 1); + cloog_int_add(val, val, val2); + cloog_int_add_ui(val, val, 1); cloog_constraint_coefficient_get(constraints, lower, level-1, &val2); - if (value_eq(val, val2)) { - value_clear_c(val); - value_clear_c(val2); + if (cloog_int_eq(val, val2)) { + cloog_int_clear(val); + cloog_int_clear(val2); return; } } - value_init_c(x); - value_init_c(y); - value_init_c(g); + cloog_int_init(x); + cloog_int_init(y); + cloog_int_init(g); - line_vector = Vector_Alloc(len); - line_vector2 = Vector_Alloc(len2); + line_vector = cloog_vec_alloc(len); + line_vector2 = cloog_vec_alloc(len2); line = line_vector->p; line2 = line_vector2->p; cloog_constraint_copy(constraints, upper, line+1); - if (value_pos_p(line[level])) - Vector_Oppose(line+1, line+1, len-1); - value_oppose(line[level], line[level]); - assert(value_pos_p(line[level])); + if (cloog_int_is_pos(line[level])) + cloog_seq_neg(line+1, line+1, len-1); + cloog_int_neg(line[level], line[level]); + assert(cloog_int_is_pos(line[level])); nb_elts = 0; for (i = nb_iter; i >= 1; --i) { if (i == level) continue; - value_pmodulus(line[i],line[i],line[level]); - if (value_zero_p(line[i])) + cloog_int_fdiv_r(line[i], line[i], line[level]); + if (cloog_int_is_zero(line[i])) continue; /* Look for an earlier variable that is also a multiple of line[level] @@ -942,53 +942,48 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, if (cloog_equal_type(infos->equal, j+1) != EQTYPE_EXAFFINE) continue; cloog_constraint_coefficient_get(equal_constraints, j, j, &val); - value_modulus(val, val, line[level]); - if (value_notzero_p(val)) + if (!cloog_int_is_divisible_by(val, line[level])) continue; cloog_constraint_coefficient_get(equal_constraints, j, i-1, &val); - value_modulus(val, val, line[level]); - if (value_zero_p(val)) + if (cloog_int_is_divisible_by(val, line[level])) continue; for (k = j; k > i; --k) { cloog_constraint_coefficient_get(equal_constraints, j, k-1, &val); - if (value_zero_p(val)) + if (cloog_int_is_zero(val)) continue; - value_modulus(val, val, line[level]); - if (value_notzero_p(val)) + if (!cloog_int_is_divisible_by(val, line[level])) break; } if (k > i) continue; cloog_constraint_coefficient_get(equal_constraints, j, i-1, &val); Euclid(val, line[level], &x, &y, &g); - value_modulus(val, line[i], g); - if (value_notzero_p(val)) + if (!cloog_int_is_divisible_by(val, line[i])) continue; - value_division(val, line[i], g); - value_oppose(val, val); - value_multiply(val, val, x); - value_set_si(y, 1); + cloog_int_divexact(val, line[i], g); + cloog_int_neg(val, val); + cloog_int_mul(val, val, x); + cloog_int_set_si(y, 1); /* Add (infos->equal->p[j][i])^{-1} * line[i] times the equality */ cloog_constraint_copy(equal_constraints, j, line2+1); - Vector_Combine(line+1, line2+1, line+1, y, val, i); - Vector_Combine(line+len-nb_par-1, line2+len2-nb_par-1, - line+len-nb_par-1, y, val, nb_par+1); + cloog_seq_combine(line+1, y, line+1, val, line2+1, i); + cloog_seq_combine(line+len-nb_par-1, y, line+len-nb_par-1, + val, line2+len2-nb_par-1, nb_par+1); break; } if (j >= 0) { - value_pmodulus(line[i],line[i],line[level]); - assert(value_zero_p(line[i])); + cloog_int_fdiv_r(line[i], line[i], line[level]); + assert(cloog_int_is_zero(line[i])); continue; } - value_modulus(val,infos->stride[i-1],line[level]); /* We need to know if an element of the equality has not to be printed * because of a stride that guarantees that this element can be divided by * the current coefficient. Because when there is a constant element, it * is included in the stride calculation (more exactly in the strided * iterator new lower bound: the 'offset') and we have not to print it. */ - if (lower == -1 && value_zero_p(val)) { + if (lower == -1 && cloog_int_is_divisible_by(infos->stride[i-1], line[level])) { in_stride = 1; continue; } @@ -996,14 +991,14 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, nb_elts++; } for (i = nb_iter+1; i <= len-1; ++i) { - value_pmodulus(line[i],line[i],line[level]); - if (value_zero_p(line[i])) + cloog_int_fdiv_r(line[i], line[i], line[level]); + if (cloog_int_is_zero(line[i])) continue; if (i <= len-2) nb_elts++; } - if (nb_elts || (value_notzero_p(line[len-1]) && (!in_stride))) { + if (nb_elts || (!cloog_int_is_zero(line[len-1]) && (!in_stride))) { struct clast_reduction *r; struct clast_expr *e; struct clast_guard *g; @@ -1014,10 +1009,9 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, /* First, the modulo guard : the iterators... */ for (i=1;i<=nb_iter;i++) { - if (i == level || value_zero_p(line[i])) + if (i == level || cloog_int_is_zero(line[i])) continue; - value_modulus(val,infos->stride[i-1],line[level]); - if (value_zero_p(val)) + if (cloog_int_is_divisible_by(infos->stride[i-1], line[level])) continue; if (i <= infos->names->nb_scattering) @@ -1030,7 +1024,7 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, /* ...the parameters... */ for (i=nb_iter+1;i<=len-2;i++) { - if (value_zero_p(line[i])) + if (cloog_int_is_zero(line[i])) continue; name = infos->names->parameters[i-nb_iter-1] ; @@ -1038,7 +1032,7 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, } /* ...the constant. */ - if (value_notzero_p(line[len-1])) + if (!cloog_int_is_zero(line[len-1])) r->elts[nb_elts++] = &new_clast_term(line[len-1], NULL)->expr; /* our initial computation may have been an overestimate */ @@ -1048,14 +1042,14 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, g = new_clast_guard(1); if (lower == -1) { g->eq[0].LHS = e; - value_set_si(val, 0); + cloog_int_set_si(val, 0); g->eq[0].RHS = &new_clast_term(val, NULL)->expr; g->eq[0].sign = 0; } else { g->eq[0].LHS = e; cloog_constraint_constant_get(constraints, upper, &val); cloog_constraint_constant_get(constraints, lower, &val2); - value_addto(val, val, val2); + cloog_int_add(val, val, val2); g->eq[0].RHS = &new_clast_term(val, NULL)->expr; g->eq[0].sign = -1; } @@ -1064,14 +1058,14 @@ static void insert_modulo_guard(CloogConstraints *constraints, int upper, *next = &g->then; } - Vector_Free(line_vector); - Vector_Free(line_vector2); + cloog_vec_free(line_vector); + cloog_vec_free(line_vector2); - value_clear_c(val); - value_clear_c(val2); - value_clear_c(x); - value_clear_c(y); - value_clear_c(g); + cloog_int_clear(val); + cloog_int_clear(val2); + cloog_int_clear(x); + cloog_int_clear(y); + cloog_int_clear(g); } @@ -1332,7 +1326,7 @@ static void insert_loop(CloogLoop * loop, int level, int scalar, constraints = cloog_constraints_simplify(temp,infos->equal,level, infos->names->nb_parameters); cloog_constraints_free(temp); - value_assign(infos->stride[level-1],loop->stride); + cloog_int_set(infos->stride[level-1], loop->stride); /* First of all we have to print the guard. */ insert_guard(constraints,level, next, infos); @@ -1391,9 +1385,9 @@ struct clast_stmt *cloog_clast_create(CloogProgram *program, * be included inside an external loop without iteration domain. */ nb_levels = program->names->nb_scattering+program->names->nb_iterators+1; - infos->stride = ALLOCN(Value, nb_levels); + infos->stride = ALLOCN(cloog_int_t, nb_levels); for (i = 0; i < nb_levels; ++i) - value_init_c(infos->stride[i]); + cloog_int_init(infos->stride[i]); infos->equal = cloog_equal_alloc(nb_levels, nb_levels, program->names->nb_parameters); @@ -1403,7 +1397,7 @@ struct clast_stmt *cloog_clast_create(CloogProgram *program, cloog_equal_free(infos->equal); for (i = 0; i < nb_levels; ++i) - value_clear_c(infos->stride[i]); + cloog_int_clear(infos->stride[i]); free(infos->stride); free(infos); diff --git a/source/cloog.c b/source/cloog.c index b98b4ee..15fe4f3 100644 --- a/source/cloog.c +++ b/source/cloog.c @@ -54,9 +54,9 @@ extern int cloog_matrix_max ; extern int cloog_block_allocated ; extern int cloog_block_freed ; extern int cloog_block_max ; -extern int cloog_value_allocated ; -extern int cloog_value_freed ; -extern int cloog_value_max ; +extern int cloog_int_allocated; +extern int cloog_int_freed; +extern int cloog_int_max; int main(int argv, char * argc[]) @@ -90,8 +90,8 @@ int main(int argv, char * argc[]) cloog_statement_allocated,cloog_statement_freed,cloog_statement_max); fprintf(output,"/* Blocks : allocated=%5d, freed=%5d, max=%5d. */\n", cloog_block_allocated,cloog_block_freed,cloog_block_max) ; - fprintf(output,"/* Value (GMP): allocated=%5d, freed=%5d, max=%5d. */\n", - cloog_value_allocated,cloog_value_freed,cloog_value_max) ; + fprintf(output,"/* Int (GMP) : allocated=%5d, freed=%5d, max=%5d. */\n", + cloog_int_allocated, cloog_int_freed, cloog_int_max); } /* Inform the user in case of a problem with the allocation statistics. */ @@ -100,7 +100,7 @@ int main(int argv, char * argc[]) (cloog_loop_allocated != cloog_loop_freed) || (cloog_statement_allocated != cloog_statement_freed) || (cloog_block_allocated != cloog_block_freed) || - (cloog_value_allocated != cloog_value_freed)) + (cloog_int_allocated != cloog_int_freed)) { fprintf(stderr, "[CLooG]INFO: an internal problem has been detected (it should have" " no\n consequence on the correctness of the output)." diff --git a/source/int.c b/source/int.c new file mode 100644 index 0000000..197447e --- /dev/null +++ b/source/int.c @@ -0,0 +1,81 @@ +#include +#include "../include/cloog/cloog.h" + +#define ALLOC(type) (type*)malloc(sizeof(type)) +#define ALLOCN(type,n) (type*)malloc((n)*sizeof(type)) + +#if defined(CLOOG_INT_INT) || \ + defined(CLOOG_INT_LONG) || \ + defined(CLOOG_INT_LONG_LONG) + +cloog_int_t cloog_gcd(cloog_int_t a, cloog_int_t b) +{ + while (a) { + cloog_int_t t = b % a; + b = a; + a = t; + } + if (b < 0) + b = -b; + return b; +} + +#endif + +struct cloog_vec *cloog_vec_alloc(unsigned size) +{ + int i; + struct cloog_vec *vec; + + vec = ALLOC(struct cloog_vec); + if (!vec) + return NULL; + + vec->p = ALLOCN(cloog_int_t, size); + if (!vec->p) + goto error; + vec->size = size; + + for (i = 0; i < size; ++i) + cloog_int_init(vec->p[i]); + + return vec; +error: + free(vec); + return NULL; +} + +void cloog_vec_free(struct cloog_vec *vec) +{ + int i; + + if (!vec) + return; + + for (i = 0; i < vec->size; ++i) + cloog_int_clear(vec->p[i]); + free(vec->p); + free(vec); +} + +void cloog_seq_neg(cloog_int_t *dst, cloog_int_t *src, unsigned len) +{ + int i; + for (i = 0; i < len; ++i) + cloog_int_neg(dst[i], src[i]); +} + +void cloog_seq_combine(cloog_int_t *dst, cloog_int_t m1, cloog_int_t *src1, + cloog_int_t m2, cloog_int_t *src2, unsigned len) +{ + int i; + cloog_int_t tmp; + + cloog_int_init(tmp); + for (i = 0; i < len; ++i) { + cloog_int_mul(tmp, m1, src1[i]); + cloog_int_addmul(tmp, m2, src2[i]); + cloog_int_set(dst[i], tmp); + } + cloog_int_clear(tmp); +} diff --git a/source/loop.c b/source/loop.c index 74ab073..f5ada20 100644 --- a/source/loop.c +++ b/source/loop.c @@ -128,7 +128,7 @@ void cloog_loop_print_structure(FILE * file, CloogLoop * loop, int level) for(j=0; j<=level; j++) fprintf(file,"|\t") ; fprintf(file, "Stride: ") ; - value_print(file,VALUE_FMT,loop->stride) ; + cloog_int_print(file, loop->stride); fprintf(file, "\n") ; /* A blank line. */ @@ -207,7 +207,7 @@ void cloog_loop_free(CloogLoop * loop) if (loop->inner != NULL) cloog_loop_free(loop->inner) ; - value_clear_c(loop->stride) ; + cloog_int_clear(loop->stride); free(loop) ; loop = next ; } @@ -241,7 +241,7 @@ int domain, block, inner, next ; if ((inner) && (loop->inner != NULL)) cloog_loop_free_parts(loop->inner,domain,block,inner,1) ; - value_clear_c(loop->stride) ; + cloog_int_clear(loop->stride); free(loop) ; if (next) loop = follow ; @@ -291,8 +291,8 @@ CloogLoop * cloog_loop_read(FILE * foo, int number, int nb_parameters) else nb_iterators = 0 ; /* stride is initialized to 1. */ - value_init_c(loop->stride) ; - value_set_si(loop->stride,1) ; + cloog_int_init(loop->stride); + cloog_int_set_si(loop->stride, 1); /* included statement block. */ statement = cloog_statement_alloc(number+1); loop->block = cloog_block_alloc(statement, 0, NULL, nb_iterators); @@ -341,8 +341,8 @@ CloogLoop * cloog_loop_malloc() loop->usr = NULL; loop->inner = NULL ; loop->next = NULL ; - value_init_c(loop->stride) ; - value_set_si(loop->stride,1) ; + cloog_int_init(loop->stride); + cloog_int_set_si(loop->stride, 1); return loop ; } @@ -359,7 +359,7 @@ CloogLoop * cloog_loop_malloc() */ CloogLoop * cloog_loop_alloc(domain, stride, block, inner, next) CloogDomain * domain ; -Value stride ; +cloog_int_t stride; CloogBlock * block ; CloogLoop * inner, * next ; { CloogLoop * loop ; @@ -370,7 +370,7 @@ CloogLoop * inner, * next ; loop->block = block ; loop->inner = inner ; loop->next = next ; - value_assign(loop->stride,stride) ; + cloog_int_set(loop->stride, stride); return(loop) ; } @@ -466,13 +466,14 @@ CloogLoop * cloog_loop_copy(CloogLoop * source) */ void cloog_loop_add_disjoint(start, now, loop) CloogLoop ** start, ** now, * loop ; -{ Value one ; +{ + cloog_int_t one; CloogLoop * sep, * inner ; CloogDomain * domain, * convex, * seen, * seen_before, * temp, * rest ; CloogBlock * block ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); if (cloog_domain_isconvex(loop->domain)) cloog_loop_add(start,now,loop) ; @@ -526,7 +527,7 @@ CloogLoop ** start, ** now, * loop ; } cloog_loop_free_parts(loop,0,0,0,0) ; } - value_clear_c(one) ; + cloog_int_clear(one); } @@ -573,7 +574,7 @@ CloogLoop * loop ; CloogDomain * context ; int nb_par ; { int new_dimension ; - Value one ; + cloog_int_t one; CloogDomain * domain, * extended_context, * new_domain ; CloogLoop * new_loop ; @@ -591,11 +592,11 @@ int nb_par ; { cloog_domain_free(new_domain) ; return(NULL) ; } - else - { value_init_c(one) ; - value_set_si(one,1) ; + else { + cloog_int_init(one); + cloog_int_set_si(one, 1); new_loop = cloog_loop_alloc(new_domain,one,loop->block,loop->inner,NULL) ; - value_clear_c(one) ; + cloog_int_clear(one); return(new_loop) ; } } @@ -613,12 +614,13 @@ int nb_par ; * - June 22nd 2005: Adaptation for GMP. */ CloogLoop * cloog_loop_project(CloogLoop * loop, int level, int nb_par) -{ Value one ; +{ + cloog_int_t one; CloogDomain * new_domain ; CloogLoop * new_loop, * copy ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); copy = cloog_loop_alloc(loop->domain,loop->stride,loop->block, loop->inner,NULL) ; @@ -629,7 +631,7 @@ CloogLoop * cloog_loop_project(CloogLoop * loop, int level, int nb_par) new_domain = cloog_domain_project(loop->domain,level,nb_par) ; new_loop = cloog_loop_alloc(new_domain,one,NULL,copy,NULL) ; - value_clear_c(one) ; + cloog_int_clear(one); return(new_loop) ; } @@ -676,7 +678,7 @@ CloogLoop * cloog_loop_concat(CloogLoop * a, CloogLoop * b) */ CloogLoop * cloog_loop_separate(CloogLoop * loop) { int first, lazy_equal=0, lazy_disjoint=0 ; - Value one ; + cloog_int_t one; CloogLoop * new_loop, * new_inner, * res, * now, * temp, * Q, * inner, * old /*, * previous, * next*/ ; CloogDomain * UQ, * old_UQ, * domain ; @@ -687,8 +689,8 @@ CloogLoop * cloog_loop_separate(CloogLoop * loop) if (loop->next == NULL) return cloog_loop_disjoint(loop) ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); UQ = cloog_domain_copy(loop->domain) ; domain = cloog_domain_copy(loop->domain) ; @@ -784,7 +786,7 @@ CloogLoop * cloog_loop_separate(CloogLoop * loop) res = temp ; } cloog_loop_free_parts(old,1,0,0,1) ; - value_clear_c(one) ; + cloog_int_clear(one); return(res) ; } @@ -833,15 +835,16 @@ static CloogLoop *cloog_loop_merge_inner_list(CloogLoop *a, CloogLoop *b, * - June 22nd 2005: Adaptation for GMP. */ CloogLoop * cloog_loop_merge(CloogLoop * loop, int nb_par, CloogOptions * options) -{ Value one ; +{ + cloog_int_t one; CloogLoop * res, * merge, * now, * Q, * P, * new_inner, * next, * old ; CloogDomain * new_domain, * temp ; if ((loop == NULL) || (loop->next == NULL)) return loop ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); /* First loop is added to the target list. */ res = cloog_loop_alloc(loop->domain,one,loop->block,loop->inner,NULL) ; @@ -893,7 +896,7 @@ CloogLoop * cloog_loop_merge(CloogLoop * loop, int nb_par, CloogOptions * option res = merge ; } cloog_loop_free_parts(old,0,0,0,1) ; - value_clear_c(one) ; + cloog_int_clear(one); return (res); } @@ -971,12 +974,12 @@ CloogLoop * loop ; CloogDomain * context ; int level, nb_par ; { int l ; - Value one ; + cloog_int_t one; CloogLoop * p, * temp, * res, * now, * next ; CloogDomain * new_domain ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); res = NULL ; /* Each domain is changed by its intersection with the context. */ @@ -1009,7 +1012,7 @@ int level, nb_par ; loop = next ; } - value_clear_c(one) ; + cloog_int_clear(one); return(res) ; } @@ -1037,40 +1040,40 @@ int level, nb_par ; */ void cloog_loop_stride(CloogLoop * loop, int level, int nb_par) { int first_search ; - Value stride, ref_offset, offset, potential, lower ; + cloog_int_t stride, ref_offset, offset, potential, lower; CloogLoop * inner ; - value_init_c(stride) ; - value_init_c(ref_offset) ; - value_init_c(offset) ; - value_init_c(potential) ; - value_init_c(lower) ; + cloog_int_init(stride); + cloog_int_init(ref_offset); + cloog_int_init(offset); + cloog_int_init(potential); + cloog_int_init(lower); - value_set_si(ref_offset,0) ; - value_set_si(offset,0) ; - value_set_si(lower,0) ; + cloog_int_set_si(ref_offset, 0); + cloog_int_set_si(offset, 0); + cloog_int_set_si(lower, 0); /* Default stride. */ - value_set_si(stride,1) ; + cloog_int_set_si(stride, 1); first_search = 1 ; inner = loop->inner ; if (cloog_domain_integral_lowerbound(loop->domain,level,&lower)) while (inner != NULL) { /* If the minimun stride has not been found yet, find the stride. */ - if ((first_search) || (value_notone_p(stride))) + if ((first_search) || (!cloog_int_is_one(stride))) { cloog_domain_stride(inner->domain,level,nb_par,&potential,&offset) ; - if (value_notone_p(potential) && (!first_search)) + if (!cloog_int_is_one(potential) && (!first_search)) { /* Offsets must be the same for common stride. */ - Gcd(potential,stride,&stride) ; - value_modulus(offset, offset, stride); - value_modulus(ref_offset, ref_offset, stride); - if (value_ne(offset,ref_offset)) - value_set_si(stride, 1); + cloog_int_gcd(stride, potential, stride); + cloog_int_fdiv_r(offset, offset, stride); + cloog_int_fdiv_r(ref_offset, ref_offset, stride); + if (cloog_int_ne(offset,ref_offset)) + cloog_int_set_si(stride, 1); } - else - { value_assign(stride,potential) ; - value_assign(ref_offset,offset) ; + else { + cloog_int_set(stride, potential); + cloog_int_set(ref_offset, offset); } first_search = 0 ; @@ -1080,9 +1083,9 @@ void cloog_loop_stride(CloogLoop * loop, int level, int nb_par) } /* Update the values if necessary. */ - if (value_notone_p(stride)) + if (!cloog_int_is_one(stride)) { /* Update the stride value. */ - value_assign(loop->stride,stride) ; + cloog_int_set(loop->stride, stride); /* The new lower bound l' is such that * (l' + offset) % s = 0 and l <= l' <= l+(s-1) * Let l' = k s - offset, then @@ -1090,20 +1093,20 @@ void cloog_loop_stride(CloogLoop * loop, int level, int nb_par) * Or l' = floor((l+offset+(s-1))/s) * s - offset * = (floor((l+offset-1)/s) + 1) * s - offset */ - value_addto(lower, lower, offset); - value_decrement(lower, lower); - value_pdivision(lower, lower, stride); - value_increment(lower, lower); - value_multiply(lower, lower, stride); - value_subtract(lower, lower, offset); + cloog_int_add(lower, lower, offset); + cloog_int_sub_ui(lower, lower, 1); + cloog_int_fdiv_q(lower, lower, stride); + cloog_int_add_ui(lower, lower, 1); + cloog_int_mul(lower, lower, stride); + cloog_int_sub(lower, lower, offset); cloog_domain_lowerbound_update(loop->domain,level,lower) ; } - value_clear_c(stride) ; - value_clear_c(ref_offset) ; - value_clear_c(offset) ; - value_clear_c(potential) ; - value_clear_c(lower) ; + cloog_int_clear(stride); + cloog_int_clear(ref_offset); + cloog_int_clear(offset); + cloog_int_clear(potential); + cloog_int_clear(lower); } @@ -1155,8 +1158,8 @@ int cloog_loop_scalar_gt(l1, l2, level, scaldims, nb_scattdims, scalar) CloogLoop * l1, * l2 ; int level, * scaldims, nb_scattdims, scalar ; { while ((scalar < l1->inner->block->nb_scaldims) && scaldims[level+scalar-1]) - { if (value_gt(l1->inner->block->scaldims[scalar], - l2->inner->block->scaldims[scalar])) + { if (cloog_int_gt(l1->inner->block->scaldims[scalar], + l2->inner->block->scaldims[scalar])) scalar ++ ; else return 0 ; @@ -1186,8 +1189,8 @@ int cloog_loop_scalar_eq(l1, l2, level, scaldims, nb_scattdims, scalar) CloogLoop * l1, * l2 ; int level, * scaldims, nb_scattdims, scalar ; { while ((scalar < l1->inner->block->nb_scaldims) && scaldims[level+scalar-1]) - { if (value_eq(l1->inner->block->scaldims[scalar], - l2->inner->block->scaldims[scalar])) + { if (cloog_int_eq(l1->inner->block->scaldims[scalar], + l2->inner->block->scaldims[scalar])) scalar ++ ; else return 0 ; @@ -1252,13 +1255,14 @@ CloogLoop * loop ; CloogDomain * context ; int level, nb_par ; CloogOptions * options ; -{ Value one ; +{ + cloog_int_t one; CloogDomain * domain ; CloogLoop * now, * now2, * next, * next2, * end, * temp, * l, * inner, * new_loop ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); temp = loop ; loop = NULL ; @@ -1288,8 +1292,8 @@ CloogOptions * options ; if (l != NULL) { l = cloog_loop_separate(l) ; l = cloog_loop_sort(l,level,nb_par) ; - while (l != NULL) - { value_assign(l->stride,temp->stride) ; + while (l != NULL) { + cloog_int_set(l->stride, temp->stride); cloog_loop_add(&loop,&now,l) ; l = l->next ; } @@ -1299,7 +1303,7 @@ CloogOptions * options ; temp = next2 ; } - value_clear_c(one) ; + cloog_int_clear(one); return loop ; } @@ -1337,7 +1341,8 @@ CloogLoop * loop ; CloogDomain * context ; int level, scalar, * scaldims, nb_scattdims, nb_par ; CloogOptions * options ; -{ Value one ; +{ + cloog_int_t one; CloogLoop * res, * now, * temp, * l, * new_loop, * inner, * now2, * end, * next, * into ; CloogDomain * domain ; @@ -1349,8 +1354,8 @@ CloogOptions * options ; /* 3b. -correction- sort the loops to determine their textual order. */ res = cloog_loop_sort(res,level,nb_par) ; - value_init_c(one) ; - value_set_si(one,1) ; + cloog_int_init(one); + cloog_int_set_si(one, 1); /* 4. Recurse for each loop with the current domain as context. */ temp = res ; @@ -1423,7 +1428,7 @@ CloogOptions * options ; */ /* res = cloog_loop_unisolate(res,context,level,nb_par) ;*/ - value_clear_c(one) ; + cloog_int_clear(one); return(res) ; } diff --git a/source/pprint.c b/source/pprint.c index 2fe8073..b4628cf 100644 --- a/source/pprint.c +++ b/source/pprint.c @@ -65,16 +65,16 @@ void pprint_term(FILE *dst, struct clast_term *t) { if (t->var) { - if (value_one_p(t->val)) + if (cloog_int_is_one(t->val)) fprintf(dst, "%s", t->var); - else if (value_mone_p(t->val)) + else if (cloog_int_is_neg_one(t->val)) fprintf(dst, "-%s", t->var); else { - value_print(dst, VALUE_FMT, t->val); + cloog_int_print(dst, t->val); fprintf(dst, "*%s", t->var); } } else - value_print(dst, VALUE_FMT, t->val); + cloog_int_print(dst, t->val); } void pprint_sum(FILE *dst, struct clast_reduction *r) @@ -90,7 +90,7 @@ void pprint_sum(FILE *dst, struct clast_reduction *r) for (i = 1; i < r->n; ++i) { assert(r->elts[i]->type == expr_term); t = (struct clast_term *) r->elts[i]; - if (value_pos_p(t->val)) + if (cloog_int_is_pos(t->val)) fprintf(dst, "+"); pprint_term(dst, t); } @@ -146,7 +146,7 @@ void pprint_binary(struct cloogoptions *i, FILE *dst, struct clast_binary *b) fprintf(dst, "%s", s1); pprint_expr(i, dst, b->LHS); fprintf(dst, "%s", s2); - value_print(dst, VALUE_FMT, b->RHS); + cloog_int_print(dst, b->RHS); fprintf(dst, "%s", s3); } @@ -330,14 +330,15 @@ void pprint_for(struct cloogoptions *options, FILE *dst, int indent, } if (options->language == LANGUAGE_FORTRAN) { - if (value_gt_si(f->stride, 1)) - value_print(dst, VALUE_FMT, f->stride); + if (cloog_int_gt_si(f->stride, 1)) + cloog_int_print(dst, f->stride); fprintf(dst,"\n"); } else { - if (value_gt_si(f->stride, 1)) { + if (cloog_int_gt_si(f->stride, 1)) { fprintf(dst,";%s+=", f->iterator); - value_print(dst, VALUE_FMT") {\n", f->stride); + cloog_int_print(dst, f->stride); + fprintf(dst, ") {\n"); } else fprintf(dst, ";%s++) {\n", f->iterator); } diff --git a/source/program.c b/source/program.c index 51f2695..9f02964 100644 --- a/source/program.c +++ b/source/program.c @@ -56,23 +56,26 @@ /** * These global variables are devoted to memory leaks hunting: we - * want to know at each moment how many Value variables have been allocated + * want to know at each moment how many cloog_int_t variables have been + * allocated * since in GMP mode they have to be freed (see domain.c for the declaration). * - July 3rd->11th 2003: first version (memory leaks hunt and correction). */ -int cloog_value_allocated = 0; -int cloog_value_freed = 0; -int cloog_value_max = 0; - -void cloog_value_leak_up() -{ cloog_value_allocated ++ ; - if ((cloog_value_allocated-cloog_value_freed) > cloog_value_max) - cloog_value_max = cloog_value_allocated - cloog_value_freed ; +int cloog_int_allocated = 0; +int cloog_int_freed = 0; +int cloog_int_max = 0; + +void cloog_int_leak_up() +{ + cloog_int_allocated++; + if ((cloog_int_allocated - cloog_int_freed) > cloog_int_max) + cloog_int_max = cloog_int_allocated - cloog_int_freed; } -void cloog_value_leak_down() -{ cloog_value_freed ++ ; +void cloog_int_leak_down() +{ + cloog_int_freed++; } @@ -939,9 +942,9 @@ CloogDomainList * scattering ; while (blocklist != NULL) { block = blocklist->block ; block->nb_scaldims = nb_scaldims ; - block->scaldims = (Value *)malloc(nb_scaldims*sizeof(Value)) ; + block->scaldims = (cloog_int_t *)malloc(nb_scaldims*sizeof(cloog_int_t)); for (i=0;iscaldims[i]) ; + cloog_int_init(block->scaldims[i]); blocklist = blocklist->next ; } -- 2.11.4.GIT