xref: /openbsd/gnu/usr.bin/gcc/gcc/sbitmap.h (revision c87b03e5)
1*c87b03e5Sespie /* Simple bitmaps.
2*c87b03e5Sespie    Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
3*c87b03e5Sespie 
4*c87b03e5Sespie This file is part of GCC.
5*c87b03e5Sespie 
6*c87b03e5Sespie GCC is free software; you can redistribute it and/or modify it under
7*c87b03e5Sespie the terms of the GNU General Public License as published by the Free
8*c87b03e5Sespie Software Foundation; either version 2, or (at your option) any later
9*c87b03e5Sespie version.
10*c87b03e5Sespie 
11*c87b03e5Sespie GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*c87b03e5Sespie WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*c87b03e5Sespie FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14*c87b03e5Sespie for more details.
15*c87b03e5Sespie 
16*c87b03e5Sespie You should have received a copy of the GNU General Public License
17*c87b03e5Sespie along with GCC; see the file COPYING.  If not, write to the Free
18*c87b03e5Sespie Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19*c87b03e5Sespie 02111-1307, USA.  */
20*c87b03e5Sespie 
21*c87b03e5Sespie #ifndef GCC_SBITMAP_H
22*c87b03e5Sespie #define GCC_SBITMAP_H
23*c87b03e5Sespie 
24*c87b03e5Sespie /* It's not clear yet whether using bitmap.[ch] will be a win.
25*c87b03e5Sespie    It should be straightforward to convert so for now we keep things simple
26*c87b03e5Sespie    while more important issues are dealt with.  */
27*c87b03e5Sespie 
28*c87b03e5Sespie #define SBITMAP_ELT_BITS ((unsigned) HOST_BITS_PER_WIDE_INT)
29*c87b03e5Sespie #define SBITMAP_ELT_TYPE unsigned HOST_WIDE_INT
30*c87b03e5Sespie 
31*c87b03e5Sespie typedef struct simple_bitmap_def
32*c87b03e5Sespie {
33*c87b03e5Sespie   unsigned int n_bits;		/* Number of bits.  */
34*c87b03e5Sespie   unsigned int size;		/* Size in elements.  */
35*c87b03e5Sespie   unsigned int bytes;		/* Size in bytes.  */
36*c87b03e5Sespie   SBITMAP_ELT_TYPE elms[1];	/* The elements.  */
37*c87b03e5Sespie } *sbitmap;
38*c87b03e5Sespie 
39*c87b03e5Sespie typedef SBITMAP_ELT_TYPE *sbitmap_ptr;
40*c87b03e5Sespie 
41*c87b03e5Sespie /* Return the set size needed for N elements.  */
42*c87b03e5Sespie #define SBITMAP_SET_SIZE(N) (((N) + SBITMAP_ELT_BITS - 1) / SBITMAP_ELT_BITS)
43*c87b03e5Sespie 
44*c87b03e5Sespie /* Set bit number bitno in the bitmap.  */
45*c87b03e5Sespie #define SET_BIT(BITMAP, BITNO)					\
46*c87b03e5Sespie   ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS]			\
47*c87b03e5Sespie    |= (SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS)
48*c87b03e5Sespie 
49*c87b03e5Sespie /* Test if bit number bitno in the bitmap is set.  */
50*c87b03e5Sespie #define TEST_BIT(BITMAP, BITNO) \
51*c87b03e5Sespie ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS] >> (BITNO) % SBITMAP_ELT_BITS & 1)
52*c87b03e5Sespie 
53*c87b03e5Sespie /* Reset bit number bitno in the bitmap.  */
54*c87b03e5Sespie #define RESET_BIT(BITMAP, BITNO)				\
55*c87b03e5Sespie   ((BITMAP)->elms [(BITNO) / SBITMAP_ELT_BITS]			\
56*c87b03e5Sespie    &= ~((SBITMAP_ELT_TYPE) 1 << (BITNO) % SBITMAP_ELT_BITS))
57*c87b03e5Sespie 
58*c87b03e5Sespie /* Loop over all elements of SBITSET, starting with MIN.  */
59*c87b03e5Sespie #define EXECUTE_IF_SET_IN_SBITMAP(SBITMAP, MIN, N, CODE)		\
60*c87b03e5Sespie do {									\
61*c87b03e5Sespie   unsigned int word_num_;						\
62*c87b03e5Sespie   unsigned int bit_num_ = (MIN) % (unsigned int) SBITMAP_ELT_BITS;	\
63*c87b03e5Sespie   unsigned int size_ = (SBITMAP)->size;					\
64*c87b03e5Sespie   SBITMAP_ELT_TYPE *ptr_ = (SBITMAP)->elms;				\
65*c87b03e5Sespie 									\
66*c87b03e5Sespie   for (word_num_ = (MIN) / (unsigned int) SBITMAP_ELT_BITS;		\
67*c87b03e5Sespie        word_num_ < size_; word_num_++, bit_num_ = 0)			\
68*c87b03e5Sespie     {									\
69*c87b03e5Sespie       SBITMAP_ELT_TYPE word_ = ptr_[word_num_];				\
70*c87b03e5Sespie 									\
71*c87b03e5Sespie       if (word_ != 0)							\
72*c87b03e5Sespie 	for (; bit_num_ < SBITMAP_ELT_BITS; bit_num_++)			\
73*c87b03e5Sespie 	  {								\
74*c87b03e5Sespie 	    SBITMAP_ELT_TYPE _mask = (SBITMAP_ELT_TYPE) 1 << bit_num_;	\
75*c87b03e5Sespie 									\
76*c87b03e5Sespie 	    if ((word_ & _mask) != 0)					\
77*c87b03e5Sespie 	      {								\
78*c87b03e5Sespie 		word_ &= ~ _mask;					\
79*c87b03e5Sespie 		(N) = word_num_ * SBITMAP_ELT_BITS + bit_num_;		\
80*c87b03e5Sespie 		CODE;							\
81*c87b03e5Sespie 		if (word_ == 0)						\
82*c87b03e5Sespie 		  break;						\
83*c87b03e5Sespie 	      }								\
84*c87b03e5Sespie 	  }								\
85*c87b03e5Sespie     }									\
86*c87b03e5Sespie } while (0)
87*c87b03e5Sespie 
88*c87b03e5Sespie #define EXECUTE_IF_SET_IN_SBITMAP_REV(SBITMAP, N, CODE)			\
89*c87b03e5Sespie do {									\
90*c87b03e5Sespie   unsigned int word_num_;						\
91*c87b03e5Sespie   unsigned int bit_num_;						\
92*c87b03e5Sespie   unsigned int size_ = (SBITMAP)->size;					\
93*c87b03e5Sespie   SBITMAP_ELT_TYPE *ptr_ = (SBITMAP)->elms;				\
94*c87b03e5Sespie 									\
95*c87b03e5Sespie   for (word_num_ = size_; word_num_ > 0; word_num_--)			\
96*c87b03e5Sespie     {									\
97*c87b03e5Sespie       SBITMAP_ELT_TYPE word_ = ptr_[word_num_ - 1];			\
98*c87b03e5Sespie 									\
99*c87b03e5Sespie       if (word_ != 0)							\
100*c87b03e5Sespie 	for (bit_num_ = SBITMAP_ELT_BITS; bit_num_ > 0; bit_num_--)	\
101*c87b03e5Sespie 	  {								\
102*c87b03e5Sespie 	    SBITMAP_ELT_TYPE _mask = (SBITMAP_ELT_TYPE)1 << (bit_num_ - 1);\
103*c87b03e5Sespie 									\
104*c87b03e5Sespie 	    if ((word_ & _mask) != 0)					\
105*c87b03e5Sespie 	      {								\
106*c87b03e5Sespie 		word_ &= ~ _mask;					\
107*c87b03e5Sespie 		(N) = (word_num_ - 1) * SBITMAP_ELT_BITS + bit_num_ - 1;\
108*c87b03e5Sespie 		CODE;							\
109*c87b03e5Sespie 		if (word_ == 0)						\
110*c87b03e5Sespie 		  break;						\
111*c87b03e5Sespie 	      }								\
112*c87b03e5Sespie 	  }								\
113*c87b03e5Sespie     }									\
114*c87b03e5Sespie } while (0)
115*c87b03e5Sespie 
116*c87b03e5Sespie #define sbitmap_free(MAP)		free(MAP)
117*c87b03e5Sespie #define sbitmap_vector_free(VEC)	free(VEC)
118*c87b03e5Sespie 
119*c87b03e5Sespie struct int_list;
120*c87b03e5Sespie 
121*c87b03e5Sespie extern void dump_sbitmap		PARAMS ((FILE *, sbitmap));
122*c87b03e5Sespie extern void dump_sbitmap_file		PARAMS ((FILE *, sbitmap));
123*c87b03e5Sespie extern void dump_sbitmap_vector 	PARAMS ((FILE *, const char *,
124*c87b03e5Sespie 						 const char *, sbitmap *,
125*c87b03e5Sespie 						 int));
126*c87b03e5Sespie extern sbitmap sbitmap_alloc		PARAMS ((unsigned int));
127*c87b03e5Sespie extern sbitmap *sbitmap_vector_alloc	PARAMS ((unsigned int, unsigned int));
128*c87b03e5Sespie extern sbitmap sbitmap_resize		PARAMS ((sbitmap, unsigned int, int));
129*c87b03e5Sespie extern void sbitmap_copy 		PARAMS ((sbitmap, sbitmap));
130*c87b03e5Sespie extern int sbitmap_equal                PARAMS ((sbitmap, sbitmap));
131*c87b03e5Sespie extern void sbitmap_zero		PARAMS ((sbitmap));
132*c87b03e5Sespie extern void sbitmap_ones		PARAMS ((sbitmap));
133*c87b03e5Sespie extern void sbitmap_vector_zero		PARAMS ((sbitmap *, unsigned int));
134*c87b03e5Sespie extern void sbitmap_vector_ones		PARAMS ((sbitmap *, unsigned int));
135*c87b03e5Sespie 
136*c87b03e5Sespie extern void sbitmap_union_of_diff	PARAMS ((sbitmap, sbitmap, sbitmap,
137*c87b03e5Sespie 						 sbitmap));
138*c87b03e5Sespie extern bool sbitmap_union_of_diff_cg	PARAMS ((sbitmap, sbitmap, sbitmap,
139*c87b03e5Sespie 						 sbitmap));
140*c87b03e5Sespie extern void sbitmap_difference		PARAMS ((sbitmap, sbitmap, sbitmap));
141*c87b03e5Sespie extern void sbitmap_not			PARAMS ((sbitmap, sbitmap));
142*c87b03e5Sespie extern void sbitmap_a_or_b_and_c	PARAMS ((sbitmap, sbitmap, sbitmap,
143*c87b03e5Sespie 						 sbitmap));
144*c87b03e5Sespie extern bool sbitmap_a_or_b_and_c_cg	PARAMS ((sbitmap, sbitmap, sbitmap,
145*c87b03e5Sespie 						 sbitmap));
146*c87b03e5Sespie extern void sbitmap_a_and_b_or_c	PARAMS ((sbitmap, sbitmap, sbitmap,
147*c87b03e5Sespie 						 sbitmap));
148*c87b03e5Sespie extern bool sbitmap_a_and_b_or_c_cg	PARAMS ((sbitmap, sbitmap, sbitmap,
149*c87b03e5Sespie 						 sbitmap));
150*c87b03e5Sespie extern void sbitmap_a_and_b		PARAMS ((sbitmap, sbitmap, sbitmap));
151*c87b03e5Sespie extern bool sbitmap_a_and_b_cg		PARAMS ((sbitmap, sbitmap, sbitmap));
152*c87b03e5Sespie extern void sbitmap_a_or_b		PARAMS ((sbitmap, sbitmap, sbitmap));
153*c87b03e5Sespie extern bool sbitmap_a_or_b_cg		PARAMS ((sbitmap, sbitmap, sbitmap));
154*c87b03e5Sespie extern void sbitmap_a_xor_b		PARAMS ((sbitmap, sbitmap, sbitmap));
155*c87b03e5Sespie extern bool sbitmap_a_xor_b_cg		PARAMS ((sbitmap, sbitmap, sbitmap));
156*c87b03e5Sespie extern bool sbitmap_a_subset_b_p	PARAMS ((sbitmap, sbitmap));
157*c87b03e5Sespie 
158*c87b03e5Sespie extern int sbitmap_first_set_bit	PARAMS ((sbitmap));
159*c87b03e5Sespie extern int sbitmap_last_set_bit		PARAMS ((sbitmap));
160*c87b03e5Sespie 
161*c87b03e5Sespie extern void sbitmap_intersect_of_predsucc PARAMS ((sbitmap, sbitmap *,
162*c87b03e5Sespie 						  int, struct int_list **));
163*c87b03e5Sespie #define sbitmap_intersect_of_predecessors  sbitmap_intersect_of_predsucc
164*c87b03e5Sespie #define sbitmap_intersect_of_successors    sbitmap_intersect_of_predsucc
165*c87b03e5Sespie 
166*c87b03e5Sespie extern void sbitmap_union_of_predsucc	PARAMS ((sbitmap, sbitmap *, int,
167*c87b03e5Sespie 						 struct int_list **));
168*c87b03e5Sespie #define sbitmap_union_of_predecessors  sbitmap_union_of_predsucc
169*c87b03e5Sespie #define sbitmap_union_of_successors    sbitmap_union_of_predsucc
170*c87b03e5Sespie 
171*c87b03e5Sespie /* Intersection and Union of preds/succs using the new flow graph
172*c87b03e5Sespie    structure instead of the pred/succ arrays.  */
173*c87b03e5Sespie 
174*c87b03e5Sespie extern void sbitmap_intersection_of_succs  PARAMS ((sbitmap, sbitmap *, int));
175*c87b03e5Sespie extern void sbitmap_intersection_of_preds  PARAMS ((sbitmap, sbitmap *, int));
176*c87b03e5Sespie extern void sbitmap_union_of_succs	   PARAMS ((sbitmap, sbitmap *, int));
177*c87b03e5Sespie extern void sbitmap_union_of_preds	   PARAMS ((sbitmap, sbitmap *, int));
178*c87b03e5Sespie 
179*c87b03e5Sespie extern void debug_sbitmap		   PARAMS ((sbitmap));
180*c87b03e5Sespie #endif /* ! GCC_SBITMAP_H */
181