25 #include "pips_config.h"
55 #include "resources.h"
130 unstructured_instruction,
134 pips_assert(
"Statement is consistent after FULL_SPAGUETTIFY",
139 pips_assert(
"Statement is consistent after FULL_SPAGUETTIFY",
141 debug_control(
"FSM STATE: Module control =======================================",current_control, 2);
144 return returned_statement;
164 bool is_first_control;
178 pips_debug(5,
"CONTROL [%p]\n", current_control);
199 is_first_control =
true;
209 if (is_first_control) {
211 first_control = new_control;
212 is_first_control =
false;
213 pips_debug(5,
"First control %p\n", first_control);
214 *new_entry = first_control;
240 new_control, last_control, new_control);
258 last_control = new_control;
259 *new_exit = new_control;
274 list sequences_to_reduce =
NIL;
275 list unstructured_to_flatten =
NIL;
276 int nb_of_sequences_to_reduce;
277 int nb_of_unstructured_to_flatten;
278 int debug_iteration = 0;
287 pips_debug(2,
"New iteration %d\n", debug_iteration);
289 sequences_to_reduce =
NIL;
290 unstructured_to_flatten =
NIL;
306 sequences_to_reduce);
307 pips_debug (5,
"MARKING SEQUENCE: %p\n", current_control);
315 nb_of_sequences_to_reduce =
gen_length (sequences_to_reduce);
323 pips_debug(2,
"Imbricated sequence: REDUCING\n");
327 &new_entry_of_imbricated,
328 &new_exit_of_imbricated);
329 pips_debug(5,
"Entry of imbricated sequence is %p\n",new_entry_of_imbricated);
330 pips_debug(5,
"Exit of imbricated sequence is %p\n",new_exit_of_imbricated);
334 new_entry_of_imbricated);
340 new_exit_of_imbricated);
352 unstructured_to_flatten
355 unstructured_to_flatten);
356 pips_debug (5,
"MARKING UNSTRUCTURED: %p\n", current_control);
364 nb_of_unstructured_to_flatten =
gen_length (unstructured_to_flatten);
370 pips_debug(2,
"Imbricated unstructured: FLATTENING\n");
372 debug_control (
"FLATTEN UNSTRUCTURED: ", current_control, 5);
375 }, unstructured_to_flatten);
378 while (((nb_of_sequences_to_reduce > 0)
379 || (nb_of_unstructured_to_flatten > 0)) && (debug_iteration < 3));
396 pips_assert(
"Control with 1 successors in CONNECT_UNSTRUCTURED",
398 pips_assert(
"Control with 1 predecessor in CONNECT_UNSTRUCTURED",
400 pips_assert(
"Control connections in CONNECT_UNSTRUCTURED",
406 pips_assert(
"Exit with no successors in CONNECT_UNSTRUCTURED",
411 pips_debug(5,
"connect_unstructured BEFORE flatten_unstructured()\n");
418 pips_debug(5,
"connect_unstructured AFTER flatten_unstructured()\n");
466 pips_assert(
"Exit of unstructured has no successor",
508 debug_statement(
"FULL_SPAGHETTIFY: Module statement: =====================================", stat, 2);
510 pips_assert(
"Control with 1 successors in FULL_SPAGHETTIFY",
512 pips_assert(
"Control with 1 predecessor in FULL_SPAGHETTIFY",
514 pips_assert(
"Control connections in FULL_SPAGHETTIFY",
522 pips_debug(2,
"full_spaghettify_statement: TEST\n");
532 control last_control = current_control;
533 pips_debug(2,
"full_spaghettify_statement: SEQUENCE\n");
547 pips_debug(2,
"full_spaghettify_statement: LOOP\n");
555 pips_debug(2,
"full_spaghettify_statement: WHILELOOP\n");
563 pips_debug(2,
"full_spaghettify_statement: FORLOOP\n");
571 pips_debug(2,
"full_spaghettify_statement: CALL\n");
579 pips_debug(2,
"full_spaghettify_statement: UNSTRUCTURED\n");
591 return current_control;
613 debug_on(
"SPAGUETTIFY_DEBUG_LEVEL");
618 pips_assert(
"Statement is consistent after FULL_SPAGUETTIFY",
621 pips_assert(
"Unstructured is consistent after FULL_SPAGUETTIFY",
628 pips_debug(5,
"====================================================\n");
629 pips_debug(5,
"Statement BEFORE simple_restructure_statement\n");
637 pips_debug(5,
"====================================================\n");
638 pips_debug(5,
"Statement AFTER simple_restructure_statement\n");
645 pips_assert(
"Statement is consistent after FULL_SPAGUETTIFY",
unstructured make_unstructured(control a1, control a2)
bool unstructured_consistent_p(unstructured p)
bool statement_consistent_p(statement p)
statement make_statement(entity a1, intptr_t a2, intptr_t a3, string a4, instruction a5, list a6, string a7, extensions a8, synchronization a9)
instruction make_instruction(enum instruction_utype tag, void *val)
synchronization make_synchronization_none(void)
control make_control(statement a1, list a2, list a3)
static statement module_statement
void const char const char const int
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
struct _newgen_struct_statement_ * statement
static list predecessors(statement st, graph tg)
static list successors(list l)
void simple_restructure_statement(statement)
A simple cleaning of the control graph without major topological restructuring.
const char * module_name(const char *s)
Return the module part of an entity name.
statement spaghettify_forloop(statement stat, const char *module_name)
This function takes the statement stat as parameter and return a new spaghettized statement,...
static void flatten_unstructured(unstructured the_unstructured)
This function takes as entry an unstructured and flatten it:
static control full_spaghettify_statement(statement stat, const char *module_name, unstructured u, control current_control, control next_control)
The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like cod...
static control connect_unstructured(statement unstructured_statement, control current_control, control next_control)
This function connect the unstructured unstructured_statement to the current Control Flow Graph betwe...
static statement full_spaghettify_module(statement module_statement, const char *module_name)
static void reduce_sequence(control current_control, sequence seq, control *new_entry, control *new_exit)
This function reduce the sequence seq at the position in the control graph indicated by control curre...
bool full_spaghettify(const char *module_name)
full_spaghettify.c
static control replace_control_with_unstructured(unstructured the_unstructured, control current_control)
This function connect the unstructured the_unstructured to the current Control Flow Graph at the plac...
void unlink_2_control_nodes(control source, control target)
Remove all edged between 2 control nodes.
void link_2_control_nodes(control source, control target)
Add an edge between 2 control nodes.
#define CONTROL_MAP(ctl, code, c, list)
Macro to walk through all the controls reachable from a given control node of an unstructured.
void reset_current_module_entity(void)
Reset the current module entity.
void reset_current_module_statement(void)
Reset the current module statement.
statement set_current_module_statement(statement)
Set the current module statement.
entity set_current_module_entity(entity)
static.c
#define NIL
The empty list (nil in Lisp)
list gen_copy_seq(list l)
Copy a list structure.
size_t gen_length(const list l)
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
gen_chunk gen_nth(int n, const list l)
to be used as ENTITY(gen_nth(3, l))...
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
string db_get_memory_resource(const char *rname, const char *oname, bool pure)
Return the pointer to the resource, whatever it is.
#define DB_PUT_MEMORY_RESOURCE(res_name, own_name, res_val)
conform to old interface.
unstructured statement_unstructured(statement stat)
Get the unstructured of a statement.
statement make_continue_statement(entity)
statement spaghettify_loop(statement stat, const char *module_name)
This function takes the statement stat as parameter and return a new spaghettized statement,...
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_user_warning
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
statement spaghettify_test(statement, const char *)
test_spaghettify.c
void short_debug_unstructured(unstructured, int)
DEBUG FUNCTION: print debugging informations for an unstructured an_unstructured (short version)
void debug_statement(const char *, statement, int)
DEBUG FUNCTION: print debugging informations for a statement stat.
void debug_control(const char *, control, int)
DEBUG FUNCTION: print debugging informations for a control a_control.
statement spaghettify_whileloop(statement, const char *)
whileloop_spaghettify.c
void print_statement(statement)
Print a statement on stderr.
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
#define empty_comments
Empty comments (i.e.
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
entity entity_empty_label(void)
#define control_undefined
#define control_predecessors(x)
#define statement_ordering(x)
#define CONTROL(x)
CONTROL.
@ is_instruction_unstructured
@ is_instruction_whileloop
@ is_instruction_sequence
#define instruction_tag(x)
#define sequence_statements(x)
#define statement_extensions(x)
#define instruction_sequence(x)
#define control_successors(x)
#define unstructured_exit(x)
#define unstructured_entry(x)
#define statement_instruction(x)
#define control_statement(x)
#define statement_number(x)
#define instruction_unstructured(x)
#define STATEMENT(x)
STATEMENT.
The structure used to build lists in NewGen.