Added LLVM copyright header (for lack of a better term).
[oota-llvm.git] / include / llvm / Support / ConstantRange.h
1 //===-- llvm/Support/ConstantRange.h - Represent a range --------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // Represent a range of possible values that may occur when the program is run
11 // for an integral value.  This keeps track of a lower and upper bound for the
12 // constant, which MAY wrap around the end of the numeric range.  To do this, it
13 // keeps track of a [lower, upper) bound, which specifies an interval just like
14 // STL iterators.  When used with boolean values, the following are important
15 // ranges (other integral ranges use min/max values for special range values):
16 //
17 //  [F, F) = {}     = Empty set
18 //  [T, F) = {T}
19 //  [F, T) = {F}
20 //  [T, T) = {F, T} = Full set
21 //
22 //===----------------------------------------------------------------------===//
23
24 #ifndef LLVM_SUPPORT_CONSTANT_RANGE_H
25 #define LLVM_SUPPORT_CONSTANT_RANGE_H
26
27 #include "Support/DataTypes.h"
28 #include <iosfwd>
29 class ConstantIntegral;
30 class Type;
31
32 class ConstantRange {
33   ConstantIntegral *Lower, *Upper;
34  public:
35   /// Initialize a full (the default) or empty set for the specified type.
36   ///
37   ConstantRange(const Type *Ty, bool isFullSet = true);
38   
39   /// Initialize a range of values explicitly... this will assert out if
40   /// Lower==Upper and Lower != Min or Max for its type (or if the two constants
41   /// have different types)
42   ///
43   ConstantRange(ConstantIntegral *Lower, ConstantIntegral *Upper);
44   
45   /// Initialize a set of values that all satisfy the condition with C.
46   ///
47   ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C);
48   
49   /// getLower - Return the lower value for this range...
50   ///
51   ConstantIntegral *getLower() const { return Lower; }
52
53   /// getUpper - Return the upper value for this range...
54   ///
55   ConstantIntegral *getUpper() const { return Upper; }
56
57   /// getType - Return the LLVM data type of this range.
58   ///
59   const Type *getType() const;
60   
61   /// isFullSet - Return true if this set contains all of the elements possible
62   /// for this data-type
63   ///
64   bool isFullSet() const;
65   
66   /// isEmptySet - Return true if this set contains no members.
67   ///
68   bool isEmptySet() const;
69
70   /// isWrappedSet - Return true if this set wraps around the top of the range,
71   /// for example: [100, 8)
72   ///
73   bool isWrappedSet() const;
74   
75   /// getSingleElement - If this set contains a single element, return it,
76   /// otherwise return null.
77   ///
78   ConstantIntegral *getSingleElement() const;
79   
80   /// isSingleElement - Return true if this set contains exactly one member.
81   ///
82   bool isSingleElement() const { return getSingleElement() != 0; }
83
84   /// getSetSize - Return the number of elements in this set.
85   ///
86   uint64_t getSetSize() const;
87
88   /// operator== - Return true if this range is equal to another range.
89   ///
90   bool operator==(const ConstantRange &CR) const {
91     return Lower == CR.Lower && Upper == CR.Upper;
92   }
93   bool operator!=(const ConstantRange &CR) const {
94     return !operator==(CR);
95   }
96
97   /// intersect - Return the range that results from the intersection of this
98   /// range with another range.  The resultant range is pruned as much as
99   /// possible, but there may be cases where elements are included that are in
100   /// one of the sets but not the other.  For example: [100, 8) intersect [3,
101   /// 120) yields [3, 120)
102   ///
103   ConstantRange intersectWith(const ConstantRange &CR) const;
104
105   /// union - Return the range that results from the union of this range with
106   /// another range.  The resultant range is guaranteed to include the elements
107   /// of both sets, but may contain more.  For example, [3, 9) union [12,15) is
108   /// [3, 15), which includes 9, 10, and 11, which were not included in either
109   /// set before.
110   ///
111   ConstantRange unionWith(const ConstantRange &CR) const;
112
113   /// print - Print out the bounds to a stream...
114   ///
115   void print(std::ostream &OS) const;
116
117   /// dump - Allow printing from a debugger easily...
118   ///
119   void dump() const;
120 };
121
122 inline std::ostream &operator<<(std::ostream &OS, const ConstantRange &CR) {
123   CR.print(OS);
124   return OS;
125 }
126
127 #endif