PIPS
comp_util.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include "linear.h"
#include "genC.h"
#include "database.h"
#include "ri.h"
#include "effects.h"
#include "complexity_ri.h"
#include "resources.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "text-util.h"
#include "effects-generic.h"
#include "effects-simple.h"
#include "misc.h"
#include "constants.h"
#include "properties.h"
#include "matrice.h"
#include "polynome.h"
#include "complexity.h"
+ Include dependency graph for comp_util.c:

Go to the source code of this file.

Macros

#define INDENT_BLANKS   " "
 comp_util.c More...
 
#define INDENT_VLINE   "| "
 
#define INDENT_BACK   "-"
 
#define INDENT_INTERVAL   2
 

Functions

bool complexity_check (complexity comp)
 return true if allright More...
 
void complexity_check_and_warn (char *s, complexity comp) const
 
void good_complexity_assert (_UNUSED_ string function, complexity comp)
 
complexity complexity_dup (complexity comp)
 duplicates complexity comp More...
 
void complexity_rm (complexity *pcomp)
 remove complexity comp More...
 
char * complexity_sprint (complexity comp, bool print_stats_p, bool print_local_names_p)
 
void complexity_fprint (FILE *fd, complexity comp, bool print_stats_p, bool print_local_names_p)
 
void complexity_dump (complexity comp)
 
void prc (complexity comp)
 
void prp (Ppolynome pp)
 
void prv (Pvecteur pv)
 
void fprint_statement_complexity (entity module, statement stat, hash_table hash_statement_to_complexity)
 
void fprint_cost_table (FILE *fd)
 
void init_cost_table ()
 Completes the intrinsic cost table with the costs read from the files specified in the "COMPLEXITY_COST_TABLE" string property See properties.rc and ~pips/Pips/pipsrc.csh for more information. More...
 
void load_cost_file (FILE *fd, float file_factor)
 Load (some) intrinsics costs from file "fd", multiplying them by "file_factor". More...
 
int intrinsic_cost (char *s, basic *pargsbasic) const
 Return the cost of the intrinsic named s, knowing that the "basic" type of its biggest argument is *pargsbasic. More...
 
float constant_entity_to_float (entity e)
 Return if possible the value of e in a float. More...
 
void trace_on (char *fmt,...)
 
void trace_off ()
 "trace off" More...
 
bool is_linear_unstructured (unstructured unstr)
 return true if unstr is simply a linear string of controls More...
 
list entity_list_reverse (list l)
 
void add_formal_parameters_to_hash_table (entity mod, hash_table hash_complexity_params)
 
void remove_formal_parameters_from_hash_table (entity mod, hash_table hash_complexity_params)
 
hash_table free_callees_complexities (hash_table h)
 
hash_table fetch_callees_complexities (char *module_name)
 
hash_table fetch_complexity_parameters (char *module_name)
 
void add_common_variables_to_hash_table (entity module, hash_table hash_complexity_params)
 
void remove_common_variables_from_hash_table (entity module, hash_table hash_complexity_params)
 
bool is_must_be_written_var (list effects_list, char *var_name)
 
complexity final_statement_to_complexity_evaluation (complexity comp, transformer precond, list effects_list)
 
complexity translate_complexity_from_local_to_current_name (complexity callee_comp, string oldname, string newname)
 translate_complexity_from_local_to_current_name(callee_comp,oldname,newname) B:M -> A:M if A calls B 5 Feb. More...
 
bool complexity_is_monomial_p (complexity c)
 
int complexity_degree (complexity c)
 

Variables

intrinsic_cost_record intrinsic_cost_table []
 The table intrinsic_cost_table[] gathers cost information of each intrinsic's cost; those costs are dynamically loaded from user files. More...
 
static int call_level =0
 "trace on" More...
 

Macro Definition Documentation

◆ INDENT_BACK

#define INDENT_BACK   "-"

Definition at line 92 of file comp_util.c.

◆ INDENT_BLANKS

#define INDENT_BLANKS   " "

comp_util.c

useful routines for evaluation of the complexity of a program

bool complexity_check(comp) void complexity_check_and_warn(function_name, comp) void good_complexity_assert(function_name, comp) void complexity_fprint(fd, comp, print_stats_p, print_local_names_p) char *complexity_sprint(comp, print_stats_p, print_local_names_p) void fprint_statement_complexity(module, stat, hash_statement_to_complexity) void prc(comp) (for dbx) void prp(pp) (for dbx) void prv(pv) (for dbx) void fprint_cost_table(fd) void init_cost_table(); int intrinsic_cost(name, argstype) bool is_inferior_basic(basic1, basic2) basic simple_basic_dup(b) float constant_entity_to_float(e) void trace_on(va_alist) void trace_off() list entity_list_reverse(l) bool is_linear_unstructured(unstr) void add_formal_parameters_to_hash_table(mod, hash_complexity_params) void remove_formal_parameters_from_hash_table(mod, hash_complexity_params) hash_table fetch_callees_complexities(module_name) hash_table fetch_complexity_parameters(module_name) Modif: – entity_local_name is replaced by module_local_name. LZ 230993 – add of missing operators to intrinsic_cost_table. Molka Becher 08.03.2011 To have strndup(): getenv print_text IMPLIED_DO_NAME is defined there get_string_property is defined there for debugging

Definition at line 90 of file comp_util.c.

◆ INDENT_INTERVAL

#define INDENT_INTERVAL   2

Definition at line 93 of file comp_util.c.

◆ INDENT_VLINE

#define INDENT_VLINE   "| "

Definition at line 91 of file comp_util.c.

Function Documentation

◆ add_common_variables_to_hash_table()

void add_common_variables_to_hash_table ( entity  module,
hash_table  hash_complexity_params 
)
Parameters
moduleodule
hash_complexity_paramsash_complexity_params

Definition at line 946 of file comp_util.c.

949 {
950  const char* module_name = module_local_name(module);
951  list sefs_list = list_undefined;
952  list ce = list_undefined;
953 
954  pips_assert("add_common_variables_to_hash_table",
956 
957  sefs_list = effects_to_list( (effects)
958  db_get_memory_resource(DBR_SUMMARY_EFFECTS, module_name, true));
959 
960  ifdebug(5) {
961  debug(5, "add_common_variables_to_hash_table",
962  "Effect list for %s\n",
963  module_name);
964  print_effects(sefs_list);
965  }
966 
967  for(ce= sefs_list; !ENDP(ce); POP(ce)) {
968  effect obj = EFFECT(CAR(ce));
970  action ac = effect_action(obj);
972  entity e = reference_variable(r);
973  storage s = entity_storage(e);
974 
975  if ( !storage_formal_p(s) &&
976  action_read_p(ac) && approximation_exact_p(ap) ) {
977  debug(5,"add_common_variables_to_hash_table",
978  "%s added\n", module_local_name(e));
979  hash_put(hash_complexity_params, (char *) module_local_name(e),
981  }
982  }
983 }
#define HASH_COMMON_VARIABLE
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
list effects_to_list(effects)
Definition: effects.c:209
#define approximation_exact_p(x)
Definition: effects.h:369
#define effect_action(x)
Definition: effects.h:642
#define action_read_p(x)
Definition: effects.h:311
#define effect_approximation(x)
Definition: effects.h:644
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#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 CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define list_undefined
Undefined list definition :-)
Definition: newgen_list.h:69
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
Definition: database.c:755
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
static char * module
Definition: pips.c:74
#define print_effects(e)
Definition: print.c:334
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool entity_module_p(entity e)
Definition: entity.c:683
#define storage_formal_p(x)
Definition: ri.h:2522
#define reference_variable(x)
Definition: ri.h:2326
#define entity_storage(x)
Definition: ri.h:2794
#define ifdebug(n)
Definition: sg.c:47
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References action_read_p, approximation_exact_p, CAR, db_get_memory_resource(), debug(), EFFECT, effect_action, effect_any_reference, effect_approximation, effects_to_list(), ENDP, entity_module_p(), entity_storage, HASH_COMMON_VARIABLE, hash_put(), ifdebug, list_undefined, module, module_local_name(), module_name(), pips_assert, POP, print_effects, reference_variable, and storage_formal_p.

Referenced by any_complexities().

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

◆ add_formal_parameters_to_hash_table()

void add_formal_parameters_to_hash_table ( entity  mod,
hash_table  hash_complexity_params 
)
Parameters
modod
hash_complexity_paramsash_complexity_params

Definition at line 768 of file comp_util.c.

771 {
772  list decl;
773 
774  pips_assert("add_formal_parameters_to_hash_table",
775  entity_module_p(mod));
777 
778  MAPL(pe, {
779  entity param = ENTITY(CAR(pe));
781  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
782  fprintf(stderr,"\nstorage_formal %s\n",
783  entity_name(param));
784  }
785  hash_put(hash_complexity_params, (char *) strdup(module_local_name(param)),
787  }
788  }, decl);
789 }
#define HASH_FORMAL_PARAM
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
Definition: newgen_list.h:203
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define code_declarations(x)
Definition: ri.h:784
#define entity_name(x)
Definition: ri.h:2790
#define value_code(x)
Definition: ri.h:3067
#define entity_initial(x)
Definition: ri.h:2796
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
Definition: replace.c:135

References CAR, code_declarations, ENTITY, entity_initial, entity_module_p(), entity_name, entity_storage, fprintf(), get_bool_property(), HASH_FORMAL_PARAM, hash_put(), MAPL, module_local_name(), pips_assert, storage_formal_p, strdup(), and value_code.

Referenced by any_complexities().

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

◆ complexity_check()

bool complexity_check ( complexity  comp)

return true if allright

comp_util.c

Parameters
compomp

Definition at line 96 of file comp_util.c.

98 {
99  if ( COMPLEXITY_UNDEFINED_P(comp) )
100  pips_internal_error("complexity undefined");
101 
102  if ( !complexity_zero_p(comp) ) {
103  return (polynome_check(complexity_polynome(comp)));
104  }
105  return (true);
106 }
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
bool complexity_zero_p(complexity comp)
zero complexity check.
Definition: comp_math.c:244
#define COMPLEXITY_UNDEFINED_P(c)
#define pips_internal_error
Definition: misc-local.h:149
bool polynome_check(Ppolynome pp)
bool polynome_check(Ppolynome pp) Return true if all's right.
Definition: pnome-error.c:131

References complexity_polynome(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), pips_internal_error, and polynome_check().

Referenced by complexity_check_and_warn(), and good_complexity_assert().

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

◆ complexity_check_and_warn()

void complexity_check_and_warn ( char *  s,
complexity  comp 
) const

Definition at line 108 of file comp_util.c.

111 {
112  if ( COMPLEXITY_UNDEFINED_P(comp) )
113  pips_internal_error("complexity undefined");
114 
115  if ( complexity_zero_p(comp) ) {
116  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
117  fprintf(stderr,"complexity ZERO for %s\n",s);
118  }
119  }
120  if (!complexity_check(comp))
121  user_warning(s,"Bad internal complexity representation!\n");
122 }
bool complexity_check(complexity comp)
return true if allright
Definition: comp_util.c:96
#define user_warning(fn,...)
Definition: misc-local.h:262

References complexity_check(), COMPLEXITY_UNDEFINED_P, complexity_zero_p(), fprintf(), get_bool_property(), pips_internal_error, and user_warning.

Referenced by arguments_to_complexity(), block_to_complexity(), call_to_complexity(), controls_to_hash_table(), expression_to_complexity(), indices_to_complexity(), instruction_to_complexity(), loop_to_complexity(), new_block_to_complexity(), range_to_complexity(), reference_to_complexity(), statement_to_complexity(), syntax_to_complexity(), test_to_complexity(), text_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_degree()

int complexity_degree ( complexity  c)

Definition at line 1167 of file comp_util.c.

1168 {
1169  Ppolynome p = complexity_eval(c);
1170  int degree = polynome_max_degree(p);
1171 
1172  return degree;
1173 }
#define complexity_eval(x)
Definition: complexity_ri.h:92
int polynome_max_degree(Ppolynome pp)
int polynome_max_degree(Ppolynome pp) returns the degree of polynomial pp Let's hope there aren't too...
Definition: pnome-reduc.c:113

References complexity_eval, and polynome_max_degree().

Referenced by loop_to_complexity().

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

◆ complexity_dump()

void complexity_dump ( complexity  comp)
Parameters
compomp

Definition at line 228 of file comp_util.c.

229 {
230  complexity_fprint(stderr, comp, false, true);
231 }
void complexity_fprint(FILE *fd, complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:217

References complexity_fprint().

+ Here is the call graph for this function:

◆ complexity_dup()

complexity complexity_dup ( complexity  comp)

duplicates complexity comp

Parameters
compomp

Definition at line 131 of file comp_util.c.

133 {
134  if ( COMPLEXITY_UNDEFINED_P(comp) )
135  pips_internal_error("complexity undefined");
136 
137  if ( complexity_zero_p(comp) )
138  return (make_zero_complexity());
139  else {
140  varcount vc = complexity_varcount(comp);
142  ifcount ic = complexity_ifcount(comp);
143 
145  varcount_guessed(vc),
146  varcount_bounded(vc),
147  varcount_unknown(vc));
149  rangecount_guessed(rc),
150  rangecount_bounded(rc),
151  rangecount_unknown(rc));
153  ifcount_computed(ic),
154  ifcount_halfhalf(ic));
155 
157  complexity compl = make_complexity(ppdup, newvc, newrc, newic);
158 
159  return(compl);
160  }
161 }
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
complexity make_zero_complexity()
make a zero complexity "0.0000 * TCST" with null statistics
Definition: comp_math.c:238
#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)
Ppolynome polynome_dup(Ppolynome pp)
Ppolynome polynome_dup(Ppolynome pp) creates and returns a copy of pp.
Definition: pnome-alloc.c:211

References complexity_ifcount, complexity_polynome(), complexity_rangecount, COMPLEXITY_UNDEFINED_P, complexity_varcount, complexity_zero_p(), ifcount_computed, ifcount_halfhalf, ifcount_profiled, make_complexity(), make_ifcount(), make_rangecount(), make_varcount(), make_zero_complexity(), pips_internal_error, polynome_dup(), rangecount_bounded, rangecount_guessed, rangecount_profiled, rangecount_unknown, varcount_bounded, varcount_guessed, varcount_symbolic, and varcount_unknown.

Referenced by complexity_add(), complexity_stats_add(), complexity_sub(), final_statement_to_complexity_evaluation(), replace_formal_parameters_by_real_ones(), test_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:

◆ complexity_fprint()

void complexity_fprint ( FILE *  fd,
complexity  comp,
bool  print_stats_p,
bool  print_local_names_p 
)
Parameters
fdd
compomp
print_stats_print_stats_p
print_local_names_print_local_names_p

Definition at line 217 of file comp_util.c.

221 {
222  char *s = complexity_sprint(comp, print_stats_p, print_local_names_p);
223 
224  fprintf(fd, "%s\n", s);
225  free(s);
226 }
char * complexity_sprint(complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:175
void free(void *)

References complexity_sprint(), fprintf(), and free().

Referenced by arguments_to_complexity(), block_to_complexity(), call_to_complexity(), call_to_polynome(), cast_to_polynome(), complexity_dump(), complexity_var_subst(), controls_to_hash_table(), expression_to_complexity_polynome(), fetch_callees_complexities(), final_statement_to_complexity_evaluation(), fprint_statement_complexity(), loop_to_complexity(), prc(), range_to_complexity(), reference_to_complexity(), statement_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_is_monomial_p()

bool complexity_is_monomial_p ( complexity  c)

Definition at line 1159 of file comp_util.c.

1160 {
1161  Ppolynome p = complexity_eval(c);
1162  bool monomial_p = is_single_monome(p);
1163 
1164  return monomial_p;
1165 }
#define is_single_monome(pp)

References complexity_eval, and is_single_monome.

Referenced by loop_to_complexity().

+ Here is the caller graph for this function:

◆ complexity_rm()

void complexity_rm ( complexity pcomp)

remove complexity comp

Parameters
pcompcomp

Definition at line 164 of file comp_util.c.

166 {
167  if ( COMPLEXITY_UNDEFINED_P(*pcomp) )
168  pips_internal_error("undefined complexity");
169 
170  if ( !complexity_zero_p(*pcomp) )
171  free_complexity(*pcomp);
172  *pcomp = make_zero_complexity();// complexity_undefined;
173 }
void free_complexity(complexity p)
Definition: complexity_ri.c:21

References COMPLEXITY_UNDEFINED_P, complexity_zero_p(), free_complexity(), make_zero_complexity(), and pips_internal_error.

Referenced by complexity_mult(), complexity_scalar_mult(), divide_op_handler(), field_op_handler(), indices_to_complexity(), loop_to_complexity(), minus_op_handler(), multiply_op_handler(), plus_op_handler(), power_op_handler(), range_to_complexity(), reference_to_complexity(), replace_formal_parameters_by_real_ones(), simplify_sc_to_complexity(), subscript_to_complexity(), syntax_to_complexity(), test_to_complexity(), and unary_minus_op_handler().

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

◆ complexity_sprint()

char* complexity_sprint ( complexity  comp,
bool  print_stats_p,
bool  print_local_names_p 
)
Parameters
compomp
print_stats_print_stats_p
print_local_names_print_local_names_p

Definition at line 175 of file comp_util.c.

178 {
179 
180  char *s=NULL;
181 
182  if ( COMPLEXITY_UNDEFINED_P(comp) )
183  pips_internal_error("complexity undefined");
184  else {
185  varcount vc = complexity_varcount(comp);
187  ifcount ic = complexity_ifcount(comp);
188 
189  char * p = polynome_sprint(complexity_polynome(comp),
190  (print_local_names_p ? variable_local_name
191  : variable_name),
193 
194  if ( print_stats_p ) {
195  asprintf(&s,"[(var:%td/%td/%td/%td)"
196  " (rng:%td/%td/%td/%td)"
197  " (ifs:%td/%td/%td)] %s",
198  varcount_symbolic(vc),
199  varcount_guessed(vc),
200  varcount_bounded(vc),
201  varcount_unknown(vc),
203  rangecount_guessed(rc),
204  rangecount_bounded(rc),
205  rangecount_unknown(rc),
206  ifcount_profiled(ic),
207  ifcount_computed(ic),
208  ifcount_halfhalf(ic),p);
209  free(p);
210  }
211  else
212  s=p;
213  }
214  return s;
215 }
char * variable_local_name(Variable)
Definition: polynome_ri.c:95
int is_inferior_pvarval(Pvecteur *, Pvecteur *)
Definition: polynome_ri.c:149
#define asprintf
Definition: misc-local.h:225
char * polynome_sprint(Ppolynome pp, char *(*variable_name)(Variable), int *is_inferior_var)
char polynome_sprint(Ppolynome pp, char (*variable_name)(), bool (*is_inferior_var)()) Outputs to fil...
Definition: pnome-io.c:197
char * variable_name(Variable v)
polynome_ri.c
Definition: polynome_ri.c:73

References asprintf, complexity_ifcount, complexity_polynome(), complexity_rangecount, COMPLEXITY_UNDEFINED_P, complexity_varcount, free(), ifcount_computed, ifcount_halfhalf, ifcount_profiled, is_inferior_pvarval(), pips_internal_error, polynome_sprint(), rangecount_bounded, rangecount_guessed, rangecount_profiled, rangecount_unknown, varcount_bounded, varcount_guessed, varcount_symbolic, varcount_unknown, variable_local_name(), and variable_name().

Referenced by complexity_fprint(), task_complexity(), task_time_polynome(), text_complexity(), and text_summary_complexity().

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

◆ constant_entity_to_float()

float constant_entity_to_float ( entity  e)

Return if possible the value of e in a float.

it is supposed to be an int or a float.

Definition at line 664 of file comp_util.c.

666 {
667  const char *cste = module_local_name(e);
668  basic b = entity_basic(e);
669  float f;
670 
671  if (basic_int_p(b) || basic_float_p(b)) {
672  sscanf(cste, "%f", &f);
673  return (f);
674  }
675  else {
676  user_warning("constant_entity_to_float",
677  "Basic tag:%d, not 4->9, (entity %s)\n",basic_tag(b),cste);
678  return (0.0);
679  }
680 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
Definition: entity.c:1380
#define basic_int_p(x)
Definition: ri.h:614
#define basic_tag(x)
Definition: ri.h:613
#define basic_float_p(x)
Definition: ri.h:617

References basic_float_p, basic_int_p, basic_tag, entity_basic(), f(), module_local_name(), and user_warning.

Referenced by call_to_polynome().

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

◆ entity_list_reverse()

list entity_list_reverse ( list  l)

Definition at line 757 of file comp_util.c.

759 {
760  entity e;
761 
762  if ((l == NIL) || (l->cdr == NIL))
763  return l;
764  e = ENTITY(CAR(l));
765  return (CONS(ENTITY, e, entity_list_reverse(l->cdr)));
766 }
list entity_list_reverse(list l)
Definition: comp_util.c:757
#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
struct cons * cdr
The pointer to the next element.
Definition: newgen_list.h:43

References CAR, CONS, ENTITY, and NIL.

◆ fetch_callees_complexities()

hash_table fetch_callees_complexities ( char *  module_name)

translate the local name to current module name. LZ 5 Feb.93

i.e. SUB:M -> MAIN:M

FI: this seems to be wrong in general because the formal parameter and actual argument are assumed to have the same name; see DemoStd/q and variables IM/IMM; 3 March 1994

Parameters
module_nameodule_name

Definition at line 821 of file comp_util.c.

823 {
824  hash_table hash_callees_comp = hash_table_make(hash_pointer, 0);
825  callees cl;
826  list callees_list;
827  complexity callee_comp;
828 
829  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
830  fprintf(stderr, "Fetching callees complexities ...\n");
831  }
832 
833  cl = (callees)db_get_memory_resource(DBR_CALLEES, module_name, true);
834  callees_list = callees_callees(cl);
835 
836  if ( callees_list == NIL ) {
837  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
838  fprintf(stderr, "Module %s has no callee! Done\n", module_name);
839  }
840  return(hash_callees_comp);
841  }
842 
843  MAPL(pc, {
844  string callee_name = STRING(CAR(pc));
845  entity callee = module_name_to_entity(callee_name);
846  type t = entity_type(callee);
847 
848  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
849  fprintf(stderr, "%s has callee %s!\n",module_name,callee_name);
850  }
851  pips_assert("call_to_complexity",
852  type_functional_p(t) || type_void_p(t));
853 
855  complexity new_comp;
856  callee_comp = (complexity)
857  db_get_memory_resource(DBR_SUMMARY_COMPLEXITY,
858  (char *) callee_name,
859  true);
860 
861  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
862  fprintf(stderr, "fetched complexity for callee %s",
863  callee_name);
864  fprintf(stderr, " of module %s:\n", module_name);
865  complexity_fprint(stderr, callee_comp,
868  }
869 
870  debug(5,"fetch_callees_complexities","callee_name %s\n",callee_name);
871 
872  /* translate the local name to current module name. LZ 5 Feb.93 */
873  /* i.e. SUB:M -> MAIN:M */
874  /* FI: this seems to be wrong in general because the
875  * formal parameter and actual argument are assumed to
876  * have the same name; see DemoStd/q and variables IM/IMM;
877  * 3 March 1994
878  */
879  new_comp = translate_complexity_from_local_to_current_name(callee_comp,
880  callee_name,module_name);
881 
882  hash_put(hash_callees_comp, (char *)callee, (char *)new_comp);
883  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
884  fprintf(stderr, "translated complexity for callee %s",
885  callee_name);
886  fprintf(stderr, " of module %s:\n", module_name);
887  complexity_fprint(stderr, new_comp,
890  }
891  }
892  }, callees_list );
893 
894  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
895  fprintf(stderr, "Fetching callees complexities ... done\n");
896  }
897 
898  return(hash_callees_comp);
899 }
static entity callee
Definition: alias_pairs.c:62
complexity translate_complexity_from_local_to_current_name(complexity callee_comp, string oldname, string newname)
translate_complexity_from_local_to_current_name(callee_comp,oldname,newname) B:M -> A:M if A calls B ...
Definition: comp_util.c:1100
#define PRINT_LOCAL_NAMES
#define DO_PRINT_STATS
defines for "complexity_fprint" calls
struct _newgen_struct_complexity_ * complexity
Definition: complexity_ri.h:30
#define STRING(x)
Definition: genC.h:87
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
@ hash_pointer
Definition: newgen_hash.h:32
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define type_functional_p(x)
Definition: ri.h:2950
#define value_code_p(x)
Definition: ri.h:3065
struct _newgen_struct_callees_ * callees
Definition: ri.h:55
#define callees_callees(x)
Definition: ri.h:675
#define type_void_p(x)
Definition: ri.h:2959
#define entity_type(x)
Definition: ri.h:2792

References callee, callees_callees, CAR, complexity_fprint(), db_get_memory_resource(), debug(), DO_PRINT_STATS, entity_initial, entity_type, fprintf(), get_bool_property(), hash_pointer, hash_put(), hash_table_make(), MAPL, module_name(), module_name_to_entity(), NIL, pips_assert, PRINT_LOCAL_NAMES, STRING, translate_complexity_from_local_to_current_name(), type_functional_p, type_void_p, and value_code_p.

Referenced by any_complexities().

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

◆ fetch_complexity_parameters()

hash_table fetch_complexity_parameters ( char *  module_name)
Parameters
module_nameodule_name

Definition at line 901 of file comp_util.c.

903 {
904  hash_table hash_comp_params = hash_table_make(hash_pointer, 0);
905  char *parameters = strdup(get_string_property("COMPLEXITY_PARAMETERS"));
906  char *sep_chars = strdup(", ");
907  char *token = (char*) malloc(30);
908  entity e;
909 
911 
912  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
913  fprintf(stderr, "Fetching complexity parameters for module %s:\n",
914  module_name);
915  }
916 
917  token = strtok(parameters, sep_chars);
918 
919  while (token != NULL) {
922  token,
923  (char *) NULL),
924  entity_domain);
925  if (e != entity_undefined) {
926  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
927  fprintf(stderr, "{\t Defined entity %s }\n", entity_name(e));
928  }
929  hash_put(hash_comp_params,(char *)e,HASH_USER_VARIABLE);
930  }
931  else {
932  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
933  fprintf(stderr, "{\t Undefined token %s }\n", token);
934  }
935  }
936  token = strtok(NULL, sep_chars);
937  }
938 
939  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
940  fprintf(stderr, "Fetching complexity parameters: ...done.\n");
941  }
942 
943  return(hash_comp_params);
944 }
#define HASH_USER_VARIABLE
char * get_string_property(const char *)
void * malloc(YYSIZE_T)
void hash_warn_on_redefinition(void)
these function set the variable should_i_warn_on_redefinition to the value true or false
Definition: hash.c:183
#define MODULE_SEP_STRING
Definition: naming-local.h:30
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void * gen_find_tabulated(const char *, int)
Definition: tabulated.c:218
#define entity_undefined
Definition: ri.h:2761
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410

References concatenate(), entity_domain, entity_name, entity_undefined, fprintf(), gen_find_tabulated(), get_bool_property(), get_string_property(), hash_pointer, hash_put(), hash_table_make(), HASH_USER_VARIABLE, hash_warn_on_redefinition(), malloc(), module_name(), MODULE_SEP_STRING, and strdup().

Referenced by any_complexities().

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

◆ final_statement_to_complexity_evaluation()

complexity final_statement_to_complexity_evaluation ( complexity  comp,
transformer  precond,
list  effects_list 
)
Parameters
compomp
precondrecond
effects_listffects_list

Definition at line 1052 of file comp_util.c.

1056 {
1057  complexity final_comp = complexity_dup(comp);
1058  Ppolynome pp = complexity_polynome(comp);
1060 
1061 
1062  fprintf(stderr, "Final evaluation\n");
1063 
1064  for ( ; !VECTEUR_NUL_P(pb); pb = pb->succ) {
1065  bool mustbewritten;
1066  char *var = variable_local_name(pb->var);
1067 
1068  fprintf(stderr, "Variable is %s\n", var);
1069 
1070  mustbewritten = is_must_be_written_var(effects_list, var);
1071 
1072  if ( mustbewritten ) {
1073  complexity compsubst;
1074  fprintf(stderr, "YES once\n");
1075  compsubst = evaluate_var_to_complexity((entity)pb->var,
1076  precond,
1077  effects_list, 1);
1078  complexity_fprint( stderr, compsubst, false, false);
1079 /*
1080 
1081  final_comp = complexity_var_subst(comp, pb->var, compsubst);
1082 */
1083  }
1084  comp = complexity_dup(final_comp);
1085  }
1086 
1087  complexity_fprint( stderr, final_comp, false, false);
1088 
1089  return ( final_comp );
1090 }
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,...
bool is_must_be_written_var(list effects_list, char *var_name)
Definition: comp_util.c:1014
complexity complexity_dup(complexity comp)
duplicates complexity comp
Definition: comp_util.c:131
int default_is_inferior_pvarval(Pvecteur *pvarval1, Pvecteur *pvarval2)
bool default_is_inferior_pvarval(Pvecteur * pvarval1, Pvecteur * pvarval2) return true if var1 is bef...
Definition: pnome-io.c:286
Pbase polynome_used_var(Ppolynome pp, int *is_inferior_var)
Pbase polynome_used_var(Ppolynome pp, bool *is_inferior_var()) PRIVATE Returns, in a Pbase,...
Definition: pnome-reduc.c:204
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
Definition: vecteur-local.h:89
Variable var
Definition: vecteur-local.h:90
struct Svecteur * succ
Definition: vecteur-local.h:92
#define VECTEUR_NUL_P(v)
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.
Definition: alloc.c:51

References complexity_dup(), complexity_fprint(), complexity_polynome(), default_is_inferior_pvarval(), evaluate_var_to_complexity(), fprintf(), is_must_be_written_var(), polynome_used_var(), Svecteur::succ, Svecteur::var, variable_local_name(), vect_dup(), and VECTEUR_NUL_P.

+ Here is the call graph for this function:

◆ fprint_cost_table()

void fprint_cost_table ( FILE *  fd)
Parameters
fdd

Definition at line 481 of file comp_util.c.

483 {
485  bool skip_one_line = false;
486 
487  fprintf(fd, "\nIntrinsic cost table:\n\n");
488  fprintf(fd, " Intrinsic name int float double complex dcomplex\n");
489  fprintf(fd, "------------------------------------------------------------------------\n");
490 
491  for(; p->name != NULL ;p++) {
492  if (1 ||(p->int_cost != 0) ||
493  (p->float_cost != 0) ||
494  (p->double_cost != 0) ||
495  (p->complex_cost != 0) ||
496  (p->dcomplex_cost != 0)) {
497  if (skip_one_line) {
498  fprintf(fd, "%25s|\n", "");
499  skip_one_line = false;
500  }
501  fprintf(fd, "%22.21s |%6td %6td %7td %8td %8td\n",
502  p->name, p->int_cost, p->float_cost,
504  }
505  else
506  skip_one_line = true;
507  }
508  fprintf(fd, "\n");
509 }
intrinsic_cost_record intrinsic_cost_table[]
The table intrinsic_cost_table[] gathers cost information of each intrinsic's cost; those costs are d...
Definition: comp_util.c:286
Intrinsics costs defines.

References intrinsic_cost_rec::complex_cost, intrinsic_cost_rec::dcomplex_cost, intrinsic_cost_rec::double_cost, intrinsic_cost_rec::float_cost, fprintf(), intrinsic_cost_rec::int_cost, intrinsic_cost_table, and intrinsic_cost_rec::name.

Referenced by any_complexities().

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

◆ fprint_statement_complexity()

void fprint_statement_complexity ( entity  module,
statement  stat,
hash_table  hash_statement_to_complexity 
)
Parameters
moduleodule
stattat
hash_statement_to_complexityash_statement_to_complexity

Definition at line 253 of file comp_util.c.

257 {
258  text t = Text_Statement(module, 0, stat);
259  complexity comp;
260 
261  comp = ((complexity) hash_get(hash_statement_to_complexity,(char *)stat));
262  if (COMPLEXITY_UNDEFINED_P(comp))
263  pips_internal_error("undefined complexity");
264  else {
265  fprintf(stderr, "C -- ");
267  }
268  print_text(stderr, t);
269 }
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
text Text_Statement(entity, int, statement)
void print_text(FILE *fd, text t)
Definition: print.c:195

References complexity_fprint(), COMPLEXITY_UNDEFINED_P, DO_PRINT_STATS, fprintf(), hash_get(), module, pips_internal_error, PRINT_LOCAL_NAMES, print_text(), and Text_Statement().

+ Here is the call graph for this function:

◆ free_callees_complexities()

hash_table free_callees_complexities ( hash_table  h)

Modified copies of the summary complexities are stored

Definition at line 812 of file comp_util.c.

813 {
814  /* Modified copies of the summary complexities are stored */
815  hash_table_clear(h);
816  hash_table_free(h);
817 
818  return hash_table_undefined;
819 }
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
void hash_table_clear(hash_table htp)
Clears all entries of a hash table HTP.
Definition: hash.c:305
#define hash_table_undefined
Value of an undefined hash_table.
Definition: newgen_hash.h:49

References hash_table_clear(), hash_table_free(), and hash_table_undefined.

Referenced by any_complexities().

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

◆ good_complexity_assert()

void good_complexity_assert ( _UNUSED_ string  function,
complexity  comp 
)

Definition at line 124 of file comp_util.c.

125 {
126  if (!complexity_check(comp))
127  pips_internal_error("bad internal complexity representation");
128 }

References complexity_check(), and pips_internal_error.

+ Here is the call graph for this function:

◆ init_cost_table()

void init_cost_table ( void  )

Completes the intrinsic cost table with the costs read from the files specified in the "COMPLEXITY_COST_TABLE" string property See properties.rc and ~pips/Pips/pipsrc.csh for more information.

L. ZHOU 13/03/91

COST_DATA are names of five data files

Definition at line 519 of file comp_util.c.

520 {
521  char *token, *comma, *filename ;
522  float file_factor;
523 
524  char *cost_data = strdup(COST_DATA);
525  char *tmp=NULL;
526 
527  for(token = strtok(cost_data, " "); (token != NULL);token = strtok(NULL, " ")) {
528  comma = strchr(token, ',');
529 
530  if (comma == NULL) {
531  tmp=strdup(token);
532  file_factor = 1.0;
533  }
534  else {
535  int ii = comma - token;
536  tmp=strndup( token, ii);
537  sscanf(++comma, "%f", &file_factor);
538  }
539 
540 
541  filename = strdup(concatenate( COMPLEXITY_COST_TABLES "/", get_string_property("COMPLEXITY_COST_TABLE"), "/", tmp, NULL));
542 
543  debug(5,"init_cost_table","file_factor is %f\n", file_factor);
544  debug(1,"init_cost_table","cost file is %s\n",filename);
545 
546  load_cost_file(fopen_config(filename,NULL,"PIPS_COSTDIR"), file_factor);
547  free(tmp);
548  free(filename);
549  }
550 
551 }
void load_cost_file(FILE *fd, float file_factor)
Load (some) intrinsics costs from file "fd", multiplying them by "file_factor".
Definition: comp_util.c:557
#define COST_DATA
defined complexity data file names here.
FILE * fopen_config(const char *canonical_name, const char *cproperty, const char *cenv)
Definition: file.c:952
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
Definition: strndup.c:26

References concatenate(), COST_DATA, debug(), fopen_config(), free(), get_string_property(), load_cost_file(), strdup(), and strndup().

Referenced by any_complexities(), generic_print_xml_application(), and print_xml_code().

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

◆ intrinsic_cost()

int intrinsic_cost ( char *  s,
basic pargsbasic 
) const

Return the cost of the intrinsic named s, knowing that the "basic" type of its biggest argument is *pargsbasic.

Update *pargsbasic if the intrinsic returns a number of bigger complexity.

Inserted by AP, oct 24th 1995

To satisfy cproto . LZ 02 Feb. 93

Definition at line 617 of file comp_util.c.

620 {
621  struct intrinsic_cost_rec *p;
622  basic b;
623 
624  for (p = intrinsic_cost_table; p->name != NULL; p++) {
625  if (same_string_p(p->name, s)) {
626 
627  /* Inserted by AP, oct 24th 1995 */
628  if (same_string_p(p->name, "LOG") || same_string_p(p->name, "LOG10")) {
629  user_warning("intrinsic_cost", "LOG or LOG10 functions used\n");
630  }
631 
632  b = make_basic(p->min_basic_result, (void *) p->min_nbytes_result);
633  if (is_inferior_basic(*pargsbasic, b)) {
634  free_basic(*pargsbasic);
635  *pargsbasic = simple_basic_dup(b);
636  }
637 
638  switch (basic_tag(*pargsbasic)) {
639  case is_basic_int:
640  return(p->int_cost);
641  case is_basic_float:
642  return (basic_float(*pargsbasic) <= FLOAT_NBYTES ?
643  p->float_cost : p->double_cost);
644  case is_basic_complex:
645  return (basic_complex(*pargsbasic) <= COMPLEX_NBYTES ?
646  p->complex_cost : p->dcomplex_cost);
647  case is_basic_string:
648  return (STRING_INTRINSICS_COST);
649  case is_basic_logical:
650  return (LOGICAL_INTRINSICS_COST);
651  default:
652  pips_internal_error("basic tag is %d", basic_tag(*pargsbasic));
653  }
654  }
655  }
656  /* To satisfy cproto . LZ 02 Feb. 93 */
657  return (STRING_INTRINSICS_COST);
658 }
basic make_basic(enum basic_utype tag, void *val)
Definition: ri.c:155
void free_basic(basic p)
Definition: ri.c:107
#define STRING_INTRINSICS_COST
#define LOGICAL_INTRINSICS_COST
#define FLOAT_NBYTES
#define COMPLEX_NBYTES
#define same_string_p(s1, s2)
basic simple_basic_dup(basic)
Definition: type.c:2735
bool is_inferior_basic(basic, basic)
bool is_inferior_basic(basic1, basic2) return true if basic1 is less complex than basic2 ex: int is l...
Definition: type.c:2687
@ is_basic_string
Definition: ri.h:576
@ is_basic_float
Definition: ri.h:572
@ is_basic_int
Definition: ri.h:571
@ is_basic_logical
Definition: ri.h:573
@ is_basic_complex
Definition: ri.h:575
#define basic_float(x)
Definition: ri.h:619
#define basic_complex(x)
Definition: ri.h:628

References basic_complex, basic_float, basic_tag, intrinsic_cost_rec::complex_cost, COMPLEX_NBYTES, intrinsic_cost_rec::dcomplex_cost, intrinsic_cost_rec::double_cost, intrinsic_cost_rec::float_cost, FLOAT_NBYTES, free_basic(), intrinsic_cost_rec::int_cost, intrinsic_cost_table, is_basic_complex, is_basic_float, is_basic_int, is_basic_logical, is_basic_string, is_inferior_basic(), LOGICAL_INTRINSICS_COST, make_basic(), intrinsic_cost_rec::min_basic_result, intrinsic_cost_rec::min_nbytes_result, intrinsic_cost_rec::name, pips_internal_error, same_string_p, simple_basic_dup(), STRING_INTRINSICS_COST, and user_warning.

Referenced by call_to_complexity(), loop_to_complexity(), reference_to_complexity(), and syntax_to_complexity().

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

◆ is_linear_unstructured()

bool is_linear_unstructured ( unstructured  unstr)

return true if unstr is simply a linear string of controls

Parameters
unstrnstr

Definition at line 738 of file comp_util.c.

740 {
742  control exit = unstructured_exit(unstr);
743 
744  while (current != exit) {
746 
747  if (succs == NIL)
748  pips_internal_error("control != exit one,it has no successor");
749  if (CDR(succs) != NIL)
750  return (false);
751  current = CONTROL(CAR(succs));
752  }
753 
754  return(true);
755 }
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define exit(code)
Definition: misc-local.h:54
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define CONTROL(x)
CONTROL.
Definition: ri.h:910
#define control_successors(x)
Definition: ri.h:945
#define unstructured_exit(x)
Definition: ri.h:3006
static size_t current
Definition: string.c:115

References CAR, CDR, CONTROL, control_successors, current, exit, NIL, pips_internal_error, unstructured_control, and unstructured_exit.

◆ is_must_be_written_var()

bool is_must_be_written_var ( list  effects_list,
char *  var_name 
)

fprintf(stderr, "is_must_be_written_var for entity %s\n", module_local_name(e) );

Parameters
effects_listffects_list
var_namear_name

Definition at line 1014 of file comp_util.c.

1017 {
1018  MAPL(ce, {
1019  effect eff = EFFECT(CAR(ce));
1020 
1021  if(eff == effect_undefined)
1022  pips_internal_error("unexpected effect undefined");
1023 
1024  if ( action_write_p(effect_action(eff))
1027  entity e = reference_variable(r);
1028 /*
1029  fprintf(stderr, "is_must_be_written_var for entity %s\n",
1030  module_local_name(e) );
1031 */
1032  if ( strcmp(module_local_name(e), var_name) == 0 ) {
1033  return (true);
1034  }
1035  }
1036 /*
1037  else {
1038  fprintf(stderr, "is_must_be_written_var for NOT entity %s\n",
1039  module_local_name(reference_variable(effect_any_reference(eff))) );
1040  }
1041 */
1042  },effects_list);
1043 
1044  return (false);
1045 }
#define effect_undefined
Definition: effects.h:614
#define action_write_p(x)
Definition: effects.h:314

References action_write_p, approximation_exact_p, CAR, EFFECT, effect_action, effect_any_reference, effect_approximation, effect_undefined, MAPL, module_local_name(), pips_internal_error, and reference_variable.

Referenced by final_statement_to_complexity_evaluation().

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

◆ load_cost_file()

void load_cost_file ( FILE *  fd,
float  file_factor 
)

Load (some) intrinsics costs from file "fd", multiplying them by "file_factor".

Definition at line 557 of file comp_util.c.

560 {
561  char *line = (char*) malloc(199);
562  char *intrinsic_name = (char*) malloc(30);
563  int int_cost, float_cost, double_cost, complex_cost, dcomplex_cost;
564  struct intrinsic_cost_rec *p;
565  float scale_factor = 1.0;
566  bool recognized;
567 
568  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
569  fprintf(stderr, "\nReading cost file ");
570  if (file_factor != 1.0)
571  fprintf(stderr, "(x %.2f)", file_factor);
572  }
573 
574  while (fgets(line, 99, fd) != NULL) {
575  if (*line == '%')
576  sscanf(line+1, "%f", &scale_factor);
577  else if ((*line != '#') && (*line != '\n')) {
578  sscanf(line, "%s %d %d %d %d %d", intrinsic_name,
581  recognized = false;
582  for (p = intrinsic_cost_table; p->name != NULL; p++) {
583  if (same_string_p(p->name, intrinsic_name)) {
584  p->int_cost = (int)
585  (int_cost * scale_factor * file_factor + 0.5);
586  p->float_cost = (int)
587  (float_cost * scale_factor * file_factor + 0.5);
588  p->double_cost = (int)
589  (double_cost * scale_factor * file_factor + 0.5);
590  p->complex_cost = (int)
591  (complex_cost * scale_factor * file_factor + 0.5);
592  p->dcomplex_cost = (int)
593  (dcomplex_cost * scale_factor * file_factor + 0.5);
594  recognized = true;
595  break;
596  }
597  }
598  if (!recognized)
599  user_warning("load_cost_file",
600  "%s:unrecognized intrinsic\n",intrinsic_name);
601  }
602  }
603  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
604  fprintf(stderr, "\nScale factor is %f\n", scale_factor);
605  }
606  fclose(fd);
607 
608  free(intrinsic_name);
609  free(line);
610 }
void const char const char const int
static int line
FLEX_SCANNER.
Definition: scanner.c:852

References intrinsic_cost_rec::complex_cost, intrinsic_cost_rec::dcomplex_cost, intrinsic_cost_rec::double_cost, intrinsic_cost_rec::float_cost, fprintf(), free(), get_bool_property(), int, intrinsic_cost_rec::int_cost, intrinsic_cost_table, line, malloc(), intrinsic_cost_rec::name, same_string_p, and user_warning.

Referenced by init_cost_table().

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

◆ prc()

void prc ( complexity  comp)
Parameters
compfor dbxtool: "print complexity"

Definition at line 233 of file comp_util.c.

235 {
236  complexity_fprint(stderr, comp, true, true);
237 }

References complexity_fprint().

Referenced by pvecteur_to_polynome().

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

◆ prp()

void prp ( Ppolynome  pp)
Parameters
ppfor dbxtool: "print polynome"

Definition at line 239 of file comp_util.c.

241 {
243  fprintf(stderr, "\n");
244 }
void polynome_fprint(FILE *fd, Ppolynome pp, char *(*variable_name)(Variable), int *is_inferior_var)
void polynome_fprint(FILE* fd, Ppolynome pp, char* (*variable_name)(), bool (*is_inferior_var)()) Out...
Definition: pnome-io.c:173

References fprintf(), is_inferior_pvarval(), polynome_fprint(), and variable_name().

Referenced by complexity_sigma().

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

◆ prv()

void prv ( Pvecteur  pv)
Parameters
pvfor dbxtool: "print vecteur (as a monome)"

Definition at line 246 of file comp_util.c.

248 {
250  fprintf(stderr, "\n");
251 }
void vect_fprint_as_monome(FILE *f, Pvecteur v, Pbase b, get_variable_name_t variable_name, char *mult_symbol)
void vect_fprint_as_monome(FILE * f, Pvecteur v, Pbase b, char * (*variable_name)(),...
Definition: io.c:201
#define BASE_NULLE
MACROS SUR LES BASES.

References BASE_NULLE, fprintf(), variable_name(), and vect_fprint_as_monome().

Referenced by sc_projection_optim_along_vecteur_ofl().

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

◆ remove_common_variables_from_hash_table()

void remove_common_variables_from_hash_table ( entity  module,
hash_table  hash_complexity_params 
)
Parameters
moduleodule
hash_complexity_paramsash_complexity_params

Definition at line 985 of file comp_util.c.

988 {
989  const char* module_name = module_local_name(module);
990  list sefs_list;
991 
992  pips_assert("remove_common_variables_from_hash_table",
994 
995  sefs_list = effects_to_list( (effects)
996  db_get_memory_resource(DBR_SUMMARY_EFFECTS, module_name, true));
997 
998  MAPL(ce, {
999  effect obj = EFFECT(CAR(ce));
1001  action ac = effect_action(obj);
1003  entity e = reference_variable(r);
1004 
1005  if ( action_read_p(ac) && approximation_exact_p(ap) ) {
1006  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
1007  fprintf(stderr, "%s deleted\n", module_local_name(e));
1008  }
1009  hash_del(hash_complexity_params, (char *) module_local_name(e));
1010  }
1011  }, sefs_list);
1012 }
void * hash_del(hash_table htp, const void *key)
this function removes from the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:439

References action_read_p, approximation_exact_p, CAR, db_get_memory_resource(), EFFECT, effect_action, effect_any_reference, effect_approximation, effects_to_list(), entity_module_p(), fprintf(), get_bool_property(), hash_del(), MAPL, module, module_local_name(), module_name(), pips_assert, and reference_variable.

Referenced by any_complexities().

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

◆ remove_formal_parameters_from_hash_table()

void remove_formal_parameters_from_hash_table ( entity  mod,
hash_table  hash_complexity_params 
)
Parameters
modod
hash_complexity_paramsash_complexity_params

Definition at line 791 of file comp_util.c.

794 {
795  list decl;
796 
797  pips_assert("remove_formal_parameters_from_hash_table",
798  entity_module_p(mod));
800 
801  MAPL(pe, {
802  entity param = ENTITY(CAR(pe));
804  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
805  fprintf(stderr,"storage_formal %s to be deleted\n",
806  entity_name(param));
807  }
808  hash_del(hash_complexity_params, (char *) module_local_name(param));
809  }, decl);
810 }

References CAR, code_declarations, ENTITY, entity_initial, entity_module_p(), entity_name, entity_storage, fprintf(), get_bool_property(), hash_del(), MAPL, module_local_name(), pips_assert, storage_formal_p, and value_code.

Referenced by any_complexities().

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

◆ trace_off()

void trace_off ( void  )

"trace off"

Definition at line 714 of file comp_util.c.

715 {
716  if (get_bool_property("COMPLEXITY_TRACE_CALLS")) {
717  char *indentstring = (char*) malloc(99);
718  bool b = (call_level >= 0);
719  int i,k=1;
720 
721  indentstring[0] = '\0';
722  call_level--;
723  for (i=0; i< (b ? call_level : - call_level); i++) {
724  indentstring = strcat(indentstring,
725  strdup(b ? ( (k>0) ? INDENT_BLANKS
726  : INDENT_VLINE )
727  : INDENT_BACK));
728  k = ( k<INDENT_INTERVAL ? k+1 : 0 );
729  }
730  fprintf(stderr, "%s<\n", indentstring);
731  free(indentstring);
732  }
733 }
#define INDENT_BACK
Definition: comp_util.c:92
#define INDENT_VLINE
Definition: comp_util.c:91
static int call_level
"trace on"
Definition: comp_util.c:683
#define INDENT_INTERVAL
Definition: comp_util.c:93
#define INDENT_BLANKS
comp_util.c
Definition: comp_util.c:90

References call_level, fprintf(), free(), get_bool_property(), INDENT_BACK, INDENT_BLANKS, INDENT_INTERVAL, INDENT_VLINE, malloc(), and strdup().

Referenced by any_complexities(), arguments_to_complexity(), block_to_complexity(), call_to_complexity(), call_to_polynome(), cast_to_polynome(), evaluate_var_to_complexity(), expression_to_complexity(), expression_to_complexity_polynome(), indices_to_complexity(), instruction_to_complexity(), loop_to_complexity(), new_block_to_complexity(), normalized_to_polynome(), pvecteur_to_polynome(), range_to_complexity(), range_to_polynome(), reference_to_complexity(), reference_to_polynome(), statement_to_complexity(), summary_complexity(), syntax_to_complexity(), syntax_to_polynome(), test_to_complexity(), and unstructured_to_complexity().

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

◆ trace_on()

void trace_on ( char *  fmt,
  ... 
)
Parameters
fmtmt

Definition at line 684 of file comp_util.c.

685 {
686  if (get_bool_property("COMPLEXITY_TRACE_CALLS")) {
687  va_list args;
688  char *indentstring = (char*) malloc(99);
689  bool b = (call_level >= 0);
690  int i,k=1;
691 
692  indentstring[0] = '\0';
693 
694  for (i=0; i< (b ? call_level : - call_level); i++) {
695  indentstring = strcat(indentstring,
696  strdup(b ? ( (k>0) ? INDENT_BLANKS
697  : INDENT_VLINE )
698  : INDENT_BACK));
699  k = ( k<INDENT_INTERVAL ? k+1 : 0 );
700  }
701 
702  fprintf(stderr, "%s>", indentstring);
703  va_start(args, fmt);
704  vfprintf(stderr, fmt, args);
705  fprintf(stderr, "\n");
706  va_end(args);
707 
708  free(indentstring);
709  call_level++;
710  }
711 }

References call_level, fprintf(), free(), get_bool_property(), INDENT_BACK, INDENT_BLANKS, INDENT_INTERVAL, INDENT_VLINE, malloc(), and strdup().

Referenced by any_complexities(), arguments_to_complexity(), block_to_complexity(), call_to_complexity(), call_to_polynome(), cast_to_polynome(), evaluate_var_to_complexity(), expression_to_complexity(), expression_to_complexity_polynome(), indices_to_complexity(), instruction_to_complexity(), loop_to_complexity(), new_block_to_complexity(), normalized_to_polynome(), pvecteur_to_polynome(), range_to_complexity(), range_to_polynome(), reference_to_complexity(), reference_to_polynome(), statement_to_complexity(), summary_complexity(), syntax_to_complexity(), syntax_to_polynome(), test_to_complexity(), and unstructured_to_complexity().

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

◆ translate_complexity_from_local_to_current_name()

complexity translate_complexity_from_local_to_current_name ( complexity  callee_comp,
string  oldname,
string  newname 
)

translate_complexity_from_local_to_current_name(callee_comp,oldname,newname) B:M -> A:M if A calls B 5 Feb.

93 LZ

This is not general enough to handle: B:M -> A:N or B:M to A:N+1 FI, 3 March 1994

constant complexity

The basis associated to a polynomial includes the constant term!

constant complexity

Parameters
callee_compallee_comp
oldnameldname
newnameewname

Definition at line 1100 of file comp_util.c.

1103 {
1104  Ppolynome pp = complexity_polynome(callee_comp);
1106  Pbase pbcur = BASE_UNDEFINED;
1108  complexity old_comp = complexity_dup(callee_comp);
1109 
1110  if(BASE_NULLE_P(pb)) {
1111  /* constant complexity */
1112  comp = complexity_dup(callee_comp);
1113  return comp;
1114  }
1115 
1116  /* The basis associated to a polynomial includes the constant term! */
1117  if(base_dimension(pb)==1 && term_cst(pb)) {
1118  /* constant complexity */
1119  comp = complexity_dup(callee_comp);
1120  return comp;
1121  }
1122 
1123  for (pbcur=pb; pbcur != VECTEUR_NUL ; pbcur = pbcur->succ ) {
1124  Variable var = pbcur->var;
1125  char * stmp = strdup(variable_name(var));
1126 
1127  char *s = stmp;
1128  char *t = strchr(stmp,':');
1129 
1130  if ( t != NULL ) {
1131  int length = (int)(t - s);
1132  char *cur_name = (char *)malloc(100);
1133 
1134  (void) strncpy(cur_name,stmp,length);
1135  * (cur_name+length) = '\0';
1136 
1137  if ( 1 || strncmp(cur_name, oldname, length) == 0 ) {
1138  Variable newvar = name_to_variable(concatenate(strdup(newname),
1139  ":",strdup(t+1),NULL));
1140  if ( newvar != (Variable) chunk_undefined ) {
1141  complexity compsubst = make_single_var_complexity(1.0, newvar);
1142 
1143 /*
1144  polynome_chg_var(&pp, var, newvar);
1145 */
1146  comp = complexity_var_subst(old_comp, var, compsubst);
1147  old_comp = complexity_dup(comp);
1148  }
1149  else {
1150  comp = complexity_dup(old_comp);
1151  old_comp = complexity_dup(comp);
1152  }
1153  }
1154  }
1155  }
1156  return (comp);
1157 }
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
complexity make_single_var_complexity(float f, Variable var)
make a complexity "f * var" with null statistics
Definition: comp_math.c:220
Variable name_to_variable(char *)
Definition: polynome_ri.c:172
#define chunk_undefined
obsolete
Definition: genC.h:79
#define VECTEUR_NUL
DEFINITION DU VECTEUR NUL.
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 BASE_UNDEFINED
#define term_cst(varval)
#define base_dimension(b)
#define BASE_NULLE_P(b)

References base_dimension, BASE_NULLE_P, BASE_UNDEFINED, chunk_undefined, complexity_dup(), complexity_polynome(), complexity_var_subst(), concatenate(), int, is_inferior_pvarval(), make_single_var_complexity(), make_zero_complexity(), malloc(), name_to_variable(), polynome_used_var(), strdup(), Svecteur::succ, term_cst, Svecteur::var, variable_name(), and VECTEUR_NUL.

Referenced by fetch_callees_complexities().

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

Variable Documentation

◆ call_level

int call_level =0
static

"trace on"

Definition at line 683 of file comp_util.c.

Referenced by trace_off(), and trace_on().

◆ intrinsic_cost_table

intrinsic_cost_record intrinsic_cost_table[]

The table intrinsic_cost_table[] gathers cost information of each intrinsic's cost; those costs are dynamically loaded from user files.

It also returns the "minimum" type of the result of each intrinsic, specified by its basic_tag and number of memory bytes. ("bigger" and "minimum" refer to the order relation defined in the routine "is_inferior_basic"; the tag is_basic_overloaded is used as a don't care tag) (ex: SIN has a type of FLOAT even if its arg is an INT)

Modif: – LOOP_OVERHEAD and CALL_OVERHEAD are added, 280993 LZ – LOOP_OVERHEAD is divided into two: INIT and BRAANCH 081093 LZ

Definition at line 286 of file comp_util.c.

Referenced by fprint_cost_table(), intrinsic_cost(), and load_cost_file().