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