PIPS
comp_expr_to_pnome.c
Go to the documentation of this file.
1 /*
2 
3  $Id: comp_expr_to_pnome.c 23647 2021-03-10 09:58:29Z 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 /* comp_expr_to_pnome.c */
28 /* scan a ri expression and try to make a polynomial of it */
29 
30 /* Modif:
31  -- entity_local_name is replaced by module_local_name. LZ 230993
32  -- MAXINT replaced by INT_MAX, -MAXINT by INT_MIN FI 1/12/95
33 */
34 
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <limits.h>
38 #include <string.h>
39 
40 #include "linear.h"
41 
42 #include "genC.h"
43 #include "ri.h"
44 #include "effects.h"
45 #include "complexity_ri.h"
46 #include "ri-util.h"
47 #include "pipsdbm.h"
48 #include "workspace-util.h"
49 #include "effects-util.h"
50 
51 #include "misc.h" /* useful, pips_error is defined there */
52 
53 #include "properties.h"
54 
55 #include "complexity.h"
56 
59 
60 char *noms_var(e)
61 entity e;
62 {
63  bool entity_has_values_p();
64  string external_value_name();
65 
66  if(e == (entity) TCST)
67  return "";
68  else
69  return entity_has_values_p(e) ? (char *)module_local_name(e) :
70  (char *)external_value_name(e);
71 }
72 
73 /*
74  * This file contains routines named "xxx_to_polynome".
75  * They don't care about the complexity of the expression they scan,
76  * however care about their value. They return a complete complexity,
77  * not only a polynomial but also statistics: guessed, unknown variables, ...
78  */
79 
80 /* builds a new unknown complexity attached to a virtual package */
81 complexity make_complexity_unknown(const char * name) {
82  entity package = FindEntity(TOP_LEVEL_MODULE_NAME,COMPLEXITY_PACKAGE_NAME);
86  return make_single_var_complexity(1.f,var);
87 }
88 
89 ␌
90 /* Entry point routine of this file:
91  *
92  * complexity expression_to_complexity_polynome(expression expr,
93  * transformer precond,
94  * list effects_list,
95  * bool keep_symbols,
96  * int maximize)
97  * return the polynomial associated to the expression expr,
98  * or POLYNOME_UNDEFINED if it's not a polynome.
99  * or POLYNOME_NULL if it's a 0 complexity.
100  * If keep_symbols is false, we force evaluation of variables.
101  * If they can't be evaluated, they enter the polynomial,
102  * but they are replaced by the pseudo-variable UNKNOWN_VARIABLE,
103  * except when they appear in a loop range:
104  * in that case, the whole range is replaced by UNKNOWN_RANGE.
105  * The int maximize lets us use the mins and maxs of
106  * preconditions system, to compute a WORST-CASE complexity
107  * for the upper bound , maximize is 1
108  * for the lower bound and increment, maximize is -1
109  * (when the precondition doesn't give an exact value)
110  *
111  * effects_list is added on 10 Nov 92 to pass the effects
112  * which can be used to determine the "must-be-written"
113  * effects to delay the variable evaluation. LZ 10 Nov 92
114  *
115  * FI:
116  * - better symbol generation for unknown complexities
117  */
118 complexity expression_to_complexity_polynome(expr, precond, effects_list, keep_symbols, maximize)
119 expression expr;
120 transformer precond;
121 list effects_list;
122 bool keep_symbols;
123 int maximize;
124 {
125  normalized no = NORMALIZE_EXPRESSION(expr);
126  syntax sy = expression_syntax(expr);
128 
129  trace_on("expression -> pnome");
130 
131  if ( expr == expression_undefined ) {
132  pips_internal_error("undefined expression");
133  }
134  if ( sy == syntax_undefined ) {
135  pips_internal_error("wrong expression");
136  }
137 
138  if ( normalized_linear_p(no) ) {
139  comp = normalized_to_polynome(no, precond, effects_list,
140  keep_symbols, maximize);
141  }
142  else {
143  comp = syntax_to_polynome(sy, precond, effects_list, keep_symbols, maximize);
144  }
145 
146  if ( complexity_unknown_p(comp) ) {
147  pips_internal_error("Better unknown value name generation required!");
148  /*
149  return(make_single_var_complexity(1.0,UNKNOWN_RANGE));
150  */
151  return complexity_undefined;
152  }
153 
154  /* The following line is merely for debugging */
155 
156  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
157  fprintf(stderr, "expr->pnome ");
158  complexity_fprint(stderr, comp, true, true);
159  }
160 
161  trace_off();
162  return (comp);
163 }
164 ␌
165 /* 1st element of expression */
166 complexity syntax_to_polynome(synt, precond, effects_list, keep_symbols, maximize)
167 syntax synt;
168 transformer precond;
169 list effects_list;
170 bool keep_symbols;
171 int maximize;
172 {
173  complexity comp = make_zero_complexity();// complexity_undefined;
174 
175  trace_on("syntax -> pnome");
176 
177  switch (syntax_tag(synt)) {
178  case is_syntax_reference:
180  precond, effects_list, keep_symbols, maximize);
181  break;
182  case is_syntax_range:
183  comp = range_to_polynome(syntax_range(synt),
184  precond, effects_list, keep_symbols, maximize);
185  break;
186  case is_syntax_call:
187  comp = call_to_polynome(syntax_call(synt),
188  precond, effects_list, keep_symbols, maximize);
189  break;
190  case is_syntax_cast:
191  comp = cast_to_polynome(syntax_cast(synt),
192  precond, effects_list, keep_symbols, maximize);
193  break;
195  case is_syntax_subscript:
197  case is_syntax_va_arg:
198  /* This expression cannot be used within a polynomial, just like
199  an array reference */
200  comp = make_zero_complexity();
201  break;
202  default:
203  pips_internal_error("Unexpected tag:%d\n", syntax_tag(synt));
204  }
205 
206  trace_off();
207  return (comp);
208 }
209 
210 /* 2nd element of expression */
211 complexity normalized_to_polynome(no, precond, effects_list, keep_symbols, maximize)
212 normalized no;
213 transformer precond;
214 list effects_list;
215 bool keep_symbols;
216 int maximize;
217 {
219 
220  trace_on("normalized -> pnome");
221 
222  if (normalized_linear_p(no) ) {
223  Pvecteur pvect = (Pvecteur)normalized_linear(no);
224  comp = pvecteur_to_polynome(pvect, precond, effects_list, keep_symbols, maximize);
225  }
226  else
227  pips_internal_error("vecteur undefined");
228 
229  trace_off();
230  return(comp);
231 }
232 ␌
233 /* The only element available of normalized */
234 complexity pvecteur_to_polynome(pvect, precond, effects_list, keep_symbols, maximize)
235 Pvecteur pvect;
236 transformer precond;
237 list effects_list;
238 bool keep_symbols;
239 int maximize;
240 {
242  Ppolynome ppvar;
243  Pvecteur pv;
244  Variable var;
245  Value val;
246  bool we_must_evaluate;
247 /* bool must_be_written = false; */
248 
249  trace_on("pvecteur -> pnome maximize is %d", maximize);
250 
251  if ( get_bool_property("COMPLEXITY_INTERMEDIATES") ) {
252  fprintf(stderr, "expr->pnome: pvecteur = ");
253  vect_fprint(stderr, pvect, variable_name);
254  }
255 
256  for(pv=pvect; !VECTEUR_NUL_P(pv); pv = pv->succ) {
257  var = vect_first_var(pv);
258  val = vect_coeff(var, pv);
259 
260  we_must_evaluate =
261  (var != TCST) &&
263  (char *)module_local_name((entity)var)))
264  : true);
265 /*
266  must_be_written = is_must_be_written_var(effects_list,
267  variable_local_name(var));
268 
269  if ( get_debug_level() >= 3 ) {
270  fprintf(stderr, "Must be written var %s\n", variable_local_name(var) );
271  }
272 */
273 /*
274  if (we_must_evaluate && must_be_written) {
275 */
276  if (we_must_evaluate && get_bool_property("COMPLEXITY_EARLY_EVALUATION")) {
277  complexity ctmp;
278  ctmp = evaluate_var_to_complexity((entity)var, precond, effects_list, maximize);
279  /* should be multiplied by "val" here */
281  complexity_add(&comp, ctmp);
282  }
283  else {
284  /* We keep this symbol (including TCST) in the polynome */
285  Value exp = VALUE_ONE;
286  float coeff = VALUE_TO_FLOAT(val);
287 
288  ppvar = make_polynome(coeff, var, exp);
289  if (complexity_zero_p(comp))
290  comp = polynome_to_new_complexity(ppvar);
291  else
292  complexity_polynome_add(&comp, ppvar);
294  }
295  }
296 
297  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
298  fprintf(stderr, "Pvecteur evaluation = ");
299  prc(comp);
300  }
301 
302  trace_off();
303  return (comp);
304 }
305 ␌
306 /* First element of the "syntax" domain */
308  transformer precond,
309  list effects_list,
310  bool keep_symbols,
311  int maximize)
312 {
314  bool we_must_evaluate;
315 /* bool must_be_written; */
317 
318  trace_on("reference -> pnome");
319 
320  if ( reference_indices(ref) == NIL) {
321  /* if it's an array: let us fail */
322  we_must_evaluate = (keep_symbols ?
324  (char *)module_local_name((entity)var) ):
325  true);
326 /*
327  must_be_written = is_must_be_written_var(effects_list, var);
328 
329  if ( get_debug_level() >= 3 ) {
330  fprintf(stderr, "Must be written var %s\n", noms_var(var) );
331  }
332 */
333 /*
334  if (we_must_evaluate && must_be_written) {
335 */
336  if (we_must_evaluate && get_bool_property("COMPLEXITY_EARLY_EVALUATION")) {
337  comp = evaluate_var_to_complexity((entity)var, precond, effects_list, maximize);
338  }
339  else { /* We keep this symbol in the polynome */
340  Ppolynome pp = make_polynome((float) 1, (Variable) var, VALUE_ONE);
341  comp = polynome_to_new_complexity(pp);
343  polynome_rm(&pp);
344  }
345  }
346 
347  trace_off();
348  return(comp);
349 }
350 
351 /* 2nd element of syntax */
353  transformer precond __attribute__ ((__unused__)),
354  list effects_list __attribute__ ((__unused__)),
355  bool keep_symbols __attribute__ ((__unused__)),
356  int maximize __attribute__ ((__unused__)))
357 {
359 
360  trace_on("range -> pnome");
361 
362  pips_internal_error("Don't you know");
363 
364  trace_off();
365  return(comp);
366 }
367 ␌
368 /* 3rd element of syntax */
369 complexity call_to_polynome(call_instr, precond, effects_list, keep_symbols, maximize)
370 call call_instr;
371 transformer precond;
372 list effects_list;
373 bool keep_symbols;
374 int maximize;
375 {
376  entity f = call_function(call_instr);
377  const char *name = module_local_name(f);
378  list args = call_arguments(call_instr);
379  type t = entity_type(f);
380  value v = entity_initial(f);
382 
383  trace_on("CALL '%s' -> pnome", name);
384 
385  if (!type_functional_p(t) ||
387  pips_internal_error("'%s' isn't an expected entity (type %d, value %d)",
388  type_tag(t), value_tag(v), name);
389 
390  switch (value_tag(v)) {
391  case is_value_code:
392  /* For the moment, we don't want to evaluate the complexity of the */
393  break; /* function defined by the users */
394  case is_value_constant:
396  break;
397  case is_value_intrinsic:
399  comp = plus_op_handler(args, precond, effects_list, keep_symbols, maximize);
400  else if (same_string_p(name, MINUS_OPERATOR_NAME))
401  comp = minus_op_handler(args, precond, effects_list, keep_symbols, maximize);
402  else if (same_string_p(name, MULTIPLY_OPERATOR_NAME))
403  comp = multiply_op_handler(args, precond, effects_list, keep_symbols, maximize);
404  else if (same_string_p(name, DIVIDE_OPERATOR_NAME))
405  comp = divide_op_handler(args, precond, effects_list, keep_symbols, maximize);
406  else if (same_string_p(name, POWER_OPERATOR_NAME))
407  comp = power_op_handler(args, precond, effects_list, keep_symbols, maximize);
409  comp = unary_minus_op_handler(args, precond, effects_list, keep_symbols, maximize);
410  else if (same_string_p(name, FIELD_OPERATOR_NAME))
411  comp = field_op_handler(args, precond, effects_list, keep_symbols, maximize);
412  else
413  pips_user_warning("operator '%s' skipped\n",name);
414  break;
415 
416  default:
417  pips_internal_error("not handled case");
418  }
419 
420  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
421  fprintf(stderr, "call->pnome '%s': ", name);
422  complexity_fprint(stderr, comp, true, true);
423  }
424 
425  trace_off();
426  return (comp);
427 }
428 /* 4th element of syntax : Molka Becher */
429 complexity cast_to_polynome(cast_instr, precond, effects_list, keep_symbols, maximize)
430 cast cast_instr;
431 transformer precond;
432 list effects_list;
433 bool keep_symbols;
434 int maximize;
435 {
436  expression exp = cast_expression(cast_instr);
437 
438  trace_on("CAST");
439 
440  complexity comp = expression_to_complexity_polynome(exp, precond, effects_list,
441  keep_symbols, maximize);
442 
443  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
444  fprintf(stderr, "cast->pnome");
445  complexity_fprint(stderr, comp, true, true);
446  }
447 
448  trace_off();
449  return (comp);
450 }
451 ␌
452 complexity plus_op_handler(args, precond, effects_list, keep_symbols, maximize)
453 list args;
454 transformer precond;
455 list effects_list;
456 bool keep_symbols;
457 int maximize;
458 {
460  precond, effects_list, keep_symbols,
461  maximize);
463  precond, effects_list, keep_symbols,
464  maximize);
465 
466  complexity_add(&c1, c2);
467  complexity_rm(&c2);
468 
469  return (c1);
470 }
471 
472 complexity minus_op_handler(args, precond, effects_list, keep_symbols, maximize)
473 list args;
474 transformer precond;
475 list effects_list;
476 bool keep_symbols;
477 int maximize;
478 {
480  precond, effects_list, keep_symbols,
481  maximize);
483  precond, effects_list, keep_symbols,
484  -maximize);
485 
486  complexity_sub(&c1, c2);
487  complexity_rm(&c2);
488 
489  return (c1);
490 }
491 
492 complexity multiply_op_handler(args, precond, effects_list, keep_symbols, maximize)
493 list args;
494 transformer precond;
495 list effects_list;
496 bool keep_symbols;
497 int maximize;
498 {
500  precond, effects_list, keep_symbols,
501  maximize);
503  precond, effects_list, keep_symbols,
504  maximize);
505 
506  complexity_mult(&c1, c2);
507  complexity_rm(&c2);
508 
509  return (c1);
510 }
511 
513  list effects_list, bool keep_symbols, int maximize) {
515  precond, effects_list, keep_symbols,
516  maximize);
518  precond, effects_list, keep_symbols,
519  maximize);
520 
521  complexity_add(&c1, c2);
522  complexity_rm(&c2);
523 
524  return (c1);
525 }
526 
527 complexity unary_minus_op_handler(args, precond, effects_list, keep_symbols, maximize)
528 list args;
529 transformer precond;
530 list effects_list;
531 bool keep_symbols;
532 int maximize;
533 {
535  precond, effects_list, keep_symbols,
536  -maximize);
538 
539  complexity_sub(&c1, c2);
540  complexity_rm(&c2);
541 
542  return (c1);
543 }
544 
545 complexity unary_plus_op_handler(args, precond, effects_list, keep_symbols, maximize)
546 list args;
547 transformer precond;
548 list effects_list;
549 bool keep_symbols;
550 int maximize;
551 {
553  precond, effects_list, keep_symbols,
554  maximize);
555 
556  return (c1);
557 }
558 
559 
560 complexity divide_op_handler(args, precond, effects_list, keep_symbols, maximize)
561 list args;
562 transformer precond;
563 list effects_list;
564 bool keep_symbols;
565 int maximize;
566 {
567  float denominateur;
569  precond, effects_list, keep_symbols,
570  maximize);
572  precond, effects_list, DONT_KEEP_SYMBOLS,
573  -maximize);
574  if (complexity_constant_p(c2)) {
575  denominateur = complexity_TCST(c2);
576  if (denominateur == 0)
577  user_error("divide_op_handler", "division by zero\n");
578  else
579  complexity_mult(&c1, make_constant_complexity(1.0/denominateur));
580  }
581  else {
582  complexity_rm(&c1);
583  }
584 
585  complexity_rm(&c2);
586  return (c1);
587 }
588 
589 complexity power_op_handler(args, precond, effects_list, keep_symbols, maximize)
590 list args;
591 transformer precond;
592 list effects_list;
593 bool keep_symbols;
594 int maximize;
595 {
596  float power;
598  precond, effects_list, keep_symbols,
599  maximize);
601  precond, effects_list, DONT_KEEP_SYMBOLS,
602  maximize);
603 
604  if (complexity_constant_p(c2)) {
605  power = complexity_TCST(c2);
606  complexity_rm(&c2);
607  if (power == (int) power) {
609  (int) power);
610  Ppolynome pt = complexity_eval(c1);
611 
612  /* polynome_rm(&(complexity_eval(c1))); */
613  polynome_rm(&pt);
614  /* (Ppolynome) complexity_eval(c1) = pp; */
616  return (c1);
617  }
618  }
619  else
620  complexity_rm(&c2);
621 
622  complexity_rm(&c1);
623  return (make_zero_complexity());
624 }
625 ␌
626 /* complexity evaluate_var_to_complexity(entity var,
627  * transformer precond,
628  * list effects_list,
629  * int maximize)
630  * Return, packed in a complexity, the exact value of variable var
631  * or its max if (maximize==MAXIMUM_VALUE), or its min, according to
632  * preconditions passed in precond.
633  *
634  * If nothing is found,
635  * the complexity returned is UNKNOWN_VARIABLE, with a
636  * varcount_unknown set to 1. The variable statistics are up to
637  * date in the new complexity returned, in any case.
638  *
639  * FI: I do not understand this algorithm as it does not try the
640  * easiest substitution, using any equation in precond that uses var
641  * with a non-zero coefficient.
642  */
644  transformer precond,
645  list effects_list __attribute__ ((__unused__)),
646  int maximize)
647 {
648  predicate pred = transformer_relation(precond);
649  Psysteme psyst = (Psysteme) predicate_system(pred);
650  Value min = VALUE_MAX;
651  Value max = VALUE_MIN;
652  bool faisable;
654 
655 #define maxint_p(i) ((i) == INT_MAX)
656 #define minint_p(i) ((i) == (INT_MIN))
657 
658  trace_on("variable %s -> pnome, maximize %d ", entity_name(var), maximize);
659 
660  /* This is the only case that we use the precondition */
661  if (entity_integer_scalar_p(var) &&
662  precond != transformer_undefined &&
663  pred != predicate_undefined &&
664  !SC_UNDEFINED_P(psyst) ) {
665  Psysteme ps = sc_dup(psyst);
666  Psysteme ps1;
667  Pvecteur pv;
668  char *precondition_to_string();
669 
670  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
671  sc_fprint(stderr, ps, (get_variable_name_t) noms_var);
672  }
673 
674  for ( pv=ps->base; !VECTEUR_NUL_P(pv); pv=pv->succ) {
675  if ( var_of(pv) != (Variable)var ) {
677  (char *)module_local_name((entity)var_of(pv)));
678 
679  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
680  fprintf(stderr,"var_of is %s -- variable is %s --bool is %d\n",
682  module_local_name((entity)(var) ), b);
683  }
684 
685  if (!b) {
686  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
687  fprintf(stderr, "in projection %s\n",noms_var((entity)var_of(pv)));
688  }
689  ps = sc_projection(ps,var_of(pv));
690  }
691  }
692  }
693 
694  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
695  fprintf(stderr, "Prec=%s", precondition_to_string(precond));
696  sc_fprint(stderr, ps, (get_variable_name_t) noms_var);
697 
698  if ( !SC_UNDEFINED_P(ps) )
699  fprintf(stderr,"ps OK\n");
700  else
701  fprintf(stderr,"ps is NULL\n");
702  }
703 
704  /* added by LZ 18/02/92 */
706  (char *) var) ) {
707  if (get_bool_property("COMPLEXITY_INTERMEDIATES"))
708  fprintf(stderr,"Don't evaluate %s------\n", noms_var(var));
709  return(make_single_var_complexity(1.0, (Variable)var));
710  }
711 
712  ps1 = sc_dup(ps);
713  faisable = sc_minmax_of_variable(ps1, (Variable) var,
714  &min, &max);
715 
716  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
717  fprintf(stderr," faisable is %d\n",faisable);
718  fprintf(stderr,"Variable %s -- ", noms_var(var));
719  fprint_string_Value(stderr, "min is ", min);
720  fprint_string_Value(stderr, ", max is ", max);
721  fprintf(stderr,", maximize is %d\n", maximize);
722  }
723 
724  if ( faisable && (value_notmin_p(min) || value_notmax_p(max)) )
725  {
726 
727  if ( value_notmax_p(max) && TAKE_MAX(maximize) ) {
728  comp = simplify_sc_to_complexity(ps,(Variable)var);
729  if ( complexity_zero_p(comp) )
732  }
733  else if ( value_notmin_p(min) && TAKE_MIN(maximize) ) {
734  comp = simplify_sc_to_complexity(ps,(Variable)var);
735  if ( complexity_zero_p(comp) )
738  }
739 
740  /* for the inner loop 28/06/91 example p.f */
741  else if ( value_max_p(max) && TAKE_MAX(maximize) ) {
742  comp = simplify_sc_to_complexity(ps,(Variable)var);
743  if ( complexity_zero_p(comp) )
746  }
747  else if ( value_min_p(min) && TAKE_MIN(maximize) ) {
748  comp = simplify_sc_to_complexity(ps,(Variable)var);
749  if ( complexity_zero_p(comp) )
752  }
753 
754  else if (min == max) {
757  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
758  fprintf(stderr,"value is ");
759  fprint_Value(stderr, val_of((ps1->egalites)->vecteur));
760  fprintf(stderr, "\n");
761  fprint_string_Value(stderr,"max = min = ",max);
762  fprintf(stderr, "\n");
763  }
764  }
765  else if ( value_notmin_p(min) && value_notmax_p(max) ) {
766  comp = simplify_sc_to_complexity(ps,(Variable)var);
767  }
768  else {
769  comp = make_single_var_complexity( 1.0, (Variable) var);
771  }
772  }
773  else if ( faisable ) {
774  comp = simplify_sc_to_complexity(ps,(Variable)var);
775  }
776  }
777  else {
778  comp = make_single_var_complexity(1.0, (Variable) var);
780  }
781 
782  trace_off();
783  return(comp);
784 }
785 ␌
786 /* This function is recently added by L.Zhou June 5, 91
787  * simplify_sc_to_complexity(Psysteme ps, Variable var)
788  * It looks for the egality formula containing (Variable)var
789  * in the system (Psysteme)ps.
790  * If ps->egalites is NULL, zero complexity is returned.
791  * The rest of the variable in that formula should be the known variable
792  * for example: formal parameter(s), inductible variable, etc.
793  * EX: M1 - M2 = 1 where M1 is formal parameter
794  * where M2 is an inductible variable
795  * This function returns M2 = M1 - 1 packed in the polynomial of the complexity
796  * the statistics of this complexity should be all zero.
797  */
799 Psysteme ps;
800 Variable var;
801 {
803  Value var_coeff=VALUE_ONE;
804 
805  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
806  sc_fprint(stderr, ps, (get_variable_name_t) noms_var);
807  }
808 
809  if ( !SC_UNDEFINED_P(ps) && !CONTRAINTE_UNDEFINED_P(ps->egalites) ) {
810  Pvecteur v = (ps->egalites)->vecteur;
811 
812  for ( ; !VECTEUR_NUL_P(v); v=v->succ ) {
813  if ( v->var != TCST ) {
814  if ( v->var != (Variable)var ) {
816  (VALUE_TO_FLOAT(v->val),v->var);
817  complexity_add(&comp, c);
818  complexity_rm(&c);
819  }
820  else {
821  var_coeff = value_uminus(v->val);
822  }
823  }
824  else {
826  (VALUE_TO_FLOAT(v->val));
827  complexity_add(&comp, c);
828  complexity_rm(&c);
829  }
830  }
831  }
832  else {
834  (char *)module_local_name((entity)var));
835 
836  if ( b )
837  comp = make_single_var_complexity(1.0, (Variable)var);
838  else
840  }
841 
842  complexity_scalar_mult(&comp,1.0/VALUE_TO_FLOAT(var_coeff));
844 
845  return (comp);
846 }
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
language make_language_fortran(void)
Definition: ri.c:1250
basic make_basic_int(intptr_t _field_)
Definition: ri.c:158
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
#define value_notmin_p(val)
#define value_uminus(val)
unary operators on values
#define VALUE_MIN
#define value_min_p(val)
#define value_notmax_p(val)
int Value
#define VALUE_TO_FLOAT(val)
#define VALUE_MAX
#define value_max_p(val)
#define VALUE_ONE
void fprint_Value(FILE *, Value)
Definition: io.c:42
void fprint_string_Value(FILE *, char *, Value)
Definition: io.c:47
complexity divide_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
hash_table hash_complexity_parameters
Definition: comp_scan.c:58
complexity make_complexity_unknown(const char *name)
builds a new unknown complexity attached to a virtual package
complexity simplify_sc_to_complexity(Psysteme ps, Variable var)
This function is recently added by L.Zhou June 5, 91 simplify_sc_to_complexity(Psysteme ps,...
complexity plus_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
hash_table hash_callee_to_complexity
comp_expr_to_pnome.c
Definition: comp_scan.c:57
complexity reference_to_polynome(reference ref, transformer precond, list effects_list, bool keep_symbols, int maximize)
First element of the "syntax" domain.
complexity call_to_polynome(call call_instr, transformer precond, list effects_list, bool keep_symbols, int maximize)
3rd element of syntax
complexity minus_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
char * noms_var(entity e)
comp_expr_to_pnome.c
complexity pvecteur_to_polynome(Pvecteur pvect, transformer precond, list effects_list, bool keep_symbols, int maximize)
The only element available of normalized.
complexity multiply_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
complexity normalized_to_polynome(normalized no, transformer precond, list effects_list, bool keep_symbols, int maximize)
2nd element of expression
complexity unary_minus_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
complexity cast_to_polynome(cast cast_instr, transformer precond, list effects_list, bool keep_symbols, int maximize)
4th element of syntax : Molka Becher
complexity field_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
complexity evaluate_var_to_complexity(entity var, transformer precond, list effects_list __attribute__((__unused__)), int maximize)
complexity evaluate_var_to_complexity(entity var, transformer precond, list effects_list,...
complexity unary_plus_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
complexity syntax_to_polynome(syntax synt, transformer precond, list effects_list, bool keep_symbols, int maximize)
1st element of expression
complexity power_op_handler(list args, transformer precond, list effects_list, bool keep_symbols, int maximize)
complexity expression_to_complexity_polynome(expression expr, transformer precond, list effects_list, bool keep_symbols, int maximize)
Entry point routine of this file:
complexity range_to_polynome(range rg __attribute__((__unused__)), transformer precond __attribute__((__unused__)), list effects_list __attribute__((__unused__)), bool keep_symbols __attribute__((__unused__)), int maximize __attribute__((__unused__)))
2nd element of syntax
void complexity_add(complexity *pcomp1, complexity comp2)
void complexity_add(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 + comp2; !...
Definition: comp_math.c:372
void complexity_scalar_mult(complexity *pcomp, float f)
multiply a complexity by a floating-point number.
Definition: comp_math.c:303
void complexity_polynome_add(complexity *pcomp, Ppolynome pp)
Definition: comp_math.c:463
Ppolynome complexity_polynome(complexity comp)
Because complexity is composed of two elements, we use this function to get the first element : polyn...
Definition: comp_math.c:506
float complexity_TCST(complexity comp)
return the constant term of comp.
Definition: comp_math.c:288
void complexity_float_add(complexity *pcomp, float f)
Add a floating point digit to the complexity May 3, 91.
Definition: comp_math.c:480
bool complexity_constant_p(complexity comp)
true if comp is constant.
Definition: comp_math.c:256
complexity make_zero_complexity()
make a zero complexity "0.0000 * TCST" with null statistics
Definition: comp_math.c:238
complexity make_constant_complexity(float f)
make a constant complexity "f * TCST" with null statistics
Definition: comp_math.c:231
void complexity_mult(complexity *pcomp1, complexity comp2)
void complexity_mult(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 * comp2; !...
Definition: comp_math.c:418
bool complexity_zero_p(complexity comp)
zero complexity check.
Definition: comp_math.c:244
void complexity_sub(complexity *pcomp1, complexity comp2)
void complexity_sub(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 - comp2; !...
Definition: comp_math.c:394
complexity polynome_to_new_complexity(Ppolynome pp)
Create a complexity equal to Ppolynome pp with null statistics.
Definition: comp_math.c:200
bool complexity_unknown_p(complexity comp)
true if comp is unknown.
Definition: comp_math.c:269
complexity make_single_var_complexity(float f, Variable var)
make a complexity "f * var" with null statistics
Definition: comp_math.c:220
void complexity_rm(complexity *pcomp)
remove complexity comp
Definition: comp_util.c:164
void trace_on(char *fmt,...)
Definition: comp_util.c:684
void complexity_fprint(FILE *fd, complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:217
float constant_entity_to_float(entity e)
Return if possible the value of e in a float.
Definition: comp_util.c:664
void trace_off()
"trace off"
Definition: comp_util.c:714
void prc(complexity comp)
Definition: comp_util.c:233
#define TAKE_MAX(m)
#define DONT_KEEP_SYMBOLS
#define hash_contains_user_var_p(htp, key)
#define hash_contains_p(htp, key)
#define UNKNOWN_VARIABLE_NAME
pseudo-variable for unknown variables
#define COMPLEXITY_PACKAGE_NAME
#define TAKE_MIN(m)
#define complexity_eval(x)
Definition: complexity_ri.h:92
#define varcount_guessed(x)
#define complexity_eval_(x)
Definition: complexity_ri.h:91
#define newgen_Ppolynome(p)
Definition: complexity_ri.h:19
#define complexity_undefined
Definition: complexity_ri.h:66
#define complexity_varcount(x)
Definition: complexity_ri.h:94
#define varcount_symbolic(x)
#define varcount_unknown(x)
#define varcount_bounded(x)
#define CONTRAINTE_UNDEFINED_P(c)
#define min(a, b)
#define max(a, b)
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
static char * package
The package name in which functions will be defined.
Definition: genLisp.c:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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
void vect_fprint(FILE *f, Pvecteur v, get_variable_name_t variable_name)
void vect_fprint(FILE * f, Pvecteur v, char * (*variable_name)()): impression d'un vecteur creux v su...
Definition: io.c:124
#define pips_user_warning
Definition: misc-local.h:146
#define pips_internal_error
Definition: misc-local.h:149
#define user_error(fn,...)
Definition: misc-local.h:265
#define same_string_p(s1, s2)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
Ppolynome make_polynome(float coeff, Variable var, Value expo)
Ppolynome make_polynome(float coeff, Variable var, Value expo) PRIVATE allocates space for,...
Definition: pnome-alloc.c:100
void polynome_rm(Ppolynome *ppp)
void polynome_rm(Ppolynome* ppp) frees space occupied by polynomial *ppp returns *ppp pointing to POL...
Definition: pnome-alloc.c:170
Ppolynome polynome_power_n(Ppolynome pp, int n)
Ppolynome polynome_power_n(Ppolynome pp, int n) returns pp ^ n (n>=0)
Definition: pnome-scal.c:121
Variable vect_first_var(Pvecteur pvec)
PRIVATE: marquage du couple var_val comme visite par remplacement de var par -var dans le couple (OBS...
Definition: private.c:227
#define POWER_OPERATOR_NAME
#define MINUS_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define DEFAULT_INTEGER_TYPE_SIZE
#define NORMALIZE_EXPRESSION(e)
#define FIELD_OPERATOR_NAME
Definition: ri-util-local.h:91
#define DIVIDE_OPERATOR_NAME
#define UNARY_MINUS_OPERATOR_NAME
#define MULTIPLY_OPERATOR_NAME
entity make_empty_program(const char *name, language l)
Definition: entity.c:261
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
entity make_new_scalar_variable_with_prefix(const char *, entity, basic)
Create a new scalar variable of type b in the given module.
Definition: variable.c:592
bool entity_integer_scalar_p(entity)
for variables (like I), not constants (like 1)! use integer_constant_p() for constants
Definition: variable.c:1130
#define type_functional_p(x)
Definition: ri.h:2950
#define value_tag(x)
Definition: ri.h:3064
#define value_code_p(x)
Definition: ri.h:3065
#define transformer_undefined
Definition: ri.h:2847
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define normalized_linear_p(x)
Definition: ri.h:1779
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define value_intrinsic_p(x)
Definition: ri.h:3074
#define type_tag(x)
Definition: ri.h:2940
#define syntax_cast(x)
Definition: ri.h:2739
@ is_value_intrinsic
Definition: ri.h:3034
@ is_value_constant
Definition: ri.h:3033
@ is_value_code
Definition: ri.h:3031
#define syntax_range(x)
Definition: ri.h:2733
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_application
Definition: ri.h:2697
@ is_syntax_cast
Definition: ri.h:2694
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_va_arg
Definition: ri.h:2698
@ is_syntax_reference
Definition: ri.h:2691
@ is_syntax_sizeofexpression
Definition: ri.h:2695
@ is_syntax_subscript
Definition: ri.h:2696
#define value_constant_p(x)
Definition: ri.h:3071
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define cast_expression(x)
Definition: ri.h:747
#define entity_undefined_p(x)
Definition: ri.h:2762
#define expression_undefined
Definition: ri.h:1223
#define entity_name(x)
Definition: ri.h:2790
#define transformer_relation(x)
Definition: ri.h:2873
#define predicate_undefined
Definition: ri.h:2046
#define reference_indices(x)
Definition: ri.h:2328
#define syntax_call(x)
Definition: ri.h:2736
#define syntax_undefined
Definition: ri.h:2676
#define call_arguments(x)
Definition: ri.h:711
#define entity_type(x)
Definition: ri.h:2792
#define normalized_linear(x)
Definition: ri.h:1781
#define expression_syntax(x)
Definition: ri.h:1247
#define predicate_system(x)
Definition: ri.h:2069
#define entity_initial(x)
Definition: ri.h:2796
struct Ssysteme * Psysteme
Psysteme sc_dup(Psysteme ps)
Psysteme sc_dup(Psysteme ps): should becomes a link.
Definition: sc_alloc.c:176
bool sc_minmax_of_variable(Psysteme ps, Variable var, Value *pmin, Value *pmax)
void sc_minmax_of_variable(Psysteme ps, Variable var, Value *pmin, *pmax): examine un systeme pour tr...
Definition: sc_eval.c:143
void sc_fprint(FILE *fp, Psysteme ps, get_variable_name_t nom_var)
void sc_fprint(FILE * f, Psysteme ps, char * (*nom_var)()): cette fonction imprime dans le fichier po...
Definition: sc_io.c:220
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * variable_name(Variable v)
polynome_ri.c
Definition: polynome_ri.c:73
Pcontrainte egalites
Definition: sc-local.h:70
Pbase base
Definition: sc-local.h:75
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
Value val
Definition: vecteur-local.h:91
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
string precondition_to_string(transformer pre)
Definition: prettyprint.c:58
const char * external_value_name(entity)
Definition: value.c:753
bool entity_has_values_p(entity)
This function could be made more robust by checking the storage of e.
Definition: value.c:911
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.
#define val_of(varval)
char *(* get_variable_name_t)(Variable)
Definition: vecteur-local.h:62
struct Svecteur * Pvecteur
#define VECTEUR_NUL_P(v)
void * Variable
arithmetique is a requirement for vecteur, but I do not want to inforce it in all pips files....
Definition: vecteur-local.h:60
#define var_of(varval)
Value vect_coeff(Variable var, Pvecteur vect)
Variable vect_coeff(Variable var, Pvecteur vect): coefficient de coordonnee var du vecteur vect —> So...
Definition: unaires.c:228