belive: Change all users of _value_strictly_dominates() to _value_strictly_dominates_...
[libfirm] / ir / adt / raw_bitset.h
index 8d9ba95..9cf5894 100644 (file)
@@ -63,15 +63,10 @@ static inline unsigned *rbitset_malloc(size_t size)
 /**
  * Allocate an empty raw bitset on the stack.
  *
- * @param res   will contain the newly allocated bitset
  * @param size  number of bits in the bitset
  */
-#define rbitset_alloca(res, size) \
-do { \
-       size_t size_bytes = BITSET_SIZE_BYTES(size); \
-       res = (unsigned*)alloca(size_bytes); \
-       memset(res, 0, size_bytes); \
-} while(0)
+#define rbitset_alloca(size) \
+       ((unsigned*)memset(alloca(BITSET_SIZE_BYTES(size)), 0, BITSET_SIZE_BYTES(size)))
 
 /**
  * Allocate an empty raw bitset on an obstack.
@@ -309,6 +304,10 @@ static inline size_t rbitset_next(const unsigned *bitset, size_t pos,
 static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos,
                                       size_t last, bool set)
 {
+       assert(pos <= last);
+       if (pos == last)
+               return (size_t)-1;
+
        size_t p;
        size_t elem_pos = pos / BITS_PER_ELEM;
        size_t bit_pos  = pos % BITS_PER_ELEM;
@@ -323,8 +322,6 @@ static inline size_t rbitset_next_max(const unsigned *bitset, size_t pos,
         */
        unsigned in_elem_mask = (1u << bit_pos) - 1;
 
-       assert(pos < last);
-
        elem ^= mask;
        p = ntz(elem & ~in_elem_mask);
 
@@ -567,4 +564,13 @@ static inline void rbitset_copy_into(unsigned *dst, const unsigned *src,
        dst[n-1] = (src[n-1] & last_mask) | (dst[n-1] & ~last_mask);
 }
 
+/**
+ * Convenience macro for raw bitset iteration.
+ * @param bitset The bitset.
+ * @param size   Size of the bitset.
+ * @param elm    A size_t variable.
+ */
+#define rbitset_foreach(bitset, size, elm) \
+       for (size_t elm = 0; (elm = rbitset_next_max((bitset), elm, size, 1)) != (size_t)-1; ++elm)
+
 #endif