Polaris: range_util.h Source File

range_util.h

Go to the documentation of this file.
00001 #ifndef _RANGE_UTIL_H
00002 #define _RANGE_UTIL_H
00003 ///
00004 /// file range_util.h
00005 ///
00006 /// \class range_util 
00007 /// \brief Routines for simplifying and manipulating ranges
00008 /// \defgroup Polaris
00009 /// \ingroup Polaris
00010 ///  Range
00011 /// \see range_util.h
00012 /// \see range_util.h
00013 /// \see range_util.cc
00014 ///
00015 /// \endcode
00016 /// \section Overview Overview
00017 /// This file describes the interfaces to a variety of routines for
00018 /// simplifying and manipulating range expressions.  These
00019 /// routines were designed to aid the implementation of the
00020 /// range propagation pass.  However, many of them may also be useful
00021 /// to a user of the range propagation pass.
00022 ///
00023 /// By default, a NULL or omega expression are considered to be the
00024 /// unconstrained range ([-infinity:+infinity]).  Because of this,
00025 /// routines that may return range expressions may also return NULL or
00026 /// Omega.
00027 ///
00028 class RangeAccessor;
00029 class StmtRanges;
00030 
00031 #include "../Collection/Map.h"
00032 #include "../Collection/Set.h"
00033 #include "../Expression/Expression.h"
00034 #include "../Symbol/Symbol.h"
00035 
00036 #include "RangeComparator.h"
00037 
00038 
00039 ///< Routines for combining and manipulating range expressions.
00040 
00041 ///< Description:
00042 ///< Compare the given pair of expressions, using the two given
00043 ///< comparators.  Expression 1 is less than expression 2 if
00044 ///< it is indicated to be less than by both range comparaters.
00045 ///< Other relations are computed similarly.
00046 
00047 Relation
00048 compare(const Expression &expr1, RangeComparator &comparator1,
00049     const Expression &expr2, RangeComparator &comparator2);
00050 
00051 ///< Description
00052 ///< Extract and return all possible ranges from the given logical
00053 ///< expression.  The given expression must be a logical expression
00054 ///< (i.e. made up of relation and .AND., .OR., and .NOT. operators) or
00055 ///< it will be ignored.  If complement_expr is true, this method will
00056 ///< extract the ranges from the complement of this expression.
00057 
00058 Map< Symbol, Set<Expression> > *
00059 extract_ranges(const Expression &expr, bool complement_expr = False);
00060 
00061 ///< Description:
00062 ///< Return the intersection of the two ranges.  That is, return the
00063 ///< range whose lower bound is the larger of the lower bounds of the
00064 ///< two given ranges, and whose upper bound is the smaller of the
00065 ///< upper bounds of the two given ranges.  If one of the given
00066 ///< ranges is NULL, then that range is assumed to be [-Infinity:Infinity].
00067 ///< Similarly, if the resulting range is the [-Infinity:Infinity], the
00068 ///< function returns NULL.
00069 
00070 Expression *
00071 intersect_ranges(const Expression *range1_ref, RangeComparator &comparator1,
00072          const Expression *range2_ref, RangeComparator &comparator2);
00073 
00074 ///< Description:
00075 ///< Return the union of the two ranges.  That is, return the
00076 ///< range whose lower bound is the smaller of the lower bounds of the
00077 ///< two given ranges, and whose upper bound is the larger of the
00078 ///< upper bounds of the two given ranges.  If one of the given
00079 ///< ranges is NULL, then that range is assumed to be [-Infinity:Infinity].
00080 ///< Similarly, if the resulting range is the [-Infinity:Infinity], the
00081 ///< function returns NULL.
00082 
00083 Expression *
00084 union_ranges(const Expression *range1_ref, RangeComparator &comparator1,
00085          const Expression *range2_ref, RangeComparator &comparator2);
00086 
00087 ///< Description:
00088 ///< Perform a widening operator on the given expression and return the
00089 ///< result.  If the lower bounds of the two given expressions are
00090 ///< equal, then the lower bound of the result will be this value,
00091 ///< otherwise the lower bound is -Infinity.  The upper bound is
00092 ///< computed similarly.
00093 
00094 Expression *
00095 widen_range(const Expression *expr_ref, const Expression *widener_ref,
00096         RangeComparator &comparator);
00097 
00098 ///< Description:
00099 ///< Perform a narrowing operator on the given expression and return the
00100 ///< result.  The lower and upper bounds will equal the lower and upper
00101 ///< bounds of the narrower_ref expression unless they are +-Infinity,
00102 ///< in which case would equal the lower and upper bounds of the given
00103 ///< expression.
00104 
00105 Expression *
00106 narrow_range(const Expression *expr_ref, const Expression *narrower_ref,
00107          RangeComparator &comparator);
00108 
00109 
00110 ///< Routines for handling intrinsic expressions.
00111 
00112 ///< Description:
00113 ///< Create a new MIN intrinsic with the given arguments.
00114 
00115 Expression *
00116 min_expr(Expression *e1, Expression *e2, const Symtab &symtab);
00117 
00118 ///< Description:
00119 ///< Create a new MAX intrinsic with the given arguments.
00120 
00121 Expression *
00122 max_expr(Expression *e1, Expression *e2, const Symtab &symtab);
00123 
00124 ///< Description:
00125 ///< Return true if the given expression is a MIN intrinsic
00126 
00127 bool 
00128 is_min(const Expression &e);
00129 
00130 ///< Description:
00131 ///< Return true if the given expression is a MAX intrinsic
00132 
00133 bool 
00134 is_max(const Expression &e);
00135 
00136 ///< Description:
00137 ///< Return true if the given expression is a MOD intrinsic
00138 
00139 bool 
00140 is_mod(const Expression &e);
00141 
00142 ///< Description:
00143 ///< Return true if the given expression is a ABS intrinsic
00144 
00145 bool 
00146 is_abs(const Expression &e);
00147 
00148 ///< Description:
00149 ///< Return true if the given expression is a MIN or MAX intrinsic
00150 
00151 bool 
00152 is_min_or_max(const Expression &e);
00153 
00154 ///< Description:
00155 ///< Return true if the given expression contains a MIN or MAX intrinsic
00156 
00157 bool 
00158 contains_min_or_max(const Expression &e);
00159 
00160 ///< Description:
00161 ///< Change a MIN intrinsic into a MAX intrinsic or vice_versa.
00162 
00163 void 
00164 swap_min_max(Expression &e, const Symtab &symtab);
00165 
00166 ///< Description:
00167 ///< Convert any ABS expressions in the given expression to MAX expressions.
00168 
00169 Expression *
00170 abs_to_max(Expression *e, const Symtab &symtab);
00171 
00172 ///< Description:
00173 ///< Eliminate all terms of MIN or MAX subexpressions of the given
00174 ///< expression which can be proved to never be the minimum or maximum
00175 ///< value respectively.
00176 
00177 Expression *
00178 remove_redundant_min_max_terms(Expression *expr, RangeComparator &comparator);
00179 
00180 ///< Description:
00181 ///< Create a new MOD intrinsic with the given arguments.
00182 
00183 Expression *
00184 mod_expr(Expression *e1, Expression *e2, Symtab &symtab);
00185 
00186 
00187 ///< Printing out ranges.
00188 
00189 ///< Description:
00190 ///< Print the given range expression as an (in)equality for the
00191 ///< given variable
00192 
00193 void
00194 pretty_print_range(ostream &o, const Expression &expr, const Symbol &var);
00195 
00196 
00197 ///< Routines for simplifying expressions containing RangeExprs.
00198 ///<
00199 ///< Meant for internal use of RangeComparator.  Shouldn't be used
00200 ///< externally.
00201 
00202 enum RANGE_HANDLING {
00203     TAKE_RANGE_MIN,
00204     TAKE_RANGE_MAX,
00205     KEEP_WHOLE_RANGE
00206 };
00207 
00208 ///< Description:
00209 ///< Pull the range subexpressions out of the expression.  The
00210 ///< range_handling argument describes exactly how this is done.
00211 ///<   TAKE_RANGE_MIN:   Generate the smallest possible value of the
00212 ///<                     expression. (e.g. 2*[1:A]+B --> 2+B)
00213 ///<   TAKE_RANGE_MAX:   Generate the largest possible value of the
00214 ///<                     expression. (e.g. 2*[1:A]+B --> 2*A+B)
00215 ///<   KEEP_WHOLE_RANGE: Pull the ranges out so that they are outermost.
00216 ///<                     (e.g. 2*[1:A]+B --> [2+B:2*A+B])
00217 ///< If ranges couldn't be pulled out by the expression, or if the
00218 ///< resulting expression becomes unconstrained, the returned
00219 ///< expression is omega.  Warning, ownership of the given expression
00220 ///< is passed to this routine.
00221 
00222 Expression *
00223 pull_ranges_out(Expression * e, RangeComparator &comparator,
00224         RANGE_HANDLING range_handling = KEEP_WHOLE_RANGE);
00225 
00226 ///< Description:
00227 ///< Pull all MIN or MAX intrinsics to the top levels of the expression.
00228 
00229 Expression *
00230 pull_min_max_out(Expression *e, RangeComparator &comparator);
00231 
00232 Expression *
00233 elim_known_facts (Expression *e, RangeComparator &comparator);
00234 
00235 void
00236 copy_expr_ranges (Expression & expr, 
00237           RangeAccessor & r_acc, 
00238           StmtRanges & ranges);
00239 
00240 void
00241 apply_limits(Expression & expr, 
00242          Expression * lower, Expression * upper, 
00243          StmtRanges & ranges, RefSet<Symbol> &set);
00244 
00245 void
00246 set_ranges_for_symbol(Expression & expr, const Symbol & sym, StmtRanges & ranges);
00247 
00248 void
00249 tighten_lower_bound(Expression & expr, const Expression * lower, StmtRanges & ranges, RefSet<Symbol> & set);
00250 
00251 void
00252 tighten_upper_bound(Expression & expr, const Expression * upper, StmtRanges & ranges, RefSet<Symbol> & set);
00253 
00254 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:06:03 2005