PIPS
util.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "pipsdbm.h"
#include "properties.h"
#include "ri.h"
#include "ri-util.h"
#include "effects.h"
#include "effects-simple.h"
+ Include dependency graph for util.c:

Go to the source code of this file.

Data Structures

struct  flfl
 

Functions

static bool filterout_statement (void *obj)
 
static bool wipeout_entity (entity e)
 entities that match the following conditions are not cleaned from declarations: More...
 
static void statement_clean_declarations_helper (list declarations, statement stmt)
 remove useless entities from declarations an entity is flagged useless when no reference is found in stmt and when it is not used by an entity found in stmt More...
 
static void entity_generate_missing_declarations (entity module, statement s)
 check if all entities used in s and module are declared in module does not work as well as expected on c module because it does not fill the statement declaration More...
 
void statement_clean_declarations (statement s)
 remove all the entity declared in s but never referenced it's a lower version of use-def-elim ! More...
 
void entity_clean_declarations (entity module, statement s)
 remove all entities declared in module but never used in s More...
 
static bool find_loop_from_label_walker (loop l, struct flfl *p)
 
statement find_loop_from_label (statement s, entity label)
 hmmm... More...
 
static bool clean_statement_label (statement st)
 
bool clean_labels (const string mod_name)
 
int get_processor_number (void)
 
int get_vector_register_length (void)
 
int get_vector_register_number (void)
 

Function Documentation

◆ clean_labels()

bool clean_labels ( const string  mod_name)
Parameters
mod_nameod_name

Definition at line 238 of file util.c.

239 {
240  statement mod_stmt = (statement) db_get_memory_resource(DBR_CODE, mod_name, true);
241 
243  set_current_module_statement( mod_stmt);
244 
246 
247  DB_PUT_MEMORY_RESOURCE(DBR_CODE,
248  strdup(mod_name),
249  (char*) mod_stmt);
250 
253 
254  return true;
255 }
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
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
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
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
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
char * strdup()
static bool clean_statement_label(statement st)
Definition: util.c:226

References clean_statement_label(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, gen_null(), gen_recurse, module_name_to_entity(), reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), statement_domain, and strdup().

+ Here is the call graph for this function:

◆ clean_statement_label()

static bool clean_statement_label ( statement  st)
static

Definition at line 226 of file util.c.

227 {
228  entity e = statement_label(st);
229  const char* label_pattern = get_string_property("LABEL_EXCEPTION");
230  bool exception = (*label_pattern!=0) && (strstr(entity_user_name(e),label_pattern)!=NULL);
231  if(!entity_empty_label_p(e) && !exception) {
234  }
235  return true;
236 }
char * get_string_property(const char *)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
entity entity_empty_label(void)
Definition: entity.c:1105
bool entity_empty_label_p(entity e)
Definition: entity.c:666
#define statement_label(x)
Definition: ri.h:2450
void gen_clear_tabulated_element(gen_chunk *obj)
GEN_CLEAR_TABULATED_ELEMENT only clears the entry for object OBJ in the gen_tabulated_ and gen_tabula...
Definition: tabulated.c:251
A gen_chunk is used to store every object.
Definition: genC.h:58

References entity_empty_label(), entity_empty_label_p(), entity_user_name(), gen_clear_tabulated_element(), get_string_property(), and statement_label.

Referenced by clean_labels().

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

◆ entity_clean_declarations()

void entity_clean_declarations ( entity  module,
statement  s 
)

remove all entities declared in module but never used in s

Parameters
modulemodule to check
sstatement where entites may be used

to keep backward compatibility with hpfc

Parameters
moduleodule

Definition at line 177 of file util.c.

178 {
180  if( ! same_entity_p(curr,module)) {
183  }
184  else
185  curr=entity_undefined;
186 
188  if(fortran_module_p(module)) /* to keep backward compatibility with hpfc*/
190 
191  if(!entity_undefined_p(curr)){
194  }
195 }
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
static char * module
Definition: pips.c:74
#define entity_declarations(e)
MISC: newgen shorthands.
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
#define entity_undefined_p(x)
Definition: ri.h:2762
#define entity_undefined
Definition: ri.h:2761
static void entity_generate_missing_declarations(entity module, statement s)
check if all entities used in s and module are declared in module does not work as well as expected o...
Definition: util.c:140
static void statement_clean_declarations_helper(list declarations, statement stmt)
remove useless entities from declarations an entity is flagged useless when no reference is found in ...
Definition: util.c:80

References entity_declarations, entity_generate_missing_declarations(), entity_undefined, entity_undefined_p, fortran_module_p(), get_current_module_entity(), module, reset_current_module_entity(), same_entity_p(), set_current_module_entity(), and statement_clean_declarations_helper().

Referenced by compile_module(), and module_clean_declarations().

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

◆ entity_generate_missing_declarations()

static void entity_generate_missing_declarations ( entity  module,
statement  s 
)
static

check if all entities used in s and module are declared in module does not work as well as expected on c module because it does not fill the statement declaration

Parameters
modulemodule to check
sstatement where reference can be found

gather referenced entities

fill the declarations with missing entities (ohhhhh a nice 0(n²) algorithm

Definition at line 140 of file util.c.

141 {
142  /* gather referenced entities */
143  set referenced_entities = get_referenced_entities(s);
144 
145  /* fill the declarations with missing entities (ohhhhh a nice 0(n²) algorithm*/
146  list new = NIL;
147  SET_FOREACH(entity,e1,referenced_entities) {
149  new=CONS(ENTITY,e1,new);
150  }
151 
152  set_free(referenced_entities);
155 }
#define gen_chunk_undefined_p(c)
Definition: genC.h:75
#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
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
void * gen_find_eq(const void *item, const list seq)
Definition: list.c:422
#define SET_FOREACH(type_name, the_item, the_set)
enumerate set elements in their internal order.
Definition: newgen_set.h:78
void set_free(set)
Definition: set.c:332
void sort_list_of_entities(list l)
sorted in place.
Definition: entity.c:1358
set get_referenced_entities(void *elem)
retrieves the set of entities used in elem beware that this entities may be formal parameters,...
Definition: entity.c:3063
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CONS, ENTITY, entity_declarations, gen_chunk_undefined_p, gen_find_eq(), gen_nconc(), get_referenced_entities(), module, NIL, SET_FOREACH, set_free(), and sort_list_of_entities().

Referenced by entity_clean_declarations().

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

◆ filterout_statement()

static bool filterout_statement ( void *  obj)
static

Definition at line 48 of file util.c.

48  {
49  bool return_val = !INSTANCE_OF(statement,(gen_chunkp)obj);
50  return return_val;
51 }
#define INSTANCE_OF(type, value)
polymorhism thanks to newgen !

References INSTANCE_OF.

Referenced by statement_clean_declarations_helper().

+ Here is the caller graph for this function:

◆ find_loop_from_label()

statement find_loop_from_label ( statement  s,
entity  label 
)

hmmm...

when all header files are not yet generated cproto may silently fail to generate these headers. this few declarations allow to generate headers without anything else. ri needed for statement_mapping in pipsdbm...

Parameters
labelabel

Definition at line 218 of file util.c.

219 {
220  struct flfl ctx = { label, statement_undefined };
221  gen_context_recurse(s, &ctx,
223  return ctx.found;
224 }
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218
#define statement_undefined
Definition: ri.h:2419
Definition: util.c:199
entity label
Definition: util.c:200
statement found
Definition: util.c:201
static bool find_loop_from_label_walker(loop l, struct flfl *p)
Definition: util.c:204

References find_loop_from_label_walker(), flfl::found, gen_context_recurse, gen_null2(), flfl::label, loop_domain, and statement_undefined.

Referenced by full_unroll(), get_loop_execution_parallel(), loop_auto_unroll(), loop_expansion(), loop_expansion_init(), loop_pragma(), module_loops(), print_loopnest_dependence_cone(), set_loop_execution_parallel(), simdizer_auto_tile(), symbolic_tiling(), and unroll().

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

◆ find_loop_from_label_walker()

static bool find_loop_from_label_walker ( loop  l,
struct flfl p 
)
static

Definition at line 204 of file util.c.

205 {
207  entity
208  do_lab_ent = loop_label(l),
209  stmt_lab_ent = statement_label(s);
210  if (gen_eq(p->label, do_lab_ent) || gen_eq(p->label, stmt_lab_ent) )
211  {
212  p->found = s;
213  gen_recurse_stop(NULL);
214  }
215  return true;
216 }
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
gen_chunk * gen_get_ancestor(int, const void *)
return the first ancestor object found of the given type.
Definition: genClib.c:3560
bool gen_eq(const void *obj1, const void *obj2)
Definition: list.c:111
#define loop_label(x)
Definition: ri.h:1646

References flfl::found, gen_eq(), gen_get_ancestor(), gen_recurse_stop(), flfl::label, loop_label, statement_domain, and statement_label.

Referenced by find_loop_from_label().

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

◆ get_processor_number()

int get_processor_number ( void  )

Definition at line 261 of file util.c.

262 {
263  return 16;
264 }

◆ get_vector_register_length()

int get_vector_register_length ( void  )

Definition at line 266 of file util.c.

267 {
268  return 64;
269 }

◆ get_vector_register_number()

int get_vector_register_number ( void  )

Definition at line 271 of file util.c.

272 {
273  return 8;
274 }

◆ statement_clean_declarations()

void statement_clean_declarations ( statement  s)

remove all the entity declared in s but never referenced it's a lower version of use-def-elim !

cproto-generated files

Parameters
sstatement to check

Definition at line 164 of file util.c.

165 {
166  if(statement_block_p(s)) {
168  }
169 }
#define statement_block_p(stat)
#define statement_declarations(x)
Definition: ri.h:2460

References statement_block_p, statement_clean_declarations_helper(), and statement_declarations.

Referenced by module_clean_declarations().

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

◆ statement_clean_declarations_helper()

static void statement_clean_declarations_helper ( list  declarations,
statement  stmt 
)
static

remove useless entities from declarations an entity is flagged useless when no reference is found in stmt and when it is not used by an entity found in stmt

Parameters
declarationslist of entity to purge
stmtstatement where entities are used

look for entity that are used in the statement SG: we need to work on a copy of the declarations because of the RemoveLocalEntityFromDeclarations

filtered referenced entities are always used, some entity types listed in keep_entity cannot be wiped out

entities whose declaration have a side effect are always used too

one should check if dimensions do not have side effects either

do not keep the declaration, and remove it from any declaration_statement

Definition at line 80 of file util.c.

81  {
82  set referenced_entities =
86 
87  /* look for entity that are used in the statement
88  * SG: we need to work on a copy of the declarations because of
89  * the RemoveLocalEntityFromDeclarations
90  */
91  list decl_cpy = gen_copy_seq(declarations);
92  FOREACH(ENTITY,e,decl_cpy) {
93  /* filtered referenced entities are always used,
94  * some entity types listed in keep_entity cannot be wiped out*/
95  if(wipeout_entity(e) && !set_belong_p(referenced_entities, e)) {
96  /* entities whose declaration have a side effect are always used too */
97  bool has_side_effects_p = false;
98  value v = entity_initial(e);
99  list effects = NIL;
100  if(value_expression_p(v))
103  /* one should check if dimensions do not have side effects either */
104  if(entity_variable_p(e)) {
106  {
107  expression upper = dimension_upper(dim), lower = dimension_lower(dim);
110  }
111  }
112  pips_debug(5,"Evaluating effects on %s\n",entity_name(e));
113  FOREACH(EFFECT, eff, effects) {
114  ifdebug(6) {
115  print_effect(eff);
116  }
117  if(action_write_p(effect_action(eff)))
118  has_side_effects_p = true;
119  }
121 
122  /* do not keep the declaration, and remove it from any declaration_statement */
123  if(!has_side_effects_p) {
124  pips_debug(4,"Remove declaration for %s\n",entity_name(e));
126  }
127  }
128  }
129  gen_free_list(decl_cpy);
130 
131  set_free(referenced_entities);
132 }
list expression_to_proper_effects(expression)
#define effect_action(x)
Definition: effects.h:642
#define action_write_p(x)
Definition: effects.h:314
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
void gen_full_free_list(list l)
Definition: genClib.c:1023
list gen_copy_seq(list l)
Copy a list structure.
Definition: list.c:501
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
bool set_belong_p(const set, const void *)
Definition: set.c:194
#define print_effect(e)
Definition: print.c:336
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
set get_referenced_entities_filtered(void *elem, bool(*chunk_filter)(void *), bool(*entity_filter)(entity))
Same as get_referenced_entities, but will only consider entities that fulfills entity_filter and will...
Definition: entity.c:2982
void RemoveLocalEntityFromDeclarations(entity, entity, statement)
Definition: variable.c:120
#define dimension_lower(x)
Definition: ri.h:980
#define type_variable(x)
Definition: ri.h:2949
#define entity_name(x)
Definition: ri.h:2790
#define dimension_upper(x)
Definition: ri.h:982
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define value_expression_p(x)
Definition: ri.h:3080
#define value_expression(x)
Definition: ri.h:3082
#define entity_initial(x)
Definition: ri.h:2796
#define ifdebug(n)
Definition: sg.c:47
Definition: statement.c:54
static bool wipeout_entity(entity e)
entities that match the following conditions are not cleaned from declarations:
Definition: util.c:56
static bool filterout_statement(void *obj)
Definition: util.c:48

References action_write_p, DIMENSION, dimension_lower, dimension_upper, EFFECT, effect_action, ENTITY, entity_initial, entity_name, entity_type, entity_variable_p, expression_to_proper_effects(), filterout_statement(), FOREACH, gen_copy_seq(), gen_free_list(), gen_full_free_list(), gen_nconc(), get_current_module_entity(), get_referenced_entities_filtered(), ifdebug, NIL, pips_debug, print_effect, RemoveLocalEntityFromDeclarations(), set_belong_p(), set_free(), type_variable, value_expression, value_expression_p, variable_dimensions, and wipeout_entity().

Referenced by entity_clean_declarations(), and statement_clean_declarations().

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

◆ wipeout_entity()

static bool wipeout_entity ( entity  e)
static

entities that match the following conditions are not cleaned from declarations:

Definition at line 56 of file util.c.

56  {
57  pips_debug(6,"Wipeout entity evaluating %s\n",entity_name(e));
58  bool return_val = entity_not_constant_or_intrinsic_p(e) && // filters out constants and intrinsics
59  !formal_parameter_p(e) &&
61  !entity_area_p(e)&&
62  !entity_struct_p(e)&&
63  !entity_union_p(e) &&
64  !typedef_entity_p(e);
65 
66  pips_debug(6,"return %d\n",return_val);
67 
68  return return_val;
69 }
bool entity_area_p(entity e)
Definition: area.c:149
bool entity_not_constant_or_intrinsic_p(entity e)
Default entity filter for get_referenced_entities()
Definition: entity.c:3050
bool entity_struct_p(entity e)
Is entity e the entity corresponding to a struct declaration?
Definition: entity.c:1002
bool typedef_entity_p(entity e)
Definition: entity.c:1902
bool entity_union_p(entity e)
Is entity e an entity representing the union declaration?
Definition: entity.c:1038
bool formal_parameter_p(entity)
Definition: variable.c:1489
#define entity_storage(x)
Definition: ri.h:2794
#define storage_return_p(x)
Definition: ri.h:2516

References entity_area_p(), entity_name, entity_not_constant_or_intrinsic_p(), entity_storage, entity_struct_p(), entity_union_p(), formal_parameter_p(), pips_debug, storage_return_p, and typedef_entity_p().

Referenced by statement_clean_declarations_helper().

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