File indexing completed on 2026-05-10 08:43:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef LLVM_IR_CONSTANTRANGELIST_H
0017 #define LLVM_IR_CONSTANTRANGELIST_H
0018
0019 #include "llvm/ADT/APInt.h"
0020 #include "llvm/IR/ConstantRange.h"
0021 #include "llvm/Support/Debug.h"
0022 #include <cstddef>
0023 #include <cstdint>
0024
0025 namespace llvm {
0026
0027 class raw_ostream;
0028
0029
0030 class [[nodiscard]] ConstantRangeList {
0031 SmallVector<ConstantRange, 2> Ranges;
0032
0033 public:
0034 ConstantRangeList() = default;
0035 ConstantRangeList(ArrayRef<ConstantRange> RangesRef) {
0036 assert(isOrderedRanges(RangesRef));
0037 for (const ConstantRange &R : RangesRef) {
0038 assert(empty() || R.getBitWidth() == getBitWidth());
0039 Ranges.push_back(R);
0040 }
0041 }
0042
0043
0044 static bool isOrderedRanges(ArrayRef<ConstantRange> RangesRef);
0045 static std::optional<ConstantRangeList>
0046 getConstantRangeList(ArrayRef<ConstantRange> RangesRef);
0047
0048 ArrayRef<ConstantRange> rangesRef() const { return Ranges; }
0049 SmallVectorImpl<ConstantRange>::iterator begin() { return Ranges.begin(); }
0050 SmallVectorImpl<ConstantRange>::iterator end() { return Ranges.end(); }
0051 SmallVectorImpl<ConstantRange>::const_iterator begin() const {
0052 return Ranges.begin();
0053 }
0054 SmallVectorImpl<ConstantRange>::const_iterator end() const {
0055 return Ranges.end();
0056 }
0057 ConstantRange getRange(unsigned i) const { return Ranges[i]; }
0058
0059
0060 bool empty() const { return Ranges.empty(); }
0061
0062
0063
0064 uint32_t getBitWidth() const { return Ranges.front().getBitWidth(); }
0065
0066
0067 size_t size() const { return Ranges.size(); }
0068
0069
0070 void insert(const ConstantRange &NewRange);
0071 void insert(int64_t Lower, int64_t Upper) {
0072 insert(ConstantRange(APInt(64, Lower, true),
0073 APInt(64, Upper, true)));
0074 }
0075
0076 void subtract(const ConstantRange &SubRange);
0077
0078
0079
0080 ConstantRangeList unionWith(const ConstantRangeList &CRL) const;
0081
0082
0083
0084 ConstantRangeList intersectWith(const ConstantRangeList &CRL) const;
0085
0086
0087 bool operator==(const ConstantRangeList &CRL) const {
0088 return Ranges == CRL.Ranges;
0089 }
0090 bool operator!=(const ConstantRangeList &CRL) const {
0091 return !operator==(CRL);
0092 }
0093
0094
0095 void print(raw_ostream &OS) const;
0096
0097 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0098 void dump() const;
0099 #endif
0100 };
0101
0102 }
0103
0104 #endif