PIPS
regions_to_loops.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

statement make_write_loopbody (entity, expression, list)
 Warning! Do not modify this file that is automatically generated! More...
 
statement make_read_loopbody (entity, entity, list)
 Makes the body of a "read" loop. More...
 
statement region_to_loop_nest (effect, bool, entity, expression)
 
expression make_addition (expression, expression)
 Makes an addition expression from two expressions. More...
 
void replace_indices_region (effect, list *, int, entity)
 
statement make_sequence_from_statement_list (list)
 Make a sequence from a statement list The equivalent of this function was already made somewhere else. More...
 
bool regions_to_loops (char *)
 This phase replaces the body of a function by automatically generated loops where the read and write statements are representative of the original function. More...
 

Function Documentation

◆ make_addition()

expression make_addition ( expression  e1,
expression  e2 
)

Makes an addition expression from two expressions.

Parameters
e11
e22

Definition at line 175 of file regions_to_loops.c.

175  {
176  entity add_ent = gen_find_entity("TOP-LEVEL:+");
177  return make_call_expression(add_ent, CONS(EXPRESSION, e1, CONS(EXPRESSION, e2, NIL)));
178 }
entity gen_find_entity(char *s)
Definition: ri.c:2551
#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
expression make_call_expression(entity e, list l)
Build an expression that call an function entity with an argument list.
Definition: expression.c:321
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217

References CONS, EXPRESSION, gen_find_entity(), make_call_expression(), and NIL.

Referenced by regions_to_loops().

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

◆ make_read_loopbody()

statement make_read_loopbody ( entity  v,
entity  readVar,
list  vl 
)

Makes the body of a "read" loop.

An assign statement is made using the variables generated and the array.

Parameters
readVareadVar
vll

Definition at line 106 of file regions_to_loops.c.

106  {
108  expression e2 = entity_to_expression(readVar);
109  statement s = make_assign_statement(e2, e);
110  pips_assert("read body is not properly generated", statement_consistent_p(s));
111  return s;
112 }
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
bool statement_consistent_p(statement p)
Definition: ri.c:2195
list gen_full_copy_list(list l)
Copy a list structure with element copy.
Definition: list.c:535
statement make_assign_statement(expression, expression)
Definition: statement.c:583
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
expression reference_to_expression(reference r)
Definition: expression.c:196
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165

References entity_to_expression(), gen_full_copy_list(), make_assign_statement(), make_reference(), pips_assert, reference_to_expression(), and statement_consistent_p().

Referenced by Psysteme_to_loop_nest().

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

◆ make_sequence_from_statement_list()

statement make_sequence_from_statement_list ( list  l)

Make a sequence from a statement list The equivalent of this function was already made somewhere else.

However when the list only has one element it returns that element instead of making a sequence of one element containing that element. This function always makes a sequence

Definition at line 243 of file regions_to_loops.c.

243  {
244  if (l == NIL) {
245  return statement_undefined;
246  }
247  else {
248  if (gen_length(l) == 1) {
250  }
251  else {
252  return make_block_statement(l);
253  }
254  }
255 }
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
statement make_block_with_stmt_if_not_already(statement)
Build a statement block from a statement if not already a statement block.
Definition: statement.c:768
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define statement_undefined
Definition: ri.h:2419
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References CAR, gen_length(), make_block_statement(), make_block_with_stmt_if_not_already(), NIL, STATEMENT, and statement_undefined.

Referenced by regions_to_loops().

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

◆ make_write_loopbody()

statement make_write_loopbody ( entity  v,
expression  exp,
list  vl 
)

Warning! Do not modify this file that is automatically generated!

Modify src/Libs/regions_to_loops/regions_to_loops-local.h instead, to add your own modifications. header file built by cproto regions_to_loops-local.h cproto-generated files regions_to_loops.c

Warning! Do not modify this file that is automatically generated!

An assign statement is made using the array and the expression built using read variables. This allows to avoid dead code elimination.

Parameters
expxp
vll

Definition at line 96 of file regions_to_loops.c.

96  {
99  pips_assert("write body is not properly generated", statement_consistent_p(s));
100  return s;
101 }
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References exp, gen_full_copy_list(), make_assign_statement(), make_reference(), pips_assert, reference_to_expression(), and statement_consistent_p().

Referenced by Psysteme_to_loop_nest().

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

◆ region_to_loop_nest()

statement region_to_loop_nest ( effect  ,
bool  ,
entity  ,
expression   
)

◆ regions_to_loops()

bool regions_to_loops ( char *  module_name)

This phase replaces the body of a function by automatically generated loops where the read and write statements are representative of the original function.

If the regions are not computable then the function is not modified.

Parameters
module_nameodule_name

Definition at line 261 of file regions_to_loops.c.

261  {
262  // List of the read/write regions
263  list l_write = NIL;
264  list l_read = NIL;
265 
266  // List of variables to add in the declaration statement
267  list declarations_to_add = NIL;
268 
269  // Standard initialization
271  statement module_stat = (statement)db_get_memory_resource(DBR_CODE, module_name, true);
272  set_ordering_to_statement(module_stat);
274  set_current_module_statement(module_stat);
276 
277  // We fetch the summary region list
278  list func_regions = effects_to_list((effects)db_get_memory_resource(DBR_SUMMARY_REGIONS, module_name, true));
279 
280  // And separate the R/W regions into two lists
281  l_write = regions_write_regions(func_regions);
282  l_read = regions_read_regions(func_regions);
283  // We remove irrelevant regions from the lists
284  filter_regions(&l_read);
285  filter_regions(&l_write);
286 
287  // If no regions were fetched or if no region is left after filtering then we do nothing
288  if (l_read == NIL && l_write == NIL) {
289  // Standard reset
296  return true;
297  }
298 
299  // List of statement we are going to use to build the new body of the function
300  list sl = NIL;
301  // Indices for variable and indices generation
302  int varNum = 0;
303  int indNum = 0;
304  // List of the generated variables for read purposes
305  list readVar = NIL;
306  // a simple "3" in order to complete the "write" assign statements in case there is no read
307  // Given that X1, X2 .. XN are the variables used to make the read statements
308  // X1+X2+..+XN+3 is the expression used to make the write statements
309  // In theory this avoids dead code elimination
311  // loop indice
312  int i = 0;
313 
314  // We build as many variable as there are read regions
315  for (i = 0; i < (int) gen_length(l_read); i++) {
317  // We add the new variable to the current expression used for write assignments
318  addVarRead = make_addition(addVarRead, entity_to_expression(e));
319  varNum++;
320  // We add this variable to a specific list
321  readVar = CONS(ENTITY, e, readVar);
322  }
323  // The variables for read purposes having been made, we can add them to the list of declarations to add
324  declarations_to_add = gen_nconc(declarations_to_add, readVar);
325 
326  // Read regions processing
327  // We replace the PHI variables of the region, we create a loop statement for this region and add
328  // it to the list of statement of the new body
329  FOREACH(effect, e, l_read) {
330  replace_indices_region(e, &declarations_to_add, indNum, module);
331  indNum++;
333  POP(readVar);
334  sl = CONS(STATEMENT, s, sl);
335  }
336 
337  // Write regions processing
338  // Same processing as above.
339  FOREACH(effect, e, l_write) {
340  replace_indices_region(e, &declarations_to_add, indNum, module);
341  indNum++;
342  statement s = region_to_loop_nest(e, false, entity_undefined, addVarRead);
343  sl = CONS(STATEMENT, s, sl);
344  }
345 
346  // Inverting and duplicating the elements of the list in order to avoid corrupting data structures.
348  // Make a new sequence statement in order to replace the old one
350 
351  // Using the list of variables needed to be declared we call a function
352  // appending declaration statements to our main sequence
353  declarations_to_add = gen_full_copy_list(gen_nreverse(declarations_to_add));
354  FOREACH(entity, e, declarations_to_add) {
355  ns = add_declaration_statement(ns, e);
356  }
357 
358  // Consistency check
359  pips_assert("list of statement is not consistent", statement_consistent_p(ns));
360  pips_assert("list of statement is not sequence", statement_sequence_p(ns));
361 
362  // Free of the old body
363  free_statement(module_stat);
364 
365  // Reorder and putting resource for the new function body
366  module_stat = ns;
367  module_reorder(module_stat);
368  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name, module_stat);
369 
370  // Standard reset
377  return true;
378 }
void free_statement(statement p)
Definition: ri.c:2189
void const char const char const int
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
list regions_write_regions(list)
list regions_read_regions(list)
void set_methods_for_convex_effects(void)
methods.c
Definition: methods.c:235
void reset_out_summary_regions_list(void)
void reset_out_summary_effects_list(void)
out_effects_engine.c
void generic_effects_reset_all_methods(void)
list effects_to_list(effects)
Definition: effects.c:209
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
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
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#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
void * gen_car(list l)
Definition: list.c:364
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
bool statement_sequence_p(statement)
Statement classes induced from instruction type.
Definition: statement.c:335
statement add_declaration_statement(statement, entity)
Definition: statement.c:2790
hash_table set_ordering_to_statement(statement s)
To be used instead of initialize_ordering_to_statement() to make sure that the hash table ots is in s...
Definition: ordering.c:172
void reset_ordering_to_statement(void)
Reset the mapping from ordering to statement.
Definition: ordering.c:185
static char * module
Definition: pips.c:74
static void filter_regions(list *l)
tatic_control
void replace_indices_region(region r, list *dadd, int indNum, entity module)
This function is in charge of replacing the PHI entity of the region by generated indices.
expression make_addition(expression e1, expression e2)
Makes an addition expression from two expressions.
statement make_sequence_from_statement_list(list l)
Make a sequence from a statement list The equivalent of this function was already made somewhere else...
statement region_to_loop_nest(region r, bool isRead, entity readVar, expression exp)
Returns the entity corresponding to the global name.
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
entity make_new_module_variable(entity, int)
Make a new module integer variable of name X<d>.
Definition: variable.c:830
entity make_integer_constant_entity(_int)
entity make_integer_constant_entity(int c) make entity for integer constant c
Definition: variable.c:1345
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_undefined
Definition: ri.h:2761
#define expression_undefined
Definition: ri.h:1223
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References add_declaration_statement(), CONS, db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, effects_to_list(), ENTITY, entity_to_expression(), entity_undefined, expression_undefined, filter_regions(), FOREACH, free_statement(), gen_car(), gen_full_copy_list(), gen_length(), gen_nconc(), gen_nreverse(), generic_effects_reset_all_methods(), get_current_module_entity(), int, local_name_to_top_level_entity(), make_addition(), make_integer_constant_entity(), make_new_module_variable(), make_sequence_from_statement_list(), module, module_name(), module_reorder(), NIL, pips_assert, POP, region_to_loop_nest(), regions_read_regions(), regions_write_regions(), replace_indices_region(), reset_current_module_entity(), reset_current_module_statement(), reset_ordering_to_statement(), reset_out_summary_effects_list(), reset_out_summary_regions_list(), set_current_module_entity(), set_current_module_statement(), set_methods_for_convex_effects(), set_ordering_to_statement(), STATEMENT, statement_consistent_p(), and statement_sequence_p().

+ Here is the call graph for this function:

◆ replace_indices_region()

void replace_indices_region ( effect  ,
list ,
int  ,
entity   
)