PIPS
area.c File Reference
#include <stdio.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "misc.h"
#include "ri.h"
#include "ri-util.h"
+ Include dependency graph for area.c:

Go to the source code of this file.

Functions

bool allocatable_area_p (entity aire)
 
bool dynamic_area_p (entity aire)
 
bool static_area_p (entity aire)
 
bool heap_area_p (entity aire)
 
bool formal_area_p (entity aire)
 
bool stack_area_p (entity aire)
 
bool pointer_dummy_targets_area_p (entity aire)
 
entity module_to_heap_area (entity f)
 Returns the heap area "a" associated to module "f". More...
 
entity module_to_dynamic_area (entity f)
 
bool entity_area_p (entity e)
 
bool entity_special_area_p (entity e)
 
int current_offset_of_area (entity a, entity v)
 
bool empty_static_area_p (entity e)
 
void print_common_layout (FILE *fd, entity c, bool debug_p)
 

Variables

entity DynamicArea = entity_undefined
 Pot-pourri of utilities for entities of kind "area". More...
 
entity StaticArea = entity_undefined
 
entity HeapArea = entity_undefined
 
entity StackArea = entity_undefined
 
entity AllocatableArea = entity_undefined
 

Function Documentation

◆ allocatable_area_p()

bool allocatable_area_p ( entity  aire)
Parameters
aireire

Definition at line 64 of file area.c.

64  {
66 }
#define ALLOCATABLE_AREA_LOCAL_NAME
Definition: naming-local.h:73
#define same_string_p(s1, s2)
const char * module_local_name(entity e)
Returns the module local user name.
Definition: entity.c:582

References ALLOCATABLE_AREA_LOCAL_NAME, module_local_name(), and same_string_p.

+ Here is the call graph for this function:

◆ current_offset_of_area()

int current_offset_of_area ( entity  a,
entity  v 
)

the local areas are StaticArea, DynamicArea, HeapArea, StackArea

Varying Length Arrays (VLA) in C or Fortran must be allocated in the stack area, where offsets are not computed in the same way.

Parameters
aarea
vscalar or array variable

Definition at line 174 of file area.c.

176 {
177  int OldOffset;
178  type ta = entity_type(a);
179  area aa = type_area(ta);
180 
181  /* the local areas are StaticArea, DynamicArea, HeapArea, StackArea */
182  OldOffset = area_size(aa);
183  int s;
184  if (!SizeOfArray(v, &s)) {
185  /* Varying Length Arrays (VLA) in C or Fortran must be allocated
186  * in the stack area, where offsets are not computed in the same
187  * way.
188  */
189  pips_internal_error("Ill. arg.: VLA");
190  }
191  else {
192  pips_assert("Offsets are not computed this way in stack areas.\n",
193  !stack_area_p(a));
194  area_size(aa) = OldOffset + s;
195  }
196 
197  area_layout(aa) = gen_nconc(area_layout(aa), CONS(ENTITY, v, NIL));
198  return OldOffset;
199 }
#define NIL
The empty list (nil in Lisp)
Definition: newgen_list.h:47
#define CONS(_t_, _i_, _l_)
List element cell constructor (insert an element at the beginning of a list)
Definition: newgen_list.h:150
list gen_nconc(list cp1, list cp2)
physically concatenates CP1 and CP2 but do not duplicates the elements
Definition: list.c:344
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
Definition: misc-local.h:172
#define pips_internal_error
Definition: misc-local.h:149
bool stack_area_p(entity aire)
Definition: area.c:104
bool SizeOfArray(entity, int *)
This function computes the total size of a variable in bytes, ie.
Definition: size.c:87
#define area_size(x)
Definition: ri.h:544
#define ENTITY(x)
ENTITY.
Definition: ri.h:2755
#define area_layout(x)
Definition: ri.h:546
#define type_area(x)
Definition: ri.h:2946
#define entity_type(x)
Definition: ri.h:2792

References area_layout, area_size, CONS, ENTITY, entity_type, gen_nconc(), NIL, pips_assert, pips_internal_error, SizeOfArray(), stack_area_p(), and type_area.

Referenced by ComputeAddresses(), GenericAddLocalEntityToDeclarations(), make_nlc_entity(), make_nsp_entity(), make_nub_entity(), replace_indices_region(), replace_indices_region_com(), and save_all_entities().

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

◆ dynamic_area_p()

bool dynamic_area_p ( entity  aire)
Parameters
aireire

Definition at line 68 of file area.c.

69 {
70 #ifndef NDEBUG
72  pips_assert("entity_kind is consistent", result == ( (entity_kind(aire) & ENTITY_DYNAMIC_AREA) == ENTITY_DYNAMIC_AREA));
73 #endif
74  return entity_kind(aire) & ENTITY_DYNAMIC_AREA;
75 }
#define DYNAMIC_AREA_LOCAL_NAME
Definition: naming-local.h:69
@ ENTITY_DYNAMIC_AREA
#define entity_kind(x)
Definition: ri.h:2798

References DYNAMIC_AREA_LOCAL_NAME, ENTITY_DYNAMIC_AREA, entity_kind, module_local_name(), pips_assert, and same_string_p.

Referenced by AnalyzeData(), common_regions_forward_translation(), compute_region_variables(), entity_dynamic_p(), entity_locations_max(), entity_special_area_p(), fix_storage(), new_add_any_variable_to_area(), region_dynamic_var_elim(), regions_dynamic_elim(), sentence_area(), text_entity_declaration(), variable_dynamic_p(), and variable_to_abstract_location().

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

◆ empty_static_area_p()

bool empty_static_area_p ( entity  e)

Definition at line 201 of file area.c.

202 {
203  if (!static_area_p(e)) return false;
204  return ENDP(area_layout(type_area(entity_type(e))));
205 }
#define ENDP(l)
Test if a list is empty.
Definition: newgen_list.h:66
bool static_area_p(entity aire)
Definition: area.c:77

References area_layout, ENDP, entity_type, static_area_p(), and type_area.

Referenced by text_entity_declaration().

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

◆ entity_area_p()

bool entity_area_p ( entity  e)

Definition at line 149 of file area.c.

150 {
151  return !type_undefined_p(entity_type(e)) && type_area_p(entity_type(e));//static_area_p(e) || dynamic_area_p(e) || heap_area_p(e) || stack_area_p(e);
152 }
#define type_undefined_p(x)
Definition: ri.h:2884
#define type_area_p(x)
Definition: ri.h:2944

References entity_type, type_area_p, and type_undefined_p.

Referenced by check_common_inclusion(), common_members_of_module(), entity_special_area_p(), inline_expression_call(), normalize_microcode(), and wipeout_entity().

+ Here is the caller graph for this function:

◆ entity_special_area_p()

bool entity_special_area_p ( entity  e)

Definition at line 154 of file area.c.

155 {
156  return entity_area_p(e) &&
158 }
bool dynamic_area_p(entity aire)
Definition: area.c:68
bool pointer_dummy_targets_area_p(entity aire)
Definition: area.c:113
bool entity_area_p(entity e)
Definition: area.c:149
bool heap_area_p(entity aire)
Definition: area.c:86

References dynamic_area_p(), entity_area_p(), heap_area_p(), pointer_dummy_targets_area_p(), stack_area_p(), and static_area_p().

Referenced by declaration_supporting_references(), entity_in_common_p(), formal_variable_add_aliases(), init_host_and_node_entities(), regions_dynamic_elim(), text_entity_declaration(), text_equivalences(), update_common_layout(), update_user_common_layouts(), and variable_in_common_p().

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

◆ formal_area_p()

bool formal_area_p ( entity  aire)
Parameters
aireire

Definition at line 95 of file area.c.

96 {
97 #ifndef NDEBUG
99  pips_assert("entity_kind is consistent", result == ( (entity_kind(aire) & ENTITY_FORMAL_AREA) == ENTITY_FORMAL_AREA));
100 #endif
101  return entity_kind(aire) & ENTITY_FORMAL_AREA;
102 }
#define FORMAL_AREA_LOCAL_NAME
Definition: naming-local.h:76
@ ENTITY_FORMAL_AREA

References ENTITY_FORMAL_AREA, entity_kind, FORMAL_AREA_LOCAL_NAME, module_local_name(), pips_assert, and same_string_p.

Referenced by entity_in_formal_area_p(), entity_stub_sink_p(), formal_context_variable_p(), and variable_to_abstract_location().

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

◆ heap_area_p()

◆ module_to_dynamic_area()

entity module_to_dynamic_area ( entity  f)

Definition at line 139 of file area.c.

140 {
142 
143  pips_assert("The dynamic area is defined for module f.\n",
144  !entity_undefined_p(a));
145 
146  return a;
147 }
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
entity FindEntity(const char *package, const char *name)
Retrieve an entity from its package/module name and its local name.
Definition: entity.c:1503
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
#define entity_undefined_p(x)
Definition: ri.h:2762

References DYNAMIC_AREA_LOCAL_NAME, entity_local_name(), entity_undefined_p, f(), FindEntity(), and pips_assert.

+ Here is the call graph for this function:

◆ module_to_heap_area()

entity module_to_heap_area ( entity  f)

Returns the heap area "a" associated to module "f".

Area "a" is always a defined entity.

Assumes that f is defined, as well as its heap area.

Definition at line 129 of file area.c.

130 {
132 
133  pips_assert("The heap area is defined for module f.\n",
134  !entity_undefined_p(a));
135 
136  return a;
137 }

References entity_local_name(), entity_undefined_p, f(), FindEntity(), HEAP_AREA_LOCAL_NAME, and pips_assert.

Referenced by entity_flow_or_context_sentitive_heap_location().

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

◆ pointer_dummy_targets_area_p()

bool pointer_dummy_targets_area_p ( entity  aire)
Parameters
aireire

Definition at line 113 of file area.c.

114 {
115 #ifndef NDEBUG
117  pips_assert("entity_kind is consistent", result == ( (entity_kind(aire) & ENTITY_POINTER_DUMMY_TARGETS_AREA) == ENTITY_POINTER_DUMMY_TARGETS_AREA));
118 #endif
120 }
#define POINTER_DUMMY_TARGETS_AREA_LOCAL_NAME
Definition: naming-local.h:77
@ ENTITY_POINTER_DUMMY_TARGETS_AREA

References entity_kind, ENTITY_POINTER_DUMMY_TARGETS_AREA, module_local_name(), pips_assert, POINTER_DUMMY_TARGETS_AREA_LOCAL_NAME, and same_string_p.

Referenced by entity_special_area_p(), sentence_area(), and text_entity_declaration().

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

◆ print_common_layout()

void print_common_layout ( FILE *  fd,
entity  c,
bool  debug_p 
)

list members = area_layout(type_area(entity_type(c)));

list members = common_members_of_module(c, mod , true);

for debugging only

Look for variables declared in this common by some procedures which declares it. The procedures involved depend on the ordering of the parser steps by pipsmake and the user. Maybe, the list should be filtered and restricted to the current module: YES!

Consistency check between the area layout and the ram section

Look for variables aliased with a variable in this common

Parameters
fdd
debug_pebug_p

Definition at line 207 of file area.c.

208 {
210  /* list members = area_layout(type_area(entity_type(c))); */
211  /* list members = common_members_of_module(c, mod , true); */
212  /* for debugging only */
213  list members = common_members_of_module(c, mod , false);
214  list equiv_members = NIL;
215 
216  (void) fprintf(fd,"\nLayout for common /%s/ of size %td:\n",
218 
219  if(ENDP(members)) {
220  pips_assert("An empty area has size 0", area_size(type_area(entity_type(c)))==0);
221  (void) fprintf(fd, "\t* empty area *\n\n");
222  }
223  else {
224  if(area_size(type_area(entity_type(c)))==0
225  // The next condition cannot be tested outside of the Fortran parser
226  // && (common_size_map == hash_table_undefined || common_to_size(c)==0)
227  && !heap_area_p(c)
228  && !stack_area_p(c)) {
229  if(debug_p) {
230  pips_user_warning("Non-empty area %s should have a final size greater than 0\n",
231  entity_module_name(c));
232  }
233  else {
234  pips_internal_error("Non-empty area %s should have a size greater than 0",
235  entity_module_name(c));
236  }
237  }
238  /* Look for variables declared in this common by *some* procedures
239  * which declares it. The procedures involved depend on the ordering
240  * of the parser steps by pipsmake and the user. Maybe, the list should
241  * be filtered and restricted to the current module: YES!
242  */
243  FOREACH(ENTITY, m, members)
244  {
245  pips_assert("RAM storage",
247  if(ram_function(storage_ram(entity_storage(m)))==mod) {
248  int s;
249 
250  /* Consistency check between the area layout and the ram section */
252  pips_internal_error("Variable %s declared in area %s but allocated in area %s",
255  }
256 
257  if(!SizeOfArray(m, &s)) {
260  s = -1;
261  }
262  else {
263  pips_user_warning("Varying size of array \"%s\"\n",
264  entity_name(m));
265  // VLA are now supported by PIPS in the stack_area and the dynamic_area
266  pips_internal_error("Fortran standard prohibit varying size array\n");
267  }
268  }
269 
270  (void) fprintf(fd,
271  "\tVariable %s,\toffset = %td,\tsize = %d\n",
272  entity_name(m),
274  s);
275 
276  }
277  }
278  (void) fprintf(fd, "\n");
279 
280  /* Look for variables aliased with a variable in this common */
281  FOREACH(ENTITY, m, members)
282  {
284  equiv_members = arguments_union(equiv_members, equiv);
285  }
286 
287  if(!ENDP(equiv_members)){
288 
289  equiv_members = arguments_difference(equiv_members, members);
290  if(!ENDP(equiv_members)) {
291  sort_list_of_entities(equiv_members);
292 
293  (void) fprintf(fd, "\tVariables aliased to this common:\n");
294 
295  FOREACH(ENTITY, m, equiv_members)
296  {
297  pips_assert("RAM storage",
299  (void) fprintf(fd,
300  "\tVariable %s,\toffset = %td,\tsize = %d\n",
301  entity_name(m),
303  array_size(m));
304  }
305  (void) fprintf(fd, "\n");
306  gen_free_list(equiv_members);
307  }
308  }
309  }
310  gen_free_list(members);
311 }
cons * arguments_union(cons *a1, cons *a2)
cons * arguments_union(cons * a1, cons * a2): returns a = union(a1, a2) where a1 and a2 are lists of ...
Definition: arguments.c:116
cons * arguments_difference(cons *a1, cons *a2)
set difference: a1 - a2 ; similar to set intersection
Definition: arguments.c:233
static int array_size(dim)
ARRAY_SIZE returns the number of elements in the array whose dimension list is DIM.
Definition: genClib.c:155
entity get_current_module_entity(void)
Get the entity of the current module.
Definition: static.c:85
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_user_warning
Definition: misc-local.h:146
entity HeapArea
Definition: area.c:59
entity StackArea
Definition: area.c:60
void sort_list_of_entities(list l)
sorted in place.
Definition: entity.c:1358
const char * entity_module_name(entity e)
See comments about module_name().
Definition: entity.c:1092
list common_members_of_module(entity common, entity module, bool only_primary)
returns the list of entity to appear in the common declaration.
Definition: entity.c:1741
#define entity_storage(x)
Definition: ri.h:2794
#define storage_ram_p(x)
Definition: ri.h:2519
#define ram_section(x)
Definition: ri.h:2249
#define entity_name(x)
Definition: ri.h:2790
#define storage_ram(x)
Definition: ri.h:2521
#define ram_function(x)
Definition: ri.h:2247
#define ram_shared(x)
Definition: ri.h:2253
#define ram_offset(x)
Definition: ri.h:2251
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
The structure used to build lists in NewGen.
Definition: newgen_list.h:41

References area_size, arguments_difference(), arguments_union(), array_size(), common_members_of_module(), ENDP, ENTITY, entity_local_name(), entity_module_name(), entity_name, entity_storage, entity_type, FOREACH, fprintf(), gen_free_list(), get_current_module_entity(), heap_area_p(), HeapArea, module_local_name(), NIL, pips_assert, pips_internal_error, pips_user_warning, ram_function, ram_offset, ram_section, ram_shared, SizeOfArray(), sort_list_of_entities(), stack_area_p(), StackArea, storage_ram, storage_ram_p, and type_area.

Referenced by fprint_any_environment(), MakeEntryCommon(), and update_user_common_layouts().

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

◆ stack_area_p()

bool stack_area_p ( entity  aire)

◆ static_area_p()

bool static_area_p ( entity  aire)
Parameters
aireire

Definition at line 77 of file area.c.

78 {
79 #ifndef NDEBUG
81  pips_assert("entity_kind is consistent", result == ( (entity_kind(aire) & ENTITY_STATIC_AREA) == ENTITY_STATIC_AREA));
82 #endif
83  return entity_kind(aire) & ENTITY_STATIC_AREA;
84 }
#define STATIC_AREA_LOCAL_NAME
Definition: naming-local.h:70
@ ENTITY_STATIC_AREA

References entity_kind, ENTITY_STATIC_AREA, module_local_name(), pips_assert, same_string_p, and STATIC_AREA_LOCAL_NAME.

Referenced by AnalyzeData(), c_text_related_entities(), empty_static_area_p(), entity_locations_max(), entity_special_area_p(), entity_static_variable_p(), fix_storage(), live_in_paths_of_statement(), new_add_any_variable_to_area(), sentence_area(), sequence_to_post_pv(), variable_static_p(), and variable_to_abstract_location().

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

Variable Documentation

◆ AllocatableArea

entity AllocatableArea = entity_undefined

Definition at line 61 of file area.c.

◆ DynamicArea

entity DynamicArea = entity_undefined

Pot-pourri of utilities for entities of kind "area".

area.c

These global variables are declared in ri-util/util.c.

functions for areas Four areas used to allocate variables which are not stored in a Fortran common. These areas are just like Fortran commons, but the dynamic area is the only non-static area according to Fortran standard. The heap and the stack area are used to deal with Fortran ANSI extensions and C, pointers and allocatable arrays, and adjustable arrays (VLA in C). The dynamic area is stack allocated by most compilers but could be statically allocated since the array sizes are known.

Areas are declared for each module. These four global variables are managed by the Fortran and C parsers and used to allocate variables in the current module. Note that the C parser uses more areas at the same time to cope with global variables.

Definition at line 57 of file area.c.

Referenced by ComputeAddresses(), EndOfProcedure(), gfc2pips_code2instruction__TOP(), gfc2pips_computeAdressesDynamic(), gfc2pips_computeAdressesOfArea(), gfc2pips_expr2entity(), gfc2pips_expr2expression(), gfc2pips_vars_(), init_c_areas(), init_c_implicit_variables(), InitAreas(), make_empty_module(), MakeStorageRam(), MakeVariableStatic(), ParserError(), save_all_entities(), and SaveEntity().

◆ HeapArea

◆ StackArea

◆ StaticArea