PIPS
bdt_read_paf.c
Go to the documentation of this file.
1 /*
2 
3  $Id: bdt_read_paf.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /* Name : bdt_read_paf.c
28  * Package : paf-util
29  * Author : Alexis Platonoff
30  * Date : april 1993
31  * Historic :
32  * - 16 july 93, changes in paf_ri, AP
33  * - 2 august 93, moved from (package) scheduling to paf-util, AP
34  * - 10 nov 93: add of reorganize_bdt() and same_predicate_p(), AP
35  *
36  * Documents:
37  * Comments :
38  * These functions are used to store a timing function (BDT) in a Newgen
39  * structure from the reading of a file generate by the PAF parallelizer:
40  * ".bdt" file, which contains the BDT functions.
41  *
42  * Each BDT function is associated with an instruction and a predicate. The
43  * Newgen structure is called "bdt" which is a list of BDT function of type
44  * "schedule". These two Newgen structures are defined in the file paf_ri.f.tex
45  * (see comments on them in this file). We also use the library of PIPS and
46  * its RI Newgen structure.
47  *
48  * The ".bdt" file is read with Yacc and Lex programs (parse.y and scan.l).
49  * The Newgen structure "bdt" is update during the parsing of the file.
50  */
51 
52 #include <stdio.h>
53 #include <string.h>
54 #include <stdlib.h>
55 
56 #include "boolean.h"
57 #include "arithmetique.h"
58 #include "vecteur.h"
59 #include "contrainte.h"
60 #include "ray_dte.h"
61 #include "sommet.h"
62 #include "sg.h"
63 #include "sc.h"
64 #include "polyedre.h"
65 #include "matrice.h"
66 #include "matrix.h"
67 
68 #include "genC.h"
69 
70 #include "linear.h"
71 #include "ri.h"
72 #include "ri-util.h"
73 #include "constants.h"
74 #include "misc.h"
75 #include "paf_ri.h"
78 #include "graph.h"
79 #include "paf-util.h"
80 
81 #define POSITIVE 1
82 #define NEGATIVE 0
83 #define INS_NAME_LENGTH 4
84 #define DOT "."
85 #define BDT_STRING "bdt"
86 
87 
88 /* Static global variables */
89 static int crt_ins; /* Current stmt (an integer) */
90 static list pred_l, /* Current list of predicates */
91  lin_exp_l; /* Current list of linear expressions */
92 static expression crt_exp; /* Current expression */
93 
94 
95 /* Global variables */
96 
97 /* This global variable is the current BDT being computed. Its type is defined
98  * in paf_ri.h
99  */
101 
102 /*============================================================================*/
103 /* bdt bdt_read_paf(char *s) : computes the BDT of the PAF program name given
104  * in argument and returns it.
105  *
106  * bdtyyparse() do the parsing over the ".bdt" file and put the timing function
107  * into the global variable "base" which is returned.
108  *
109  */
111 char *s;
112 {
113  extern bdt base;
114 
115  FILE *bdt_file;
116  char *bdt_file_name;
117 
118  bdt_file_name = strdup(concatenate(s, DOT, BDT_STRING, (char *) NULL));
119 
120  if( (bdt_file = fopen(bdt_file_name, "r")) == NULL)
121  {
122  fprintf(stderr, "Cannot open file %s\n", bdt_file_name);
123  exit(1);
124  }
125 
126 #if defined(HAS_BDTYY)
127 
128  bdtyyin = bdt_file;
129  (void) bdtyyparse();
130 
131 #else
132 
133  pips_internal_error("not bdtyy{in,parse} compiled in (HAS_BDTYY undef)");
134 
135 #endif
136 
137  fclose(bdt_file);
138 
140 
141  return(base);
142 }
143 
144 /*============================================================================*/
145 bool same_predicate_p(p1, p2)
146 predicate p1, p2;
147 {
148 
149  if( (p1 == predicate_undefined) && (p2 == predicate_undefined) )
150  return(true);
151  else if(p1 == predicate_undefined)
152  return(false);
153  else if(p2 == predicate_undefined)
154  return(false);
155 
156  if( (p1 == NULL) && (p2 == NULL) )
157  return(true);
158  else if(p1 == NULL)
159  return(false);
160  else if(p2 == NULL)
161  return(false);
162 
163  /* If the predicate are defined, we consider them as always different */
164  return(false);
165 }
166 
167 
168 /*============================================================================*/
169 /* void reorganize_bdt(bdt base):
170  */
172 bdt base;
173 {
174  list sch_l, new_sch_l = NIL, l;
175 
176  for(sch_l = bdt_schedules(base); !ENDP(sch_l); POP(sch_l)) {
177  schedule sch = SCHEDULE(CAR(sch_l));
178  int stmt = schedule_statement(sch);
179  predicate pred = schedule_predicate(sch);
180  bool to_add = true;
181 
182  for(l = new_sch_l; (!ENDP(l)) && to_add; POP(l)) {
183  schedule nsch = SCHEDULE(CAR(l));
184  int nstmt = schedule_statement(nsch);
185  predicate npred = schedule_predicate(nsch);
186 
187  if(stmt == nstmt) {
188  if(same_predicate_p(pred, npred)) {
189  expression nexp = EXPRESSION(CAR(schedule_dims(sch)));
190  schedule_dims(nsch) = gen_nconc(schedule_dims(nsch),
191  CONS(EXPRESSION, nexp, NIL));
192  to_add = false;
193  }
194  }
195  }
196  if(to_add)
197  new_sch_l = gen_nconc(new_sch_l, CONS(SCHEDULE, sch, NIL));
198  }
199  bdt_schedules(base) = new_sch_l;
200 }
201 
202 
203 /*============================================================================*/
204 /* void bdt_init_new_base() : initializes the computation of the BDT, i.e. the
205  * creation of the BDT in the "base" variable.
206  */
208 {
209  extern bdt base;
210 
211  base = make_bdt(NIL);
212 }
213 
214 /*============================================================================*/
215 /* void bdt_init_new_ins(char *s_ins): initializes the computation of the
216  * current statement for which we are now parsing its BDT. This statement is
217  * represented by its ordering contained in its name "s_ins".
218  * Also, we initialize "lin_exp_l" used for the parsing of the lisp
219  * expressions and "pred_l" used for the parsing of the predicates.
220  */
221 void bdt_init_new_ins(s_ins)
222 char * s_ins;
223 {
224  extern int crt_ins;
225  extern list pred_l, lin_exp_l;
226 
227  /* In PAF, a statement name is a string "ins_#", where "#" is the number
228  * associated with the statement. We get this number.
229  */
230  crt_ins = atoi(strdup(s_ins + INS_NAME_LENGTH));
231 
232  pred_l = NIL;
233  lin_exp_l = NIL;
234 }
235 
236 /*============================================================================*/
237 /* void bdt_new_shedule(char *s_func): the parser has found all the predicates
238  * of a schedule. We create this new schedule and put it in "base". This
239  * predicate is formed with the list of expressions of "pred_l". The function
240  * expressions_to_predicate() translates this list of expressions into a
241  * predicate. The schedule statement number is the current one (crt_ins"). The
242  * schedule has one dimension, the corresponding expression is found in
243  * "crt_exp".
244  */
245 void bdt_new_shedule(string s_func __attribute__ ((unused)))
246 {
247  extern int crt_ins;
248  extern expression crt_exp;
249  extern list pred_l, lin_exp_l;
250 
256 
257  lin_exp_l = NIL;
259 }
260 
261 /*============================================================================*/
262 /* void bdt_save_pred(int option): computes one expression of the predicate.
263  * Each expression is used twice ; indeed, an expression may be greater or
264  * equal than zero (>=) and smaller than zero (<). "option" says in which case
265  * we are: POSITIVE indicates that the predicate is >=, with NEGATIVE it is <.
266  * However, the C3 library always represents its inequalities with <=. So, the
267  * inequality "A >= 0" becomes "-A <= 0" and "A < 0" becomes "A + 1 <= 0".
268  *
269  * This function updates the global list "pred_l" that contains the current
270  * list of predicates. When a new predicate expression is parsed, the POSITIVE
271  * is always considered first (that is why only in that case we use "crt_exp").
272  * When the NEGATICE case is considered, the corresponding expression (used in
273  * the POSITIVE case) is the first expression of the list "pred_l". So, we only
274  * have to replace this expression by it equivalent for the NEGATIVE case (that
275  * is why the expression is multiplied by -1).
276  */
277 void bdt_save_pred(option)
278 int option;
279 {
280  extern list pred_l, lin_exp_l;
281  extern expression crt_exp;
282 
283  expression aux_pred;
284 
285  if(option == POSITIVE)
286  {
288  pips_internal_error("current expression is undefined");
289 
292  }
293  else
294  /* option == NEGATIVE */
295  {
296  aux_pred = make_op_exp(PLUS_OPERATOR_NAME,
298  int_to_expression(1));
299 
300  pred_l = CONS(EXPRESSION, aux_pred, CDR(pred_l));
301  }
302 
303 /* Initialization of global variables */
304  lin_exp_l = NIL;
305 }
306 
307 /*============================================================================*/
308 /* void bdt_elim_last_pred(): When POSITIVE and NEGATIVE cases of one predicate
309  * have been completed, we eliminate the corresponding expression which is the
310  * first one of the list "pred_l".
311  */
313 {
314  extern list pred_l;
315 
316  pred_l = CDR(pred_l);
317 }
318 
319 /*============================================================================*/
320 /* void bdt_save_int(int i): The parser has found an integer as a part of a
321  * lisp expression. We save it in our global variable "lin_exp_l".
322  *
323  * If "lin_exp_l" is empty, then this integer becomes the current expression.
324  * If not, it becomes an argument of the first lisp expression of "lin_exp_l".
325  */
327 int i;
328 {
329  extern list lin_exp_l;
330  extern expression crt_exp;
331  expression aux_exp;
332 
333  aux_exp = int_to_expression(i);
334 
335  if(lin_exp_l == NIL)
336  crt_exp = aux_exp;
337  else
338  {
341  CONS(EXPRESSION, aux_exp, NIL));
342  }
343 }
344 
345 /*============================================================================*/
346 /* void bdt_save_id(string s): The parser has found a variable as a part of a
347  * lisp expression. We save it in our global variable "lin_exp_l".
348  *
349  * If "lin_exp_l" is empty, then this variable becomes the current expression.
350  * If not, it becomes an argument of the first lisp expression of "lin_exp_l".
351  */
352 void bdt_save_id(s)
353 string s;
354 {
355  extern list lin_exp_l;
356  extern expression crt_exp;
357  expression aux_exp;
358 
359  aux_exp = make_id_expression(s);
360 
361  if(lin_exp_l == NIL)
362  crt_exp = aux_exp;
363  else
364  {
367  CONS(EXPRESSION, aux_exp, NIL));
368  }
369 }
370 
371 /*============================================================================*/
372 /* void bdt_init_op_exp(string op_name): initializes a new lisp expression with
373  * the operation "op_name". This expression is put at the beginning of
374  * "lin_exp_l", it is the expression the parser is currently reading.
375  *
376  * If "op_name" is the string "0" then the operator used is "crt_op_name", else
377  * the operator name is contained in "op_name".
378  */
379 void bdt_init_op_exp(op_name)
380 string op_name;
381 {
382  extern list lin_exp_l;
383 
385 }
386 
387 /*============================================================================*/
388 /* void bdt_save_exp(): the parser has completed the reading of one lisp
389  * expression, this is the first lisp expression of "lin_exp_l". We extract it
390  * from this list and translate it into a Pips expression. If there is no other
391  * lisp expression in "lin_exp_l", then this expression becomes the current
392  * expression, else it becomes an argument of the next lisp expression which is
393  * now the first object of "lin_exp_l".
394  */
396 {
397  extern expression crt_exp;
398 
399  expression aux_exp;
400  lisp_expression aux_le;
401 
402  aux_le = LISP_EXPRESSION(CAR(lin_exp_l));
403  aux_exp = lisp_exp_to_ri_exp(aux_le);
404 
406 
407  if(lin_exp_l == NIL)
408  crt_exp = aux_exp;
409  else
410  {
413  CONS(EXPRESSION, aux_exp, NIL));
414  }
415 }
416 
417 
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
bdt make_bdt(list a)
Definition: paf_ri.c:54
schedule make_schedule(intptr_t a1, predicate a2, list a3)
Definition: paf_ri.c:613
lisp_expression make_lisp_expression(string a1, list a2)
Definition: paf_ri.c:348
bdt base
Current expression.
Definition: bdt_read_paf.c:100
void bdt_save_pred(int option)
===========================================================================
Definition: bdt_read_paf.c:277
dfg_arc_label arc_label
Name : bdt_read_paf.c Package : paf-util Author : Alexis Platonoff Date : april 1993 Historic :
Definition: bdt_read_paf.c:76
bool same_predicate_p(predicate p1, predicate p2)
===========================================================================
Definition: bdt_read_paf.c:145
#define BDT_STRING
Definition: bdt_read_paf.c:85
void bdt_init_new_ins(char *s_ins)
===========================================================================
Definition: bdt_read_paf.c:221
void bdt_init_op_exp(string op_name)
===========================================================================
Definition: bdt_read_paf.c:379
void reorganize_bdt(bdt base)
===========================================================================
Definition: bdt_read_paf.c:171
void bdt_new_shedule(string s_func __attribute__((unused)))
===========================================================================
Definition: bdt_read_paf.c:245
dfg_vertex_label vertex_label
Definition: bdt_read_paf.c:77
static list pred_l
Current stmt (an integer)
Definition: bdt_read_paf.c:90
#define DOT
Definition: bdt_read_paf.c:84
static expression crt_exp
Current list of linear expressions.
Definition: bdt_read_paf.c:92
void bdt_save_id(string s)
===========================================================================
Definition: bdt_read_paf.c:352
static int crt_ins
Static global variables.
Definition: bdt_read_paf.c:89
#define INS_NAME_LENGTH
Definition: bdt_read_paf.c:83
void bdt_save_int(int i)
===========================================================================
Definition: bdt_read_paf.c:326
void bdt_elim_last_pred()
===========================================================================
Definition: bdt_read_paf.c:312
void bdt_init_new_base()
===========================================================================
Definition: bdt_read_paf.c:207
void bdt_save_exp()
===========================================================================
Definition: bdt_read_paf.c:395
#define POSITIVE
Definition: bdt_read_paf.c:81
bdt bdt_read_paf(char *s)
===========================================================================
Definition: bdt_read_paf.c:110
static list lin_exp_l
Current list of predicates.
Definition: bdt_read_paf.c:91
#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
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
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
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define pips_internal_error
Definition: misc-local.h:149
#define exit(code)
Definition: misc-local.h:54
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
expression negate_expression(expression)
===========================================================================
Definition: utils.c:792
expression lisp_exp_to_ri_exp(lisp_expression)
===========================================================================
Definition: utils.c:755
expression make_id_expression(string)
===========================================================================
Definition: utils.c:672
predicate expressions_to_predicate(list)
===========================================================================
Definition: utils.c:826
#define SCHEDULE(x)
SCHEDULE.
Definition: paf_ri.h:682
#define LISP_EXPRESSION(x)
LISP_EXPRESSION.
Definition: paf_ri.h:457
#define schedule_predicate(x)
Definition: paf_ri.h:715
#define bdt_schedules(x)
Definition: paf_ri.h:226
#define schedule_dims(x)
Definition: paf_ri.h:717
#define schedule_statement(x)
Definition: paf_ri.h:713
#define lisp_expression_args(x)
Definition: paf_ri.h:489
#define PLUS_OPERATOR_NAME
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
expression make_op_exp(char *op_name, expression exp1, expression exp2)
================================================================
Definition: expression.c:2012
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define expression_undefined
Definition: ri.h:1223
#define predicate_undefined
Definition: ri.h:2046
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: statement.c:54