PIPS
|
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "linear.h"
#include "genC.h"
#include "ri.h"
#include "misc.h"
#include "ri-util.h"
#include "properties.h"
#include "operator.h"
Go to the source code of this file.
Functions | |
value | EvalExpression (expression e) |
Evaluate statically an expression. More... | |
value | EvalSyntax (syntax s) |
value | EvalCall (call c) |
only calls to constant, symbolic or intrinsic functions might be evaluated. More... | |
value | EvalSizeofexpression (sizeofexpression soe) |
value | EvalConstant (constant c) |
Constant c is returned as field of value v. More... | |
value | EvalIntrinsic (entity e, list la) |
This function tries to evaluate a call to an intrinsic function. More... | |
value | EvalConditionalOp (list la) |
value | EvalUnaryOp (int t, list la) |
value | EvalBinaryOp (int t, list la) |
t defines the operator and la is a list to two sub-expressions. More... | |
value | EvalNaryOp (int t, list la) |
int | IsUnaryOperator (entity e) |
int | IsBinaryOperator (entity e) |
FI: These string constants are defined in ri-util.h and the tokens in ri-util/operator.h. More... | |
int | IsNaryOperator (entity e) |
int | ipow (int vg, int vd) |
FI: such a function should exist in Linear/arithmetique. More... | |
bool | expression_integer_value (expression e, intptr_t *pval) |
bool | expression_negative_integer_value_p (expression e) |
Return true iff the expression has an integer value known statically and this value is negative. More... | |
bool | positive_expression_p (expression e) |
Use constants and type information to decide if the value of sigma(e) is always positive, e.g. More... | |
bool | negative_expression_p (expression e) |
Use constants and type information to decide if the value of sigma(e) is always negative, e.g. More... | |
bool | expression_linear_p (expression e) |
returns if e is already normalized and linear. More... | |
expression | range_to_expression (range r, enum range_to_expression_mode mode) |
computes the distance between the lower bound and the upper bound of the range More... | |
bool | range_count (range r, intptr_t *pcount) |
The range count only can be evaluated if the three range expressions are constant and if the increment is non zero. More... | |
static bool | vect_const_p (Pvecteur v) |
returns true if v is not NULL and is constant More... | |
Pvecteur | vect_product (Pvecteur *pv1, Pvecteur *pv2) |
returns a Pvecteur equal to (*pv1) * (*pv2) if this product is linear or NULL otherwise. More... | |
reference | constant_reference_to_normalized_constant_reference (reference cr) |
Allocate a new reference with evaluated subscripts. More... | |
expression | normalize_integer_constant_expression (expression e) |
Allocate a new expression equivalent to e, but constant expressions are evaluated. More... | |
Allocate a new reference with evaluated subscripts.
For instance, return a[2] for a[10/2-3]
This function deals with all kinds of references, including the points-to references which use fields as subscripts.
There is an ambiguity for a[*] where * may be considered a constant in some passes of PIPS. However, it denotes a constant set of references and not a constant reference. The returned reference is undefined.
cr | r |
Definition at line 1068 of file eval.c.
References CONS, constant_p(), copy_expression(), EXPRESSION, expression_integer_value(), expression_reference_p(), expression_undefined, FOREACH, gen_full_free_list(), gen_nreverse(), int_to_expression(), intptr_t, make_reference(), NIL, pips_internal_error, reference_indices, reference_undefined, reference_variable, and unbounded_expression_p().
Referenced by constant_memory_access_path_to_location_entity(), and make_location_entity().
t defines the operator and la is a list to two sub-expressions.
Integer and floatint point constants are evaluated.
FI: lazy...
OK for Fortran Logical? Int value or logical value?
la | a |
Definition at line 385 of file eval.c.
References AND, BITWISE_AND, BITWISE_OR, BITWISE_XOR, CAR, CDR, constant_float, constant_float_p, constant_int, constant_int_p, EQ, EQV, EvalExpression(), EXPRESSION, free_value(), GE, GT, ipow(), is_value_unknown, LEFT_SHIFT, LT, make_value(), MINUS, MOD, NE, NEQV, NIL, OR, pips_assert, pips_user_error, PLUS, POWER, RIGHT_SHIFT, SLASH, STAR, value_constant, and value_constant_p.
Referenced by EvalIntrinsic().
only calls to constant, symbolic or intrinsic functions might be evaluated.
recall that intrinsic functions are not known.
SG: it may be better not to evaluate symbolic and keep their symbolic name
it might be an intrinsic function
Definition at line 170 of file eval.c.
References call_arguments, call_function, entity_initial, entity_name, EvalConstant(), EvalIntrinsic(), f(), get_bool_property(), is_value_code, is_value_constant, is_value_intrinsic, is_value_symbolic, is_value_unknown, make_value_unknown(), pips_internal_error, symbolic_constant, value_constant, value_symbolic, value_tag, value_undefined, and value_undefined_p.
Referenced by EvalSyntax().
la | a |
Definition at line 309 of file eval.c.
References CAR, CDR, constant_int, constant_int_p, EvalExpression(), EXPRESSION, free_value(), gen_length(), is_constant_int, is_value_constant, is_value_unknown, make_constant(), make_value(), NIL, pips_assert, value_constant, and value_constant_p.
Referenced by EvalIntrinsic().
Constant c is returned as field of value v.
Definition at line 235 of file eval.c.
References constant_call, constant_call_p, constant_float, constant_float_p, constant_int, constant_int_p, entity_local_name(), entity_type, f(), float_type_p(), functional_result, is_constant_float, is_constant_int, is_constant_litteral, is_value_constant, make_constant(), make_value(), NIL, scalar_integer_type_p(), type_functional, type_functional_p, and value_undefined.
Referenced by EvalCall().
value EvalExpression | ( | expression | e | ) |
Evaluate statically an expression.
cproto-generated files
If the expression can be evaluated regardless of the store and regardless of the target machine, and if the expression type is integer or float, return a constant value. Else, return a value unknown.
To accept dependencies on target architecture, set the property "EVAL_SIZEOF" to true.
A new value is always allocated.
If you are not interested in the object value, but simply to the integer value of a constant expression, see expression_integer_value().
This function is not fully implemented. It does not take care of logical (apparently) and string expressions. Some intrinsic operators are not evaluated. Floating point expressions are not as well covered as integer expression.
It is not clear if the evaluation of floating point expressions should be considered target dependent (e.g. for GPU code) or if the IEEE floating point standard is considered strongly enforced.
If information about the store used to evaluate the expression, i.e. preconditions, use precondition_minmax_of_expression()
The algorithm is built on a recursive analysis of the expression structure. Lower level functions are called until basic atoms are reached. The success of basic atom evaluation depend on the atom type:
reference: right now, the evaluation fails because we do not compute predicates on variables, unless the variable type is qualified by const.
call: a call to a user function is not evaluated. a call to an intrinsic function is successfully evaluated if arguments can be evaluated. a call to a constant function is evaluated if its basic type is integer.
range: a range is not evaluated.
Definition at line 108 of file eval.c.
References EvalSyntax(), and expression_syntax.
Referenced by cell_is_xxx_p(), EvalBinaryOp(), EvalConditionalOp(), EvalNaryOp(), EvalSyntax(), EvalUnaryOp(), expression_integer_value(), ExpressionToInt(), extended_integer_constant_expression_p(), extended_integer_constant_expression_p_to_int(), InitializeEnumMemberValues(), MakeDataValueSet(), MakeValueSymbolic(), offset_array_reference(), offset_points_to_cell(), reference_to_points_to_translations(), reference_to_type(), simplified_reference(), subscript_expressions_to_constant_subscript_expressions(), xml_Argument(), xml_AssignArgument(), xml_expression(), and xml_Transposition().
This function tries to evaluate a call to an intrinsic function.
right now, we only try to evaluate unary and binary intrinsic functions, ie. Fortran operators.
e is the intrinsic function.
la is the list of arguments.
la | a |
Definition at line 290 of file eval.c.
References ENTITY_CONDITIONAL_P, EvalBinaryOp(), EvalConditionalOp(), EvalNaryOp(), EvalUnaryOp(), is_value_unknown, IsBinaryOperator(), IsNaryOperator(), IsUnaryOperator(), make_value(), and NIL.
Referenced by EvalCall().
2 operands at least are needed
la | a |
Definition at line 591 of file eval.c.
References assert, CDR, constant_int, constant_int_p, EvalExpression(), EXPRESSION, free_value(), MAP, MAX, MAXIMUM, MIN, MINIMUM, NIL, value_constant, value_constant_p, and value_undefined.
Referenced by EvalIntrinsic().
value EvalSizeofexpression | ( | sizeofexpression | soe | ) |
soe | oe |
Definition at line 210 of file eval.c.
References expression_to_type(), free_type(), make_constant_int(), make_value_constant(), sizeofexpression_expression, sizeofexpression_expression_p, sizeofexpression_type, type_memory_size(), type_undefined, and value_undefined.
Referenced by EvalSyntax(), expression_constant(), expression_to_int(), and integer_expression_to_transformer().
Is it a reference to a const variable?
SG: sizeof is architecture dependant, it is better not to evaluate it by default
Definition at line 113 of file eval.c.
References abort, const_variable_p(), copy_value(), entity_initial, EvalCall(), EvalExpression(), EvalSizeofexpression(), get_bool_property(), is_syntax_application, is_syntax_call, is_syntax_cast, is_syntax_range, is_syntax_reference, is_syntax_sizeofexpression, is_syntax_subscript, is_syntax_va_arg, make_value_unknown(), pips_internal_error, reference_variable, syntax_call, syntax_reference, syntax_sizeofexpression, syntax_tag, value_constant_p, value_expression, value_expression_p, and value_undefined.
Referenced by EvalExpression().
la | a |
Definition at line 349 of file eval.c.
References assert, CAR, constant_int, constant_int_p, EvalExpression(), EXPRESSION, free_value(), is_value_unknown, make_value(), MINUS, NIL, NOT, PLUS, value_constant, and value_constant_p.
Referenced by EvalIntrinsic().
bool expression_integer_value | ( | expression | e, |
intptr_t * | pval | ||
) |
pval | val |
Definition at line 792 of file eval.c.
References constant_int, constant_int_p, EvalExpression(), free_value(), is_int, value_constant, and value_constant_p.
Referenced by array_references_may_conflict_p(), c_dim_string(), c_reference(), cell_reference_compare(), comparable_statements_on_distance_p(), compare_statements_on_distance_to_origin(), conflict_is_a_real_conflict_p(), consecutive_expression_p(), constant_image_p(), constant_reference_to_normalized_constant_reference(), convert_bound_expression(), copy_image_p(), dag_normalize(), declarations_to_dimensions(), dimension_size(), do_group_statement_constant(), do_isolate_statement_preconditions_satisified_p(), do_loop_unroll(), do_loop_unroll_with_prologue(), do_simdizer_init(), do_solve_hardware_constraints_on_volume(), expression_negative_integer_value_p(), fcs_call_flt(), freia_convolution_width_height(), freia_extract_kernel(), full_loop_unroll(), HpfcExpressionToInt(), loop_fully_unrollable_p(), loop_nest_to_offset(), make_condition_from_loop(), make_op_exp(), make_send_receive_conversion(), make_transStat(), MakeCaseStatement(), MakeDimension(), negative_expression_p(), normalize_integer_constant_expression(), NumberOfElements(), old_effects_conflict_p(), points_to_cell_update_last_subscript(), positive_expression_p(), range_count(), region_to_minimal_dimensions(), simd_loop_unroll(), size_of_dimension(), SizeOfIthDimension(), st_dimension_bound_as_string(), st_dimension_reference_as_string(), st_loop(), subscripted_field_list_to_type(), symbolic_tiling_valid_p(), terapix_loop_optimizer(), terapixify_loops(), update_range(), ValueSizeOfDimension(), variable_references_may_conflict_p(), variable_to_string(), words_dimension(), xml_Argument(), xml_AssignArgument(), xml_Bounds(), xml_Bounds_and_Stride(), xml_declarations(), and xml_dim_string().
bool expression_linear_p | ( | expression | e | ) |
returns if e is already normalized and linear.
FI: should be moved into expression.c. Treacherous because the normalization is assumed to have occured earlier.
Definition at line 951 of file eval.c.
References expression_normalized, normalized_linear_p, and normalized_undefined_p.
Referenced by convert_bound_expression(), expression_flt(), reference_filter(), and substitute_and_create().
bool expression_negative_integer_value_p | ( | expression | e | ) |
Return true iff the expression has an integer value known statically and this value is negative.
All leaves of the expression tree must be constant integer.
If preconditions are available, a more general expression can be evaluated using precondition_minmax_of_expression().
Definition at line 814 of file eval.c.
References expression_integer_value(), and intptr_t.
FI: such a function should exist in Linear/arithmetique.
FI: should it return a long long int?
vg | g |
vd | d |
Definition at line 769 of file eval.c.
References assert.
Referenced by binary_to_normalized(), EvalBinaryOp(), and partial_eval_power_operator().
FI: These string constants are defined in ri-util.h and the tokens in ri-util/operator.h.
Definition at line 660 of file eval.c.
References AND, AND_OPERATOR_NAME, ASSIGN, ASSIGN_OPERATOR_NAME, BITWISE_AND, BITWISE_AND_OPERATOR_NAME, BITWISE_OR, BITWISE_OR_OPERATOR_NAME, BITWISE_OR_UPDATE, BITWISE_OR_UPDATE_OPERATOR_NAME, BITWISE_XOR, BITWISE_XOR_OPERATOR_NAME, C_AND_OPERATOR_NAME, C_EQUAL_OPERATOR_NAME, C_GREATER_OR_EQUAL_OPERATOR_NAME, C_LESS_OR_EQUAL_OPERATOR_NAME, C_LESS_THAN_OPERATOR_NAME, C_MODULO_OPERATOR_NAME, C_NON_EQUAL_OPERATOR_NAME, C_OR_OPERATOR_NAME, CAST_OP, DIVIDE_OPERATOR_NAME, DIVIDE_UPDATE, DIVIDE_UPDATE_OPERATOR_NAME, entity_local_name(), EQ, EQUAL_OPERATOR_NAME, EQUIV_OPERATOR_NAME, EQV, GE, GREATER_OR_EQUAL_OPERATOR_NAME, GREATER_THAN_OPERATOR_NAME, GT, IMPLIED_COMPLEX_NAME, IMPLIED_DCOMPLEX_NAME, LE, LEFT_SHIFT, LEFT_SHIFT_OPERATOR_NAME, LEFT_SHIFT_UPDATE, LEFT_SHIFT_UPDATE_OPERATOR_NAME, LESS_OR_EQUAL_OPERATOR_NAME, LESS_THAN_OPERATOR_NAME, LT, MINUS, MINUS_C_OPERATOR_NAME, MINUS_OPERATOR_NAME, MINUS_UPDATE, MINUS_UPDATE_OPERATOR_NAME, MOD, MODULO_OPERATOR_NAME, MULTIPLY_OPERATOR_NAME, MULTIPLY_UPDATE, MULTIPLY_UPDATE_OPERATOR_NAME, NE, NEQV, NON_EQUAL_OPERATOR_NAME, OR, OR_OPERATOR_NAME, PLUS, PLUS_C_OPERATOR_NAME, PLUS_OPERATOR_NAME, PLUS_UPDATE, PLUS_UPDATE_OPERATOR_NAME, POWER, POWER_OPERATOR_NAME, RIGHT_SHIFT, RIGHT_SHIFT_OPERATOR_NAME, RIGHT_SHIFT_UPDATE, RIGHT_SHIFT_UPDATE_OPERATOR_NAME, same_string_p, SLASH, and STAR.
Referenced by EvalIntrinsic().
Definition at line 746 of file eval.c.
References entity_local_name(), MAX0_OPERATOR_NAME, MAX_OPERATOR_NAME, MAXIMUM, MIN0_OPERATOR_NAME, MIN_OPERATOR_NAME, and MINIMUM.
Referenced by EvalIntrinsic().
Definition at line 632 of file eval.c.
References C_NOT_OPERATOR_NAME, entity_local_name(), MINUS, NOT, NOT_OPERATOR_NAME, PLUS, POST_DECREMENT, POST_DECREMENT_OPERATOR_NAME, POST_INCREMENT, POST_INCREMENT_OPERATOR_NAME, PRE_DECREMENT, PRE_DECREMENT_OPERATOR_NAME, PRE_INCREMENT, PRE_INCREMENT_OPERATOR_NAME, same_string_p, UNARY_MINUS_OPERATOR_NAME, and UNARY_PLUS_OPERATOR_NAME.
Referenced by EvalIntrinsic().
bool negative_expression_p | ( | expression | e | ) |
Use constants and type information to decide if the value of sigma(e) is always negative, e.g.
<=0. If this can be proven, true is returned.
false is returned when no decision can be made, i.e. negative_expression_p(e)==false does not imply positive_expression_p(e)
Similar and linked to previous function
We assume an operator is used
We can check a few cases recursively...
Definition at line 896 of file eval.c.
References call_arguments, call_function, CAR, CDR, ENTITY_DIVIDE_P, ENTITY_MINUS_P, ENTITY_MULTIPLY_P, ENTITY_PLUS_P, entity_type, ENTITY_UNARY_MINUS_P, EXPRESSION, expression_integer_value(), expression_syntax, f(), functional_result, gen_length(), intptr_t, overloaded_type_p(), pips_assert, positive_expression_p(), syntax_call, syntax_call_p, type_functional, and type_functional_p.
Referenced by add_index_range_conditions(), C_loop_range(), incrementation_expression_to_increment(), and positive_expression_p().
expression normalize_integer_constant_expression | ( | expression | e | ) |
Allocate a new expression equivalent to e, but constant expressions are evaluated.
This function is used to normalize array dimensions to obtain type equality for a[2] and a[4/2].
Definition at line 1112 of file eval.c.
References copy_expression(), expression_integer_value(), expression_undefined, int_to_expression(), and intptr_t.
Referenced by dimensions_to_normalized_dimensions().
bool positive_expression_p | ( | expression | e | ) |
Use constants and type information to decide if the value of sigma(e) is always positive, e.g.
>=0
Should we define positive_integer_expression_p() and check the expression type?
We assume an operator is used
We can check a few cases recursively...
Definition at line 826 of file eval.c.
References call_arguments, call_function, CAR, CDR, ENTITY_ABS_P, ENTITY_CABS_P, ENTITY_DABS_P, ENTITY_DIVIDE_P, ENTITY_IABS_P, ENTITY_MINUS_P, ENTITY_MULTIPLY_P, ENTITY_PLUS_P, entity_type, ENTITY_UNARY_MINUS_P, EXPRESSION, expression_integer_value(), expression_syntax, f(), functional_result, gen_length(), intptr_t, negative_expression_p(), overloaded_type_p(), pips_assert, reference_variable, syntax_call, syntax_call_p, syntax_reference, syntax_reference_p, type_functional, type_functional_p, ultimate_type(), and unsigned_type_p().
Referenced by add_index_range_conditions(), C_loop_range(), incrementation_expression_to_increment(), and negative_expression_p().
The range count only can be evaluated if the three range expressions are constant and if the increment is non zero.
On failure, a zero count is returned. See also SizeOfRange().
inc>0
pcount | count |
Definition at line 979 of file eval.c.
References expression_integer_value(), intptr_t, range_increment, range_lower, and range_upper.
Referenced by implied_do_reference_number().
expression range_to_expression | ( | range | r, |
enum range_to_expression_mode | mode | ||
) |
computes the distance between the lower bound and the upper bound of the range
r | range to analyse |
mode | wether we compute the distance or count the number of iterations |
Definition at line 963 of file eval.c.
References copy_expression(), DIVIDE_OPERATOR_NAME, int_to_expression(), make_op_exp(), MINUS_OPERATOR_NAME, PLUS_OPERATOR_NAME, range_increment, range_lower, range_to_nbiter_p, and range_upper.
Referenced by add_loop_parallel_threshold(), build_iteration_list(), do_loop_expansion(), do_loop_expansion_init(), sesamify(), simd_loop_unroll(), simdizer_auto_tile(), and terapix_loop_handler().
returns true if v is not NULL and is constant
I make it "static" because it conflicts with a Linear library function. Both functions have the same name but a slightly different behavior. The Linear version returns 0 when a null vector is passed as argument. Francois Irigoin, 16 April 1990
See vect_constant_p() placed in linear/src/contrainte/predicats.c. Seems now OK.
Definition at line 1020 of file eval.c.
References pips_assert, TCST, value_notzero_p, vect_coeff(), and vect_size().
Referenced by vect_product().
returns a Pvecteur equal to (*pv1) * (*pv2) if this product is linear or NULL otherwise.
the result is built from pv1 or pv2 and the other vector is removed.
pv1 | v1 |
pv2 | v2 |
Definition at line 1032 of file eval.c.
References TCST, vect_coeff(), vect_const_p(), vect_multiply(), and vect_rm().