summaryrefslogtreecommitdiff
path: root/gcc/sbitmap.h
diff options
context:
space:
mode:
authorkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-07 14:30:25 +0000
committerkazu <kazu@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-07 14:30:25 +0000
commit3e790786cfb2c88061ebc1faad8273489bf3c388 (patch)
tree562f4507f40d0b9cd1ffaff1ad4960266f21f391 /gcc/sbitmap.h
parentaed164c3b749041e52ddb15d0114078e9dbeb7ae (diff)
downloadgcc-3e790786cfb2c88061ebc1faad8273489bf3c388.tar.gz
* sbitmap.h (sbitmap_iterator, sbitmap_iter_init,
sbitmap_iter_cond, sbitmap_iter_next): New. * bt-load.c, cfganal.c, combine.c, ddg.c, flow.c, modulo-sched.c, sbitmap.c, sched-rgn.c, tree-into-ssa.c, tree-outof-ssa.c, tree-ssa-alias.c, tree-ssa-live.c: Update uses of EXECUTE_IF_SET_IN_SBITMAP to the new style. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@100709 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/sbitmap.h')
-rw-r--r--gcc/sbitmap.h110
1 files changed, 80 insertions, 30 deletions
diff --git a/gcc/sbitmap.h b/gcc/sbitmap.h
index edaa0580ebf..fe23cbf91fa 100644
--- a/gcc/sbitmap.h
+++ b/gcc/sbitmap.h
@@ -55,36 +55,86 @@ typedef SBITMAP_ELT_TYPE *sbitmap_ptr;
((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \
&= ~((SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS))
-/* Loop over all elements of SBITSET, starting with MIN. */
-#define EXECUTE_IF_SET_IN_SBITMAP(SBITMAP, MIN, N, CODE) \
-do { \
- unsigned int word_num_ = (MIN) / (unsigned int) SBITMAP_ELT_BITS; \
- unsigned int bit_num_ = (MIN) % (unsigned int) SBITMAP_ELT_BITS; \
- unsigned int size_ = (SBITMAP)->size; \
- SBITMAP_ELT_TYPE *ptr_ = (SBITMAP)->elms; \
- SBITMAP_ELT_TYPE word_; \
- \
- if (word_num_ < size_) \
- { \
- word_ = ptr_[word_num_] >> bit_num_; \
- \
- while (1) \
- { \
- for (; word_ != 0; word_ >>= 1, bit_num_++) \
- { \
- if ((word_ & 1) != 0) \
- { \
- (N) = word_num_ * SBITMAP_ELT_BITS + bit_num_; \
- CODE; \
- } \
- } \
- word_num_++; \
- if (word_num_ >= size_) \
- break; \
- bit_num_ = 0, word_ = ptr_[word_num_]; \
- } \
- } \
-} while (0)
+/* The iterator for sbitmap. */
+typedef struct {
+ /* The pointer to the first word of the bitmap. */
+ SBITMAP_ELT_TYPE *ptr;
+
+ /* The size of the bitmap. */
+ unsigned int size;
+
+ /* The current word index. */
+ unsigned int word_num;
+
+ /* The current bit index. */
+ unsigned int bit_num;
+
+ /* The words currently visited. */
+ SBITMAP_ELT_TYPE word;
+} sbitmap_iterator;
+
+/* Initialize the iterator I with sbitmap BMP and the initial index
+ MIN. */
+
+static inline void
+sbitmap_iter_init (sbitmap_iterator *i, sbitmap bmp, unsigned int min)
+{
+ i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
+ i->bit_num = min % (unsigned int) SBITMAP_ELT_BITS;
+ i->size = bmp->size;
+ i->ptr = bmp->elms;
+
+ if (i->word_num >= i->size)
+ i->word = 0;
+ else
+ i->word = i->ptr[i->word_num] >> i->bit_num;
+}
+
+/* Return true if we have more bits to visit, in which case *N is set
+ to the index of the bit to be visited. Otherwise, return
+ false. */
+
+static inline bool
+sbitmap_iter_cond (sbitmap_iterator *i, unsigned int *n)
+{
+ /* Skip words that are zeros. */
+ for (; i->word == 0; i->word = i->ptr[i->word_num])
+ {
+ i->word_num++;
+
+ /* If we have reached the end, break. */
+ if (i->word_num >= i->size)
+ return false;
+
+ i->bit_num = i->word_num * SBITMAP_ELT_BITS;
+ }
+
+ /* Skip bits that are zero. */
+ for (; (i->word & 1) == 0; i->word >>= 1)
+ i->bit_num++;
+
+ *n = i->bit_num;
+
+ return true;
+}
+
+/* Advance to the next bit. */
+
+static inline void
+sbitmap_iter_next (sbitmap_iterator *i)
+{
+ i->word >>= 1;
+ i->bit_num++;
+}
+
+/* Loop over all elements of SBITMAP, starting with MIN. In each
+ iteration, N is set to the index of the bit being visited. ITER is
+ an instance of sbitmap_iterator used to iterate the bitmap. */
+
+#define EXECUTE_IF_SET_IN_SBITMAP(SBITMAP, MIN, N, ITER) \
+ for (sbitmap_iter_init (&(ITER), (SBITMAP), (MIN)); \
+ sbitmap_iter_cond (&(ITER), &(N)); \
+ sbitmap_iter_next (&(ITER)))
#define EXECUTE_IF_SET_IN_SBITMAP_REV(SBITMAP, N, CODE) \
do { \