25 #include "pips_config.h"
73 #include "resources.h"
83 #include "constants.h"
90 #define INDENT_BLANKS " "
91 #define INDENT_VLINE "| "
92 #define INDENT_BACK "-"
93 #define INDENT_INTERVAL 2
117 fprintf(stderr,
"complexity ZERO for %s\n",s);
121 user_warning(s,
"Bad internal complexity representation!\n");
177 bool print_stats_p, print_local_names_p;
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",
220 bool print_stats_p, print_local_names_p;
485 bool skip_one_line =
false;
487 fprintf(fd,
"\nIntrinsic cost table:\n\n");
488 fprintf(fd,
" Intrinsic name int float double complex dcomplex\n");
489 fprintf(fd,
"------------------------------------------------------------------------\n");
491 for(; p->
name != NULL ;p++) {
499 skip_one_line =
false;
501 fprintf(fd,
"%22.21s |%6td %6td %7td %8td %8td\n",
506 skip_one_line =
true;
521 char *token, *comma, *filename ;
527 for(token = strtok(cost_data,
" "); (token != NULL);token = strtok(NULL,
" ")) {
528 comma = strchr(token,
',');
535 int ii = comma - token;
537 sscanf(++comma,
"%f", &file_factor);
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);
562 char *intrinsic_name = (
char*)
malloc(30);
565 float scale_factor = 1.0;
569 fprintf(stderr,
"\nReading cost file ");
570 if (file_factor != 1.0)
571 fprintf(stderr,
"(x %.2f)", file_factor);
574 while (fgets(
line, 99, fd) != NULL) {
576 sscanf(
line+1,
"%f", &scale_factor);
577 else if ((*
line !=
'#') && (*
line !=
'\n')) {
578 sscanf(
line,
"%s %d %d %d %d %d", intrinsic_name,
585 (
int_cost * scale_factor * file_factor + 0.5);
587 (
float_cost * scale_factor * file_factor + 0.5);
600 "%s:unrecognized intrinsic\n",intrinsic_name);
604 fprintf(stderr,
"\nScale factor is %f\n", scale_factor);
608 free(intrinsic_name);
629 user_warning(
"intrinsic_cost",
"LOG or LOG10 functions used\n");
672 sscanf(cste,
"%f", &
f);
677 "Basic tag:%d, not 4->9, (entity %s)\n",
basic_tag(b),cste);
688 char *indentstring = (
char*)
malloc(99);
692 indentstring[0] =
'\0';
695 indentstring = strcat(indentstring,
702 fprintf(stderr,
"%s>", indentstring);
704 vfprintf(stderr, fmt, args);
717 char *indentstring = (
char*)
malloc(99);
721 indentstring[0] =
'\0';
724 indentstring = strcat(indentstring,
730 fprintf(stderr,
"%s<\n", indentstring);
762 if ((l ==
NIL) || (l->cdr ==
NIL))
782 fprintf(stderr,
"\nstorage_formal %s\n",
797 pips_assert(
"remove_formal_parameters_from_hash_table",
805 fprintf(stderr,
"storage_formal %s to be deleted\n",
830 fprintf(stderr,
"Fetching callees complexities ...\n");
836 if ( callees_list ==
NIL ) {
840 return(hash_callees_comp);
858 (
char *) callee_name,
862 fprintf(stderr,
"fetched complexity for callee %s",
870 debug(5,
"fetch_callees_complexities",
"callee_name %s\n",callee_name);
884 fprintf(stderr,
"translated complexity for callee %s",
895 fprintf(stderr,
"Fetching callees complexities ... done\n");
898 return(hash_callees_comp);
906 char *sep_chars =
strdup(
", ");
907 char *token = (
char*)
malloc(30);
913 fprintf(stderr,
"Fetching complexity parameters for module %s:\n",
917 token = strtok(parameters, sep_chars);
919 while (token != NULL) {
933 fprintf(stderr,
"{\t Undefined token %s }\n", token);
936 token = strtok(NULL, sep_chars);
940 fprintf(stderr,
"Fetching complexity parameters: ...done.\n");
943 return(hash_comp_params);
961 debug(5,
"add_common_variables_to_hash_table",
962 "Effect list for %s\n",
967 for(ce= sefs_list; !
ENDP(ce);
POP(ce)) {
977 debug(5,
"add_common_variables_to_hash_table",
992 pips_assert(
"remove_common_variables_from_hash_table",
1062 fprintf(stderr,
"Final evaluation\n");
1068 fprintf(stderr,
"Variable is %s\n", var);
1072 if ( mustbewritten ) {
1074 fprintf(stderr,
"YES once\n");
1089 return ( final_comp );
1102 string oldname,newname;
1128 char *t = strchr(stmp,
':');
1131 int length = (
int)(t - s);
1132 char *cur_name = (
char *)
malloc(100);
1134 (void) strncpy(cur_name,stmp,length);
1135 * (cur_name+length) =
'\0';
1137 if ( 1 || strncmp(cur_name, oldname, length) == 0 ) {
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)
void free_complexity(complexity p)
ifcount make_ifcount(intptr_t a1, intptr_t a2, intptr_t a3)
complexity make_complexity(Ppolynome a1, varcount a2, rangecount a3, ifcount a4)
basic make_basic(enum basic_utype tag, void *val)
void const char const char const int
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...
complexity make_zero_complexity()
make a zero complexity "0.0000 * TCST" with null statistics
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...
bool complexity_zero_p(complexity comp)
zero complexity check.
complexity make_single_var_complexity(float f, Variable var)
make a complexity "f * var" with null statistics
void complexity_rm(complexity *pcomp)
remove complexity comp
void remove_formal_parameters_from_hash_table(entity mod, hash_table hash_complexity_params)
void remove_common_variables_from_hash_table(entity module, hash_table hash_complexity_params)
void good_complexity_assert(_UNUSED_ string function, complexity comp)
void trace_on(char *fmt,...)
hash_table free_callees_complexities(hash_table h)
void complexity_fprint(FILE *fd, complexity comp, bool print_stats_p, bool print_local_names_p)
void fprint_statement_complexity(entity module, statement stat, hash_table hash_statement_to_complexity)
void load_cost_file(FILE *fd, float file_factor)
Load (some) intrinsics costs from file "fd", multiplying them by "file_factor".
bool is_must_be_written_var(list effects_list, char *var_name)
void add_common_variables_to_hash_table(entity module, hash_table hash_complexity_params)
void complexity_check_and_warn(char *s, complexity comp) const
bool complexity_check(complexity comp)
return true if allright
float constant_entity_to_float(entity e)
Return if possible the value of e in a float.
list entity_list_reverse(list l)
int complexity_degree(complexity c)
hash_table fetch_complexity_parameters(char *module_name)
void trace_off()
"trace off"
bool is_linear_unstructured(unstructured unstr)
return true if unstr is simply a linear string of controls
void add_formal_parameters_to_hash_table(entity mod, hash_table hash_complexity_params)
static int call_level
"trace on"
void fprint_cost_table(FILE *fd)
intrinsic_cost_record intrinsic_cost_table[]
The table intrinsic_cost_table[] gathers cost information of each intrinsic's cost; those costs are d...
hash_table fetch_callees_complexities(char *module_name)
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...
void prc(complexity comp)
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 ...
void complexity_dump(complexity comp)
complexity complexity_dup(complexity comp)
duplicates complexity comp
char * complexity_sprint(complexity comp, bool print_stats_p, bool print_local_names_p)
#define INDENT_BLANKS
comp_util.c
void init_cost_table()
Completes the intrinsic cost table with the costs read from the files specified in the "COMPLEXITY_CO...
bool complexity_is_monomial_p(complexity c)
complexity final_statement_to_complexity_evaluation(complexity comp, transformer precond, list effects_list)
#define COST_DATA
defined complexity data file names here.
#define STRING_INTRINSICS_COST
#define LOGICAL_INTRINSICS_COST
#define CALL_TWO_OVERHEAD
#define CALL_FIVE_OVERHEAD
#define LOOP_BRANCH_OVERHEAD
#define PRINT_LOCAL_NAMES
#define TYPE_CAST_COST
TYPE_CAST_COST added to handle cast case ; Molka Becher
#define HASH_COMMON_VARIABLE
#define MEMORY_READ_NAME
the above two lines are added for 6th cost file, overhead.
#define HASH_USER_VARIABLE
#define CALL_ZERO_OVERHEAD
#define LOOP_INIT_OVERHEAD
#define CALL_THREE_OVERHEAD
#define CONDITION_OVERHEAD
#define COMPLEXITY_UNDEFINED_P(c)
#define HASH_FORMAL_PARAM
#define CALL_ONE_OVERHEAD
#define CALL_SIX_OVERHEAD
#define DO_PRINT_STATS
defines for "complexity_fprint" calls
#define CALL_SEVEN_OVERHEAD
#define CALL_FOUR_OVERHEAD
char * variable_local_name(Variable)
Variable name_to_variable(char *)
int is_inferior_pvarval(Pvecteur *, Pvecteur *)
#define ifcount_computed(x)
#define complexity_eval(x)
#define rangecount_unknown(x)
#define varcount_guessed(x)
#define complexity_ifcount(x)
#define ifcount_profiled(x)
#define complexity_varcount(x)
#define complexity_rangecount(x)
struct _newgen_struct_complexity_ * complexity
#define rangecount_guessed(x)
#define varcount_symbolic(x)
#define varcount_unknown(x)
#define varcount_bounded(x)
#define rangecount_profiled(x)
#define ifcount_halfhalf(x)
#define rangecount_bounded(x)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
list effects_to_list(effects)
#define approximation_exact_p(x)
#define action_write_p(x)
#define effect_approximation(x)
const char * module_name(const char *s)
Return the module part of an entity name.
char * get_string_property(const char *)
FILE * fopen_config(const char *canonical_name, const char *cproperty, const char *cenv)
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define chunk_undefined
obsolete
#define ENDP(l)
Test if a list is empty.
#define POP(l)
Modify a list pointer to point on the next element of the list.
#define NIL
The empty list (nil in Lisp)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
#define CAR(pcons)
Get the value of the first element of a list.
#define CDR(pcons)
Get the list less its first element.
#define MAPL(_map_list_cp, _code, _l)
Apply some code on the addresses of all the elements of a list.
#define list_undefined
Undefined list definition :-)
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
hash_table hash_table_make(hash_key_type key_type, size_t size)
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.
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.
void hash_warn_on_redefinition(void)
these function set the variable should_i_warn_on_redefinition to the value true or false
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
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.
void hash_table_clear(hash_table htp)
Clears all entries of a hash table HTP.
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)(),...
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
#define pips_internal_error
#define user_warning(fn,...)
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
#define LIST_DIRECTED_FORMAT_NAME
#define MODULE_SEP_STRING
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define hash_table_undefined
Value of an undefined hash_table.
#define same_string_p(s1, s2)
void * gen_find_tabulated(const char *, int)
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Ppolynome polynome_dup(Ppolynome pp)
Ppolynome polynome_dup(Ppolynome pp) creates and returns a copy of pp.
bool polynome_check(Ppolynome pp)
bool polynome_check(Ppolynome pp) Return true if all's right.
int default_is_inferior_pvarval(Pvecteur *pvarval1, Pvecteur *pvarval2)
bool default_is_inferior_pvarval(Pvecteur * pvarval1, Pvecteur * pvarval2) return true if var1 is bef...
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...
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...
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,...
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...
#define is_single_monome(pp)
text Text_Statement(entity, int, statement)
#define UNBOUNDED_DIMENSION_NAME
#define BITWISE_OR_OPERATOR_NAME
#define NINT_CONVERSION_NAME
#define ATAN2_OPERATOR_NAME
#define MAX_OPERATOR_NAME
#define POWER_OPERATOR_NAME
#define LLE_OPERATOR_NAME
#define CABS_OPERATOR_NAME
#define POST_DECREMENT_OPERATOR_NAME
#define CEXP_OPERATOR_NAME
#define IDNINT_CONVERSION_NAME
#define FLOAT_GENERIC_CONVERSION_NAME
#define BITWISE_XOR_OPERATOR_NAME
#define TANH_OPERATOR_NAME
#define COS_OPERATOR_NAME
#define DSIGN_OPERATOR_NAME
#define DOUBLE_MODULO_OPERATOR_NAME
#define READ_FUNCTION_NAME
#define C_AND_OPERATOR_NAME
#define GREATER_THAN_OPERATOR_NAME
#define ENDFILE_FUNCTION_NAME
#define SIGN_OPERATOR_NAME
#define DMIN1_OPERATOR_NAME
#define BITWISE_OR_UPDATE_OPERATOR_NAME
#define ABS_OPERATOR_NAME
#define DBLE_GENERIC_CONVERSION_NAME
#define DACOS_OPERATOR_NAME
#define COSH_OPERATOR_NAME
#define BUFFERIN_FUNCTION_NAME
#define DSQRT_OPERATOR_NAME
#define C_MODULO_OPERATOR_NAME
#define MINUS_OPERATOR_NAME
#define IDIM_OPERATOR_NAME
#define AINT_CONVERSION_NAME
#define LESS_THAN_OPERATOR_NAME
#define DNINT_CONVERSION_NAME
#define CLOG_OPERATOR_NAME
#define DINT_CONVERSION_NAME
#define IABS_OPERATOR_NAME
#define EQUIV_OPERATOR_NAME
#define DIVIDE_UPDATE_OPERATOR_NAME
#define MODULO_UPDATE_OPERATOR_NAME
#define POINT_TO_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define LOG10_OPERATOR_NAME
#define LENGTH_OPERATOR_NAME
#define DCOSH_OPERATOR_NAME
#define DIM_OPERATOR_NAME
#define SIN_OPERATOR_NAME
#define EQUAL_OPERATOR_NAME
#define DLOG10_OPERATOR_NAME
#define MAX0_OPERATOR_NAME
#define AMIN0_OPERATOR_NAME
#define RETURN_FUNCTION_NAME
#define DEREFERENCING_OPERATOR_NAME
#define MIN0_OPERATOR_NAME
#define MAX1_OPERATOR_NAME
#define FIELD_OPERATOR_NAME
#define NON_EQUIV_OPERATOR_NAME
#define C_NON_EQUAL_OPERATOR_NAME
#define LEFT_SHIFT_UPDATE_OPERATOR_NAME
#define IMS_OPERATOR_NAME
#define REAL_MODULO_OPERATOR_NAME
#define CONJG_OPERATOR_NAME
#define AMAX0_OPERATOR_NAME
#define REWIND_FUNCTION_NAME
#define DMAX1_OPERATOR_NAME
#define IFIX_GENERIC_CONVERSION_NAME
#define ACOS_OPERATOR_NAME
#define MULTIPLY_UPDATE_OPERATOR_NAME
#define OPEN_FUNCTION_NAME
#define END_FUNCTION_NAME
#define LEFT_SHIFT_OPERATOR_NAME
#define CONDITIONAL_OPERATOR_NAME
#define ALOG10_OPERATOR_NAME
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define LLT_OPERATOR_NAME
#define C_RETURN_FUNCTION_NAME
#define BUFFEROUT_FUNCTION_NAME
#define CCOS_OPERATOR_NAME
#define DPROD_OPERATOR_NAME
#define AND_OPERATOR_NAME
FI: intrinsics are defined at a third place after bootstrap and effects! I guess the name should be d...
#define MINUS_UPDATE_OPERATOR_NAME
#define ANINT_CONVERSION_NAME
#define C_NOT_OPERATOR_NAME
#define INT_TO_CHAR_CONVERSION_NAME
#define CONTINUE_FUNCTION_NAME
#define ADDRESS_OF_OPERATOR_NAME
#define CMPLX_GENERIC_CONVERSION_NAME
#define PRE_DECREMENT_OPERATOR_NAME
#define CHAR_TO_INT_CONVERSION_NAME
#define SQRT_OPERATOR_NAME
#define ATAN_OPERATOR_NAME
#define ISIGN_OPERATOR_NAME
#define INT_GENERIC_CONVERSION_NAME
generic conversion names.
#define LGE_OPERATOR_NAME
#define DIVIDE_OPERATOR_NAME
#define WRITE_FUNCTION_NAME
#define DABS_OPERATOR_NAME
#define CLOSE_FUNCTION_NAME
#define UNARY_MINUS_OPERATOR_NAME
#define AMIN1_OPERATOR_NAME
#define DCOS_OPERATOR_NAME
#define BITWISE_XOR_UPDATE_OPERATOR_NAME
#define CONCATENATION_FUNCTION_NAME
#define EXP_OPERATOR_NAME
#define IMA_OPERATOR_NAME
Integer Multiply Add and Sub, FC 27/10/2005 for FI.
#define LOG_OPERATOR_NAME
#define RIGHT_SHIFT_UPDATE_OPERATOR_NAME
#define DSIN_OPERATOR_NAME
#define CSQRT_OPERATOR_NAME
#define BITWISE_NOT_OPERATOR_NAME
#define GREATER_OR_EQUAL_OPERATOR_NAME
#define TAN_OPERATOR_NAME
#define STOP_FUNCTION_NAME
#define PRE_INCREMENT_OPERATOR_NAME
#define POST_INCREMENT_OPERATOR_NAME
#define DSINH_OPERATOR_NAME
#define AIMAG_CONVERSION_NAME
#define PLUS_UPDATE_OPERATOR_NAME
#define INDEX_OPERATOR_NAME
#define FORMAT_FUNCTION_NAME
#define DATAN2_OPERATOR_NAME
#define DDIM_OPERATOR_NAME
#define SINH_OPERATOR_NAME
#define REAL_GENERIC_CONVERSION_NAME
#define ENDDO_FUNCTION_NAME
#define MULTIPLY_OPERATOR_NAME
#define DEXP_OPERATOR_NAME
#define BITWISE_AND_UPDATE_OPERATOR_NAME
#define DLOG_OPERATOR_NAME
#define LESS_OR_EQUAL_OPERATOR_NAME
#define BITWISE_AND_OPERATOR_NAME
#define CSIN_OPERATOR_NAME
#define SNGL_GENERIC_CONVERSION_NAME
#define DTANH_OPERATOR_NAME
#define RIGHT_SHIFT_OPERATOR_NAME
#define ASIN_OPERATOR_NAME
#define AMAX1_OPERATOR_NAME
#define DASIN_OPERATOR_NAME
#define IDINT_GENERIC_CONVERSION_NAME
#define NOT_OPERATOR_NAME
#define LGT_OPERATOR_NAME
#define MIN1_OPERATOR_NAME
#define NON_EQUAL_OPERATOR_NAME
#define DATAN_OPERATOR_NAME
#define DTAN_OPERATOR_NAME
#define ASSIGN_OPERATOR_NAME
#define MODULO_OPERATOR_NAME
#define ALOG_OPERATOR_NAME
#define MIN_OPERATOR_NAME
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
const char * module_local_name(entity e)
Returns the module local user name.
bool entity_module_p(entity e)
basic simple_basic_dup(basic)
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...
#define type_functional_p(x)
struct _newgen_struct_callees_ * callees
#define storage_formal_p(x)
#define callees_callees(x)
#define reference_variable(x)
#define entity_storage(x)
#define code_declarations(x)
#define CONTROL(x)
CONTROL.
#define control_successors(x)
#define unstructured_exit(x)
#define entity_domain
newgen_syntax_domain_defined
#define entity_initial(x)
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * variable_name(Variable v)
polynome_ri.c
static int line
FLEX_SCANNER.
char * strndup(char const *s, size_t n)
A replacement function, for systems that lack strndup.
le type des coefficients dans les vecteurs: Value est defini dans le package arithmetique
The structure used to build lists in NewGen.
Intrinsics costs defines.
void print_text(FILE *fd, text t)
#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....
#define base_dimension(b)
#define BASE_NULLE
MACROS SUR LES BASES.
Pvecteur vect_dup(Pvecteur v_in)
Pvecteur vect_dup(Pvecteur v_in): duplication du vecteur v_in; allocation de et copie dans v_out;.