aboutsummaryrefslogtreecommitdiff
path: root/gcc/vec.h
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2014-01-17 14:40:11 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2014-01-17 14:40:11 +0000
commit32500433ce102db43dc4c43ce97820e0d2615fb3 (patch)
tree2287fbea3d96ba177cef06d334d06ad153958a8c /gcc/vec.h
parent24fcf4bc0c6ac701e9c2e1ae1f92908c50afd11f (diff)
downloadgcc-32500433ce102db43dc4c43ce97820e0d2615fb3.zip
gcc-32500433ce102db43dc4c43ce97820e0d2615fb3.tar.gz
gcc-32500433ce102db43dc4c43ce97820e0d2615fb3.tar.bz2
re PR tree-optimization/46590 (long compile time with -O2 and many loops)
2014-01-17 Richard Biener <rguenther@suse.de> PR tree-optimization/46590 * vec.h (vec<>::bseach): New member function implementing binary search according to C89 bsearch. (vec<>::qsort): Avoid calling ::qsort for vectors with sizes 0 or 1. * tree-ssa-loop-im.c (struct mem_ref): Make stored member a bitmap pointer again. Make accesses_in_loop a flat array. (mem_ref_obstack): New global. (outermost_indep_loop): Adjust for mem_ref->stored changes. (mark_ref_stored): Likewise. (ref_indep_loop_p_2): Likewise. (set_ref_stored_in_loop): New helper function. (mem_ref_alloc): Allocate mem_refs on the mem_ref_obstack obstack. (memref_free): Adjust. (record_mem_ref_loc): Simplify. (gather_mem_refs_stmt): Adjust. (sort_locs_in_loop_postorder_cmp): New function. (analyze_memory_references): Sort accesses_in_loop after loop postorder number. (find_ref_loc_in_loop_cmp): New function. (for_all_locs_in_loop): Find relevant cluster of locs in accesses_in_loop and iterate without recursion. (execute_sm): Avoid uninit warning. (struct ref_always_accessed): Simplify. (ref_always_accessed::operator ()): Likewise. (ref_always_accessed_p): Likewise. (tree_ssa_lim_initialize): Initialize mem_ref_obstack, compute loop postorder numbers here. (tree_ssa_lim_finalize): Free mem_ref_obstack and loop postorder numbers. From-SVN: r206709
Diffstat (limited to 'gcc/vec.h')
-rw-r--r--gcc/vec.h54
1 files changed, 53 insertions, 1 deletions
diff --git a/gcc/vec.h b/gcc/vec.h
index 5d148f9..4e8e3b8 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -476,6 +476,7 @@ public:
void unordered_remove (unsigned);
void block_remove (unsigned, unsigned);
void qsort (int (*) (const void *, const void *));
+ 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);
@@ -938,7 +939,43 @@ template<typename T, typename A>
inline void
vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const void *))
{
- ::qsort (address (), length (), sizeof (T), cmp);
+ if (length () > 1)
+ ::qsort (address (), length (), sizeof (T), cmp);
+}
+
+
+/* Search the contents of the sorted vector with a binary search.
+ CMP is the comparison function to pass to bsearch. */
+
+template<typename T, typename A>
+inline T *
+vec<T, A, vl_embed>::bsearch (const void *key,
+ int (*compar) (const void *, const void *))
+{
+ const void *base = this->address ();
+ size_t nmemb = this->length ();
+ size_t size = sizeof (T);
+ /* The following is a copy of glibc stdlib-bsearch.h. */
+ size_t l, u, idx;
+ const void *p;
+ int comparison;
+
+ l = 0;
+ u = nmemb;
+ while (l < u)
+ {
+ idx = (l + u) / 2;
+ p = (const void *) (((const char *) base) + (idx * size));
+ comparison = (*compar) (key, p);
+ if (comparison < 0)
+ u = idx;
+ else if (comparison > 0)
+ l = idx + 1;
+ else
+ return (T *)const_cast<void *>(p);
+ }
+
+ return NULL;
}
@@ -1174,6 +1211,7 @@ public:
void unordered_remove (unsigned);
void block_remove (unsigned, unsigned);
void qsort (int (*) (const void *, const void *));
+ T *bsearch (const void *key, int (*compar)(const void *, const void *));
unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
bool using_auto_storage () const;
@@ -1635,6 +1673,20 @@ vec<T, va_heap, vl_ptr>::qsort (int (*cmp) (const void *, const void *))
}
+/* Search the contents of the sorted vector with a binary search.
+ CMP is the comparison function to pass to bsearch. */
+
+template<typename T>
+inline T *
+vec<T, va_heap, vl_ptr>::bsearch (const void *key,
+ int (*cmp) (const void *, const void *))
+{
+ if (m_vec)
+ return m_vec->bsearch (key, cmp);
+ return NULL;
+}
+
+
/* Find and return the first position in which OBJ could be inserted
without changing the ordering of this vector. LESSTHAN is a
function that returns true if the first argument is strictly less