00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef GCC_SBITMAP_H
00022 #define GCC_SBITMAP_H
00023
00024
00025
00026
00027
00028 #define SBITMAP_ELT_BITS ((unsigned) HOST_BITS_PER_WIDEST_FAST_INT)
00029 #define SBITMAP_ELT_TYPE unsigned HOST_WIDEST_FAST_INT
00030
00031 typedef struct simple_bitmap_def
00032 {
00033 unsigned int n_bits;
00034 unsigned int size;
00035 unsigned int bytes;
00036 SBITMAP_ELT_TYPE elms[1];
00037 } *sbitmap;
00038
00039 typedef SBITMAP_ELT_TYPE *sbitmap_ptr;
00040
00041
00042 #define SBITMAP_SET_SIZE(N) (((N) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS)
00043
00044
00045 #define SET_BIT(BITMAP, BITNO) \
00046 ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \
00047 |= (SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS)
00048
00049
00050 #define TEST_BIT(BITMAP, BITNO) \
00051 ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] >> (BITNO) % SBITMAP_ELT_BITS & 1)
00052
00053
00054 #define RESET_BIT(BITMAP, BITNO) \
00055 ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \
00056 &= ~((SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS))
00057
00058
00059 typedef struct {
00060
00061 SBITMAP_ELT_TYPE *ptr;
00062
00063
00064 unsigned int size;
00065
00066
00067 unsigned int word_num;
00068
00069
00070 unsigned int bit_num;
00071
00072
00073 SBITMAP_ELT_TYPE word;
00074 } sbitmap_iterator;
00075
00076
00077
00078
00079 static inline void
00080 sbitmap_iter_init (sbitmap_iterator *i, sbitmap bmp, unsigned int min)
00081 {
00082 i->word_num = min / (unsigned int) SBITMAP_ELT_BITS;
00083 i->bit_num = min;
00084 i->size = bmp->size;
00085 i->ptr = bmp->elms;
00086
00087 if (i->word_num >= i->size)
00088 i->word = 0;
00089 else
00090 i->word = (i->ptr[i->word_num]
00091 >> (i->bit_num % (unsigned int) SBITMAP_ELT_BITS));
00092 }
00093
00094
00095
00096
00097
00098 static inline bool
00099 sbitmap_iter_cond (sbitmap_iterator *i, unsigned int *n)
00100 {
00101
00102 for (; i->word == 0; i->word = i->ptr[i->word_num])
00103 {
00104 i->word_num++;
00105
00106
00107 if (i->word_num >= i->size)
00108 return false;
00109
00110 i->bit_num = i->word_num * SBITMAP_ELT_BITS;
00111 }
00112
00113
00114 for (; (i->word & 1) == 0; i->word >>= 1)
00115 i->bit_num++;
00116
00117 *n = i->bit_num;
00118
00119 return true;
00120 }
00121
00122
00123
00124 static inline void
00125 sbitmap_iter_next (sbitmap_iterator *i)
00126 {
00127 i->word >>= 1;
00128 i->bit_num++;
00129 }
00130
00131
00132
00133
00134
00135 #define EXECUTE_IF_SET_IN_SBITMAP(SBITMAP, MIN, N, ITER) \
00136 for (sbitmap_iter_init (&(ITER), (SBITMAP), (MIN)); \
00137 sbitmap_iter_cond (&(ITER), &(N)); \
00138 sbitmap_iter_next (&(ITER)))
00139
00140 #define EXECUTE_IF_SET_IN_SBITMAP_REV(SBITMAP, N, CODE) \
00141 do { \
00142 unsigned int word_num_; \
00143 unsigned int bit_num_; \
00144 unsigned int size_ = (SBITMAP)->size; \
00145 SBITMAP_ELT_TYPE *ptr_ = (SBITMAP)->elms; \
00146 \
00147 for (word_num_ = size_; word_num_ > 0; word_num_--) \
00148 { \
00149 SBITMAP_ELT_TYPE word_ = ptr_[word_num_ - 1]; \
00150 \
00151 if (word_ != 0) \
00152 for (bit_num_ = SBITMAP_ELT_BITS; bit_num_ > 0; bit_num_--) \
00153 { \
00154 SBITMAP_ELT_TYPE _mask = (SBITMAP_ELT_TYPE)1 << (bit_num_ - 1);\
00155 \
00156 if ((word_ & _mask) != 0) \
00157 { \
00158 word_ &= ~ _mask; \
00159 (N) = (word_num_ - 1) * SBITMAP_ELT_BITS + bit_num_ - 1;\
00160 CODE; \
00161 if (word_ == 0) \
00162 break; \
00163 } \
00164 } \
00165 } \
00166 } while (0)
00167
00168 #define sbitmap_free(MAP) free(MAP)
00169 #define sbitmap_vector_free(VEC) free(VEC)
00170
00171 struct int_list;
00172
00173 extern void dump_sbitmap (FILE *, sbitmap);
00174 extern void dump_sbitmap_file (FILE *, sbitmap);
00175 extern void dump_sbitmap_vector (FILE *, const char *, const char *, sbitmap *,
00176 int);
00177 extern sbitmap sbitmap_alloc (unsigned int);
00178 extern sbitmap *sbitmap_vector_alloc (unsigned int, unsigned int);
00179 extern sbitmap sbitmap_resize (sbitmap, unsigned int, int);
00180 extern void sbitmap_copy (sbitmap, sbitmap);
00181 extern int sbitmap_equal (sbitmap, sbitmap);
00182 extern void sbitmap_zero (sbitmap);
00183 extern void sbitmap_ones (sbitmap);
00184 extern void sbitmap_vector_zero (sbitmap *, unsigned int);
00185 extern void sbitmap_vector_ones (sbitmap *, unsigned int);
00186
00187 extern void sbitmap_union_of_diff (sbitmap, sbitmap, sbitmap, sbitmap);
00188 extern bool sbitmap_union_of_diff_cg (sbitmap, sbitmap, sbitmap, sbitmap);
00189 extern void sbitmap_difference (sbitmap, sbitmap, sbitmap);
00190 extern void sbitmap_not (sbitmap, sbitmap);
00191 extern void sbitmap_a_or_b_and_c (sbitmap, sbitmap, sbitmap, sbitmap);
00192 extern bool sbitmap_a_or_b_and_c_cg (sbitmap, sbitmap, sbitmap, sbitmap);
00193 extern void sbitmap_a_and_b_or_c (sbitmap, sbitmap, sbitmap, sbitmap);
00194 extern bool sbitmap_a_and_b_or_c_cg (sbitmap, sbitmap, sbitmap, sbitmap);
00195 extern bool sbitmap_any_common_bits (sbitmap, sbitmap);
00196 extern void sbitmap_a_and_b (sbitmap, sbitmap, sbitmap);
00197 extern bool sbitmap_a_and_b_cg (sbitmap, sbitmap, sbitmap);
00198 extern void sbitmap_a_or_b (sbitmap, sbitmap, sbitmap);
00199 extern bool sbitmap_a_or_b_cg (sbitmap, sbitmap, sbitmap);
00200 extern void sbitmap_a_xor_b (sbitmap, sbitmap, sbitmap);
00201 extern bool sbitmap_a_xor_b_cg (sbitmap, sbitmap, sbitmap);
00202 extern bool sbitmap_a_subset_b_p (sbitmap, sbitmap);
00203
00204 extern int sbitmap_first_set_bit (sbitmap);
00205 extern int sbitmap_last_set_bit (sbitmap);
00206
00207 extern void sbitmap_intersect_of_predsucc (sbitmap, sbitmap *, int,
00208 struct int_list **);
00209 #define sbitmap_intersect_of_predecessors sbitmap_intersect_of_predsucc
00210 #define sbitmap_intersect_of_successors sbitmap_intersect_of_predsucc
00211
00212 extern void sbitmap_union_of_predsucc (sbitmap, sbitmap *, int,
00213 struct int_list **);
00214 #define sbitmap_union_of_predecessors sbitmap_union_of_predsucc
00215 #define sbitmap_union_of_successors sbitmap_union_of_predsucc
00216
00217
00218
00219
00220 extern void sbitmap_intersection_of_succs (sbitmap, sbitmap *, int);
00221 extern void sbitmap_intersection_of_preds (sbitmap, sbitmap *, int);
00222 extern void sbitmap_union_of_succs (sbitmap, sbitmap *, int);
00223 extern void sbitmap_union_of_preds (sbitmap, sbitmap *, int);
00224
00225 extern void debug_sbitmap (sbitmap);
00226 extern sbitmap sbitmap_realloc (sbitmap, unsigned int);
00227 #endif