LLVM: include/llvm/Transforms/Vectorize/SandboxVectorizer/Interval.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#ifndef LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_INSTRINTERVAL_H
21#define LLVM_TRANSFORMS_VECTORIZE_SANDBOXVECTORIZER_INSTRINTERVAL_H
22
27#include
28#include <type_traits>
29
31
32
34 T *I;
35 IntervalType &R;
36
37public:
43
46 assert(&R == &Other.R && "Iterators belong to different regions!");
47 return Other.I == I;
48 }
50 return !(*this == Other);
51 }
53 assert(I != nullptr && "already at end()!");
54 I = I->getNextNode();
55 return *this;
56 }
58 auto ItCopy = *this;
59 ++*this;
60 return ItCopy;
61 }
63
64 I = I != nullptr ? I->getPrevNode() : R.bottom();
65 return *this;
66 }
68 auto ItCopy = *this;
69 --*this;
70 return ItCopy;
71 }
72 template <typename HT = std::enable_if<std::is_same<T, T *&>::value>>
77};
78
80 T *Top;
81 T *Bottom;
82
83public:
84 Interval() : Top(nullptr), Bottom(nullptr) {}
85 Interval(T *Top, T *Bottom) : Top(Top), Bottom(Bottom) {
86 assert((Top == Bottom || Top->comesBefore(Bottom)) &&
87 "Top should come before Bottom!");
88 }
90 assert(!Elems.empty() && "Expected non-empty Elems!");
91 Top = Elems[0];
92 Bottom = Elems[0];
94 if (I->comesBefore(Top))
95 Top = I;
96 else if (Bottom->comesBefore(I))
97 Bottom = I;
98 }
99 }
101 assert(((Top == nullptr && Bottom == nullptr) ||
102 (Top != nullptr && Bottom != nullptr)) &&
103 "Either none or both should be null");
104 return Top == nullptr;
105 }
108 return false;
109 return (Top == I || Top->comesBefore(I)) &&
110 (I == Bottom || I->comesBefore(Bottom));
111 }
112
114 return Top == Elm->getNextNode() || Bottom == Elm->getPrevNode();
115 }
116 T *top() const { return Top; }
118
122 return iterator(Bottom != nullptr ? Bottom->getNextNode() : nullptr, *this);
123 }
128 return iterator(Bottom != nullptr ? Bottom->getNextNode() : nullptr,
129 const_cast<Interval &>(*this));
130 }
131
133 return Top == Other.Top && Bottom == Other.Bottom;
134 }
135
137
138
143
145
146
147
148
149
152 return *this;
153 if (Other.empty())
155
156
157
158 if (Bottom->comesBefore(Other.Top) || Other.Bottom->comesBefore(Top))
160
161
162
163 auto NewTopI = Top->comesBefore(Other.Top) ? Other.Top : Top;
164 auto NewBottomI = Bottom->comesBefore(Other.Bottom) ? Bottom : Other.Bottom;
165 return Interval(NewTopI, NewBottomI);
166 }
167
168
169
170
171
174 return {*this};
175 if (Other.empty())
176 return {*this};
177 if (*this == Other)
181
182 if (Top != Intersection.Top)
183 Result.emplace_back(Top, Intersection.Top->getPrevNode());
184
185 if (Intersection.Bottom != Bottom)
186 Result.emplace_back(Intersection.Bottom->getNextNode(), Bottom);
187 return Result;
188 }
189
190
192 auto Diff = *this - Other;
193 assert(Diff.size() == 1 && "Expected a single interval!");
194 return Diff[0];
195 }
196
197
198
199
200
204 if (Other.empty())
205 return *this;
206 auto *NewTop = Top->comesBefore(Other.Top) ? Top : Other.Top;
207 auto *NewBottom = Bottom->comesBefore(Other.Bottom) ? Other.Bottom : Bottom;
208 return {NewTop, NewBottom};
209 }
210
211
212
213 template
214 std::enable_if_t<std::is_same<HelperT, Instruction>::value, void>
217 assert(I->getIterator() != BeforeIt && "Can't move `I` before itself!");
218
219
220 if (std::next(I->getIterator()) == BeforeIt)
221 return;
222
223 T *NewTop = Top->getIterator() == BeforeIt ? I
224 : I == Top ? Top->getNextNode()
225 : Top;
226 T *NewBottom = std::next(Bottom->getIterator()) == BeforeIt ? I
227 : I == Bottom ? Bottom->getPrevNode()
228 : Bottom;
229 Top = NewTop;
230 Bottom = NewBottom;
231 }
232
233#ifndef NDEBUG
236#endif
237};
238
239
241
242}
243
244#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_TEMPLATE_ABI
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
std::pair< uint64_t, uint64_t > Interval
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
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.
A simple iterator for iterating the interval.
Definition Interval.h:33
bool operator!=(const IntervalIterator &Other) const
Definition Interval.h:49
IntervalIterator & operator--()
Definition Interval.h:62
T & operator*()
Definition Interval.h:73
IntervalIterator(T *I, IntervalType &R)
Definition Interval.h:44
std::bidirectional_iterator_tag iterator_category
Definition Interval.h:42
T & operator*() const
Definition Interval.h:76
T & reference
Definition Interval.h:41
value_type * pointer
Definition Interval.h:40
bool operator==(const IntervalIterator &Other) const
Definition Interval.h:45
IntervalIterator operator++(int)
Definition Interval.h:57
T value_type
Definition Interval.h:39
std::ptrdiff_t difference_type
Definition Interval.h:38
IntervalIterator & operator++()
Definition Interval.h:52
IntervalIterator operator--(int)
Definition Interval.h:67
Interval(T *Top, T *Bottom)
Definition Interval.h:85
iterator end()
Definition Interval.h:121
SmallVector< Interval, 2 > operator-(const Interval &Other)
Difference operation. This returns up to two intervals.
Definition Interval.h:172
bool operator==(const Interval &Other) const
Equality.
Definition Interval.h:132
bool touches(T *Elm) const
\Returns true if Elm is right before the top or right after the bottom.
Definition Interval.h:113
Interval getUnionInterval(const Interval &Other)
\Returns a single interval that spans across both this and Other.
Definition Interval.h:201
LLVM_DUMP_METHOD void dump() const
bool contains(T *I) const
Definition Interval.h:106
Interval getSingleDiff(const Interval &Other)
\Returns the interval difference this - Other.
Definition Interval.h:191
bool operator!=(const Interval &Other) const
Inequality.
Definition Interval.h:136
Interval(ArrayRef< T * > Elems)
Definition Interval.h:89
IntervalIterator< T, Interval > iterator
Definition Interval.h:119
T * bottom() const
Definition Interval.h:117
iterator end() const
Definition Interval.h:127
iterator begin()
Definition Interval.h:120
bool empty() const
Definition Interval.h:100
bool disjoint(const Interval &Other) const
\Returns true if this and Other have nothing in common.
T * top() const
Definition Interval.h:116
bool comesBefore(const Interval &Other) const
\Returns true if this interval comes before Other in program order.
Definition Interval.h:139
void print(raw_ostream &OS) const
iterator begin() const
Definition Interval.h:124
Interval intersection(const Interval &Other) const
\Returns the intersection between this and Other.
Definition Interval.h:150
std::enable_if_t< std::is_same< HelperT, Instruction >::value, void > notifyMoveInstr(HelperT *I, decltype(I->getIterator()) BeforeIt)
Update the interval when I is about to be moved before Before.
Definition Interval.h:215
Interval()
Definition Interval.h:84
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.