PIPS
reorder.c File Reference

These functions compute the statement_ordering of their arguments. More...

#include <stdio.h>
#include <strings.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "misc.h"
#include "ri-util.h"
+ Include dependency graph for reorder.c:

Go to the source code of this file.

Functions

void reset_unstructured_number ()
 Reset the unstructured number for a new module reordering. More...
 
static int get_unstructured_number ()
 Compute the next unstructured order. More...
 
static int get_next_unstructured_number ()
 Compute the next unstructured order. More...
 
static int statement_reorder (statement st, int un, int sn, bool *changed)
 Compute the statement ordering of a statement and all its components. More...
 
void control_node_reorder (__attribute__((unused)) control c, __attribute__((unused)) set visited_control)
 
bool unstructured_reorder (unstructured u)
 Reorder an unstructured. More...
 
bool module_body_reorder (statement body)
 Reorder a module. More...
 
bool module_reorder (statement body)
 Reorder a module and recompute order to statement if any. More...
 

Variables

static int u_number
 The current unstructured number, that is the number of control node encountered during depth first visiting
More...
 

Detailed Description

These functions compute the statement_ordering of their arguments.

To ease referencing statements, statements are numbered with an ordering that is made of 2 parts, an unstructured order that is the occurence order of unstructured control node in a depth first visit of the RI, and a local order that corresponds to appearance order in a depth first visit of the statements inside a control node. This last number in reset to one when encountering a control node.

Definition in file reorder.c.

Function Documentation

◆ control_node_reorder()

void control_node_reorder ( __attribute__((unused)) control  c,
__attribute__((unused)) set  visited_control 
)

Definition at line 153 of file reorder.c.

154  {
155 }

◆ get_next_unstructured_number()

static int get_next_unstructured_number ( )
static

Compute the next unstructured order.

Definition at line 68 of file reorder.c.

68  {
69  return ++u_number;
70 }
static int u_number
The current unstructured number, that is the number of control node encountered during depth first vi...
Definition: reorder.c:52

References u_number.

Referenced by unstructured_reorder().

+ Here is the caller graph for this function:

◆ get_unstructured_number()

static int get_unstructured_number ( )
static

Compute the next unstructured order.

Definition at line 62 of file reorder.c.

62  {
63  return u_number;
64 }

References u_number.

Referenced by module_body_reorder().

+ Here is the caller graph for this function:

◆ module_body_reorder()

bool module_body_reorder ( statement  body)

Reorder a module.

This recompute the ordering of a module, that is the ordering number of all the statements in the module..

Parameters
bodyis the top-level statement of the module to reorder

If a module_body_reorder() is required, ordering_to_statement must be recomputed if any. So use module_reorder() instead of the low-level module_body_reorder():

Reorder the module statements by beginning with unstructured number and statement number at 1

Parameters
bodyody

Definition at line 211 of file reorder.c.

212 {
213  /* If a module_body_reorder() is required, ordering_to_statement must be
214  recomputed if any. So use module_reorder() instead of the low-level
215  module_body_reorder(): */
216  pips_assert("ordering to statement is not initialized",
218 
219  debug_on("CONTROL_DEBUG_LEVEL");
220 
222 
223  /* Reorder the module statements by beginning with unstructured number
224  and statement number at 1 */
225  bool changed = false;
226  statement_reorder(body, get_unstructured_number(), 1, &changed);
227 
228  debug_off();
229 
230  return changed;
231 }
#define debug_on(env)
Definition: misc-local.h:157
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define debug_off()
Definition: misc-local.h:160
bool ordering_to_statement_initialized_p()
Test if the ordering to statement is initialized.
Definition: ordering.c:63
static int statement_reorder(statement st, int un, int sn, bool *changed)
Compute the statement ordering of a statement and all its components.
Definition: reorder.c:83
void reset_unstructured_number()
Reset the unstructured number for a new module reordering.
Definition: reorder.c:56
static int get_unstructured_number()
Compute the next unstructured order.
Definition: reorder.c:62

References debug_off, debug_on, get_unstructured_number(), ordering_to_statement_initialized_p(), pips_assert, reset_unstructured_number(), and statement_reorder().

Referenced by do_it(), and module_reorder().

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

◆ module_reorder()

bool module_reorder ( statement  body)

Reorder a module and recompute order to statement if any.

This recompute the ordering of a module, that is the ordering number of all the statements in the module..

If there is also already a mapping from the ordering to the statements, it is reset and recompute after reordering.

Parameters
bodyis the top-level statement of the module to reorder

There was a mapping to associate a statement to a given ordering, so clean it:

There was a mapping to associate a statement to a given ordering, so we recompute it:

FI: I'd rather use set_ordering_to_statement() so that reset are properly called and no outdated ots hash table remains for ever in the background, but I do not want to break PIPS right now.

How do you know ordering to statement to be useful in the future?

May be, we are going to work on a different module very soon..

Parameters
bodyody

Definition at line 244 of file reorder.c.

245 {
246  bool ordering_mapping_used = ordering_to_statement_initialized_p();
247  if(ordering_mapping_used)
248  /* There was a mapping to associate a statement to a given ordering,
249  so clean it: */
251 
252  bool changed = module_body_reorder(body);
253 
254  if (ordering_mapping_used) {
255  /* There was a mapping to associate a statement to a given ordering,
256  so we recompute it: */
258  /* FI: I'd rather use set_ordering_to_statement() so that reset are
259  properly called and no outdated ots hash table remains for ever in
260  the background, but I do not want to break PIPS right now.
261 
262  How do you know ordering to statement to be useful in the future?
263 
264  May be, we are going to work on a different module very soon..
265  */
266  }
267 
268  return changed;
269 }
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
bool module_body_reorder(statement body)
Reorder a module.
Definition: reorder.c:211

References module_body_reorder(), ordering_to_statement_initialized_p(), reset_ordering_to_statement(), and set_ordering_to_statement().

Referenced by add_control_counters(), AddEntityToCompilationUnit(), array_bound_check_bottom_up(), array_bound_check_interprocedural(), array_bound_check_top_down(), array_expansion(), atomizer(), bdsc_code_instrumentation(), controlizer(), copy_value_of_write(), copy_value_of_write_with_cumulated_regions(), deatomizer(), delay_communications(), delay_communications_interprocedurally(), delay_load_communications(), delay_store_communications(), do_kernelize(), dowhile_to_while(), dsc_code_parallelization(), eliminate_original_variables(), expression_substitution(), flatten_code(), for_loop_to_do_loop(), for_loop_to_while_loop(), freia_unroll_while(), fsm_generation(), fsm_merge_states(), fsm_split_state(), full_fsm_generation(), full_spaghettify(), full_unroll(), full_unroll_pragma(), generate_starpu_pragma(), generate_two_addresses_code(), global_parallelization(), gpu_promote_sequential(), group_constants(), guard_elimination(), if_conversion(), if_conversion_compact(), if_conversion_init(), interactive_loop_transformation(), invariant_code_motion(), isolate_statement(), kernel_load_store_engine(), kernelize(), linearize_array_generic(), loop_auto_unroll(), loop_expansion(), loop_expansion_init(), loop_nest_unswitching(), module_to_wp65_modules(), mpi_conversion(), mpi_task_generation(), new_atomizer(), new_controlizer(), normalize_microcode(), old_array_bound_check_instrumentation(), old_reductions(), one_thread_parallelize(), openmp_task_generation(), optimize_expressions(), outline(), partial_eval(), phrase_comEngine_distributor(), phrase_distributor(), phrase_distributor_control_code(), phrase_distributor_init(), phrase_remove_dependences(), reduction_atomization(), reduction_detection(), reduction_propagation(), redundant_load_store_elimination(), regions_to_loops(), RemoveEntityFromCompilationUnit(), restructure_control(), safescale_distributor(), safescale_distributor_init(), scalar_renaming(), sesamify(), simd_atomizer(), simd_remove_reductions(), simdizer(), simdizer_auto_tile(), simdizer_auto_unroll(), simdizer_init(), simplify_complex(), simplify_subscripts(), solve_hardware_constraints(), spaghettify(), spire_distributed_unstructured_to_structured(), spire_shared_unstructured_to_structured(), split_initializations(), split_structures(), statement_insertion(), static_controlize(), step_parser(), strip_mine(), symbolic_tiling(), taskify(), terapix_warmup(), tiling_sequence(), unroll(), unspaghettify(), variable_replication(), and wrap_kernel_argument().

+ Here is the call graph for this function:

◆ reset_unstructured_number()

void reset_unstructured_number ( void  )

Reset the unstructured number for a new module reordering.

reorder.c

Definition at line 56 of file reorder.c.

56  {
57  u_number = 0;
58 }

References u_number.

Referenced by control_graph(), and module_body_reorder().

+ Here is the caller graph for this function:

◆ statement_reorder()

static int statement_reorder ( statement  st,
int  un,
int  sn,
bool changed 
)
static

Compute the statement ordering of a statement and all its components.

This function should be rewritten with a gen_multi_recurse_context() on statements and controls...

Parameters
stis the statement which we want to compute the ordering
unis the unstructured number before statement entry
stis the statement number before statement entry
Returns
the statement number after the end of the given statement

Definition at line 83 of file reorder.c.

84 {
86  pips_assert("instruction is defined", !instruction_undefined_p(i));
87 
88  // temporary, just to avoid rebooting...
89  static int check_depth_hack = 0;
90  check_depth_hack++;
91  pips_assert("not too deep", check_depth_hack<10000);
92 
93  pips_debug(5, "entering for %"_intFMT" : (%d,%d)\n",
94  statement_number(st), un, sn);
95 
96  // update ordering if needed
97  int new_order = MAKE_ORDERING(un, sn);
98  if (new_order != statement_ordering(st))
99  {
100  statement_ordering(st) = new_order;
101  *changed = true;
102  }
103  sn += 1;
104 
105  switch (instruction_tag(i))
106  {
108  pips_debug(5, "sequence\n");
110  sn = statement_reorder(s, un, sn, changed);
111  break;
112  case is_instruction_test:
113  pips_debug(5, "test\n");
114  sn = statement_reorder(test_true(instruction_test(i)), un, sn, changed);
115  sn = statement_reorder(test_false(instruction_test(i)), un, sn, changed);
116  break;
117  case is_instruction_loop:
118  pips_debug(5, "loop\n");
119  sn = statement_reorder(loop_body(instruction_loop(i)), un, sn, changed);
120  break;
122  pips_debug(5, "whileloop\n");
124  un, sn, changed);
125  break;
127  pips_debug(5, "forloop\n");
129  un, sn, changed);
130  break;
131  case is_instruction_goto:
132  case is_instruction_call:
133  pips_debug(5, "goto or call\n");
134  // nothing to do, does not contain statements
135  break;
137  pips_debug(5, "expression\n");
138  break;
140  pips_debug(5, "unstructured\n");
142  break;
143  // missing: is_instruction_multitest
144  default:
145  pips_internal_error("Unknown tag %d", instruction_tag(i));
146  }
147  pips_debug(5, "exiting %d\n", sn);
148  check_depth_hack--;
149  return sn;
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 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 _intFMT
Definition: newgen_types.h:57
bool unstructured_reorder(unstructured u)
Reorder an unstructured.
Definition: reorder.c:166
#define MAKE_ORDERING(u, s)
On devrait utiliser Newgen pour cela, mais comme on ne doit pas les utiliser directement (mais via st...
#define loop_body(x)
Definition: ri.h:1644
#define instruction_loop(x)
Definition: ri.h:1520
#define statement_ordering(x)
Definition: ri.h:2454
#define test_false(x)
Definition: ri.h:2837
#define instruction_undefined_p(x)
Definition: ri.h:1455
@ 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_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 test_true(x)
Definition: ri.h:2835
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define instruction_forloop(x)
Definition: ri.h:1538
#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_test(x)
Definition: ri.h:1517
#define statement_number(x)
Definition: ri.h:2452
#define forloop_body(x)
Definition: ri.h:1372
#define instruction_unstructured(x)
Definition: ri.h:1532

References _intFMT, FOREACH, forloop_body, instruction_forloop, instruction_loop, instruction_sequence, instruction_tag, instruction_test, instruction_undefined_p, instruction_unstructured, instruction_whileloop, is_instruction_call, is_instruction_expression, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, loop_body, MAKE_ORDERING, pips_assert, pips_debug, pips_internal_error, sequence_statements, statement_instruction, statement_number, statement_ordering, test_false, test_true, unstructured_reorder(), and whileloop_body.

Referenced by module_body_reorder(), and unstructured_reorder().

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

◆ unstructured_reorder()

bool unstructured_reorder ( unstructured  u)

Reorder an unstructured.

All the nodes of the unstructured are numbered, first the reachable one and the the unreachable ones if any.

Parameters
uthe unstructured to reorder.

this function is used by control/old_controlizer.c

To store the visited nodes by CONTROL_MAP and avoid visiting twice a control node:

To avoid renaming twice a control node statement, keep track of the visited statements:

First iterate on the reachable control nodes from the entry node of the unstructured and then from the exit node:

Since we enter a control node, increase the unstructured order:

ifdebug(3)

print_statement(st);

Since we enter a control node, number the statements inside this control node with a statement number starting from 1:

Free the list build up during the visit:

Definition at line 166 of file reorder.c.

167 {
168  bool changed = false;
169  /* To store the visited nodes by CONTROL_MAP and avoid visiting twice a
170  control node: */
171  list blocs = NIL;
172  /* To avoid renaming twice a control node statement, keep track of the
173  visited statements: */
174  // set visited_control =
175 
176  pips_debug(2, "entering\n");
177 
178  /* First iterate on the reachable control nodes from the entry node of
179  the unstructured and then from the exit node: */
180  UNSTRUCTURED_CONTROL_MAP(c, u, blocs, {
182  /* Since we enter a control node, increase the unstructured
183  order: */
184  int un = get_next_unstructured_number();
185 
186  pips_debug(3, "will reorder %ld %d\n", statement_number(st), un);
187  /* ifdebug(3) */
188  /* print_statement(st); */
189 
190  /* Since we enter a control node, number the statements inside this
191  control node with a statement number starting from 1: */
192  statement_reorder(st, un, 1, &changed);
193  });
194 
195  /* Free the list build up during the visit: */
196  gen_free_list(blocs);
197 
198  debug(3, "unstructured_reorder", "exiting\n");
199 
200  return changed;
201 }
#define UNSTRUCTURED_CONTROL_MAP(c, u, l, code)
Walk through all the controls of un unstructured.
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
void debug(const int the_expected_debug_level, const char *calling_function_name, const char *a_message_format,...)
ARARGS0.
Definition: debug.c:189
static int get_next_unstructured_number()
Compute the next unstructured order.
Definition: reorder.c:68
#define control_statement(x)
Definition: ri.h:941
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References control_statement, debug(), gen_free_list(), get_next_unstructured_number(), NIL, pips_debug, statement_number, statement_reorder(), and UNSTRUCTURED_CONTROL_MAP.

Referenced by control_graph(), and statement_reorder().

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

Variable Documentation

◆ u_number

int u_number
static

The current unstructured number, that is the number of control node encountered during depth first visiting

Definition at line 52 of file reorder.c.

Referenced by get_next_unstructured_number(), get_unstructured_number(), and reset_unstructured_number().