PIPS
dowhile_to_while.c File Reference
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "misc.h"
#include "control.h"
#include "pipsdbm.h"
#include "resources.h"
+ Include dependency graph for dowhile_to_while.c:

Go to the source code of this file.

Functions

static void dowhile_to_while_walker (statement stmt, bool *changed)
 
bool dowhile_to_while (const char *module_name)
 dowhile_to_while.c More...
 
void do_loop_to_while_loop (statement sl)
 converts a doloop to a while loop, in place More...
 
void do_loop_to_for_loop (statement sl)
 converts a doloop to a for loop, in place More...
 

Function Documentation

◆ do_loop_to_for_loop()

void do_loop_to_for_loop ( statement  sl)

converts a doloop to a for loop, in place

Parameters
sll

Definition at line 162 of file dowhile_to_while.c.

163 {
164  pips_assert("statement is a loop",statement_loop_p(sl));
165  loop l =statement_loop(sl);
166  range r = loop_range(l);
167 
168  forloop fl = make_forloop(
179 }
instruction make_instruction_forloop(forloop _field_)
Definition: ri.c:1193
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
statement copy_statement(statement p)
STATEMENT.
Definition: ri.c:2186
forloop make_forloop(expression a1, expression a2, expression a3, statement a4)
Definition: ri.c:1025
loop statement_loop(statement)
Get the loop of a statement.
Definition: statement.c:1374
bool statement_loop_p(statement)
Definition: statement.c:349
statement update_statement_instruction(statement, instruction)
Replace the instruction in statement s by instruction i.
Definition: statement.c:3039
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define PLUS_UPDATE_OPERATOR_NAME
#define LESS_OR_EQUAL_OPERATOR_NAME
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
expression make_assign_expression(expression lhs, expression rhs)
Make an assign expression, since in C the assignment is a side effect operator.
Definition: expression.c:390
#define loop_body(x)
Definition: ri.h:1644
#define range_upper(x)
Definition: ri.h:2290
#define range_increment(x)
Definition: ri.h:2292
#define range_lower(x)
Definition: ri.h:2288
#define loop_range(x)
Definition: ri.h:1642
#define loop_index(x)
Definition: ri.h:1640

References copy_expression(), copy_statement(), entity_intrinsic(), entity_to_expression(), LESS_OR_EQUAL_OPERATOR_NAME, loop_body, loop_index, loop_range, make_assign_expression(), make_forloop(), make_instruction_forloop(), MakeBinaryCall(), pips_assert, PLUS_UPDATE_OPERATOR_NAME, range_increment, range_lower, range_upper, statement_loop(), statement_loop_p(), and update_statement_instruction().

Referenced by rw_loop().

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

◆ do_loop_to_while_loop()

void do_loop_to_while_loop ( statement  sl)

converts a doloop to a while loop, in place

convert the loop to a while loop : fst the body

then the whileloop

and the prelude

Parameters
sll

Definition at line 115 of file dowhile_to_while.c.

116 {
117  pips_assert("statement is a loop",statement_loop_p(sl));
118  loop l =statement_loop(sl);
119  range r = loop_range(l);
120 
121  /* convert the loop to a while loop :
122  * fst the body
123  */
124  list statements = make_statement_list(
131  range_increment(r)
132  )
133  )
134  );
135  /* then the whileloop */
140  range_upper(r)
141  ),
142  make_block_statement(statements),
145 
146  /* and the prelude */
147  sequence seq = make_sequence(
150  range_lower(r)),
152  )
153  );
157 
159 }
evaluation make_evaluation_before(void)
Definition: ri.c:786
whileloop make_whileloop(expression a1, statement a2, entity a3, evaluation a4)
Definition: ri.c:2937
instruction make_instruction_sequence(sequence _field_)
Definition: ri.c:1169
sequence make_sequence(list a)
Definition: ri.c:2125
instruction make_instruction_whileloop(whileloop _field_)
Definition: ri.c:1178
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
statement make_assign_statement(expression, expression)
Definition: statement.c:583
#define PLUS_OPERATOR_NAME
#define make_statement_list(stats...)
easy list constructor
entity entity_empty_label(void)
Definition: entity.c:1105
#define expression_undefined
Definition: ri.h:1223
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References copy_statement(), entity_empty_label(), entity_intrinsic(), entity_to_expression(), expression_undefined, instruction_to_statement(), LESS_OR_EQUAL_OPERATOR_NAME, loop_body, loop_index, loop_range, make_assign_statement(), make_block_statement(), make_evaluation_before(), make_instruction_sequence(), make_instruction_whileloop(), make_sequence(), make_statement_list, make_whileloop(), MakeBinaryCall(), pips_assert, PLUS_OPERATOR_NAME, range_increment, range_lower, range_upper, statement_loop(), statement_loop_p(), and update_statement_instruction().

Referenced by terapix_loop_handler().

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

◆ dowhile_to_while()

bool dowhile_to_while ( const char *  module_name)

dowhile_to_while.c

Parameters
module_nameodule_name

Definition at line 82 of file dowhile_to_while.c.

83 {
84  // prelude
85  debug_on("CONTROL_DEBUG_LEVEL");
89  );
90 
91  // whether anything was changed
92  bool changed = false;
93 
94  // actual transformation
97 
98  // postlude
99  if (changed)
100  {
104  }
105 
108  debug_off();
109  return true;
110 }
static void dowhile_to_while_walker(statement stmt, bool *changed)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
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
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
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
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
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

References db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, dowhile_to_while_walker(), gen_context_recurse, gen_true2(), get_current_module_statement(), module_name(), module_name_to_entity(), module_reorder(), reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), and statement_domain.

+ Here is the call graph for this function:

◆ dowhile_to_while_walker()

static void dowhile_to_while_walker ( statement  stmt,
bool changed 
)
static

Definition at line 38 of file dowhile_to_while.c.

39 {
41  if ( instruction_whileloop_p(instr) )
42  {
43  whileloop wl = instruction_whileloop(instr);
44 
45  // is it a do-while loop?
47  {
48  // we did something!
49  *changed = true;
50 
51  // do-while -> while-do
54 
55  // push while-do instruction
56  statement duplicated_stat = make_empty_statement();
57 
58  // duplicate while-do body statements and push it
59  // BUG: it seems that clone does not handle "unstructured"
63  NIL,
64  duplicated_stat
65  );
68 
69  insert_statement(duplicated_stat, dup, false);
70  insert_statement(duplicated_stat, instruction_to_statement(instr), false);
71 
72  // see how elegant is the patching ?
75  (stmt,
76  make_instruction_block(CONS(statement, duplicated_stat, NIL))
77  );
78  }
79  }
80 }
clone_context make_clone_context(entity a1, entity a2, list a3, statement a4)
Definition: cloning.c:52
void free_clone_context(clone_context p)
Definition: cloning.c:19
void free_evaluation(evaluation p)
Definition: ri.c:743
statement clone_statement(statement s, clone_context cc)
clone_statement.c
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
instruction make_instruction_block(list statements)
Build an instruction block from a list of statements.
Definition: instruction.c:106
#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
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
#define make_empty_statement
An alias for make_empty_block_statement.
#define whileloop_evaluation(x)
Definition: ri.h:3166
#define instruction_undefined
Definition: ri.h:1454
#define instruction_whileloop(x)
Definition: ri.h:1523
#define whileloop_body(x)
Definition: ri.h:3162
#define statement_instruction(x)
Definition: ri.h:2458
#define instruction_whileloop_p(x)
Definition: ri.h:1521
#define evaluation_after_p(x)
Definition: ri.h:1162
Definition: statement.c:54

References clone_statement(), CONS, evaluation_after_p, free_clone_context(), free_evaluation(), get_current_module_entity(), insert_statement(), instruction_to_statement(), instruction_undefined, instruction_whileloop, instruction_whileloop_p, make_clone_context(), make_empty_statement, make_evaluation_before(), make_instruction_block(), NIL, statement_instruction, update_statement_instruction(), whileloop_body, and whileloop_evaluation.

Referenced by dowhile_to_while().

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