Append a DIR_SEPARATOR to a path specified by the -B switch, if doing so would
[official-gcc.git] / gcc / bitmap.h
blob95c2a5e8f0d528c26d48ac9789891d4da242c9b6
1 /* Functions to support general ended bitmaps.
2 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifndef GCC_BITMAP_H
22 #define GCC_BITMAP_H
24 /* Number of words to use for each element in the linked list. */
26 #ifndef BITMAP_ELEMENT_WORDS
27 #define BITMAP_ELEMENT_WORDS 2
28 #endif
30 /* Number of bits in each actual element of a bitmap. We get slightly better
31 code for bit % BITMAP_ELEMENT_ALL_BITS and bit / BITMAP_ELEMENT_ALL_BITS if
32 bits is unsigned, assuming it is a power of 2. */
34 #define BITMAP_ELEMENT_ALL_BITS \
35 ((unsigned) (BITMAP_ELEMENT_WORDS * HOST_BITS_PER_WIDE_INT))
37 /* Bitmap set element. We use a linked list to hold only the bits that
38 are set. This allows for use to grow the bitset dynamically without
39 having to realloc and copy a giant bit array. The `prev' field is
40 undefined for an element on the free list. */
42 typedef struct bitmap_element_def
44 struct bitmap_element_def *next; /* Next element. */
45 struct bitmap_element_def *prev; /* Previous element. */
46 unsigned int indx; /* regno/BITMAP_ELEMENT_ALL_BITS. */
47 unsigned HOST_WIDE_INT bits[BITMAP_ELEMENT_WORDS]; /* Bits that are set. */
48 } bitmap_element;
50 /* Head of bitmap linked list. */
51 typedef struct bitmap_head_def {
52 bitmap_element *first; /* First element in linked list. */
53 bitmap_element *current; /* Last element looked at. */
54 unsigned int indx; /* Index of last element looked at. */
56 } bitmap_head, *bitmap;
58 /* Enumeration giving the various operations we support. */
59 enum bitmap_bits {
60 BITMAP_AND, /* TO = FROM1 & FROM2 */
61 BITMAP_AND_COMPL, /* TO = FROM1 & ~ FROM2 */
62 BITMAP_IOR, /* TO = FROM1 | FROM2 */
63 BITMAP_XOR, /* TO = FROM1 ^ FROM2 */
64 BITMAP_IOR_COMPL /* TO = FROM1 | ~FROM2 */
67 /* Global data */
68 extern bitmap_element *bitmap_free; /* Freelist of bitmap elements */
69 extern bitmap_element bitmap_zero; /* Zero bitmap element */
71 /* Clear a bitmap by freeing up the linked list. */
72 extern void bitmap_clear PARAMS ((bitmap));
74 /* Copy a bitmap to another bitmap. */
75 extern void bitmap_copy PARAMS ((bitmap, bitmap));
77 /* True if two bitmaps are identical. */
78 extern int bitmap_equal_p PARAMS ((bitmap, bitmap));
80 /* Perform an operation on two bitmaps, yielding a third. */
81 extern int bitmap_operation PARAMS ((bitmap, bitmap, bitmap, enum bitmap_bits));
83 /* `or' into one bitmap the `and' of a second bitmap witih the complement
84 of a third. */
85 extern void bitmap_ior_and_compl PARAMS ((bitmap, bitmap, bitmap));
87 /* Clear a single register in a register set. */
88 extern void bitmap_clear_bit PARAMS ((bitmap, int));
90 /* Set a single register in a register set. */
91 extern void bitmap_set_bit PARAMS ((bitmap, int));
93 /* Return true if a register is set in a register set. */
94 extern int bitmap_bit_p PARAMS ((bitmap, int));
96 /* Debug functions to print a bitmap linked list. */
97 extern void debug_bitmap PARAMS ((bitmap));
98 extern void debug_bitmap_file PARAMS ((FILE *, bitmap));
100 /* Print a bitmap */
101 extern void bitmap_print PARAMS ((FILE *, bitmap, const char *, const char *));
103 /* Initialize a bitmap header. */
104 extern bitmap bitmap_initialize PARAMS ((bitmap));
106 /* Release all memory held by bitmaps. */
107 extern void bitmap_release_memory PARAMS ((void));
109 /* A few compatibility/functions macros for compatibility with sbitmaps */
110 #define dump_bitmap(file, bitmap) bitmap_print (file, bitmap, "", "\n")
111 #define bitmap_zero(a) bitmap_clear (a)
112 #define bitmap_a_or_b(a,b,c) bitmap_operation (a, b, c, BITMAP_IOR)
113 #define bitmap_a_and_b(a,b,c) bitmap_operation (a, b, c, BITMAP_AND)
114 extern int bitmap_union_of_diff PARAMS((bitmap, bitmap, bitmap, bitmap));
115 extern int bitmap_first_set_bit PARAMS((bitmap));
116 extern int bitmap_last_set_bit PARAMS((bitmap));
118 /* Allocate a bitmap with oballoc. */
119 #define BITMAP_OBSTACK_ALLOC(OBSTACK) \
120 bitmap_initialize ((bitmap) obstack_alloc (OBSTACK, sizeof (bitmap_head)))
122 /* Allocate a bitmap with alloca. */
123 #define BITMAP_ALLOCA() \
124 bitmap_initialize ((bitmap) alloca (sizeof (bitmap_head)))
126 /* Allocate a bitmap with xmalloc. */
127 #define BITMAP_XMALLOC() \
128 bitmap_initialize ((bitmap) xmalloc (sizeof (bitmap_head)))
130 /* Do any cleanup needed on a bitmap when it is no longer used. */
131 #define BITMAP_FREE(BITMAP) \
132 do { \
133 if (BITMAP) \
135 bitmap_clear (BITMAP); \
136 (BITMAP) = 0; \
138 } while (0)
140 /* Do any cleanup needed on an xmalloced bitmap when it is no longer used. */
141 #define BITMAP_XFREE(BITMAP) \
142 do { \
143 if (BITMAP) \
145 bitmap_clear (BITMAP); \
146 free (BITMAP); \
147 (BITMAP) = 0; \
149 } while (0)
151 /* Do any one-time initializations needed for bitmaps. */
152 #define BITMAP_INIT_ONCE()
154 /* Loop over all bits in BITMAP, starting with MIN, setting BITNUM to the
155 bit number and executing CODE for all bits that are set. */
157 #define EXECUTE_IF_SET_IN_BITMAP(BITMAP, MIN, BITNUM, CODE) \
158 do { \
159 bitmap_element *ptr_ = (BITMAP)->first; \
160 unsigned int indx_ = (MIN) / BITMAP_ELEMENT_ALL_BITS; \
161 unsigned bit_num_ = (MIN) % ((unsigned) HOST_BITS_PER_WIDE_INT); \
162 unsigned word_num_ = (((MIN) / ((unsigned) HOST_BITS_PER_WIDE_INT)) \
163 % BITMAP_ELEMENT_WORDS); \
166 /* Find the block the minimum bit is in. */ \
167 while (ptr_ != 0 && ptr_->indx < indx_) \
168 ptr_ = ptr_->next; \
170 if (ptr_ != 0 && ptr_->indx != indx_) \
172 bit_num_ = 0; \
173 word_num_ = 0; \
176 for (; ptr_ != 0; ptr_ = ptr_->next) \
178 for (; word_num_ < BITMAP_ELEMENT_WORDS; word_num_++) \
180 unsigned HOST_WIDE_INT word_ = ptr_->bits[word_num_]; \
182 if (word_ != 0) \
184 for (; bit_num_ < HOST_BITS_PER_WIDE_INT; bit_num_++) \
186 unsigned HOST_WIDE_INT mask_ \
187 = ((unsigned HOST_WIDE_INT) 1) << bit_num_; \
189 if ((word_ & mask_) != 0) \
191 word_ &= ~ mask_; \
192 (BITNUM) = (ptr_->indx * BITMAP_ELEMENT_ALL_BITS \
193 + word_num_ * HOST_BITS_PER_WIDE_INT \
194 + bit_num_); \
195 CODE; \
197 if (word_ == 0) \
198 break; \
203 bit_num_ = 0; \
206 word_num_ = 0; \
208 } while (0)
210 /* Loop over all bits in BITMAP1 and BITMAP2, starting with MIN, setting
211 BITNUM to the bit number and executing CODE for all bits that are set in
212 the first bitmap and not set in the second. */
214 #define EXECUTE_IF_AND_COMPL_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, CODE) \
215 do { \
216 bitmap_element *ptr1_ = (BITMAP1)->first; \
217 bitmap_element *ptr2_ = (BITMAP2)->first; \
218 unsigned int indx_ = (MIN) / BITMAP_ELEMENT_ALL_BITS; \
219 unsigned bit_num_ = (MIN) % ((unsigned) HOST_BITS_PER_WIDE_INT); \
220 unsigned word_num_ = (((MIN) / ((unsigned) HOST_BITS_PER_WIDE_INT)) \
221 % BITMAP_ELEMENT_WORDS); \
223 /* Find the block the minimum bit is in in the first bitmap. */ \
224 while (ptr1_ != 0 && ptr1_->indx < indx_) \
225 ptr1_ = ptr1_->next; \
227 if (ptr1_ != 0 && ptr1_->indx != indx_) \
229 bit_num_ = 0; \
230 word_num_ = 0; \
233 for (; ptr1_ != 0 ; ptr1_ = ptr1_->next) \
235 /* Advance BITMAP2 to the equivalent link, using an all \
236 zero element if an equivalent link doesn't exist. */ \
237 bitmap_element *tmp2_; \
239 while (ptr2_ != 0 && ptr2_->indx < ptr1_->indx) \
240 ptr2_ = ptr2_->next; \
242 tmp2_ = ((ptr2_ != 0 && ptr2_->indx == ptr1_->indx) \
243 ? ptr2_ : &bitmap_zero); \
245 for (; word_num_ < BITMAP_ELEMENT_WORDS; word_num_++) \
247 unsigned HOST_WIDE_INT word_ = (ptr1_->bits[word_num_] \
248 & ~ tmp2_->bits[word_num_]); \
249 if (word_ != 0) \
251 for (; bit_num_ < HOST_BITS_PER_WIDE_INT; bit_num_++) \
253 unsigned HOST_WIDE_INT mask_ \
254 = ((unsigned HOST_WIDE_INT)1) << bit_num_; \
256 if ((word_ & mask_) != 0) \
258 word_ &= ~ mask_; \
259 (BITNUM) = (ptr1_->indx * BITMAP_ELEMENT_ALL_BITS \
260 + word_num_ * HOST_BITS_PER_WIDE_INT \
261 + bit_num_); \
263 CODE; \
264 if (word_ == 0) \
265 break; \
270 bit_num_ = 0; \
273 word_num_ = 0; \
275 } while (0)
277 /* Loop over all bits in BITMAP1 and BITMAP2, starting with MIN, setting
278 BITNUM to the bit number and executing CODE for all bits that are set in
279 the both bitmaps. */
281 #define EXECUTE_IF_AND_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, CODE) \
282 do { \
283 bitmap_element *ptr1_ = (BITMAP1)->first; \
284 bitmap_element *ptr2_ = (BITMAP2)->first; \
285 unsigned int indx_ = (MIN) / BITMAP_ELEMENT_ALL_BITS; \
286 unsigned bit_num_ = (MIN) % ((unsigned) HOST_BITS_PER_WIDE_INT); \
287 unsigned word_num_ = (((MIN) / ((unsigned) HOST_BITS_PER_WIDE_INT)) \
288 % BITMAP_ELEMENT_WORDS); \
290 /* Find the block the minimum bit is in in the first bitmap. */ \
291 while (ptr1_ != 0 && ptr1_->indx < indx_) \
292 ptr1_ = ptr1_->next; \
294 if (ptr1_ != 0 && ptr1_->indx != indx_) \
296 bit_num_ = 0; \
297 word_num_ = 0; \
300 for (; ptr1_ != 0 ; ptr1_ = ptr1_->next) \
302 /* Advance BITMAP2 to the equivalent link */ \
303 while (ptr2_ != 0 && ptr2_->indx < ptr1_->indx) \
304 ptr2_ = ptr2_->next; \
306 if (ptr2_ == 0) \
308 /* If there are no more elements in BITMAP2, exit loop now.*/ \
309 ptr1_ = (bitmap_element *)0; \
310 break; \
312 else if (ptr2_->indx > ptr1_->indx) \
314 bit_num_ = word_num_ = 0; \
315 continue; \
318 for (; word_num_ < BITMAP_ELEMENT_WORDS; word_num_++) \
320 unsigned HOST_WIDE_INT word_ = (ptr1_->bits[word_num_] \
321 & ptr2_->bits[word_num_]); \
322 if (word_ != 0) \
324 for (; bit_num_ < HOST_BITS_PER_WIDE_INT; bit_num_++) \
326 unsigned HOST_WIDE_INT mask_ \
327 = ((unsigned HOST_WIDE_INT)1) << bit_num_; \
329 if ((word_ & mask_) != 0) \
331 word_ &= ~ mask_; \
332 (BITNUM) = (ptr1_->indx * BITMAP_ELEMENT_ALL_BITS \
333 + word_num_ * HOST_BITS_PER_WIDE_INT \
334 + bit_num_); \
336 CODE; \
337 if (word_ == 0) \
338 break; \
343 bit_num_ = 0; \
346 word_num_ = 0; \
348 } while (0)
350 #endif /* GCC_BITMAP_H */