20#ifndef GCC_VECTOR_BUILDER_H
21#define GCC_VECTOR_BUILDER_H
111template<
typename T,
typename Shape,
typename Derived>
122 T
elt (
unsigned int)
const;
145 Derived *
derived () {
return static_cast<Derived *
> (
this); }
153template<
typename T,
typename Shape,
typename Derived>
154inline const Derived *
157 return static_cast<const Derived *
> (
this);
160template<
typename T,
typename Shape,
typename Derived>
165 m_nelts_per_pattern (0)
172template<
typename T,
typename Shape,
typename Derived>
176 return m_npatterns * m_nelts_per_pattern;
181template<
typename T,
typename Shape,
typename Derived>
185 return known_eq (m_npatterns * m_nelts_per_pattern, m_full_nelts);
191template<
typename T,
typename Shape,
typename Derived>
194 unsigned int npatterns,
195 unsigned int nelts_per_pattern)
197 m_full_nelts = full_nelts;
198 m_npatterns = npatterns;
199 m_nelts_per_pattern = nelts_per_pattern;
200 this->reserve (encoded_nelts ());
207template<
typename T,
typename Shape,
typename Derived>
211 if (maybe_ne (m_full_nelts, other.m_full_nelts)
212 || m_npatterns != other.m_npatterns
213 || m_nelts_per_pattern != other.m_nelts_per_pattern)
216 unsigned int nelts = encoded_nelts ();
217 for (
unsigned int i = 0;
i < nelts; ++
i)
218 if (!derived ()->equal_p ((*
this)[
i], other[
i]))
227template<
typename T,
typename Shape,
typename Derived>
242 unsigned int pattern =
i % m_npatterns;
243 unsigned int count =
i / m_npatterns;
244 unsigned int final_i = encoded_nelts () - m_npatterns + pattern;
245 T
final = (*this)[final_i];
248 if (m_nelts_per_pattern <= 2)
252 T prev = (*this)[final_i - m_npatterns];
253 return derived ()->apply_step (
final,
count - 2,
254 derived ()->step (prev,
final));
265template<
typename T,
typename Shape,
typename Derived>
268 bool allow_stepped_p)
270 poly_uint64 full_nelts = Derived::shape_nelts (shape);
272 unsigned int npatterns = Derived::npatterns_of (
vec);
273 unsigned int nelts_per_pattern = Derived::nelts_per_pattern_of (
vec);
274 if (!allow_stepped_p && nelts_per_pattern > 2)
279 nelts_per_pattern = 1;
281 derived ()->new_vector (shape, npatterns, nelts_per_pattern);
293template<
typename T,
typename Shape,
typename Derived>
297 bool allow_stepped_p)
299 poly_uint64 full_nelts = Derived::shape_nelts (shape);
301 &&
known_eq (full_nelts, Derived::nelts_of (vec2)));
321 unsigned int npatterns
323 Derived::npatterns_of (vec2));
324 unsigned int nelts_per_pattern
325 =
MAX (Derived::nelts_per_pattern_of (vec1),
326 Derived::nelts_per_pattern_of (vec2));
327 if (!allow_stepped_p && nelts_per_pattern > 2)
332 nelts_per_pattern = 1;
334 derived ()->new_vector (shape, npatterns, nelts_per_pattern);
343template<
typename T,
typename Shape,
typename Derived>
350 unsigned int npatterns
352 Derived::npatterns_of (vec2));
353 unsigned int nelts_per_pattern
354 =
MAX (Derived::nelts_per_pattern_of (vec1),
355 Derived::nelts_per_pattern_of (vec2));
356 unsigned HOST_WIDE_INT const_nelts;
358 return MIN (npatterns * nelts_per_pattern, const_nelts);
359 return npatterns * nelts_per_pattern;
365template<
typename T,
typename Shape,
typename Derived>
372 unsigned int ndups = 1;
373 for (
int i = start + step;
374 i !=
end && derived ()->equal_p (elt (
i), elt (start));
383template<
typename T,
typename Shape,
typename Derived>
386 unsigned int nelts_per_pattern)
388 unsigned int old_encoded_nelts = encoded_nelts ();
389 unsigned int new_encoded_nelts = npatterns * nelts_per_pattern;
391 unsigned int next = new_encoded_nelts - npatterns;
392 for (
unsigned int i = new_encoded_nelts;
i < old_encoded_nelts; ++
i)
394 derived ()->note_representative (&(*
this)[next], (*
this)[
i]);
396 if (next == new_encoded_nelts)
399 m_npatterns = npatterns;
400 m_nelts_per_pattern = nelts_per_pattern;
406template<
typename T,
typename Shape,
typename Derived>
412 for (
unsigned int i = start;
i <
end - step; ++
i)
413 if (!derived ()->equal_p ((*
this)[
i], (*
this)[
i + step]))
421template<
typename T,
typename Shape,
typename Derived>
427 if (!derived ()->allow_steps_p ())
430 for (
unsigned int i = start + step * 2;
i <
end; ++
i)
432 T elt1 = (*this)[
i - step * 2];
433 T elt2 = (*this)[
i - step];
436 if (!derived ()->integral_p (elt1)
437 || !derived ()->integral_p (elt2)
438 || !derived ()->integral_p (elt3))
441 if (maybe_ne (derived ()->step (elt1, elt2),
442 derived ()->step (elt2, elt3)))
445 if (!derived ()->can_elide_p (elt3))
454template<
typename T,
typename Shape,
typename Derived>
458 if (m_nelts_per_pattern == 1)
462 if (repeating_sequence_p (0, encoded_nelts (), npatterns))
464 reshape (npatterns, 1);
470 if (!encoded_full_vector_p ())
474 if (m_nelts_per_pattern <= 2)
478 if (repeating_sequence_p (npatterns, encoded_nelts (), npatterns))
480 reshape (npatterns, 2);
486 if (!encoded_full_vector_p ())
490 if (m_nelts_per_pattern <= 3)
494 if (stepped_sequence_p (npatterns, encoded_nelts (), npatterns))
496 reshape (npatterns, 3);
507template<
typename T,
typename Shape,
typename Derived>
513 gcc_assert (multiple_p (m_full_nelts, m_npatterns));
518 unsigned HOST_WIDE_INT const_full_nelts;
519 if (m_full_nelts.is_constant (&const_full_nelts)
520 && const_full_nelts <= encoded_nelts ())
522 m_npatterns = const_full_nelts;
523 m_nelts_per_pattern = 1;
534 while (m_nelts_per_pattern > 1
535 && repeating_sequence_p (encoded_nelts () - m_npatterns * 2,
536 encoded_nelts (), m_npatterns))
539 reshape (m_npatterns, m_nelts_per_pattern - 1);
582 while ((m_npatterns & 1) == 0 && try_npatterns (m_npatterns / 2))
593 if (m_nelts_per_pattern == 1
594 && m_full_nelts.is_constant (&const_full_nelts)
595 && this->length () >= const_full_nelts
596 && (m_npatterns & 3) == 0
597 && stepped_sequence_p (m_npatterns / 4, const_full_nelts,
600 reshape (m_npatterns / 4, 3);
601 while ((m_npatterns & 1) == 0 && try_npatterns (m_npatterns / 2))
607 for (
unsigned int i = 1;
i <= m_npatterns / 2; ++
i)
608 if (m_npatterns %
i == 0 && try_npatterns (
i))
C to_constant() const
Definition poly-int.h:590
bool is_constant() const
Definition poly-int.h:557
Definition vector-builder.h:113
bool encoded_full_vector_p() const
Definition vector-builder.h:183
void new_vector(poly_uint64, unsigned int, unsigned int)
Definition vector-builder.h:193
vector_builder()
Definition vector-builder.h:162
bool operator!=(const Derived &x) const
Definition vector-builder.h:126
void reshape(unsigned int, unsigned int)
Definition vector-builder.h:385
Derived * derived()
Definition vector-builder.h:145
bool operator==(const Derived &) const
Definition vector-builder.h:209
const Derived * derived() const
Definition vector-builder.h:155
bool new_binary_operation(Shape, T, T, bool)
Definition vector-builder.h:295
vector_builder & operator=(const vector_builder &)
static unsigned int binary_encoded_nelts(T, T)
Definition vector-builder.h:345
bool new_unary_operation(Shape, T, bool)
Definition vector-builder.h:267
bool stepped_sequence_p(unsigned int, unsigned int, unsigned int)
Definition vector-builder.h:423
poly_uint64 full_nelts() const
Definition vector-builder.h:117
void finalize()
Definition vector-builder.h:509
unsigned int nelts_per_pattern() const
Definition vector-builder.h:119
bool try_npatterns(unsigned int)
Definition vector-builder.h:456
vector_builder(const vector_builder &)
unsigned int encoded_nelts() const
Definition vector-builder.h:174
unsigned int m_nelts_per_pattern
Definition vector-builder.h:150
poly_uint64 m_full_nelts
Definition vector-builder.h:148
bool repeating_sequence_p(unsigned int, unsigned int, unsigned int)
Definition vector-builder.h:408
unsigned int count_dups(int, int, int) const
Definition vector-builder.h:367
unsigned int m_npatterns
Definition vector-builder.h:149
unsigned int npatterns() const
Definition vector-builder.h:118
T elt(unsigned int) const
Definition vector-builder.h:229
static unsigned int count[debug_counter_number_of_counters]
Definition dbgcnt.cc:50
HOST_WIDE_INT least_common_multiple(HOST_WIDE_INT a, HOST_WIDE_INT b)
Definition hwint.cc:187
bool pow2p_hwi(unsigned HOST_WIDE_INT x)
Definition hwint.h:179
i
Definition poly-int.h:776
#define gcc_assert(EXPR)
Definition system.h:814
#define gcc_unreachable()
Definition system.h:841
#define MIN(X, Y)
Definition system.h:396
#define gcc_checking_assert(EXPR)
Definition system.h:821
#define MAX(X, Y)
Definition system.h:397
T * end(vec< T, A, L > *v)
Definition vec.h:457