summaryrefslogtreecommitdiff
path: root/gcc/vec.h
diff options
context:
space:
mode:
authorTom de Vries <tom@codesourcery.com>2018-05-01 19:16:43 +0000
committerTom de Vries <vries@gcc.gnu.org>2018-05-01 19:16:43 +0000
commitb94c2dc138c60636e3898b04c1026cbb1b868b26 (patch)
treee99c38252e340bc2e91a93e586b47cdf8ba5aaf3 /gcc/vec.h
parent2cc7d3a7da20bcfd854302b1f265c6551b8a3741 (diff)
Add VEC_ORDERED_REMOVE_IF
2018-05-01 Tom de Vries <tom@codesourcery.com> PR other/83786 * vec.h (VEC_ORDERED_REMOVE_IF, VEC_ORDERED_REMOVE_IF_FROM_TO): Define. * vec.c (test_ordered_remove_if): New function. (vec_c_tests): Call test_ordered_remove_if. * dwarf2cfi.c (connect_traces): Use VEC_ORDERED_REMOVE_IF_FROM_TO. * lto-streamer-out.c (prune_offload_funcs): Use VEC_ORDERED_REMOVE_IF. * tree-vect-patterns.c (vect_pattern_recog_1): Use VEC_ORDERED_REMOVE_IF. From-SVN: r259808
Diffstat (limited to 'gcc/vec.h')
-rw-r--r--gcc/vec.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/vec.h b/gcc/vec.h
index 4d2046c04af..2d1f468ca1c 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1028,6 +1028,40 @@ vec<T, A, vl_embed>::ordered_remove (unsigned ix)
}
+/* Remove elements in [START, END) from VEC for which COND holds. Ordering of
+ remaining elements is preserved. This is an O(N) operation. */
+
+#define VEC_ORDERED_REMOVE_IF_FROM_TO(vec, read_index, write_index, \
+ elem_ptr, start, end, cond) \
+ { \
+ gcc_assert ((end) <= (vec).length ()); \
+ for (read_index = write_index = (start); read_index < (end); \
+ ++read_index) \
+ { \
+ elem_ptr = &(vec)[read_index]; \
+ bool remove_p = (cond); \
+ if (remove_p) \
+ continue; \
+ \
+ if (read_index != write_index) \
+ (vec)[write_index] = (vec)[read_index]; \
+ \
+ write_index++; \
+ } \
+ \
+ if (read_index - write_index > 0) \
+ (vec).block_remove (write_index, read_index - write_index); \
+ }
+
+
+/* Remove elements from VEC for which COND holds. Ordering of remaining
+ elements is preserved. This is an O(N) operation. */
+
+#define VEC_ORDERED_REMOVE_IF(vec, read_index, write_index, elem_ptr, \
+ cond) \
+ VEC_ORDERED_REMOVE_IF_FROM_TO ((vec), read_index, write_index, \
+ elem_ptr, 0, (vec).length (), (cond))
+
/* Remove an element from the IXth position of this vector. Ordering of
remaining elements is destroyed. This is an O(1) operation. */