PIPS
spaghettify.c File Reference
#include <stdio.h>
#include <ctype.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "text-util.h"
#include "dg.h"
#include "properties.h"
#include "control.h"
#include "callgraph.h"
#include "spaghettify.h"
#include "phrase_tools.h"
+ Include dependency graph for spaghettify.c:

Go to the source code of this file.

Functions

statement spaghettify_statement (statement stat, const char *module_name)
 The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like code portions in order to synthetise them in reconfigurables units. More...
 
bool spaghettify (const char *module_name)
 

Function Documentation

◆ spaghettify()

bool spaghettify ( const char *  module_name)

get the resources

Now do the job

Reorder the module, because new statements have been added

update/release resources

Parameters
module_nameodule_name

Definition at line 173 of file spaghettify.c.

174 {
175  /* get the resources */
176  statement stat = (statement) db_get_memory_resource(DBR_CODE,
177  module_name,
178  true);
179 
182 
183  debug_on("SPAGUETTIFY_DEBUG_LEVEL");
184 
185  /* Now do the job */
186  stat = spaghettify_statement(stat,module_name);
187 
188  pips_assert("Statement is consistent after SPAGUETTIFY",
189  statement_consistent_p(stat));
190 
191  /* Reorder the module, because new statements have been added */
192  module_reorder(stat);
193  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name, stat);
194  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, module_name,
195  compute_callees(stat));
196 
197  /* update/release resources */
200 
201  debug_off();
202 
203  return true;
204 }
bool statement_consistent_p(statement p)
Definition: ri.c:2195
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
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
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
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 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 module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
entity local_name_to_top_level_entity(const char *n)
This function try to find a top-level entity from a local name.
Definition: entity.c:1450
statement spaghettify_statement(statement stat, const char *module_name)
The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like cod...
Definition: spaghettify.c:85

References compute_callees(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, local_name_to_top_level_entity(), module_name(), module_reorder(), pips_assert, reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), spaghettify_statement(), and statement_consistent_p().

+ Here is the call graph for this function:

◆ spaghettify_statement()

statement spaghettify_statement ( statement  stat,
const char *  module_name 
)

The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like code portions in order to synthetise them in reconfigurables units.

spaghettify.c

This phase transforms structured code portions (eg. loops) in unstructured statements.

To add flexibility, the behavior of \texttt{spaghettifier} is controlled by the properties

  • DESTRUCTURE_TESTS
  • DESTRUCTURE_LOOPS
  • DESTRUCTURE_WHILELOOPS
  • DESTRUCTURE_FORLOOPS to allow more or less destruction power !

spaghettify > MODULE.code < PROGRAM.entities < MODULE.code This function is recursively called during spaghettization. It takes the statement stat as parameter and return a new spaghettized statement (or the same if nothing has been done). Spaguettization is done:

  • on Tests (if property DESTRUCTURE_TESTS set to true)
  • on Loops (if property DESTRUCTURE_LOOPS set to true)
  • on WhileLoops (if property DESTRUCTURE_WHILELOOPS set to true)
  • on ForLoops (if property DESTRUCTURE_FORLOOPS set to true)
Parameters
stattat
module_nameodule_name

Definition at line 85 of file spaghettify.c.

86 {
87  // Defaut behaviour is to return parameter statement stat
88  statement returned_statement = stat;
90 
91  pips_debug(2,"\nSPAGHETTIFY: Module statement: =====================================\n");
92  ifdebug(2) {
93  print_statement(stat);
94  }
95  pips_debug(2,"domain number = %"PRIdPTR"\n", statement_domain_number(stat));
96  pips_debug(2,"entity = UNDEFINED\n");
97  pips_debug(2,"statement number = %"PRIdPTR"\n", statement_number(stat));
98  pips_debug(2,"statement ordering = %"PRIdPTR"\n", statement_ordering(stat));
100  pips_debug(2,"statement comments = EMPTY\n");
101  }
102  else {
103  pips_debug(2,"statement comments = %s\n", statement_comments(stat));
104  }
105  pips_debug(2,"statement instruction = %s\n", statement_type_as_string(stat));
106  switch (instruction_tag(i)) {
107  case is_instruction_test:
108  {
109  pips_debug(2, "TEST\n");
110  if (get_bool_property("DESTRUCTURE_TESTS")) {
111  returned_statement = spaghettify_test (stat, module_name);
112  }
113  break;
114  }
116  {
118  pips_debug(2, "SEQUENCE\n");
119  MAP(STATEMENT, current_stat,
120  {
121  statement new_stat = spaghettify_statement(current_stat, module_name);
122  if (new_stat != NULL) {
123  gen_list_patch (sequence_statements(seq), current_stat, new_stat);
124  }
125  }, sequence_statements(seq));
126  break;
127  }
128  case is_instruction_loop: {
129  pips_debug(2, "LOOP\n");
130  if (get_bool_property("DESTRUCTURE_LOOPS")) {
131  returned_statement = spaghettify_loop (stat, module_name);
132  }
133  break;
134  }
136  pips_debug(2, "WHILELOOP\n");
137  if (get_bool_property("DESTRUCTURE_WHILELOOPS")) {
138  returned_statement = spaghettify_whileloop (stat, module_name);
139  }
140  break;
141  }
142  case is_instruction_forloop: {
143  pips_debug(2, "FORLOOP\n");
144  if (get_bool_property("DESTRUCTURE_FORLOOPS")) {
145  returned_statement = spaghettify_forloop (stat, module_name);
146  }
147  break;
148  }
149  case is_instruction_call: {
150  pips_debug(2, "CALL\n");
151  break;
152  }
154  pips_debug(2, "UNSTRUCTURED\n");
155  break;
156  }
157  case is_instruction_goto: {
158  pips_debug(2, "GOTO\n");
159  break;
160  }
161  default:
162  pips_debug(2, "UNDEFINED\n");
163  break;
164  }
165 
166  return returned_statement;
167 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
statement spaghettify_forloop(statement stat, const char *module_name)
This function takes the statement stat as parameter and return a new spaghettized statement,...
void gen_list_patch(list l, const void *x, const void *y)
Replace all the reference to x in list l by a reference to y:
Definition: list.c:985
#define MAP(_map_CASTER, _map_item, _map_code, _map_list)
Apply/map an instruction block on all the elements of a list (old fashioned)
Definition: newgen_list.h:226
bool statement_with_empty_comment_p(statement)
Return true if the statement has an empty statement:
Definition: statement.c:126
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.
Definition: misc-local.h:145
statement spaghettify_test(statement, const char *)
test_spaghettify.c
string statement_type_as_string(statement)
phrase_tools.c
Definition: phrase_tools.c:65
statement spaghettify_whileloop(statement, const char *)
whileloop_spaghettify.c
void print_statement(statement)
Print a statement on stderr.
Definition: statement.c:98
#define statement_ordering(x)
Definition: ri.h:2454
@ is_instruction_goto
Definition: ri.h:1473
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_whileloop
Definition: ri.h:1472
@ 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 statement_domain_number(x)
Definition: ri.h:2448
#define sequence_statements(x)
Definition: ri.h:2360
#define instruction_sequence(x)
Definition: ri.h:1514
#define statement_instruction(x)
Definition: ri.h:2458
#define statement_comments(x)
Definition: ri.h:2456
#define statement_number(x)
Definition: ri.h:2452
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define ifdebug(n)
Definition: sg.c:47

References gen_list_patch(), get_bool_property(), ifdebug, instruction_sequence, instruction_tag, is_instruction_call, is_instruction_forloop, is_instruction_goto, is_instruction_loop, is_instruction_sequence, is_instruction_test, is_instruction_unstructured, is_instruction_whileloop, MAP, module_name(), pips_debug, print_statement(), sequence_statements, spaghettify_forloop(), spaghettify_loop(), spaghettify_statement(), spaghettify_test(), spaghettify_whileloop(), STATEMENT, statement_comments, statement_domain_number, statement_instruction, statement_number, statement_ordering, statement_type_as_string(), and statement_with_empty_comment_p().

Referenced by make_body_from_forloop(), make_body_from_loop(), make_body_from_whileloop(), make_if_false_from_test(), make_if_true_from_test(), spaghettify(), and spaghettify_statement().

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