Commit 32500433 by Richard Biener Committed by Richard Biener

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
parent 24fcf4bc
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.
2014-01-17 Jan Hubicka <hubicka@ucw.cz> 2014-01-17 Jan Hubicka <hubicka@ucw.cz>
PR c++/57945 PR c++/57945
......
...@@ -476,6 +476,7 @@ public: ...@@ -476,6 +476,7 @@ public:
void unordered_remove (unsigned); void unordered_remove (unsigned);
void block_remove (unsigned, unsigned); void block_remove (unsigned, unsigned);
void qsort (int (*) (const void *, const void *)); 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; unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
static size_t embedded_size (unsigned); static size_t embedded_size (unsigned);
void embedded_init (unsigned, unsigned = 0); void embedded_init (unsigned, unsigned = 0);
...@@ -938,7 +939,43 @@ template<typename T, typename A> ...@@ -938,7 +939,43 @@ template<typename T, typename A>
inline void inline void
vec<T, A, vl_embed>::qsort (int (*cmp) (const void *, const 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: ...@@ -1174,6 +1211,7 @@ public:
void unordered_remove (unsigned); void unordered_remove (unsigned);
void block_remove (unsigned, unsigned); void block_remove (unsigned, unsigned);
void qsort (int (*) (const void *, const void *)); 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; unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
bool using_auto_storage () const; bool using_auto_storage () const;
...@@ -1635,6 +1673,20 @@ vec<T, va_heap, vl_ptr>::qsort (int (*cmp) (const void *, const void *)) ...@@ -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 /* Find and return the first position in which OBJ could be inserted
without changing the ordering of this vector. LESSTHAN is a without changing the ordering of this vector. LESSTHAN is a
function that returns true if the first argument is strictly less function that returns true if the first argument is strictly less
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment