PIPS
fsm_generation.c
Go to the documentation of this file.
1 /*
2 
3  $Id: fsm_generation.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  *
29  * This phase is used for PHRASE project.
30  *
31  * NB: The PHRASE project is an attempt to automatically (or
32  * semi-automatically) transform high-level language for partial
33  * evaluation in reconfigurable logic (such as FPGAs or DataPaths).
34 
35 * This library provides phases allowing to build and modify "Finite State
36 * Machine"-like code portions which will be later synthetized in
37 * reconfigurable units.
38 
39 * This phase tries to generate finite state machine from arbitrary code by
40 * applying rules numeroting branches of the syntax tree and using it as
41 * state variable for the finite state machine.
42 
43 * This phase recursively transform each UNSTRUCTURED statement in a
44 * WHILE-LOOP statement controlled by a state variable, whose different
45 * values are associated to the different statements.
46 
47 * To add flexibility, the behavior of FSM_GENERATION is controlled by the
48 * property FSMIZE_WITH_GLOBAL_VARIABLE which control the fact that the
49 * same global variable (global to the current module) must be used for
50 * each FSMized statements.
51 
52  * alias fsm_generation 'FSM Generation'
53  *
54  * fsm_generation > MODULE.code
55  * > PROGRAM.entities
56  * < PROGRAM.entities
57  * < MODULE.code
58  *
59  */
60 
61 #include <stdio.h>
62 #include <ctype.h>
63 
64 #include "genC.h"
65 #include "linear.h"
66 #include "ri.h"
67 #include "effects.h"
68 
69 #include "resources.h"
70 
71 #include "misc.h"
72 #include "ri-util.h"
73 #include "effects-util.h"
74 #include "pipsdbm.h"
75 
76 #include "text-util.h"
77 
78 #include "dg.h"
79 
82 
83 #include "graph.h"
84 
85 #include "ray_dte.h"
86 #include "sommet.h"
87 #include "sg.h"
88 #include "polyedre.h"
89 #include "control.h"
90 #include "callgraph.h"
91 #include "properties.h"
92 
93 #include "phrase_tools.h"
94 #include "fsm_generation.h"
95 
96 //static graph dependence_graph;
97 
98 
99 /*********************************************************
100  * Phase main
101  *********************************************************/
102 
103 bool fsm_generation(const char* module_name)
104 {
105  entity state_variable = NULL;
106 
107  /* get the resources */
108  statement stat = (statement) db_get_memory_resource(DBR_CODE,
109  module_name,
110  true);
111 
112 
115  /* dependence_graph =
116  (graph) db_get_memory_resource(DBR_DG, module_name, true); */
117 
118  debug_on("FSM_GENERATION_DEBUG_LEVEL");
119 
120  /* Now do the job */
121 
122  /* If property FSMIZE_WITH_GLOBAL_VARIABLE is set to true, we
123  * declare here the state variable which will be used in the whole
124  * module */
125  if (get_bool_property("FSMIZE_WITH_GLOBAL_VARIABLE")) {
126  state_variable = create_state_variable(module_name, 0);
127  }
128 
129  stat = fsmize_statement(stat, state_variable, module_name);
130 
131  pips_assert("Statement is consistent after FSM_GENERATION",
132  statement_consistent_p(stat));
133 
134  /* Reorder the module, because new statements have been added */
135  module_reorder(stat);
136  DB_PUT_MEMORY_RESOURCE(DBR_CODE, module_name, stat);
137  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, module_name,
138  compute_callees(stat));
139 
140  /* update/release resources */
143 
144  debug_off();
145 
146  return true;
147 }
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
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
bool fsm_generation(const char *module_name)
fsm_generation.c
dg_vertex_label vertex_label
dg_arc_label arc_label
This phase is used for PHRASE project.
statement fsmize_statement(statement stat, entity state_variable, const char *module_name)
This function is recursively called during FSMization.
Definition: fsm_tools.c:536
entity create_state_variable(const char *module_name, int name_identifier)
This function creates (and add declaration) state variable.
Definition: fsm_tools.c:84
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 module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479