PIPS
forloop_spaghettify.c
Go to the documentation of this file.
1 /*
2 
3  $Id: forloop_spaghettify.c 23065 2016-03-02 09:05:50Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of PIPS.
8 
9  PIPS is free software: you can redistribute it and/or modify it
10  under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 #ifdef HAVE_CONFIG_H
25  #include "pips_config.h"
26 #endif
27 /**
28  * The spaghettifier is used in context of PHRASE project while creating
29  * "Finite State Machine"-like code portions in order to synthetise them
30  * in reconfigurables units.
31  *
32  * This file contains the code used for spaghettify forloops.
33  *
34  * NOT YET IMPLEMENTED
35  */
36 
37 #include <stdio.h>
38 #include <ctype.h>
39 
40 #include "genC.h"
41 #include "linear.h"
42 #include "ri.h"
43 #include "effects.h"
44 
45 #include "resources.h"
46 
47 #include "misc.h"
48 #include "ri-util.h"
49 #include "effects-util.h"
50 
51 #include "text-util.h"
52 
53 #include "dg.h"
54 
55 
56 #include "phrase_tools.h"
57 #include "spaghettify.h"
58 
60  statement stat)
61 {
62  statement condition_statement;
63 
64  test condition_test
65  = make_test (forloop_condition(curLoop),
68 
69 
70  condition_statement = make_statement(entity_empty_label(),
71  statement_number(stat),
72  statement_ordering(stat),
75  condition_test),
76  NIL,NULL,
78 
79  return make_control(condition_statement, NIL, NIL);
80 }
81 
83 {
85 }
86 
88  const char* module_name)
89 {
90  return make_control
92  module_name), NIL, NIL);
93 }
94 
96  statement stat,
97  const char* module_name)
98 {
99  control condition = make_condition_from_forloop(curLoop, stat);
102 
103  expression loopInit = forloop_initialization(curLoop);
104  expression loopCond = forloop_condition(curLoop);
105  expression loopInc = forloop_increment(curLoop);
106 
107  pips_assert("syntax_call_p(expression_syntax(loopInit))",
108  syntax_call_p(expression_syntax(loopInit)));
109 
110  pips_assert("syntax_call_p(expression_syntax(loopCond))",
111  syntax_call_p(expression_syntax(loopCond)));
112 
113  pips_assert("syntax_call_p(expression_syntax(loopInc))",
114  syntax_call_p(expression_syntax(loopInc)));
115 
118 
119  control init_control = make_control(initStat, NIL, NIL);
120  control inc_control = make_control(incStat, NIL, NIL);
121 
122  link_2_control_nodes (init_control, condition);
123  link_2_control_nodes (condition, exit); /* false condition, we exit from forloop */
124  link_2_control_nodes (condition, body); /* true condition, we go to body */
125  link_2_control_nodes(body, inc_control);
126  link_2_control_nodes (inc_control, condition); /* after body, we go back to condition */
127 
128  return make_unstructured(init_control, exit);
129 }
130 
131 /*
132  * This function takes the statement stat as parameter and return a new
133  * spaghettized statement, asserting stat is a FORLOOP statement
134  */
136 {
137  statement returned_statement = stat;
138  instruction unstructured_instruction;
139  unstructured new_unstructured;
140 
141  pips_assert("Statement is FORLOOP in FSM_GENERATION",
144 
145  pips_debug(2, "spaghettify_forloop, module %s\n", module_name);
146 
147  new_unstructured
150  stat,
151  module_name);
152 
153  unstructured_instruction = make_instruction(is_instruction_unstructured,
154  new_unstructured);
155 
156  statement_instruction(returned_statement) = unstructured_instruction;
157 
158  return returned_statement;
159 }
unstructured make_unstructured(control a1, control a2)
Definition: ri.c:2778
test make_test(expression a1, statement a2, statement a3)
Definition: ri.c:2607
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
instruction make_instruction(enum instruction_utype tag, void *val)
Definition: ri.c:1166
synchronization make_synchronization_none(void)
Definition: ri.c:2424
control make_control(statement a1, list a2, list a3)
Definition: ri.c:523
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
static control make_body_from_forloop(forloop curLoop, const char *module_name)
static control make_exit_from_forloop()
static unstructured make_unstructured_from_forloop(forloop curLoop, statement stat, const char *module_name)
static control make_condition_from_forloop(forloop curLoop, statement stat)
The spaghettifier is used in context of PHRASE project while creating "Finite State Machine"-like cod...
statement spaghettify_forloop(statement stat, const char *module_name)
This function takes the statement stat as parameter and return a new spaghettized statement,...
void link_2_control_nodes(control source, control target)
Add an edge between 2 control nodes.
Definition: control.c:1193
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
statement make_continue_statement(entity)
Definition: statement.c:953
#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_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define exit(code)
Definition: misc-local.h:54
statement spaghettify_statement(statement, const char *)
spaghettify.c
Definition: spaghettify.c:85
#define call_to_statement(c)
#define empty_comments
Empty comments (i.e.
entity entity_empty_label(void)
Definition: entity.c:1105
#define forloop_initialization(x)
Definition: ri.h:1366
#define forloop_increment(x)
Definition: ri.h:1370
#define syntax_call_p(x)
Definition: ri.h:2734
#define statement_ordering(x)
Definition: ri.h:2454
@ is_instruction_unstructured
Definition: ri.h:1475
@ is_instruction_test
Definition: ri.h:1470
@ is_instruction_forloop
Definition: ri.h:1477
#define instruction_tag(x)
Definition: ri.h:1511
#define statement_extensions(x)
Definition: ri.h:2464
#define instruction_forloop(x)
Definition: ri.h:1538
#define syntax_call(x)
Definition: ri.h:2736
#define statement_instruction(x)
Definition: ri.h:2458
#define forloop_condition(x)
Definition: ri.h:1368
#define statement_number(x)
Definition: ri.h:2452
#define expression_syntax(x)
Definition: ri.h:1247
#define forloop_body(x)
Definition: ri.h:1372