PIPS
defs_elim.c File Reference
#include "local.h"
#include "prettyprint.h"
+ Include dependency graph for defs_elim.c:

Go to the source code of this file.

Functions

static vertex get_vertex_of_statement (graph dg, statement stmt)
 defs_elim.c More...
 
bool true_dependence_with_entity_p (conflict conf, entity e)
 =========================================================================== More...
 
static bool entity_dynamic_p (entity e)
 =========================================================================== More...
 
bool defs_elim_of_assign_call (statement assign_stmt, graph dg)
 =========================================================================== More...
 
bool defs_elim_of_statement (statement s, graph dg)
 =========================================================================== More...
 
void defs_elim_of_unstructured (unstructured u, graph dg)
 =========================================================================== More...
 

Function Documentation

◆ defs_elim_of_assign_call()

bool defs_elim_of_assign_call ( statement  assign_stmt,
graph  dg 
)

===========================================================================

bool defs_elim_of_assign_call(statement assign_stmt, graph dg): returns true if "assign_stmt" is to be eliminated. It is eliminated if the lhs of this assignment verifies two conditions :

  1. it is a local variable
  2. it is not at the source of a def-use dependence, ie true dependence.

Definitions upon non local (non dynamic) variables are always kept.

Gets the vertex of the dependence graph that gives all the edges of which the assign statement is the source.

We scan all the dependences of the assign statement. If at least one true dependence is found, the statement is not removed.

Parameters
assign_stmtssign_stmt
dgg

Definition at line 136 of file defs_elim.c.

139 {
140  call assign_call;
141  expression lhs_exp;
142  entity lhs_ent;
143  vertex stmt_vertex;
144  list succs;
145  bool true_dep_found = false;
146 
148  pips_internal_error("Statement must be a CALL");
149 
150  assign_call = instruction_call(statement_instruction(assign_stmt));
151  if(! ENTITY_ASSIGN_P(call_function(assign_call)))
152  pips_internal_error("Call must be an ASSIGN");
153 
154  pips_debug(5, "begin ASSIGN : %s\n",
155  words_to_string(Words_Call(assign_call, 0, true, true)));
156 
157  lhs_exp = EXPRESSION(CAR(call_arguments(assign_call)));
159  pips_internal_error("Lhs must be a REFERENCE");
160 
162 
163 /* Definitions upon non local (non dynamic) variables are always kept. */
164  if(! entity_dynamic_p(lhs_ent) )
165  return(false);
166 
167 /* Gets the vertex of the dependence graph that gives all the edges of
168  * which the assign statement is the source.
169  */
170  stmt_vertex = get_vertex_of_statement(dg, assign_stmt);
171 
172 /* We scan all the dependences of the assign statement. If at least one
173  * true dependence is found, the statement is not removed.
174  */
175  if(stmt_vertex != vertex_undefined)
176  {
177  list confs;
178  dg_arc_label dal;
179  succs = vertex_successors(stmt_vertex);
180  for(; (succs != NIL) && (! true_dep_found) ; succs = CDR(succs))
181  {
183  confs = dg_arc_label_conflicts(dal);
184  for(; (confs != NIL) && (! true_dep_found) ; confs = CDR(confs))
185  if( true_dependence_with_entity_p(CONFLICT(CAR(confs)), lhs_ent) )
186  true_dep_found = true;
187  }
188  }
189  else
190  user_warning("defs_elim_of_assign_call",
191  "Vertex of assign stmt should not be undefined\n");
192 
193  debug(5, "defs_elim_of_assign_call", "end ASSIGN , true dep : %s\n",
194  bool_to_string(true_dep_found));
195 
196  return(! true_dep_found);
197 }
static graph dg
dg is the dependency graph ; FIXME : should not be static global ?
Definition: chains.c:124
static vertex get_vertex_of_statement(graph dg, statement stmt)
– defs_elim.c
Definition: defs_elim.c:49
bool true_dependence_with_entity_p(conflict conf, entity e)
===========================================================================
Definition: defs_elim.c:82
static bool entity_dynamic_p(entity e)
===========================================================================
Definition: defs_elim.c:114
struct _newgen_struct_dg_arc_label_ * dg_arc_label
Definition: dg.h:60
#define CONFLICT(x)
CONFLICT.
Definition: dg.h:134
#define dg_arc_label_conflicts(x)
Definition: dg.h:201
#define vertex_undefined
Definition: graph.h:128
#define successor_arc_label(x)
Definition: graph.h:116
#define vertex_successors(x)
Definition: graph.h:154
#define SUCCESSOR(x)
SUCCESSOR.
Definition: graph.h:86
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define pips_internal_error
Definition: misc-local.h:149
#define user_warning(fn,...)
Definition: misc-local.h:262
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
string bool_to_string(bool)
Definition: string.c:243
list Words_Call(call obj, int precedence, bool leftmost, bool is_a_subroutine)
Definition: misc.c:2597
#define ENTITY_ASSIGN_P(e)
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
@ is_syntax_reference
Definition: ri.h:2691
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
@ is_instruction_call
Definition: ri.h:1474
#define instruction_tag(x)
Definition: ri.h:1511
#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 expression_syntax(x)
Definition: ri.h:1247
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
string words_to_string(cons *lw)
Definition: print.c:211

References bool_to_string(), call_arguments, call_function, CAR, CDR, CONFLICT, debug(), dg, dg_arc_label_conflicts, ENTITY_ASSIGN_P, entity_dynamic_p(), EXPRESSION, expression_syntax, get_vertex_of_statement(), instruction_call, instruction_tag, is_instruction_call, is_syntax_reference, NIL, pips_debug, pips_internal_error, reference_variable, statement_instruction, SUCCESSOR, successor_arc_label, syntax_reference, syntax_tag, true_dependence_with_entity_p(), user_warning, vertex_successors, vertex_undefined, Words_Call(), and words_to_string().

Referenced by defs_elim_of_statement().

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

◆ defs_elim_of_statement()

bool defs_elim_of_statement ( statement  s,
graph  dg 
)

===========================================================================

bool defs_elim_of_statement(statement s, graph dg): returns true if "s" is to be eliminated. As we eliminate assign statements, only statement with call to the assign function may be eliminated.

Called_functions : _ make_empty_statement() : ri-util/statement.c

We scan all the statements of the block, and we build in the same time a new block where the statements to delete do not appear.

Parameters
dgg

Definition at line 211 of file defs_elim.c.

214 {
215  bool elim = false;
217 
218  debug(4, "defs_elim_of_statement", "begin STATEMENT\n");
219 
220  switch(instruction_tag(inst))
221  {
222  /* We scan all the statements of the block, and we build in the same time
223  * a new block where the statements to delete do not appear.
224  */
225  case is_instruction_block :
226  {
227  list new_block = NIL,
228  block = instruction_block(inst);
229  for(; block != NIL ; block = CDR(block))
230  {
233  new_block = gen_nconc(new_block, CONS(STATEMENT, stmt, NIL));
234  }
235  instruction_block(inst) = new_block;
236  break;
237  }
238  case is_instruction_test :
239  {
240  test t = instruction_test(inst);
245  break;
246  }
247  case is_instruction_loop :
248  {
249  loop l = instruction_loop(inst);
252  break;
253  }
254  case is_instruction_call :
255  {
256  call c = instruction_call(inst);
257 
258  debug(4, "defs_elim_of_statement", "Stmt CALL: %s\n",
260 
262  elim = defs_elim_of_assign_call(s, dg);
263  break;
264  }
265  case is_instruction_goto : break;
267  {
269  break;
270  }
271  default : pips_internal_error("Bad instruction tag");
272  }
273  debug(4, "defs_elim_of_statement", "end STATEMENT\n");
274 
275  return(elim);
276 }
bool defs_elim_of_statement(statement s, graph dg)
===========================================================================
Definition: defs_elim.c:211
bool defs_elim_of_assign_call(statement assign_stmt, graph dg)
===========================================================================
Definition: defs_elim.c:136
void defs_elim_of_unstructured(unstructured u, graph dg)
===========================================================================
Definition: defs_elim.c:291
#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
#define is_instruction_block
soft block->sequence transition
#define instruction_block(i)
#define make_empty_statement
An alias for make_empty_block_statement.
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
#define loop_body(x)
Definition: ri.h:1644
#define instruction_loop(x)
Definition: ri.h:1520
#define test_false(x)
Definition: ri.h:2837
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_loop
Definition: ri.h:1471
#define test_true(x)
Definition: ri.h:2835
#define instruction_test(x)
Definition: ri.h:1517
#define instruction_unstructured(x)
Definition: ri.h:1532
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
Definition: statement.c:54

References call_function, CAR, CDR, CONS, debug(), defs_elim_of_assign_call(), defs_elim_of_statement(), defs_elim_of_unstructured(), dg, ENTITY_ASSIGN_P, entity_local_name(), gen_nconc(), instruction_block, instruction_call, instruction_loop, instruction_tag, instruction_test, instruction_unstructured, is_instruction_block, is_instruction_call, is_instruction_goto, is_instruction_loop, is_instruction_test, is_instruction_unstructured, loop_body, make_empty_statement, NIL, pips_internal_error, STATEMENT, statement_instruction, test_false, and test_true.

Referenced by atomizer(), defs_elim_of_statement(), and defs_elim_of_unstructured().

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

◆ defs_elim_of_unstructured()

void defs_elim_of_unstructured ( unstructured  u,
graph  dg 
)

===========================================================================

void defs_elim_of_unstructured(unstructured, graph dg): computes the elimination of all the definitions with no def-use dependence of an unstructured instruction.

If the statement of the control of a node of the control graph has to be eliminated, it is replaced by an empty block of statement.

Called_functions : _ make_empty_statement() : ri-util/statement.c

Parameters
dgg

Definition at line 291 of file defs_elim.c.

294 {
295  list blocs = NIL;
296 
297  debug(3, "defs_elim_of_unstructured", "begin UNSTRUCTURED\n");
298 
300  if(elim) { control_statement(c) = make_empty_statement();};},
301  unstructured_control( u ), blocs);
302 
303  gen_free_list(blocs);
304 
305  debug(3, "defs_elim_of_unstructured", "end UNSTRUCTURED\n");
306 }
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#define unstructured_control
After the modification in Newgen: unstructured = entry:control x exit:control we have create a macro ...
#define control_statement(x)
Definition: ri.h:941

References CONTROL_MAP, control_statement, debug(), defs_elim_of_statement(), dg, gen_free_list(), make_empty_statement, NIL, and unstructured_control.

Referenced by defs_elim_of_statement().

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

◆ entity_dynamic_p()

static bool entity_dynamic_p ( entity  e)
static

===========================================================================

static bool entity_dynamic_p(entity e): returns true if "e" is a local variable, ie an entity with a storage DYNAMIC.

Called_functions : _ dynamic_area_p() : ri-util/util.c

Definition at line 114 of file defs_elim.c.

115 {
116  ram r;
117  storage s = entity_storage(e);
118 
119  if(storage_tag(s) != is_storage_ram)
120  return(false);
121  r = storage_ram(s);
123  return(true);
124  return(false);
125 }
bool dynamic_area_p(entity aire)
Definition: area.c:68
#define storage_tag(x)
Definition: ri.h:2515
#define entity_storage(x)
Definition: ri.h:2794
#define ram_section(x)
Definition: ri.h:2249
@ is_storage_ram
Definition: ri.h:2492
#define storage_ram(x)
Definition: ri.h:2521

References dynamic_area_p(), entity_storage, is_storage_ram, ram_section, storage_ram, and storage_tag.

Referenced by defs_elim_of_assign_call().

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

◆ get_vertex_of_statement()

static vertex get_vertex_of_statement ( graph  dg,
statement  stmt 
)
static

defs_elim.c

package atomizer : Alexis Platonoff, aout 91

Those functions remove the definition instructions with no def-use dependence. =========================================================================== static vertex get_vertex_of_statement(graph dg, statement stmt): returns the vertex of "dg" corresponding to "stmt".

We scan all the "dg" until we find the "vertex" with the same "ordering" as "stmt".

Definition at line 49 of file defs_elim.c.

52 {
54  list dg_vertices = graph_vertices(dg);
55  bool not_found = true;
56 
57  for(; (dg_vertices != NIL) && not_found ; dg_vertices = CDR(dg_vertices))
58  {
59  vertex v = VERTEX(CAR(dg_vertices));
61  {
62  rv = v;
63  not_found = false;
64  }
65  }
66  return(rv);
67 }
#define graph_vertices(x)
Definition: graph.h:82
#define VERTEX(x)
VERTEX.
Definition: graph.h:122
#define statement_ordering(x)
Definition: ri.h:2454
int vertex_ordering(vertex)
Definition: util.c:51

References CAR, CDR, dg, graph_vertices, NIL, statement_ordering, VERTEX, vertex_ordering(), and vertex_undefined.

Referenced by defs_elim_of_assign_call().

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

◆ true_dependence_with_entity_p()

bool true_dependence_with_entity_p ( conflict  conf,
entity  e 
)

===========================================================================

defs_elim.c

bool true_dependence_with_entity_p(conflict conf, entity e): returns TRUE if the conflict "conf" is a true dependence upon the entity "e".

A true dependence is a conflict with a Write at the "source" and a Read at the "sink".

called functions : _ effect_entity() : ri-util/util.c _ same_entity_p() : ri-util/util.c

Parameters
confonf

Definition at line 82 of file defs_elim.c.

85 {
86  effect source_eff, sink_eff;
87  entity source_ent, sink_ent;
88 
89  source_eff = conflict_source(conf);
90  sink_eff = conflict_sink(conf);
91  source_ent = effect_entity(source_eff);
92  sink_ent = effect_entity(sink_eff);
93 
94  pips_debug(6, " CONFLICT : %s --> %s\n",
95  effect_to_string(source_eff),
96  effect_to_string(sink_eff));
97 
98  if(! same_entity_p(source_ent, sink_ent))
99  pips_internal_error("Source and sink entities must be equal");
100 
101  return( same_entity_p(e, source_ent) &&
102  (action_tag(effect_action(source_eff)) == is_action_write) &&
103  (action_tag(effect_action(sink_eff)) == is_action_read) );
104 }
#define conflict_sink(x)
Definition: dg.h:167
#define conflict_source(x)
Definition: dg.h:165
string effect_to_string(effect)
entity effect_entity(effect)
cproto-generated files
Definition: effects.c:52
#define effect_action(x)
Definition: effects.h:642
#define action_tag(x)
Definition: effects.h:310
@ is_action_write
Definition: effects.h:293
@ is_action_read
Definition: effects.h:292
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321

References action_tag, conflict_sink, conflict_source, effect_action, effect_entity(), effect_to_string(), is_action_read, is_action_write, pips_debug, pips_internal_error, and same_entity_p().

Referenced by defs_elim_of_assign_call().

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