Polaris: range_util.h File Reference

range_util.h File Reference

Go to the source code of this file.

Enumerations

enum  RANGE_HANDLING {
  TAKE_RANGE_MIN,
  TAKE_RANGE_MAX,
  KEEP_WHOLE_RANGE
}

Functions

class Relation compare (const Expression &expr1, RangeComparator &comparator1, const Expression &expr2, RangeComparator &comparator2)
 Description Extract and return all possible ranges from the given logical expression.
Map< Symbol, Set< Expression > > * extract_ranges (const Expression &expr, bool complement_expr=False)
 Description: Return the intersection of the two ranges.
Expressionintersect_ranges (const Expression *range1_ref, RangeComparator &comparator1, const Expression *range2_ref, RangeComparator &comparator2)
 Description: Return the union of the two ranges.
Expressionunion_ranges (const Expression *range1_ref, RangeComparator &comparator1, const Expression *range2_ref, RangeComparator &comparator2)
 Description: Perform a widening operator on the given expression and return the result.
Expressionwiden_range (const Expression *expr_ref, const Expression *widener_ref, RangeComparator &comparator)
 Description: Perform a narrowing operator on the given expression and return the result.
Expressionnarrow_range (const Expression *expr_ref, const Expression *narrower_ref, RangeComparator &comparator)
 Description: Create a new MIN intrinsic with the given arguments.
Expressionmin_expr (Expression *e1, Expression *e2, const Symtab &symtab)
 Description: Create a new MAX intrinsic with the given arguments.
Expressionmax_expr (Expression *e1, Expression *e2, const Symtab &symtab)
 Description: Return true if the given expression is a MIN intrinsic.
bool is_min (const Expression &e)
 Description: Return true if the given expression is a MAX intrinsic.
bool is_max (const Expression &e)
 Description: Return true if the given expression is a MOD intrinsic.
bool is_mod (const Expression &e)
 Description: Return true if the given expression is a ABS intrinsic.
bool is_abs (const Expression &e)
 Description: Return true if the given expression is a MIN or MAX intrinsic.
bool is_min_or_max (const Expression &e)
 Description: Return true if the given expression contains a MIN or MAX intrinsic.
bool contains_min_or_max (const Expression &e)
 Description: Change a MIN intrinsic into a MAX intrinsic or vice_versa.
void swap_min_max (Expression &e, const Symtab &symtab)
 Description: Convert any ABS expressions in the given expression to MAX expressions.
Expressionabs_to_max (Expression *e, const Symtab &symtab)
 Description: Eliminate all terms of MIN or MAX subexpressions of the given expression which can be proved to never be the minimum or maximum value respectively.
Expressionremove_redundant_min_max_terms (Expression *expr, RangeComparator &comparator)
 Description: Create a new MOD intrinsic with the given arguments.
Expressionmod_expr (Expression *e1, Expression *e2, Symtab &symtab)
 Description: Print the given range expression as an (in)equality for the given variable.
void pretty_print_range (ostream &o, const Expression &expr, const Symbol &var)
 Routines for simplifying expressions containing RangeExprs.
Expressionpull_ranges_out (Expression *e, RangeComparator &comparator, RANGE_HANDLING range_handling=KEEP_WHOLE_RANGE)
 Description: Pull all MIN or MAX intrinsics to the top levels of the expression.
Expressionpull_min_max_out (Expression *e, RangeComparator &comparator)
 pull_min_max_out Pull all MIN or MAX intrinsics to the top levels of the expression.
Expressionelim_known_facts (Expression *e, RangeComparator &comparator)
 elim_known_facts
void copy_expr_ranges (Expression &expr, RangeAccessor &r_acc, StmtRanges &ranges)
void apply_limits (Expression &expr, Expression *lower, Expression *upper, StmtRanges &ranges, RefSet< Symbol > &set)
 This routine checks expr for containing exactly one variable, and if it does, applies the [lower:upper] range to it.
void set_ranges_for_symbol (Expression &expr, const Symbol &sym, StmtRanges &ranges)
 This routine extracts ranges for a particular symbol from an expression and sets them in the given StmtRanges object.
void tighten_lower_bound (Expression &expr, const Expression *lower, StmtRanges &ranges, RefSet< Symbol > &set)
void tighten_upper_bound (Expression &expr, const Expression *upper, StmtRanges &ranges, RefSet< Symbol > &set)


Enumeration Type Documentation

enum RANGE_HANDLING
 

Enumeration values:
TAKE_RANGE_MIN 
TAKE_RANGE_MAX 
KEEP_WHOLE_RANGE 

Definition at line 202 of file range_util.h.


Function Documentation

class class Relation compare const Expression expr1,
RangeComparator comparator1,
const Expression expr2,
RangeComparator comparator2
 

Description Extract and return all possible ranges from the given logical expression.

Expression 1 is less than expression 2 if it is indicated to be less than by both range comparaters. Other relations are computed similarly.

The given expression must be a logical expression (i.e. made up of relation and .AND., .OR., and .NOT. operators) or it will be ignored. If complement_expr is true, this method will extract the ranges from the complement of this expression.

Definition at line 2400 of file range_util.cc.

References Relation::is_unknown().

Referenced by intersect_ranges(), and union_ranges().

Map< Symbol, Set<Expression> >* extract_ranges const Expression expr,
bool  complement_expr = False
 

Description: Return the intersection of the two ranges.

That is, return the range whose lower bound is the larger of the lower bounds of the two given ranges, and whose upper bound is the smaller of the upper bounds of the two given ranges. If one of the given ranges is NULL, then that range is assumed to be [-Infinity:Infinity]. Similarly, if the resulting range is the [-Infinity:Infinity], the function returns NULL.

Expression* intersect_ranges const Expression range1_ref,
RangeComparator comparator1,
const Expression range2_ref,
RangeComparator comparator2
 

Description: Return the union of the two ranges.

... New range has one element.

... New range has no elements.

Definition at line 2165 of file range_util.cc.

References _join_ranges(), _pull_out_common_min_max(), Expression::clone(), Expression::compare(), compare(), constant(), convert_to_range(), expr_expand_substituted(), RangeExpr::grab_lb(), RangeExpr::grab_ub(), Relation::is_circular(), is_empty_range(), Relation::is_equal(), Relation::is_greater_equal(), Relation::is_greater_than(), Relation::is_less_equal(), Relation::is_unknown(), RangeExpr::lb(), max_expr(), min(), min_expr(), OMEGA_OP, simplify(), and RangeExpr::ub().

Referenced by GSAFullRangeDict::_get_range_ref(), SSAFullRangeDict::_get_range_ref(), and RangeAccessor::get_range_ref().

Expression* union_ranges const Expression range1_ref,
RangeComparator comparator1,
const Expression range2_ref,
RangeComparator comparator2
 

Description: Perform a widening operator on the given expression and return the result.

... New range has one element.

Definition at line 2250 of file range_util.cc.

References _join_ranges(), _pull_out_common_min_max(), Expression::clone(), compare(), convert_to_range(), expr_expand_substituted(), RangeExpr::grab_lb(), RangeExpr::grab_ub(), RangeExpr::has_lb(), RangeExpr::has_ub(), is_empty_range(), Relation::is_equal(), Relation::is_greater_equal(), Relation::is_less_equal(), RangeExpr::lb(), max_expr(), min(), min_expr(), OMEGA_OP, simplify(), and RangeExpr::ub().

Referenced by RangeAccessor::get_range_ref().

Expression* widen_range const Expression expr_ref,
const Expression widener_ref,
RangeComparator comparator
 

Description: Perform a narrowing operator on the given expression and return the result.

... New range has one element.

Definition at line 2318 of file range_util.cc.

References _join_ranges(), _pull_out_common_min_max(), Expression::clone(), convert_to_range(), RangeExpr::grab_lb(), RangeExpr::has_lb(), RangeExpr::has_ub(), is_empty_range(), RangeExpr::lb(), OMEGA_OP, RangeExpr::ub(), and widen_range().

Referenced by widen_range().

Expression* narrow_range const Expression expr_ref,
const Expression narrow_ref,
RangeComparator comparator
 

Description: Create a new MIN intrinsic with the given arguments.

... New range has one element.

Definition at line 2360 of file range_util.cc.

References _join_ranges(), _pull_out_common_min_max(), Expression::clone(), convert_to_range(), RangeExpr::grab_lb(), RangeExpr::lb(), narrow_range(), OMEGA_OP, RANGE_OP, and RangeExpr::ub().

Referenced by narrow_range().

Expression* min_expr Expression e1,
Expression e2,
const Symtab symtab
 

Description: Create a new MAX intrinsic with the given arguments.

Definition at line 1317 of file range_util.cc.

References comma(), INFINITY_OP, intrinsic_call(), and OMEGA_OP.

Referenced by _join_ranges(), intersect_ranges(), and union_ranges().

Expression* max_expr Expression e1,
Expression e2,
const Symtab symtab
 

Description: Return true if the given expression is a MIN intrinsic.

Definition at line 1346 of file range_util.cc.

References comma(), INFINITY_OP, intrinsic_call(), and OMEGA_OP.

Referenced by _join_ranges(), abs_to_max(), intersect_ranges(), and union_ranges().

bool is_min const Expression e  ) 
 

Description: Return true if the given expression is a MAX intrinsic.

Definition at line 1402 of file range_util.cc.

References e, Expression::intrinsic(), INTRINSIC_CALL_OP, Symbol::name_ref(), Expression::op(), and Expression::symbol().

Referenced by _elim_known_facts(), _is_neg_min(), _pull_out_common_min_max1(), RangeComparator::signz(), and swap_min_max().

bool is_max const Expression e  ) 
 

Description: Return true if the given expression is a MOD intrinsic.

Definition at line 1413 of file range_util.cc.

References e, Expression::intrinsic(), INTRINSIC_CALL_OP, Symbol::name_ref(), Expression::op(), and Expression::symbol().

Referenced by _combine_min_max(), _elim_known_facts(), _is_pos_max(), _pull_out_common_min_max1(), remove_redundant_min_max_terms(), and RangeComparator::signz().

bool is_mod const Expression e  ) 
 

Description: Return true if the given expression is a ABS intrinsic.

Definition at line 1424 of file range_util.cc.

References e, Expression::intrinsic(), INTRINSIC_CALL_OP, Symbol::name_ref(), Expression::op(), and Expression::symbol().

Referenced by RangeComparator::signz().

bool is_abs const Expression e  ) 
 

Description: Return true if the given expression is a MIN or MAX intrinsic.

Definition at line 1435 of file range_util.cc.

References e, Expression::intrinsic(), INTRINSIC_CALL_OP, Symbol::name_ref(), Expression::op(), and Expression::symbol().

Referenced by abs_to_max(), and RangeComparator::signz().

bool is_min_or_max const Expression e  ) 
 

Description: Return true if the given expression contains a MIN or MAX intrinsic.

Definition at line 1448 of file range_util.cc.

References e, Expression::intrinsic(), INTRINSIC_CALL_OP, Symbol::name_ref(), Expression::op(), and Expression::symbol().

Referenced by _find_visit_order(), _multiply_out_divs_for_var1(), _p_mm_o_of_add(), _p_mm_o_of_divide(), _p_mm_o_of_exp(), _p_mm_o_of_mult(), _pull_in_add_expr(), _pull_in_div_expr(), _pull_in_exp_expr(), _pull_in_mult_expr(), _pull_min_max_out_top(), _substitute_mono_var(), _substitute_mono_var1(), contains_min_or_max(), remove_redundant_min_max_terms(), and swap_min_max().

bool contains_min_or_max const Expression e  ) 
 

Description: Change a MIN intrinsic into a MAX intrinsic or vice_versa.

Definition at line 1465 of file range_util.cc.

References Expression::arg_list(), contains_min_or_max(), Iterator< T >::current(), e, is_min_or_max(), and Iterator< T >::valid().

Referenced by contains_min_or_max(), and StmtRanges::simplify_min_max().

void swap_min_max Expression e,
const Symtab symtab
 

Description: Convert any ABS expressions in the given expression to MAX expressions.

Definition at line 1513 of file range_util.cc.

References e, Expression::intrinsic(), is_min(), is_min_or_max(), and Expression::symbol().

Referenced by _pull_in_div_expr(), _pull_in_exp_expr(), _pull_in_mult_expr(), and _substitute_mono_var1().

Expression* abs_to_max Expression e,
const Symtab symtab
 

Description: Eliminate all terms of MIN or MAX subexpressions of the given expression which can be proved to never be the minimum or maximum value respectively.

Definition at line 1485 of file range_util.cc.

References abs_to_max(), Expression::arg_list(), Mutator< T >::assign(), Expression::clone(), constant(), e, List< T >::grab(), List< T >::ins_first(), is_abs(), max_expr(), Expression::parameters_guarded(), Mutator< T >::pull(), simplify(), unary_minus(), and Iterator< T >::valid().

Referenced by abs_to_max().

Expression* remove_redundant_min_max_terms Expression expr,
RangeComparator comparator
 

Description: Create a new MOD intrinsic with the given arguments.

Definition at line 1928 of file range_util.cc.

References Expression::arg_list(), Mutator< T >::assign(), Iterator< T >::current(), Mutator< T >::del(), List< T >::entries(), List< T >::first_ref(), List< T >::grab(), List< T >::ins_last(), Relation::is_greater_equal(), Relation::is_less_equal(), is_max(), is_min_or_max(), Expression::parameters_guarded(), Mutator< T >::pull(), remove_redundant_min_max_terms(), and Iterator< T >::valid().

Referenced by remove_redundant_min_max_terms(), and StmtRanges::simplify_min_max().

Expression* mod_expr Expression e1,
Expression e2,
Symtab symtab
 

Description: Print the given range expression as an (in)equality for the given variable.

Definition at line 1375 of file range_util.cc.

References comma(), INTEGER_TYPE, Symbol::intrinsic(), intrinsic_call(), IS_INTRINSIC, make_type(), mod_expr(), NOT_EXTERNAL, NOT_FORMAL, NOT_INTRINSIC, and Expression::type().

Referenced by _multiply_out_div(), _remove_truncates1(), and mod_expr().

void pretty_print_range ostream &  o,
const Expression expr,
const Symbol var
 

Routines for simplifying expressions containing RangeExprs.

Meant for internal use of RangeComparator. Shouldn't be used externally.

Definition at line 2742 of file range_util.cc.

References RangeExpr::has_lb(), RangeExpr::has_ub(), RangeExpr::lb(), OMEGA_OP, RANGE_OP, and RangeExpr::ub().

Referenced by BaseStmtRanges::pretty_print(), ControlRangeDict::pretty_print(), GSAControlRangeDict::pretty_print(), GSAFullRangeDict::pretty_print(), RangeAccessor::pretty_print(), SSAControlRangeDict::pretty_print(), SSAFullRangeDict::pretty_print(), GSAControlRangeData::print(), and SSAControlRangeData::print().

Expression* pull_ranges_out Expression e,
RangeComparator comparator,
RANGE_HANDLING  range_handling = KEEP_WHOLE_RANGE
 

Description: Pull all MIN or MAX intrinsics to the top levels of the expression.

Expression* pull_min_max_out Expression e,
RangeComparator comparator
 

pull_min_max_out Pull all MIN or MAX intrinsics to the top levels of the expression.

... Handle the base cases. (Expression leaves and ranges.)

... Pull out the min's or max's from the expression's arguments.

... Pull out the min or max expressions from the expression itself.

Definition at line 1900 of file range_util.cc.

References _pull_min_max_out_top(), Expression::arg_list(), Mutator< T >::assign(), e, List< T >::entries(), Mutator< T >::pull(), pull_min_max_out(), and Iterator< T >::valid().

Referenced by _remove_mods_with_var(), and pull_min_max_out().

Expression* elim_known_facts Expression e,
RangeComparator comparator
 

elim_known_facts

This routine uses a static recursive routine to turn relational expressions inside the given expression into .TRUE. or .FALSE., based on the facts passed in the RangeComparator. If the truth of a given relational expression cannot be determined, it is unchanged by this routine.

Definition at line 2772 of file range_util.cc.

References _elim_known_facts(), e, and simplify().

Referenced by AIRangeDict::elim_known_facts().

void copy_expr_ranges Expression expr,
RangeAccessor r_acc,
StmtRanges ranges
 

Definition at line 2962 of file range_util.cc.

References Expression::clone(), copy_expr_ranges(), and is_scalar_id().

Referenced by copy_expr_ranges().

void apply_limits Expression expr,
Expression lower,
Expression upper,
StmtRanges ranges,
RefSet< Symbol > &  set
 

This routine checks expr for containing exactly one variable, and if it does, applies the [lower:upper] range to it.

If the variable already has an upper or lower bound associated with it, then apply the limits to that bound.

... Now, if expr is just an ID_OP, assert that its range bounds are ... within the bounds of the declaration, or if one of its range bounds ... is an InfinityExpr, change that to the declaration bounds.

... Don't allow infinite recursion

... Check for Infinity in lower bound

... if not, constrain the lower bound to be within the declaration bound

... Check for infinity in upper bound

... if not, constrain the upper bound to be within the declaration bound

... Range is a single value - KDIM: kmax

Definition at line 3003 of file range_util.cc.

References and(), apply_limits(), RefSet< T >::clear(), Expression::clone(), ge(), ID_OP, INFINITY_OP, INTEGER_CONSTANT_OP, is_ID_OP(), le(), Expression::op(), RANGE_OP, set_ranges_for_symbol(), substitute_var(), tighten_lower_bound(), and tighten_upper_bound().

Referenced by _add_subscript_constraints_to_ranges(), and apply_limits().

void set_ranges_for_symbol Expression expr,
const Symbol sym,
StmtRanges ranges
 

This routine extracts ranges for a particular symbol from an expression and sets them in the given StmtRanges object.

It doesn't disturb the ranges of any other variable in the StmtRanges object.

... Get the existing range

... Get the existing range

Definition at line 3093 of file range_util.cc.

References Expression::clone(), Iterator< T >::current(), extract_ranges(), ProtoMap< S, T >::find_ref(), INFINITY_OP, Expression::op(), RANGE_OP, and Iterator< T >::valid().

Referenced by apply_limits().

void tighten_lower_bound Expression expr,
const Expression lower,
StmtRanges ranges,
RefSet< Symbol > &  set
 

... Don't allow infinite recursion

... Range is a single value - KDIM: kmax

Definition at line 3179 of file range_util.cc.

References ID_OP, INFINITY_OP, INTEGER_CONSTANT_OP, is_ID_OP(), Expression::op(), RANGE_OP, tighten_lower_bound(), and tighten_upper_bound().

Referenced by apply_limits(), tighten_lower_bound(), and tighten_upper_bound().

void tighten_upper_bound Expression expr,
const Expression upper,
StmtRanges ranges,
RefSet< Symbol > &  set
 

... Don't allow infinite recursion

... Range is a single value - KDIM: kmax

Definition at line 3135 of file range_util.cc.

References ID_OP, INFINITY_OP, INTEGER_CONSTANT_OP, is_ID_OP(), Expression::op(), RANGE_OP, tighten_lower_bound(), and tighten_upper_bound().

Referenced by apply_limits(), tighten_lower_bound(), and tighten_upper_bound().

 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:25 2005