X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Flpp%2Flpp.c;h=2d2c8a98aad623288ae515f3122f63fbabc9c64c;hb=6ccff2965d94c272f71df2a1655336af47bb7753;hp=82ea74cbbf84644f9def6400af029531ec612476;hpb=c86aa375b9fe725d85d012dd1231727a03a16585;p=libfirm diff --git a/ir/lpp/lpp.c b/ir/lpp/lpp.c index 82ea74cbb..2d2c8a98a 100644 --- a/ir/lpp/lpp.c +++ b/ir/lpp/lpp.c @@ -1,11 +1,26 @@ -/** - * Author: Daniel Grund - * Date: Fri 13.05.2005 - * Copyright: (c) Universitaet Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. - * CVS-Id: $Id: lpp.c 27353 2010-04-07 13:33:16Z matze $ +/* + * Copyright (C) 2005-2011 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ +/** + * @file + * @author Daniel Grund + */ #include "config.h" #include @@ -17,6 +32,7 @@ #include "hashptr.h" #include "debug.h" #include "set.h" +#include "debug.h" #include "sp_matrix.h" #include "mps.h" @@ -27,7 +43,7 @@ #define HASH_NAME_T(n) HASH_STR((n)->name, strlen((n)->name)) -static firm_dbg_module_t *dbg = NULL; +DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;) static inline char *obst_xstrdup(struct obstack *obst, const char *str) { @@ -38,7 +54,7 @@ static int cmp_name_t(const void *x, const void *y, size_t size) { const lpp_name_t *n = x; const lpp_name_t *m = y; - (void)size; /* stop warnings */ + (void)size; return strcmp(n->name, m->name); } @@ -52,20 +68,19 @@ static void update_stats(lpp_t *lpp) lpp->density = (double)lpp->n_elems / (double)(lpp->cst_next * lpp->var_next) * 100.0; } -#define INITIAL_SIZE 64 - -lpp_t *new_lpp(const char *name, lpp_opt_t opt_type) +lpp_t *lpp_new(const char *name, lpp_opt_t opt_type) { - return new_lpp_userdef(name, opt_type, INITIAL_SIZE, INITIAL_SIZE, 2.0); + return lpp_new_userdef(name, opt_type, 64, 64, 2.0); } -lpp_t *new_lpp_userdef(const char *name, lpp_opt_t opt_type, - int estimated_vars, int estimated_csts, double grow_factor) +lpp_t *lpp_new_userdef(const char *name, lpp_opt_t opt_type, + int estimated_vars, int estimated_csts, + double grow_factor) { lpp_t *lpp; int idx; - dbg = firm_dbg_register("lpp"); + DEBUG_ONLY(dbg = firm_dbg_register("lpp");) lpp = XMALLOCZ(lpp_t); obstack_init(&lpp->obst); @@ -88,13 +103,13 @@ lpp_t *new_lpp_userdef(const char *name, lpp_opt_t opt_type, return lpp; } -void free_lpp_matrix(lpp_t *lpp) +void lpp_free_matrix(lpp_t *lpp) { del_matrix(lpp->m); lpp->m = NULL; } -void free_lpp(lpp_t *lpp) +void lpp_free(lpp_t *lpp) { obstack_free(&lpp->obst, NULL); @@ -121,7 +136,7 @@ void lpp_set_fix_costs(lpp_t *lpp, double value) matrix_set(lpp->m, 0, 0, value); } -static inline int name2nr(set *where, const char *name) +static int name2nr(set *where, const char *name) { lpp_name_t find, *found; find.name = name; @@ -129,8 +144,15 @@ static inline int name2nr(set *where, const char *name) return (found ? found->nr : -1); } -#define cst_nr(lpp, name) name2nr(lpp->cst2nr, name) -#define var_nr(lpp, name) name2nr(lpp->var2nr, name) +static int cst_nr(const lpp_t *lpp, const char *name) +{ + return name2nr(lpp->cst2nr, name); +} + +static int var_nr(const lpp_t *lpp, const char *name) +{ + return name2nr(lpp->var2nr, name); +} static inline char *get_next_name(lpp_t *lpp) { @@ -342,14 +364,14 @@ void lpp_check_startvals(lpp_t *lpp) fprintf(stderr, "constraint %s unsatisfied: %g != %g\n", cst->name, sum, cst_val); } break; - case lpp_less: + case lpp_less_equal: if(sum > cst_val) { - fprintf(stderr, "constraint %s unsatisfied: %g > %g\n", cst->name, sum, cst_val); + fprintf(stderr, "constraint %s unsatisfied: %g >= %g\n", cst->name, sum, cst_val); } break; - case lpp_greater: + case lpp_greater_equal: if(sum < cst_val) { - fprintf(stderr, "constraint %s unsatisfied: %g < %g\n", cst->name, sum, cst_val); + fprintf(stderr, "constraint %s unsatisfied: %g <= %g\n", cst->name, sum, cst_val); } break; default: @@ -377,9 +399,9 @@ static const char *lpp_cst_op_to_str(lpp_cst_t cst) switch(cst) { case lpp_equal: return "="; - case lpp_less: + case lpp_less_equal: return "<="; - case lpp_greater: + case lpp_greater_equal: return ">="; default: return ""; @@ -465,8 +487,6 @@ void lpp_serialize(lpp_comm_t *comm, const lpp_t *lpp, int with_names) } } -#define NAMELEN 64 - /** * Deserialize an lpp from a file descriptor. * @param comm The file descriptor. @@ -512,8 +532,8 @@ lpp_t *lpp_deserialize(lpp_comm_t *comm) if(with_names) { name.name = lpp_reads(comm); } else { - char* buf = XMALLOCN(char, NAMELEN); - snprintf(buf, NAMELEN, "c%d\n", name.nr); + char* buf = XMALLOCN(char, 32); + snprintf(buf, 32, "c%d\n", name.nr); name.name = buf; } @@ -531,8 +551,8 @@ lpp_t *lpp_deserialize(lpp_comm_t *comm) if(with_names) { name.name = lpp_reads(comm); } else { - char* buf = XMALLOCN(char, NAMELEN); - snprintf(buf, NAMELEN, "v%d\n", name.nr); + char* buf = XMALLOCN(char, 32); + snprintf(buf, 32, "v%d\n", name.nr); name.name = buf; }