aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2014-02-12 16:01:03 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2014-02-12 16:01:03 +0000
commit3a938d756bad13643f32468815db337d3e5c1821 (patch)
tree4573e5bb36217b90a92b4e79ed9e8f3631260871 /gcc
parentad0188be2152e741de7aa4b839a3e8b72b930dfa (diff)
downloadgcc-3a938d756bad13643f32468815db337d3e5c1821.zip
gcc-3a938d756bad13643f32468815db337d3e5c1821.tar.gz
gcc-3a938d756bad13643f32468815db337d3e5c1821.tar.bz2
vec.c (vec_prefix::calculate_allocation): Move as inline variant to vec.h.
2014-02-12 Richard Biener <rguenther@suse.de> * vec.c (vec_prefix::calculate_allocation): Move as inline variant to vec.h. (vec_prefix::calculate_allocation_1): New out-of-line version. * vec.h (vec_prefix::calculate_allocation_1): Declare. (vec_prefix::m_has_auto_buf): Rename to ... (vec_prefix::m_using_auto_storage): ... this. (vec_prefix::calculate_allocation): Inline the easy cases and dispatch to calculate_allocation_1 which doesn't need the prefix address. (va_heap::reserve): Use gcc_checking_assert. (vec<T, A, vl_embed>::embedded_init): Add argument to initialize m_using_auto_storage. (auto_vec): Change m_vecpfx member to a vec<T, va_heap, vl_embed> member and adjust. (vec<T, va_heap, vl_ptr>::reserve): Remove redundant check. (vec<T, va_heap, vl_ptr>::release): Avoid casting. (vec<T, va_heap, vl_ptr>::using_auto_storage): Simplify. From-SVN: r207729
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog20
-rw-r--r--gcc/vec.c51
-rw-r--r--gcc/vec.h49
3 files changed, 64 insertions, 56 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c33da78..cf01571 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,25 @@
2014-02-12 Richard Biener <rguenther@suse.de>
+ * vec.c (vec_prefix::calculate_allocation): Move as
+ inline variant to vec.h.
+ (vec_prefix::calculate_allocation_1): New out-of-line version.
+ * vec.h (vec_prefix::calculate_allocation_1): Declare.
+ (vec_prefix::m_has_auto_buf): Rename to ...
+ (vec_prefix::m_using_auto_storage): ... this.
+ (vec_prefix::calculate_allocation): Inline the easy cases
+ and dispatch to calculate_allocation_1 which doesn't need the
+ prefix address.
+ (va_heap::reserve): Use gcc_checking_assert.
+ (vec<T, A, vl_embed>::embedded_init): Add argument to initialize
+ m_using_auto_storage.
+ (auto_vec): Change m_vecpfx member to a vec<T, va_heap, vl_embed>
+ member and adjust.
+ (vec<T, va_heap, vl_ptr>::reserve): Remove redundant check.
+ (vec<T, va_heap, vl_ptr>::release): Avoid casting.
+ (vec<T, va_heap, vl_ptr>::using_auto_storage): Simplify.
+
+2014-02-12 Richard Biener <rguenther@suse.de>
+
* gcse.c (compute_transp): break from loop over canon_modify_mem_list
when we found a dependence.
diff --git a/gcc/vec.c b/gcc/vec.c
index bd0af2d..c0cd338 100644
--- a/gcc/vec.c
+++ b/gcc/vec.c
@@ -171,46 +171,27 @@ vec_prefix::release_overhead (void)
/* Calculate the number of slots to reserve a vector, making sure that
- RESERVE slots are free. If EXACT grow exactly, otherwise grow
- exponentially. PFX is the control data for the vector. */
+ it is of at least DESIRED size by growing ALLOC exponentially. */
unsigned
-vec_prefix::calculate_allocation (vec_prefix *pfx, unsigned reserve,
- bool exact)
+vec_prefix::calculate_allocation_1 (unsigned alloc, unsigned desired)
{
- unsigned alloc = 0;
- unsigned num = 0;
-
- if (pfx)
- {
- alloc = pfx->m_alloc;
- num = pfx->m_num;
- }
- else if (!reserve)
- gcc_unreachable ();
-
/* We must have run out of room. */
- gcc_assert (alloc - num < reserve);
-
- if (exact)
- /* Exact size. */
- alloc = num + reserve;
+ gcc_assert (alloc < desired);
+
+ /* Exponential growth. */
+ if (!alloc)
+ alloc = 4;
+ else if (alloc < 16)
+ /* Double when small. */
+ alloc = alloc * 2;
else
- {
- /* Exponential growth. */
- if (!alloc)
- alloc = 4;
- else if (alloc < 16)
- /* Double when small. */
- alloc = alloc * 2;
- else
- /* Grow slower when large. */
- alloc = (alloc * 3 / 2);
-
- /* If this is still too small, set it to the right size. */
- if (alloc < num + reserve)
- alloc = num + reserve;
- }
+ /* Grow slower when large. */
+ alloc = (alloc * 3 / 2);
+
+ /* If this is still too small, set it to the right size. */
+ if (alloc < desired)
+ alloc = desired;
return alloc;
}
diff --git a/gcc/vec.h b/gcc/vec.h
index cb4ba63..5873023 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -218,6 +218,7 @@ struct vec_prefix
void register_overhead (size_t, const char *, int, const char *);
void release_overhead (void);
static unsigned calculate_allocation (vec_prefix *, unsigned, bool);
+ static unsigned calculate_allocation_1 (unsigned, unsigned);
/* Note that vec_prefix should be a base class for vec, but we use
offsetof() on vector fields of tree structures (e.g.,
@@ -233,10 +234,25 @@ struct vec_prefix
friend struct va_heap;
unsigned m_alloc : 31;
- unsigned m_has_auto_buf : 1;
+ unsigned m_using_auto_storage : 1;
unsigned m_num;
};
+/* Calculate the number of slots to reserve a vector, making sure that
+ RESERVE slots are free. If EXACT grow exactly, otherwise grow
+ exponentially. PFX is the control data for the vector. */
+
+inline unsigned
+vec_prefix::calculate_allocation (vec_prefix *pfx, unsigned reserve,
+ bool exact)
+{
+ if (exact)
+ return (pfx ? pfx->m_num : 0) + reserve;
+ else if (!pfx)
+ return MAX (4, reserve);
+ return calculate_allocation_1 (pfx->m_alloc, pfx->m_num + reserve);
+}
+
template<typename, typename, typename> struct vec;
/* Valid vector layouts
@@ -283,7 +299,7 @@ va_heap::reserve (vec<T, va_heap, vl_embed> *&v, unsigned reserve, bool exact
{
unsigned alloc
= vec_prefix::calculate_allocation (v ? &v->m_vecpfx : 0, reserve, exact);
- gcc_assert (alloc);
+ gcc_checking_assert (alloc);
if (GATHER_STATISTICS && v)
v->m_vecpfx.release_overhead ();
@@ -479,7 +495,7 @@ public:
T *bsearch (const void *key, int (*compar)(const void *, const void *));
unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
static size_t embedded_size (unsigned);
- void embedded_init (unsigned, unsigned = 0);
+ void embedded_init (unsigned, unsigned = 0, unsigned = 0);
void quick_grow (unsigned len);
void quick_grow_cleared (unsigned len);
@@ -1037,10 +1053,10 @@ vec<T, A, vl_embed>::embedded_size (unsigned alloc)
template<typename T, typename A>
inline void
-vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num)
+vec<T, A, vl_embed>::embedded_init (unsigned alloc, unsigned num, unsigned aut)
{
m_vecpfx.m_alloc = alloc;
- m_vecpfx.m_has_auto_buf = 0;
+ m_vecpfx.m_using_auto_storage = aut;
m_vecpfx.m_num = num;
}
@@ -1234,10 +1250,8 @@ class auto_vec : public vec<T, va_heap>
public:
auto_vec ()
{
- m_header.m_alloc = N;
- m_header.m_has_auto_buf = 1;
- m_header.m_num = 0;
- this->m_vec = reinterpret_cast<vec<T, va_heap, vl_embed> *> (&m_header);
+ m_auto.embedded_init (MAX (N, 2), 0, 1);
+ this->m_vec = &m_auto;
}
~auto_vec ()
@@ -1246,10 +1260,8 @@ public:
}
private:
- friend class vec<T, va_heap, vl_ptr>;
-
- vec_prefix m_header;
- T m_data[N];
+ vec<T, va_heap, vl_embed> m_auto;
+ T m_data[MAX (N - 1, 1)];
};
/* auto_vec is a sub class of vec whose storage is released when it is
@@ -1396,7 +1408,7 @@ template<typename T>
inline bool
vec<T, va_heap, vl_ptr>::reserve (unsigned nelems, bool exact MEM_STAT_DECL)
{
- if (!nelems || space (nelems))
+ if (space (nelems))
return false;
/* For now play a game with va_heap::reserve to hide our auto storage if any,
@@ -1462,7 +1474,7 @@ vec<T, va_heap, vl_ptr>::release (void)
if (using_auto_storage ())
{
- static_cast<auto_vec<T, 1> *> (this)->m_header.m_num = 0;
+ m_vec->m_vecpfx.m_num = 0;
return;
}
@@ -1705,12 +1717,7 @@ template<typename T>
inline bool
vec<T, va_heap, vl_ptr>::using_auto_storage () const
{
- if (!m_vec->m_vecpfx.m_has_auto_buf)
- return false;
-
- const vec_prefix *auto_header
- = &static_cast<const auto_vec<T, 1> *> (this)->m_header;
- return reinterpret_cast<vec_prefix *> (m_vec) == auto_header;
+ return m_vec->m_vecpfx.m_using_auto_storage;
}
#if (GCC_VERSION >= 3000)