PIPS
comp_math.c File Reference
#include <stdio.h>
#include <string.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "effects.h"
#include "complexity_ri.h"
#include "ri-util.h"
#include "effects-util.h"
#include "misc.h"
#include "matrice.h"
#include "properties.h"
#include "complexity.h"
+ Include dependency graph for comp_math.c:

Go to the source code of this file.

Functions

complexity complexity_sigma (complexity comp, Variable index, complexity clower, complexity cupper)
 comp_math.c More...
 
complexity complexity_var_subst (complexity comp, Variable var, complexity compsubst)
 complexity complexity_var_subst(comp, var, compsubst) replaces every occurrence of variable var in complexity comp by the polynomial of complexity compsubst. More...
 
complexity polynome_to_new_complexity (Ppolynome pp)
 Create a complexity equal to Ppolynome pp with null statistics. More...
 
complexity make_single_var_complexity (float f, Variable var)
 make a complexity "f * var" with null statistics More...
 
complexity make_constant_complexity (float f)
 make a constant complexity "f * TCST" with null statistics More...
 
complexity make_zero_complexity ()
 make a zero complexity "0.0000 * TCST" with null statistics More...
 
bool complexity_zero_p (complexity comp)
 zero complexity check. More...
 
bool complexity_constant_p (complexity comp)
 true if comp is constant. More...
 
bool complexity_unknown_p (complexity comp)
 true if comp is unknown. More...
 
float complexity_TCST (complexity comp)
 return the constant term of comp. More...
 
void complexity_scalar_mult (complexity *pcomp, float f)
 multiply a complexity by a floating-point number. More...
 
void complexity_stats_add (complexity *pcomp1, complexity comp2)
 Add comp2's statistics to *pcomp1's comp2 keeps unchanged. More...
 
void complexity_add (complexity *pcomp1, complexity comp2)
 void complexity_add(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 + comp2; !usage: complexity_add(&comp1, comp2); comp2 keeps unchanged More...
 
void complexity_sub (complexity *pcomp1, complexity comp2)
 void complexity_sub(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 - comp2; !usage: complexity_sub(&comp1, comp2); comp2 keeps unchanged More...
 
void complexity_mult (complexity *pcomp1, complexity comp2)
 void complexity_mult(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 * comp2; !usage: complexity_mult(&comp1, comp2); More...
 
void complexity_div (complexity *pcomp1, complexity comp2)
 void complexity_div(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 / comp2; !usage: complexity_div(&comp1, comp2); More...
 
void complexity_polynome_add (complexity *pcomp, Ppolynome pp)
 
void complexity_float_add (complexity *pcomp, float f)
 Add a floating point digit to the complexity May 3, 91. More...
 
Ppolynome complexity_polynome (complexity comp)
 Because complexity is composed of two elements, we use this function to get the first element : polynome Usage : complexity_polynome(complexity comp) you will get a pointer to the polynome May 3, 91 lz. More...
 
complexity replace_formal_parameters_by_real_ones (complexity comp, entity mod, list args, transformer precond, list effects_list)
 transform formal params into real ones (args) in complexity comp More...
 
list list_ith_element (list thelist, int ith)
 return a pointer to the (i)th element of the list if i = 1, the pointer doesn't change at all. More...
 

Function Documentation

◆ complexity_add()

void complexity_add ( complexity pcomp1,
complexity  comp2 
)

void complexity_add(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 + comp2; !usage: complexity_add(&comp1, comp2); comp2 keeps unchanged

Parameters
pcomp1comp1
comp2omp2

Definition at line 372 of file comp_math.c.

374 {
375  if ( COMPLEXITY_UNDEFINED_P(comp2) || COMPLEXITY_UNDEFINED_P(*pcomp1) )
376  pips_internal_error("complexity undefined");
377 
378  if ( complexity_zero_p(*pcomp1) ) {
379  *pcomp1 = complexity_dup(comp2);
380  }
381  else if ( !complexity_zero_p(comp2) ) {
382  complexity_eval_(*pcomp1) =
384  complexity_eval(comp2)));
385  complexity_stats_add(pcomp1, comp2);
386  }
387 }
void complexity_stats_add(complexity *pcomp1, complexity comp2)
Add comp2's statistics to *pcomp1's comp2 keeps unchanged.
Definition: comp_math.c:323
bool complexity_zero_p(complexity comp)
zero complexity check.
Definition: comp_math.c:244
complexity complexity_dup(complexity comp)
duplicates complexity comp
Definition: comp_util.c:131
#define COMPLEXITY_UNDEFINED_P(c)
#define complexity_eval(x)
Definition: complexity_ri.h:92
#define complexity_eval_(x)
Definition: complexity_ri.h:91
#define newgen_Ppolynome(p)
Definition: complexity_ri.h:19
#define pips_internal_error
Definition: misc-local.h:149
Ppolynome polynome_addition(Ppolynome pp, Ppolynome pp2)
Ppolynome polynome_addition(Ppolynome pp, Ppolynome pp2) pp = pp + pp2.
Definition: pnome-bin.c:195

References complexity_dup(), complexity_eval, complexity_eval_, complexity_stats_add(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), newgen_Ppolynome, pips_internal_error, and polynome_addition().

Referenced by arguments_to_complexity(), block_to_complexity(), field_op_handler(), indices_to_complexity(), new_block_to_complexity(), plus_op_handler(), pvecteur_to_polynome(), range_to_complexity(), reference_to_complexity(), simplify_sc_to_complexity(), subscript_to_complexity(), syntax_to_complexity(), test_to_complexity(), unstructured_to_complexity(), and whileloop_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_constant_p()

bool complexity_constant_p ( complexity  comp)

true if comp is constant.

Abort if undefined

Parameters
compomp

Definition at line 256 of file comp_math.c.

258 {
259  if ( COMPLEXITY_UNDEFINED_P(comp) )
260  pips_internal_error("undefined complexity");
261 
262  if ( complexity_zero_p(comp) )
263  return (true);
264  else
265  return (polynome_constant_p(complexity_eval(comp)));
266 }
bool polynome_constant_p(Ppolynome pp)
bool polynome_constant_p(Ppolynome pp) return true if pp is a constant polynomial (including null pol...
Definition: pnome-reduc.c:180

References complexity_eval, COMPLEXITY_UNDEFINED_P, complexity_zero_p(), pips_internal_error, and polynome_constant_p().

Referenced by divide_op_handler(), loop_to_complexity(), and power_op_handler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_div()

void complexity_div ( complexity pcomp1,
complexity  comp2 
)

void complexity_div(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 / comp2; !usage: complexity_div(&comp1, comp2);

polynome_rm(&(complexity_eval(*pcomp1)));

Parameters
pcomp1comp1
comp2omp2

Definition at line 445 of file comp_math.c.

447 {
448  if ( COMPLEXITY_UNDEFINED_P(comp2) || COMPLEXITY_UNDEFINED_P(*pcomp1) )
449  pips_internal_error("complexity undefined");
450 
451  if ( complexity_zero_p(comp2) ) {
452  pips_internal_error("complexity divider is zero");
453  }
454  else if ( !complexity_zero_p(*pcomp1) ) {
455  Ppolynome ppdiv;
456  ppdiv = polynome_div(complexity_eval(*pcomp1), complexity_eval(comp2));
457 /* polynome_rm(&(complexity_eval(*pcomp1))); */
458  complexity_eval_(*pcomp1) = newgen_Ppolynome(ppdiv);
459  complexity_stats_add(pcomp1, comp2);
460  }
461 }
Ppolynome polynome_div(Ppolynome pp1, Ppolynome pp2)
Ppolynome polynome_div(Ppolynome pp1, Ppolynome pp2) returns p = pp1 / pp2.
Definition: pnome-bin.c:381

References complexity_eval, complexity_eval_, complexity_stats_add(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), newgen_Ppolynome, pips_internal_error, and polynome_div().

Referenced by loop_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_float_add()

void complexity_float_add ( complexity pcomp,
float  f 
)

Add a floating point digit to the complexity May 3, 91.

Definition at line 480 of file comp_math.c.

483 {
484  if ( COMPLEXITY_UNDEFINED_P(*pcomp) )
485  pips_internal_error("complexity undefined");
486 
487  if ( complexity_zero_p(*pcomp) )
488  {
490  *pcomp = polynome_to_new_complexity(ppnew);
491  polynome_rm(&ppnew);
492  }
493  else
494  complexity_eval_(*pcomp) =
496  f));
497 }
#define VALUE_ONE
complexity polynome_to_new_complexity(Ppolynome pp)
Create a complexity equal to Ppolynome pp with null statistics.
Definition: comp_math.c:200
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_scalar_addition(Ppolynome pp, float term)
Ppolynome polynome_scalar_addition(Ppolynome pp, float term) pp = pp + term !usage: pp = polynome_sca...
Definition: pnome-scal.c:101
#define TCST
VARIABLE REPRESENTANT LE TERME CONSTANT.

References complexity_eval, complexity_eval_, COMPLEXITY_UNDEFINED_P, complexity_zero_p(), f(), make_polynome(), newgen_Ppolynome, pips_internal_error, polynome_rm(), polynome_scalar_addition(), polynome_to_new_complexity(), TCST, and VALUE_ONE.

Referenced by call_to_complexity(), call_to_polynome(), and subscript_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_mult()

void complexity_mult ( complexity pcomp1,
complexity  comp2 
)

void complexity_mult(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 * comp2; !usage: complexity_mult(&comp1, comp2);

(Ppolynome) complexity_eval(*pcomp1) = (Ppolynome) ppmult;

Parameters
pcomp1comp1
comp2omp2

Definition at line 418 of file comp_math.c.

420 {
421  if ( COMPLEXITY_UNDEFINED_P(comp2) || COMPLEXITY_UNDEFINED_P(*pcomp1) )
422  pips_internal_error("complexity undefined");
423 
424  if ( complexity_zero_p(comp2) ) {
425  complexity_rm(pcomp1);
426  *pcomp1 = make_zero_complexity();
427  }
428  else if ( !complexity_zero_p(*pcomp1) ) {
429  Ppolynome ppmult;
430 
431  ppmult = polynome_mult(complexity_eval(*pcomp1),
432  complexity_eval(comp2));
433  complexity_eval_(*pcomp1) =
435  /* (Ppolynome) complexity_eval(*pcomp1) = (Ppolynome) ppmult; */
436  complexity_eval_(*pcomp1) = newgen_Ppolynome(ppmult);
437  complexity_stats_add(pcomp1, comp2);
438  }
439 }
complexity make_zero_complexity()
make a zero complexity "0.0000 * TCST" with null statistics
Definition: comp_math.c:238
void complexity_rm(complexity *pcomp)
remove complexity comp
Definition: comp_util.c:164
Ppolynome polynome_free(Ppolynome pp)
Ppolynome polynome_free(Ppolynome pp) frees space occupied by polynomial pp returns pp == POLYNOME_NU...
Definition: pnome-alloc.c:191
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2)
Ppolynome polynome_mult(Ppolynome pp1, Ppolynome pp2) returns pp1 * pp2.
Definition: pnome-bin.c:287

References complexity_eval, complexity_eval_, complexity_rm(), complexity_stats_add(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), make_zero_complexity(), newgen_Ppolynome, pips_internal_error, polynome_free(), and polynome_mult().

Referenced by complexity_sigma(), divide_op_handler(), multiply_op_handler(), and whileloop_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_polynome()

Ppolynome complexity_polynome ( complexity  comp)

Because complexity is composed of two elements, we use this function to get the first element : polynome Usage : complexity_polynome(complexity comp) you will get a pointer to the polynome May 3, 91 lz.

Parameters
compomp

Definition at line 506 of file comp_math.c.

508 {
509  if ( COMPLEXITY_UNDEFINED_P(comp) )
510  pips_internal_error("complexity undefined");
511 
512  if ( complexity_zero_p(comp) )
513  return (POLYNOME_NUL);
514  else
515  return ((Ppolynome)complexity_eval(comp));
516 }
#define POLYNOME_NUL

References complexity_eval, COMPLEXITY_UNDEFINED_P, complexity_zero_p(), pips_internal_error, and POLYNOME_NUL.

Referenced by block_to_complexity(), complexity_check(), complexity_dup(), complexity_sigma(), complexity_sprint(), complexity_var_subst(), do_computation_intensity(), final_statement_to_complexity_evaluation(), if_conv_init_statement(), loop_to_complexity(), power_op_handler(), task_time(), and translate_complexity_from_local_to_current_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_polynome_add()

void complexity_polynome_add ( complexity pcomp,
Ppolynome  pp 
)
Parameters
pcompcomp
ppp

Definition at line 463 of file comp_math.c.

466 {
467  if ( COMPLEXITY_UNDEFINED_P(*pcomp) )
468  pips_internal_error("complexity undefined");
469  else if ( POLYNOME_UNDEFINED_P(pp) )
470  pips_internal_error("polynome undefined");
471  else {
472  complexity_eval_(*pcomp) =
474  }
475 }
#define POLYNOME_UNDEFINED_P(pp)

References complexity_eval, complexity_eval_, COMPLEXITY_UNDEFINED_P, newgen_Ppolynome, pips_internal_error, polynome_addition(), and POLYNOME_UNDEFINED_P.

Referenced by loop_to_complexity(), and pvecteur_to_polynome().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_scalar_mult()

void complexity_scalar_mult ( complexity pcomp,
float  f 
)

multiply a complexity by a floating-point number.

Abort if undefined.

Definition at line 303 of file comp_math.c.

306 {
307  if ( COMPLEXITY_UNDEFINED_P(*pcomp) )
308  pips_internal_error("complexity undefined");
309 
310  if ( f == 0.00 ) {
311  complexity_rm(pcomp);
312  *pcomp = make_zero_complexity();
313  }
314  else if ( !complexity_zero_p(*pcomp) )
315  complexity_eval_(*pcomp) =
318 }
Ppolynome polynome_scalar_multiply(Ppolynome pp, float factor)
Ppolynome polynome_scalar_multiply(Ppolynome pp, float factor) pp = factor * (pp) !...
Definition: pnome-scal.c:65

References complexity_eval, complexity_eval_, complexity_rm(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), f(), make_zero_complexity(), newgen_Ppolynome, pips_internal_error, and polynome_scalar_multiply().

Referenced by loop_to_complexity(), pvecteur_to_polynome(), simplify_sc_to_complexity(), test_to_complexity(), and unstructured_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_sigma()

complexity complexity_sigma ( complexity  comp,
Variable  index,
complexity  clower,
complexity  cupper 
)

comp_math.c

"mathematical" operations on complexities

complexity complexity_sigma(comp, index, clower, cupper) complexity_var_subst(comp, var, compsubst) complexity polynome_to_new_complexity(pp) complexity complexity_dup(comp) void complexity_rm(pcomp) complexity make_single_var_complexity(float, var) bool complexity_constant_p(comp) float complexity_TCST(comp) void complexity_scalar_mult(pcomp, f) void complexity_float_add(pcomp, f) void complexity_stats_add(pcomp1, comp2) void complexity_add(pcomp1, comp2) void complexity_sub(pcomp1, comp2) void complexity_mult(pcomp1, comp2) void complexity_polynome_add(pcomp, pp) Ppolynome complexity_polynome(comp) complexity replace_formal_parameters_by_real_ones(comp, mod, args, precond) Modif: – entity_local_name is replaced by module_local_name. LZ 230993 complexity complexity_sigma(complexity comp, Variable index, complexity clower, cupper) return the integration of complexity comp when the index is running between clower and cupper. Based on the polynomial library routine polynome_sigma.

  • comp is undefined => result undefined.
  • comp is null => result is null whatever the bounds are.
  • bound(s) is(are) undefined: if comp depends on the index, the result is undefined; else the result is comp * UNKNOWN_RANGE.
  • everything is defined: the result is the integration of the respective polynomials.

FI: Too late to build a meaningful unknown range name!

tats

Parameters
compomp
indexndex
clowerlower
cupperupper

Definition at line 84 of file comp_math.c.

88 {
89  complexity cresult = make_zero_complexity();
90  Ppolynome ppsum;
91  Ppolynome pplower = POLYNOME_NUL;
92  Ppolynome ppupper = POLYNOME_NUL;
93 
94  if (COMPLEXITY_UNDEFINED_P(comp))
95  pips_internal_error("complexity undefined");
96 
97  if (complexity_zero_p(comp))
98  return (cresult);
99  else if ( COMPLEXITY_UNDEFINED_P(clower) ||
100  COMPLEXITY_UNDEFINED_P(cupper) ) {
102  (Variable)index) )
103  return (cresult);
104  else {
105  /* FI: Too late to build a meaningful unknown range name! */
106  /*
107  ppsum = make_polynome(1.0, UNKNOWN_RANGE, 1);
108  */
114  ppsum = make_polynome(1.0, (Variable) ur, VALUE_ONE);
115  cresult = polynome_to_new_complexity(ppsum); /*stats*/
116  complexity_mult(&cresult, comp);
117 
118  polynome_rm(&ppsum);
119  return(cresult);
120  }
121  }
122  else {
123  pplower = complexity_polynome(clower);
124  ppupper = complexity_polynome(cupper);
125 
126  if (false) {
127  fprintf(stderr, "summing ");
128  prp(complexity_polynome(comp));
129  fprintf(stderr, " %s running between ",
130  module_local_name((entity)index));
131  prp(pplower);
132  fprintf(stderr, " and ");
133  prp(ppupper);
134  fprintf(stderr, "\n");
135  }
136 
137  ppsum = polynome_sigma(complexity_polynome(comp),
138  (Variable) index,
139  pplower, ppupper);
140  cresult = polynome_to_new_complexity(ppsum);
141  complexity_stats_add(&cresult, comp);
142  complexity_stats_add(&cresult, clower);
143  complexity_stats_add(&cresult, cupper);
144 
145  polynome_rm(&ppsum);
146  return(cresult);
147  }
148 }
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
void complexity_mult(complexity *pcomp1, complexity comp2)
void complexity_mult(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 * comp2; !...
Definition: comp_math.c:418
void prp(Ppolynome pp)
Definition: comp_util.c:239
#define UNKNOWN_RANGE_NAME
pseudo-variable for default iteration number of a loop
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
bool polynome_contains_var(Ppolynome pp, Variable var)
bool polynome_contains_var(Ppolynome pp, Variable var) PRIVATE returns true if variable var is in pol...
Definition: pnome-reduc.c:238
Ppolynome polynome_sigma(Ppolynome pp, Variable var, Ppolynome ppinf, Ppolynome ppsup)
Ppolynome polynome_sigma(Ppolynome pp, Variable var, Ppolynome ppinf, ppsup) returns the sum of pp wh...
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
basic MakeBasic(int)
END_EOLE.
Definition: type.c:128
void AddEntityToCurrentModule(entity)
Add a variable entity to the current module declarations.
Definition: variable.c:260
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
@ is_basic_int
Definition: ri.h:571
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
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

References AddEntityToCurrentModule(), complexity_mult(), complexity_polynome(), complexity_stats_add(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), fprintf(), get_current_module_entity(), is_basic_int, make_new_scalar_variable_with_prefix(), make_polynome(), make_zero_complexity(), MakeBasic(), module_local_name(), pips_internal_error, polynome_contains_var(), POLYNOME_NUL, polynome_rm(), polynome_sigma(), polynome_to_new_complexity(), prp(), UNKNOWN_RANGE_NAME, and VALUE_ONE.

Referenced by loop_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_stats_add()

void complexity_stats_add ( complexity pcomp1,
complexity  comp2 
)

Add comp2's statistics to *pcomp1's comp2 keeps unchanged.

Parameters
pcomp1comp1
comp2omp2

Definition at line 323 of file comp_math.c.

325 {
326  ifdebug (1) {
327  (void) complexity_consistent_p(*pcomp1);
328  (void) complexity_consistent_p(comp2);
329  }
330 
331  if ( COMPLEXITY_UNDEFINED_P(comp2) || COMPLEXITY_UNDEFINED_P(*pcomp1) )
332  pips_internal_error("complexity undefined");
333 
334  if ( complexity_zero_p(*pcomp1) ) {
335  *pcomp1 = complexity_dup(comp2);
336  complexity_eval_(*pcomp1) =
338  }
339  else if ( !complexity_zero_p(comp2) ) {
340  varcount vc1 = complexity_varcount(*pcomp1);
341  rangecount rc1 = complexity_rangecount(*pcomp1);
342  ifcount ic1 = complexity_ifcount(*pcomp1);
343  varcount vc2 = complexity_varcount(comp2);
344  rangecount rc2 = complexity_rangecount(comp2);
345  ifcount ic2 = complexity_ifcount(comp2);
346 
348  varcount_guessed(vc1) += varcount_guessed(vc2);
349  varcount_bounded(vc1) += varcount_bounded(vc2);
350  varcount_unknown(vc1) += varcount_unknown(vc2);
351 
356 
357  ifcount_profiled(ic1) += ifcount_profiled(ic2);
358  ifcount_computed(ic1) += ifcount_computed(ic2);
359  ifcount_halfhalf(ic1) += ifcount_halfhalf(ic2);
360  }
361 
362  ifdebug (1) {
363  (void) complexity_consistent_p(*pcomp1);
364  }
365 }
bool complexity_consistent_p(complexity p)
Definition: complexity_ri.c:27
#define ifcount_computed(x)
#define rangecount_unknown(x)
#define varcount_guessed(x)
#define complexity_ifcount(x)
Definition: complexity_ri.h:98
#define ifcount_profiled(x)
#define complexity_varcount(x)
Definition: complexity_ri.h:94
#define complexity_rangecount(x)
Definition: complexity_ri.h:96
#define rangecount_guessed(x)
#define varcount_symbolic(x)
#define varcount_unknown(x)
#define varcount_bounded(x)
#define rangecount_profiled(x)
#define ifcount_halfhalf(x)
#define rangecount_bounded(x)
#define ifdebug(n)
Definition: sg.c:47

References complexity_consistent_p(), complexity_dup(), complexity_eval, complexity_eval_, complexity_ifcount, complexity_rangecount, COMPLEXITY_UNDEFINED_P, complexity_varcount, complexity_zero_p(), ifcount_computed, ifcount_halfhalf, ifcount_profiled, ifdebug, newgen_Ppolynome, pips_internal_error, polynome_free(), rangecount_bounded, rangecount_guessed, rangecount_profiled, rangecount_unknown, varcount_bounded, varcount_guessed, varcount_symbolic, and varcount_unknown.

Referenced by complexity_add(), complexity_div(), complexity_mult(), complexity_sigma(), complexity_sub(), complexity_var_subst(), and loop_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_sub()

void complexity_sub ( complexity pcomp1,
complexity  comp2 
)

void complexity_sub(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 - comp2; !usage: complexity_sub(&comp1, comp2); comp2 keeps unchanged

Parameters
pcomp1comp1
comp2omp2

Definition at line 394 of file comp_math.c.

396 {
397  if ( COMPLEXITY_UNDEFINED_P(comp2) || COMPLEXITY_UNDEFINED_P(*pcomp1) )
398  pips_internal_error("complexity undefined");
399 
400  if ( complexity_zero_p(*pcomp1) )
401  *pcomp1 = complexity_dup(comp2);
402  else if ( !complexity_zero_p(comp2) ) {
403  complexity_eval_(comp2) =
405  complexity_eval_(*pcomp1) =
407  complexity_eval(comp2)));
408  complexity_stats_add(pcomp1, comp2);
409  complexity_eval_(comp2) =
411  }
412 }
Ppolynome polynome_opposed(Ppolynome pp)
Ppolynome polynome_opposed(Ppolynome pp); changes sign of polynomial pp.
Definition: pnome-unaires.c:59

References complexity_dup(), complexity_eval, complexity_eval_, complexity_stats_add(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), newgen_Ppolynome, pips_internal_error, polynome_addition(), and polynome_opposed().

Referenced by minus_op_handler(), and unary_minus_op_handler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_TCST()

float complexity_TCST ( complexity  comp)

return the constant term of comp.

Abort if undefined

Parameters
compomp

Definition at line 288 of file comp_math.c.

290 {
291  if ( COMPLEXITY_UNDEFINED_P(comp) )
292  pips_internal_error("undefined complexity");
293 
294  if ( complexity_zero_p(comp) )
295  return ((float) 0);
296  else
297  return (polynome_TCST(complexity_eval(comp)));
298 }
float polynome_TCST(Ppolynome pp)
float polynome_TCST(Ppolynome pp) returns the constant term of polynomial pp.
Definition: pnome-reduc.c:156

References complexity_eval, COMPLEXITY_UNDEFINED_P, complexity_zero_p(), pips_internal_error, and polynome_TCST().

Referenced by divide_op_handler(), loop_to_complexity(), and power_op_handler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_unknown_p()

bool complexity_unknown_p ( complexity  comp)

true if comp is unknown.

Abort if undefined

FI: Management of unknown complexities, when polynomes are in fact used to represent the value of a variables or an expression, has to be revisited

Parameters
compomp

Definition at line 269 of file comp_math.c.

271 {
272  if ( COMPLEXITY_UNDEFINED_P(comp) )
273  pips_internal_error("undefined complexity");
274 
275  /* FI: Management of unknown complexities, when polynomes are in
276  fact used to represent the value of a variables or an expression,
277  has to be revisited */
278  /*
279  if ( polynome_contains_var((Ppolynome)complexity_eval(comp),
280  UNKNOWN_RANGE) )
281  return (true);
282  else
283  */
284  return (false);
285 }

References COMPLEXITY_UNDEFINED_P, and pips_internal_error.

Referenced by expression_to_complexity_polynome(), and loop_to_complexity().

+ Here is the caller graph for this function:

◆ complexity_var_subst()

complexity complexity_var_subst ( complexity  comp,
Variable  var,
complexity  compsubst 
)

complexity complexity_var_subst(comp, var, compsubst) replaces every occurrence of variable var in complexity comp by the polynomial of complexity compsubst.

The statistics of compsubst are added to those of comp.

substitutes

Parameters
compomp
varar
compsubstompsubst

Definition at line 155 of file comp_math.c.

159 {
160  Ppolynome pp, ppsubst, ppresult;
161  complexity cresult = make_zero_complexity();
162 
163  if (COMPLEXITY_UNDEFINED_P(comp) || COMPLEXITY_UNDEFINED_P(compsubst))
164  pips_internal_error("complexity undefined");
165 
166  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
167  fprintf(stderr,"complexity_var_subst, variable name=%s\n",
168  variable_name(var) );
169  }
170 
171  if (complexity_zero_p(comp))
172  return (cresult);
173  else {
174  pp = complexity_polynome(comp);
175  ppsubst = complexity_polynome(compsubst);
176 
177  ppresult = polynome_var_subst(pp, var, ppsubst); /* substitutes */
178 
179  cresult = polynome_to_new_complexity(ppresult);
180  complexity_stats_add(&cresult, compsubst);
181 
182  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
183  (void) complexity_consistent_p(cresult);
184  fprintf(stderr,"complexity_var_subst, comp is ");
185  complexity_fprint(stderr, comp, false, true);
186  fprintf(stderr,"complexity_var_subst, compsubst is ");
187  complexity_fprint(stderr, compsubst, false, true);
188  fprintf(stderr,"complexity_var_subst, cresult is ");
189  complexity_fprint(stderr, cresult, false, true);
190  }
191  }
192 
193  return(cresult);
194 }
void complexity_fprint(FILE *fd, complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:217
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
Ppolynome polynome_var_subst(Ppolynome pp, Variable var, Ppolynome ppsubst)
Ppolynome polynome_var_subst(Ppolynome pp, Variable var, Ppolynome ppsubst) creates and returns a Ppo...
Definition: pnome-reduc.c:47
char * variable_name(Variable v)
polynome_ri.c
Definition: polynome_ri.c:73

References complexity_consistent_p(), complexity_fprint(), complexity_polynome(), complexity_stats_add(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), fprintf(), get_bool_property(), make_zero_complexity(), pips_internal_error, polynome_to_new_complexity(), polynome_var_subst(), and variable_name().

Referenced by block_to_complexity(), new_block_to_complexity(), replace_formal_parameters_by_real_ones(), and translate_complexity_from_local_to_current_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ complexity_zero_p()

bool complexity_zero_p ( complexity  comp)

◆ list_ith_element()

list list_ith_element ( list  thelist,
int  ith 
)

return a pointer to the (i)th element of the list if i = 1, the pointer doesn't change at all.

Parameters
thelisthelist
ithth

Definition at line 579 of file comp_math.c.

582 {
583  for( ; --ith > 0; thelist = CDR(thelist) ) {
584  pips_assert("list_ith_element", thelist != NIL);
585  }
586 
587  return (thelist);
588 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172

References CDR, NIL, and pips_assert.

◆ make_constant_complexity()

complexity make_constant_complexity ( float  f)

make a constant complexity "f * TCST" with null statistics

Definition at line 231 of file comp_math.c.

233 {
235 }
complexity make_single_var_complexity(float f, Variable var)
make a complexity "f * var" with null statistics
Definition: comp_math.c:220

References f(), make_single_var_complexity(), and TCST.

Referenced by divide_op_handler(), evaluate_var_to_complexity(), loop_to_complexity(), make_zero_complexity(), reference_to_complexity(), simplify_sc_to_complexity(), and syntax_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_single_var_complexity()

complexity make_single_var_complexity ( float  f,
Variable  var 
)

make a complexity "f * var" with null statistics

Definition at line 220 of file comp_math.c.

223 {
224  Ppolynome pp = make_polynome(f, var, VALUE_ONE);
226  polynome_rm(&pp);
227  return(comp);
228 }

References f(), make_polynome(), polynome_rm(), polynome_to_new_complexity(), and VALUE_ONE.

Referenced by evaluate_var_to_complexity(), loop_to_complexity(), make_complexity_unknown(), make_constant_complexity(), simplify_sc_to_complexity(), and translate_complexity_from_local_to_current_name().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_zero_complexity()

◆ polynome_to_new_complexity()

complexity polynome_to_new_complexity ( Ppolynome  pp)

Create a complexity equal to Ppolynome pp with null statistics.

pp IS duplicated.

Parameters
ppp

Definition at line 200 of file comp_math.c.

202 {
203  varcount vc = make_varcount(0,0,0,0);
204  rangecount rc = make_rangecount(0,0,0,0);
205  ifcount ic = make_ifcount(0,0,0);
206  Ppolynome ppdup;
207  complexity comp;
208 
209  pips_assert("polynome_to_new_complexity", !POLYNOME_UNDEFINED_P(pp));
210 
211  ppdup = polynome_dup(pp);
212  comp = make_complexity(ppdup, vc, rc, ic);
213  ifdebug(1) {
214  (void) complexity_consistent_p(comp);
215  }
216  return comp;
217 }
rangecount make_rangecount(intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
varcount make_varcount(intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4)
ifcount make_ifcount(intptr_t a1, intptr_t a2, intptr_t a3)
Definition: complexity_ri.c:96
complexity make_complexity(Ppolynome a1, varcount a2, rangecount a3, ifcount a4)
Definition: complexity_ri.c:54
Ppolynome polynome_dup(Ppolynome pp)
Ppolynome polynome_dup(Ppolynome pp) creates and returns a copy of pp.
Definition: pnome-alloc.c:211

References complexity_consistent_p(), ifdebug, make_complexity(), make_ifcount(), make_rangecount(), make_varcount(), pips_assert, polynome_dup(), and POLYNOME_UNDEFINED_P.

Referenced by complexity_float_add(), complexity_sigma(), complexity_var_subst(), make_single_var_complexity(), pvecteur_to_polynome(), and reference_to_polynome().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ replace_formal_parameters_by_real_ones()

complexity replace_formal_parameters_by_real_ones ( complexity  comp,
entity  mod,
list  args,
transformer  precond,
list  effects_list 
)

transform formal params into real ones (args) in complexity comp

print out the entity name for debugging purpose

if formal parameter...

minus one because offsets start at 1 not 0

Parameters
compomp
modod
argsrgs
precondrecond
effects_listffects_list

Definition at line 519 of file comp_math.c.

525 {
526  complexity cresult = complexity_dup(comp);
527  complexity carg, ctemp;
529  char *param_name;
530  int param_rank;
531  list argument;
532 
533  pips_assert("replace_formal_parameters_by_real_ones", entity_module_p(mod));
534 
535  FOREACH (ENTITY, param,decl) {
537 
538  /* print out the entity name for debugging purpose */
539  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
540  fprintf(stderr,"in REPLACE, entity name is %s\n",
541  entity_name(param));
542  }
543 
544  if (storage_formal_p(st)) {
545  /* if formal parameter... */
546  param_name = entity_name(param);
547  param_rank = formal_offset(storage_formal(st));
548 
549  argument = gen_nthcdr(param_rank-1,args);/* minus one because offsets start at 1 not 0 */
550 
551  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
552  fprintf(stderr,"formal offset=%d, formal name=%s\n",
553  param_rank, param_name);
554  }
555 
557  precond,
558  effects_list,
559  KEEP_SYMBOLS,
560  EXACT_VALUE);
561 
562  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
563  fprintf(stderr,"variable name is %s\n", variable_name((Variable)param) );
564  }
565 
566  ctemp = complexity_var_subst(cresult, (Variable)param, carg);
567  complexity_rm(&cresult);
568  cresult = complexity_dup(ctemp);
569  complexity_rm(&carg);
570  }
571  }
572 
573  return (cresult);
574 }
complexity expression_to_complexity_polynome(expression expr, transformer precond, list effects_list, bool keep_symbols, int maximize)
Entry point routine of this file:
complexity complexity_var_subst(complexity comp, Variable var, complexity compsubst)
complexity complexity_var_subst(comp, var, compsubst) replaces every occurrence of variable var in co...
Definition: comp_math.c:155
#define KEEP_SYMBOLS
defines for "expression_to_polynome" parameters
#define EXACT_VALUE
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
list gen_nthcdr(int n, const list lx)
caution: the first item is 0! was: return( (n<=0) ? l : gen_nthcdr( n-1, CDR( l ))) ; if n>gen_length...
Definition: list.c:700
bool entity_module_p(entity e)
Definition: entity.c:683
#define formal_offset(x)
Definition: ri.h:1408
#define storage_formal_p(x)
Definition: ri.h:2522
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_storage(x)
Definition: ri.h:2794
#define code_declarations(x)
Definition: ri.h:784
#define storage_formal(x)
Definition: ri.h:2524
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_name(x)
Definition: ri.h:2790
#define value_code(x)
Definition: ri.h:3067
#define entity_initial(x)
Definition: ri.h:2796
Polymorphic argument.
Definition: printf-args.h:92
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: replace.c:135

References CAR, code_declarations, complexity_dup(), complexity_rm(), complexity_var_subst(), ENTITY, entity_initial, entity_module_p(), entity_name, entity_storage, EXACT_VALUE, EXPRESSION, expression_to_complexity_polynome(), FOREACH, formal_offset, fprintf(), gen_nthcdr(), get_bool_property(), KEEP_SYMBOLS, pips_assert, storage_formal, storage_formal_p, value_code, and variable_name().

Referenced by call_to_complexity().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: