PIPS
declarations.c File Reference
#include <stdio.h>
#include "genC.h"
#include "linear.h"
#include "pipsdbm.h"
#include "misc.h"
#include "properties.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "effects-util.h"
#include "effects-generic.h"
#include "control.h"
#include "transformations.h"
+ Include dependency graph for declarations.c:

Go to the source code of this file.

Data Structures

struct  entity_used_somewhere_param
 

Functions

static void remove_unread_variable (statement s, entity e)
 
static bool entity_may_conflict_with_a_formal_parameter_p (entity e, entity module)
 
static void entity_used_somewhere_walker (statement s, entity_used_somewhere_param *p)
 
static bool entity_read_somewhere_p (entity e, statement in)
 
static void remove_unread_variables (statement s)
 
void module_clean_declarations (entity module, statement module_statement)
 declarations.c More...
 
bool clean_declarations (const string module_name)
 A phase to remove the declaration of useless variables. More...
 

Function Documentation

◆ clean_declarations()

bool clean_declarations ( const string  module_name)

A phase to remove the declaration of useless variables.

It recursively calls statement_remove_unused_declarations on all module statement

Parameters
[in]module_nameis the name of the module to process
Returns
true because always successful

prelude

first remove any statement that writes only variable that are never read

body

ostlude

Parameters
module_nameodule_name

Definition at line 155 of file declarations.c.

156 {
157  /* prelude */
161 
162  debug_on("CLEAN_DECLARATIONS_DEBUG_LEVEL");
163 
164  /* first remove any statement that writes only variable that are never read */
166 
167  /* body*/
169 
171 
172  debug_off();
173 
174  /*postlude */
178  return true;
179 }
void set_cumulated_rw_effects(statement_effects)
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
#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
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
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
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
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
static void remove_unread_variables(statement s)
Definition: declarations.c:116
void module_clean_declarations(entity module, statement module_statement)
declarations.c
Definition: declarations.c:140

References db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, gen_recurse, gen_true(), get_current_module_entity(), get_current_module_statement(), module_clean_declarations(), module_name(), module_name_to_entity(), remove_unread_variables(), reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), and statement_domain.

+ Here is the call graph for this function:

◆ entity_may_conflict_with_a_formal_parameter_p()

static bool entity_may_conflict_with_a_formal_parameter_p ( entity  e,
entity  module 
)
static

Definition at line 91 of file declarations.c.

92 {
94  if(formal_parameter_p(d) && entities_may_conflict_p(e,d)) return true;
95  return false;
96 }
bool entities_may_conflict_p(entity e1, entity e2)
Check if two entities may conflict.
Definition: conflicts.c:984
#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
static char * module
Definition: pips.c:74
#define entity_declarations(e)
MISC: newgen shorthands.
bool formal_parameter_p(entity)
Definition: variable.c:1489

References entities_may_conflict_p(), entity_declarations, FOREACH, formal_parameter_p(), and module.

Referenced by remove_unread_variables().

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

◆ entity_read_somewhere_p()

static bool entity_read_somewhere_p ( entity  e,
statement  in 
)
static

Definition at line 110 of file declarations.c.

111 {
112  entity_used_somewhere_param p = { e, false };
114  return p.result;
115 }
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
static void entity_used_somewhere_walker(statement s, entity_used_somewhere_param *p)
Definition: declarations.c:103

References entity_used_somewhere_walker(), gen_context_recurse, gen_true2(), entity_used_somewhere_param::result, and statement_domain.

Referenced by remove_unread_variables().

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

◆ entity_used_somewhere_walker()

static void entity_used_somewhere_walker ( statement  s,
entity_used_somewhere_param p 
)
static

Definition at line 103 of file declarations.c.

104 {
107  { p->result = true; gen_recurse_stop(0); }
108 }
list load_cumulated_rw_effects_list(statement)
bool effects_read_variable_p(list, entity)
Definition: effects.c:1123
void gen_recurse_stop(void *obj)
Tells the recursion not to go in this object.
Definition: genClib.c:3251
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References entity_used_somewhere_param::e, effects_read_variable_p(), gen_recurse_stop(), load_cumulated_rw_effects_list(), and entity_used_somewhere_param::result.

Referenced by entity_read_somewhere_p().

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

◆ module_clean_declarations()

void module_clean_declarations ( entity  module,
statement  module_statement 
)

declarations.c

Parameters
moduleodule
module_statementodule_statement

Definition at line 140 of file declarations.c.

140  {
142 
144 }
static statement module_statement
Definition: alias_check.c:125
void statement_clean_declarations(statement)
cproto-generated files
Definition: util.c:164
void entity_clean_declarations(entity, statement)
remove all entities declared in module but never used in s
Definition: util.c:177

References entity_clean_declarations(), gen_recurse, gen_true(), module, module_statement, statement_clean_declarations(), and statement_domain.

Referenced by clean_declarations(), and do_scalar_renaming().

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

◆ remove_unread_variable()

static void remove_unread_variable ( statement  s,
entity  e 
)
static

we only manage written entity in the form of e binary_op something else

Definition at line 50 of file declarations.c.

51 {
53  {
55  bool entity_written = false;
58  { entity_written = true; break; }
59  if(entity_written) /* we only manage written entity in the form of e binary_op something else */
60  {
61  call c = statement_call(s);
62  expression lhs = binary_call_lhs(c);
64  {
65  list next = CDR(call_arguments(c));
66  if(ENDP(next))
68  else if( ENDP(CDR(next)) ) {
69  expression rhs = binary_call_rhs(c);
70  if(expression_call_p(rhs))
71  {
72  call new_c = expression_call(rhs);
74  free_call(c);
76  }
77  else {
81  }
82  }
83  else {
84  pips_internal_error("case unhandled yet\nfell free to contribute :-)");
85  }
86  }
87  }
88 
89  }
90 }
instruction make_instruction_expression(expression _field_)
Definition: ri.c:1196
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
void free_instruction(instruction p)
Definition: ri.c:1118
void free_call(call p)
Definition: ri.c:236
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define effect_write_p(eff)
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
bool entities_must_conflict_p(entity e1, entity e2)
Check if two entities must conflict.
Definition: conflicts.c:992
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
call statement_call(statement)
Get the call of a statement.
Definition: statement.c:1406
bool statement_call_p(statement)
Definition: statement.c:364
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
#define pips_internal_error
Definition: misc-local.h:149
#define binary_call_rhs(c)
#define CONTINUE_FUNCTION_NAME
#define binary_call_lhs(c)
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
bool expression_call_p(expression e)
Definition: expression.c:415
call expression_call(expression e)
Definition: expression.c:445
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define syntax_call(x)
Definition: ri.h:2736
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_call(x)
Definition: ri.h:1529
#define call_arguments(x)
Definition: ri.h:711
#define call_undefined
Definition: ri.h:685
#define expression_syntax(x)
Definition: ri.h:1247
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References binary_call_lhs, binary_call_rhs, call_arguments, call_function, call_undefined, CDR, CONTINUE_FUNCTION_NAME, copy_expression(), declaration_statement_p(), EFFECT, effect_any_reference, effect_write_p, ENDP, entities_may_conflict_p(), entities_must_conflict_p(), entity_intrinsic(), exp, expression_call(), expression_call_p(), expression_reference(), expression_reference_p(), expression_syntax, FOREACH, free_call(), free_instruction(), instruction_call, load_cumulated_rw_effects_list(), make_instruction_expression(), pips_internal_error, reference_variable, statement_call(), statement_call_p(), statement_instruction, and syntax_call.

Referenced by remove_unread_variables().

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

◆ remove_unread_variables()

static void remove_unread_variables ( statement  s)
static

it is useless to try to remove formal parameters

and we cannot afford removing something that may implies aliasing

the entity is never read, it is disposable

Definition at line 116 of file declarations.c.

117 {
118  if(statement_block_p(s))
119  {
121  {
122  if(entity_variable_p(e)) {
123  if(!entity_may_conflict_with_a_formal_parameter_p(e,get_current_module_entity()) && /* it is useless to try to remove formal parameters */
124  entity_scalar_p(e) ) /* and we cannot afford removing something that may implies aliasing */
125  {
126  bool effects_read_variable = entity_read_somewhere_p(e,s);
127  if(!effects_read_variable) {
128  /* the entity is never read, it is disposable */
129  pips_debug(4,"Entity %s is never read, we can remove "
130  "statements that only produce it.\n",
131  entity_name(e));
133  }
134  }
135  }
136  }
137  }
138 }
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define statement_block_p(stat)
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
bool entity_scalar_p(entity)
The concrete type of e is a scalar type.
Definition: variable.c:1113
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_name(x)
Definition: ri.h:2790
#define statement_declarations(x)
Definition: ri.h:2460
static void remove_unread_variable(statement s, entity e)
Definition: declarations.c:50
static bool entity_read_somewhere_p(entity e, statement in)
Definition: declarations.c:110
static bool entity_may_conflict_with_a_formal_parameter_p(entity e, entity module)
Definition: declarations.c:91

References ENTITY, entity_may_conflict_with_a_formal_parameter_p(), entity_name, entity_read_somewhere_p(), entity_scalar_p(), entity_variable_p, FOREACH, gen_context_recurse, gen_true2(), get_current_module_entity(), pips_debug, remove_unread_variable(), statement_block_p, statement_declarations, and statement_domain.

Referenced by clean_declarations().

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