PIPS
scalopify.c
Go to the documentation of this file.
1 /* A simple phase that change wrap references to flow outside kernel for dataflow runtime manager
2 
3  clement.marguet@hpc-project.com
4 */
5 #ifdef HAVE_CONFIG_H
6 #include "pips_config.h"
7 #endif
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 "prettyprint.h"
16 #include "effects-util.h"
17 #include "misc.h"
18 #include "effects-generic.h"
19 #include "effects-simple.h"
20 #include "control.h"
21 #include "callgraph.h"
22 #include "pipsdbm.h"
23 #include "properties.h"
24 #include "accel-util.h"
25 #include "resources.h"
26 
27 
28 
29 static bool call_load_store_p(call c){
30  if(strstr(entity_name(call_function(c)),get_string_property("KERNEL_LOAD_STORE_LOAD_FUNCTION"))!=NULL
31  || strstr(entity_name(call_function(c)),get_string_property("KERNEL_LOAD_STORE_STORE_FUNCTION"))!=NULL){
32  return true;
33  }
34 
35  return false;
36 
37 }
38 
39 static bool find_call_to_wrap(call c,list *call_to_wrap){
40  *call_to_wrap = CONS(CALL,c,*call_to_wrap);
41  return false;
42 }
43 
44 
45 static bool find_entities_to_wrap(call c,set* entities_to_wrap){
46 
47  if(call_load_store_p(c)){
49 
51  call expcall = expression_call(exp);
52  if(call_intrinsic_p(expcall)){
53  c = expcall;
54  }
55  }
56 
58  pips_debug(1,"=========================\n");
59 
61 
62  if(!set_belong_p(*entities_to_wrap,e)) {
63  set_add_element(*entities_to_wrap,*entities_to_wrap,e);
64  }
65  }
66  return true;
67 }
68 
69 
70 static bool pointer_to_array_p(entity e){
71 
73 
74  if(ENDP(ls)) return true;
75 
76  return false;
77 }
78 
80 
81  list ls = variable_dimensions(type_variable(local_type));
82  size_t size = gen_length(ls);
84  basic b;
85 
86  for(unsigned int i = 0; i<size; i++){
87  b = make_basic_pointer(pointer_type);
88  pointer_type = make_type_variable(make_variable(b,NIL,NIL));
89  }
90 
91  return pointer_type;
92 }
93 
94 bool scalopify (char* module_name) {
95 
96  // Use this module name and this environment variable to set
98  "SCALOPIFY_DEBUG_LEVEL");
99  set entities_to_wrap=set_make(set_pointer);
100  list call_to_wrap=NIL;
101 
102  expression exp;
103  type t;
104 
105  entity get_call_entity = local_name_to_top_level_entity("P4A_scmp_flow");
106 
108 
109  gen_context_recurse(module_statement,&entities_to_wrap,
111 
112  gen_context_recurse(module_statement, &call_to_wrap,
114 
115  FOREACH(CALL, c , call_to_wrap){
116 
117  if(!call_load_store_p(c)){
118 
119  SET_FOREACH(entity, e, entities_to_wrap){
120 
121  /*Two cases: vector or scalar*/
122  if(entity_array_p(e)) {
123 
124  exp = MakeUnaryCall(get_call_entity, entity_to_expression(e));
125 
126  if(!pointer_to_array_p(e)){
128  }
129  else{
130  t= entity_type(e);
131  }
132 
134  }
135  else{
136 
139 
141  exp = MakeUnaryCall(get_call_entity, exp);
144  }
146  }
147  }
148  }
149 
150 
151 
152  gen_free_list(call_to_wrap);
153  set_free(entities_to_wrap);
154 
155  // We may have outline some code, so recompute the callees:
156  DB_PUT_MEMORY_RESOURCE(DBR_CALLEES, module_name,
158 
160  // Put back the new statement module
162 
163  return true;
164 }
cast make_cast(type a1, expression a2)
Definition: ri.c:311
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
type make_type_variable(variable _field_)
Definition: ri.c:2715
type copy_type(type p)
TYPE.
Definition: ri.c:2655
basic copy_basic(basic p)
BASIC.
Definition: ri.c:104
basic make_basic_pointer(type _field_)
Definition: ri.c:179
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
syntax make_syntax_cast(cast _field_)
Definition: ri.c:2503
static statement module_statement
Definition: alias_check.c:125
callees compute_callees(const statement stat)
Recompute the callees of a module statement.
Definition: callgraph.c:355
void set_cumulated_rw_effects(statement_effects)
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
char * get_string_property(const char *)
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
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
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 ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
#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 CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
void gen_free_list(list l)
free the spine of the list
Definition: list.c:327
#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 PIPS_PHASE_POSTLUDE(new_module_statement)
End a transformation phase by putting back into PIPS the (possibly) modified statement.
#define PIPS_PHASE_PRELUDE(module_name, debug_env_var)
Start a phase that use a module CODE.
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 pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
#define SET_FOREACH(type_name, the_item, the_set)
enumerate set elements in their internal order.
Definition: newgen_set.h:78
void set_free(set)
Definition: set.c:332
bool set_belong_p(const set, const void *)
Definition: set.c:194
@ set_pointer
Definition: newgen_set.h:44
set set_make(set_type)
Create an empty set of any type but hash_private.
Definition: set.c:102
set set_add_element(set, const set, const void *)
Definition: set.c:152
void print_expression(expression e)
no file descriptor is passed to make is easier to use in a debugging stage.
Definition: expression.c:58
#define DEREFERENCING_OPERATOR_NAME
Definition: ri-util-local.h:93
#define call_intrinsic_p(C)
#define ADDRESS_OF_OPERATOR_NAME
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
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
bool expression_call_p(expression e)
Definition: expression.c:415
expression entity_to_expression(entity e)
if v is a constant, returns a constant call.
Definition: expression.c:165
call expression_call(expression e)
Definition: expression.c:445
expression MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
Definition: expression.c:342
entity expression_variable(expression e)
Definition: expression.c:532
#define normalized_undefined
Definition: ri.h:1745
#define call_function(x)
Definition: ri.h:709
#define type_variable(x)
Definition: ri.h:2949
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define entity_name(x)
Definition: ri.h:2790
#define variable_dimensions(x)
Definition: ri.h:3122
#define CALL(x)
CALL.
Definition: ri.h:679
#define call_arguments(x)
Definition: ri.h:711
#define entity_type(x)
Definition: ri.h:2792
#define variable_basic(x)
Definition: ri.h:3120
static bool pointer_to_array_p(entity e)
Definition: scalopify.c:70
bool scalopify(char *module_name)
Warning! Do not modify this file that is automatically generated!
Definition: scalopify.c:94
static bool call_load_store_p(call c)
A simple phase that change wrap references to flow outside kernel for dataflow runtime manager.
Definition: scalopify.c:29
static bool find_entities_to_wrap(call c, set *entities_to_wrap)
Definition: scalopify.c:45
static type convert_local_to_pointer_array(type local_type)
Definition: scalopify.c:79
static bool find_call_to_wrap(call c, list *call_to_wrap)
Definition: scalopify.c:39
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
The structure used to build lists in NewGen.
Definition: newgen_list.h:41
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207