PIPS
simd_memory_packing.c File Reference
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "resources.h"
#include "misc.h"
#include "ri-util.h"
#include "syntheses.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "pipsdbm.h"
#include "effects-generic.h"
#include "accel-util.h"
#include "sac.h"
#include "effects-convex.h"
#include "preprocessor.h"
+ Include dependency graph for simd_memory_packing.c:

Go to the source code of this file.

Functions

static bool simd_replace_parameters (hash_table array_to_vector)
 
static void simd_trace_call (statement s, hash_table array_to_vector)
 
string compilation_unit_of_module (const char *)
 The output is undefined if the module is referenced but not defined in the workspace, for instance because its code should be synthesized. More...
 
bool simd_memory_packing (char *mod_name)
 pack load / store from char or short array into load / store from int array a new module is generated More...
 

Function Documentation

◆ compilation_unit_of_module()

string compilation_unit_of_module ( const char *  module_name)

The output is undefined if the module is referenced but not defined in the workspace, for instance because its code should be synthesized.

Fabien Coelho suggests to build a default compilation unit where all synthesized module codes would be located.

Definition at line 350 of file module.c.

351 {
353  pips_assert("only for C modules\n", entity_undefined_p(e) || c_module_p(e));
354 
355  // Should only be called for C modules.
357 
358  // The guard may not be sufficient...
359  // and this may crash in db_get_memory_resource()
360  if(db_resource_p(DBR_USER_FILE, module_name)) {
361  string source_file_name =
362  db_get_memory_resource(DBR_USER_FILE, module_name, true);
363  string simpler_file_name = pips_basename(source_file_name, PP_C_ED);
364 
365  // It is not clear how robust it is going to be
366  // when file name conflicts occur.
368  simpler_file_name);
369  free(simpler_file_name);
370  }
371 
372  return compilation_unit_name;
373 }
bool db_resource_p(const char *rname, const char *oname)
true if exists and in loaded or stored state.
Definition: database.c:524
string compilation_unit_name
cproto-generated files
Definition: c_parser.c:49
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296
char * pips_basename(char *fullpath, char *suffix)
Definition: file.c:822
void free(void *)
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 asprintf
Definition: misc-local.h:225
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define FILE_SEP_STRING
Definition: naming-local.h:41
#define string_undefined
Definition: newgen_types.h:40
bool c_module_p(entity m)
Test if a module "m" is written in C.
Definition: entity.c:2777
entity module_name_to_entity(const char *mn)
This is an alias for local_name_to_top_level_entity.
Definition: entity.c:1479
#define entity_undefined_p(x)
Definition: ri.h:2762

Referenced by simd_memory_packing().

+ Here is the caller graph for this function:

◆ simd_memory_packing()

bool simd_memory_packing ( char *  mod_name)

pack load / store from char or short array into load / store from int array a new module is generated

simd_memory_packing.c

Parameters
mod_namename of the module to convert
Returns
false if something went wrong

get the resources

first step : create a vector <> array table

second step : look for any array `‘vectorized’' in the parameter and modify their type to fit the real array size

update/release resources

Parameters
mod_nameod_name

Definition at line 151 of file simd_memory_packing.c.

152 {
153  bool failed = false;
154  /* get the resources */
155  statement mod_stmt = (statement)db_get_memory_resource(DBR_CODE, mod_name, true);
158 
159  /* first step : create a vector <> array table */
160  hash_table array_to_vector = hash_table_make(hash_pointer,0);
161  gen_context_recurse(mod_stmt, array_to_vector, statement_domain, gen_true2, simd_trace_call);
162  if(( failed=hash_table_empty_p(array_to_vector)) )
163  {
164  pips_user_warning("I did not find any simd load / store operation :'(\n");
165  goto simd_memory_packing_end;
166  }
167 
168  /* second step : look for any array ``vectorized'' in the parameter
169  * and modify their type to fit the real array size
170  */
171  {
172  bool replaced_something = simd_replace_parameters(array_to_vector);
173  if( ( failed = !replaced_something ) )
174  {
175  pips_user_warning("I did not find any vectorized array in module parameters :'(\n");
176  goto simd_memory_packing_end;
177  }
179  add_new_module_from_text( mod_name,
180  t,
182  );
183  free_text(t);
184  /* update/release resources */
185  hash_table_free(array_to_vector);
186 
189  }
190 
191 simd_memory_packing_end:
192  return !failed;
193 }
void free_text(text p)
Definition: text.c:74
struct _newgen_struct_statement_ * statement
Definition: cloning.h:21
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285
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
const char * get_current_module_name(void)
Get the name of the current module.
Definition: static.c:121
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
bool gen_true2(__attribute__((unused)) gen_chunk *u1, __attribute__((unused)) void *u2)
Definition: genClib.c:2785
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
bool add_new_module_from_text(const char *module_name, text code_text, bool is_fortran, const char *compilation_unit_name)
Add the new resource files associated to a module with its more-or-less correct code.
Definition: initializer.c:431
#define pips_user_warning
Definition: misc-local.h:146
@ hash_pointer
Definition: newgen_hash.h:32
#define hash_table_empty_p(htp)
Definition: newgen_hash.h:58
text text_module(entity, statement)
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
#define statement_domain
newgen_sizeofexpression_domain_defined
Definition: ri.h:362
static bool simd_replace_parameters(hash_table array_to_vector)
static void simd_trace_call(statement s, hash_table array_to_vector)
string compilation_unit_of_module(const char *)
The output is undefined if the module is referenced but not defined in the workspace,...
Definition: module.c:350

References add_new_module_from_text(), compilation_unit_of_module(), db_get_memory_resource(), fortran_module_p(), free_text(), gen_context_recurse, gen_true2(), get_current_module_entity(), get_current_module_name(), get_current_module_statement(), hash_pointer, hash_table_empty_p, hash_table_free(), hash_table_make(), module_name_to_entity(), pips_user_warning, reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), simd_replace_parameters(), simd_trace_call(), statement_domain, and text_module().

+ Here is the call graph for this function:

◆ simd_replace_parameters()

static bool simd_replace_parameters ( hash_table  array_to_vector)
static

recover the parameter name

get associated entity

find associated vector if any

gather information concerning the vector

create a new basic : increased int size

substitute this basic to the old one

update dummy parameter

update declaration

Definition at line 50 of file simd_memory_packing.c.

51 {
52  bool failed = true;
55  {
56  dummy d = parameter_dummy(p);
57  if( dummy_identifier_p(d) )
58  {
59  /* recover the parameter name */
60  entity dummy_e = dummy_identifier(d);
61  const char* parameter_name = entity_local_name(dummy_e);
62  /* get associated entity */
64  /* find associated vector if any */
65  entity found = hash_get(array_to_vector,real_e);
66  if( ! entity_undefined_p(found) )
67  {
68  /* gather information concerning the vector */
71 
72  basic b = variable_basic(v);
73  pips_assert( "found vector is a vector of int", !basic_undefined_p(b) && basic_int_p(b) );
74 
75  /* create a new basic : increased int size*/
76  /* substitute this basic to the old one*/
77  variable new_var = copy_variable( type_variable(entity_type(real_e)) );
78 
79  basic new_var_basic = variable_basic(new_var);
80  while( basic_pointer_p(new_var_basic))
81  {
82  new_var_basic = variable_basic(type_variable( basic_pointer(new_var_basic)));
83  }
84  pips_assert("is a basic int",basic_int_p(new_var_basic));
85  basic_int(new_var_basic)=basic_int(b) * n ;
86 
87  /* update dummy parameter */
89  entity_type(dummy_e)= make_type_variable(new_var);
92 
93  /* update declaration */
94  FOREACH(ENTITY, decl_ent,
96  {
97  if( same_entity_lname_p(decl_ent, real_e))
98  {
100  entity_type(decl_ent)= make_type_variable(copy_variable(new_var));
101  }
102  }
103 
104  failed=false;
105  }
106  }
107  }
108  return !failed;
109 
110 }
type make_type_variable(variable _field_)
Definition: ri.c:2715
variable copy_variable(variable p)
VARIABLE.
Definition: ri.c:2859
void free_variable(variable p)
Definition: ri.c:2862
int dummy
A dummy file, to prevent empty libraries from breaking builds.
Definition: dummy.c:41
#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
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
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
bool same_entity_lname_p(entity, entity)
Definition: same_names.c:64
const char * entity_local_name(entity e)
entity_local_name modified so that it does not core when used in vect_fprint, since someone thought t...
Definition: entity.c:453
entity FindOrCreateEntity(const char *package, const char *local_name)
Problem: A functional global entity may be referenced without parenthesis or CALL keyword in a functi...
Definition: entity.c:1586
Value ValueNumberOfElements(list)
Definition: size.c:435
#define dummy_identifier(x)
Definition: ri.h:1033
#define basic_pointer(x)
Definition: ri.h:637
#define parameter_dummy(x)
Definition: ri.h:1823
#define parameter_type(x)
Definition: ri.h:1819
#define basic_int_p(x)
Definition: ri.h:614
#define basic_int(x)
Definition: ri.h:616
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define type_functional(x)
Definition: ri.h:2952
#define type_variable(x)
Definition: ri.h:2949
#define basic_pointer_p(x)
Definition: ri.h:635
#define code_declarations(x)
Definition: ri.h:784
#define basic_undefined_p(x)
Definition: ri.h:557
#define functional_parameters(x)
Definition: ri.h:1442
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define value_code(x)
Definition: ri.h:3067
#define variable_dimensions(x)
Definition: ri.h:3122
#define entity_type(x)
Definition: ri.h:2792
#define dummy_identifier_p(x)
Definition: ri.h:1031
#define variable_basic(x)
Definition: ri.h:3120
#define entity_initial(x)
Definition: ri.h:2796

References basic_int, basic_int_p, basic_pointer, basic_pointer_p, basic_undefined_p, code_declarations, copy_variable(), dummy_identifier, dummy_identifier_p, ENTITY, entity_initial, entity_local_name(), entity_type, entity_undefined_p, f(), FindOrCreateEntity(), FOREACH, free_variable(), functional_parameters, get_current_module_entity(), hash_get(), make_type_variable(), PARAMETER, parameter_dummy, parameter_type, pips_assert, same_entity_lname_p(), type_functional, type_variable, value_code, ValueNumberOfElements(), variable_basic, and variable_dimensions.

Referenced by simd_memory_packing().

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

◆ simd_trace_call()

static void simd_trace_call ( statement  s,
hash_table  array_to_vector 
)
static

we only look for load - save statement

and only of the form SIMD_(...)(vect,array)

Definition at line 113 of file simd_memory_packing.c.

114 {
115  /* we only look for load - save statement */
116  if( simd_dma_stat_p(s) )
117  {
119  int nb_args = gen_length(args);
120  /* and only of the form SIMD_(...)(vect,array) */
121  if( nb_args == 2 )
122  {
123  expression e = EXPRESSION(CAR(CDR(args)));
124  syntax s = expression_syntax(e);
125  bool through_address_of = false;
126  if( (through_address_of=(syntax_call_p(s) && ENTITY_ADDRESS_OF_P(call_function(syntax_call(s))))) )
128  pips_assert("parameter is a reference", syntax_reference_p(s));
130  pips_assert("parameter is a variable",type_variable_p(entity_type(reference_variable(r))));
132  pips_assert("parameter is an array", (through_address_of&&reference_indices(r)) || ! ENDP(variable_dimensions(v)));
133  hash_put(array_to_vector,
136  );
137  }
138  }
139 
140 }
bool simd_dma_stat_p(statement)
This function returns true if the statement is a simd loadsave statement.
Definition: delay.c:127
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
size_t gen_length(const list l)
Definition: list.c:150
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
call statement_call(statement)
Get the call of a statement.
Definition: statement.c:1406
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
#define ENTITY_ADDRESS_OF_P(e)
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
#define syntax_reference_p(x)
Definition: ri.h:2728
#define syntax_reference(x)
Definition: ri.h:2730
#define call_function(x)
Definition: ri.h:709
#define reference_variable(x)
Definition: ri.h:2326
#define syntax_call_p(x)
Definition: ri.h:2734
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define reference_indices(x)
Definition: ri.h:2328
#define syntax_call(x)
Definition: ri.h:2736
#define call_arguments(x)
Definition: ri.h:711
#define expression_syntax(x)
Definition: ri.h:1247
#define type_variable_p(x)
Definition: ri.h:2947
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References call_arguments, call_function, CAR, CDR, ENDP, ENTITY_ADDRESS_OF_P, entity_type, EXPRESSION, expression_reference(), expression_syntax, gen_length(), hash_put(), pips_assert, reference_indices, reference_variable, simd_dma_stat_p(), statement_call(), syntax_call, syntax_call_p, syntax_reference, syntax_reference_p, type_variable, type_variable_p, and variable_dimensions.

Referenced by simd_memory_packing().

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