PIPS
cell_relations.c
Go to the documentation of this file.
1 /*
2 
3  $Id: cell_relations.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6  Copyright 2010 HPC Project
7 
8  This file is part of PIPS.
9 
10  PIPS is free software: you can redistribute it and/or modify it
11  under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  any later version.
14 
15  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
16  WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  FITNESS FOR A PARTICULAR PURPOSE.
18 
19  See the GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
23 */
24 
25 /* functions specific to cell_relations */
26 
27 #ifdef HAVE_CONFIG_H
28  #include "pips_config.h"
29 #endif
30 
31 #include <stdio.h>
32 #include <string.h>
33 
34 #include "genC.h"
35 #include "linear.h"
36 #include "ri.h"
37 #include "ri-util.h"
38 #include "effects.h"
39 #include "effects-util.h"
40 #include "misc.h"
41 
42 /**
43  beware : modifies l1, l2 and their effects
44 
45  @param l1 and l2 are two lists of cell_relations.
46  @param cr1_cr2_combinable_p is a bool function that takes two
47  individual cell_relations as arguments and renders true when they are
48  considered as combinable ;
49  @param cr1_cr2_binary_op is a binary operator that combines two
50  individual cell_relations;
51  @param cr1_unary_op is a unary operators that deal with the remnants of l1,
52  that is those cell_relations that are not combinable with any effect of l2;
53  @param cr2_unary_op is a unary operators that deal with the remnants of l2,
54  that is those cell_relations that are not combinable with any effect of l1;
55 
56  @return a list of cell_relations, combination of l1 and l2.
57 
58 */
60  list l1,
61  list l2,
62  bool (*cr1_cr2_combinable_p)(cell_relation,cell_relation),
63  list (*cr1_cr2_binary_op)(cell_relation,cell_relation),
64  list (*cr1_unary_op)(cell_relation),
65  list (*cr2_unary_op)(cell_relation),
66  list (*union_op)(list, list))
67 {
68  list l_res = NIL;
69  list l_cr1 = list_undefined;
70  list l_cr2 = list_undefined;
71 
72  debug_on("CELL_RELATIONS_OPERATORS_DEBUG_LEVEL");
73 
74  pips_debug_pvs(1, "l1:\n", l1);
75  pips_debug_pvs(1, "l2:\n", l2);
76 
77  /* we first deal with the elements of l1 : those that are combinable with
78  * the elements of l2, and the others, which we call the remnants of l1 */
79  for(l_cr1 = l1; !ENDP(l_cr1); POP(l_cr1))
80  {
81  cell_relation cr1 = CELL_RELATION(CAR(l_cr1));
82  list prec_l_cr2 = NIL;
83  bool combinable = false;
84 
85  pips_debug_pv(2, "dealing with cr1:\n", cr1);
86 
87  l_cr2 = l2;
88  while(!ENDP(l_cr2))
89  {
90  cell_relation cr2 = CELL_RELATION(CAR(l_cr2));
91 
92  pips_debug_pv(2, "considering cr2:\n", cr2);
93 
94  if ( (*cr1_cr2_combinable_p)(cr1,cr2) )
95  {
96  pips_debug(2, "combinable\n");
97  combinable = true;
98  list l_res_tmp = (*cr1_cr2_binary_op)(cr1,cr2);
99  l_res = (*union_op)(l_res, l_res_tmp);
100 
101  /* gen_remove(&l2, EFFECT(CAR(l_cr2))); */
102  if (prec_l_cr2 != NIL)
103  CDR(prec_l_cr2) = CDR(l_cr2);
104  else
105  l2 = CDR(l_cr2);
106 
107  free(l_cr2); l_cr2 = NIL;
108  /* */
109  //free_cell_relation(cr1); cr1=cell_relation_undefined;
111  }
112  else
113  {
114  pips_debug(2, "not combinable\n");
115  prec_l_cr2 = l_cr2;
116  l_cr2 = CDR(l_cr2);
117  }
118  }
119 
120  pips_debug_pvs(2, "intermediate l_res 1:\n", l_res);
121 
122  if(!combinable)
123  {
124  /* cr1 belongs to the remnants of l1 : it is combinable
125  * with no effects of l2 */
126  if ( (*cr1_cr2_combinable_p)(cr1,cell_relation_undefined) )
127  l_res = gen_nconc(l_res, (*cr1_unary_op)(cr1));
128  }
129  else
130  {
132  }
133  }
134 
135  pips_debug_pvs(2, "intermediate l_res 2:\n", l_res);
136 
137  /* we must then deal with the remnants of l2 */
138  for(l_cr2 = l2; !ENDP(l_cr2); POP(l_cr2))
139  {
140  cell_relation cr2 = CELL_RELATION(CAR(l_cr2));
141 
142  if ( (*cr1_cr2_combinable_p)(cell_relation_undefined,cr2) )
143  l_res = gen_nconc(l_res, (*cr2_unary_op)(cr2));
144  }
145 
146  pips_debug_pvs(1, "final pvs:\n", l_res);
147 
148  /* no memory leaks: l1 and l2 won't be used anymore */
149  gen_free_list(l1);
150  gen_free_list(l2);
151 
152  debug_off();
153 
154  return l_res;
155 }
void free_cell_relation(cell_relation p)
Definition: effects.c:308
list cell_relations_generic_binary_op(list l1, list l2, bool(*cr1_cr2_combinable_p)(cell_relation, cell_relation), list(*cr1_cr2_binary_op)(cell_relation, cell_relation), list(*cr1_unary_op)(cell_relation), list(*cr2_unary_op)(cell_relation), list(*union_op)(list, list))
functions specific to cell_relations
#define pips_debug_pv(level, message, pv)
#define pips_debug_pvs(level, message, l_pv)
#define CELL_RELATION(x)
CELL_RELATION.
Definition: effects.h:479
#define cell_relation_undefined
Definition: effects.h:485
void free(void *)
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define debug_off()
Definition: misc-local.h:160
The structure used to build lists in NewGen.
Definition: newgen_list.h:41