PIPS
clone_statement.c File Reference
#include "linear.h"
#include "genC.h"
#include "misc.h"
#include "ri.h"
#include "cloning.h"
#include "ri-util.h"
+ Include dependency graph for clone_statement.c:

Go to the source code of this file.

Functions

static expression do_clone_expression (expression e, clone_context cc, hash_table ht)
 forward declarations More...
 
static call do_clone_call (call c, clone_context cc, hash_table ht)
 
static statement do_clone_statement (statement s, clone_context cc, hash_table ht)
 
static entity do_clone_label (entity l, clone_context cc)
 
static gen_chunkdo_clone_reference (reference r, clone_context cc, hash_table ht)
 nd formard declarations More...
 
static range do_clone_range (range r, clone_context cc, hash_table ht)
 
static cast do_clone_cast (cast c, clone_context cc, hash_table ht)
 
static sizeofexpression do_clone_sizeofexpression (sizeofexpression s, clone_context cc, hash_table ht)
 
static subscript do_clone_subscript (subscript s, clone_context cc, hash_table ht)
 
static application do_clone_application (application a, clone_context cc, hash_table ht)
 
static syntax do_clone_syntax (syntax s, clone_context cc, hash_table ht)
 
static entity do_clone_entity (entity e, clone_context cc, hash_table ht)
 
static sequence do_clone_sequence (sequence s, clone_context cc, hash_table ht)
 
static test do_clone_test (test t, clone_context cc, hash_table ht)
 
static loop do_clone_loop (loop l, clone_context cc, hash_table ht)
 
static whileloop do_clone_whileloop (whileloop w, clone_context cc, hash_table ht)
 
static multitest do_clone_multitest (multitest m, clone_context cc, hash_table ht)
 
static forloop do_clone_forloop (forloop f, clone_context cc, hash_table ht)
 
static instruction do_clone_instruction (instruction i, clone_context cc, hash_table ht)
 
statement clone_statement (statement s, clone_context cc)
 clone_statement.c More...
 

Function Documentation

◆ clone_statement()

statement clone_statement ( statement  s,
clone_context  cc 
)

clone_statement.c

Parameters
ccc

Definition at line 437 of file clone_statement.c.

438 {
440  statement sout = do_clone_statement(s,cc,ht);
441  hash_table_free(ht);
442  return sout;
443 }
static statement do_clone_statement(statement s, clone_context cc, hash_table ht)
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
@ hash_string
Definition: newgen_hash.h:32

References do_clone_statement(), hash_string, hash_table_free(), and hash_table_make().

Referenced by do_loop_expansion_init(), do_loop_nest_unswitching_purge(), do_loop_unroll_with_epilogue(), do_loop_unroll_with_prologue(), do_simdizer_auto_tile_generate_all_tests(), dowhile_to_while_walker(), full_loop_unroll(), and make_new_loop_statement().

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

◆ do_clone_application()

static application do_clone_application ( application  a,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 102 of file clone_statement.c.

103 {
104  list new_arguments = NIL;
106  new_arguments=CONS(EXPRESSION,do_clone_expression(e,cc, ht),new_arguments);
107  return make_application(do_clone_expression(application_function(a),cc, ht),gen_nreverse(new_arguments));
108 }
application make_application(expression a1, list a2)
Definition: ri.c:56
static expression do_clone_expression(expression e, clone_context cc, hash_table ht)
forward declarations
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#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
#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 EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define application_arguments(x)
Definition: ri.h:510
#define application_function(x)
Definition: ri.h:508
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References application_arguments, application_function, CONS, do_clone_expression(), EXPRESSION, FOREACH, gen_nreverse(), make_application(), and NIL.

Referenced by do_clone_syntax().

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

◆ do_clone_call()

static call do_clone_call ( call  c,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 331 of file clone_statement.c.

332 {
333  list new_arguments = NIL;
335  {
336  new_arguments=CONS(EXPRESSION,do_clone_expression(e,cc, ht),new_arguments);
337  }
338  return make_call(
339  call_function(c),
340  gen_nreverse(new_arguments));
341 }
call make_call(entity a1, list a2)
Definition: ri.c:269
#define call_function(x)
Definition: ri.h:709
#define call_arguments(x)
Definition: ri.h:711

References call_arguments, call_function, CONS, do_clone_expression(), EXPRESSION, FOREACH, gen_nreverse(), make_call(), and NIL.

Referenced by do_clone_instruction(), and do_clone_syntax().

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

◆ do_clone_cast()

static cast do_clone_cast ( cast  c,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 72 of file clone_statement.c.

73 {
74  return make_cast(
75  copy_type(cast_type(c)),
77 }
cast make_cast(type a1, expression a2)
Definition: ri.c:311
type copy_type(type p)
TYPE.
Definition: ri.c:2655
#define cast_expression(x)
Definition: ri.h:747
#define cast_type(x)
Definition: ri.h:745

References cast_expression, cast_type, copy_type(), do_clone_expression(), and make_cast().

Referenced by do_clone_syntax().

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

◆ do_clone_entity()

static entity do_clone_entity ( entity  e,
clone_context  cc,
hash_table  ht 
)
static

There is no reason to replicate such an entity when cloning since they are left unchanged, except maybe if they contain dependent types...

The entity can be a typedef instead of a variable...

The type of the entity can be a typedef that has been renamed...

FI: I am adding this for loop_unroll, but I believe 1) that typedef variables should not be renamed since only non-dependent types are supported, and 2) that loop unroll should be implemented in a simpler way and complemented by flatten_code

For dependent types, the variables used in dimension might have been renamed, but the cloning is not compatible with dependent types because declarations are moved...

Definition at line 166 of file clone_statement.c.

167 {
168  pips_assert("entity is fine",entity_consistent_p(e));
169  entity new_entity = entity_undefined;
170  if( (new_entity=hash_get(ht,entity_name(e))) == HASH_UNDEFINED_VALUE)
171  {
172  //string ln = entity_user_name(e);
173  string en = entity_name(e);
174  string ms = strrchr(en, BLOCK_SEP_CHAR);
175  if(ms==NULL)
176  ms = strchr(en, MODULE_SEP);
177  string ln = ms+1;
178 
179  if(entity_scalar_p(e))
181  //entity_user_name(e),
182  ln,
185  );
186  else if(entity_array_p(e))
188  //entity_user_name(e),
189  ln,
193  );
194  else if(entity_struct_p(e) || entity_union_p(e) || entity_enum_p(e)) {
195  /* There is no reason to replicate such an entity when
196  cloning since they are left unchanged, except maybe if
197  they contain dependent types... */
199  ln,
201  entity_type(e)
202  );
203  }
204  else {
205  pips_internal_error("Unexpected case\n");
206  }
207 
208  /* The entity can be a typedef instead of a
209  variable... */
210  if(typedef_entity_p(e)) {
211  storage s = entity_storage(new_entity);
212  free_storage(s);
213  s = make_storage_rom();
214  entity_storage(new_entity) = s;
215  }
216 
217  /* The type of the entity can be a typedef that has been renamed... */
218  /* FI: I am adding this for loop_unroll, but I believe 1) that
219  typedef variables should not be renamed since only
220  non-dependent types are supported, and 2) that loop unroll
221  should be implemented in a simpler way and complemented by
222  flatten_code */
223  type nt = entity_type(new_entity);
224  if(type_variable_p(nt)) {
225  variable nv = type_variable(nt);
226  /* For dependent types, the variables used in dimension
227  might have been renamed, but the cloning is not
228  compatible with dependent types because declarations are
229  moved... */
230  basic nb = variable_basic(nv);
231  if(basic_typedef_p(nb)) {
232  entity otd = basic_typedef(nb);
233  entity ntd = hash_get(ht,entity_name(otd));
234  if(ntd != HASH_UNDEFINED_VALUE)
235  basic_typedef(nb) = ntd;
236  }
237  else if(basic_derived_p(nb)) {
238  entity de = basic_derived(nb);
239  entity nde = hash_get(ht,entity_name(de));
240  if(nde != HASH_UNDEFINED_VALUE)
241  basic_derived(nb) = nde;
242  }
243  }
244 
246  hash_put(ht,entity_name(e),new_entity);
247  }
248  return new_entity;
249 }
storage make_storage_rom(void)
Definition: ri.c:2285
basic copy_basic(basic p)
BASIC.
Definition: ri.c:104
void free_storage(storage p)
Definition: ri.c:2231
bool entity_consistent_p(entity p)
Definition: ri.c:2530
#define clone_context_new_module_statement(x)
Definition: cloning.h:72
#define clone_context_new_module(x)
Definition: cloning.h:68
list gen_full_copy_list(list l)
Copy a list structure with element copy.
Definition: list.c:535
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
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
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
#define BLOCK_SEP_CHAR
Definition: naming-local.h:51
#define MODULE_SEP
special characters to build entity names of various kinds
Definition: naming-local.h:27
#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
bool entity_struct_p(entity e)
Is entity e the entity corresponding to a struct declaration?
Definition: entity.c:1002
bool entity_array_p(entity e)
Is e a variable with an array type?
Definition: entity.c:754
bool entity_enum_p(entity e)
Definition: entity.c:968
bool typedef_entity_p(entity e)
Definition: entity.c:1902
basic entity_basic(entity e)
return the basic associated to entity e if it's a function/variable/constant basic_undefined otherwis...
Definition: entity.c:1380
bool entity_union_p(entity e)
Is entity e an entity representing the union declaration?
Definition: entity.c:1038
void AddLocalEntityToDeclarations(entity, entity, statement)
Add the variable entity e to the list of variables of the function module.
Definition: variable.c:233
bool entity_scalar_p(entity)
The concrete type of e is a scalar type.
Definition: variable.c:1113
entity make_new_array_variable_with_prefix(const char *, entity, basic, list)
J'ai ameliore la fonction make_new_scalar_variable_with_prefix
Definition: variable.c:785
entity make_new_derived_entity_with_prefix(const char *, entity, type)
derived from make_new_scalar_variable_with_prefix
Definition: variable.c:685
entity make_new_scalar_variable_with_prefix(const char *, entity, basic)
Create a new scalar variable of type b in the given module.
Definition: variable.c:592
#define basic_derived(x)
Definition: ri.h:640
#define basic_typedef_p(x)
Definition: ri.h:641
#define type_variable(x)
Definition: ri.h:2949
#define basic_derived_p(x)
Definition: ri.h:638
#define entity_storage(x)
Definition: ri.h:2794
#define basic_typedef(x)
Definition: ri.h:643
#define entity_undefined
Definition: ri.h:2761
#define entity_name(x)
Definition: ri.h:2790
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947
#define variable_basic(x)
Definition: ri.h:3120

References AddLocalEntityToDeclarations(), basic_derived, basic_derived_p, basic_typedef, basic_typedef_p, BLOCK_SEP_CHAR, clone_context_new_module, clone_context_new_module_statement, copy_basic(), entity_array_p(), entity_basic(), entity_consistent_p(), entity_enum_p(), entity_name, entity_scalar_p(), entity_storage, entity_struct_p(), entity_type, entity_undefined, entity_union_p(), free_storage(), gen_full_copy_list(), hash_get(), hash_put(), HASH_UNDEFINED_VALUE, make_new_array_variable_with_prefix(), make_new_derived_entity_with_prefix(), make_new_scalar_variable_with_prefix(), make_storage_rom(), MODULE_SEP, pips_assert, pips_internal_error, type_variable, type_variable_p, typedef_entity_p(), variable_basic, and variable_dimensions.

Referenced by do_clone_loop(), and do_clone_statement().

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

◆ do_clone_expression()

static expression do_clone_expression ( expression  e,
clone_context  cc,
hash_table  ht 
)
static

forward declarations

Definition at line 157 of file clone_statement.c.

158 {
159  return make_expression(
162 }
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
static syntax do_clone_syntax(syntax s, clone_context cc, hash_table ht)
#define normalized_undefined
Definition: ri.h:1745
#define expression_syntax(x)
Definition: ri.h:1247

References do_clone_syntax(), expression_syntax, make_expression(), and normalized_undefined.

Referenced by do_clone_application(), do_clone_call(), do_clone_cast(), do_clone_forloop(), do_clone_instruction(), do_clone_multitest(), do_clone_range(), do_clone_reference(), do_clone_sizeofexpression(), do_clone_statement(), do_clone_subscript(), do_clone_test(), and do_clone_whileloop().

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

◆ do_clone_forloop()

static forloop do_clone_forloop ( forloop  f,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 352 of file clone_statement.c.

353 {
354  return make_forloop(
359 }
forloop make_forloop(expression a1, expression a2, expression a3, statement a4)
Definition: ri.c:1025
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
#define forloop_initialization(x)
Definition: ri.h:1366
#define forloop_increment(x)
Definition: ri.h:1370
#define forloop_condition(x)
Definition: ri.h:1368
#define forloop_body(x)
Definition: ri.h:1372

References do_clone_expression(), do_clone_statement(), f(), forloop_body, forloop_condition, forloop_increment, forloop_initialization, and make_forloop().

Referenced by do_clone_instruction().

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

◆ do_clone_instruction()

static instruction do_clone_instruction ( instruction  i,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 362 of file clone_statement.c.

363 {
364  if(instruction_undefined_p(i)) return i;
365 
366  switch(instruction_tag(i))
367  {
370  case is_instruction_test:
372  case is_instruction_loop:
376  case is_instruction_goto:
377  pips_user_error("don't know how to clone a goto");
378  case is_instruction_call:
381  pips_user_error("don't know how to clone an unstructured");
388  };
389  return instruction_undefined;
390 }
instruction make_instruction_loop(loop _field_)
Definition: ri.c:1175
instruction make_instruction_forloop(forloop _field_)
Definition: ri.c:1193
instruction make_instruction_expression(expression _field_)
Definition: ri.c:1196
instruction make_instruction_sequence(sequence _field_)
Definition: ri.c:1169
instruction make_instruction_test(test _field_)
Definition: ri.c:1172
instruction make_instruction_call(call _field_)
Definition: ri.c:1184
instruction make_instruction_multitest(multitest _field_)
Definition: ri.c:1190
instruction make_instruction_whileloop(whileloop _field_)
Definition: ri.c:1178
static call do_clone_call(call c, clone_context cc, hash_table ht)
static loop do_clone_loop(loop l, clone_context cc, hash_table ht)
static test do_clone_test(test t, clone_context cc, hash_table ht)
static forloop do_clone_forloop(forloop f, clone_context cc, hash_table ht)
static multitest do_clone_multitest(multitest m, clone_context cc, hash_table ht)
static sequence do_clone_sequence(sequence s, clone_context cc, hash_table ht)
static whileloop do_clone_whileloop(whileloop w, clone_context cc, hash_table ht)
#define pips_user_error
Definition: misc-local.h:147
#define instruction_loop(x)
Definition: ri.h:1520
#define instruction_multitest(x)
Definition: ri.h:1535
#define instruction_undefined_p(x)
Definition: ri.h:1455
#define instruction_undefined
Definition: ri.h:1454
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ is_instruction_expression
Definition: ri.h:1478
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_multitest
Definition: ri.h:1476
@ is_instruction_call
Definition: ri.h:1474
@ is_instruction_sequence
Definition: ri.h:1469
@ is_instruction_forloop
Definition: ri.h:1477
@ is_instruction_loop
Definition: ri.h:1471
#define instruction_tag(x)
Definition: ri.h:1511
#define instruction_sequence(x)
Definition: ri.h:1514
#define instruction_forloop(x)
Definition: ri.h:1538
#define instruction_expression(x)
Definition: ri.h:1541
#define instruction_whileloop(x)
Definition: ri.h:1523
#define instruction_call(x)
Definition: ri.h:1529
#define instruction_test(x)
Definition: ri.h:1517

References do_clone_call(), do_clone_expression(), do_clone_forloop(), do_clone_loop(), do_clone_multitest(), do_clone_sequence(), do_clone_test(), do_clone_whileloop(), instruction_call, instruction_expression, instruction_forloop, instruction_loop, instruction_multitest, instruction_sequence, instruction_tag, instruction_test, instruction_undefined, instruction_undefined_p, instruction_whileloop, is_instruction_call, is_instruction_expression, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_multitest, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, make_instruction_call(), make_instruction_expression(), make_instruction_forloop(), make_instruction_loop(), make_instruction_multitest(), make_instruction_sequence(), make_instruction_test(), make_instruction_whileloop(), and pips_user_error.

Referenced by do_clone_statement().

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

◆ do_clone_label()

static entity do_clone_label ( entity  l,
clone_context  cc 
)
static

if the label was cloned in the past, we get the same clone this function returned before instead of creating a new one

Checking if the entity is in the list of cloned labels

Insert those two values at beginning of the list (reverse inserting order as it's insterting before instead of inserting at the end)

Parameters
cchash_table ht

Definition at line 291 of file clone_statement.c.

292 {
294 
295  /* if the label was cloned in the past, we get the same clone this function
296  returned before instead of creating a new one */
297  entity replacement = entity_undefined;
298 
299  /* Checking if the entity is in the list of cloned labels */
300  for (list iter = clone_context_labels(cc); !ENDP(iter); POP(iter)) {
301  if (same_entity_p(ENTITY(CAR(iter)), l)) {
302  POP(iter);
303  replacement = ENTITY(CAR(iter));
304  } else {
305  POP(iter);
306  }
307  }
308 
309  if(entity_undefined_p(replacement)) {
310  replacement=make_new_label(clone_context_new_module(cc));
311  /* Insert those two values at beginning of the list (reverse inserting order
312  as it's insterting before instead of inserting at the end) */
313  clone_context_labels(cc) = CONS(ENTITY, replacement, clone_context_labels(cc));
315  }
316 
317  return replacement;
318 }
#define clone_context_labels(x)
Definition: cloning.h:70
#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
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321
entity entity_empty_label(void)
Definition: entity.c:1105
bool entity_empty_label_p(entity e)
Definition: entity.c:666
entity make_new_label(entity module)
This function returns a new label.
Definition: entity.c:357
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define entity_undefined_p(x)
Definition: ri.h:2762

References CAR, clone_context_labels, clone_context_new_module, CONS, ENDP, ENTITY, entity_empty_label(), entity_empty_label_p(), entity_undefined, entity_undefined_p, make_new_label(), POP, and same_entity_p().

Referenced by do_clone_loop(), do_clone_statement(), and do_clone_whileloop().

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

◆ do_clone_loop()

static loop do_clone_loop ( loop  l,
clone_context  cc,
hash_table  ht 
)
static

ht

unsure ...

Definition at line 275 of file clone_statement.c.

276 {
277  entity new_entity =
279  do_clone_entity(loop_index(l),cc, ht):
280  loop_index(l);
281  return make_loop(
282  new_entity,
283  do_clone_range(loop_range(l),cc, ht),
284  do_clone_statement(loop_body(l),cc, ht),
285  do_clone_label(loop_label(l),cc/*, ht*/),
287  NIL /* unsure ...*/);
288 }
loop make_loop(entity a1, range a2, statement a3, entity a4, execution a5, list a6)
Definition: ri.c:1301
execution make_execution_sequential(void)
Definition: ri.c:841
static entity do_clone_entity(entity e, clone_context cc, hash_table ht)
static entity do_clone_label(entity l, clone_context cc)
static range do_clone_range(range r, clone_context cc, hash_table ht)
#define gen_chunk_undefined_p(c)
Definition: genC.h:75
void * gen_find_eq(const void *item, const list seq)
Definition: list.c:422
#define loop_body(x)
Definition: ri.h:1644
#define loop_label(x)
Definition: ri.h:1646
#define loop_locals(x)
Definition: ri.h:1650
#define loop_range(x)
Definition: ri.h:1642
#define loop_index(x)
Definition: ri.h:1640

References do_clone_entity(), do_clone_label(), do_clone_range(), do_clone_statement(), gen_chunk_undefined_p, gen_find_eq(), loop_body, loop_index, loop_label, loop_locals, loop_range, make_execution_sequential(), make_loop(), and NIL.

Referenced by do_clone_instruction().

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

◆ do_clone_multitest()

static multitest do_clone_multitest ( multitest  m,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 344 of file clone_statement.c.

345 {
346  return make_multitest(
349 }
multitest make_multitest(expression a1, statement a2)
Definition: ri.c:1398
#define multitest_controller(x)
Definition: ri.h:1733
#define multitest_body(x)
Definition: ri.h:1735

References do_clone_expression(), do_clone_statement(), make_multitest(), multitest_body, and multitest_controller.

Referenced by do_clone_instruction().

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

◆ do_clone_range()

static range do_clone_range ( range  r,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 64 of file clone_statement.c.

65 {
66  return make_range(
70 }
range make_range(expression a1, expression a2, expression a3)
Definition: ri.c:2041
#define range_upper(x)
Definition: ri.h:2290
#define range_increment(x)
Definition: ri.h:2292
#define range_lower(x)
Definition: ri.h:2288

References do_clone_expression(), make_range(), range_increment, range_lower, and range_upper.

Referenced by do_clone_loop(), and do_clone_syntax().

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

◆ do_clone_reference()

static gen_chunk* do_clone_reference ( reference  r,
clone_context  cc,
hash_table  ht 
)
static

nd formard declarations

Definition at line 46 of file clone_statement.c.

47 {
48  entity new_entity = entity_undefined;
49  if( (new_entity = hash_get(ht,entity_name(reference_variable(r)))) == HASH_UNDEFINED_VALUE )
50  {
51  new_entity = reference_variable(r);
52  if( entity_constant_p(new_entity) )
53  {
54  return (gen_chunk*)make_call(new_entity,NIL);
55  }
56  }
57  list new_indices = NIL;
59  new_indices=CONS(EXPRESSION,do_clone_expression(e,cc, ht),new_indices);
60  return (gen_chunk*)make_reference(new_entity,gen_nreverse(new_indices));
61 }
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
#define entity_constant_p(e)
#define reference_variable(x)
Definition: ri.h:2326
#define reference_indices(x)
Definition: ri.h:2328
A gen_chunk is used to store every object.
Definition: genC.h:58

References CONS, do_clone_expression(), entity_constant_p, entity_name, entity_undefined, EXPRESSION, FOREACH, gen_nreverse(), hash_get(), HASH_UNDEFINED_VALUE, make_call(), make_reference(), NIL, reference_indices, and reference_variable.

Referenced by do_clone_syntax().

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

◆ do_clone_sequence()

static sequence do_clone_sequence ( sequence  s,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 252 of file clone_statement.c.

253 {
256  {
258  }
261 }
sequence make_sequence(list a)
Definition: ri.c:2125
#define new_statements(p)
Definition: inlining.c:97
#define sequence_statements(x)
Definition: ri.h:2360
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References CONS, do_clone_statement(), FOREACH, gen_nreverse(), make_sequence(), new_statements, NIL, sequence_statements, and STATEMENT.

Referenced by do_clone_instruction().

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

◆ do_clone_sizeofexpression()

static sizeofexpression do_clone_sizeofexpression ( sizeofexpression  s,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 80 of file clone_statement.c.

81 {
82  switch(sizeofexpression_tag(s))
83  {
85  return copy_sizeofexpression(s);
88  };
90 }
sizeofexpression make_sizeofexpression_expression(expression _field_)
Definition: ri.c:2180
sizeofexpression copy_sizeofexpression(sizeofexpression p)
SIZEOFEXPRESSION.
Definition: ri.c:2131
@ is_sizeofexpression_expression
Definition: ri.h:2386
@ is_sizeofexpression_type
Definition: ri.h:2385
#define sizeofexpression_tag(x)
Definition: ri.h:2403
#define sizeofexpression_expression(x)
Definition: ri.h:2409
#define sizeofexpression_undefined
Definition: ri.h:2370

References copy_sizeofexpression(), do_clone_expression(), is_sizeofexpression_expression, is_sizeofexpression_type, make_sizeofexpression_expression(), sizeofexpression_expression, sizeofexpression_tag, and sizeofexpression_undefined.

Referenced by do_clone_syntax().

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

◆ do_clone_statement()

static statement do_clone_statement ( statement  s,
clone_context  cc,
hash_table  ht 
)
static

ht

add new declarations to top level statement this prevents difficult scope renaming in C

Definition at line 393 of file clone_statement.c.

394 {
395  if (statement_undefined_p(s)) return s;
396 
397  entity new_label = do_clone_label(statement_label(s),cc/*, ht*/);
398  /* add new declarations to top level statement
399  * this prevents difficult scope renaming in C
400  */
401  list new_declarations_initialization = NIL;
403  {
404  entity new_entity = do_clone_entity(e,cc, ht);
405  if( !value_unknown_p(entity_initial(e)) &&
408  {
410  entity_to_expression(new_entity),
412  new_declarations_initialization=CONS(STATEMENT,ns,new_declarations_initialization);
413  }
414  }
415  instruction new_instruction = do_clone_instruction(statement_instruction(s),cc, ht);
416  instruction new_instruction_with_decl = ENDP(new_declarations_initialization)?
417  new_instruction:
420  gen_nconc(
421  gen_nreverse(new_declarations_initialization),
422  CONS(STATEMENT,instruction_to_statement(new_instruction),NIL))
423  ));
424 
425  return make_statement(
426  new_label,
430  new_instruction_with_decl,
431  NIL,
432  NULL,
434 
435 }
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
Definition: ri.c:2222
synchronization make_synchronization_none(void)
Definition: ri.c:2424
static instruction do_clone_instruction(instruction i, clone_context cc, hash_table ht)
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
statement make_assign_statement(expression, expression)
Definition: statement.c:583
#define STATEMENT_ORDERING_UNDEFINED
mapping.h inclusion
Definition: newgen-local.h:35
#define STATEMENT_NUMBER_UNDEFINED
default values
#define empty_comments
Empty comments (i.e.
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
extensions empty_extensions(void)
extension.c
Definition: extension.c:43
#define value_unknown_p(x)
Definition: ri.h:3077
#define statement_label(x)
Definition: ri.h:2450
#define expression_undefined_p(x)
Definition: ri.h:1224
#define statement_declarations(x)
Definition: ri.h:2460
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_undefined_p(x)
Definition: ri.h:2420
#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

References CONS, do_clone_entity(), do_clone_expression(), do_clone_instruction(), do_clone_label(), empty_comments, empty_extensions(), ENDP, ENTITY, entity_initial, entity_to_expression(), expression_undefined_p, FOREACH, gen_nconc(), gen_nreverse(), instruction_to_statement(), make_assign_statement(), make_instruction_sequence(), make_sequence(), make_statement(), make_synchronization_none(), NIL, STATEMENT, statement_declarations, statement_instruction, statement_label, STATEMENT_NUMBER_UNDEFINED, STATEMENT_ORDERING_UNDEFINED, statement_undefined_p, value_expression, value_expression_p, and value_unknown_p.

Referenced by clone_statement(), do_clone_forloop(), do_clone_loop(), do_clone_multitest(), do_clone_sequence(), do_clone_test(), and do_clone_whileloop().

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

◆ do_clone_subscript()

static subscript do_clone_subscript ( subscript  s,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 93 of file clone_statement.c.

94 {
95  list new_indices = NIL;
97  new_indices=CONS(EXPRESSION,do_clone_expression(e,cc, ht),new_indices);
98  return make_subscript(do_clone_expression(subscript_array(s),cc, ht),gen_nreverse(new_indices));
99 }
subscript make_subscript(expression a1, list a2)
Definition: ri.c:2327
#define subscript_indices(x)
Definition: ri.h:2563
#define subscript_array(x)
Definition: ri.h:2561

References CONS, do_clone_expression(), EXPRESSION, FOREACH, gen_nreverse(), make_subscript(), NIL, subscript_array, and subscript_indices.

Referenced by do_clone_syntax().

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

◆ do_clone_syntax()

static syntax do_clone_syntax ( syntax  s,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 111 of file clone_statement.c.

112 {
113  switch(syntax_tag(s))
114  {
115  case is_syntax_reference:
116  {
117  gen_chunk* chunk = do_clone_reference(syntax_reference(s),cc, ht);
118  if(INSTANCE_OF(reference,chunk))
119  {
120  pips_assert("result of cloning is a reference", check_reference((reference)chunk));
121  return make_syntax_reference((reference)chunk);
122  }
123  else if(INSTANCE_OF(call,chunk))
124  {
125  pips_assert("result of cloning is a call", check_call((call)chunk));
126  return make_syntax_call((call)chunk);
127  }
128  else
129  pips_internal_error("expecting a call or a reference as result of cloning");
130  }
131  case is_syntax_range:
132  return make_syntax_range(do_clone_range(syntax_range(s),cc, ht));
133  case is_syntax_call:
134  return make_syntax_call(do_clone_call(syntax_call(s),cc, ht));
135  case is_syntax_cast:
136  return make_syntax_cast(do_clone_cast(syntax_cast(s),cc, ht));
139  case is_syntax_subscript:
143  case is_syntax_va_arg:
144  {
145  list new_va_args = NIL;
147  new_va_args=CONS(SIZEOFEXPRESSION,do_clone_sizeofexpression(soe,cc, ht),new_va_args);
148  return make_syntax_va_arg(gen_nreverse(new_va_args));
149  }
150 
151  };
152  return syntax_undefined;
153 }
syntax make_syntax_application(application _field_)
Definition: ri.c:2512
syntax make_syntax_call(call _field_)
Definition: ri.c:2500
reference check_reference(reference p)
Definition: ri.c:2053
syntax make_syntax_sizeofexpression(sizeofexpression _field_)
Definition: ri.c:2506
syntax make_syntax_va_arg(list _field_)
Definition: ri.c:2515
syntax make_syntax_cast(cast _field_)
Definition: ri.c:2503
syntax make_syntax_range(range _field_)
Definition: ri.c:2497
syntax make_syntax_subscript(subscript _field_)
Definition: ri.c:2509
call check_call(call p)
Definition: ri.c:239
syntax make_syntax_reference(reference _field_)
Definition: ri.c:2494
static application do_clone_application(application a, clone_context cc, hash_table ht)
static cast do_clone_cast(cast c, clone_context cc, hash_table ht)
static subscript do_clone_subscript(subscript s, clone_context cc, hash_table ht)
static sizeofexpression do_clone_sizeofexpression(sizeofexpression s, clone_context cc, hash_table ht)
static gen_chunk * do_clone_reference(reference r, clone_context cc, hash_table ht)
nd formard declarations
#define INSTANCE_OF(type, value)
polymorhism thanks to newgen !
#define syntax_reference(x)
Definition: ri.h:2730
#define syntax_tag(x)
Definition: ri.h:2727
#define SIZEOFEXPRESSION(x)
SIZEOFEXPRESSION.
Definition: ri.h:2364
#define syntax_cast(x)
Definition: ri.h:2739
#define syntax_application(x)
Definition: ri.h:2748
#define syntax_va_arg(x)
Definition: ri.h:2751
#define syntax_range(x)
Definition: ri.h:2733
@ is_syntax_range
Definition: ri.h:2692
@ is_syntax_application
Definition: ri.h:2697
@ is_syntax_cast
Definition: ri.h:2694
@ is_syntax_call
Definition: ri.h:2693
@ is_syntax_va_arg
Definition: ri.h:2698
@ is_syntax_reference
Definition: ri.h:2691
@ is_syntax_sizeofexpression
Definition: ri.h:2695
@ is_syntax_subscript
Definition: ri.h:2696
#define syntax_sizeofexpression(x)
Definition: ri.h:2742
#define syntax_call(x)
Definition: ri.h:2736
#define syntax_undefined
Definition: ri.h:2676
#define syntax_subscript(x)
Definition: ri.h:2745

References check_call(), check_reference(), CONS, do_clone_application(), do_clone_call(), do_clone_cast(), do_clone_range(), do_clone_reference(), do_clone_sizeofexpression(), do_clone_subscript(), FOREACH, gen_nreverse(), INSTANCE_OF, is_syntax_application, is_syntax_call, is_syntax_cast, is_syntax_range, is_syntax_reference, is_syntax_sizeofexpression, is_syntax_subscript, is_syntax_va_arg, make_syntax_application(), make_syntax_call(), make_syntax_cast(), make_syntax_range(), make_syntax_reference(), make_syntax_sizeofexpression(), make_syntax_subscript(), make_syntax_va_arg(), NIL, pips_assert, pips_internal_error, SIZEOFEXPRESSION, syntax_application, syntax_call, syntax_cast, syntax_range, syntax_reference, syntax_sizeofexpression, syntax_subscript, syntax_tag, syntax_undefined, and syntax_va_arg.

Referenced by do_clone_expression().

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

◆ do_clone_test()

static test do_clone_test ( test  t,
clone_context  cc,
hash_table  ht 
)
static

Definition at line 264 of file clone_statement.c.

265 {
266  if(test_undefined_p(t)) return t;
267  return make_test(
269  do_clone_statement(test_true(t),cc, ht),
270  do_clone_statement(test_false(t),cc, ht));
271 
272 }
test make_test(expression a1, statement a2, statement a3)
Definition: ri.c:2607
#define test_false(x)
Definition: ri.h:2837
#define test_true(x)
Definition: ri.h:2835
#define test_condition(x)
Definition: ri.h:2833
#define test_undefined_p(x)
Definition: ri.h:2809

References do_clone_expression(), do_clone_statement(), make_test(), test_condition, test_false, test_true, and test_undefined_p.

Referenced by do_clone_instruction().

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

◆ do_clone_whileloop()

static whileloop do_clone_whileloop ( whileloop  w,
clone_context  cc,
hash_table  ht 
)
static

ht

Definition at line 321 of file clone_statement.c.

322 {
323  return make_whileloop(
326  do_clone_label(whileloop_label(w),cc/*, ht*/),
328 }
whileloop make_whileloop(expression a1, statement a2, entity a3, evaluation a4)
Definition: ri.c:2937
evaluation copy_evaluation(evaluation p)
EVALUATION.
Definition: ri.c:740
#define whileloop_evaluation(x)
Definition: ri.h:3166
#define whileloop_label(x)
Definition: ri.h:3164
#define whileloop_body(x)
Definition: ri.h:3162
#define whileloop_condition(x)
Definition: ri.h:3160

References copy_evaluation(), do_clone_expression(), do_clone_label(), do_clone_statement(), make_whileloop(), whileloop_body, whileloop_condition, whileloop_evaluation, and whileloop_label.

Referenced by do_clone_instruction().

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