GCC Middle and Back End API Reference
value-range-storage.h
Go to the documentation of this file.
1/* Support routines for vrange storage.
2 Copyright (C) 2022-2026 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 3, or (at your option)
10any later version.
11
12GCC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_VALUE_RANGE_STORAGE_H
22#define GCC_VALUE_RANGE_STORAGE_H
23
24// This class is used to allocate chunks of memory that can store
25// ranges as memory efficiently as possible.
26
28{
29public:
30 // Use GC memory when GC is true, otherwise use obstacks.
31 vrange_allocator (bool gc = false);
33 class vrange_storage *clone (const vrange &r, bool shared_p = true);
36 void *alloc (size_t size);
37 void free (void *);
38private:
41};
42
43// Efficient memory storage for a vrange.
44
45class GTY((desc ("%h.m_discriminator"), tag("VR_UNKNOWN"))) vrange_storage
46{
47public:
49 bool shared_p = true);
50 void get_vrange (vrange &r, tree type) const;
51 void set_vrange (const vrange &r);
52 bool fits_p (const vrange &r) const;
53 bool equal_p (const vrange &r) const;
54
55 class irange_storage *dyn_irange ();
56 class prange_storage *dyn_prange ();
57 class frange_storage *dyn_frange ();
58 const irange_storage *dyn_irange () const;
59 const prange_storage *dyn_prange () const;
60 const frange_storage *dyn_frange () const;
61 // Stack initialization disallowed.
64};
65
66// Efficient memory storage for an irange.
67
68class GTY((tag ("VR_IRANGE"))) irange_storage: public vrange_storage
69{
70public:
72 void set_irange (const irange &r);
73 void get_irange (irange &r, tree type) const;
74 bool equal_p (const irange &r) const;
75 bool fits_p (const irange &r) const;
76 void dump () const;
77private:
79 static size_t size (const irange &r);
80 const unsigned short *lengths_address () const;
81 unsigned short *write_lengths_address ();
82
83 // The shared precision of each number.
84 unsigned short m_precision;
85
86 // The max number of sub-ranges that fit in this storage.
87 const unsigned char m_max_ranges;
88
89 // The number of stored sub-ranges.
90 unsigned char m_num_ranges;
91
93
94 // The length of this is m_num_ranges * 2 + 2 to accommodate the bitmask.
95 HOST_WIDE_INT m_val[1];
96
97 // Another variable-length part of the structure following the HWIs.
98 // This is the length of each wide_int in m_val.
99 //
100 // unsigned short m_len[];
101
102 irange_storage (const irange &r);
103};
104
105
106// A prange_kind summarizes some common variations for a prange, and is used
107// in a prange_storage clas for efficiency.
108
109enum prange_kind { PR_UNDEFINED, // VR_UNDEFINED
110 PR_VARYING, // VR_VARYING
111 PR_ZERO, // [0, 0]
112 PR_NONZERO, // [1, +INF] (May have bitmask)
113 PR_FULL, // [0, +INF] (Must have bitmask)
114 PR_OTHER }; // [x, y] (MAy have bitmask)
115
116// Maximum number of words that may be allocated by a prange_storage class.
117const unsigned int PRANGE_STORAGE_NINTS = 4;
118
119// Efficient memory storage for a prange.
120class GTY((tag ("VR_PRANGE"))) prange_storage : public vrange_storage
121{
122private:
123 // vrange_storage ends after four bytes but the first pointer member below
124 // needs eight-byte alignment, so there is a four-byte hole.
126 unsigned int m_has_bitmask : 1;
127 unsigned int m_known_p : 1;
128
129public:
130 friend void gt_ggc_mx_vrange_storage(void *);
131 friend void gt_pch_nx_vrange_storage(void *);
133 void *);
135 bool shared_p = true);
136 void set_prange (const prange &r);
137 void get_prange (prange &r, tree type) const;
138 bool equal_p (const prange &r) const;
139 bool fits_p (const prange &r) const;
140 bool undefined_p () const { return m_kind == PR_UNDEFINED; }
141 irange_bitmask get_bitmask (tree type) const;
142 bool nonnull_p (tree type) const;
143 void set_nonnull (tree type);
144 void dump () const;
145
146 // The points-to solution for the SSA name is flow insensitive and is
147 // reached only through ssa_name_pt_solution.
149
150private:
152 prange_storage (const prange &r);
153 static enum prange_kind prange_format (const prange &r, unsigned &num_words);
154
156
157 // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
158 // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
159 // const and return wide_int instead of trailing_wide_int.
160 wide_int get_word (unsigned i, tree) const
161 { return m_trailing_ints[i]; }
162 template <typename T> void set_word (unsigned i, const T &x, tree)
163 { m_trailing_ints[i] = x; }
164
166};
167
168// Return TRUE if this range of type TYPE does not contain zero.
169
170inline bool
172{
173 switch (m_kind)
174 {
175 case PR_UNDEFINED:
176 case PR_VARYING:
177 case PR_ZERO:
178 case PR_FULL:
179 return false;
180 case PR_NONZERO:
181 return true;
182 case PR_OTHER:
183 return (get_word (0, type) != 0);
184 default:
186 }
187}
188
189
190// Efficient memory storage for an frange.
191
192class GTY((tag ("VR_FRANGE"))) frange_storage : public vrange_storage
193{
194 public:
196 void set_frange (const frange &r);
197 void get_frange (frange &r, tree type) const;
198 bool equal_p (const frange &r) const;
199 bool fits_p (const frange &) const;
200 private:
201 frange_storage (const frange &r);
203 static size_t size (const frange &r);
204
206 // The max number of sub-ranges that fit in this storage.
207 const unsigned char m_max_ranges;
208 unsigned char m_num_ranges;
212};
213
214inline irange_storage *
216{
218 return static_cast <irange_storage *> (this);
219 return NULL;
220}
221
222inline prange_storage *
224{
226 return static_cast <prange_storage *> (this);
227 return NULL;
228}
229
230inline frange_storage *
232{
234 return static_cast <frange_storage *> (this);
235 return NULL;
236}
237
238inline const irange_storage *
240{
242 return static_cast <const irange_storage *> (this);
243 return NULL;
244}
245
246inline const prange_storage *
248{
250 return static_cast <const prange_storage *> (this);
251 return NULL;
252}
253
254inline const frange_storage *
256{
258 return static_cast <const frange_storage *> (this);
259 return NULL;
260}
263 bool shared_p = true);
264
265#endif // GCC_VALUE_RANGE_STORAGE_H
Definition value-range-storage.h:193
static size_t size(const frange &r)
Definition value-range-storage.cc:481
void get_frange(frange &r, tree type) const
Definition value-range-storage.cc:517
bool fits_p(const frange &) const
Definition value-range-storage.cc:574
static frange_storage * alloc(vrange_internal_alloc &, const frange &r)
Definition value-range-storage.cc:489
bool m_neg_nan
Definition value-range-storage.h:210
bool m_pos_nan
Definition value-range-storage.h:209
DISABLE_COPY_AND_ASSIGN(frange_storage)
unsigned char m_num_ranges
Definition value-range-storage.h:208
const unsigned char m_max_ranges
Definition value-range-storage.h:207
bool equal_p(const frange &r) const
Definition value-range-storage.cc:563
enum value_range_kind m_kind
Definition value-range-storage.h:205
frange_pair m_pairs[1]
Definition value-range-storage.h:211
frange_storage(const frange &r)
Definition value-range-storage.cc:497
void set_frange(const frange &r)
Definition value-range-storage.cc:504
Definition value-range.h:603
Definition value-range.h:152
Definition value-range-storage.h:69
static size_t size(const irange &r)
Definition value-range-storage.cc:408
irange_storage(const irange &r)
Definition value-range-storage.cc:268
static irange_storage * alloc(vrange_internal_alloc &, const irange &)
Definition value-range-storage.cc:258
bool equal_p(const irange &r) const
Definition value-range-storage.cc:391
unsigned short m_precision
Definition value-range-storage.h:84
HOST_WIDE_INT m_val[1]
Definition value-range-storage.h:95
const unsigned char m_max_ranges
Definition value-range-storage.h:87
void set_irange(const irange &r)
Definition value-range-storage.cc:287
unsigned short * write_lengths_address()
Definition value-range-storage.cc:243
const unsigned short * lengths_address() const
Definition value-range-storage.cc:250
bool fits_p(const irange &r) const
Definition value-range-storage.cc:424
enum value_range_kind m_kind
Definition value-range-storage.h:92
DISABLE_COPY_AND_ASSIGN(irange_storage)
void dump() const
Definition value-range-storage.cc:430
unsigned char m_num_ranges
Definition value-range-storage.h:90
void get_irange(irange &r, tree type) const
Definition value-range-storage.cc:333
Definition value-range.h:291
Definition value-range-storage.h:121
static prange_storage * alloc(vrange_internal_alloc &, const prange &, bool shared_p=true)
Definition value-range-storage.cc:584
bool undefined_p() const
Definition value-range-storage.h:140
void set_nonnull(tree type)
Definition value-range-storage.cc:856
bool nonnull_p(tree type) const
Definition value-range-storage.h:171
void dump() const
unsigned int m_known_p
Definition value-range-storage.h:127
wide_int get_word(unsigned i, tree) const
Definition value-range-storage.h:160
static enum prange_kind prange_format(const prange &r, unsigned &num_words)
Definition value-range-storage.cc:643
friend void gt_pch_p_14vrange_storage(void *, void *, gt_pointer_operator, void *)
void set_prange(const prange &r)
Definition value-range-storage.cc:682
bool fits_p(const prange &r) const
Definition value-range-storage.cc:841
bool equal_p(const prange &r) const
Definition value-range-storage.cc:784
trailing_wide_ints< PRANGE_STORAGE_NINTS > m_trailing_ints
Definition value-range-storage.h:165
friend void gt_ggc_mx_vrange_storage(void *)
prange_storage(const prange &r)
Definition value-range-storage.cc:608
DISABLE_COPY_AND_ASSIGN(prange_storage)
irange_bitmask get_bitmask(tree type) const
Definition value-range-storage.cc:900
enum prange_kind m_kind
Definition value-range-storage.h:125
tree m_addr
Definition value-range-storage.h:155
void set_word(unsigned i, const T &x, tree)
Definition value-range-storage.h:162
unsigned int m_has_bitmask
Definition value-range-storage.h:126
void get_prange(prange &r, tree type) const
Definition value-range-storage.cc:722
struct pt_solution * pt
Definition value-range-storage.h:148
friend void gt_pch_nx_vrange_storage(void *)
Definition value-range.h:405
class vrange_storage * clone(const vrange &r, bool shared_p=true)
Definition value-range-storage.cc:111
class vrange_internal_alloc * m_alloc
Definition value-range-storage.h:40
vrange_storage * clone_varying(tree type)
Definition value-range-storage.cc:117
void * alloc(size_t size)
Definition value-range-storage.cc:96
DISABLE_COPY_AND_ASSIGN(vrange_allocator)
vrange_allocator(bool gc=false)
Definition value-range-storage.cc:82
void free(void *)
Definition value-range-storage.cc:102
vrange_storage * clone_undefined(tree type)
Definition value-range-storage.cc:129
Definition value-range-storage.cc:37
Definition value-range-storage.h:46
static vrange_storage * alloc(vrange_internal_alloc &, const vrange &, bool shared_p=true)
Definition value-range-storage.cc:144
enum value_range_discriminator m_discriminator
Definition value-range-storage.h:63
class frange_storage * dyn_frange()
Definition value-range-storage.h:231
void get_vrange(vrange &r, tree type) const
Definition value-range-storage.cc:196
class irange_storage * dyn_irange()
Definition value-range-storage.h:215
bool equal_p(const vrange &r) const
Definition value-range-storage.cc:227
void set_vrange(const vrange &r)
Definition value-range-storage.cc:159
class prange_storage * dyn_prange()
Definition value-range-storage.h:223
vrange_storage(enum value_range_discriminator d)
Definition value-range-storage.h:62
bool fits_p(const vrange &r) const
Definition value-range-storage.cc:211
Definition value-range.h:88
#define GTY(x)
Definition coretypes.h:41
union tree_node * tree
Definition coretypes.h:97
void(*) gt_pointer_operator(void *, void *, void *)
Definition coretypes.h:477
poly_int< N, C > r
Definition poly-int.h:774
i
Definition poly-int.h:776
Definition value-range.h:592
Definition tree-ssa-alias.h:29
Definition wide-int.h:1758
Definition gengtype.h:252
#define NULL
Definition system.h:55
#define gcc_unreachable()
Definition system.h:785
vrange_storage * ggc_alloc_vrange_storage(tree type)
Definition value-range-storage.cc:938
const unsigned int PRANGE_STORAGE_NINTS
Definition value-range-storage.h:117
prange_kind
Definition value-range-storage.h:109
@ PR_NONZERO
Definition value-range-storage.h:112
@ PR_VARYING
Definition value-range-storage.h:110
@ PR_ZERO
Definition value-range-storage.h:111
@ PR_OTHER
Definition value-range-storage.h:114
@ PR_UNDEFINED
Definition value-range-storage.h:109
@ PR_FULL
Definition value-range-storage.h:113
value_range_kind
Definition value-range.h:29
value_range_discriminator
Definition value-range.h:47
@ VR_IRANGE
Definition value-range.h:49
@ VR_PRANGE
Definition value-range.h:51
@ VR_FRANGE
Definition value-range.h:53
generic_wide_int< wide_int_storage > wide_int
Definition wide-int.h:343