diff options
Diffstat (limited to 'include/llvm/IR/ConstantRange.h')
-rw-r--r-- | include/llvm/IR/ConstantRange.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/include/llvm/IR/ConstantRange.h b/include/llvm/IR/ConstantRange.h index 9458fa9f5c86..27a9b1364448 100644 --- a/include/llvm/IR/ConstantRange.h +++ b/include/llvm/IR/ConstantRange.h @@ -38,6 +38,8 @@ namespace llvm { +class MDNode; + /// This class represents a range of values. /// class ConstantRange { @@ -166,6 +168,14 @@ public: return nullptr; } + /// If this set contains all but a single element, return it, otherwise return + /// null. + const APInt *getSingleMissingElement() const { + if (Lower == Upper + 1) + return &Upper; + return nullptr; + } + /// Return true if this set contains exactly one member. /// bool isSingleElement() const { return getSingleElement() != nullptr; } @@ -223,6 +233,15 @@ public: /// ConstantRange unionWith(const ConstantRange &CR) const; + /// Return a new range representing the possible values resulting + /// from an application of the specified cast operator to this range. \p + /// BitWidth is the target bitwidth of the cast. For casts which don't + /// change bitwidth, it must be the same as the source bitwidth. For casts + /// which do change bitwidth, the bitwidth must be consistent with the + /// requested cast and source bitwidth. + ConstantRange castOp(Instruction::CastOps CastOp, + uint32_t BitWidth) const; + /// Return a new range in the specified integer type, which must /// be strictly larger than the current type. The returned range will /// correspond to the possible range of values if the source range had been @@ -250,9 +269,19 @@ public: ConstantRange sextOrTrunc(uint32_t BitWidth) const; /// Return a new range representing the possible values resulting + /// from an application of the specified binary operator to an left hand side + /// of this range and a right hand side of \p Other. + ConstantRange binaryOp(Instruction::BinaryOps BinOp, + const ConstantRange &Other) const; + + /// Return a new range representing the possible values resulting /// from an addition of a value in this range and a value in \p Other. ConstantRange add(const ConstantRange &Other) const; + /// Return a new range representing the possible values resulting from a + /// known NSW addition of a value in this range and \p Other constant. + ConstantRange addWithNoSignedWrap(const APInt &Other) const; + /// Return a new range representing the possible values resulting /// from a subtraction of a value in this range and a value in \p Other. ConstantRange sub(const ConstantRange &Other) const; @@ -318,6 +347,11 @@ inline raw_ostream &operator<<(raw_ostream &OS, const ConstantRange &CR) { return OS; } +/// Parse out a conservative ConstantRange from !range metadata. +/// +/// E.g. if RangeMD is !{i32 0, i32 10, i32 15, i32 20} then return [0, 20). +ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD); + } // End llvm namespace #endif |