1 //===-- llvm/Support/ConstantRange.h - Represent a range --------*- C++ -*-===//
3 // Represent a range of possible values that may occur when the program is run
4 // for an integral value. This keeps track of a lower and upper bound for the
5 // constant, which MAY wrap around the end of the numeric range. To do this, it
6 // keeps track of a [lower, upper) bound, which specifies an interval just like
7 // STL iterators. When used with boolean values, the following are important
8 // ranges (other integral ranges use min/max values for special range values):
10 // [F, F) = {} = Empty set
13 // [T, T) = {F, T} = Full set
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_SUPPORT_CONSTANT_RANGE_H
18 #define LLVM_SUPPORT_CONSTANT_RANGE_H
20 #include "Support/DataTypes.h"
21 class ConstantIntegral;
25 ConstantIntegral *Lower, *Upper;
27 /// Initialize a full (the default) or empty set for the specified type.
29 ConstantRange(const Type *Ty, bool isFullSet = true);
31 /// Initialize a range of values explicitly... this will assert out if
32 /// Lower==Upper and Lower != Min or Max for its type (or if the two constants
33 /// have different types)
35 ConstantRange(ConstantIntegral *Lower, ConstantIntegral *Upper);
37 /// Initialize a set of values that all satisfy the condition with C.
39 ConstantRange(unsigned SetCCOpcode, ConstantIntegral *C);
41 /// getLower - Return the lower value for this range...
43 ConstantIntegral *getLower() const { return Lower; }
45 /// getUpper - Return the upper value for this range...
47 ConstantIntegral *getUpper() const { return Upper; }
49 /// getType - Return the LLVM data type of this range.
51 const Type *getType() const;
53 /// isFullSet - Return true if this set contains all of the elements possible
54 /// for this data-type
56 bool isFullSet() const;
58 /// isEmptySet - Return true if this set contains no members.
60 bool isEmptySet() const;
62 /// isWrappedSet - Return true if this set wraps around the top of the range,
63 /// for example: [100, 8)
65 bool isWrappedSet() const;
67 /// getSingleElement - If this set contains a single element, return it,
68 /// otherwise return null.
70 ConstantIntegral *getSingleElement() const;
72 /// isSingleElement - Return true if this set contains exactly one member.
74 bool isSingleElement() const { return getSingleElement() != 0; }
76 /// getSetSize - Return the number of elements in this set.
78 uint64_t getSetSize() const;
80 /// intersect - Return the range that results from the intersection of this
81 /// range with another range. The resultant range is pruned as much as
82 /// possible, but there may be cases where elements are included that are in
83 /// one of the sets but not the other. For example: [100, 8) intersect [3,
84 /// 120) yields [3, 120)
86 ConstantRange intersectWith(const ConstantRange &CR) const;
88 /// union - Return the range that results from the union of this range with
89 /// another range. The resultant range is guaranteed to include the elements
90 /// of both sets, but may contain more. For example, [3, 9) union [12,15) is
91 /// [3, 15), which includes 9, 10, and 11, which were not included in either
94 ConstantRange unionWith(const ConstantRange &CR) const;