PIPS
sesamify.c
Go to the documentation of this file.
1 /* A phase that transform simple tasks in SCMP code.
2  clement.marguet@hpc-project.com
3 */
4 #ifdef HAVE_CONFIG_H
5 #include "pips_config.h"
6 #endif
7 #include <ctype.h>
8 
9 
10 #include "genC.h"
11 #include "linear.h"
12 #include "ri.h"
13 #include "effects.h"
14 #include "ri-util.h"
15 #include "effects-util.h"
16 #include "text.h"
17 #include "pipsdbm.h"
18 #include "resources.h"
19 #include "misc.h"
20 #include "control.h"
21 #include "callgraph.h"
22 #include "effects-generic.h"
23 #include "effects-simple.h"
24 #include "effects-convex.h"
25 #include "text-util.h"
26 #include "parser_private.h"
27 #include "scalopes.h"
28 
29 /*Use to store action on entities*/
30 struct dma_action {
31  int read;
32  int write;
33 };
34 
37 /*Convert pointer to fixed size type to normal pointer*/
39  list ls = variable_dimensions(type_variable(local_type));
40  size_t size = gen_length(ls);
42  NIL,
43  NIL));
44  basic b;
45  for(unsigned int i = 0; i<size-1; i++){
46  b = make_basic_pointer(pointer_type);
47  pointer_type = make_type_variable(make_variable(b,NIL,NIL));
48  }
49  return pointer_type;
50 }
51 
52 bool sesamify (char* module_name) {
53  debug_on("SESAMIFY_DEBUG_LEVEL");
54 
55  list args,args2,args3, args4, args5, malloc_statements, map_statements, unmap_statements, wait_statements, send_statements, rw_effects, entity_declaration;
56  callees callees_list = (callees) db_get_memory_resource(DBR_CALLEES, module_name, true);
57  intptr_t id;
58  entity reserve_data = local_name_to_top_level_entity("sesam_reserve_data");
59  entity get_page_size = local_name_to_top_level_entity("sesam_get_page_size");
60  entity data_assignation = local_name_to_top_level_entity("sesam_data_assignation");
61  entity map_data = local_name_to_top_level_entity("sesam_map_data");
62  entity unmap_data = local_name_to_top_level_entity("sesam_unmap_data");
63  entity wait_dispo = local_name_to_top_level_entity("sesam_wait_dispo");
64  entity send_dispo = local_name_to_top_level_entity("sesam_send_dispo");
65  entity chown_data = local_name_to_top_level_entity("sesam_chown_data");
66  entity new, re;
67  struct dma_action * val;
68 
71 
72  intptr_t counter = 1;
73  int nb_task_total = gen_length(callees_callees(callees_list));
74  int num_task=1;
75 
76  FOREACH(STRING,callee_name,gen_nreverse(callees_callees(callees_list))) {
77 
78  pips_debug(1,"%s\n", callee_name);
79  //Change context
82  callee_name,
83  true));
85  callee_name,
86  true));
87 
88  //reset tables
90 
92  map_statements = NIL;
93  malloc_statements = NIL;
94  unmap_statements = NIL;
95  wait_statements = NIL;
96  send_statements = NIL;
97  entity_declaration = NIL;
98 
99  /*list effects in the task*/
100  FOREACH(EFFECT,e,rw_effects) {
101 
103 
104  val = (struct dma_action *) hash_get(entity_action, re);
105  /*check if the entities has already been processed with the same action to avoid doublons*/
106  if(val==HASH_UNDEFINED_VALUE|| (action_read_p(effect_action(e)) && val->read==0) || (action_write_p(effect_action(e)) && val->write==0)){
107 
108  /*if the entity is not stored yet*/
109  if(val==HASH_UNDEFINED_VALUE)
110  val = (struct dma_action *) malloc(sizeof(struct dma_action));
111  //flags entity effects
113  val->read=1;
114  else
115  val->write=1;
116 
117  //MEMORY ALLOCATION
119  //shared memory ID
120  id=counter-1;
121  hash_put(shared_mem, re, (void*)counter);
122  //compute table memory size
123  range the_range = make_range(int_to_expression(0),
127  int_to_expression(1)),
128  int_to_expression(1));
129 
130  expression memory_size = range_to_expression(the_range,range_to_distance);
132  memory_size,
133  call_to_expression(make_call(get_page_size,NIL)));
134 
136  size,
137  int_to_expression(1));
138  args = make_expression_list(size);
139 
140  args2 = CONS(EXPRESSION, int_to_expression(1), NIL);
141  args2 = CONS(EXPRESSION, size,args2);
142  args2 = CONS(EXPRESSION, int_to_expression(counter-1),args2);
143 
144  malloc_statements=CONS(STATEMENT,
146  malloc_statements);
147  malloc_statements=CONS(STATEMENT,
148  instruction_to_statement(make_instruction_call(make_call(data_assignation,args2))),
149  malloc_statements);
150  counter++;
151  }
152  else{
153  id = (intptr_t) hash_get(shared_mem, re)-1;
154  }
155 
156  //MAP_DATA + pointer creation +UNMAP + CHMOD
159  make_basic_pointer(t));
160  entity_declaration = CONS(ENTITY,new, entity_declaration);
162  expression map_data_exp = call_to_expression(make_call(map_data,args3));
163  expression new_exp = entity_to_expression(new);
165  args4 = CONS(EXPRESSION,map_data_exp, NIL);
166  args4 = CONS(EXPRESSION,new_exp,args4);
167 
168  map_statements=CONS(STATEMENT,
170  map_statements);
171  unmap_statements=CONS(STATEMENT,
173  unmap_statements);
174 
175  //change data owner
176  if(num_task < nb_task_total){
178  unmap_statements=CONS(STATEMENT,
180  unmap_statements);
181  }
182 
183  //SEND + WAIT dispo
184  print_effect(e);
187  pips_debug(1,"READ\n");
188  wait_statements=CONS(STATEMENT,
193  int_to_expression(0))))),
194  wait_statements);
195  send_statements=CONS(STATEMENT,
199  int_to_expression(1))))),
200  send_statements);
201  }
202  else{
204  pips_debug(1,"WRITE\n");
205  wait_statements=CONS(STATEMENT,
210  int_to_expression(0))))),
211  wait_statements);
212  send_statements=CONS(STATEMENT,
216  int_to_expression(0))))),
217  send_statements);
218  }
219  }
220  }
221 
222  //insert all statements
224  make_block_statement(gen_nreverse(wait_statements)),true);
226  make_block_statement(gen_nreverse(map_statements)),true);
228  make_block_statement(gen_nreverse(malloc_statements)),true);
230  make_block_statement(gen_nreverse(send_statements)),false);
232  make_block_statement(gen_nreverse(unmap_statements)),false);
233 
234  //add declaration
235  FOREACH(ENTITY,ent,entity_declaration){
237  }
238 
239  /* validate */
241  DB_PUT_MEMORY_RESOURCE(DBR_CODE, callee_name,
243  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, callee_name,
245 
246  /*postlude*/
250  num_task++;
251  }
252 
253  debug_off();
254  return true;
255 }
call make_call(entity a1, list a2)
Definition: ri.c:269
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
type make_type_variable(variable _field_)
Definition: ri.c:2715
syntax make_syntax_sizeofexpression(sizeofexpression _field_)
Definition: ri.c:2506
basic copy_basic(basic p)
BASIC.
Definition: ri.c:104
basic make_basic_pointer(type _field_)
Definition: ri.c:179
sizeofexpression make_sizeofexpression_type(type _field_)
Definition: ri.c:2177
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
instruction make_instruction_call(call _field_)
Definition: ri.c:1184
range make_range(expression a1, expression a2, expression a3)
Definition: ri.c:2041
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
void set_cumulated_rw_effects(statement_effects)
list load_cumulated_rw_effects_list(statement)
void reset_cumulated_rw_effects(void)
#define effect_any_reference(e)
FI: cannot be used as a left hand side.
#define effect_action(x)
Definition: effects.h:642
#define action_write_p(x)
Definition: effects.h:314
#define action_read_p(x)
Definition: effects.h:311
#define EFFECT(x)
EFFECT.
Definition: effects.h:608
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
#define STRING(x)
Definition: genC.h:87
void * malloc(YYSIZE_T)
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
statement instruction_to_statement(instruction)
Build a statement from a give instruction.
Definition: statement.c:597
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 replace_entity_by_expression(void *s, entity ent, expression exp)
replace all reference to entity ent by expression exp in s.
Definition: replace.c:220
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
size_t gen_length(const list l)
Definition: list.c:150
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#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
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
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void * hash_get(const hash_table htp, const void *key)
this function retrieves in the hash table pointed to by htp the couple whose key is equal to key.
Definition: hash.c:449
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
Definition: hash.c:364
void hash_table_clear(hash_table htp)
Clears all entries of a hash table HTP.
Definition: hash.c:305
#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
@ hash_pointer
Definition: newgen_hash.h:32
#define HASH_UNDEFINED_VALUE
value returned by hash_get() when the key is not found; could also be called HASH_KEY_NOT_FOUND,...
Definition: newgen_hash.h:56
#define HASH_DEFAULT_SIZE
Definition: newgen_hash.h:26
#define print_effect(e)
Definition: print.c:336
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
#define make_expression_list(stats...)
#define MINUS_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define DIVIDE_OPERATOR_NAME
@ range_to_distance
#define ASSIGN_OPERATOR_NAME
Definition: ri-util-local.h:95
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
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
void print_entities(list l)
Definition: entity.c:167
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
expression range_to_expression(range r, enum range_to_expression_mode mode)
computes the distance between the lower bound and the upper bound of the range
Definition: eval.c:963
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
expression MakeBinaryCall(entity f, expression eg, expression ed)
Creates a call expression to a function with 2 arguments.
Definition: expression.c:354
expression int_to_expression(_int i)
transform an int into an expression and generate the corresponding entity if necessary; it is not cle...
Definition: expression.c:1188
expression make_op_exp(char *op_name, expression exp1, expression exp2)
================================================================
Definition: expression.c:2012
expression call_to_expression(call c)
Build an expression that call a function or procedure.
Definition: expression.c:309
entity make_new_scalar_variable(entity, basic)
Definition: variable.c:741
void AddEntityToCurrentModule(entity)
Add a variable entity to the current module declarations.
Definition: variable.c:260
#define normalized_undefined
Definition: ri.h:1745
struct _newgen_struct_callees_ * callees
Definition: ri.h:55
#define callees_callees(x)
Definition: ri.h:675
#define reference_variable(x)
Definition: ri.h:2326
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define type_variable(x)
Definition: ri.h:2949
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define variable_basic(x)
Definition: ri.h:3120
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413
hash_table shared_mem
sesamify.c
Definition: sesamify.c:35
static type convert_local_to_pointer_array(type local_type)
onvert pointer to fixed size type to normal pointer
Definition: sesamify.c:38
hash_table entity_action
Definition: sesamify.c:36
bool sesamify(char *module_name)
Definition: sesamify.c:52
#define intptr_t
Definition: stdint.in.h:294
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
A phase that transform simple tasks in SCMP code.
Definition: sesamify.c:30
int read
Definition: sesamify.c:31
int write
Definition: sesamify.c:32