LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ConstantRange.h

Go to the documentation of this file.
00001 //===-- llvm/Support/ConstantRange.h - Represent a range --------*- C++ -*-===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // Represent a range of possible values that may occur when the program is run
00011 // for an integral value.  This keeps track of a lower and upper bound for the
00012 // constant, which MAY wrap around the end of the numeric range.  To do this, it
00013 // keeps track of a [lower, upper) bound, which specifies an interval just like
00014 // STL iterators.  When used with boolean values, the following are important
00015 // ranges (other integral ranges use min/max values for special range values):
00016 //
00017 //  [F, F) = {}     = Empty set
00018 //  [T, F) = {T}
00019 //  [F, T) = {F}
00020 //  [T, T) = {F, T} = Full set
00021 //
00022 //===----------------------------------------------------------------------===//
00023 
00024 #ifndef LLVM_SUPPORT_CONSTANT_RANGE_H
00025 #define LLVM_SUPPORT_CONSTANT_RANGE_H
00026 
00027 #include "llvm/Support/DataTypes.h"
00028 #include <iosfwd>
00029 
00030 namespace llvm {
00031 class Constant;
00032 class ConstantIntegral;
00033 class ConstantInt;
00034 class Type;
00035 
00036 class ConstantRange {
00037   ConstantIntegral *Lower, *Upper;
00038  public:
00039   /// Initialize a full (the default) or empty set for the specified type.
00040   ///
00041   ConstantRange(const Type *Ty, bool isFullSet = true);
00042   
00043   /// Initialize a range to hold the single specified value.
00044   ///
00045   ConstantRange(Constant *Value);
00046 
00047   /// Initialize a range of values explicitly... this will assert out if
00048   /// Lower==Upper and Lower != Min or Max for its type, if the two constants
00049   /// have different types, or if the constant are not integral values.
00050   ///
00051   ConstantRange(Constant *Lower, Constant *Upper);
00052   
00053   /// Initialize a set of values that all satisfy the condition with C.
00054   ///
00055   ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C);
00056 
00057   /// getLower - Return the lower value for this range...
00058   ///
00059   ConstantIntegral *getLower() const { return Lower; }
00060 
00061   /// getUpper - Return the upper value for this range...
00062   ///
00063   ConstantIntegral *getUpper() const { return Upper; }
00064 
00065   /// getType - Return the LLVM data type of this range.
00066   ///
00067   const Type *getType() const;
00068   
00069   /// isFullSet - Return true if this set contains all of the elements possible
00070   /// for this data-type
00071   ///
00072   bool isFullSet() const;
00073   
00074   /// isEmptySet - Return true if this set contains no members.
00075   ///
00076   bool isEmptySet() const;
00077 
00078   /// isWrappedSet - Return true if this set wraps around the top of the range,
00079   /// for example: [100, 8)
00080   ///
00081   bool isWrappedSet() const;
00082 
00083   /// contains - Return true if the specified value is in the set.
00084   ///
00085   bool contains(ConstantInt *Val) const;
00086   
00087   /// getSingleElement - If this set contains a single element, return it,
00088   /// otherwise return null.
00089   ///
00090   ConstantIntegral *getSingleElement() const;
00091   
00092   /// isSingleElement - Return true if this set contains exactly one member.
00093   ///
00094   bool isSingleElement() const { return getSingleElement() != 0; }
00095 
00096   /// getSetSize - Return the number of elements in this set.
00097   ///
00098   uint64_t getSetSize() const;
00099 
00100   /// operator== - Return true if this range is equal to another range.
00101   ///
00102   bool operator==(const ConstantRange &CR) const {
00103     return Lower == CR.Lower && Upper == CR.Upper;
00104   }
00105   bool operator!=(const ConstantRange &CR) const {
00106     return !operator==(CR);
00107   }
00108 
00109   /// subtract - Subtract the specified constant from the endpoints of this
00110   /// constant range.
00111   ConstantRange subtract(ConstantInt *CI) const;
00112 
00113   /// intersect - Return the range that results from the intersection of this
00114   /// range with another range.  The resultant range is pruned as much as
00115   /// possible, but there may be cases where elements are included that are in
00116   /// one of the sets but not the other.  For example: [100, 8) intersect [3,
00117   /// 120) yields [3, 120)
00118   ///
00119   ConstantRange intersectWith(const ConstantRange &CR) const;
00120 
00121   /// union - Return the range that results from the union of this range with
00122   /// another range.  The resultant range is guaranteed to include the elements
00123   /// of both sets, but may contain more.  For example, [3, 9) union [12,15) is
00124   /// [3, 15), which includes 9, 10, and 11, which were not included in either
00125   /// set before.
00126   ///
00127   ConstantRange unionWith(const ConstantRange &CR) const;
00128 
00129   /// zeroExtend - Return a new range in the specified integer type, which must
00130   /// be strictly larger than the current type.  The returned range will
00131   /// correspond to the possible range of values if the source range had been
00132   /// zero extended.
00133   ConstantRange zeroExtend(const Type *Ty) const;
00134 
00135   /// truncate - Return a new range in the specified integer type, which must be
00136   /// strictly smaller than the current type.  The returned range will
00137   /// correspond to the possible range of values if the source range had been
00138   /// truncated to the specified type.
00139   ConstantRange truncate(const Type *Ty) const;
00140 
00141   /// print - Print out the bounds to a stream...
00142   ///
00143   void print(std::ostream &OS) const;
00144 
00145   /// dump - Allow printing from a debugger easily...
00146   ///
00147   void dump() const;
00148 };
00149 
00150 inline std::ostream &operator<<(std::ostream &OS, const ConstantRange &CR) {
00151   CR.print(OS);
00152   return OS;
00153 }
00154 
00155 } // End llvm namespace
00156 
00157 #endif