PIPS
comp_scan.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 "database.h"
#include "ri-util.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "resources.h"
#include "properties.h"
#include "text-util.h"
#include "misc.h"
#include "matrice.h"
#include "semantics.h"
#include "effects-simple.h"
#include "effects-generic.h"
#include "transformer.h"
#include "complexity.h"
+ Include dependency graph for comp_scan.c:

Go to the source code of this file.

Functions

bool uniform_complexities (const string module_name)
 declares the static variable complexity_map and defines its access functions More...
 
bool fp_complexities (const string module_name)
 
bool any_complexities (const string module_name)
 
bool summary_complexity (const string module_name)
 
complexity statement_to_complexity (statement stat, transformer precon __attribute__((__unused__)), list eff_list __attribute__((__unused__)))
 starting point of Abstract Syntax Tree More...
 
complexity instruction_to_complexity (instruction instr, transformer precond, list effects_list)
 The only element available of the statement. More...
 
complexity block_to_complexity (list block, transformer precond, list effects_list)
 1st element of instruction More...
 
complexity test_to_complexity (test test_instr, transformer precond, list effects_list)
 2nd element of instruction More...
 
complexity loop_to_complexity (loop loop_instr, transformer precond, list effects_list)
 3rd element of instruction More...
 
complexity goto_to_complexity (statement st __attribute__((__unused__)), transformer precond __attribute__((__unused__)), list effects_list __attribute__((__unused__)))
 4th element of instruction More...
 
complexity whileloop_to_complexity (whileloop while_instr, transformer precond, list effects_list)
 5th element of instruction More...
 
complexity call_to_complexity (call call_instr, basic *pbasic, transformer precond, list effects_list)
 3rd element of syntax More...
 
complexity arguments_to_complexity (list exprlist, basic *pbasic, transformer precond, list effects_list)
 2nd element of call More...
 
complexity expression_to_complexity (expression expr, basic *pbasic, transformer precond, list effects_list)
 2nd element of call –arguments More...
 
complexity subscript_to_complexity (subscript sub, basic *pbasic, transformer precond, list effects_list)
 
complexity syntax_to_complexity (syntax s, basic *pbasic, transformer precond, list effects_list)
 the only available element of expression More...
 
complexity reference_to_complexity (reference ref, basic *pbasic, transformer precond, list effects_list)
 1st element of syntax More...
 
complexity indices_to_complexity (list exprlist, basic *pbasic, transformer precond, list effects_list)
 2nd element of reference More...
 
complexity range_to_complexity (range rng, transformer precond, list effects_list)
 2nd element of syntax More...
 

Variables

hash_table hash_callee_to_complexity = hash_table_undefined
 comp_expr_to_pnome.c More...
 
hash_table hash_complexity_parameters = hash_table_undefined
 

Function Documentation

◆ any_complexities()

bool any_complexities ( const string  module_name)

we may need to print preconditions for debugging purposes

Parameters
module_nameodule_name

Definition at line 99 of file comp_scan.c.

100 {
102  list effects_list = NIL;
103  entity module_entity;
104  statement module_stat;
105 
106  trace_on("complexities %s", (char *)module_name);
107  debug_on("COMPLEXITY_DEBUG_LEVEL");
108 
109  /* we may need to print preconditions for debugging purposes */
111  db_get_memory_resource(DBR_PRECONDITIONS, module_name, true));
113  db_get_memory_resource(DBR_CUMULATED_EFFECTS, module_name, true));
115  db_get_memory_resource(DBR_PROPER_EFFECTS, module_name, true));
118  db_get_memory_resource(DBR_CODE, module_name, true ) );
119 
120  module_entity = get_current_module_entity();
121  module_stat = get_current_module_statement();
122 
123  module_to_value_mappings(module_entity);
124 
125  precond = load_statement_precondition(module_stat);
126  effects_list = load_cumulated_rw_effects_list(module_stat);
127 
128  init_cost_table();
129 
130  if (get_bool_property("COMPLEXITY_PRINT_COST_TABLE"))
131  fprint_cost_table(stdout);
132 
134 
137 
140 
143 
144  (void)statement_to_complexity(module_stat, precond, effects_list);
145 
148 
151  debug_off();
152  trace_off();
153 
154  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
155  fprintf(stderr,"\n");
156  fprintf(stderr,"Before ------- COMPLEXITIES; module %s\n",module_name);
157  }
158 
159  DB_PUT_MEMORY_RESOURCE(DBR_COMPLEXITIES,
161  (char *) get_complexity_map() );
162  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
163  fprintf(stderr,"After ------- COMPLEXITIES; module %s\n",module_name);
164  }
165 
175 
176  return true;
177 }
hash_table hash_complexity_parameters
Definition: comp_scan.c:58
hash_table hash_callee_to_complexity
comp_expr_to_pnome.c
Definition: comp_scan.c:57
complexity statement_to_complexity(statement stat, transformer precon __attribute__((__unused__)), list eff_list __attribute__((__unused__)))
starting point of Abstract Syntax Tree
Definition: comp_scan.c:230
void remove_formal_parameters_from_hash_table(entity mod, hash_table hash_complexity_params)
Definition: comp_util.c:791
void remove_common_variables_from_hash_table(entity module, hash_table hash_complexity_params)
Definition: comp_util.c:985
void trace_on(char *fmt,...)
Definition: comp_util.c:684
hash_table free_callees_complexities(hash_table h)
Definition: comp_util.c:812
void add_common_variables_to_hash_table(entity module, hash_table hash_complexity_params)
Definition: comp_util.c:946
hash_table fetch_complexity_parameters(char *module_name)
Definition: comp_util.c:901
void trace_off()
"trace off"
Definition: comp_util.c:714
void add_formal_parameters_to_hash_table(entity mod, hash_table hash_complexity_params)
Definition: comp_util.c:768
void fprint_cost_table(FILE *fd)
Definition: comp_util.c:481
hash_table fetch_callees_complexities(char *module_name)
Definition: comp_util.c:821
void init_cost_table()
Completes the intrinsic cost table with the costs read from the files specified in the "COMPLEXITY_CO...
Definition: comp_util.c:519
statement_mapping get_complexity_map(void)
void reset_complexity_map(void)
void set_complexity_map(statement_mapping)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
list load_cumulated_rw_effects_list(statement)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
void reset_current_module_statement(void)
Reset the current module statement.
Definition: static.c:221
statement set_current_module_statement(statement)
Set the current module statement.
Definition: static.c:165
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
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
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
Definition: pipsdbm-local.h:66
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define MAKE_STATEMENT_MAPPING()
Definition: newgen-local.h:43
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define transformer_undefined
Definition: ri.h:2847
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
void module_to_value_mappings(entity m)
void module_to_value_mappings(entity m): build hash tables between variables and values (old,...
Definition: mappings.c:624
transformer load_statement_precondition(statement)
void reset_precondition_map(void)
void set_precondition_map(statement_mapping)
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
void free_value_mappings(void)
Normal call to free the mappings.
Definition: value.c:1212

References add_common_variables_to_hash_table(), add_formal_parameters_to_hash_table(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, fetch_callees_complexities(), fetch_complexity_parameters(), fprint_cost_table(), fprintf(), free_callees_complexities(), free_value_mappings(), get_bool_property(), get_complexity_map(), get_current_module_entity(), get_current_module_statement(), hash_callee_to_complexity, hash_complexity_parameters, init_cost_table(), load_cumulated_rw_effects_list(), load_statement_precondition(), MAKE_STATEMENT_MAPPING, module_name(), module_name_to_entity(), module_to_value_mappings(), NIL, remove_common_variables_from_hash_table(), remove_formal_parameters_from_hash_table(), reset_complexity_map(), reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_precondition_map(), reset_proper_rw_effects(), set_complexity_map(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_precondition_map(), set_proper_rw_effects(), statement_to_complexity(), strdup(), trace_off(), trace_on(), and transformer_undefined.

Referenced by fp_complexities(), and uniform_complexities().

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

◆ arguments_to_complexity()

complexity arguments_to_complexity ( list  exprlist,
basic pbasic,
transformer  precond,
list  effects_list 
)

2nd element of call

arguments_to_complexity Return the sum of the complexities of the list of expressions passed. Return also in *pbasic the basic of the "biggest" argument (int/float/double/...)

Parameters
exprlistxprlist
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 804 of file comp_scan.c.

809 {
811  basic abasic = MAKE_INT_BASIC;
812 
813  trace_on("arguments");
814 
815  *pbasic = MAKE_INT_BASIC;
816  MAPL (pa, {
817  expression e = EXPRESSION(CAR(pa));
818  complexity ctmp = expression_to_complexity(e, &abasic, precond, effects_list);
819  complexity_add(&comp, ctmp);
820  if (is_inferior_basic(*pbasic, abasic)) {
821  free_basic(*pbasic);
822  *pbasic = simple_basic_dup(abasic);
823  }
824  },exprlist);
825 
826  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
827  fprintf(stderr, "argument comp is at %p and value is ", comp);
828  complexity_fprint(stderr, comp, false, true);
829  }
830  complexity_check_and_warn("arguments_to_complexity", comp);
831 
832  trace_off();
833  return(comp);
834 }
void free_basic(basic p)
Definition: ri.c:107
void complexity_add(complexity *pcomp1, complexity comp2)
void complexity_add(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 + comp2; !...
Definition: comp_math.c:372
complexity make_zero_complexity()
make a zero complexity "0.0000 * TCST" with null statistics
Definition: comp_math.c:238
complexity expression_to_complexity(expression expr, basic *pbasic, transformer precond, list effects_list)
2nd element of call –arguments
Definition: comp_scan.c:838
void complexity_fprint(FILE *fd, complexity comp, bool print_stats_p, bool print_local_names_p)
Definition: comp_util.c:217
void complexity_check_and_warn(char *s, complexity comp) const
Definition: comp_util.c:108
#define MAKE_INT_BASIC
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#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
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
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217

References CAR, complexity_add(), complexity_check_and_warn(), complexity_fprint(), EXPRESSION, expression_to_complexity(), fprintf(), free_basic(), get_bool_property(), is_inferior_basic(), MAKE_INT_BASIC, make_zero_complexity(), MAPL, simple_basic_dup(), trace_off(), and trace_on().

Referenced by call_to_complexity().

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

◆ block_to_complexity()

complexity block_to_complexity ( list  block,
transformer  precond,
list  effects_list 
)

1st element of instruction

Modification:

  • To postpone the variable evaluation, we reverse the block. Attention: gen_nreverse destroys the original list. LZ 4 Dec. 92
  • Secondly, we check the variables in complexity. If a certain variable is must_be_written variable ( obtained from cumulated effects ), we evaluate it. LZ 5 Dec. 92
  • When the variable is must_be_written, the precondition is no longer available with this effect. So we need to use the next statement effect with current precondition to evaluate the variable. LZ 9 Dec. 92
  • Francois suggested not to create new list, ie, reverse block. Hence we don't use MAPL any more here. Instead, gen_nthcdr is used. 16 Dec 92
Parameters
blocklock
precondrecond
effects_listffects_list

Definition at line 344 of file comp_scan.c.

347 {
349  int block_length = gen_length( block );
350  int i;
351 
352  trace_on("block");
353 
354  if (get_bool_property("COMPLEXITY_EARLY_EVALUATION")) {
355  FOREACH(STATEMENT, stat, block) {
356  complexity ctemp = statement_to_complexity(stat, precond, effects_list);
357  complexity_add(&comp, ctemp);
358  }
359  }
360  else { // default property setting
361  for ( i = block_length; i > 0 ; i-- ) {
362  statement stat = STATEMENT(CAR(gen_nthcdr( i-1, block )));
363  statement up_stat;
365  complexity ctemp = statement_to_complexity(stat,
366  prec, effects_list);
367 
368  list cumu_list = load_cumulated_rw_effects_list(stat);
369  //extern int default_is_inferior_pvarval(Pvecteur *, Pvecteur *);
370 
371  Pbase pb = VECTEUR_NUL;
372 
373  if ( i > 1 ) {
374  up_stat = STATEMENT(CAR(gen_nthcdr( i-2, block )));
375  cumu_list = load_cumulated_rw_effects_list(up_stat);
376  }
377  complexity_add(&comp, ctemp);
378 
381 
382  for ( ; !VECTEUR_NUL_P(pb); pb = pb->succ) {
383  bool mustbewritten;
384  entity v = (entity) (pb->var);
385  //char *var = variable_local_name(pb->var);
386 
387  //mustbewritten = is_must_be_written_var(cumu_list, var);
388  mustbewritten = effects_write_variable_p(cumu_list, v);
389 
390  if ( mustbewritten ) {
391  complexity csubst;
392 
393  csubst = evaluate_var_to_complexity((entity)pb->var,
394  prec,
395  cumu_list, 1);
396  comp = complexity_var_subst(comp, pb->var, csubst);
397  }
398  }
399  }
400  }
401 
402  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
403  (void) complexity_consistent_p(comp);
404  fprintf(stderr, "block comp is at %p and comp value is ", comp);
405  complexity_fprint(stderr, comp, false, true);
406  }
407  complexity_check_and_warn("block_to_complexity", comp);
408 
409  trace_off();
410  return(comp);
411 }
bool complexity_consistent_p(complexity p)
Definition: complexity_ri.c:27
struct _newgen_struct_entity_ * entity
Definition: abc_private.h:14
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,...
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
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
bool effects_write_variable_p(list, entity)
Definition: effects.c:1091
size_t gen_length(const list l)
Definition: list.c:150
#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
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
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
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
DEFINITION DU VECTEUR NUL.
#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 CAR, complexity_add(), complexity_check_and_warn(), complexity_consistent_p(), complexity_fprint(), complexity_polynome(), complexity_var_subst(), default_is_inferior_pvarval(), effects_write_variable_p(), evaluate_var_to_complexity(), FOREACH, fprintf(), gen_length(), gen_nthcdr(), get_bool_property(), load_cumulated_rw_effects_list(), load_statement_precondition(), make_zero_complexity(), polynome_used_var(), STATEMENT, statement_to_complexity(), Svecteur::succ, trace_off(), trace_on(), Svecteur::var, vect_dup(), VECTEUR_NUL, and VECTEUR_NUL_P.

Referenced by instruction_to_complexity().

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

◆ call_to_complexity()

complexity call_to_complexity ( call  call_instr,
basic pbasic,
transformer  precond,
list  effects_list 
)

3rd element of syntax

The only case that hash_callee_to_complexity is used

transform formal params into real ones

if not format case

Parameters
call_instrall_instr
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 736 of file comp_scan.c.

741 {
743  entity f = call_function(call_instr);
744  list args= call_arguments(call_instr);
745  type t = entity_type(f);
746  value v = entity_initial(f);
747 
748  const char *name = module_local_name(f);
749 
750  trace_on("call %s", entity_name(f));
751 
752  pips_assert("call_to_complexity",
754 
755  switch (value_tag(v)) {
756  case is_value_code: {
757  complexity compcallee;
758 
759  /* The only case that hash_callee_to_complexity is used */
761  (char *) f);
762  if ( compcallee == COMPLEXITY_NOT_FOUND )
763  user_error("call_to_complexity", "unknown complexity\n");
764  /* transform formal params into real ones */
765  comp = replace_formal_parameters_by_real_ones(compcallee,
766  f, args,
767  precond,
768  effects_list);
769  break;
770  }
771  case is_value_symbolic:
772  case is_value_constant:
773  if ( !type_statement_p(t) ) /* if not format case */
774  *pbasic = entity_basic(f);
775  comp = make_zero_complexity();
776  break;
777  case is_value_intrinsic:
778  comp = arguments_to_complexity(args, pbasic, precond, effects_list);
779  complexity_float_add(&comp, (float) intrinsic_cost(name, pbasic));
780  break;
781  case is_value_unknown:
782  user_error("call_to_complexity", "unknown value");
783  default:
784  pips_internal_error("value_tag is %d not in 37->41", (int)value_tag(v));
785  }
786 
787  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
788  fprintf(stderr, "call '%s': ", name);
789  complexity_fprint(stderr, comp, false, true);
790  fprintf(stderr, "call comp is at %p\n", comp);
791  }
792  complexity_check_and_warn("call_to_complexity", comp);
793 
794  trace_off();
795  return(comp);
796 }
void complexity_float_add(complexity *pcomp, float f)
Add a floating point digit to the complexity May 3, 91.
Definition: comp_math.c:480
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
Definition: comp_math.c:519
complexity arguments_to_complexity(list exprlist, basic *pbasic, transformer precond, list effects_list)
2nd element of call
Definition: comp_scan.c:804
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 *p...
Definition: comp_util.c:617
#define COMPLEXITY_NOT_FOUND
struct _newgen_struct_complexity_ * complexity
Definition: complexity_ri.h:30
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
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define user_error(fn,...)
Definition: misc-local.h:265
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
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
#define type_functional_p(x)
Definition: ri.h:2950
#define value_tag(x)
Definition: ri.h:3064
#define call_function(x)
Definition: ri.h:709
#define type_statement_p(x)
Definition: ri.h:2941
@ is_value_intrinsic
Definition: ri.h:3034
@ is_value_unknown
Definition: ri.h:3035
@ is_value_constant
Definition: ri.h:3033
@ is_value_code
Definition: ri.h:3031
@ is_value_symbolic
Definition: ri.h:3032
#define type_void_p(x)
Definition: ri.h:2959
#define entity_name(x)
Definition: ri.h:2790
#define call_arguments(x)
Definition: ri.h:711
#define entity_type(x)
Definition: ri.h:2792
#define entity_initial(x)
Definition: ri.h:2796

References arguments_to_complexity(), call_arguments, call_function, complexity_check_and_warn(), complexity_float_add(), complexity_fprint(), COMPLEXITY_NOT_FOUND, entity_basic(), entity_initial, entity_name, entity_type, f(), fprintf(), get_bool_property(), hash_callee_to_complexity, hash_get(), intrinsic_cost(), is_value_code, is_value_constant, is_value_intrinsic, is_value_symbolic, is_value_unknown, make_zero_complexity(), module_local_name(), pips_assert, pips_internal_error, replace_formal_parameters_by_real_ones(), trace_off(), trace_on(), type_functional_p, type_statement_p, type_void_p, user_error, and value_tag.

Referenced by instruction_to_complexity(), and syntax_to_complexity().

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

◆ expression_to_complexity()

complexity expression_to_complexity ( expression  expr,
basic pbasic,
transformer  precond,
list  effects_list 
)

2nd element of call –arguments

2nd element of reference –indices

Parameters
exprxpr
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 838 of file comp_scan.c.

843 {
844  syntax s = expression_syntax(expr);
845  complexity comp = make_zero_complexity();// complexity_undefined;
846 
847  trace_on("expression");
848 
849  if ( s != syntax_undefined )
850  comp = syntax_to_complexity(s, pbasic, precond, effects_list);
851  else
852  pips_internal_error("syntax undefined");
853 
854  complexity_check_and_warn("expression_to_complexity", comp);
855 
856  trace_off();
857  return(comp);
858 }
complexity syntax_to_complexity(syntax s, basic *pbasic, transformer precond, list effects_list)
the only available element of expression
Definition: comp_scan.c:881
#define syntax_undefined
Definition: ri.h:2676
#define expression_syntax(x)
Definition: ri.h:1247

References complexity_check_and_warn(), expression_syntax, make_zero_complexity(), pips_internal_error, syntax_to_complexity(), syntax_undefined, trace_off(), and trace_on().

Referenced by arguments_to_complexity(), indices_to_complexity(), instruction_to_complexity(), range_to_complexity(), subscript_to_complexity(), syntax_to_complexity(), test_to_complexity(), and whileloop_to_complexity().

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

◆ fp_complexities()

bool fp_complexities ( const string  module_name)
Parameters
module_nameodule_name

Definition at line 89 of file comp_scan.c.

90 {
91  bool success = true;
92 
93  //set_string_property("COMPLEXITY_COST_TABLE", "fp_1");
95 
96  return success;
97 }
bool any_complexities(const string module_name)
Definition: comp_scan.c:99
bool success
Definition: gpips-local.h:59

References any_complexities(), and module_name().

+ Here is the call graph for this function:

◆ goto_to_complexity()

complexity goto_to_complexity ( statement st   __attribute__(__unused__),
transformer precond   __attribute__(__unused__),
list effects_list   __attribute__(__unused__) 
)

4th element of instruction

Definition at line 683 of file comp_scan.c.

686 {
687  pips_internal_error("A GOTO is remaining.");
688  return(make_zero_complexity());
689 }

References make_zero_complexity(), and pips_internal_error.

Referenced by instruction_to_complexity().

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

◆ indices_to_complexity()

complexity indices_to_complexity ( list  exprlist,
basic pbasic,
transformer  precond,
list  effects_list 
)

2nd element of reference

exactly the same with arguments_to_complexity I add this function in order to make the structure clearer Apr. 15,91

Parameters
exprlistxprlist
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 1057 of file comp_scan.c.

1062 {
1064  basic ibasic = MAKE_INT_BASIC;
1065 
1066  trace_on("indices");
1067 
1068  *pbasic = MAKE_INT_BASIC;
1069 
1070  MAPL (pa, {
1071  expression e = EXPRESSION(CAR(pa));
1072  complexity ctmp = expression_to_complexity(e, &ibasic, precond, effects_list);
1073  complexity_add(&comp, ctmp);
1074  complexity_rm(&ctmp);
1075 
1076  if (is_inferior_basic(*pbasic, ibasic)) {
1077  free_basic(*pbasic);
1078  *pbasic = simple_basic_dup(ibasic);
1079  }
1080  },exprlist);
1081 
1082  complexity_check_and_warn("indices_to_complexity", comp);
1083 
1084  trace_off();
1085  return(comp);
1086 }
void complexity_rm(complexity *pcomp)
remove complexity comp
Definition: comp_util.c:164

References CAR, complexity_add(), complexity_check_and_warn(), complexity_rm(), EXPRESSION, expression_to_complexity(), free_basic(), is_inferior_basic(), MAKE_INT_BASIC, make_zero_complexity(), MAPL, simple_basic_dup(), trace_off(), and trace_on().

Referenced by reference_to_complexity(), and subscript_to_complexity().

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

◆ instruction_to_complexity()

complexity instruction_to_complexity ( instruction  instr,
transformer  precond,
list  effects_list 
)

The only element available of the statement.

dummy parameter

dummy parameter

Parameters
instrnstr
precondrecond
effects_listffects_list

Definition at line 275 of file comp_scan.c.

279 {
280  complexity comp = make_zero_complexity();// complexity_undefined;
281 
282  trace_on("instruction");
283 
284  switch (instruction_tag(instr)) {
286  comp = block_to_complexity(instruction_block(instr), precond, effects_list);
287  break;
288  case is_instruction_test:
289  comp = test_to_complexity(instruction_test(instr), precond, effects_list);
290  break;
291  case is_instruction_loop:
292  comp = loop_to_complexity(instruction_loop(instr), precond, effects_list);
293  break;
295  comp= whileloop_to_complexity(instruction_whileloop(instr), precond, effects_list);
296  break;
297  case is_instruction_goto:
298  comp = goto_to_complexity(instruction_goto(instr), precond, effects_list);
299  break;
300  case is_instruction_call: {
301  basic callbasic = MAKE_INT_BASIC; /* dummy parameter */
302  comp = call_to_complexity(instruction_call(instr),
303  &callbasic, precond, effects_list);
304  break;
305  }
308  precond, effects_list);
309  break;
310  case is_instruction_expression: { // copied from is_instruction_call
311  basic callbasic = MAKE_INT_BASIC; /* dummy parameter */
313  &callbasic,
314  precond, effects_list);
315  break;
316  }
317  default:
318  pips_internal_error("instruction tag %d isn't in 14->19.",
319  (int) instruction_tag(instr));
320  }
321  complexity_check_and_warn("instruction_to_complexity", comp);
322 
323  trace_off();
324  return(comp);
325 }
complexity whileloop_to_complexity(whileloop while_instr, transformer precond, list effects_list)
5th element of instruction
Definition: comp_scan.c:692
complexity call_to_complexity(call call_instr, basic *pbasic, transformer precond, list effects_list)
3rd element of syntax
Definition: comp_scan.c:736
complexity loop_to_complexity(loop loop_instr, transformer precond, list effects_list)
3rd element of instruction
Definition: comp_scan.c:460
complexity test_to_complexity(test test_instr, transformer precond, list effects_list)
2nd element of instruction
Definition: comp_scan.c:414
complexity goto_to_complexity(statement st __attribute__((__unused__)), transformer precond __attribute__((__unused__)), list effects_list __attribute__((__unused__)))
4th element of instruction
Definition: comp_scan.c:683
complexity block_to_complexity(list block, transformer precond, list effects_list)
1st element of instruction
Definition: comp_scan.c:344
complexity unstructured_to_complexity(unstructured unstr, transformer precond, list effects_list)
6th element of instruction
Definition: comp_unstr.c:75
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
#define instruction_loop(x)
Definition: ri.h:1520
#define instruction_goto(x)
Definition: ri.h:1526
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_expression
Definition: ri.h:1478
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_expression(x)
Definition: ri.h:1541
#define instruction_whileloop(x)
Definition: ri.h:1523
#define instruction_call(x)
Definition: ri.h:1529
#define instruction_test(x)
Definition: ri.h:1517
#define instruction_unstructured(x)
Definition: ri.h:1532

References block_to_complexity(), call_to_complexity(), complexity_check_and_warn(), expression_to_complexity(), goto_to_complexity(), instruction_block, instruction_call, instruction_expression, instruction_goto, instruction_loop, instruction_tag, instruction_test, instruction_unstructured, instruction_whileloop, is_instruction_block, is_instruction_call, is_instruction_expression, is_instruction_goto, is_instruction_loop, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, loop_to_complexity(), MAKE_INT_BASIC, make_zero_complexity(), pips_internal_error, test_to_complexity(), trace_off(), trace_on(), unstructured_to_complexity(), and whileloop_to_complexity().

Referenced by statement_to_complexity().

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

◆ loop_to_complexity()

complexity loop_to_complexity ( loop  loop_instr,
transformer  precond,
list  effects_list 
)

3rd element of instruction

FI: Lei chose to allocate the UL and UU entities in the current module... Maybe, we are ready fo some dynamic profiling...

string mod_name = entity_module_name(ll);

if the statement were still reachable, we could try to use the statement nunber...

In order to get rid of at-sign, add 1 , LZ 010492

tell callees that they mustn't try to evaluate the loop index

cioh cboh are derived from overhead file "overhead" LZ, 280993

zero iteration for sure

at least one iteration

maybe some iteration

an intermediate test based on preconditions would give better result with affine loop bounds

Parameters
loop_instroop_instr
precondrecond
effects_listffects_list

Definition at line 460 of file comp_scan.c.

464 {
465  entity ll = loop_label (loop_instr);
466  entity index = loop_index(loop_instr);
467  range rng = loop_range(loop_instr);
468  statement s = loop_body(loop_instr);
469  execution ex = loop_execution(loop_instr);
470  complexity comp, cbody, crange, clower, cupper, cincr, cioh, cboh;
471  string sl,su,si;
472  /* FI: Lei chose to allocate the UL and UU entities in the current
473  module... Maybe, we are ready fo some dynamic profiling... */
474  /* string mod_name = entity_module_name(ll); */
475  basic ibioh = MAKE_INT_BASIC;
476  basic ibboh = MAKE_INT_BASIC;
477 
478  trace_on("loop %s label %s",entity_name(index),
479  entity_name(loop_label(loop_instr)));
480 
481  if ( empty_global_label_p(entity_name(ll)) ) {
482  /* if the statement were still reachable, we could try to use the
483  * statement nunber...
484  */
485  sl=strdup("UL_");
486  su=strdup("UU_");
487  si=strdup("UU_");
488  }
489  else {
490  /* In order to get rid of at-sign, add 1 , LZ 010492 */
491  asprintf(&sl,"UL_%s",entity_local_name(loop_label(loop_instr))+1);
492  asprintf(&su,"UU_%s",entity_local_name(loop_label(loop_instr))+1);
493  asprintf(&si,"UI_%s",entity_local_name(loop_label(loop_instr))+1);
494  }
495 
496  /* tell callees that they mustn't try to evaluate the loop index */
497 
500 
501  crange = range_to_complexity(rng, precond, effects_list);
502  cbody = statement_to_complexity(s, precond, effects_list);
503 
504  cioh = make_constant_complexity((float)
506  cboh = make_constant_complexity((float)
508  /* cioh cboh are derived from overhead file "overhead" LZ, 280993 */
509 
511 
512  if ( execution_parallel_p(ex) ) {
513  user_warning("loop_to_complexity", "DOALL not implemented yet\n");
514  }
515 
517  precond, effects_list,
519  if ( complexity_unknown_p(clower) ) {
520  /*
521  clower = make_single_var_complexity(1.0,
522  (Variable)FindOrCreateEntity(mod_name, sl));
523  */
526  clower = make_single_var_complexity(1.0,var);
527  }
528 
530  precond, effects_list,
532  if ( complexity_unknown_p(cupper) ) {
533  /*
534  cupper = make_single_var_complexity(1.0,
535  (Variable)FindOrCreateEntity(mod_name, su));
536  */
539  cupper = make_single_var_complexity(1.0,var);
540  }
541 
543  precond, effects_list,
545 
546  if ( complexity_constant_p(cincr) ) {
547  int incr = complexity_TCST(cincr);
548  if (incr == 0)
549  user_error("loop_to_complexity", "null increment\n");
550  else if ( incr < 0 ) {
551  complexity cswap;
552 
553  complexity_scalar_mult(&cincr, -1.0);
554  if ( incr != -1.0 ) {
555  complexity_div(&clower, cincr);
556  complexity_div(&cupper, cincr);
557  }
558  complexity_scalar_mult(&cincr, -1.0/incr);
559  cswap = clower;
560  clower = cupper;
561  cupper = cswap;
562  }
563  else if ( incr != 1) {
564  complexity_div(&clower, cincr);
565  complexity_div(&cupper, cincr);
566  complexity_scalar_mult(&cincr, 1.0/incr);
567  }
568  else if ( complexity_constant_p(clower) || complexity_constant_p(cupper) ) {
569  ;
570  }
571  }
572 
573  if ( complexity_constant_p(clower) && complexity_constant_p(cupper)) {
574  float lower = complexity_TCST(clower);
575  float upper = complexity_TCST(cupper);
576  if (lower>upper) {
577  /* zero iteration for sure */
578  comp = make_zero_complexity();
579  }
580  else {
581  /* at least one iteration */
582  comp = complexity_sigma(cbody, (Variable)index, clower, cupper);
583  }
584  }
585  else {
586  /* maybe some iteration */
587  comp = complexity_sigma(cbody, (Variable)index, clower, cupper);
588  /* an intermediate test based on preconditions would give better
589  result with affine loop bounds */
590  }
591 
592  /*
593  if ( !complexity_constant_p(cincr)
594  || complexity_constant_p(clower) || complexity_constant_p(cupper) ) {
595  complexity_div(&comp, cincr);
596  }
597  */
598 
599  if(!complexity_constant_p(cincr)) {
600  if(complexity_is_monomial_p(cincr) && complexity_degree(cincr)==1) {
601  complexity_div(&comp, cincr);
602  }
603  else {
604  free_complexity(cincr);
607  cincr = make_single_var_complexity(1.0,var);
608  }
609  }
610 
611  if ( complexity_constant_p(comp) && complexity_TCST(comp) < 0 )
612  comp = make_zero_complexity();
613 
614  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
615  fprintf(stderr, "\n");
616  fprintf(stderr, "@@@ body complexity: ");
617  complexity_fprint(stderr, cbody, false, true);
618  fprintf(stderr, "@@@ range complexity: ");
619  complexity_fprint(stderr, crange, false, true);
620  fprintf(stderr, "@@@ lower value : ");
621  complexity_fprint(stderr, clower, false, true);
622  fprintf(stderr, "@@@ upper value : ");
623  complexity_fprint(stderr, cupper, false, true);
624  fprintf(stderr, "@@@ increment value : ");
625  complexity_fprint(stderr, cincr, false, true);
626  fprintf(stderr, "@@@ sigma complexity: ");
627  complexity_fprint(stderr, comp, false, true);
628  }
629 /*
630  if ( !complexity_constant_p(cincr) ) {
631  complexity_div(&comp, cincr);
632  }
633  else {
634  float incr = complexity_TCST(cincr);
635  if (incr == 0)
636  user_error("loop_to_complexity", "null increment\n");
637 
638  if ( complexity_constant_p(clower) && complexity_constant_p(cupper) ) {
639  float lower = complexity_TCST(clower);
640  float upper = complexity_TCST(cupper);
641  int times=0;
642  float curf;
643 
644  for ( curf = lower; curf <= upper; curf += incr )
645  times++;
646 
647  complexity_scalar_mult(&comp, 1./(float)times);
648  if ( complexity_zero_p(comp) )
649  comp = make_constant_complexity(1.0);
650  }
651  else {
652  complexity_scalar_mult(&comp, 1.0/incr);
653  }
654  }
655 */
658  complexity_stats_add(&comp, cincr);
660 
661  complexity_rm(&crange);
662  complexity_rm(&cioh);
663  complexity_rm(&cboh);
664  complexity_rm(&clower);
665  complexity_rm(&cupper);
666  complexity_rm(&cincr);
667 
668  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
669  fprintf(stderr, "@@@ loop total compl: ");
670  complexity_fprint(stderr, comp, true, true);
671  fprintf(stderr, "\n");
672  }
673 
675  complexity_check_and_warn("loop_to_complexity", comp);
676 
677  trace_off();
678  free(sl);free(su);free(si);
679  return(comp);
680 }
void free_complexity(complexity p)
Definition: complexity_ri.c:21
complexity expression_to_complexity_polynome(expression expr, transformer precond, list effects_list, bool keep_symbols, int maximize)
Entry point routine of this file:
void complexity_scalar_mult(complexity *pcomp, float f)
multiply a complexity by a floating-point number.
Definition: comp_math.c:303
void complexity_polynome_add(complexity *pcomp, Ppolynome pp)
Definition: comp_math.c:463
float complexity_TCST(complexity comp)
return the constant term of comp.
Definition: comp_math.c:288
void complexity_div(complexity *pcomp1, complexity comp2)
void complexity_div(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 / comp2; !...
Definition: comp_math.c:445
bool complexity_constant_p(complexity comp)
true if comp is constant.
Definition: comp_math.c:256
complexity make_constant_complexity(float f)
make a constant complexity "f * TCST" with null statistics
Definition: comp_math.c:231
complexity complexity_sigma(complexity comp, Variable index, complexity clower, complexity cupper)
comp_math.c
Definition: comp_math.c:84
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_unknown_p(complexity comp)
true if comp is unknown.
Definition: comp_math.c:269
complexity make_single_var_complexity(float f, Variable var)
make a complexity "f * var" with null statistics
Definition: comp_math.c:220
complexity range_to_complexity(range rng, transformer precond, list effects_list)
2nd element of syntax
Definition: comp_scan.c:1089
int complexity_degree(complexity c)
Definition: comp_util.c:1167
bool complexity_is_monomial_p(complexity c)
Definition: comp_util.c:1159
#define LOOP_BRANCH_OVERHEAD
#define MAXIMUM_VALUE
#define KEEP_SYMBOLS
defines for "expression_to_polynome" parameters
#define HASH_LOOP_INDEX
#define LOOP_INIT_OVERHEAD
#define MINIMUM_VALUE
#define complexity_rangecount(x)
Definition: complexity_ri.h:96
#define rangecount_guessed(x)
bool empty_global_label_p(const char *gln)
Definition: entity_names.c:264
void free(void *)
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
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
#define asprintf
Definition: misc-local.h:225
#define user_warning(fn,...)
Definition: misc-local.h:262
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
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
#define loop_body(x)
Definition: ri.h:1644
@ is_basic_int
Definition: ri.h:571
#define loop_execution(x)
Definition: ri.h:1648
#define range_upper(x)
Definition: ri.h:2290
#define range_increment(x)
Definition: ri.h:2292
#define loop_label(x)
Definition: ri.h:1646
#define range_lower(x)
Definition: ri.h:2288
#define loop_range(x)
Definition: ri.h:1642
#define execution_parallel_p(x)
Definition: ri.h:1211
#define loop_index(x)
Definition: ri.h:1640
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(), asprintf, complexity_check_and_warn(), complexity_constant_p(), complexity_degree(), complexity_div(), complexity_fprint(), complexity_is_monomial_p(), complexity_polynome(), complexity_polynome_add(), complexity_rangecount, complexity_rm(), complexity_scalar_mult(), complexity_sigma(), complexity_stats_add(), complexity_TCST(), complexity_unknown_p(), empty_global_label_p(), entity_local_name(), entity_name, execution_parallel_p, expression_to_complexity_polynome(), fprintf(), free(), free_complexity(), get_bool_property(), get_current_module_entity(), hash_complexity_parameters, hash_del(), HASH_LOOP_INDEX, hash_put(), intrinsic_cost(), is_basic_int, KEEP_SYMBOLS, loop_body, LOOP_BRANCH_OVERHEAD, loop_execution, loop_index, LOOP_INIT_OVERHEAD, loop_label, loop_range, make_constant_complexity(), MAKE_INT_BASIC, make_new_scalar_variable_with_prefix(), make_single_var_complexity(), make_zero_complexity(), MakeBasic(), MAXIMUM_VALUE, MINIMUM_VALUE, module_local_name(), range_increment, range_lower, range_to_complexity(), range_upper, rangecount_guessed, statement_to_complexity(), strdup(), trace_off(), trace_on(), user_error, and user_warning.

Referenced by instruction_to_complexity().

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

◆ range_to_complexity()

complexity range_to_complexity ( range  rng,
transformer  precond,
list  effects_list 
)

2nd element of syntax

Parameters
rngng
precondrecond
effects_listffects_list

Definition at line 1089 of file comp_scan.c.

1093 {
1094  complexity compl = NULL, compu = NULL, compi = NULL;
1095  expression lower = range_lower(rng);
1096  expression upper = range_upper(rng);
1097  expression incr = range_increment(rng);
1098  basic rngbasic;
1099 
1100  trace_on("range");
1101 
1102  if (!expression_undefined_p(lower))
1103  compl = expression_to_complexity(lower, &rngbasic, precond,
1104  effects_list);
1105  else
1106  pips_internal_error("lower undefined");
1107 
1108  if (!expression_undefined_p(upper))
1109  compu = expression_to_complexity(upper, &rngbasic, precond,
1110  effects_list);
1111  else
1112  pips_internal_error("upper undefined");
1113 
1114  if (!expression_undefined_p(incr))
1115  compi = expression_to_complexity(incr, &rngbasic, precond,
1116  effects_list);
1117  else
1118  pips_internal_error("increment undefined");
1119 
1120  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
1121  fprintf(stderr, "\n");
1122  fprintf(stderr, "--- range lower complexity: ");
1123  complexity_fprint(stderr, compl, false, true);
1124  fprintf(stderr, "--- range upper complexity: ");
1125  complexity_fprint(stderr, compu, false, true);
1126  fprintf(stderr, "--- range incr complexity: ");
1127  complexity_fprint(stderr, compi, false, true);
1128  }
1129 
1130  complexity_add(&compl, compu);
1131  complexity_add(&compl, compi);
1132  complexity_rm(&compu);
1133  complexity_rm(&compi);
1134 
1135  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
1136  fprintf(stderr, "--- range total complexity: ");
1137  complexity_fprint(stderr, compl, true, true);
1138  fprintf(stderr, "\n");
1139  }
1140  complexity_check_and_warn("range_to_complexity", compl);
1141 
1142  trace_off();
1143  return(compl);
1144 }
#define expression_undefined_p(x)
Definition: ri.h:1224

References complexity_add(), complexity_check_and_warn(), complexity_fprint(), complexity_rm(), expression_to_complexity(), expression_undefined_p, fprintf(), get_bool_property(), pips_internal_error, range_increment, range_lower, range_upper, trace_off(), and trace_on().

Referenced by loop_to_complexity(), and syntax_to_complexity().

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

◆ reference_to_complexity()

complexity reference_to_complexity ( reference  ref,
basic pbasic,
transformer  precond,
list  effects_list 
)

1st element of syntax

reference_to_complexity: return the complexity of the computing of the indices plus the complexity of one memory read Also return basic type of variable in *pbasic.

indices basic

ci=compindexation, ca=compaccess

ci=compindexation counts multi-dimension arrays indexation costs

Parameters
refef
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 952 of file comp_scan.c.

957 {
959  list ind = reference_indices(ref);
960 
961  const char* name = module_local_name(var);
963  basic ib = MAKE_INT_BASIC; /* indices basic */
964  complexity comp, ci, ca; /* ci=compindexation, ca=compaccess */
965 
966  trace_on("reference %s", entity_name(var));
967 
968  if ( basic_int_p(b) || basic_float_p(b) ||
970  *pbasic = simple_basic_dup(b);
971  else if (basic_string_p(b))
972  *pbasic = MAKE_STRING_BASIC;
973  else if (basic_derived_p(b) || basic_pointer_p(b)){
974  *pbasic = MAKE_ADDRESS_BASIC;
975  }
976  else {
977  user_warning("reference_to_complexity",
978  "basic_tag %d, not in 1->9\n", (int)basic_tag(b));
979  }
980 
981  comp = indices_to_complexity(ind, &ib, precond, effects_list);
982 
983  /* ci=compindexation counts multi-dimension arrays indexation costs */
984 
985  switch ( gen_length(ind) ) {
986  case 0:
987  ci = make_zero_complexity();
988  break;
989  case 1:
990  ci = make_constant_complexity((float)
992  break;
993  case 2:
994  ci = make_constant_complexity((float)
996  break;
997  case 3:
998  ci = make_constant_complexity((float)
1000  break;
1001  case 4:
1002  ci = make_constant_complexity((float)
1004  break;
1005  case 5:
1006  ci = make_constant_complexity((float)
1008  break;
1009  case 6:
1010  ci = make_constant_complexity((float)
1012  break;
1013  default:
1014  ci = make_constant_complexity((float)
1016  }
1017 
1018  if(entity_register_p(var))
1019  ca = make_zero_complexity();
1020  else
1021  ca = make_constant_complexity((float)
1023  &ib));
1024 
1025  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
1026  fprintf(stderr, "\n");
1027  fprintf(stderr, ">>> ref. %s argus complexity: ", name);
1028  complexity_fprint(stderr, comp, false, true);
1029  fprintf(stderr, ">>> ref. %s access complexity: ", name);
1030  complexity_fprint(stderr, ca, false, true);
1031  fprintf(stderr, ">>> ref. %s indices complexity: ", name);
1032  complexity_fprint(stderr, ci, false, true);
1033  }
1034 
1035  complexity_add(&comp, ca);
1036  complexity_add(&comp, ci);
1037  complexity_rm(&ca);
1038  complexity_rm(&ci);
1039 
1040  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
1041  fprintf(stderr, ">>> ref. %s total complexity: ", name);
1042  complexity_fprint(stderr, comp, true, true);
1043  fprintf(stderr,"\n");
1044  }
1045 
1046  complexity_check_and_warn("reference_to_complexity", comp);
1047 
1048  trace_off();
1049  return(comp);
1050 }
static reference ref
Current stmt (an integer)
Definition: adg_read_paf.c:163
complexity indices_to_complexity(list exprlist, basic *pbasic, transformer precond, list effects_list)
2nd element of reference
Definition: comp_scan.c:1057
#define MAKE_ADDRESS_BASIC
#define FOUR_INDEX_NAME
#define ONE_INDEX_NAME
#define MEMORY_READ_NAME
the above two lines are added for 6th cost file, overhead.
#define MAKE_STRING_BASIC
#define SIX_INDEX_NAME
#define FIVE_INDEX_NAME
#define SEVEN_INDEX_NAME
#define THREE_INDEX_NAME
#define TWO_INDEX_NAME
bool entity_register_p(entity e)
Definition: entity.c:766
type entity_basic_concrete_type(entity)
retrieves or computes and then returns the basic concrete type of an entity
Definition: type.c:3677
#define basic_complex_p(x)
Definition: ri.h:626
#define basic_int_p(x)
Definition: ri.h:614
#define reference_variable(x)
Definition: ri.h:2326
#define basic_tag(x)
Definition: ri.h:613
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define basic_derived_p(x)
Definition: ri.h:638
#define reference_indices(x)
Definition: ri.h:2328
#define basic_string_p(x)
Definition: ri.h:629
#define variable_basic(x)
Definition: ri.h:3120
#define basic_logical_p(x)
Definition: ri.h:620
#define basic_float_p(x)
Definition: ri.h:617

References basic_complex_p, basic_derived_p, basic_float_p, basic_int_p, basic_logical_p, basic_pointer_p, basic_string_p, basic_tag, complexity_add(), complexity_check_and_warn(), complexity_fprint(), complexity_rm(), entity_basic_concrete_type(), entity_name, entity_register_p(), FIVE_INDEX_NAME, FOUR_INDEX_NAME, fprintf(), gen_length(), get_bool_property(), indices_to_complexity(), intrinsic_cost(), MAKE_ADDRESS_BASIC, make_constant_complexity(), MAKE_INT_BASIC, MAKE_STRING_BASIC, make_zero_complexity(), MEMORY_READ_NAME, module_local_name(), ONE_INDEX_NAME, ref, reference_indices, reference_variable, SEVEN_INDEX_NAME, simple_basic_dup(), SIX_INDEX_NAME, THREE_INDEX_NAME, trace_off(), trace_on(), TWO_INDEX_NAME, type_variable, user_warning, and variable_basic.

Referenced by syntax_to_complexity().

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

◆ statement_to_complexity()

complexity statement_to_complexity ( statement  stat,
transformer precon   __attribute__(__unused__),
list eff_list   __attribute__(__unused__) 
)

starting point of Abstract Syntax Tree

Check and store the complexity in the statement_mapping

SET_STATEMENT_MAPPING(get_complexity_map() , stat, (char *) comp);

Definition at line 230 of file comp_scan.c.

233 {
234  instruction instr = statement_instruction(stat);
235  int so = statement_ordering(stat);
237  list effects_list = load_cumulated_rw_effects_list(stat);
239 
240  trace_on("statement %s, ordering (%d %d)",
243  /*
244  if ( perfectly_nested_loop_p(stat) )
245  fprintf(stderr, "PERFECTLY nested loop, ordering %d\n",
246  statement_ordering(perfectly_nested_loop_to_body(stat)));
247  else
248  fprintf(stderr, "NOT a perfectly nested loop\n");
249 */
250  if (instr != instruction_undefined)
251  comp = instruction_to_complexity(instr, precond, effects_list);
252  else {
253  pips_internal_error("instruction undefined");
254  }
255 
256  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
257  fprintf(stderr,"complexity for statement (%td,%td) at %p\n",
258  (statement_ordering(stat) >> 16),
259  (statement_ordering(stat) & 0xffff), comp);
260  complexity_fprint(stderr, comp, true, true);
261  }
262 
263  /* Check and store the complexity in the statement_mapping */
264  complexity_check_and_warn("statement_to_complexity", comp);
265  pips_assert("comp is consistent", complexity_consistent_p(comp));
266 
267  /* SET_STATEMENT_MAPPING(get_complexity_map() , stat, (char *) comp); */
268  store_statement_complexity(stat, comp);
269 
270  trace_off();
271  return(comp);
272 }
complexity instruction_to_complexity(instruction instr, transformer precond, list effects_list)
The only element available of the statement.
Definition: comp_scan.c:275
void store_statement_complexity(statement, complexity)
#define ORDERING_NUMBER(o)
#define ORDERING_STATEMENT(o)
#define statement_ordering(x)
Definition: ri.h:2454
#define instruction_undefined
Definition: ri.h:1454
#define statement_label(x)
Definition: ri.h:2450
#define statement_instruction(x)
Definition: ri.h:2458

References complexity_check_and_warn(), complexity_consistent_p(), complexity_fprint(), fprintf(), get_bool_property(), instruction_to_complexity(), instruction_undefined, load_cumulated_rw_effects_list(), load_statement_precondition(), make_zero_complexity(), module_local_name(), ORDERING_NUMBER, ORDERING_STATEMENT, pips_assert, pips_internal_error, statement_instruction, statement_label, statement_ordering, store_statement_complexity(), trace_off(), and trace_on().

Referenced by any_complexities(), block_to_complexity(), controls_to_hash_table(), loop_to_complexity(), new_block_to_complexity(), test_to_complexity(), and whileloop_to_complexity().

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

◆ subscript_to_complexity()

complexity subscript_to_complexity ( subscript  sub,
basic pbasic,
transformer  precond,
list  effects_list 
)

G:let us assume . cost 1

Parameters
subub
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 860 of file comp_scan.c.

861  {
862 
864  subscript_array(sub),
865  pbasic,
866  precond,
867  effects_list);
869  subscript_indices(sub),
870  pbasic,
871  precond,
872  effects_list);
873  complexity_add(&cl,cr);
874  complexity_rm(&cr);
875  complexity_float_add(&cl,1.f);/*SG:let us assume . cost 1 */
876  return cl;
877 
878 }
#define subscript_indices(x)
Definition: ri.h:2563
#define subscript_array(x)
Definition: ri.h:2561

References complexity_add(), complexity_float_add(), complexity_rm(), expression_to_complexity(), indices_to_complexity(), subscript_array, and subscript_indices.

Referenced by syntax_to_complexity().

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

◆ summary_complexity()

bool summary_complexity ( const string  module_name)

summary_comp_dup = complexity_dup(summary_comp);

Parameters
module_nameodule_name

Definition at line 179 of file comp_scan.c.

180 {
181  complexity summary_comp = make_zero_complexity();// complexity_undefined;
182  complexity summary_comp_dup = make_zero_complexity();// complexity_undefined;
183 
185  db_get_memory_resource(DBR_CODE, module_name, true ) );
186 
188  db_get_memory_resource(DBR_COMPLEXITIES, module_name, true));
190 
191  trace_on("summary complexity %s", module_name);
192  debug_on("COMPLEXITY_DEBUG_LEVEL");
193 
194  if ( summary_comp == COMPLEXITY_NOT_FOUND )
195  pips_internal_error("No summary complexity!");
196  else {
197  /* summary_comp_dup = complexity_dup(summary_comp); */
198  summary_comp_dup = copy_complexity(summary_comp);
199  }
200 
201  pips_assert("summary_comp is conssten",
202  complexity_consistent_p(summary_comp));
203  pips_assert("summary_comp_dup is consistent",
204  complexity_consistent_p(summary_comp_dup));
205 
206  trace_off();
207 
208  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
209  fprintf(stderr,"\n");
210  fprintf(stderr,"Before ======== SUMMARY ; module %s\n",module_name);
211  }
212 
213  debug_off();
214 
215  DB_PUT_MEMORY_RESOURCE(DBR_SUMMARY_COMPLEXITY,
217  (char *) summary_comp_dup);
218 
219  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
220  fprintf(stderr,"After ======== SUMMARY ; module %s\n",module_name);
221  }
222 
225 
226  return true;
227 }
complexity copy_complexity(complexity p)
COMPLEXITY.
Definition: complexity_ri.c:18
complexity load_statement_complexity(statement)

References complexity_consistent_p(), COMPLEXITY_NOT_FOUND, copy_complexity(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, fprintf(), get_bool_property(), get_current_module_statement(), load_statement_complexity(), make_zero_complexity(), module_name(), pips_assert, pips_internal_error, reset_complexity_map(), reset_current_module_statement(), set_complexity_map(), set_current_module_statement(), strdup(), trace_off(), and trace_on().

+ Here is the call graph for this function:

◆ syntax_to_complexity()

complexity syntax_to_complexity ( syntax  s,
basic pbasic,
transformer  precond,
list  effects_list 
)

the only available element of expression

A cost for casting could be added, although casting is mostly used for typing issue. However, (float) 2 has a cost.

TypeCast operation added by Molka Becher to complexity_cost_tables for handling the cost of cast when it is necessary, 24 March 2011

Compiler generated constant: equivalent to a constant load --> 0

Parameters
pbasicbasic
precondrecond
effects_listffects_list

Definition at line 881 of file comp_scan.c.

886 {
887  complexity comp = make_zero_complexity();// complexity_undefined;
888 
889  trace_on("syntax");
890 
891  switch (syntax_tag(s)) {
892  case is_syntax_reference:
893  comp = reference_to_complexity(syntax_reference(s), pbasic,
894  precond, effects_list);
895  break;
896  case is_syntax_range:
897  comp = range_to_complexity(syntax_range(s), precond, effects_list);
898  break;
899  case is_syntax_call:
900  comp = call_to_complexity(syntax_call(s), pbasic, precond, effects_list);
901  break;
902  case is_syntax_cast: {
903  cast c = syntax_cast(s);
904  /* A cost for casting could be added, although casting is mostly
905  used for typing issue. However, (float) 2 has a cost. */
906  /* TypeCast operation added by Molka Becher to complexity_cost_tables
907  for handling the cost of cast when it is necessary, 24 March 2011 */
908  basic ib = MAKE_INT_BASIC;
909  comp = expression_to_complexity(cast_expression(c), pbasic, precond, effects_list);
911  complexity_add(&comp, c1);
912  complexity_rm(&c1);
913  break;
914  }
919  pbasic, precond, effects_list);
920  else {
921  /* Compiler generated constant: equivalent to a constant load --> 0*/
922  comp = make_zero_complexity();
923  }
924  break;
925  }
926  case is_syntax_subscript:
927  comp=subscript_to_complexity(syntax_subscript(s),pbasic,precond,effects_list);
928  break;
930  pips_internal_error("Not implemented yet");
931  break;
932  case is_syntax_va_arg:
933  pips_internal_error("Not implemented yet");
934  break;
935  default:
936  pips_internal_error("syntax_tag %d, not in %d->%d", (int)syntax_tag(s),
938  }
939 
940  complexity_check_and_warn("syntax_to_complexity", comp);
941 
942  trace_off();
943  return(comp);
944 }
complexity reference_to_complexity(reference ref, basic *pbasic, transformer precond, list effects_list)
1st element of syntax
Definition: comp_scan.c:952
complexity subscript_to_complexity(subscript sub, basic *pbasic, transformer precond, list effects_list)
Definition: comp_scan.c:860
#define TYPE_CAST_COST
TYPE_CAST_COST added to handle cast case ; Molka Becher
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define sizeofexpression_expression(x)
Definition: ri.h:2409
#define syntax_cast(x)
Definition: ri.h:2739
#define syntax_range(x)
Definition: ri.h:2733
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_application
Definition: ri.h:2697
@ is_syntax_cast
Definition: ri.h:2694
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_va_arg
Definition: ri.h:2698
@ is_syntax_reference
Definition: ri.h:2691
@ is_syntax_sizeofexpression
Definition: ri.h:2695
@ is_syntax_subscript
Definition: ri.h:2696
#define cast_expression(x)
Definition: ri.h:747
#define syntax_sizeofexpression(x)
Definition: ri.h:2742
#define sizeofexpression_expression_p(x)
Definition: ri.h:2407
#define syntax_call(x)
Definition: ri.h:2736
#define syntax_subscript(x)
Definition: ri.h:2745

References call_to_complexity(), cast_expression, complexity_add(), complexity_check_and_warn(), complexity_rm(), expression_to_complexity(), intrinsic_cost(), is_syntax_application, is_syntax_call, is_syntax_cast, is_syntax_range, is_syntax_reference, is_syntax_sizeofexpression, is_syntax_subscript, is_syntax_va_arg, make_constant_complexity(), MAKE_INT_BASIC, make_zero_complexity(), pips_internal_error, range_to_complexity(), reference_to_complexity(), sizeofexpression_expression, sizeofexpression_expression_p, subscript_to_complexity(), syntax_call, syntax_cast, syntax_range, syntax_reference, syntax_sizeofexpression, syntax_subscript, syntax_tag, trace_off(), trace_on(), and TYPE_CAST_COST.

Referenced by expression_to_complexity().

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

◆ test_to_complexity()

complexity test_to_complexity ( test  test_instr,
transformer  precond,
list  effects_list 
)

2nd element of instruction

Parameters
test_instrest_instr
precondrecond
effects_listffects_list

Definition at line 414 of file comp_scan.c.

418 {
419  complexity comp, ctrue, cfalse, ctemp;
420  basic testbasic;
421 
422  trace_on("test");
423 
424  ctrue = statement_to_complexity(test_true(test_instr), precond, effects_list);
425  cfalse = statement_to_complexity(test_false(test_instr), precond, effects_list);
426  comp = expression_to_complexity(test_condition(test_instr),
427  &testbasic, precond, effects_list);
428 
429  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
430  fprintf(stderr, "\n");
431  fprintf(stderr, "YYY test true complexity: ");
432  complexity_fprint(stderr, ctrue, false, true);
433  fprintf(stderr, "YYY test false complexity: ");
434  complexity_fprint(stderr, cfalse, false, true);
435  fprintf(stderr, "YYY test cond. complexity: ");
436  complexity_fprint(stderr, comp, false, true);
437  }
438 
439  ctemp = complexity_dup(ctrue);
440  complexity_add(&ctemp, cfalse);
441  complexity_scalar_mult(&ctemp, 0.5);
442  complexity_add(&comp, ctemp);
443  complexity_rm(&ctemp);
444 
445  if ( !complexity_zero_p(comp) )
447 
448  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
449  fprintf(stderr, "YYY test total complexity: ");
450  complexity_fprint(stderr, comp, true, true);
451  fprintf(stderr, "\n");
452  }
453  complexity_check_and_warn("test_to_complexity", comp);
454 
455  trace_off();
456  return(comp);
457 }
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_ifcount(x)
Definition: complexity_ri.h:98
#define ifcount_halfhalf(x)
#define test_false(x)
Definition: ri.h:2837
#define test_true(x)
Definition: ri.h:2835
#define test_condition(x)
Definition: ri.h:2833

References complexity_add(), complexity_check_and_warn(), complexity_dup(), complexity_fprint(), complexity_ifcount, complexity_rm(), complexity_scalar_mult(), complexity_zero_p(), expression_to_complexity(), fprintf(), get_bool_property(), ifcount_halfhalf, statement_to_complexity(), test_condition, test_false, test_true, trace_off(), and trace_on().

Referenced by instruction_to_complexity().

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

◆ uniform_complexities()

bool uniform_complexities ( const string  module_name)

declares the static variable complexity_map and defines its access functions

bool complexities(module_name) Entry point called by the pips makefile

"hash_callee_to_complexity" contains a list of summary_complexity of callees, Non-recursive: callees complexities are supposed to be computed when arriving here.

"hash_complexity_parameters" contains the list of variables that we don't want to evaluate; so they will appear in the polynomial. All other variables (except for the loop indices) are evaluated as the scan proceeds, thanks to semantic analysis. Those which can't be evaluated are replaced by the pseudo-variable UNKNOWN_VARIABLE, which will be given an arbitrary value at the end of the evaluation.

Parameters
module_nameodule_name

Definition at line 79 of file comp_scan.c.

80 {
81  bool success = true;
82 
83  //set_string_property("COMPLEXITY_COST_TABLE", "all_1");
85 
86  return success;
87 }

References any_complexities(), and module_name().

+ Here is the call graph for this function:

◆ whileloop_to_complexity()

complexity whileloop_to_complexity ( whileloop  while_instr,
transformer  precond,
list  effects_list 
)

5th element of instruction

Parameters
while_instrhile_instr
precondrecond
effects_listffects_list

Definition at line 692 of file comp_scan.c.

693 {
694  basic b;
695  expression exp1, exp2,exp3;
696  expression exp = whileloop_condition(while_instr);
697  complexity range ;
698  complexity cbody = statement_to_complexity(whileloop_body(while_instr), precond, effects_list),
699  ctest = expression_to_complexity(exp, &b,precond, effects_list);
700  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
701  fprintf(stderr, "\n");
702  fprintf(stderr, "YYY body complexity: ");
703  complexity_fprint(stderr, cbody, false, true);
704  fprintf(stderr, "YYY test complexity: ");
705  complexity_fprint(stderr, ctest, false, true);
706  }
707 
709  entity fun = call_function(syntax_call( s ));
710  if (ENTITY_LESS_THAN_P( fun )) {
713  exp3 = make_op_exp( MINUS_OPERATOR_NAME,exp1,exp2);
715  precond, effects_list,
717  }
718  else
719  {
721  }
722  complexity_add(&cbody,ctest);
723  complexity_mult(&cbody,range);
724 
725  if (get_bool_property("COMPLEXITY_INTERMEDIATES")) {
726  fprintf(stderr, "YYY while total complexity: ");
727  complexity_fprint(stderr, cbody, true, true);
728  fprintf(stderr, "\n");
729  }
730  complexity_check_and_warn(__FUNCTION__, cbody);
731 
732  return cbody;
733 }
complexity make_complexity_unknown(const char *name)
builds a new unknown complexity attached to a virtual package
void complexity_mult(complexity *pcomp1, complexity comp2)
void complexity_mult(complexity *pcomp1, comp2) performs *pcomp1 = *pcomp1 * comp2; !...
Definition: comp_math.c:418
#define UNKNOWN_RANGE_NAME
pseudo-variable for default iteration number of a loop
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
struct _newgen_struct_range_ * range
Definition: message.h:21
#define MINUS_OPERATOR_NAME
#define ENTITY_LESS_THAN_P(e)
expression make_op_exp(char *op_name, expression exp1, expression exp2)
================================================================
Definition: expression.c:2012
#define whileloop_body(x)
Definition: ri.h:3162
#define whileloop_condition(x)
Definition: ri.h:3160
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References call_arguments, call_function, CAR, CDR, complexity_add(), complexity_check_and_warn(), complexity_fprint(), complexity_mult(), ENTITY_LESS_THAN_P, exp, EXPRESSION, expression_syntax, expression_to_complexity(), expression_to_complexity_polynome(), fprintf(), get_bool_property(), KEEP_SYMBOLS, make_complexity_unknown(), make_op_exp(), MINIMUM_VALUE, MINUS_OPERATOR_NAME, statement_to_complexity(), syntax_call, UNKNOWN_RANGE_NAME, whileloop_body, and whileloop_condition.

Referenced by instruction_to_complexity().

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

Variable Documentation

◆ hash_callee_to_complexity

hash_table hash_callee_to_complexity = hash_table_undefined

comp_expr_to_pnome.c

cproto-generated files

scan a ri expression and try to make a polynomial of it Modif: – entity_local_name is replaced by module_local_name. LZ 230993 – MAXINT replaced by INT_MAX, -MAXINT by INT_MIN FI 1/12/95 useful, pips_error is defined there

Definition at line 57 of file comp_scan.c.

Referenced by any_complexities(), and call_to_complexity().

◆ hash_complexity_parameters