PIPS
array_to_pointer.c File Reference
#include <ctype.h>
#include "genC.h"
#include "ri-util.h"
#include "effects.h"
#include "pipsdbm.h"
#include "workspace-util.h"
#include "pipsmake.h"
#include "properties.h"
#include "callgraph.h"
#include "misc.h"
#include "control.h"
#include "expressions.h"
#include "preprocessor.h"
#include "accel-util.h"
+ Include dependency graph for array_to_pointer.c:

Go to the source code of this file.

Data Structures

struct  param_t
 

Functions

bool do_convert_this_array_to_pointer_p (entity e)
 array_to_pointer.c More...
 
size_t type_dereferencement_depth (type t)
 
static void do_linearize_array_reference (reference r)
 
static void do_linearize_array_subscript (_UNUSED_ subscript s)
 
static bool type_void_or_void_pointer_p (type t)
 
static bool do_linearize_type (type *t, bool *rr)
 
static void do_array_to_pointer_type_aux (type *t)
 
static bool do_array_to_pointer_type (type *t)
 returns true if a dereferencment has been supressed More...
 
static void do_linearize_array_manage_callers (entity m, set linearized_param, param_t *param)
 
static void do_linearize_array_cast (cast c)
 
static void do_linearize_array_walker (void *obj)
 
static void do_linearize_expression_is_pointer (expression exp, hash_table ht)
 
static void do_linearize_pointer_is_expression (expression exp, hash_table ht)
 
static hash_table init_expression_is_pointer (void *obj)
 
static void do_linearize_patch_expressions (void *obj, hash_table ht)
 
static void do_linearize_array_init (value v)
 
static void do_linearize_remove_dereferencment_walker (expression exp, entity e)
 
static void do_linearize_remove_dereferencment (statement s, entity e)
 
static void do_linearize_prepatch_type (type t)
 
static void do_linearize_prepatch_subscript (subscript s)
 subscripts of the form (*a)[n] are transformed into a[n] it is coherent with other transformations scattered here and there in this file :p More...
 
static void do_linearize_prepatch_subscripts (entity m, statement s)
 transform some subscripts for generic handling later More...
 
static void do_linearize_prepatch (entity m, _UNUSED_ statement s)
 
static void do_linearize_array (entity m, statement s, param_t *param)
 
static void do_array_to_pointer_walk_expression (expression exp)
 
static bool do_array_to_pointer_patch_call_expression (expression exp)
 fix some strange constructs introduced by previous processing More...
 
static void do_array_to_pointer_patch_call_expr_rwt (expression e)
 
static void do_array_to_pointer_walk_call_and_patch (call c)
 special ad-hoc handler for pointer to arrays More...
 
static void do_array_to_pointer_walk_cast (cast ct)
 
static void do_array_to_pointer_walker (void *obj)
 converts arrays to pointer More...
 
static list initialization_list_to_statements (entity e)
 create a list of statements from entity declarations More...
 
static void insert_statements_after_declarations (statement st, list stats)
 initialization statements are added right after declarations More...
 
static void do_array_to_pointer (entity m, statement s, _UNUSED_ param_t *p)
 transform each array type in module m with statement s More...
 
bool linearize_array_generic (const char *module_name)
 linearize accesses to an array, and use pointers if asked to More...
 
bool linearize_array (const char *module_name)
 linearize accesses to an array, and use pointers if asked to More...
 
bool linearize_array_fortran (const char *module_name)
 

Function Documentation

◆ do_array_to_pointer()

static void do_array_to_pointer ( entity  m,
statement  s,
_UNUSED_ param_t p 
)
static

transform each array type in module m with statement s

step1: the statements

step2: the declarations

step3: insert the initialization statement just after declarations

pips bonus step: the consistency

Definition at line 892 of file array_to_pointer.c.

892  {
893  /* step1: the statements */
898  }
899  }
900 
901  /* step2: the declarations */
902  list inits = NIL;
905  // must do this before the type conversion
909  }
910  /* step3: insert the initialization statement just after declarations */
912 
913  /* pips bonus step: the consistency */
915  dummy d = parameter_dummy(p);
916  if(dummy_identifier_p(d))
917  {
918  entity di = dummy_identifier(d);
922  }
923  }
924  pips_assert("everything went well",parameter_consistent_p(p));
925  }
926 
927 }
bool parameter_consistent_p(parameter p)
Definition: ri.c:1468
bool do_convert_this_array_to_pointer_p(entity e)
array_to_pointer.c
static void insert_statements_after_declarations(statement st, list stats)
initialization statements are added right after declarations
static list initialization_list_to_statements(entity e)
create a list of statements from entity declarations
static void do_array_to_pointer_walker(void *obj)
converts arrays to pointer
static void do_linearize_remove_dereferencment(statement s, entity e)
static bool do_array_to_pointer_type(type *t)
returns true if a dereferencment has been supressed
int dummy
A dummy file, to prevent empty libraries from breaking builds.
Definition: dummy.c:41
statement get_current_module_statement(void)
Get the current module statement.
Definition: static.c:208
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#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
list gen_append(list l1, const list l2)
Definition: list.c:471
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define entity_declarations(e)
MISC: newgen shorthands.
#define entity_variable_p(e)
An entity_variable_p(e) may hide a typedef and hence a functional type.
#define module_functional_parameters(func)
#define dummy_identifier(x)
Definition: ri.h:1033
#define parameter_dummy(x)
Definition: ri.h:1823
#define parameter_type(x)
Definition: ri.h:1819
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define PARAMETER(x)
PARAMETER.
Definition: ri.h:1788
#define entity_type(x)
Definition: ri.h:2792
#define dummy_identifier_p(x)
Definition: ri.h:1031
#define entity_initial(x)
Definition: ri.h:2796
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References do_array_to_pointer_type(), do_array_to_pointer_walker(), do_convert_this_array_to_pointer_p(), do_linearize_remove_dereferencment(), dummy_identifier, dummy_identifier_p, ENTITY, entity_declarations, entity_initial, entity_type, entity_variable_p, FOREACH, gen_append(), get_current_module_statement(), initialization_list_to_statements(), insert_statements_after_declarations(), module_functional_parameters, NIL, PARAMETER, parameter_consistent_p(), parameter_dummy, parameter_type, and pips_assert.

Referenced by linearize_array_generic().

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

◆ do_array_to_pointer_patch_call_expr_rwt()

static void do_array_to_pointer_patch_call_expr_rwt ( expression  e)
static

Definition at line 733 of file array_to_pointer.c.

734 {
736 }
static bool do_array_to_pointer_patch_call_expression(expression exp)
fix some strange constructs introduced by previous processing

References do_array_to_pointer_patch_call_expression().

Referenced by do_array_to_pointer_walker().

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

◆ do_array_to_pointer_patch_call_expression()

static bool do_array_to_pointer_patch_call_expression ( expression  exp)
static

fix some strange constructs introduced by previous processing

Definition at line 711 of file array_to_pointer.c.

711  {
712  if(expression_call_p(exp)) {
713  call c = expression_call(exp);
714  entity op = call_function(c);
715  if(ENTITY_ADDRESS_OF_P(op)) {
717  if(expression_call_p(arg)) {
718  call c2 = expression_call(arg);
723  }
724  else if( ENTITY_ADDRESS_OF_P(call_function(c2))) {
726  }
727  }
728  }
729  }
730  return true;
731 }
syntax copy_syntax(syntax p)
SYNTAX.
Definition: ri.c:2442
#define CAR(pcons)
Get the value of the first element of a list.
Definition: newgen_list.h:92
#define ENTITY_DEREFERENCING_P(e)
#define ENTITY_ADDRESS_OF_P(e)
bool expression_call_p(expression e)
Definition: expression.c:415
call expression_call(expression e)
Definition: expression.c:445
void update_expression_syntax(expression e, syntax s)
frees expression syntax of e and replace it by the new syntax s
Definition: expression.c:3564
#define call_function(x)
Definition: ri.h:709
#define EXPRESSION(x)
EXPRESSION.
Definition: ri.h:1217
#define syntax_undefined
Definition: ri.h:2676
#define call_arguments(x)
Definition: ri.h:711
#define expression_syntax(x)
Definition: ri.h:1247
#define exp
Avoid some warnings from "gcc -Wshadow".
Definition: vasnprintf.c:207

References call_arguments, call_function, CAR, copy_syntax(), ENTITY_ADDRESS_OF_P, ENTITY_DEREFERENCING_P, exp, EXPRESSION, expression_call(), expression_call_p(), expression_syntax, syntax_undefined, and update_expression_syntax().

Referenced by do_array_to_pointer_patch_call_expr_rwt(), and do_array_to_pointer_walker().

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

◆ do_array_to_pointer_type()

static bool do_array_to_pointer_type ( type t)
static

returns true if a dereferencment has been supressed

Definition at line 268 of file array_to_pointer.c.

268  {
269  bool remove = false;
270  if(!type_void_or_void_pointer_p(*t)) {
271  if(pointer_type_p(*t)){
272  variable vt = type_variable(*t);
273  basic bt = variable_basic(vt);
274  type t2 = basic_pointer(bt);
275  if(array_type_p(t2)) {
277  free_type(*t);
278  *t=t2;
279  remove=true;
280  }
281  }
283  }
284  return remove;
285 }
void free_type(type p)
Definition: ri.c:2658
static void do_array_to_pointer_type_aux(type *t)
static bool type_void_or_void_pointer_p(type t)
bool array_type_p(type)
Definition: type.c:2942
bool pointer_type_p(type)
Check for scalar pointers.
Definition: type.c:2993
#define basic_pointer(x)
Definition: ri.h:637
#define type_variable(x)
Definition: ri.h:2949
#define type_undefined
Definition: ri.h:2883
#define variable_basic(x)
Definition: ri.h:3120

References array_type_p(), basic_pointer, do_array_to_pointer_type_aux(), free_type(), pointer_type_p(), type_undefined, type_variable, type_void_or_void_pointer_p(), and variable_basic.

Referenced by do_array_to_pointer(), do_array_to_pointer_walk_cast(), and do_linearize_array().

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

◆ do_array_to_pointer_type_aux()

static void do_array_to_pointer_type_aux ( type t)
static

Definition at line 251 of file array_to_pointer.c.

251  {
252  variable v = type_variable(*t);
255  list dimensions = variable_dimensions(v);
257  FOREACH(DIMENSION,d,dimensions) {
260  make_basic_pointer(*t),
261  NIL,NIL
262  )
263  );
264  }
265 }
type make_type_variable(variable _field_)
Definition: ri.c:2715
basic make_basic_pointer(type _field_)
Definition: ri.c:179
variable make_variable(basic a1, list a2, list a3)
Definition: ri.c:2895
#define basic_pointer_p(x)
Definition: ri.h:635
#define variable_dimensions(x)
Definition: ri.h:3122

References basic_pointer, basic_pointer_p, DIMENSION, FOREACH, make_basic_pointer(), make_type_variable(), make_variable(), NIL, type_variable, variable_basic, and variable_dimensions.

Referenced by do_array_to_pointer_type().

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

◆ do_array_to_pointer_walk_call_and_patch()

static void do_array_to_pointer_walk_call_and_patch ( call  c)
static

special ad-hoc handler for pointer to arrays

pointer to an array ...

Definition at line 739 of file array_to_pointer.c.

739  {
740  entity op = call_function(c);
741  if(ENTITY_DEREFERENCING_P(op)) {
745  entity e = reference_variable(r);
746  /* pointer to an array ... */
747  if(entity_pointer_p(e)) {
752  make_call(
755  )
756  )
757  );
758  }
759  }
760  }
761  }
762 }
call make_call(entity a1, list a2)
Definition: ri.c:269
syntax make_syntax_call(call _field_)
Definition: ri.c:2500
expression copy_expression(expression p)
EXPRESSION.
Definition: ri.c:850
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
#define ADDRESS_OF_OPERATOR_NAME
bool entity_pointer_p(entity e)
Definition: entity.c:745
entity entity_intrinsic(const char *name)
FI: I do not understand this function name (see next one!).
Definition: entity.c:1292
bool expression_reference_p(expression e)
Test if an expression is a reference.
Definition: expression.c:528
reference expression_reference(expression e)
Short cut, meaningful only if expression_reference_p(e) holds.
Definition: expression.c:1832
type ultimate_type(type)
Definition: type.c:3466
type pointed_type(type)
returns the type pointed by the input type if it is a pointer or an array of pointers
Definition: type.c:3035
#define reference_variable(x)
Definition: ri.h:2326

References ADDRESS_OF_OPERATOR_NAME, array_type_p(), basic_pointer, call_arguments, call_function, CAR, CONS, copy_expression(), ENTITY_DEREFERENCING_P, entity_intrinsic(), entity_pointer_p(), entity_type, exp, EXPRESSION, expression_reference(), expression_reference_p(), make_call(), make_syntax_call(), NIL, pointed_type(), reference_variable, type_variable, ultimate_type(), update_expression_syntax(), and variable_basic.

Referenced by do_array_to_pointer_walker().

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

◆ do_array_to_pointer_walk_cast()

static void do_array_to_pointer_walk_cast ( cast  ct)
static

Definition at line 764 of file array_to_pointer.c.

764  {
766 }
#define cast_type(x)
Definition: ri.h:745

References cast_type, and do_array_to_pointer_type().

Referenced by do_array_to_pointer_walker().

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

◆ do_array_to_pointer_walk_expression()

static void do_array_to_pointer_walk_expression ( expression  exp)
static

Definition at line 677 of file array_to_pointer.c.

677  {
683  if(!ENDP(indices)) {
684  expression new_expression = expression_undefined;
687  FOREACH(EXPRESSION,index,indices) {
688  new_expression=MakeUnaryCall(
692  expression_undefined_p(new_expression)?
694  new_expression,
695  index
696  )
697  );
698  }
699  syntax syn = expression_syntax(new_expression);
700  expression_syntax(new_expression)=syntax_undefined;
702  }
703  }
704  }
706  pips_user_warning("subscript are not well handled (yet)!\n");
707  }
708 }
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
list gen_nreverse(list cp)
reverse a list in place
Definition: list.c:304
static list indices
Definition: icm.c:204
#define pips_user_warning
Definition: misc-local.h:146
#define DEREFERENCING_OPERATOR_NAME
Definition: ri-util-local.h:93
#define PLUS_C_OPERATOR_NAME
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 MakeUnaryCall(entity f, expression a)
Creates a call expression to a function with one argument.
Definition: expression.c:342
#define expression_undefined
Definition: ri.h:1223
#define reference_indices(x)
Definition: ri.h:2328
#define expression_undefined_p(x)
Definition: ri.h:1224
#define syntax_subscript_p(x)
Definition: ri.h:2743

References DEREFERENCING_OPERATOR_NAME, do_convert_this_array_to_pointer_p(), ENDP, entity_intrinsic(), entity_to_expression(), exp, EXPRESSION, expression_reference(), expression_reference_p(), expression_syntax, expression_undefined, expression_undefined_p, FOREACH, gen_nreverse(), indices, MakeBinaryCall(), MakeUnaryCall(), NIL, pips_user_warning, PLUS_C_OPERATOR_NAME, reference_indices, reference_variable, syntax_subscript_p, syntax_undefined, and update_expression_syntax().

Referenced by do_array_to_pointer_walker().

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

◆ do_array_to_pointer_walker()

static void do_array_to_pointer_walker ( void *  obj)
static

converts arrays to pointer

Definition at line 769 of file array_to_pointer.c.

769  {
770  gen_multi_recurse(obj,
774  NULL);
776 
777 }
static void do_array_to_pointer_patch_call_expr_rwt(expression e)
static void do_array_to_pointer_walk_expression(expression exp)
static void do_array_to_pointer_walk_cast(cast ct)
static void do_array_to_pointer_walk_call_and_patch(call c)
special ad-hoc handler for pointer to arrays
#define gen_recurse(start, domain_number, flt, rwt)
Definition: genC.h:283
void gen_multi_recurse(void *o,...)
Multi recursion visitor function.
Definition: genClib.c:3428
bool gen_true(__attribute__((unused)) gen_chunk *unused)
Return true and ignore the argument.
Definition: genClib.c:2780
#define expression_domain
newgen_execution_domain_defined
Definition: ri.h:154
#define cast_domain
newgen_call_domain_defined
Definition: ri.h:66
#define call_domain
newgen_callees_domain_defined
Definition: ri.h:58

References call_domain, cast_domain, do_array_to_pointer_patch_call_expr_rwt(), do_array_to_pointer_patch_call_expression(), do_array_to_pointer_walk_call_and_patch(), do_array_to_pointer_walk_cast(), do_array_to_pointer_walk_expression(), expression_domain, gen_multi_recurse(), gen_recurse, and gen_true().

Referenced by do_array_to_pointer().

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

◆ do_convert_this_array_to_pointer_p()

bool do_convert_this_array_to_pointer_p ( entity  e)

array_to_pointer.c

Definition at line 68 of file array_to_pointer.c.

68  {
69  if(get_bool_property("LINEARIZE_ARRAY_USE_POINTERS")) {
70  if(get_bool_property("LINEARIZE_ARRAY_SKIP_STATIC_LENGTH_ARRAYS") && !entity_variable_length_array_p(e))
71  return false;
72  value v =entity_initial(e);
74  return true;
75  if( get_bool_property("LINEARIZE_ARRAY_SKIP_LOCAL_ARRAYS") && !entity_formal_p(e) )
76  return false;
77  return true;
78  }
79  return false;
80 }
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
bool entity_formal_p(entity p)
is p a formal parameter?
Definition: entity.c:1935
bool entity_variable_length_array_p(entity e)
Definition: entity.c:798
bool expression_brace_p(expression e)
predicates and short cut accessors on expressions
Definition: expression.c:407
#define value_undefined_p(x)
Definition: ri.h:3017
#define value_expression_p(x)
Definition: ri.h:3080
#define value_expression(x)
Definition: ri.h:3082

References entity_formal_p(), entity_initial, entity_variable_length_array_p(), expression_brace_p(), get_bool_property(), value_expression, value_expression_p, and value_undefined_p.

Referenced by do_array_to_pointer(), do_array_to_pointer_walk_expression(), and do_linearize_array().

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

◆ do_linearize_array()

static void do_linearize_array ( entity  m,
statement  s,
param_t param 
)
static

step 0: remind all expressions types

step 0.25: hack some subscripts typically found in pips inputs

step 0.5: transform int (*a) [3] into int a[*][3]

step1: the statements

step2: the declarations

pips bonus step: the consistency

step3: change the caller to reflect the new types accordingly

final step: fix expressions if we have disturbed typing in the process

Definition at line 608 of file array_to_pointer.c.

608  {
609  /* step 0: remind all expressions types */
611 
612  /* step 0.25: hack some subscripts typically found in pips inputs */
614 
615  /* step 0.5: transform int (*a) [3] into int a[*][3] */
617 
618  /* step1: the statements */
621  if(entity_variable_p(e))
623 
624  /* step2: the declarations */
626  if(entity_variable_p(e)) {
627  bool rr;
628  pips_debug (5, "linearizing entity %s\n", entity_name (e));
632  }
633  }
634 
635  /* pips bonus step: the consistency */
636  set linearized_param = set_make(set_pointer);
638  dummy d = parameter_dummy(p);
639  pips_debug (5, "linearizing parameters\n");
640  if(dummy_identifier_p(d))
641  {
642  entity di = dummy_identifier(d);
643  do_linearize_type(&entity_type(di),NULL);
644  pips_debug (5, "linearizing dummy parameter %s\n", entity_name (di));
645  }
646 
647  if(do_linearize_type(&parameter_type(p),NULL))
648  set_add_element(linearized_param,linearized_param,p);
649 
650  // Convert to pointer if requested
651  if(param->use_pointers_p) {
652  if(dummy_identifier_p(d)) {
653  entity di = dummy_identifier(d);
657  }
658  }
659  }
660  pips_assert("everything went well",parameter_consistent_p(p));
661  }
662 
663  /* step3: change the caller to reflect the new types accordingly */
664  if (param->modify_call_site_p) {
665  do_linearize_array_manage_callers(m,linearized_param,param);
666  }
667  set_free(linearized_param);
668 
669  /* final step: fix expressions if we have disturbed typing in the process */
671  hash_table_free(e2t);
673  pips_assert("everything went well",parameter_consistent_p(p));
674  }
675 }
static void do_linearize_patch_expressions(void *obj, hash_table ht)
static bool do_linearize_type(type *t, bool *rr)
static hash_table init_expression_is_pointer(void *obj)
static void do_linearize_array_walker(void *obj)
static void do_linearize_array_init(value v)
static void do_linearize_array_manage_callers(entity m, set linearized_param, param_t *param)
static void do_linearize_prepatch(entity m, _UNUSED_ statement s)
static void do_linearize_prepatch_subscripts(entity m, statement s)
transform some subscripts for generic handling later
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
void hash_table_free(hash_table htp)
this function deletes a hash table that is no longer useful.
Definition: hash.c:327
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
Definition: misc-local.h:145
void set_free(set)
Definition: set.c:332
@ 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
#define entity_name(x)
Definition: ri.h:2790
FI: I do not understand why the type is duplicated at the set level.
Definition: set.c:59
Definition: replace.c:135

References do_array_to_pointer_type(), do_convert_this_array_to_pointer_p(), do_linearize_array_init(), do_linearize_array_manage_callers(), do_linearize_array_walker(), do_linearize_patch_expressions(), do_linearize_prepatch(), do_linearize_prepatch_subscripts(), do_linearize_remove_dereferencment(), do_linearize_type(), dummy_identifier, dummy_identifier_p, ENTITY, entity_declarations, entity_initial, entity_name, entity_type, entity_variable_p, FOREACH, get_current_module_entity(), hash_table_free(), init_expression_is_pointer(), module_functional_parameters, PARAMETER, parameter_consistent_p(), parameter_dummy, parameter_type, pips_assert, pips_debug, set_add_element(), set_free(), set_make(), and set_pointer.

Referenced by linearize_array_generic().

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

◆ do_linearize_array_cast()

static void do_linearize_array_cast ( cast  c)
static

Definition at line 397 of file array_to_pointer.c.

397  {
398  do_linearize_type(&cast_type(c),NULL);
399 }

References cast_type, and do_linearize_type().

Referenced by do_linearize_array_walker().

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

◆ do_linearize_array_init()

static void do_linearize_array_init ( value  v)
static

Definition at line 455 of file array_to_pointer.c.

455  {
456  if(value_expression_p(v)) {
458  if(expression_call_p(exp)) {
459  call c = expression_call(exp);
460  entity op = call_function(c);
461  if(ENTITY_BRACE_INTRINSIC_P(op)) {
462  list inits = NIL;
463  for(list iter = call_arguments(c); !ENDP(iter) ; POP(iter)) {
464  expression *eiter = (expression*)REFCAR(iter);
465  if(expression_call_p(*eiter)) {
466  call c2 = expression_call(*eiter);
468  iter=gen_append(iter,call_arguments(c2));
469  call_arguments(c2)=NIL;
470  continue;
471  }
472  }
473  inits=CONS(EXPRESSION,copy_expression(*eiter),inits);
474  }
475  inits=gen_nreverse(inits);
477  call_arguments(c)=inits;
478  }
479  }
480  }
481 }
void gen_full_free_list(list l)
Definition: genClib.c:1023
#define POP(l)
Modify a list pointer to point on the next element of the list.
Definition: newgen_list.h:59
#define REFCAR(pc)
Get the adress of the first element of a list.
Definition: newgen_list.h:119
#define ENTITY_BRACE_INTRINSIC_P(e)
C initialization expression.

References call_arguments, call_function, CONS, copy_expression(), ENDP, ENTITY_BRACE_INTRINSIC_P, exp, EXPRESSION, expression_call(), expression_call_p(), gen_append(), gen_full_free_list(), gen_nreverse(), NIL, POP, REFCAR, value_expression, and value_expression_p.

Referenced by do_linearize_array().

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

◆ do_linearize_array_manage_callers()

static void do_linearize_array_manage_callers ( entity  m,
set  linearized_param,
param_t param 
)
static

we may have to change the call sites, prepare iterators over call sites arguments here

Definition at line 288 of file array_to_pointer.c.

288  {
289  list callers = callees_callees((callees)db_get_memory_resource(DBR_CALLERS,module_local_name(m), true));
290  list callers_statement = callers_to_statements(callers);
291  list call_sites = callers_to_call_sites(callers_statement,m);
292 
293  /* we may have to change the call sites, prepare iterators over call sites arguments here */
294  FOREACH(CALL,c,call_sites) {
295  list args = call_arguments(c);
297  if(set_belong_p(linearized_param,p)) {
298  expression * arg = (expression*)REFCAR(args);
299  type type_at_call_site = expression_to_type(*arg);
300  type type_in_func_prototype = parameter_type(p);
301  if(!pointer_type_p(type_at_call_site)) {
302  /*
303  type t = make_type_variable(
304  make_variable(
305  make_basic_pointer(
306  copy_type(parameter_type(p))
307  ),
308  NIL,NIL)
309  );
310  */
311  if(array_type_p(type_at_call_site)) {
312  if(param->cast_at_call_site_p && !fixed_length_array_type_p(type_in_func_prototype)) {
313  *arg =
316  make_cast(
317  copy_type(type_in_func_prototype),
318  *arg
319  )
320  ),
322  );
323  if(!param->use_pointers_p) {
324  *arg=MakeUnaryCall(
326  *arg);
327  }
328  }
329  }
330  else {
331  if(!fixed_length_array_type_p(type_in_func_prototype))
332  *arg =
335  make_cast(
336  copy_type(type_in_func_prototype),
339  *arg
340  )
341  )
342  ),
344  );
345  if(!param->use_pointers_p) {
346  *arg=MakeUnaryCall(
348  *arg);
349  }
350  }
351  }
352  else if(!param->use_pointers_p && !type_equal_p(type_at_call_site,type_in_func_prototype)) {
353  *arg =
356  }
357 
358 #if 0 // ***SG: optional, and I don't want to valdiate it
359  /* handle call sites in the form *pointer_to_array */
360  if( param->cast_at_call_site_p && expression_call_p(*arg) && ENTITY_DEREFERENCING_P(call_function(expression_call(*arg)))) {
361  expression *dereferenced = (expression*)REFCAR(call_arguments(expression_call(*arg)));
362  type dereferenced_type = expression_to_type(*dereferenced);
363  if ( pointer_type_p(dereferenced_type)) {
364  type dereferenced_pointed_type = basic_pointer(variable_basic(type_variable(dereferenced_type)));
365  if(array_type_p(dereferenced_pointed_type)) {
366  *dereferenced =
369  make_cast(
372  make_basic_pointer(copy_type(type_in_func_prototype)),
373  NIL,
374  NIL
375  )
376  ),
377  *dereferenced
378  )
379  ),
381  );
382 
383  }
384  }
385 
386  }
387 #endif
388  free_type(type_at_call_site);
389  }
390  POP(args);
391  }
392  }
393  for(list citer=callers,siter=callers_statement;!ENDP(citer);POP(citer),POP(siter))
394  DB_PUT_MEMORY_RESOURCE(DBR_CODE, STRING(CAR(citer)),STATEMENT(CAR(siter)));
395 
396 }
cast make_cast(type a1, expression a2)
Definition: ri.c:311
expression make_expression(syntax a1, normalized a2)
Definition: ri.c:886
type copy_type(type p)
TYPE.
Definition: ri.c:2655
syntax make_syntax_cast(cast _field_)
Definition: ri.c:2503
list callers_to_call_sites(list callers_statement, entity called_module)
given a list callers_statement of module statements returns a list of calls to module called_module
Definition: callgraph.c:149
list callers_to_statements(list callers)
given a list callers of module name calling module called module return a list of their body
Definition: callgraph.c:163
#define STRING(x)
Definition: genC.h:87
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 set_belong_p(const set, const void *)
Definition: set.c:194
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582
bool fixed_length_array_type_p(type)
Definition: type.c:2987
type expression_to_type(expression)
For an array declared as int a[10][20], the type returned for a[i] is int [20].
Definition: type.c:2486
bool type_equal_p(type, type)
Definition: type.c:547
#define normalized_undefined
Definition: ri.h:1745
#define callees_callees(x)
Definition: ri.h:675
#define CALL(x)
CALL.
Definition: ri.h:679
#define STATEMENT(x)
STATEMENT.
Definition: ri.h:2413

References ADDRESS_OF_OPERATOR_NAME, array_type_p(), basic_pointer, CALL, call_arguments, call_function, callees_callees, callers_to_call_sites(), callers_to_statements(), CAR, copy_type(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, DEREFERENCING_OPERATOR_NAME, ENDP, ENTITY_DEREFERENCING_P, entity_intrinsic(), expression_call(), expression_call_p(), expression_to_type(), fixed_length_array_type_p(), FOREACH, free_type(), make_basic_pointer(), make_cast(), make_expression(), make_syntax_cast(), make_type_variable(), make_variable(), MakeUnaryCall(), module_functional_parameters, module_local_name(), NIL, normalized_undefined, PARAMETER, parameter_type, pointer_type_p(), POP, REFCAR, set_belong_p(), STATEMENT, STRING, type_equal_p(), type_variable, and variable_basic.

Referenced by do_linearize_array().

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

◆ do_linearize_array_reference()

static void do_linearize_array_reference ( reference  r)
static

must first check the dimensions , then the pointer type

one dimension variable, nothing to do

merge all

better start with this than nothing

it's a pointer: pop type

Definition at line 107 of file array_to_pointer.c.

107  {
109  if(entity_variable_p(e)) {
111  list to_be_free = indices;
112  bool fortran_p = fortran_module_p(get_current_module_entity());
113  if (fortran_p) {
115  }
116  if(!ENDP(indices)) {
117  type et = ultimate_type(entity_type(e));
118  list new_indices = NIL;
119  while(!ENDP(indices)) {
120  expression new_index = expression_undefined;
121  variable v = type_variable(et);
122  /* must first check the dimensions , then the pointer type */
123  list vdims = variable_dimensions(v);
124  /* one dimension variable, nothing to do */
125  if(ENDP(vdims)||ENDP(CDR(vdims))) {
126  }
127  else {
128  /* merge all */
129  new_index=int_to_expression(0);/* better start with this than nothing */
130  while(!ENDP(vdims) && !ENDP(indices) ) {
132  if (fortran_p) {
133  // in fortran we have to take care of the lower bound that can
134  // be set to any value
135  // First compute the lower bound
137  if (ENDP(CDR(indices))) {
138  // for the last dimension (the most contiguous in the memory)
139  // substract the lower bound minus 1 since the first index is
140  // one
141  lower = add_integer_to_expression (lower, -1);
142  curr_exp = make_op_exp (MINUS_OPERATOR_NAME, curr_exp, lower);
143  }
144  else {
145  // substract the lower bound to the index to compute the
146  // dimension stride in the linearized array
147  curr_exp = make_op_exp (MINUS_OPERATOR_NAME, curr_exp, lower);
148  }
149  }
152  curr_exp,
153  SizeOfDimensions(CDR(vdims))
154  ),
155  new_index
156  );
157  POP(vdims);
158  POP(indices);
159  }
160  }
161  /* it's a pointer: pop type */
163  et = basic_pointer(variable_basic(v));
164  }
165  if(expression_undefined_p(new_index)) {
166  new_index =copy_expression(EXPRESSION(CAR(indices)));
167  POP(indices);
168  }
169  new_indices=CONS(EXPRESSION,new_index,new_indices);
170  }
171  reference_indices(r)=gen_nreverse(new_indices);
172  gen_full_free_list (to_be_free);
173  }
174  }
175 }
#define CDR(pcons)
Get the list less its first element.
Definition: newgen_list.h:111
#define MINUS_OPERATOR_NAME
#define PLUS_OPERATOR_NAME
#define MULTIPLY_OPERATOR_NAME
bool fortran_module_p(entity m)
Test if a module is in Fortran.
Definition: entity.c:2799
expression add_integer_to_expression(expression exp, int val)
Definition: expression.c:2132
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 SizeOfDimensions(list)
computes the product of all dimensions in dims
Definition: size.c:522
#define dimension_lower(x)
Definition: ri.h:980

References add_integer_to_expression(), basic_pointer, basic_pointer_p, CAR, CDR, CONS, copy_expression(), DIMENSION, dimension_lower, ENDP, entity_type, entity_variable_p, EXPRESSION, expression_undefined, expression_undefined_p, fortran_module_p(), gen_full_free_list(), gen_nreverse(), get_current_module_entity(), indices, int_to_expression(), make_op_exp(), MINUS_OPERATOR_NAME, MULTIPLY_OPERATOR_NAME, NIL, PLUS_OPERATOR_NAME, POP, reference_indices, reference_variable, SizeOfDimensions(), type_variable, ultimate_type(), variable_basic, and variable_dimensions.

Referenced by do_linearize_array_walker().

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

◆ do_linearize_array_subscript()

static void do_linearize_array_subscript ( _UNUSED_ subscript  s)
static

Definition at line 177 of file array_to_pointer.c.

177  {
178  pips_user_warning("subscript linearization not handled yet\n");
179 }

References pips_user_warning.

Referenced by do_linearize_array_walker().

+ Here is the caller graph for this function:

◆ do_linearize_array_walker()

static void do_linearize_array_walker ( void *  obj)
static

Definition at line 400 of file array_to_pointer.c.

400  {
401  gen_multi_recurse(obj,
405  NULL);
406 }
static void do_linearize_array_reference(reference r)
static void do_linearize_array_cast(cast c)
static void do_linearize_array_subscript(_UNUSED_ subscript s)
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
#define subscript_domain
newgen_storage_domain_defined
Definition: ri.h:378
#define reference_domain
newgen_range_domain_defined
Definition: ri.h:338

References cast_domain, do_linearize_array_cast(), do_linearize_array_reference(), do_linearize_array_subscript(), gen_multi_recurse(), gen_null2(), gen_true2(), reference_domain, and subscript_domain.

Referenced by do_linearize_array().

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

◆ do_linearize_expression_is_pointer()

static void do_linearize_expression_is_pointer ( expression  exp,
hash_table  ht 
)
static

Definition at line 408 of file array_to_pointer.c.

408  {
410  hash_put(ht,exp,(void*)(intptr_t)basic_pointer_p(b));
411  free_basic(b);
412 }
void free_basic(basic p)
Definition: ri.c:107
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
basic basic_of_expression(expression)
basic basic_of_expression(expression exp): Makes a basic of the same basic as the expression "exp".
Definition: type.c:1383
#define intptr_t
Definition: stdint.in.h:294

References basic_of_expression(), basic_pointer_p, exp, free_basic(), hash_put(), and intptr_t.

Referenced by init_expression_is_pointer().

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

◆ do_linearize_patch_expressions()

static void do_linearize_patch_expressions ( void *  obj,
hash_table  ht 
)
static

Definition at line 447 of file array_to_pointer.c.

447  {
450  if(entity_variable_p(e))
452  }
453 }
static void do_linearize_pointer_is_expression(expression exp, hash_table ht)
#define gen_context_recurse(start, ctxt, domain_number, flt, rwt)
Definition: genC.h:285

References do_linearize_pointer_is_expression(), ENTITY, entity_declarations, entity_initial, entity_variable_p, expression_domain, FOREACH, gen_context_recurse, gen_true2(), and get_current_module_entity().

Referenced by do_linearize_array().

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

◆ do_linearize_pointer_is_expression()

static void do_linearize_pointer_is_expression ( expression  exp,
hash_table  ht 
)
static

G: let us hope that by fixing only references, it will be enough

Definition at line 414 of file array_to_pointer.c.

414  {
415  intptr_t t = (intptr_t)hash_get(ht,exp);
416  if(t != (intptr_t)HASH_UNDEFINED_VALUE ) {
418  /*SG: let us hope that by fixing only references, it will be enough */
419  if(t && !basic_pointer_p(b) && expression_reference_p(exp)){
424  make_call(
428  NIL)
429  )
430  )
431  );
432  }
433  free_basic(b);
434  }
435 }
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
#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

References ADDRESS_OF_OPERATOR_NAME, basic_of_expression(), basic_pointer_p, CONS, entity_intrinsic(), exp, EXPRESSION, expression_reference_p(), expression_syntax, free_basic(), hash_get(), HASH_UNDEFINED_VALUE, intptr_t, make_call(), make_expression(), make_syntax_call(), NIL, normalized_undefined, syntax_undefined, and update_expression_syntax().

Referenced by do_linearize_patch_expressions().

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

◆ do_linearize_prepatch()

static void do_linearize_prepatch ( entity  m,
_UNUSED_ statement  s 
)
static

Definition at line 585 of file array_to_pointer.c.

585  {
587  if(entity_variable_p(e)) {
588  if(local_entity_of_module_p(e,m) &&
589  entity_pointer_p(e) &&
593  }
595  }
597  dummy d = parameter_dummy(p);
598  if(dummy_identifier_p(d))
599  {
600  entity di = dummy_identifier(d);
602  }
604  pips_assert("everything went well",parameter_consistent_p(p));
605  }
606 }
value make_value_expression(expression _field_)
Definition: ri.c:2850
void free_value(value p)
Definition: ri.c:2787
static void do_linearize_prepatch_type(type t)
bool local_entity_of_module_p(entity e, entity module)
This test shows that "e" has been declared in "module".
Definition: entity.c:1069
#define value_unknown_p(x)
Definition: ri.h:3077

References do_linearize_prepatch_type(), dummy_identifier, dummy_identifier_p, ENTITY, entity_declarations, entity_initial, entity_pointer_p(), entity_type, entity_variable_p, FOREACH, free_value(), int_to_expression(), local_entity_of_module_p(), make_value_expression(), module_functional_parameters, PARAMETER, parameter_consistent_p(), parameter_dummy, parameter_type, pips_assert, and value_unknown_p.

Referenced by do_linearize_array().

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

◆ do_linearize_prepatch_subscript()

static void do_linearize_prepatch_subscript ( subscript  s)
static

subscripts of the form (*a)[n] are transformed into a[n] it is coherent with other transformations scattered here and there in this file :p

Definition at line 550 of file array_to_pointer.c.

550  {
552  if(expression_call_p(exp)) {
554  entity op = call_function(c);
555  if(ENTITY_DEREFERENCING_P(op)) {
557  if(expression_reference_p(arg)) {
559  entity var = reference_variable(r);
560  if(entity_pointer_p(var)) {
565  }
566  }
567  }
568  }
569  }
570 }
#define subscript_array(x)
Definition: ri.h:2561

References array_type_p(), basic_pointer, call_arguments, call_function, CAR, CONS, copy_syntax(), ENTITY_DEREFERENCING_P, entity_pointer_p(), entity_type, exp, EXPRESSION, expression_call(), expression_call_p(), expression_reference(), expression_reference_p(), expression_syntax, int_to_expression(), pointed_type(), reference_indices, reference_variable, subscript_array, type_variable, ultimate_type(), update_expression_syntax(), and variable_basic.

Referenced by do_linearize_prepatch_subscripts().

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

◆ do_linearize_prepatch_subscripts()

static void do_linearize_prepatch_subscripts ( entity  m,
statement  s 
)
static

transform some subscripts for generic handling later

Definition at line 573 of file array_to_pointer.c.

573  {
577  if(entity_variable_p(e)) {
580  }
581 
582 
583 }
static void do_linearize_prepatch_subscript(subscript s)
subscripts of the form (*a)[n] are transformed into a[n] it is coherent with other transformations sc...
void cleanup_subscripts(void *)

References cleanup_subscripts(), do_linearize_prepatch_subscript(), ENTITY, entity_declarations, entity_initial, entity_variable_p, FOREACH, gen_recurse, gen_true(), and subscript_domain.

Referenced by do_linearize_array().

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

◆ do_linearize_prepatch_type()

static void do_linearize_prepatch_type ( type  t)
static

Definition at line 523 of file array_to_pointer.c.

523  {
524  if(pointer_type_p(t)) {
526  type t3 = ultimate_type(t2);
527  if(array_type_p(t2)) {
528  variable v = type_variable(t2);
534  type_variable(t)=v;
535  }
536  else if(array_type_p(t3)) {
542  type_variable(t)=v;
543  }
544  }
545 }
variable copy_variable(variable p)
VARIABLE.
Definition: ri.c:2859
dimension make_dimension(expression a1, expression a2, list a3)
Definition: ri.c:565
void free_variable(variable p)
Definition: ri.c:2862

References array_type_p(), basic_pointer, CONS, copy_variable(), DIMENSION, free_variable(), int_to_expression(), make_dimension(), NIL, pointer_type_p(), type_undefined, type_variable, ultimate_type(), variable_basic, and variable_dimensions.

Referenced by do_linearize_prepatch().

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

◆ do_linearize_remove_dereferencment()

static void do_linearize_remove_dereferencment ( statement  s,
entity  e 
)
static

◆ do_linearize_remove_dereferencment_walker()

static void do_linearize_remove_dereferencment_walker ( expression  exp,
entity  e 
)
static

Definition at line 483 of file array_to_pointer.c.

483  {
484  if(expression_call_p(exp)) {
485  call c = expression_call(exp);
488  if(expression_reference_p(arg)) {
491  syntax syn = expression_syntax(arg);
494  }
495  }
496  else if(expression_call_p(arg)) {
497  call c2 = expression_call(arg);
498  if(ENTITY_PLUS_C_P(call_function(c2))) {
499  bool remove =false;
500  FOREACH(EXPRESSION,exp2,call_arguments(c2)) {
501  if(expression_reference_p(exp2))
503  }
504  if(remove) {
505  syntax syn = expression_syntax(arg);
508  }
509  }
510 
511  }
512  }
513  }
514 }
#define ENTITY_PLUS_C_P(e)
bool same_entity_p(entity e1, entity e2)
predicates on entities
Definition: entity.c:1321

References call_arguments, call_function, CAR, ENTITY_DEREFERENCING_P, ENTITY_PLUS_C_P, exp, EXPRESSION, expression_call(), expression_call_p(), expression_reference(), expression_reference_p(), expression_syntax, FOREACH, reference_variable, same_entity_p(), syntax_undefined, and update_expression_syntax().

Referenced by do_linearize_remove_dereferencment().

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

◆ do_linearize_type()

static bool do_linearize_type ( type t,
bool rr 
)
static

Definition at line 191 of file array_to_pointer.c.

191  {
192  bool linearized =false;
194  pips_user_warning("cannot linearize void type\n");
195  }
196  else {
197  pips_assert ("variable expected", type_variable_p (*t));
198  pips_debug (5, "try to linearize type: %s\n", type_to_string (*t));
199  if(rr)*rr=false;
200  variable v = type_variable(*t);
201  type ut = ultimate_type(*t);
202  variable uv = type_variable(ut);
203  size_t uvl = gen_length(variable_dimensions(uv));
204  size_t vl = gen_length(variable_dimensions(v));
205  if(uvl > 1 ) {
210  NIL);
211  }
212  else {
216  int_to_expression(1)),
217  NIL);
218  }
219 
220  type nt = type_undefined;
221  bool free_it = false;
222  // copy only if needed, otherwise modify in place
223  if (ut == *t) {
224  nt = *t;
225  free_it = false;
226  }
227  else {
228  nt = copy_type(uvl>vl?ut:*t);
229  free_it = true;
230  }
231  variable nv = type_variable(nt);
234  if (free_it) {
235  // it might be dangerous to free the type that can be reused somewhere
236  // else in the RI
237  free_type(*t);
238  *t=nt;
239  }
240  linearized=true;
241  if(rr)*rr=true;
242  pips_debug (5, "type has been linearized\n");
243  }
244 
246  return do_linearize_type(&basic_pointer(variable_basic(type_variable(*t))),rr) || linearized;
247  }
248  return linearized;
249 }
size_t gen_length(const list l)
Definition: list.c:150
string type_to_string(const type)
type.c
Definition: type.c:51
#define dimension_undefined
Definition: ri.h:955
#define type_variable_p(x)
Definition: ri.h:2947

References basic_pointer, basic_pointer_p, CONS, copy_type(), DIMENSION, dimension_undefined, fortran_module_p(), free_type(), gen_full_free_list(), gen_length(), get_current_module_entity(), int_to_expression(), make_dimension(), make_op_exp(), MINUS_OPERATOR_NAME, NIL, pips_assert, pips_debug, pips_user_warning, SizeOfDimensions(), type_to_string(), type_undefined, type_variable, type_variable_p, type_void_or_void_pointer_p(), ultimate_type(), variable_basic, and variable_dimensions.

Referenced by do_linearize_array(), and do_linearize_array_cast().

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

◆ init_expression_is_pointer()

static hash_table init_expression_is_pointer ( void *  obj)
static

Definition at line 437 of file array_to_pointer.c.

437  {
441  if(entity_variable_p(e))
443  }
444  return ht;
445 }
static void do_linearize_expression_is_pointer(expression exp, hash_table ht)
hash_table hash_table_make(hash_key_type key_type, size_t size)
Definition: hash.c:294
@ hash_int
Definition: newgen_hash.h:32
#define HASH_DEFAULT_SIZE
Definition: newgen_hash.h:26

References do_linearize_expression_is_pointer(), ENTITY, entity_declarations, entity_initial, entity_variable_p, expression_domain, FOREACH, gen_context_recurse, gen_true2(), get_current_module_entity(), HASH_DEFAULT_SIZE, hash_int, and hash_table_make().

Referenced by do_linearize_array().

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

◆ initialization_list_to_statements()

static list initialization_list_to_statements ( entity  e)
static

create a list of statements from entity declarations

we assume that we only have one level of braces, linearize_array should have done the previous job incomplete type are not handled ...

use alloca when converting array to pointers, to make sure everything is initialized correctly

Definition at line 781 of file array_to_pointer.c.

781  {
782  list stats = NIL;
783  if(entity_array_p(e)) {
784  value v = entity_initial(e);
785  if(value_expression_p(v)) {
787  if(expression_call_p(exp)) {
788  call c = expression_call(exp);
789  entity op = call_function(c);
790  /* we assume that we only have one level of braces, linearize_array should have done the previous job
791  * incomplete type are not handled ...
792  * */
793  if(ENTITY_BRACE_INTRINSIC_P(op)) {
796  stats=CONS(STATEMENT,
800  e,
801  CONS(EXPRESSION,i,NIL)
802  )
803  ),
807  )
808  ),
809  stats);
812  copy_expression(i),
814  );
815  }
816  }
817  }
818  }
819  if(!formal_parameter_p(e)) {
820  value v = entity_initial(e);
821  expression ev;
824  }
825  else {
826  /* use alloca when converting array to pointers, to make sure everything is initialized correctly */
829  if(array_type_p(ct)) {
830  POP(variable_dimensions(type_variable(ct))); //leak spotted !
831  ct = make_type_variable(
834  )
835  );
836  }
837 
841  make_cast(ct,
848  )
849  ),
851  )
852  )
853  )
854  )
855  )
856  );
859  }
860  }
861  }
862  return gen_nreverse(stats);
863 }
syntax make_syntax_sizeofexpression(sizeofexpression _field_)
Definition: ri.c:2506
reference make_reference(entity a1, list a2)
Definition: ri.c:2083
sizeofexpression make_sizeofexpression_type(type _field_)
Definition: ri.c:2177
statement make_assign_statement(expression, expression)
Definition: statement.c:583
#define ALLOCA_FUNCTION_NAME
bool entity_array_p(entity e)
Is e a variable with an array type?
Definition: entity.c:754
expression reference_to_expression(reference r)
Definition: expression.c:196
expression syntax_to_expression(syntax s)
generates an expression from a syntax
Definition: expression.c:3581
bool formal_parameter_p(entity)
Definition: variable.c:1489
void AddEntityToModuleCompilationUnit(entity e, entity module)
Definition: module.c:301

References AddEntityToModuleCompilationUnit(), ALLOCA_FUNCTION_NAME, array_type_p(), call_arguments, call_function, CAR, CONS, copy_expression(), copy_type(), DIMENSION, dimension_lower, entity_array_p(), ENTITY_BRACE_INTRINSIC_P, entity_initial, entity_intrinsic(), entity_type, exp, EXPRESSION, expression_call(), expression_call_p(), expression_syntax, FOREACH, formal_parameter_p(), free_value(), gen_nreverse(), get_current_module_entity(), int_to_expression(), make_assign_statement(), make_basic_pointer(), make_cast(), make_expression(), make_op_exp(), make_reference(), make_sizeofexpression_type(), make_syntax_cast(), make_syntax_sizeofexpression(), make_type_variable(), make_value_expression(), make_variable(), MakeUnaryCall(), NIL, normalized_undefined, PLUS_OPERATOR_NAME, POP, reference_to_expression(), STATEMENT, syntax_to_expression(), syntax_undefined, type_variable, ultimate_type(), value_expression, value_expression_p, and variable_dimensions.

Referenced by do_array_to_pointer().

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

◆ insert_statements_after_declarations()

static void insert_statements_after_declarations ( statement  st,
list  stats 
)
static

initialization statements are added right after declarations

No declarations

Definition at line 866 of file array_to_pointer.c.

866  {
867  if(!ENDP(stats)) {
868  if(ENDP(statement_declarations(st))) {
869  insert_statement(st,make_block_statement(stats),true);
870  }
871  else {
872  for(list iter=statement_block(st),prev=NIL;!ENDP(iter);POP(iter)) {
874  prev=iter;
875  } else if(prev == NIL) {
876  /* No declarations */
877  insert_statement(st, make_block_statement(stats), true);
878  } else {
879  CDR(prev) = stats;
880  while(!ENDP(CDR(stats)))
881  POP(stats);
882  CDR(stats) = iter;
883  break;
884  }
885  }
886  }
887 
888  }
889 }
statement make_block_statement(list)
Make a block statement from a list of statement.
Definition: statement.c:616
list statement_block(statement)
Get the list of block statements of a statement sequence.
Definition: statement.c:1338
void insert_statement(statement, statement, bool)
This is the normal entry point.
Definition: statement.c:2570
bool declaration_statement_p(statement)
Had to be optimized according to Beatrice Creusillet.
Definition: statement.c:224
#define statement_declarations(x)
Definition: ri.h:2460

References CAR, CDR, declaration_statement_p(), ENDP, insert_statement(), make_block_statement(), NIL, POP, STATEMENT, statement_block(), and statement_declarations.

Referenced by do_array_to_pointer().

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

◆ linearize_array()

bool linearize_array ( const char *  module_name)

linearize accesses to an array, and use pointers if asked to

Parameters
module_nameodule_name

Definition at line 987 of file array_to_pointer.c.

988 {
990 }
bool linearize_array_generic(const char *module_name)
linearize accesses to an array, and use pointers if asked to
const char * module_name(const char *s)
Return the module part of an entity name.
Definition: entity_names.c:296

References linearize_array_generic(), and module_name().

+ Here is the call graph for this function:

◆ linearize_array_fortran()

bool linearize_array_fortran ( const char *  module_name)
Parameters
module_nameodule_name

Definition at line 992 of file array_to_pointer.c.

993 {
995 }

References linearize_array_generic(), and module_name().

+ Here is the call graph for this function:

◆ linearize_array_generic()

bool linearize_array_generic ( const char *  module_name)

linearize accesses to an array, and use pointers if asked to

prelude

Do we have to cast the array at call site ?

it is too dangerous to perform this task on compilation unit, system variables may be changed

just linearize accesses and change signature from n-D arrays to 1-D arrays

additionally perform array-to-pointer conversion for c modules only

validate

ostlude

Parameters
module_nameodule_name

Definition at line 930 of file array_to_pointer.c.

931 {
932 
933  debug_on("LINEARIZE_ARRAY_DEBUG_LEVEL");
934  /* prelude */
936 
937  param_t param = { .use_pointers_p = false , .modify_call_site_p = false, .cast_at_call_site_p = false };
938  /* Do we have to cast the array at call site ? */
940  param.use_pointers_p = get_bool_property("LINEARIZE_ARRAY_USE_POINTERS");
941  param.cast_at_call_site_p = get_bool_property("LINEARIZE_ARRAY_CAST_AT_CALL_SITE");
942  }
943  param.modify_call_site_p = get_bool_property("LINEARIZE_ARRAY_MODIFY_CALL_SITE");
944 
945  /* it is too dangerous to perform this task on compilation unit, system variables may be changed */
947 
949 
950  /* just linearize accesses and change signature from n-D arrays to 1-D arrays */
952 
953  /* additionally perform array-to-pointer conversion for c modules only */
954  if(param.use_pointers_p) {
959  if(entity_variable_p(e)) {
961  }
962  }
963  }
964  else pips_user_warning("no pointers in fortran !,LINEARIZE_ARRAY_USE_POINTERS ignored\n");
965  }
966 
967  /* validate */
972  // remove decls_text or the prettyprinter will use that field
974  } else {
975  //compilation unti doesn't exit in fortran
977  }
978  /*postlude*/
980  }
982  debug_off();
983  return true;
984 }
bool statement_consistent_p(statement p)
Definition: ri.c:2195
bool db_touch_resource(const char *rname, const char *oname)
touch logical time for resource[owner], possibly behind the back of pipsdbm.
Definition: database.c:538
static void do_linearize_array(entity m, statement s, param_t *param)
static void do_array_to_pointer(entity m, statement s, _UNUSED_ param_t *p)
transform each array type in module m with statement s
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
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
entity set_current_module_entity(entity)
static.c
Definition: static.c:66
#define debug_on(env)
Definition: misc-local.h:157
#define debug_off()
Definition: misc-local.h:160
#define false
Definition: newgen_types.h:80
bool module_reorder(statement body)
Reorder a module and recompute order to statement if any.
Definition: reorder.c:244
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
bool compilation_unit_entity_p(entity e)
Check if the given module entity is a compilation unit.
Definition: module.c:87
void discard_module_declaration_text(entity)
Discard the decls_text string of the module code to make the prettyprinter ignoring the textual decla...
Definition: variable.c:1696

References c_module_p(), cleanup_subscripts(), compilation_unit_entity_p(), compilation_unit_of_module(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, db_touch_resource(), debug_off, debug_on, discard_module_declaration_text(), do_array_to_pointer(), do_linearize_array(), ENTITY, entity_declarations, entity_initial, entity_variable_p, false, FOREACH, fortran_module_p(), get_bool_property(), get_current_module_entity(), get_current_module_statement(), module_name(), module_name_to_entity(), module_reorder(), pips_assert, pips_user_warning, reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), and statement_consistent_p().

Referenced by linearize_array(), and linearize_array_fortran().

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

◆ type_dereferencement_depth()

size_t type_dereferencement_depth ( type  t)
Returns
the number of dimensions in
Parameters
t,countingpointers as a dimension

BEWARE: does not take structs and unions into account

Definition at line 89 of file array_to_pointer.c.

89  {
90  t = ultimate_type(t);
91  if(type_variable_p(t)) {
92  ifdebug(8) {
93  pips_debug(8,"Type is : ");
94  print_type(t);
95  }
96  variable v = type_variable(t);
97  basic b = variable_basic(v);
100  }
101  return 0;
102 }
size_t type_dereferencement_depth(type t)
void print_type(type)
For debugging.
Definition: type.c:111
#define ifdebug(n)
Definition: sg.c:47

References basic_pointer, basic_pointer_p, gen_length(), ifdebug, pips_debug, print_type(), type_dereferencement_depth(), type_variable, type_variable_p, ultimate_type(), variable_basic, and variable_dimensions.

Referenced by type_dereferencement_depth().

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

◆ type_void_or_void_pointer_p()

static bool type_void_or_void_pointer_p ( type  t)
static

Definition at line 181 of file array_to_pointer.c.

181  {
182  if(type_void_p(t)) return true;
183  else if(type_variable_p(t)) {
185  return basic_pointer_p(b) &&
187  }
188  return false;
189 }
#define type_void_p(x)
Definition: ri.h:2959

References basic_pointer, basic_pointer_p, type_variable, type_variable_p, type_void_p, ultimate_type(), and variable_basic.

Referenced by do_array_to_pointer_type(), and do_linearize_type().

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