Polaris: BaseStmtRanges.h Source File

BaseStmtRanges.h

Go to the documentation of this file.
00001 ///
00002 ///
00003 /// file BaseStmtRanges.h
00004 ///
00005 #ifndef _BASE_STMT_RANGES_H
00006 #define _BASE_STMT_RANGES_H
00007 ///
00008 /// \class BaseStmtRanges 
00009 /// \brief Abstract collection of ranges for a single statement
00010 /// \defgroup Polaris
00011 /// \ingroup Polaris
00012 ///  Range
00013 /// \see BaseStmtRanges.h
00014 /// \see BaseStmtRanges.h
00015 /// \see BaseStmtRanges.cc
00016 ///
00017 /// \endcode
00018 /// \section Overview Overview
00019 /// A BaseStmtRanges object is a collection of ranges for each program
00020 /// variable for a single statement.  This class is abstract in that
00021 /// it doesn't actually describe how these ranges are stored.
00022 ///
00023 /// \endcode
00024 /// \section Description Description
00025 /// This object holds all the ranges of a single statement.  However,
00026 /// the data structures that hold these ranges are not provided.  The
00027 /// user must create a subclass that holds these ranges as well as
00028 /// provide the interfaces to these data structures, (i.e, get_range_ref(),
00029 /// etc.).
00030 /// 
00031 /// Several methods have been provided to aid the computation of ranges
00032 /// in a ProgramUnit.  The method extract_ranges() will extract
00033 /// all the ranges that can be determined from a logical expression and
00034 /// intersect (AND) these ranges with the ranges in the BaseStmtRanges.
00035 /// The method union_constriants() unions (ORs) the ranges of two
00036 /// BaseStmtRangess.  The method subst_in_ranges() can be used to replace
00037 /// all accesses of a certain variable in all ranges with some other
00038 /// value.  This method is useful for handling variable modifications by
00039 /// statements.  Finally, a set of low level methods are provided for
00040 /// accessing and modifying individual ranges in a BaseStmtRanges.
00041 ///
00042 #include "../Collection/RefSet.h"
00043 #include "../Symbol/Symbol.h"
00044 ///
00045 #include "RangeComparator.h"
00046 ///
00047 class Expression;
00048 class Symtab;
00049 
00050 class BaseStmtRanges : public RangeComparator {
00051 public:
00052     BaseStmtRanges(const Symtab &symtab);
00053     BaseStmtRanges(const BaseStmtRanges &other);
00054     virtual ~BaseStmtRanges();
00055 
00056     void extract_ranges(const Expression &expr,
00057                         bool complement_expr = false);
00058     ///< Extract all possible ranges from the given logical expression and
00059     ///< intersect these ranges with the current constraints.  The given
00060     ///< expression must be a logical expression (i.e. made up of relation
00061     ///< and .AND., .OR., and .NOT. operators) or it will be ignored.  If
00062     ///< complement_expr is true, this method will extract the ranges from
00063     ///< the complement of this expression.
00064 
00065     void subst_in_ranges(const Symbol &var, const Expression *subst_expr);
00066     ///< Replace all uses of variable var in all of the ranges in myself
00067     ///< with the given substitution expression.  If subst_expr is NULL,
00068     ///< the variable references are instead replaced by an unconstrained
00069     ///< range. ([-Inf:Inf])
00070 
00071     void union_ranges(BaseStmtRanges &other);
00072     ///< Union all ranges in the other range dictionary with myself.
00073 
00074     void widen_ranges(BaseStmtRanges &other);
00075     ///< Widen all ranges in the other range dictionary with myself.
00076 
00077     void widen_some_ranges(BaseStmtRanges &other,
00078                const RefSet<Symbol> &vars_to_widen);
00079     ///< Widen the ranges of the given vars in the other range
00080     ///< dictionary with myself.
00081 
00082     void narrow_ranges(BaseStmtRanges &other);
00083     ///< Narrow all ranges in the other constraint dictionary with myself.
00084 
00085     virtual int operator == (const BaseStmtRanges &other) const;
00086     virtual int operator != (const BaseStmtRanges &other) const;
00087     ///< Value comparisons of stmt range dictionaries.
00088 
00089     void widen_range(const Symbol &var, const Expression &range);
00090     ///< Widen the range of the given variable access with the
00091     ///< given range.
00092 
00093     void narrow_range(const Symbol &var, const Expression &range);
00094     ///< Narrow the range of the given variable access with the given
00095     ///< range.
00096 
00097     BaseStmtRanges &operator = (const BaseStmtRanges &other);
00098     ///< Completely copy the contents of the other constraint dictionary
00099     ///< into myself.
00100 
00101     const Expression *get_range_ref(const Symbol &var);
00102     ///< Return the range associated with the given variable.  If the
00103     ///< variable doesn't have an associated range, return 0;
00104 
00105     virtual int entries() const = 0;
00106     ///< Return the number of constrained variable entries in myself.
00107 
00108     virtual void clear() = 0;
00109     ///< Discard all constraints within myself.
00110 
00111     virtual RefSet<Symbol> *range_vars() const = 0;
00112     ///< Return the set of variables that have ranges.
00113 
00114     virtual void print(ostream & out) const;
00115     ///< Print out the constraint dictionary.
00116 
00117     void pretty_print(ostream & out) const;
00118     ///< Print out the constraint dictionary in a more user-readable
00119     ///< manner.
00120 
00121     virtual int structures_OK() const;
00122     ///< Methods required by Listable
00123 
00124 protected:
00125     virtual const Expression *_get_range_ref_c(const Symbol &var) const = 0;
00126     ///< Like get_range_ref(), but is a const method.
00127 };
00128 
00129 #endif
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:05:41 2005