PIPS
starpu_pragma_generation.c
Go to the documentation of this file.
1 /*
2  Copyright 2012 MINES ParisTech
3  Copyright 2012 Silkan
4 
5  This file is part of PIPS.
6 
7  PIPS is free software: you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  any later version.
11 
12  PIPS is distributed in the hope that it will be useful, but WITHOUT ANY
13  WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  FITNESS FOR A PARTICULAR PURPOSE.
15 
16  See the GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with PIPS. If not, see <http://www.gnu.org/licenses/>.
20 
21  */
22 
23 /**
24  * @file starpu_pragma_generation.c
25  * Task generation
26  * @author Mehdi Amini <mehdi.amini@silkan.com>
27  */
28 
29 #ifdef HAVE_CONFIG_H
30  #include "pips_config.h"
31 #endif
32 #include "genC.h"
33 #include "linear.h"
34 #include "ri.h"
35 #include "ri-util.h"
36 #include "effects-util.h"
37 #include "gpu.h"
38 #include "accel-util.h"
39 #include "text.h"
40 #include "pipsdbm.h"
41 #include "pipsmake.h"
42 #include "resources.h"
43 #include "properties.h"
44 #include "misc.h"
45 #include "control.h"
46 #include "callgraph.h"
47 #include "effects.h"
48 #include "effects-simple.h"
49 #include "effects-generic.h"
50 #include "effects-convex.h"
51 #include "preprocessor.h"
52 #include "expressions.h"
53 #include "text-util.h"
54 #include "parser_private.h"
55 
56 static statement get_statement_pragma_register(entity e, bool address_of) {
58  string str;
59  if(address_of)
60  asprintf(&str,"starpu register &%s sizeof(%s)",entity_user_name(e),entity_user_name(e));
61  else
62  asprintf(&str,"starpu register %s",entity_user_name(e));
63 
65  return pragma;
66 }
67 
70  add_pragma_str_to_statement(pragma,"starpu initialize",true);
71  return pragma;
72 }
75  add_pragma_str_to_statement(pragma,"starpu shutdown",true);
76  return pragma;
77 }
78 
80  bool found;
82 };
83 
87  if(expression_to_entity(arg)==context->e) {
88  context->found=true;
89  }
90  }
91  return !context->found;
92 }
93 
94 static bool address_of_variable_is_taken(void *start, entity e) {
95  struct context_address_of_entity c = { false, e };
97  return c.found;
98 }
99 
101  if(reference_variable(r)==e) {
102  pips_assert("no index for scalar",ENDP(reference_indices(r)));
105  }
106 }
107 
109  list stmts = sequence_statements(seq);
110  list registered_entities = NIL;
111  list last_stmt = NIL;
112  for( ; !ENDP(stmts) ; POP(stmts) ) {
113  statement s = STATEMENT(CAR(stmts));
114  last_stmt = stmts;
115  if(declaration_statement_p(s)) {
117  if(entity_array_p(e)) {
119  CDR(stmts) = CONS(statement, pragma, CDR(stmts) );
120  POP(stmts);
121  registered_entities = CONS(entity,e,registered_entities);
122  } else if(address_of_variable_is_taken(seq,e)) {
123  type t = entity_type(e);
124  pips_assert("is a variable",type_variable_p(t));
125  variable v = type_variable(t);
126  pips_assert("scalar !", ENDP(variable_dimensions(v)));
129  NIL);
133  CDR(stmts) = CONS(statement, pragma, CDR(stmts) );
134  POP(stmts);
135 
136  registered_entities = CONS(entity,e,registered_entities);
137  }
138  }
139  }
140  }
141  FOREACH(entity,e,registered_entities) {
143  string str;
144  asprintf(&str,"starpu unregister %s",entity_user_name(e));
146  CDR(last_stmt) = CONS(statement, pragma, NIL );
147  POP(last_stmt);
148  }
149  return true;
150 }
151 
153  type array_t = ultimate_type(entity_type(e));
154  if(array_type_p(array_t)) {
155  variable v = type_variable(array_t);
157  if(unbounded_dimension_p(d)) {
158  return false;
159  }
160  }
161  return true;
162  }
163  return false;
164 }
165 
166 
168  if(return_statement_p(s)) {
169  add_pragma_str_to_statement(s,"starpu shutdown",true);
170  }
171  return true;
172 }
173 
175 
176  statement module_stat = (statement)db_get_memory_resource(DBR_CODE,
177  module_name,
178  true);
179  set_current_module_statement(module_stat);
180 
182 
183  debug_on("GENERATE_STARPU_PRAGMA_DEBUG_LEVEL");
184 
185 
186  /* regions */
187 // set_proper_rw_effects((statement_effects) db_get_memory_resource(DBR_REGIONS, module_name, true));
190  module_name,
191  true));
192 
193 
194  /* Initialize set for each statement */
196 
197 
198 
199  // If module is main, then register global variables
201  list regs = load_cumulated_rw_effects_list(module_stat);
202  ifdebug(2) {
203  pips_debug(2,"Regions for main module : ");
204  print_regions(regs);
205  }
206  // Do not use regions currently because of anywhere effects !
207  // FOREACH(effect, reg, regs) {
208  // entity e = region_entity(reg);
210  FOREACH(entity, e, entities ) {
211  pips_debug(6,"Considering entity %s\n",entity_name(e));
213  && array_bounded_p(e)) {
214  pips_debug(2,"Registering global array %s in main\n",entity_user_name(e));
216  insert_statement(module_stat,pragma,true);
217  }
218  }
219  insert_statement(module_stat,get_statement_pragma_init(),true);
220  insert_statement(module_stat,get_statement_pragma_shutdown(),false);
222  }
223 
224 
226  DB_PUT_MEMORY_RESOURCE(DBR_CODE,
227  module_name,
228  module_stat);
229 
230  // We may have outline some code, so recompute the callees:
231  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, module_name,
233 
234 
235  debug_off();
236 
241 
242  return true;
243 }
244 
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
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
void print_regions(list)
void reset_proper_rw_effects(void)
void set_proper_rw_effects(statement_effects)
void set_cumulated_rw_effects(statement_effects)
list load_cumulated_rw_effects_list(statement)
void reset_cumulated_rw_effects(void)
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
static char start[1024]
The name of the variable from which to start counting domain numbers.
Definition: genLisp.c:55
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
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
void gen_null(__attribute__((unused)) void *unused)
Ignore the argument.
Definition: genClib.c:2752
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define FOREACH(_fe_CASTER, _fe_item, _fe_list)
Apply/map an instruction block on all the elements of a list.
Definition: newgen_list.h:179
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
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
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
statement make_plain_continue_statement(void)
Make a simple continue statement to be used as a NOP or ";" in C.
Definition: statement.c:964
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
#define debug_on(env)
Definition: misc-local.h:157
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define asprintf
Definition: misc-local.h:225
#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
list gen_filter_tabulated(bool(*)(gen_chunk *), int)
returns the list of entities with this caracteristics.
Definition: tabulated.c:144
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define ENTITY_ADDRESS_OF_P(e)
const char * entity_user_name(entity e)
Since entity_local_name may contain PIPS special characters such as prefixes (label,...
Definition: entity.c:487
bool entity_array_p(entity e)
Is e a variable with an array type?
Definition: entity.c:754
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
bool entity_main_module_p(entity e)
Definition: entity.c:700
bool top_level_entity_p(entity e)
Check if the scope of entity e is global.
Definition: entity.c:1130
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
bool unbounded_dimension_p(dimension dim)
bool unbounded_dimension_p(dim) input : a dimension of an array entity.
Definition: expression.c:1130
entity expression_to_entity(expression e)
just returns the entity of an expression, or entity_undefined
Definition: expression.c:3140
void add_pragma_str_to_statement(statement st, const char *s, bool copy_flag)
Add a string as a pragma to a statement.
Definition: pragma.c:425
type ultimate_type(type)
Definition: type.c:3466
bool array_type_p(type)
Definition: type.c:2942
entity make_integer_constant_entity(_int)
entity make_integer_constant_entity(int c) make entity for integer constant c
Definition: variable.c:1345
struct _newgen_struct_pragma_ * pragma
Definition: ri.h:295
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define type_variable(x)
Definition: ri.h:2949
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
#define entity_name(x)
Definition: ri.h:2790
#define sequence_statements(x)
Definition: ri.h:2360
#define reference_indices(x)
Definition: ri.h:2328
#define variable_dimensions(x)
Definition: ri.h:3122
#define statement_declarations(x)
Definition: ri.h:2460
#define call_arguments(x)
Definition: ri.h:711
#define entity_type(x)
Definition: ri.h:2792
#define sequence_domain
newgen_reference_domain_defined
Definition: ri.h:346
#define type_variable_p(x)
Definition: ri.h:2947
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
#define ifdebug(n)
Definition: sg.c:47
bool add_shutdown_pragma_to_return(statement s)
bool generate_starpu_pragma(char *module_name)
static void scalar_to_array(reference r, entity e)
bool address_of_entity_p(call c, struct context_address_of_entity *context)
bool array_bounded_p(entity e)
static bool address_of_variable_is_taken(void *start, entity e)
static statement get_statement_pragma_init()
static statement get_statement_pragma_register(entity e, bool address_of)
static bool add_pragma_to_sequence(sequence seq)
static statement get_statement_pragma_shutdown()
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
Definition: delay.c:253