PIPS
starpu_pragma_generation.c File Reference

Task generation. More...

#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "ri-util.h"
#include "effects-util.h"
#include "gpu.h"
#include "accel-util.h"
#include "text.h"
#include "pipsdbm.h"
#include "pipsmake.h"
#include "resources.h"
#include "properties.h"
#include "misc.h"
#include "control.h"
#include "callgraph.h"
#include "effects.h"
#include "effects-simple.h"
#include "effects-generic.h"
#include "effects-convex.h"
#include "preprocessor.h"
#include "expressions.h"
#include "text-util.h"
#include "parser_private.h"
+ Include dependency graph for starpu_pragma_generation.c:

Go to the source code of this file.

Data Structures

struct  context_address_of_entity
 

Functions

static statement get_statement_pragma_register (entity e, bool address_of)
 
static statement get_statement_pragma_init ()
 
static statement get_statement_pragma_shutdown ()
 
bool address_of_entity_p (call c, struct context_address_of_entity *context)
 
static bool address_of_variable_is_taken (void *start, entity e)
 
static void scalar_to_array (reference r, entity e)
 
static bool add_pragma_to_sequence (sequence seq)
 
bool array_bounded_p (entity e)
 
bool add_shutdown_pragma_to_return (statement s)
 
bool generate_starpu_pragma (char *module_name)
 

Detailed Description

Task generation.

Author
Mehdi Amini mehdi.nosp@m..ami.nosp@m.ni@si.nosp@m.lkan.nosp@m..com

Definition in file starpu_pragma_generation.c.

Function Documentation

◆ add_pragma_to_sequence()

static bool add_pragma_to_sequence ( sequence  seq)
static

Definition at line 108 of file starpu_pragma_generation.c.

108  {
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 }
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
#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
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 asprintf
Definition: misc-local.h:225
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
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
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
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
entity make_integer_constant_entity(_int)
entity make_integer_constant_entity(int c) make entity for integer constant c
Definition: variable.c:1345
#define type_variable(x)
Definition: ri.h:2949
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338
#define sequence_statements(x)
Definition: ri.h:2360
#define variable_dimensions(x)
Definition: ri.h:3122
#define statement_declarations(x)
Definition: ri.h:2460
#define entity_type(x)
Definition: ri.h:2792
#define type_variable_p(x)
Definition: ri.h:2947
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
static void scalar_to_array(reference r, entity e)
static bool address_of_variable_is_taken(void *start, entity e)
static statement get_statement_pragma_register(entity e, bool address_of)
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References add_pragma_str_to_statement(), address_of_variable_is_taken(), asprintf, CAR, CDR, CONS, declaration_statement_p(), context_address_of_entity::e, ENDP, entity_array_p(), entity_to_expression(), entity_type, entity_user_name(), FOREACH, gen_context_recurse, gen_true2(), get_statement_pragma_register(), make_dimension(), make_integer_constant_entity(), make_plain_continue_statement(), NIL, pips_assert, POP, reference_domain, scalar_to_array(), sequence_statements, STATEMENT, statement_declarations, type_variable, type_variable_p, and variable_dimensions.

Referenced by generate_starpu_pragma().

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

◆ add_shutdown_pragma_to_return()

bool add_shutdown_pragma_to_return ( statement  s)

Definition at line 167 of file starpu_pragma_generation.c.

167  {
168  if(return_statement_p(s)) {
169  add_pragma_str_to_statement(s,"starpu shutdown",true);
170  }
171  return true;
172 }
bool return_statement_p(statement)
Test if a statement is a C or Fortran "return".
Definition: statement.c:172

References add_pragma_str_to_statement(), and return_statement_p().

Referenced by generate_starpu_pragma().

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

◆ address_of_entity_p()

bool address_of_entity_p ( call  c,
struct context_address_of_entity context 
)

Definition at line 84 of file starpu_pragma_generation.c.

84  {
87  if(expression_to_entity(arg)==context->e) {
88  context->found=true;
89  }
90  }
91  return !context->found;
92 }
#define ENTITY_ADDRESS_OF_P(e)
entity expression_to_entity(expression e)
just returns the entity of an expression, or entity_undefined
Definition: expression.c:3140
#define call_function(x)
Definition: ri.h:709
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define call_arguments(x)
Definition: ri.h:711
Definition: delay.c:253

References call_arguments, call_function, CAR, ENTITY_ADDRESS_OF_P, EXPRESSION, and expression_to_entity().

Referenced by address_of_variable_is_taken().

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

◆ address_of_variable_is_taken()

static bool address_of_variable_is_taken ( void *  start,
entity  e 
)
static

Definition at line 94 of file starpu_pragma_generation.c.

94  {
95  struct context_address_of_entity c = { false, e };
97  return c.found;
98 }
static char start[1024]
The name of the variable from which to start counting domain numbers.
Definition: genLisp.c:55
void gen_null2(__attribute__((unused)) void *u1, __attribute__((unused)) void *u2)
idem with 2 args, to please overpeaky compiler checks
Definition: genClib.c:2758
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
bool address_of_entity_p(call c, struct context_address_of_entity *context)

References address_of_entity_p(), call_domain, context_address_of_entity::e, context_address_of_entity::found, gen_context_recurse, gen_null2(), and start.

Referenced by add_pragma_to_sequence().

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

◆ array_bounded_p()

bool array_bounded_p ( entity  e)

Definition at line 152 of file starpu_pragma_generation.c.

152  {
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 }
bool unbounded_dimension_p(dimension dim)
bool unbounded_dimension_p(dim) input : a dimension of an array entity.
Definition: expression.c:1130
type ultimate_type(type)
Definition: type.c:3466
bool array_type_p(type)
Definition: type.c:2942

References array_type_p(), context_address_of_entity::e, entity_type, FOREACH, type_variable, ultimate_type(), unbounded_dimension_p(), and variable_dimensions.

Referenced by generate_starpu_pragma().

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

◆ generate_starpu_pragma()

bool generate_starpu_pragma ( char *  module_name)

regions

Initialize set for each statement

Definition at line 174 of file starpu_pragma_generation.c.

174  {
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));
212  if(top_level_entity_p(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 }
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_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
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_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
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
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
#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 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
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
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
#define entity_name(x)
Definition: ri.h:2790
#define sequence_domain
newgen_reference_domain_defined
Definition: ri.h:346
#define entity_domain
newgen_syntax_domain_defined
Definition: ri.h:410
#define ifdebug(n)
Definition: sg.c:47
bool add_shutdown_pragma_to_return(statement s)
bool array_bounded_p(entity e)
static statement get_statement_pragma_init()
static bool add_pragma_to_sequence(sequence seq)
static statement get_statement_pragma_shutdown()

References add_pragma_to_sequence(), add_shutdown_pragma_to_return(), array_bounded_p(), compute_callees(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, debug_off, debug_on, context_address_of_entity::e, entity_domain, entity_main_module_p(), entity_name, entity_user_name(), FOREACH, gen_filter_tabulated(), gen_null(), gen_recurse, gen_true(), get_current_module_entity(), get_current_module_statement(), get_statement_pragma_init(), get_statement_pragma_register(), get_statement_pragma_shutdown(), ifdebug, insert_statement(), load_cumulated_rw_effects_list(), local_name_to_top_level_entity(), module_name(), module_reorder(), pips_debug, print_regions(), reset_cumulated_rw_effects(), reset_current_module_entity(), reset_current_module_statement(), reset_proper_rw_effects(), sequence_domain, set_cumulated_rw_effects(), set_current_module_entity(), set_current_module_statement(), set_proper_rw_effects(), statement_domain, and top_level_entity_p().

+ Here is the call graph for this function:

◆ get_statement_pragma_init()

static statement get_statement_pragma_init ( )
static

Definition at line 68 of file starpu_pragma_generation.c.

68  {
70  add_pragma_str_to_statement(pragma,"starpu initialize",true);
71  return pragma;
72 }
struct _newgen_struct_pragma_ * pragma
Definition: ri.h:295

References add_pragma_str_to_statement(), and make_plain_continue_statement().

Referenced by generate_starpu_pragma().

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

◆ get_statement_pragma_register()

static statement get_statement_pragma_register ( entity  e,
bool  address_of 
)
static

Definition at line 56 of file starpu_pragma_generation.c.

56  {
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 }

References add_pragma_str_to_statement(), asprintf, entity_user_name(), and make_plain_continue_statement().

Referenced by add_pragma_to_sequence(), and generate_starpu_pragma().

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

◆ get_statement_pragma_shutdown()

static statement get_statement_pragma_shutdown ( )
static

Definition at line 73 of file starpu_pragma_generation.c.

73  {
75  add_pragma_str_to_statement(pragma,"starpu shutdown",true);
76  return pragma;
77 }

References add_pragma_str_to_statement(), and make_plain_continue_statement().

Referenced by generate_starpu_pragma().

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

◆ scalar_to_array()

static void scalar_to_array ( reference  r,
entity  e 
)
static

Definition at line 100 of file starpu_pragma_generation.c.

100  {
101  if(reference_variable(r)==e) {
102  pips_assert("no index for scalar",ENDP(reference_indices(r)));
105  }
106 }
#define reference_variable(x)
Definition: ri.h:2326
#define reference_indices(x)
Definition: ri.h:2328

References CONS, context_address_of_entity::e, ENDP, entity_to_expression(), make_integer_constant_entity(), NIL, pips_assert, reference_indices, and reference_variable.

Referenced by add_pragma_to_sequence().

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