PIPS
scheduling.c
Go to the documentation of this file.
1 /*
2 
3  $Id: scheduling.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 #ifndef lint
29 char vcid_scheduling_scheduling[] = "$Id: scheduling.c 23065 2016-03-02 09:05:50Z coelho $";
30 #endif /* lint */
31 
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <setjmp.h>
36 
37 #include "genC.h"
38 #include "ri.h"
39 #include "constants.h"
40 #include "ri-util.h"
41 #include "misc.h"
42 
43 /* C3 includes */
44 #include "boolean.h"
45 #include "arithmetique.h"
46 #include "vecteur.h"
47 #include "contrainte.h"
48 #include "ray_dte.h"
49 #include "sommet.h"
50 #include "sg.h"
51 #include "sc.h"
52 #include "polyedre.h"
53 #include "union.h"
54 #include "matrix.h"
55 
56 
57 /* Pips includes */
58 
59 #include "complexity_ri.h"
60 #include "database.h"
61 #include "dg.h"
62 #include "parser_private.h"
63 #include "property.h"
64 #include "reduction.h"
65 #include "tiling.h"
66 
67 #include "text.h"
68 #include "text-util.h"
69 #include "graph.h"
70 #include "paf_ri.h"
71 #include "paf-util.h"
72 #include "pipsdbm.h"
73 #include "resources.h"
74 #include "scheduling.h"
75 #include "array_dfg.h"
76 
77 /* Local defines */
80 
81 #define BDT_EXT ".bdt_file"
82 
83 /*==================================================================*/
84 /* void print_bdt(module_name): print the bdt of module name
85  *
86  * AC 94/03/30
87  */
88 
89 bool print_bdt(const string module_name)
90 {
91  char *localfilename;
92  FILE *fd;
93  char *filename;
94  bdt the_bdt;
95 
96  debug_on( "PRINT_BDT_DEBUG_LEVEL" );
97 
98  if (get_debug_level() > 1)
99  user_log("\n\n *** PRINTING BDT for %s\n", module_name);
100 
101  the_bdt = (bdt) db_get_memory_resource(DBR_BDT, module_name, true);
102 
103  localfilename = strdup(concatenate(module_name, BDT_EXT, NULL));
105  "/", localfilename, NULL));
106 
107  fd = safe_fopen(filename, "w");
108  fprint_bdt(fd, the_bdt);
109  safe_fclose(fd, filename);
110 
111  DB_PUT_FILE_RESOURCE(DBR_BDT_FILE, strdup(module_name), localfilename);
112 
113  free(filename);
114 
115  if(get_debug_level() > 0)
116  fprintf(stderr, "\n\n *** PRINT_BDT DONE\n");
117 
118  debug_off();
119 
120  return(true);
121 }
122 
123 /*==================================================================*/
124 /* void scheduling(mod_name ): this is the main function to calculate
125  * the schedules of the node of a dfg. It first reverse the graph to
126  * have each node in function of its predecessors, then calculates
127  * the strongly connected components by the Trajan algorithm, then
128  * calls the function that really find the schedules.
129  *
130  * AC 93/10/30
131  */
132 
133 bool scheduling(const string mod_name)
134 {
135  graph dfg, rdfg;
136  sccs rgraph;
137  bdt bdt_list;
138  entity ent;
140  static_control stco;
142 
143  debug_on("SCHEDULING_DEBUG_LEVEL");
144  if (get_debug_level() > 0)
145  {
146  fprintf(stderr,"\n\nBegin scheduling\n");
147  fprintf(stderr,"DEBUT DU PROGRAMME\n");
148  fprintf(stderr,"==================\n\n");
149  }
150 
151  /* We get the required data: module entity, code, static_control, dataflow
152  * graph, timing function.
153  */
154  ent = local_name_to_top_level_entity(mod_name);
155 
157 
158  mod_stat = (statement)db_get_memory_resource(DBR_CODE, mod_name, true);
159  STS = (statement_mapping) db_get_memory_resource(DBR_STATIC_CONTROL,
160  mod_name, true);
162 
164 
165  if (stco == static_control_undefined)
166  pips_internal_error("This is an undefined static control !");
167 
168  if (!static_control_yes(stco))
169  pips_internal_error("This is not a static control program !");
170 
171  /* Read the DFG */
172  dfg = (graph)db_get_memory_resource(DBR_ADFG, mod_name, true);
173  dfg = adg_pure_dfg(dfg);
174  rdfg = dfg_reverse_graph(dfg);
175  if (get_debug_level() > 5) fprint_dfg(stderr, rdfg);
176  rgraph = dfg_find_sccs(rdfg);
177 
178  if (get_debug_level() > 0) fprint_sccs(stderr, rgraph);
179 
180  bdt_list = search_graph_bdt(rgraph);
181 
182  if (get_debug_level() > 0)
183  {
184  fprintf(stderr,"\n==============================================");
185  fprintf(stderr,"\nBase de temps trouvee :\n");
186  fprint_bdt_with_stat(stderr, bdt_list);
187  fprintf(stderr,"\nEnd of scheduling\n");
188  }
189 
190  DB_PUT_MEMORY_RESOURCE(DBR_BDT, strdup(mod_name), bdt_list);
191 
194 
195  debug_off();
196 
197  return(true);
198 }
void user_log(const char *format,...)
Definition: message.c:234
graph adg_pure_dfg(graph in_gr)
======================================================================
Definition: adg_graph.c:56
void fprint_dfg(FILE *fp, graph obj)
===========================================================================
static hash_table STS
The "STS" global variable is the hash table that maps the static_control on the statements.
Definition: adg_read_paf.c:155
graph dfg
Global variables
Definition: adg_read_paf.c:138
void fprint_bdt_with_stat(FILE *fp, bdt obj)
===========================================================================
Definition: bdt_utils.c:115
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
FILE * safe_fopen(const char *filename, const char *what)
Definition: file.c:67
int safe_fclose(FILE *stream, const char *filename)
Definition: file.c:77
void free(void *)
struct _newgen_struct_graph_ * graph
Definition: graph.h:31
void reset_current_module_entity(void)
Reset the current module entity.
Definition: static.c:97
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 DB_PUT_FILE_RESOURCE
Put a file resource into the current workspace database.
Definition: pipsdbm-local.h:85
static statement mod_stat
We want to keep track of the current statement inside the recurse.
Definition: impact_check.c:41
bdt search_graph_bdt(sccs rgraph)
=================================================================
Definition: makebdt.c:3001
#define debug_on(env)
Definition: misc-local.h:157
#define pips_internal_error
Definition: misc-local.h:149
#define debug_off()
Definition: misc-local.h:160
int get_debug_level(void)
GET_DEBUG_LEVEL returns the current debugging level.
Definition: debug.c:67
#define GET_STATEMENT_MAPPING(map, stat)
Definition: newgen-local.h:49
hash_table statement_mapping
these macros are obsolete! newgen functions (->) should be used instead
Definition: newgen-local.h:42
string concatenate(const char *,...)
Return the concatenation of the given strings.
Definition: string.c:183
void reset_current_stco_map(void)
========================================================================
Definition: utils.c:2423
void set_current_stco_map(statement_mapping)
========================================================================
Definition: utils.c:2408
void fprint_bdt(FILE *, bdt)
===========================================================================
Definition: print.c:352
struct _newgen_struct_static_control_ * static_control
Definition: paf_ri.h:184
struct _newgen_struct_bdt_ * bdt
Definition: paf_ri.h:72
#define static_control_yes(x)
Definition: paf_ri.h:753
#define static_control_undefined
Definition: paf_ri.h:727
string db_get_current_workspace_directory(void)
Definition: workspace.c:96
bdt the_bdt
The data flow graph.
Definition: prgm_mapping.c:100
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
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
char * strdup()
graph dfg_reverse_graph(graph g)
======================================================================
Definition: sccdfg.c:339
sccs dfg_find_sccs(graph g)
=================================================================
Definition: sccdfg.c:223
void fprint_sccs(FILE *fp, sccs obj)
===========================================================================
Definition: sccdfg.c:258
dfg_arc_label arc_label
lint
Definition: scheduling.c:78
#define BDT_EXT
Definition: scheduling.c:81
bool print_bdt(const string module_name)
=================================================================
Definition: scheduling.c:89
dfg_vertex_label vertex_label
Definition: scheduling.c:79
bool scheduling(const string mod_name)
=================================================================
Definition: scheduling.c:133
char vcid_scheduling_scheduling[]
Definition: scheduling.c:29