annotate gcc/bitmap.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Functions to support general ended bitmaps.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 1997-2020 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #ifndef GCC_BITMAP_H
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #define GCC_BITMAP_H
111
kono
parents: 67
diff changeset
22
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
23 /* Implementation of sparse integer sets as a linked list or tree.
111
kono
parents: 67
diff changeset
24
kono
parents: 67
diff changeset
25 This sparse set representation is suitable for sparse sets with an
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
26 unknown (a priori) universe.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
27
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
28 Sets are represented as double-linked lists of container nodes of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
29 type "struct bitmap_element" or as a binary trees of the same
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
30 container nodes. Each container node consists of an index for the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
31 first member that could be held in the container, a small array of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
32 integers that represent the members in the container, and pointers
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
33 to the next and previous element in the linked list, or left and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
34 right children in the tree. In linked-list form, the container
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
35 nodes in the list are sorted in ascending order, i.e. the head of
111
kono
parents: 67
diff changeset
36 the list holds the element with the smallest member of the set.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
37 In tree form, nodes to the left have a smaller container index.
111
kono
parents: 67
diff changeset
38
kono
parents: 67
diff changeset
39 For a given member I in the set:
kono
parents: 67
diff changeset
40 - the element for I will have index is I / (bits per element)
kono
parents: 67
diff changeset
41 - the position for I within element is I % (bits per element)
kono
parents: 67
diff changeset
42
kono
parents: 67
diff changeset
43 This representation is very space-efficient for large sparse sets, and
kono
parents: 67
diff changeset
44 the size of the set can be changed dynamically without much overhead.
kono
parents: 67
diff changeset
45 An important parameter is the number of bits per element. In this
kono
parents: 67
diff changeset
46 implementation, there are 128 bits per element. This results in a
kono
parents: 67
diff changeset
47 high storage overhead *per element*, but a small overall overhead if
kono
parents: 67
diff changeset
48 the set is very sparse.
kono
parents: 67
diff changeset
49
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
50 The storage requirements for linked-list sparse sets are O(E), with E->N
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
51 in the worst case (a sparse set with large distances between the values
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
52 of the set members).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
53
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
54 This representation also works well for data flow problems where the size
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
55 of the set may grow dynamically, but care must be taken that the member_p,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
56 add_member, and remove_member operations occur with a suitable access
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
57 pattern.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
58
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
59 The linked-list set representation works well for problems involving very
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
60 sparse sets. The canonical example in GCC is, of course, the "set of
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
61 sets" for some CFG-based data flow problems (liveness analysis, dominance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
62 frontiers, etc.).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
63
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
64 For random-access sparse sets of unknown universe, the binary tree
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
65 representation is likely to be a more suitable choice. Theoretical
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
66 access times for the binary tree representation are better than those
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
67 for the linked-list, but in practice this is only true for truely
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
68 random access.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
69
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
70 Often the most suitable representation during construction of the set
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
71 is not the best choice for the usage of the set. For such cases, the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
72 "view" of the set can be changed from one representation to the other.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
73 This is an O(E) operation:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
74
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
75 * from list to tree view : bitmap_tree_view
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
76 * from tree to list view : bitmap_list_view
111
kono
parents: 67
diff changeset
77
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
78 Traversing linked lists or trees can be cache-unfriendly. Performance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
79 can be improved by keeping container nodes in the set grouped together
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
80 in memory, using a dedicated obstack for a set (or group of related
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
81 sets). Elements allocated on obstacks are released to a free-list and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
82 taken off the free list. If multiple sets are allocated on the same
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
83 obstack, elements freed from one set may be re-used for one of the other
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
84 sets. This usually helps avoid cache misses.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
85
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
86 A single free-list is used for all sets allocated in GGC space. This is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
87 bad for persistent sets, so persistent sets should be allocated on an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
88 obstack whenever possible.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
89
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
90 For random-access sets with a known, relatively small universe size, the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
91 SparseSet or simple bitmap representations may be more efficient than a
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
92 linked-list set.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
93
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
94
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
95 LINKED LIST FORM
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
96 ================
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
97
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
98 In linked-list form, in-order iterations of the set can be executed
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
99 efficiently. The downside is that many random-access operations are
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
100 relatively slow, because the linked list has to be traversed to test
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
101 membership (i.e. member_p/ add_member/remove_member).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
102
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
103 To improve the performance of this set representation, the last
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
104 accessed element and its index are cached. For membership tests on
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
105 members close to recently accessed members, the cached last element
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
106 improves membership test to a constant-time operation.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
107
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
108 The following operations can always be performed in O(1) time in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
109 list view:
111
kono
parents: 67
diff changeset
110
kono
parents: 67
diff changeset
111 * clear : bitmap_clear
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
112 * smallest_member : bitmap_first_set_bit
111
kono
parents: 67
diff changeset
113 * choose_one : (not implemented, but could be
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
114 in constant time)
111
kono
parents: 67
diff changeset
115
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
116 The following operations can be performed in O(E) time worst-case in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
117 list view (with E the number of elements in the linked list), but in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
118 O(1) time with a suitable access patterns:
111
kono
parents: 67
diff changeset
119
kono
parents: 67
diff changeset
120 * member_p : bitmap_bit_p
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
121 * add_member : bitmap_set_bit / bitmap_set_range
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
122 * remove_member : bitmap_clear_bit / bitmap_clear_range
111
kono
parents: 67
diff changeset
123
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
124 The following operations can be performed in O(E) time in list view:
111
kono
parents: 67
diff changeset
125
kono
parents: 67
diff changeset
126 * cardinality : bitmap_count_bits
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
127 * largest_member : bitmap_last_set_bit (but this could
111
kono
parents: 67
diff changeset
128 in constant time with a pointer to
kono
parents: 67
diff changeset
129 the last element in the chain)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
130 * set_size : bitmap_last_set_bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
132 In tree view the following operations can all be performed in O(log E)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
133 amortized time with O(E) worst-case behavior.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
134
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
135 * smallest_member
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
136 * largest_member
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
137 * set_size
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
138 * member_p
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
139 * add_member
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
140 * remove_member
111
kono
parents: 67
diff changeset
141
kono
parents: 67
diff changeset
142 Additionally, the linked-list sparse set representation supports
kono
parents: 67
diff changeset
143 enumeration of the members in O(E) time:
kono
parents: 67
diff changeset
144
kono
parents: 67
diff changeset
145 * forall : EXECUTE_IF_SET_IN_BITMAP
kono
parents: 67
diff changeset
146 * set_copy : bitmap_copy
kono
parents: 67
diff changeset
147 * set_intersection : bitmap_intersect_p /
kono
parents: 67
diff changeset
148 bitmap_and / bitmap_and_into /
kono
parents: 67
diff changeset
149 EXECUTE_IF_AND_IN_BITMAP
kono
parents: 67
diff changeset
150 * set_union : bitmap_ior / bitmap_ior_into
kono
parents: 67
diff changeset
151 * set_difference : bitmap_intersect_compl_p /
kono
parents: 67
diff changeset
152 bitmap_and_comp / bitmap_and_comp_into /
kono
parents: 67
diff changeset
153 EXECUTE_IF_AND_COMPL_IN_BITMAP
kono
parents: 67
diff changeset
154 * set_disjuction : bitmap_xor_comp / bitmap_xor_comp_into
kono
parents: 67
diff changeset
155 * set_compare : bitmap_equal_p
kono
parents: 67
diff changeset
156
kono
parents: 67
diff changeset
157 Some operations on 3 sets that occur frequently in data flow problems
kono
parents: 67
diff changeset
158 are also implemented:
kono
parents: 67
diff changeset
159
kono
parents: 67
diff changeset
160 * A | (B & C) : bitmap_ior_and_into
kono
parents: 67
diff changeset
161 * A | (B & ~C) : bitmap_ior_and_compl /
kono
parents: 67
diff changeset
162 bitmap_ior_and_compl_into
kono
parents: 67
diff changeset
163
kono
parents: 67
diff changeset
164
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
165 BINARY TREE FORM
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
166 ================
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
167 An alternate "view" of a bitmap is its binary tree representation.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
168 For this representation, splay trees are used because they can be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
169 implemented using the same data structures as the linked list, with
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
170 no overhead for meta-data (like color, or rank) on the tree nodes.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
171
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
172 In binary tree form, random-access to the set is much more efficient
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
173 than for the linked-list representation. Downsides are the high cost
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
174 of clearing the set, and the relatively large number of operations
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
175 necessary to balance the tree. Also, iterating the set members is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
176 not supported.
111
kono
parents: 67
diff changeset
177
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
178 As for the linked-list representation, the last accessed element and
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
179 its index are cached, so that membership tests on the latest accessed
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
180 members is a constant-time operation. Other lookups take O(logE)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
181 time amortized (but O(E) time worst-case).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
183 The following operations can always be performed in O(1) time:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
184
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
185 * choose_one : (not implemented, but could be
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
186 implemented in constant time)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
187
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
188 The following operations can be performed in O(logE) time amortized
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
189 but O(E) time worst-case, but in O(1) time if the same element is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
190 accessed.
111
kono
parents: 67
diff changeset
191
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
192 * member_p : bitmap_bit_p
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
193 * add_member : bitmap_set_bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
194 * remove_member : bitmap_clear_bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
195
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
196 The following operations can be performed in O(logE) time amortized
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 but O(E) time worst-case:
111
kono
parents: 67
diff changeset
198
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
199 * smallest_member : bitmap_first_set_bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
200 * largest_member : bitmap_last_set_bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
201 * set_size : bitmap_last_set_bit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
202
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
203 The following operations can be performed in O(E) time:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
204
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
205 * clear : bitmap_clear
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
206
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
207 The binary tree sparse set representation does *not* support any form
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
208 of enumeration, and does also *not* support logical operations on sets.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
209 The binary tree representation is only supposed to be used for sets
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
210 on which many random-access membership tests will happen. */
111
kono
parents: 67
diff changeset
211
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 #include "obstack.h"
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
213 #include "array-traits.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
111
kono
parents: 67
diff changeset
215 /* Bitmap memory usage. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
216 class bitmap_usage: public mem_usage
111
kono
parents: 67
diff changeset
217 {
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
218 public:
111
kono
parents: 67
diff changeset
219 /* Default contructor. */
kono
parents: 67
diff changeset
220 bitmap_usage (): m_nsearches (0), m_search_iter (0) {}
kono
parents: 67
diff changeset
221 /* Constructor. */
kono
parents: 67
diff changeset
222 bitmap_usage (size_t allocated, size_t times, size_t peak,
kono
parents: 67
diff changeset
223 uint64_t nsearches, uint64_t search_iter)
kono
parents: 67
diff changeset
224 : mem_usage (allocated, times, peak),
kono
parents: 67
diff changeset
225 m_nsearches (nsearches), m_search_iter (search_iter) {}
kono
parents: 67
diff changeset
226
kono
parents: 67
diff changeset
227 /* Sum the usage with SECOND usage. */
kono
parents: 67
diff changeset
228 bitmap_usage
kono
parents: 67
diff changeset
229 operator+ (const bitmap_usage &second)
kono
parents: 67
diff changeset
230 {
kono
parents: 67
diff changeset
231 return bitmap_usage (m_allocated + second.m_allocated,
kono
parents: 67
diff changeset
232 m_times + second.m_times,
kono
parents: 67
diff changeset
233 m_peak + second.m_peak,
kono
parents: 67
diff changeset
234 m_nsearches + second.m_nsearches,
kono
parents: 67
diff changeset
235 m_search_iter + second.m_search_iter);
kono
parents: 67
diff changeset
236 }
kono
parents: 67
diff changeset
237
kono
parents: 67
diff changeset
238 /* Dump usage coupled to LOC location, where TOTAL is sum of all rows. */
kono
parents: 67
diff changeset
239 inline void
kono
parents: 67
diff changeset
240 dump (mem_location *loc, mem_usage &total) const
kono
parents: 67
diff changeset
241 {
kono
parents: 67
diff changeset
242 char *location_string = loc->to_string ();
kono
parents: 67
diff changeset
243
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
244 fprintf (stderr, "%-48s " PRsa (9) ":%5.1f%%"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
245 PRsa (9) PRsa (9) ":%5.1f%%"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
246 PRsa (11) PRsa (11) "%10s\n",
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
247 location_string, SIZE_AMOUNT (m_allocated),
111
kono
parents: 67
diff changeset
248 get_percent (m_allocated, total.m_allocated),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
249 SIZE_AMOUNT (m_peak), SIZE_AMOUNT (m_times),
111
kono
parents: 67
diff changeset
250 get_percent (m_times, total.m_times),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
251 SIZE_AMOUNT (m_nsearches), SIZE_AMOUNT (m_search_iter),
111
kono
parents: 67
diff changeset
252 loc->m_ggc ? "ggc" : "heap");
kono
parents: 67
diff changeset
253
kono
parents: 67
diff changeset
254 free (location_string);
kono
parents: 67
diff changeset
255 }
kono
parents: 67
diff changeset
256
kono
parents: 67
diff changeset
257 /* Dump header with NAME. */
kono
parents: 67
diff changeset
258 static inline void
kono
parents: 67
diff changeset
259 dump_header (const char *name)
kono
parents: 67
diff changeset
260 {
kono
parents: 67
diff changeset
261 fprintf (stderr, "%-48s %11s%16s%17s%12s%12s%10s\n", name, "Leak", "Peak",
kono
parents: 67
diff changeset
262 "Times", "N searches", "Search iter", "Type");
kono
parents: 67
diff changeset
263 }
kono
parents: 67
diff changeset
264
kono
parents: 67
diff changeset
265 /* Number search operations. */
kono
parents: 67
diff changeset
266 uint64_t m_nsearches;
kono
parents: 67
diff changeset
267 /* Number of search iterations. */
kono
parents: 67
diff changeset
268 uint64_t m_search_iter;
kono
parents: 67
diff changeset
269 };
kono
parents: 67
diff changeset
270
kono
parents: 67
diff changeset
271 /* Bitmap memory description. */
kono
parents: 67
diff changeset
272 extern mem_alloc_description<bitmap_usage> bitmap_mem_desc;
kono
parents: 67
diff changeset
273
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 /* Fundamental storage type for bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 typedef unsigned long BITMAP_WORD;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 /* BITMAP_WORD_BITS needs to be unsigned, but cannot contain casts as
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 it is used in preprocessor directives -- hence the 1u. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 #define BITMAP_WORD_BITS (CHAR_BIT * SIZEOF_LONG * 1u)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 /* Number of words to use for each element in the linked list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 #ifndef BITMAP_ELEMENT_WORDS
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 #define BITMAP_ELEMENT_WORDS ((128 + BITMAP_WORD_BITS - 1) / BITMAP_WORD_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 #endif
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 /* Number of bits in each actual element of a bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 #define BITMAP_ELEMENT_ALL_BITS (BITMAP_ELEMENT_WORDS * BITMAP_WORD_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 /* Obstack for allocating bitmaps and elements from. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
292 struct bitmap_obstack {
111
kono
parents: 67
diff changeset
293 struct bitmap_element *elements;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
294 bitmap_head *heads;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
295 struct obstack obstack;
111
kono
parents: 67
diff changeset
296 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 /* Bitmap set element. We use a linked list to hold only the bits that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 are set. This allows for use to grow the bitset dynamically without
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 having to realloc and copy a giant bit array.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 The free list is implemented as a list of lists. There is one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 outer list connected together by prev fields. Each element of that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 outer is an inner list (that may consist only of the outer list
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 element) that are connected by the next fields. The prev pointer
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 is undefined for interior elements. This allows
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 bitmap_elt_clear_from to be implemented in unit time rather than
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 linear in the number of elements to be freed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
310 struct GTY((chain_next ("%h.next"))) bitmap_element {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
311 /* In list form, the next element in the linked list;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
312 in tree form, the left child node in the tree. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
313 struct bitmap_element *next;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
314 /* In list form, the previous element in the linked list;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
315 in tree form, the right child node in the tree. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
316 struct bitmap_element *prev;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 /* regno/BITMAP_ELEMENT_ALL_BITS. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
318 unsigned int indx;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
319 /* Bits that are set, counting from INDX, inclusive */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
320 BITMAP_WORD bits[BITMAP_ELEMENT_WORDS];
111
kono
parents: 67
diff changeset
321 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322
111
kono
parents: 67
diff changeset
323 /* Head of bitmap linked list. The 'current' member points to something
kono
parents: 67
diff changeset
324 already pointed to by the chain started by first, so GTY((skip)) it. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
326 class GTY(()) bitmap_head {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
327 public:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
328 static bitmap_obstack crashme;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
329 /* Poison obstack to not make it not a valid initialized GC bitmap. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
330 CONSTEXPR bitmap_head()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
331 : indx (0), tree_form (false), padding (0), alloc_descriptor (0), first (NULL),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
332 current (NULL), obstack (&crashme)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
333 {}
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
334 /* Index of last element looked at. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
335 unsigned int indx;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
336 /* False if the bitmap is in list form; true if the bitmap is in tree form.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
337 Bitmap iterators only work on bitmaps in list form. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
338 unsigned tree_form: 1;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
339 /* Next integer is shifted, so padding is needed. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
340 unsigned padding: 2;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
341 /* Bitmap UID used for memory allocation statistics. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
342 unsigned alloc_descriptor: 29;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
343 /* In list form, the first element in the linked list;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
344 in tree form, the root of the tree. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
345 bitmap_element *first;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
346 /* Last element looked at. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
347 bitmap_element * GTY((skip(""))) current;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
348 /* Obstack to allocate elements from. If NULL, then use GGC allocation. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
349 bitmap_obstack * GTY((skip(""))) obstack;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
350
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
351 /* Dump bitmap. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
352 void dump ();
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
353
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
354 /* Get bitmap descriptor UID casted to an unsigned integer pointer.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
355 Shift the descriptor because pointer_hash<Type>::hash is
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
356 doing >> 3 shift operation. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
357 unsigned *get_descriptor ()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
358 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
359 return (unsigned *)(ptrdiff_t)(alloc_descriptor << 3);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
360 }
111
kono
parents: 67
diff changeset
361 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 /* Global data */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 extern bitmap_element bitmap_zero_bits; /* Zero bitmap element */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 extern bitmap_obstack bitmap_default_obstack; /* Default bitmap obstack */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
367 /* Change the view of the bitmap to list, or tree. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
368 void bitmap_list_view (bitmap);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
369 void bitmap_tree_view (bitmap);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
370
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 /* Clear a bitmap by freeing up the linked list. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 extern void bitmap_clear (bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 /* Copy a bitmap to another bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 extern void bitmap_copy (bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376
111
kono
parents: 67
diff changeset
377 /* Move a bitmap to another bitmap. */
kono
parents: 67
diff changeset
378 extern void bitmap_move (bitmap, bitmap);
kono
parents: 67
diff changeset
379
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 /* True if two bitmaps are identical. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 extern bool bitmap_equal_p (const_bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 /* True if the bitmaps intersect (their AND is non-empty). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 extern bool bitmap_intersect_p (const_bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 /* True if the complement of the second intersects the first (their
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 AND_COMPL is non-empty). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 extern bool bitmap_intersect_compl_p (const_bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 /* True if MAP is an empty bitmap. */
111
kono
parents: 67
diff changeset
391 inline bool bitmap_empty_p (const_bitmap map)
kono
parents: 67
diff changeset
392 {
kono
parents: 67
diff changeset
393 return !map->first;
kono
parents: 67
diff changeset
394 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 /* True if the bitmap has only a single bit set. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 extern bool bitmap_single_bit_set_p (const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 /* Count the number of bits set in the bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 extern unsigned long bitmap_count_bits (const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401
111
kono
parents: 67
diff changeset
402 /* Count the number of unique bits set across the two bitmaps. */
kono
parents: 67
diff changeset
403 extern unsigned long bitmap_count_unique_bits (const_bitmap, const_bitmap);
kono
parents: 67
diff changeset
404
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 /* Boolean operations on bitmaps. The _into variants are two operand
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
406 versions that modify the first source operand. The other variants
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 are three operand versions that to not destroy the source bitmaps.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 The operations supported are &, & ~, |, ^. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 extern void bitmap_and (bitmap, const_bitmap, const_bitmap);
111
kono
parents: 67
diff changeset
410 extern bool bitmap_and_into (bitmap, const_bitmap);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 extern bool bitmap_and_compl (bitmap, const_bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 extern bool bitmap_and_compl_into (bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 #define bitmap_compl_and(DST, A, B) bitmap_and_compl (DST, B, A)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 extern void bitmap_compl_and_into (bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
415 extern void bitmap_clear_range (bitmap, unsigned int, unsigned int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 extern void bitmap_set_range (bitmap, unsigned int, unsigned int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 extern bool bitmap_ior (bitmap, const_bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 extern bool bitmap_ior_into (bitmap, const_bitmap);
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
419 extern bool bitmap_ior_into_and_free (bitmap, bitmap *);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 extern void bitmap_xor (bitmap, const_bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 extern void bitmap_xor_into (bitmap, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
422
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
423 /* DST = A | (B & C). Return true if DST changes. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
424 extern bool bitmap_ior_and_into (bitmap DST, const_bitmap B, const_bitmap C);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 /* DST = A | (B & ~C). Return true if DST changes. */
111
kono
parents: 67
diff changeset
426 extern bool bitmap_ior_and_compl (bitmap DST, const_bitmap A,
kono
parents: 67
diff changeset
427 const_bitmap B, const_bitmap C);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 /* A |= (B & ~C). Return true if A changes. */
111
kono
parents: 67
diff changeset
429 extern bool bitmap_ior_and_compl_into (bitmap A,
kono
parents: 67
diff changeset
430 const_bitmap B, const_bitmap C);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 /* Clear a single bit in a bitmap. Return true if the bit changed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 extern bool bitmap_clear_bit (bitmap, int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 /* Set a single bit in a bitmap. Return true if the bit changed. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 extern bool bitmap_set_bit (bitmap, int);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
438 /* Return true if a bit is set in a bitmap. */
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
439 extern int bitmap_bit_p (const_bitmap, int);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
441 /* Debug functions to print a bitmap. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 extern void debug_bitmap (const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 extern void debug_bitmap_file (FILE *, const_bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 /* Print a bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 extern void bitmap_print (FILE *, const_bitmap, const char *, const char *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 /* Initialize and release a bitmap obstack. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 extern void bitmap_obstack_initialize (bitmap_obstack *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 extern void bitmap_obstack_release (bitmap_obstack *);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 extern void bitmap_register (bitmap MEM_STAT_DECL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 extern void dump_bitmap_statistics (void);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 /* Initialize a bitmap header. OBSTACK indicates the bitmap obstack
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 to allocate from, NULL for GC'd bitmap. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 static inline void
111
kono
parents: 67
diff changeset
458 bitmap_initialize (bitmap head, bitmap_obstack *obstack CXX_MEM_STAT_INFO)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 head->first = head->current = NULL;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
461 head->indx = head->tree_form = 0;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
462 head->padding = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
463 head->alloc_descriptor = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 head->obstack = obstack;
111
kono
parents: 67
diff changeset
465 if (GATHER_STATISTICS)
kono
parents: 67
diff changeset
466 bitmap_register (head PASS_MEM_STAT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
468
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
469 /* Release a bitmap (but not its head). This is suitable for pairing with
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
470 bitmap_initialize. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
471
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
472 static inline void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
473 bitmap_release (bitmap head)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
474 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
475 bitmap_clear (head);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
476 /* Poison the obstack pointer so the obstack can be safely released.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
477 Do not zero it as the bitmap then becomes initialized GC. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
478 head->obstack = &bitmap_head::crashme;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
479 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
480
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 /* Allocate and free bitmaps from obstack, malloc and gc'd memory. */
111
kono
parents: 67
diff changeset
482 extern bitmap bitmap_alloc (bitmap_obstack *obstack CXX_MEM_STAT_INFO);
kono
parents: 67
diff changeset
483 #define BITMAP_ALLOC bitmap_alloc
kono
parents: 67
diff changeset
484 extern bitmap bitmap_gc_alloc (ALONE_CXX_MEM_STAT_INFO);
kono
parents: 67
diff changeset
485 #define BITMAP_GGC_ALLOC bitmap_gc_alloc
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 extern void bitmap_obstack_free (bitmap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 /* A few compatibility/functions macros for compatibility with sbitmaps */
111
kono
parents: 67
diff changeset
489 inline void dump_bitmap (FILE *file, const_bitmap map)
kono
parents: 67
diff changeset
490 {
kono
parents: 67
diff changeset
491 bitmap_print (file, map, "", "\n");
kono
parents: 67
diff changeset
492 }
kono
parents: 67
diff changeset
493 extern void debug (const bitmap_head &ref);
kono
parents: 67
diff changeset
494 extern void debug (const bitmap_head *ptr);
kono
parents: 67
diff changeset
495
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 extern unsigned bitmap_first_set_bit (const_bitmap);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
497 extern unsigned bitmap_last_set_bit (const_bitmap);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 /* Compute bitmap hash (for purposes of hashing etc.) */
111
kono
parents: 67
diff changeset
500 extern hashval_t bitmap_hash (const_bitmap);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
501
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 /* Do any cleanup needed on a bitmap when it is no longer used. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 #define BITMAP_FREE(BITMAP) \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 ((void) (bitmap_obstack_free ((bitmap) BITMAP), (BITMAP) = (bitmap) NULL))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 /* Iterator for bitmaps. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507
111
kono
parents: 67
diff changeset
508 struct bitmap_iterator
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 /* Pointer to the current bitmap element. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 bitmap_element *elt1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 /* Pointer to 2nd bitmap element when two are involved. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 bitmap_element *elt2;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
515
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 /* Word within the current element. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 unsigned word_no;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 /* Contents of the actually processed word. When finding next bit
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 it is shifted right, so that the actual bit is always the least
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 significant bit of ACTUAL. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 BITMAP_WORD bits;
111
kono
parents: 67
diff changeset
523 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 /* Initialize a single bitmap iterator. START_BIT is the first bit to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 iterate from. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 bmp_iter_set_init (bitmap_iterator *bi, const_bitmap map,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 unsigned start_bit, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 bi->elt1 = map->first;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 bi->elt2 = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
535 gcc_checking_assert (!map->tree_form);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
536
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 /* Advance elt1 until it is not before the block containing start_bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 if (!bi->elt1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 bi->elt1 = &bitmap_zero_bits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 bi->elt1 = bi->elt1->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 /* We might have gone past the start bit, so reinitialize it. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 /* Initialize for what is now start_bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 bi->bits = bi->elt1->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 bi->bits >>= start_bit % BITMAP_WORD_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 /* If this word is zero, we must make sure we're not pointing at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 first bit, otherwise our incrementing to the next word boundary
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 will fail. It won't matter if this increment moves us into the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 next word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 start_bit += !bi->bits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566 *bit_no = start_bit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 /* Initialize an iterator to iterate over the intersection of two
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 bitmaps. START_BIT is the bit to commence from. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 bmp_iter_and_init (bitmap_iterator *bi, const_bitmap map1, const_bitmap map2,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 unsigned start_bit, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 bi->elt1 = map1->first;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 bi->elt2 = map2->first;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
579 gcc_checking_assert (!map1->tree_form && !map2->tree_form);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
580
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 /* Advance elt1 until it is not before the block containing
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 start_bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 if (!bi->elt1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 bi->elt2 = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 bi->elt1 = bi->elt1->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 /* Advance elt2 until it is not before elt1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 if (!bi->elt2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 bi->elt1 = bi->elt2 = &bitmap_zero_bits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 if (bi->elt2->indx >= bi->elt1->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 bi->elt2 = bi->elt2->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 /* If we're at the same index, then we have some intersecting bits. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 if (bi->elt1->indx == bi->elt2->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 /* We might have advanced beyond the start_bit, so reinitialize
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 for that. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
619 bi->bits = bi->elt1->bits[bi->word_no] & bi->elt2->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 bi->bits >>= start_bit % BITMAP_WORD_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 /* Otherwise we must immediately advance elt1, so initialize for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 that. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 bi->word_no = BITMAP_ELEMENT_WORDS - 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 bi->bits = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 /* If this word is zero, we must make sure we're not pointing at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 first bit, otherwise our incrementing to the next word boundary
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 will fail. It won't matter if this increment moves us into the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 next word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 start_bit += !bi->bits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 *bit_no = start_bit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
639 /* Initialize an iterator to iterate over the bits in MAP1 & ~MAP2. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 static inline void
111
kono
parents: 67
diff changeset
642 bmp_iter_and_compl_init (bitmap_iterator *bi,
kono
parents: 67
diff changeset
643 const_bitmap map1, const_bitmap map2,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 unsigned start_bit, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 bi->elt1 = map1->first;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 bi->elt2 = map2->first;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
649 gcc_checking_assert (!map1->tree_form && !map2->tree_form);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
650
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 /* Advance elt1 until it is not before the block containing start_bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 if (!bi->elt1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 bi->elt1 = &bitmap_zero_bits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 if (bi->elt1->indx >= start_bit / BITMAP_ELEMENT_ALL_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 bi->elt1 = bi->elt1->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 /* Advance elt2 until it is not before elt1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 while (bi->elt2 && bi->elt2->indx < bi->elt1->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 bi->elt2 = bi->elt2->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 /* We might have advanced beyond the start_bit, so reinitialize for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 that. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 if (bi->elt1->indx != start_bit / BITMAP_ELEMENT_ALL_BITS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 start_bit = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 bi->word_no = start_bit / BITMAP_WORD_BITS % BITMAP_ELEMENT_WORDS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 bi->bits = bi->elt1->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 if (bi->elt2 && bi->elt1->indx == bi->elt2->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 bi->bits &= ~bi->elt2->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 bi->bits >>= start_bit % BITMAP_WORD_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 /* If this word is zero, we must make sure we're not pointing at the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 first bit, otherwise our incrementing to the next word boundary
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 will fail. It won't matter if this increment moves us into the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 next word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 start_bit += !bi->bits;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 *bit_no = start_bit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 /* Advance to the next bit in BI. We don't advance to the next
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 nonzero bit yet. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 static inline void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 bmp_iter_next (bitmap_iterator *bi, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 bi->bits >>= 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 *bit_no += 1;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
699 /* Advance to first set bit in BI. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
700
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
701 static inline void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
702 bmp_iter_next_bit (bitmap_iterator * bi, unsigned *bit_no)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
703 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
704 #if (GCC_VERSION >= 3004)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
705 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
706 unsigned int n = __builtin_ctzl (bi->bits);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
707 gcc_assert (sizeof (unsigned long) == sizeof (BITMAP_WORD));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
708 bi->bits >>= n;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
709 *bit_no += n;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
710 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
711 #else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
712 while (!(bi->bits & 1))
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
713 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
714 bi->bits >>= 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
715 *bit_no += 1;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
716 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
717 #endif
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
718 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
719
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 /* Advance to the next nonzero bit of a single bitmap, we will have
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 already advanced past the just iterated bit. Return true if there
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 is a bit to iterate. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 static inline bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 bmp_iter_set (bitmap_iterator *bi, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 /* If our current word is nonzero, it contains the bit we want. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 if (bi->bits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 next_bit:
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
731 bmp_iter_next_bit (bi, bit_no);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
734
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 /* Round up to the word boundary. We might have just iterated past
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 the end of the last word, hence the -1. It is not possible for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 bit_no to point at the beginning of the now last word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 *bit_no = ((*bit_no + BITMAP_WORD_BITS - 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 / BITMAP_WORD_BITS * BITMAP_WORD_BITS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 bi->word_no++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 /* Find the next nonzero word in this elt. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 while (bi->word_no != BITMAP_ELEMENT_WORDS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 bi->bits = bi->elt1->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 if (bi->bits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 goto next_bit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 *bit_no += BITMAP_WORD_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 bi->word_no++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753
111
kono
parents: 67
diff changeset
754 /* Make sure we didn't remove the element while iterating. */
kono
parents: 67
diff changeset
755 gcc_checking_assert (bi->elt1->indx != -1U);
kono
parents: 67
diff changeset
756
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 /* Advance to the next element. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 bi->elt1 = bi->elt1->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 if (!bi->elt1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 *bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 bi->word_no = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 /* Advance to the next nonzero bit of an intersecting pair of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 bitmaps. We will have already advanced past the just iterated bit.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 Return true if there is a bit to iterate. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 static inline bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 bmp_iter_and (bitmap_iterator *bi, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
772 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 /* If our current word is nonzero, it contains the bit we want. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 if (bi->bits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
776 next_bit:
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
777 bmp_iter_next_bit (bi, bit_no);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
778 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
780
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 /* Round up to the word boundary. We might have just iterated past
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 the end of the last word, hence the -1. It is not possible for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
783 bit_no to point at the beginning of the now last word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 *bit_no = ((*bit_no + BITMAP_WORD_BITS - 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 / BITMAP_WORD_BITS * BITMAP_WORD_BITS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 bi->word_no++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
787
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 /* Find the next nonzero word in this elt. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 while (bi->word_no != BITMAP_ELEMENT_WORDS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
792 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 bi->bits = bi->elt1->bits[bi->word_no] & bi->elt2->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
794 if (bi->bits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
795 goto next_bit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
796 *bit_no += BITMAP_WORD_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
797 bi->word_no++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
798 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
799
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 /* Advance to the next identical element. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
802 {
111
kono
parents: 67
diff changeset
803 /* Make sure we didn't remove the element while iterating. */
kono
parents: 67
diff changeset
804 gcc_checking_assert (bi->elt1->indx != -1U);
kono
parents: 67
diff changeset
805
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
806 /* Advance elt1 while it is less than elt2. We always want
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
807 to advance one elt. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
808 do
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
809 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810 bi->elt1 = bi->elt1->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 if (!bi->elt1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
813 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
814 while (bi->elt1->indx < bi->elt2->indx);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
815
111
kono
parents: 67
diff changeset
816 /* Make sure we didn't remove the element while iterating. */
kono
parents: 67
diff changeset
817 gcc_checking_assert (bi->elt2->indx != -1U);
kono
parents: 67
diff changeset
818
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
819 /* Advance elt2 to be no less than elt1. This might not
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
820 advance. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
821 while (bi->elt2->indx < bi->elt1->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
822 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
823 bi->elt2 = bi->elt2->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
824 if (!bi->elt2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
825 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
826 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
827 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
828 while (bi->elt1->indx != bi->elt2->indx);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
829
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
830 *bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831 bi->word_no = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 /* Advance to the next nonzero bit in the intersection of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 complemented bitmaps. We will have already advanced past the just
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 iterated bit. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 static inline bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 bmp_iter_and_compl (bitmap_iterator *bi, unsigned *bit_no)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
842 /* If our current word is nonzero, it contains the bit we want. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 if (bi->bits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 next_bit:
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
846 bmp_iter_next_bit (bi, bit_no);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 /* Round up to the word boundary. We might have just iterated past
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851 the end of the last word, hence the -1. It is not possible for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 bit_no to point at the beginning of the now last word. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 *bit_no = ((*bit_no + BITMAP_WORD_BITS - 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854 / BITMAP_WORD_BITS * BITMAP_WORD_BITS);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 bi->word_no++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
857 while (1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
858 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 /* Find the next nonzero word in this elt. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
860 while (bi->word_no != BITMAP_ELEMENT_WORDS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
861 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862 bi->bits = bi->elt1->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
863 if (bi->elt2 && bi->elt2->indx == bi->elt1->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 bi->bits &= ~bi->elt2->bits[bi->word_no];
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 if (bi->bits)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 goto next_bit;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 *bit_no += BITMAP_WORD_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 bi->word_no++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870
111
kono
parents: 67
diff changeset
871 /* Make sure we didn't remove the element while iterating. */
kono
parents: 67
diff changeset
872 gcc_checking_assert (bi->elt1->indx != -1U);
kono
parents: 67
diff changeset
873
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 /* Advance to the next element of elt1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 bi->elt1 = bi->elt1->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
876 if (!bi->elt1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878
111
kono
parents: 67
diff changeset
879 /* Make sure we didn't remove the element while iterating. */
kono
parents: 67
diff changeset
880 gcc_checking_assert (! bi->elt2 || bi->elt2->indx != -1U);
kono
parents: 67
diff changeset
881
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 /* Advance elt2 until it is no less than elt1. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 while (bi->elt2 && bi->elt2->indx < bi->elt1->indx)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 bi->elt2 = bi->elt2->next;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 *bit_no = bi->elt1->indx * BITMAP_ELEMENT_ALL_BITS;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
887 bi->word_no = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
889 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
890
111
kono
parents: 67
diff changeset
891 /* If you are modifying a bitmap you are currently iterating over you
kono
parents: 67
diff changeset
892 have to ensure to
kono
parents: 67
diff changeset
893 - never remove the current bit;
kono
parents: 67
diff changeset
894 - if you set or clear a bit before the current bit this operation
kono
parents: 67
diff changeset
895 will not affect the set of bits you are visiting during the iteration;
kono
parents: 67
diff changeset
896 - if you set or clear a bit after the current bit it is unspecified
kono
parents: 67
diff changeset
897 whether that affects the set of bits you are visiting during the
kono
parents: 67
diff changeset
898 iteration.
kono
parents: 67
diff changeset
899 If you want to remove the current bit you can delay this to the next
kono
parents: 67
diff changeset
900 iteration (and after the iteration in case the last iteration is
kono
parents: 67
diff changeset
901 affected). */
kono
parents: 67
diff changeset
902
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 /* Loop over all bits set in BITMAP, starting with MIN and setting
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 BITNUM to the bit number. ITER is a bitmap iterator. BITNUM
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905 should be treated as a read-only variable as it contains loop
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 state. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907
111
kono
parents: 67
diff changeset
908 #ifndef EXECUTE_IF_SET_IN_BITMAP
kono
parents: 67
diff changeset
909 /* See sbitmap.h for the other definition of EXECUTE_IF_SET_IN_BITMAP. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 #define EXECUTE_IF_SET_IN_BITMAP(BITMAP, MIN, BITNUM, ITER) \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 for (bmp_iter_set_init (&(ITER), (BITMAP), (MIN), &(BITNUM)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
912 bmp_iter_set (&(ITER), &(BITNUM)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
913 bmp_iter_next (&(ITER), &(BITNUM)))
111
kono
parents: 67
diff changeset
914 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
915
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 /* Loop over all the bits set in BITMAP1 & BITMAP2, starting with MIN
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 and setting BITNUM to the bit number. ITER is a bitmap iterator.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 BITNUM should be treated as a read-only variable as it contains
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
919 loop state. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
920
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 #define EXECUTE_IF_AND_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, ITER) \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
922 for (bmp_iter_and_init (&(ITER), (BITMAP1), (BITMAP2), (MIN), \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
923 &(BITNUM)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
924 bmp_iter_and (&(ITER), &(BITNUM)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
925 bmp_iter_next (&(ITER), &(BITNUM)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
926
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 /* Loop over all the bits set in BITMAP1 & ~BITMAP2, starting with MIN
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 and setting BITNUM to the bit number. ITER is a bitmap iterator.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
929 BITNUM should be treated as a read-only variable as it contains
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
930 loop state. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
931
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
932 #define EXECUTE_IF_AND_COMPL_IN_BITMAP(BITMAP1, BITMAP2, MIN, BITNUM, ITER) \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
933 for (bmp_iter_and_compl_init (&(ITER), (BITMAP1), (BITMAP2), (MIN), \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
934 &(BITNUM)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 bmp_iter_and_compl (&(ITER), &(BITNUM)); \
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 bmp_iter_next (&(ITER), &(BITNUM)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937
111
kono
parents: 67
diff changeset
938 /* A class that ties the lifetime of a bitmap to its scope. */
kono
parents: 67
diff changeset
939 class auto_bitmap
kono
parents: 67
diff changeset
940 {
kono
parents: 67
diff changeset
941 public:
kono
parents: 67
diff changeset
942 auto_bitmap () { bitmap_initialize (&m_bits, &bitmap_default_obstack); }
kono
parents: 67
diff changeset
943 explicit auto_bitmap (bitmap_obstack *o) { bitmap_initialize (&m_bits, o); }
kono
parents: 67
diff changeset
944 ~auto_bitmap () { bitmap_clear (&m_bits); }
kono
parents: 67
diff changeset
945 // Allow calling bitmap functions on our bitmap.
kono
parents: 67
diff changeset
946 operator bitmap () { return &m_bits; }
kono
parents: 67
diff changeset
947
kono
parents: 67
diff changeset
948 private:
kono
parents: 67
diff changeset
949 // Prevent making a copy that references our bitmap.
kono
parents: 67
diff changeset
950 auto_bitmap (const auto_bitmap &);
kono
parents: 67
diff changeset
951 auto_bitmap &operator = (const auto_bitmap &);
kono
parents: 67
diff changeset
952 #if __cplusplus >= 201103L
kono
parents: 67
diff changeset
953 auto_bitmap (auto_bitmap &&);
kono
parents: 67
diff changeset
954 auto_bitmap &operator = (auto_bitmap &&);
kono
parents: 67
diff changeset
955 #endif
kono
parents: 67
diff changeset
956
kono
parents: 67
diff changeset
957 bitmap_head m_bits;
kono
parents: 67
diff changeset
958 };
kono
parents: 67
diff changeset
959
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
960 /* Base class for bitmap_view; see there for details. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
961 template<typename T, typename Traits = array_traits<T> >
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
962 class base_bitmap_view
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
963 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
964 public:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
965 typedef typename Traits::element_type array_element_type;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
966
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
967 base_bitmap_view (const T &, bitmap_element *);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
968 operator const_bitmap () const { return &m_head; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
969
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
970 private:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
971 base_bitmap_view (const base_bitmap_view &);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
972
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
973 bitmap_head m_head;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
974 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
975
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
976 /* Provides a read-only bitmap view of a single integer bitmask or a
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
977 constant-sized array of integer bitmasks, or of a wrapper around such
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
978 bitmasks. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
979 template<typename T, typename Traits>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
980 class bitmap_view<T, Traits, true> : public base_bitmap_view<T, Traits>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
981 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
982 public:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
983 bitmap_view (const T &array)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
984 : base_bitmap_view<T, Traits> (array, m_bitmap_elements) {}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
985
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
986 private:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
987 /* How many bitmap_elements we need to hold a full T. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
988 static const size_t num_bitmap_elements
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
989 = CEIL (CHAR_BIT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
990 * sizeof (typename Traits::element_type)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
991 * Traits::constant_size,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
992 BITMAP_ELEMENT_ALL_BITS);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
993 bitmap_element m_bitmap_elements[num_bitmap_elements];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
994 };
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
995
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
996 /* Initialize the view for array ARRAY, using the array of bitmap
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
997 elements in BITMAP_ELEMENTS (which is known to contain enough
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
998 entries). */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
999 template<typename T, typename Traits>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1000 base_bitmap_view<T, Traits>::base_bitmap_view (const T &array,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1001 bitmap_element *bitmap_elements)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1002 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1003 m_head.obstack = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1004
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1005 /* The code currently assumes that each element of ARRAY corresponds
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1006 to exactly one bitmap_element. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1007 const size_t array_element_bits = CHAR_BIT * sizeof (array_element_type);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1008 STATIC_ASSERT (BITMAP_ELEMENT_ALL_BITS % array_element_bits == 0);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1009 size_t array_step = BITMAP_ELEMENT_ALL_BITS / array_element_bits;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1010 size_t array_size = Traits::size (array);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1011
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1012 /* Process each potential bitmap_element in turn. The loop is written
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1013 this way rather than per array element because usually there are
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1014 only a small number of array elements per bitmap element (typically
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1015 two or four). The inner loops should therefore unroll completely. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1016 const array_element_type *array_elements = Traits::base (array);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1017 unsigned int indx = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1018 for (size_t array_base = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1019 array_base < array_size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1020 array_base += array_step, indx += 1)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1021 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1022 /* How many array elements are in this particular bitmap_element. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1023 unsigned int array_count
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1024 = (STATIC_CONSTANT_P (array_size % array_step == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1025 ? array_step : MIN (array_step, array_size - array_base));
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1026
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1027 /* See whether we need this bitmap element. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1028 array_element_type ior = array_elements[array_base];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1029 for (size_t i = 1; i < array_count; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1030 ior |= array_elements[array_base + i];
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1031 if (ior == 0)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1032 continue;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1033
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1034 /* Grab the next bitmap element and chain it. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1035 bitmap_element *bitmap_element = bitmap_elements++;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1036 if (m_head.current)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1037 m_head.current->next = bitmap_element;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1038 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1039 m_head.first = bitmap_element;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1040 bitmap_element->prev = m_head.current;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1041 bitmap_element->next = NULL;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1042 bitmap_element->indx = indx;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1043 m_head.current = bitmap_element;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1044 m_head.indx = indx;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1045
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1046 /* Fill in the bits of the bitmap element. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1047 if (array_element_bits < BITMAP_WORD_BITS)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1048 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1049 /* Multiple array elements fit in one element of
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1050 bitmap_element->bits. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1051 size_t array_i = array_base;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1052 for (unsigned int word_i = 0; word_i < BITMAP_ELEMENT_WORDS;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1053 ++word_i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1054 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1055 BITMAP_WORD word = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1056 for (unsigned int shift = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1057 shift < BITMAP_WORD_BITS && array_i < array_size;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1058 shift += array_element_bits)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1059 word |= array_elements[array_i++] << shift;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1060 bitmap_element->bits[word_i] = word;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1061 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1062 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1063 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1064 {
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1065 /* Array elements are the same size as elements of
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1066 bitmap_element->bits, or are an exact multiple of that size. */
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1067 unsigned int word_i = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1068 for (unsigned int i = 0; i < array_count; ++i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1069 for (unsigned int shift = 0; shift < array_element_bits;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1070 shift += BITMAP_WORD_BITS)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1071 bitmap_element->bits[word_i++]
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1072 = array_elements[array_base + i] >> shift;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1073 while (word_i < BITMAP_ELEMENT_WORDS)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1074 bitmap_element->bits[word_i++] = 0;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1075 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1076 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1077 }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1078
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1079 #endif /* GCC_BITMAP_H */