]>
Commit | Line | Data |
---|---|---|
5f6c11d6 | 1 | /* Simple bitmaps. |
9311a396 | 2 | Copyright (C) 1999, 2000 Free Software Foundation, Inc. |
5f6c11d6 RH |
3 | |
4 | This file is part of GNU CC. | |
5 | ||
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. | |
10 | ||
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. | |
15 | ||
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. */ | |
20 | ||
4dc9341c MH |
21 | #ifndef _SBITMAP_H |
22 | #define _SBITMAP_H 1 | |
23 | ||
5f6c11d6 RH |
24 | /* It's not clear yet whether using bitmap.[ch] will be a win. |
25 | It should be straightforward to convert so for now we keep things simple | |
26 | while more important issues are dealt with. */ | |
27 | ||
be200dff | 28 | #define SBITMAP_ELT_BITS ((unsigned) HOST_BITS_PER_WIDE_INT) |
5f6c11d6 RH |
29 | #define SBITMAP_ELT_TYPE unsigned HOST_WIDE_INT |
30 | ||
08158df3 RK |
31 | typedef struct simple_bitmap_def |
32 | { | |
33 | unsigned int n_bits; /* Number of bits. */ | |
34 | unsigned int size; /* Size in elements. */ | |
35 | unsigned int bytes; /* Size in bytes. */ | |
36 | SBITMAP_ELT_TYPE elms[1]; /* The elements. */ | |
5f6c11d6 RH |
37 | } *sbitmap; |
38 | ||
39 | typedef SBITMAP_ELT_TYPE *sbitmap_ptr; | |
40 | ||
41 | /* Return the set size needed for N elements. */ | |
08158df3 | 42 | #define SBITMAP_SET_SIZE(N) (((N) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS) |
5f6c11d6 | 43 | |
08158df3 RK |
44 | /* Set bit number bitno in the bitmap. */ |
45 | #define SET_BIT(BITMAP, BITNO) \ | |
46 | ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \ | |
47 | |= (SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS) | |
5f6c11d6 | 48 | |
08158df3 RK |
49 | /* Test if bit number bitno in the bitmap is set. */ |
50 | #define TEST_BIT(BITMAP, BITNO) \ | |
51 | ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] >> (BITNO) % SBITMAP_ELT_BITS & 1) | |
5f6c11d6 | 52 | |
08158df3 RK |
53 | /* Reset bit number bitno in the bitmap. */ |
54 | #define RESET_BIT(BITMAP, BITNO) \ | |
55 | ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] \ | |
56 | &= ~((SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS)) | |
5f6c11d6 RH |
57 | |
58 | /* Loop over all elements of SBITSET, starting with MIN. */ | |
59 | #define EXECUTE_IF_SET_IN_SBITMAP(SBITMAP, MIN, N, CODE) \ | |
60 | do { \ | |
e0bf4f7b RK |
61 | unsigned int word_num_; \ |
62 | unsigned int bit_num_ = (MIN) % (unsigned int) SBITMAP_ELT_BITS; \ | |
63 | unsigned int size_ = (SBITMAP)->size; \ | |
64 | SBITMAP_ELT_TYPE *ptr_ = (SBITMAP)->elms; \ | |
5f6c11d6 | 65 | \ |
e0bf4f7b RK |
66 | for (word_num_ = (MIN) / (unsigned int) SBITMAP_ELT_BITS; \ |
67 | word_num_ < size_; word_num_++, bit_num_ = 0) \ | |
5f6c11d6 | 68 | { \ |
e0bf4f7b | 69 | SBITMAP_ELT_TYPE word_ = ptr_[word_num_]; \ |
08158df3 | 70 | \ |
e0bf4f7b RK |
71 | if (word_ != 0) \ |
72 | for (; bit_num_ < SBITMAP_ELT_BITS; bit_num_++) \ | |
08158df3 | 73 | { \ |
e0bf4f7b | 74 | SBITMAP_ELT_TYPE _mask = (SBITMAP_ELT_TYPE)1 << bit_num_; \ |
08158df3 | 75 | \ |
e0bf4f7b | 76 | if ((word_ & _mask) != 0) \ |
08158df3 | 77 | { \ |
e0bf4f7b RK |
78 | word_ &= ~ _mask; \ |
79 | (N) = word_num_ * SBITMAP_ELT_BITS + bit_num_; \ | |
08158df3 | 80 | CODE; \ |
e0bf4f7b | 81 | if (word_ == 0) \ |
08158df3 RK |
82 | break; \ |
83 | } \ | |
84 | } \ | |
85 | } \ | |
5f6c11d6 RH |
86 | } while (0) |
87 | ||
08158df3 RK |
88 | #define sbitmap_free(MAP) free(MAP) |
89 | #define sbitmap_vector_free(VEC) free(VEC) | |
5f6c11d6 | 90 | |
08158df3 | 91 | struct int_list; |
5f6c11d6 | 92 | |
08158df3 RK |
93 | extern void dump_sbitmap PARAMS ((FILE *, sbitmap)); |
94 | extern void dump_sbitmap_vector PARAMS ((FILE *, const char *, | |
95 | const char *, sbitmap *, | |
96 | int)); | |
97 | extern sbitmap sbitmap_alloc PARAMS ((unsigned int)); | |
98 | extern sbitmap *sbitmap_vector_alloc PARAMS ((unsigned int, unsigned int)); | |
99 | extern void sbitmap_copy PARAMS ((sbitmap, sbitmap)); | |
100 | extern void sbitmap_zero PARAMS ((sbitmap)); | |
101 | extern void sbitmap_ones PARAMS ((sbitmap)); | |
102 | extern void sbitmap_vector_zero PARAMS ((sbitmap *, unsigned int)); | |
103 | extern void sbitmap_vector_ones PARAMS ((sbitmap *, unsigned int)); | |
104 | ||
105 | extern int sbitmap_union_of_diff PARAMS ((sbitmap, sbitmap, sbitmap, | |
106 | sbitmap)); | |
107 | extern void sbitmap_difference PARAMS ((sbitmap, sbitmap, sbitmap)); | |
108 | extern void sbitmap_not PARAMS ((sbitmap, sbitmap)); | |
109 | extern int sbitmap_a_or_b_and_c PARAMS ((sbitmap, sbitmap, sbitmap, | |
110 | sbitmap)); | |
111 | extern int sbitmap_a_and_b_or_c PARAMS ((sbitmap, sbitmap, sbitmap, | |
112 | sbitmap)); | |
113 | extern int sbitmap_a_and_b PARAMS ((sbitmap, sbitmap, sbitmap)); | |
114 | extern int sbitmap_a_or_b PARAMS ((sbitmap, sbitmap, sbitmap)); | |
115 | extern int sbitmap_a_subset_b_p PARAMS ((sbitmap, sbitmap)); | |
116 | ||
117 | extern int sbitmap_first_set_bit PARAMS ((sbitmap)); | |
118 | extern int sbitmap_last_set_bit PARAMS ((sbitmap)); | |
65169dcf | 119 | |
cdadb1dd | 120 | extern void sbitmap_intersect_of_predsucc PARAMS ((sbitmap, sbitmap *, |
5f6c11d6 RH |
121 | int, struct int_list **)); |
122 | #define sbitmap_intersect_of_predecessors sbitmap_intersect_of_predsucc | |
123 | #define sbitmap_intersect_of_successors sbitmap_intersect_of_predsucc | |
124 | ||
08158df3 RK |
125 | extern void sbitmap_union_of_predsucc PARAMS ((sbitmap, sbitmap *, int, |
126 | struct int_list **)); | |
5f6c11d6 RH |
127 | #define sbitmap_union_of_predecessors sbitmap_union_of_predsucc |
128 | #define sbitmap_union_of_successors sbitmap_union_of_predsucc | |
36349f8b AM |
129 | |
130 | /* Intersection and Union of preds/succs using the new flow graph | |
131 | structure instead of the pred/succ arrays. */ | |
132 | ||
08158df3 RK |
133 | extern void sbitmap_intersection_of_succs PARAMS ((sbitmap, sbitmap *, int)); |
134 | extern void sbitmap_intersection_of_preds PARAMS ((sbitmap, sbitmap *, int)); | |
135 | extern void sbitmap_union_of_succs PARAMS ((sbitmap, sbitmap *, int)); | |
136 | extern void sbitmap_union_of_preds PARAMS ((sbitmap, sbitmap *, int)); | |
36349f8b | 137 | |
4dc9341c | 138 | #endif /* _SBITMAP_H */ |