PIPS
replacement in statements

it is not unusual to generate a new entity, this helper functions will take care of substituing all referenced to an old entity by reference in new entities More...

Data Structures

struct  param
 

Functions

static void replace_entities_declaration_walker (statement s, hash_table ht)
 
static void replace_entities_call_walker (call c, hash_table ht)
 
static void replace_entities_expression_walker (expression parent, hash_table ht)
 
static void replace_entities_loop_walker (loop l, hash_table ht)
 
void replace_entities (void *s, hash_table ht)
 Recursively substitute a set of entities in a statement. More...
 
void replace_entity (void *s, entity old, entity new)
 per variable version of replace_entities. More...
 
void replace_reference (void *s, reference old, entity new)
 Replace an old reference by a reference to a new entity in a statement. More...
 
static void replace_entity_by_expression_expression_walker (expression e, struct param *p)
 
static void replace_entity_by_expression_entity_walker (entity e, struct param *p)
 
static void replace_entity_by_expression_declarations_walker (statement s, struct param *p)
 
static void replace_entity_by_expression_loop_walker (loop l, struct param *p)
 
void replace_entity_by_expression_with_filter (void *s, entity ent, expression exp, bool(*filter)(expression))
 
void replace_entity_by_expression (void *s, entity ent, expression exp)
 replace all reference to entity ent by expression exp in s. More...
 
void replace_entities_by_expression (void *s, hash_table ht)
 

Detailed Description

it is not unusual to generate a new entity, this helper functions will take care of substituing all referenced to an old entity by reference in new entities

Function Documentation

◆ replace_entities()

void replace_entities ( void *  s,
hash_table  ht 
)

Recursively substitute a set of entities in a statement.

replace.c

Parameters
snewgen type where the substitution must be done
httable of old->new pairs

Warning: if the intersection between the input and output sets is not empty, the behavior is undefined

Parameters
htt

Definition at line 91 of file replace.c.

92 {
93  if( INSTANCE_OF(entity,(gen_chunkp)s) ) {
95  value v = entity_initial((entity)s);
96  if( !value_undefined_p(v) && value_expression_p( v ) )
97  replace_entities(v,ht);
98  }
99  else {
105  NULL);
106  }
107 }
static void replace_entities_loop_walker(loop l, hash_table ht)
Definition: replace.c:64
static void replace_entities_expression_walker(expression parent, hash_table ht)
Definition: replace.c:41
void replace_entities(void *s, hash_table ht)
Recursively substitute a set of entities in a statement.
Definition: replace.c:91
static void replace_entities_declaration_walker(statement s, hash_table ht)
Definition: replace.c:23
static void replace_entities_call_walker(call c, hash_table ht)
Definition: replace.c:33
void gen_context_multi_recurse(void *o, void *context,...)
Multi-recursion with context function visitor.
Definition: genClib.c:3373
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define INSTANCE_OF(type, value)
polymorhism thanks to newgen !
#define value_undefined_p(x)
Definition: ri.h:3017
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define loop_domain
newgen_language_domain_defined
Definition: ri.h:218
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
#define entity_type(x)
Definition: ri.h:2792
#define value_expression_p(x)
Definition: ri.h:3080
#define entity_initial(x)
Definition: ri.h:2796
A gen_chunk is used to store every object.
Definition: genC.h:58

References call_domain, entity_initial, entity_type, expression_domain, gen_context_multi_recurse(), gen_true(), INSTANCE_OF, loop_domain, replace_entities_call_walker(), replace_entities_declaration_walker(), replace_entities_expression_walker(), replace_entities_loop_walker(), statement_domain, value_expression_p, and value_undefined_p.

Referenced by rename_statement_declarations(), replace_entities_declaration_walker(), replace_entity(), slightly_rename_entities(), statement_flatten_declarations(), and sww_seq_rwt().

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

◆ replace_entities_by_expression()

void replace_entities_by_expression ( void *  s,
hash_table  ht 
)
Parameters
htt

Definition at line 225 of file replace.c.

226 {
228 }
void replace_entity_by_expression(void *s, entity ent, expression exp)
replace all reference to entity ent by expression exp in s.
Definition: replace.c:220
#define HASH_MAP(k, v, code, ht)
Definition: newgen_hash.h:60

References HASH_MAP, and replace_entity_by_expression().

+ Here is the call graph for this function:

◆ replace_entities_call_walker()

static void replace_entities_call_walker ( call  c,
hash_table  ht 
)
static

Definition at line 33 of file replace.c.

33  {
34  entity new = hash_get(ht, call_function(c));
35  if( new != HASH_UNDEFINED_VALUE) {
36  call_function(c)=new;
37  }
38 }
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.
Definition: hash.c:449
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
#define call_function(x)
Definition: ri.h:709

References call_function, hash_get(), and HASH_UNDEFINED_VALUE.

Referenced by replace_entities().

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

◆ replace_entities_declaration_walker()

static void replace_entities_declaration_walker ( statement  s,
hash_table  ht 
)
static

Definition at line 23 of file replace.c.

24 {
25  // FI: this does not seem to replace the declaration itself
26  // I need a side-effect on the statement_declarations list when
27  // decl_ent == thecouple->old
29  replace_entities(decl_ent,ht);
30 }
#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 ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define statement_declarations(x)
Definition: ri.h:2460

References ENTITY, FOREACH, replace_entities(), and statement_declarations.

Referenced by replace_entities().

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

◆ replace_entities_expression_walker()

static void replace_entities_expression_walker ( expression  parent,
hash_table  ht 
)
static

we need to unormalize the uppermost parent of this expression otherwise its normalized field gets incorrect

otherwise field normalized get wrong

Definition at line 41 of file replace.c.

42 {
43  if(expression_reference_p(parent)) {
44  reference r = expression_reference(parent);
45  entity new = hash_get(ht,reference_variable(r));
46  if(new!= HASH_UNDEFINED_VALUE) {
47  if(entity_constant_p(new)) {
50  );
51  }
52  else
53  reference_variable(r)=new;
54  expression next=parent,root=parent;
55  /* we need to unormalize the uppermost parent of this expression
56  * otherwise its normalized field gets incorrect */
57  while((next=(expression) gen_get_ancestor(expression_domain,next)))
58  root=next;
59  unnormalize_expression(root); /* otherwise field normalized get wrong */
60  }
61  }
62 }
call make_call(entity a1, list a2)
Definition: ri.c:269
syntax make_syntax_call(call _field_)
Definition: ri.c:2500
gen_chunk * gen_get_ancestor(int, const void *)
return the first ancestor object found of the given type.
Definition: genClib.c:3560
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void unnormalize_expression(void *st)
void unnormalize_expression(expression exp): puts all the normalized field of expressions in "st" to ...
Definition: normalize.c:452
#define entity_constant_p(e)
void update_expression_syntax(expression e, syntax s)
frees expression syntax of e and replace it by the new syntax s
Definition: expression.c:3564
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 reference_variable(x)
Definition: ri.h:2326

References entity_constant_p, expression_domain, expression_reference(), expression_reference_p(), gen_get_ancestor(), hash_get(), HASH_UNDEFINED_VALUE, make_call(), make_syntax_call(), NIL, reference_variable, unnormalize_expression(), and update_expression_syntax().

Referenced by replace_entities().

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

◆ replace_entities_loop_walker()

static void replace_entities_loop_walker ( loop  l,
hash_table  ht 
)
static

Definition at line 64 of file replace.c.

64  {
65  entity new = hash_get(ht,loop_index(l));
66  if(new!= HASH_UNDEFINED_VALUE) {
67  // We replace the loop index
68  loop_index(l) = new;
69  }
70 
71  // Handle loop locals, in-place replacement
72  for(list ll = loop_locals(l); !ENDP(ll); POP(ll)) {
73  entity local = ENTITY(CAR(ll));
74  entity new = hash_get(ht,local);
75  if(new!= HASH_UNDEFINED_VALUE) {
76  CAR(ll).p = (gen_chunkp)new;
77  }
78  }
79 }
union gen_chunk * gen_chunkp
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define loop_locals(x)
Definition: ri.h:1650
#define loop_index(x)
Definition: ri.h:1640
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References CAR, ENDP, ENTITY, hash_get(), HASH_UNDEFINED_VALUE, loop_index, loop_locals, and POP.

Referenced by replace_entities().

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

◆ replace_entity()

void replace_entity ( void *  s,
entity  old,
entity  new 
)

per variable version of replace_entities.

Much slower if you have an hash table of old/new pairs than the replace_entities version

Parameters
oldld
newew

Definition at line 113 of file replace.c.

113  {
115  hash_put(ht,old,new);
116  replace_entities(s,ht);
117  hash_table_free(ht);
118 }
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
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.
Definition: hash.c:364
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
@ hash_pointer
Definition: newgen_hash.h:32

References hash_pointer, hash_put(), hash_table_free(), hash_table_make(), and replace_entities().

Referenced by do_kernelize(), do_scalar_renaming_in_successors(), do_scalar_renaming_in_vertex(), do_terapix_argument_handler(), fix_loop_index_sign(), inline_expression_call(), loadstore_type_conversion_string(), make_array_communication_statement(), move_declaration_control_node_declarations_to_statement(), outliner_independent_recursively(), promote_local_entities(), replace_reference(), solve_name_clashes(), statements_localize_declarations(), terapix_loop_handler(), and terapix_optimize_accumulator().

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

◆ replace_entity_by_expression()

void replace_entity_by_expression ( void *  s,
entity  ent,
expression  exp 
)

replace all reference to entity ent by expression exp in s.

@s can be any newgen type !

Parameters
entnt
expxp

Definition at line 220 of file replace.c.

221 {
223 }
void replace_entity_by_expression_with_filter(void *s, entity ent, expression exp, bool(*filter)(expression))
Definition: replace.c:204
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References param::ent, exp, gen_true(), and replace_entity_by_expression_with_filter().

Referenced by do_loop_unroll_with_epilogue(), do_loop_unroll_with_prologue(), do_reduction_propagation(), full_loop_unroll(), fusion(), fusion_buffer(), Hierarchical_tiling(), inline_expression_call(), loop_annotate(), make_loadsave_statement(), normalize_microcode(), replace_entities_by_expression(), scalopify(), sesamify(), Tiling2_buffer(), Tiling_buffer_allocation(), and translate_arguments().

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

◆ replace_entity_by_expression_declarations_walker()

static void replace_entity_by_expression_declarations_walker ( statement  s,
struct param p 
)
static

Definition at line 191 of file replace.c.

192 {
195 
196 }
static void replace_entity_by_expression_entity_walker(entity e, struct param *p)
Definition: replace.c:176

References ENTITY, FOREACH, replace_entity_by_expression_entity_walker(), and statement_declarations.

Referenced by replace_entity_by_expression_with_filter().

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

◆ replace_entity_by_expression_entity_walker()

static void replace_entity_by_expression_entity_walker ( entity  e,
struct param p 
)
static

Definition at line 176 of file replace.c.

177 {
178  if( ! set_belong_p(p->visited_entities,e)) {
180  value v = entity_initial(e);
181  if( value_expression_p(v) )
186  }
187 }
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
static void replace_entity_by_expression_expression_walker(expression e, struct param *p)
Definition: replace.c:137
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
bool set_belong_p(const set, const void *)
Definition: set.c:194
set set_add_element(set, const set, const void *)
Definition: set.c:152
#define value_expression(x)
Definition: ri.h:3082
set visited_entities
Definition: replace.c:135

References entity_initial, entity_type, expression_domain, gen_context_recurse, gen_true2(), replace_entity_by_expression_expression_walker(), set_add_element(), set_belong_p(), value_expression, value_expression_p, and param::visited_entities.

Referenced by replace_entity_by_expression_declarations_walker(), and replace_entity_by_expression_loop_walker().

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

◆ replace_entity_by_expression_expression_walker()

static void replace_entity_by_expression_expression_walker ( expression  e,
struct param p 
)
static

if both are references , concatenante indices

else generate a subscript

Definition at line 137 of file replace.c.

138 {
139  if( expression_reference_p(e) )
140  {
143  {
145  if(!ENDP(reference_indices(r))) {
147  /* if both are references , concatenante indices */
149  {
151  syn = make_syntax_reference(
153  reference_variable(pr),
155  )
156  );
157  }
158  /* else generate a subscript */
159  else {
161  }
162  }
164  }
165  }
166  else if(expression_call_p(e))
167  {
168  call c = expression_call(e);
171 
172  }
173 }
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
subscript make_subscript(expression a1, list a2)
Definition: ri.c:2327
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
syntax copy_syntax(syntax p)
SYNTAX.
Definition: ri.c:2442
syntax make_syntax_subscript(subscript _field_)
Definition: ri.c:2509
syntax make_syntax_reference(reference _field_)
Definition: ri.c:2494
#define call_constant_p(C)
Definition: flint_check.c:51
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
list gen_full_copy_list(list l)
Copy a list structure with element copy.
Definition: list.c:535
static list indices
Definition: icm.c:204
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
bool expression_call_p(expression e)
Definition: expression.c:415
call expression_call(expression e)
Definition: expression.c:445
#define normalized_undefined
Definition: ri.h:1745
#define reference_indices(x)
Definition: ri.h:2328
#define expression_syntax(x)
Definition: ri.h:1247
expression exp
Definition: replace.c:135
entity ent
Definition: replace.c:135

References call_constant_p, call_function, copy_syntax(), ENDP, param::ent, param::exp, expression_call(), expression_call_p(), expression_reference(), expression_reference_p(), expression_syntax, gen_full_copy_list(), gen_nconc(), indices, make_expression(), make_reference(), make_subscript(), make_syntax_reference(), make_syntax_subscript(), normalized_undefined, reference_indices, reference_variable, same_entity_p(), and update_expression_syntax().

Referenced by replace_entity_by_expression_entity_walker(), and replace_entity_by_expression_with_filter().

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

◆ replace_entity_by_expression_loop_walker()

static void replace_entity_by_expression_loop_walker ( loop  l,
struct param p 
)
static

Definition at line 199 of file replace.c.

References loop_index, and replace_entity_by_expression_entity_walker().

Referenced by replace_entity_by_expression_with_filter().

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

◆ replace_entity_by_expression_with_filter()

void replace_entity_by_expression_with_filter ( void *  s,
entity  ent,
expression  exp,
bool(*)(expression filter 
)
Parameters
entnt
expxp

Definition at line 204 of file replace.c.

205 {
206  struct param p = { ent, exp, set_make(set_pointer)};
211  NULL);
213 }
static void replace_entity_by_expression_loop_walker(loop l, struct param *p)
Definition: replace.c:199
static void replace_entity_by_expression_declarations_walker(statement s, struct param *p)
Definition: replace.c:191
void set_free(set)
Definition: set.c:332
@ set_pointer
Definition: newgen_set.h:44
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
Definition: replace.c:135

References param::ent, exp, expression_domain, gen_context_multi_recurse(), gen_true(), loop_domain, replace_entity_by_expression_declarations_walker(), replace_entity_by_expression_expression_walker(), replace_entity_by_expression_loop_walker(), set_free(), set_make(), set_pointer, statement_domain, and param::visited_entities.

Referenced by do_group_constants_terapix(), and replace_entity_by_expression().

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

◆ replace_reference()

void replace_reference ( void *  s,
reference  old,
entity  new 
)

Replace an old reference by a reference to a new entity in a statement.

If the reference is a scalar, it's similar to replace_entity, otherwise, it's replace_entity_by_expression

Parameters
oldld
newew

Definition at line 124 of file replace.c.

124  {
125  /* If the reference is a scalar, it's similar to replace_entity,
126  otherwise, it's replace_entity_by_expression */
127  if (ENDP(reference_indices(old)))
128  replace_entity(s, reference_variable(old), new);
129  else {
130  pips_internal_error("not implemented yet");
131  }
132 }
void replace_entity(void *s, entity old, entity new)
per variable version of replace_entities.
Definition: replace.c:113
#define pips_internal_error
Definition: misc-local.h:149

References ENDP, pips_internal_error, reference_indices, reference_variable, and replace_entity().

Referenced by add_parameter_variable_to_module(), add_private_variable_to_module(), do_reduction_detection(), and do_reduction_propagation().

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