LLVM: lib/IR/ConstantRangeList.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10#include
11
12using namespace llvm;
13
15 if (RangesRef.empty())
16 return true;
17 auto Range = RangesRef[0];
19 return false;
20 for (unsigned i = 1; i < RangesRef.size(); i++) {
21 auto CurRange = RangesRef[i];
22 auto PreRange = RangesRef[i - 1];
23 if (CurRange.getLower().sge(CurRange.getUpper()) ||
24 CurRange.getLower().sle(PreRange.getUpper()))
25 return false;
26 }
27 return true;
28}
29
30std::optional
33 return std::nullopt;
35}
36
39 return;
40 assert(!NewRange.isFullSet() && "Do not support full set");
42
43 if (empty() || Ranges.back().getUpper().slt(NewRange.getLower())) {
44 Ranges.push_back(NewRange);
45 return;
46 }
47
49
50 if (NewRange.getUpper().slt(Ranges.front().getLower())) {
51 Ranges.insert(Ranges.begin(), NewRange);
52 return;
53 }
54
57 return a.getLower().slt(b.getLower());
58 });
59 if (LowerBound != Ranges.end() && LowerBound->contains(NewRange))
60 return;
61
62
64 Ranges.erase(LowerBound, Ranges.end());
65
66 if (!Ranges.empty() && NewRange.getLower().sle(Ranges.back().getUpper())) {
67 APInt NewLower = Ranges.back().getLower();
70 Ranges.back() = ConstantRange(NewLower, NewUpper);
71 } else {
72 Ranges.push_back(NewRange);
73 }
74 for (auto Iter = ExistingTail.begin(); Iter != ExistingTail.end(); Iter++) {
75 if (Ranges.back().getUpper().slt(Iter->getLower())) {
76 Ranges.push_back(*Iter);
77 } else {
78 APInt NewLower = Ranges.back().getLower();
80 APIntOps::smax(Iter->getUpper(), Ranges.back().getUpper());
81 Ranges.back() = ConstantRange(NewLower, NewUpper);
82 }
83 }
84}
85
88 return;
89 assert(!SubRange.isFullSet() && "Do not support full set");
92
93 if (Ranges.back().getUpper().sle(SubRange.getLower()))
94 return;
95 if (SubRange.getUpper().sle(Ranges.front().getLower()))
96 return;
97
99 auto AppendRangeIfNonEmpty = [&Result](APInt Start, APInt End) {
100 if (Start.slt(End))
102 };
103 for (auto &Range : Ranges) {
106
107
108
109
110 Result.push_back(Range);
113
114
115
116
117
122
123
124
125 continue;
128
129
130
132 } else {
133
134
135
139 }
140 }
141
142 Ranges = Result;
143}
144
147
149 return CRL;
151 return *this;
152
154 "ConstantRangeList bitwidths don't agree!");
155
157 size_t i = 0, j = 0;
158
159
161 if (Ranges[i].getLower().slt(CRL.Ranges[j].getLower())) {
162 PreviousRange = Ranges[i++];
163 } else {
164 PreviousRange = CRL.Ranges[j++];
165 }
166
167
168
169
170
171 auto UnionAndUpdateRange = [&PreviousRange,
173 if (PreviousRange.getUpper().slt(CR.getLower())) {
174 Result.Ranges.push_back(PreviousRange);
175 PreviousRange = CR;
176 } else {
180 }
181 };
182 while (i < size() || j < CRL.size()) {
183 if (j == CRL.size() ||
184 (i < size() && Ranges[i].getLower().slt(CRL.Ranges[j].getLower()))) {
185
186 UnionAndUpdateRange(Ranges[i++]);
187 } else {
188
189 UnionAndUpdateRange(CRL.Ranges[j++]);
190 }
191 }
192 Result.Ranges.push_back(PreviousRange);
193 return Result;
194}
195
198
200 return *this;
202 return CRL;
203
205 "ConstantRangeList bitwidths don't agree!");
206
208 size_t i = 0, j = 0;
209 while (i < size() && j < CRL.size()) {
210 auto &Range = this->Ranges[i];
211 auto &OtherRange = CRL.Ranges[j];
212
213
214
215
216
217
218
221 if (Start.slt(End))
223
224
225
226
228 i++;
229 else
230 j++;
231 }
232 return Result;
233}
234
238 });
239}
240
241#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
244 dbgs() << '\n';
245}
246#endif
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
bool sle(const APInt &RHS) const
Signed less or equal comparison.
bool slt(const APInt &RHS) const
Signed less than comparison.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
This class represents a list of constant ranges.
void subtract(const ConstantRange &SubRange)
uint32_t getBitWidth() const
Get the bit width of this ConstantRangeList.
void insert(const ConstantRange &NewRange)
Insert a new range to Ranges and keep the list ordered.
bool empty() const
Return true if this list contains no members.
void print(raw_ostream &OS) const
Print out the ranges to a stream.
static std::optional< ConstantRangeList > getConstantRangeList(ArrayRef< ConstantRange > RangesRef)
ConstantRangeList()=default
size_t size() const
Return the number of ranges in this ConstantRangeList.
ConstantRangeList intersectWith(const ConstantRangeList &CRL) const
Return the range list that results from the intersection of this ConstantRangeList with another Const...
ConstantRangeList unionWith(const ConstantRangeList &CRL) const
Return the range list that results from the union of this ConstantRangeList with another ConstantRang...
static bool isOrderedRanges(ArrayRef< ConstantRange > RangesRef)
This class represents a range of values.
const APInt & getLower() const
Return the lower value for this range.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
bool isEmptySet() const
Return true if this set contains no members.
const APInt & getUpper() const
Return the upper value for this range.
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
const APInt & smin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
const APInt & smax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be signed.
This is an optimization pass for GlobalISel generic memory operations.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...