PIPS
|
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "ri-util.h"
#include "misc.h"
Go to the source code of this file.
Macros | |
#define | INTERVAL_INTERSECTION(a, b, c, d) (!((b) <= (c) || (d) <= (a))) |
Functions | |
int | number_of_initial_values (list args) |
Functions to compute the numer of bytes required to store a variable or an object of a given type in memory; used by memory allocation functions in parsers, when allocation is possible (STATIC and DYNAMIC). More... | |
bool | SizeOfArray (entity e, int *s) |
This function computes the total size of a variable in bytes, ie. More... | |
int | array_size (entity a) |
Value | ValueSizeOfArray (entity e) |
int | CSafeSizeOfArray (entity a) |
BEGIN_EOLE. More... | |
int | entity_memory_size (entity dt) |
int | type_memory_size (type t) |
_int | SizeOfElements (basic b) |
This function returns the length in bytes of the Fortran or C type represented by a basic, except for a varying size string (formal parameter). More... | |
int | element_number (basic b, list ld) |
END_EOLE. More... | |
bool | NumberOfElements (basic b, list ld, int *n) |
Value | ValueNumberOfElements (list ld) |
int | SizeOfIthDimension (entity e, int i) |
this function returns the size of the ith dimension of a variable e. More... | |
int | dimension_size (dimension d) |
this function computes the size of a dimension. More... | |
expression | SizeOfDimension (dimension d) |
static void * | do_sizeofdimension_reduction (void *v, const list l) |
expression | SizeOfDimensions (list dims) |
computes the product of all dimensions in dims More... | |
Value | ValueSizeOfDimension (dimension d) |
FI: I do not understand the "Value" cast. More... | |
int | ExpressionToInt (expression e) |
this function computes the value of an integer constant expression and returns it to the calling function. More... | |
int | NumberOfDimension (entity e) |
void | set_entity_to_size () |
void | reset_entity_to_size () |
void | safe_reset_entity_to_size () |
In case of error handling, PIPS may try to reset this table twice. More... | |
int | storage_space_of_variable (entity v) |
bool | variable_entities_may_conflict_p (entity e1, entity e2) |
Variables | |
static hash_table | entity_to_size = hash_table_undefined |
a hash table to map entities to their numbers of elements More... | |
#define INTERVAL_INTERSECTION | ( | a, | |
b, | |||
c, | |||
d | |||
) | (!((b) <= (c) || (d) <= (a))) |
Definition at line 195 of file size.c.
References entity_name, pips_internal_error, and SizeOfArray().
BEGIN_EOLE.
should be a pips_user_error() to avoid useless and dangerous results
Definition at line 225 of file size.c.
References entity_name, pips_user_warning, and SizeOfArray().
Referenced by ComputeAreaOffset(), SizeOfElements(), and type_memory_size().
this function computes the size of a dimension.
Definition at line 491 of file size.c.
References expression_integer_value(), free_expression(), intptr_t, pips_internal_error, and SizeOfDimension().
Referenced by ComputeNewSizeOfIthDimension(), loadstore_type_conversion_string(), make_emulated_shared_variable(), normalize_microcode_anotate(), reference_offset(), template_ranges_to_processors_ranges(), and type_memory_size().
|
static |
Definition at line 513 of file size.c.
References CAR, DIMENSION, make_op_exp(), MULTIPLY_OPERATOR_NAME, and SizeOfDimension().
Referenced by SizeOfDimensions().
END_EOLE.
this function computes the number of elements of a variable. ld is the list of dimensions of the variable
ld | d |
Definition at line 391 of file size.c.
References NumberOfElements(), and pips_internal_error.
Referenced by compile_one_reduction(), max_size_of_processors(), and processor_loop().
dt is assumed to be a derived type: struct, union, and maybe enum
dt | t |
Definition at line 239 of file size.c.
References entity_type, type_memory_size(), and ultimate_type().
Referenced by reductions_rewrite(), and SizeOfElements().
int ExpressionToInt | ( | expression | e | ) |
this function computes the value of an integer constant expression and returns it to the calling function.
it aborts if the expression is not constant.
See expression_integer_value() to check before aborting
Definition at line 562 of file size.c.
References constant_int, constant_int_p, EvalExpression(), free_value(), pips_internal_error, value_constant, and value_constant_p.
Referenced by get_entity_dimensions(), OffsetOfReference(), SizeOfRange(), and ValueOfIthLowerBound().
Functions to compute the numer of bytes required to store a variable or an object of a given type in memory; used by memory allocation functions in parsers, when allocation is possible (STATIC and DYNAMIC).
If the size is unknown, the variable is allocated in the STACK area. See ri.pdf, section about "area".
args | rgs |
Definition at line 44 of file size.c.
References call_arguments, call_function, CAR, ENDP, ENTITY_BRACE_INTRINSIC_P, EXPRESSION, expression_call_p(), expression_syntax, f(), list_undefined, number_of_initial_values(), POP, and syntax_call.
Referenced by number_of_initial_values(), and SizeOfArray().
Definition at line 588 of file size.c.
References assert, CDR, ENDP, entity_type, type_variable, type_variable_p, and variable_dimensions.
Referenced by add_bound_arguments(), align_check(), array_as_template(), array_bounds_list(), array_distribution_similar_p(), array_ranges_to_template_ranges(), array_with_numerical_bounds_p(), block_distributed_p(), caller_list_of_bounds(), clean_distributed_io_system(), clean_shared_io_system(), compute_receive_content(), conformant_entities_p(), create_init_common_param_for_arrays(), create_init_common_param_for_processors(), create_init_common_param_for_templates(), create_parameters_h(), define_node_processor_id(), entity_unbounded_p(), extract_the_align(), extract_the_distribute(), full_linearization(), generate_compute_local_indices(), hpfc_broadcast_buffers(), hpfc_compute_align_constraints(), hpfc_compute_distribute_constraints(), hpfc_compute_entity_to_new_declaration(), hpfc_compute_lid(), hpfc_compute_unicity_constraints(), make_guard_expression(), make_reference_expression(), normalize_distribute(), number_of_distributed_dimensions(), one_message_guards_and_neighbour(), partial_linearization(), put_variables_in_ordered_lists(), reduction_parameters(), reference_to_points_to_sinks(), region_translation_init(), replicated_p(), st_generate_packing(), step_local_regionArray(), template_ranges_to_processors_ranges(), text_equivalence_class(), and update_overlaps_of().
do we have many elements at the lower typedef levels?
let's take care of the current level
ld | d |
Definition at line 403 of file size.c.
References basic_typedef, basic_typedef_p, CAR, CDR, DIMENSION, entity_type, expression_integer_value(), free_expression(), intptr_t, NumberOfElements(), ok, SizeOfDimension(), type_variable, variable_basic, and variable_dimensions.
Referenced by element_number(), expression_reference_number(), number_of_items(), NumberOfElements(), and SizeOfArray().
void reset_entity_to_size | ( | void | ) |
Definition at line 635 of file size.c.
References entity_to_size, hash_table_free(), hash_table_undefined, and pips_internal_error.
Referenced by create_workspace().
void safe_reset_entity_to_size | ( | void | ) |
In case of error handling, PIPS may try to reset this table twice.
Definition at line 647 of file size.c.
References entity_to_size, hash_table_free(), and hash_table_undefined.
Referenced by close_workspace().
void set_entity_to_size | ( | void | ) |
hash_table_clear(entity_to_size);
Definition at line 625 of file size.c.
References entity_to_size, hash_pointer, hash_table_make(), hash_table_undefined, and pips_internal_error.
Referenced by create_workspace(), and open_workspace().
This function computes the total size of a variable in bytes, ie.
the product of the number of elements and the size of each element in byte, when this size is a constant.
Arrays cannot be sized by a variable according to Fortran 77 standard, unless they are formal parameters (see SafeSizeOfArray). This restriction is lifted for arrays allocated in the area STACK.
Arrays can be sized by expressions according to C latest standard (see Validation/C_syntax/array_declarators.c). Then their sizes are not available at compile time and their addresses in stack cannot be computed at compiler time (see CSafeSizeOfArray).
Since the size is returned in a signed int, there is a maximum PIPS size for an array.
Let's try to use the initial value
FI: should eveb be freed?
Is it an array of characters initialized with a string expression?
Is it a call to the BRACE_INTRINSIC operator?
This is too simple unfortunately: OK, but why? which test case?
ne = gen_length(args);
Should be a call to CParserError()...
Check for other dimensions which must be all declared: the first dimension only can be implicit
Already taken care of by "ni"
Check for 32 bit signed overflows
Definition at line 87 of file size.c.
References assert, basic_derived, basic_derived_p, basic_of_expression(), basic_string_p, basic_undefined_p, call_arguments, call_function, char_type_p(), ENTITY_BRACE_INTRINSIC_P, entity_initial, entity_type, expression_call_p(), expression_syntax, f(), gen_length(), number_of_initial_values(), number_of_items(), NumberOfElements(), ok, pips_internal_error, pips_user_warning, SizeOfElements(), string_type_size(), syntax_call, type_variable, type_variable_p, ultimate_type(), value_constant_p, value_expression, value_expression_p, value_undefined_p, variable_basic, and variable_dimensions.
Referenced by add_any_variable_to_area(), alias_check(), array_size(), common_members_of_module(), ComputeAddresses(), CSafeSizeOfArray(), current_offset_of_area(), dump_common_layout(), formal_variable_add_aliases(), fprint_any_environment(), GenericAddLocalEntityToDeclarations(), gfc2pips_computeAdressesOfArea(), gfc2pips_symbol2data_instruction(), impact_check(), MakeStorageRam(), new_add_any_variable_to_area(), print_C_common_layout(), print_common_layout(), ram_variable_add_aliases(), SafeSizeOfArray(), same_or_equivalence_argument_add_aliases(), and storage_space_of_variable().
expression SizeOfDimension | ( | dimension | d | ) |
Definition at line 503 of file size.c.
References copy_expression(), dimension_lower, dimension_upper, int_to_expression(), make_op_exp(), MINUS_OPERATOR_NAME, and PLUS_OPERATOR_NAME.
Referenced by dimension_size(), dimensions_to_dma(), do_sizeofdimension_reduction(), do_terapix_warmup_patching(), NumberOfElements(), and SizeOfIthDimension().
expression SizeOfDimensions | ( | list | dims | ) |
computes the product of all dimensions in dims
dims | ims |
Definition at line 522 of file size.c.
References do_sizeofdimension_reduction(), gen_reduce(), and int_to_expression().
Referenced by dimensions_to_dma(), do_group_constants_terapix(), do_group_count_elements_reduce(), do_linearize_array_reference(), do_linearize_type(), and makeTransfertSizeExpression().
This function returns the length in bytes of the Fortran or C type represented by a basic, except for a varying size string (formal parameter).
What is the semantics for bitfields? Return its size rounded to a byte number large enough to fit, and not the size in bit.
Some of these values are target architecture dependent: e == 1 character e == 2 short int e == 4 int e == 6 long int e == 8 long long int They are defined in ri-util-local.h To be consistent with the machine compiling and executing PIPS, we could use a switch(e) and the corresponding sizeof().
As for int, e encodes some fine typing information: remove it
pips_assert("SizeOfElements", gen_consistent_p(b));
Size can be zero, i.e. unknown, for an external variable
Definition at line 297 of file size.c.
References basic_bit, basic_complex, basic_derived, basic_float, basic_int, basic_logical, basic_string, basic_tag, basic_typedef, constant_int, constant_int_p, constant_undefined, CSafeSizeOfArray(), DEFAULT_INTEGER_TYPE_SIZE, DEFAULT_LONG_INTEGER_TYPE_SIZE, DEFAULT_POINTER_TYPE_SIZE, entity_memory_size(), is_basic_bit, is_basic_complex, is_basic_derived, is_basic_float, is_basic_int, is_basic_logical, is_basic_pointer, is_basic_string, is_basic_typedef, pips_internal_error, symbolic_constant, user_error, value_constant, value_constant_p, value_symbolic, and value_symbolic_p.
Referenced by abc_with_allocation_size(), alias_check(), array_size_stride(), basic_maximum(), consecutive_expression_p(), distance_between_expression(), edge_cost_polynome(), formal_variable_add_aliases(), get_optimal_opcode(), get_symbol_table(), get_vect_name_from_data(), impact_check(), interprocedural_abc_arrays(), make_datum_movement(), make_movement_scalar_wp65(), make_movements_loop_body_wp65(), ram_variable_add_aliases(), region_translation_init(), same_or_equivalence_argument_add_aliases(), size_of_regions(), SizeOfArray(), SizeOfIthDimension(), subscript_value_stride(), text_equivalence_class(), type_and_size_of_var(), type_memory_size(), ValueSizeOfArray(), and variables_width_filter().
this function returns the size of the ith dimension of a variable e.
if called for the 0th dimension, it returns the variable element size.
Definition at line 453 of file size.c.
References abort, CAR, CDR, DIMENSION, entity_type, expression_integer_value(), fprintf(), free_expression(), intptr_t, NIL, SizeOfDimension(), SizeOfElements(), type_variable, type_variable_p, variable_basic, and variable_dimensions.
Referenced by array_distribution_similar_p(), ComputeNewSizeOfIthDimension(), create_init_common_param_for_arrays(), hpfc_broadcast_buffers(), hpfc_compute_distribute_constraints(), NormalizeOneTemplateDistribution(), OffsetOfReference(), one_message_guards_and_neighbour(), processor_number(), same_alignment_p(), and text_equivalence_class().
Storage size is expressed in bytes
Definition at line 656 of file size.c.
References abort, entity_to_size, fprintf(), hash_get(), hash_pointer, hash_put(), hash_table_make(), hash_table_undefined, HASH_UNDEFINED_VALUE, SizeOfArray(), and user_warning.
Referenced by create_new_common_variable(), and variable_entities_may_conflict_p().
Seems to be the case for defined types; FI: why are they allocated in RAM while they only exist at compile time ?
How is it implemented? 32 bit integer?
A struct (or a union) may be hidden, with its declaration located in the source code of a library. For instance, "_IO_FILE_plus" in stdio.h. Since it contains at least one byte, let set s to 1? Or let the caller deal with the problem?
Definition at line 248 of file size.c.
References CSafeSizeOfArray(), DIMENSION, dimension_size(), ENTITY, FOREACH, is_type_area, is_type_enum, is_type_functional, is_type_statement, is_type_struct, is_type_union, is_type_unknown, is_type_varargs, is_type_variable, is_type_void, MAP, pips_internal_error, SizeOfElements(), type_struct, type_tag, type_union, type_variable, variable_basic, and variable_dimensions.
Referenced by entity_memory_size(), EvalSizeofexpression(), get_type_max_width(), and partial_eval_syntax().
ld | d |
Definition at line 435 of file size.c.
References CAR, CDR, DIMENSION, value_mult, VALUE_ONE, and ValueSizeOfDimension().
Referenced by simd_replace_parameters(), and ValueSizeOfArray().
Definition at line 206 of file size.c.
References assert, entity_type, SizeOfElements(), type_variable, type_variable_p, value_mult, ValueNumberOfElements(), variable_basic, and variable_dimensions.
Referenced by equivalent_entity_compare(), and text_equivalence_class().
FI: I do not understand the "Value" cast.
Definition at line 531 of file size.c.
References abort, dimension_lower, dimension_upper, expression_integer_value(), fprintf(), intptr_t, ok, value_minus, VALUE_ONE, and value_plus.
Referenced by ValueNumberOfElements().
Can we have and check static aliasing in a1?
Let's assume we are dealing with Fortran code, but another test should be added about the current module language. No test on dynamic aliasing since we are dealing here with direct read and write effects.
return(r1 != ram_undefined && r2 != ram_undefined && f1 == f2 && a1 == a2 && INTERVAL_INTERSECTION(o1, l1, o2, l2));
FI: it's too late to check if r1 and r2 are defined: you already have core dumped! also, f1 and f2 are not relevant since location are governed by area a1 and a2
e1 | 1 |
e2 | 2 |
Definition at line 689 of file size.c.
References c_module_p(), ENDP, entity_storage, f2(), formal_function, formal_offset, get_current_module_entity(), heap_area_p(), INTERVAL_INTERSECTION, ram_function, ram_offset, ram_section, ram_shared, ram_undefined, s1, same_entity_p(), stack_area_p(), storage_formal, storage_formal_p, storage_ram, storage_ram_p, and storage_space_of_variable().
Referenced by entities_maymust_conflict_p(), references_may_conflict_p(), and SaveChains().
|
static |
a hash table to map entities to their numbers of elements
This table is critical to compute use-def chains at an acceptable speed because the computation of a variable allocated space is very slow. Declaration are preserved in PIPS and constant expressions must be evaluated.
Note: the current implementation is not safe. The hash table may be kept from module to module (which should be OK) and from workspace to workspace, which is not.
This is an unusual object because it's life time is the workspace life time and not the module analysis life time. This hash table acts as a cache of the symbol table.
Definition at line 623 of file size.c.
Referenced by reset_entity_to_size(), safe_reset_entity_to_size(), set_entity_to_size(), and storage_space_of_variable().