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 // Stack initialization disallowed.
58};
59
60// Efficient memory storage for an irange.
61
62class GTY((tag ("VR_IRANGE"))) irange_storage: public vrange_storage
63{
64public:
66 void set_irange (const irange &r);
67 void get_irange (irange &r, tree type) const;
68 bool equal_p (const irange &r) const;
69 bool fits_p (const irange &r) const;
70 void dump () const;
71private:
73 static size_t size (const irange &r);
74 const unsigned short *lengths_address () const;
75 unsigned short *write_lengths_address ();
76
77 // The shared precision of each number.
78 unsigned short m_precision;
79
80 // The max number of sub-ranges that fit in this storage.
81 const unsigned char m_max_ranges;
82
83 // The number of stored sub-ranges.
84 unsigned char m_num_ranges;
85
87
88 // The length of this is m_num_ranges * 2 + 2 to accommodate the bitmask.
89 HOST_WIDE_INT m_val[1];
90
91 // Another variable-length part of the structure following the HWIs.
92 // This is the length of each wide_int in m_val.
93 //
94 // unsigned short m_len[];
95
96 irange_storage (const irange &r);
97};
98
99
100// A prange_kind summarizes some common variations for a prange, and is used
101// in a prange_storage clas for efficiency.
102
103enum prange_kind { PR_UNDEFINED, // VR_UNDEFINED
104 PR_VARYING, // VR_VARYING
105 PR_ZERO, // [0, 0]
106 PR_NONZERO, // [1, +INF] (May have bitmask)
107 PR_FULL, // [0, +INF] (Must have bitmask)
108 PR_OTHER }; // [x, y] (MAy have bitmask)
109
110// Maximum number of words that may be allocated by a prange_storage class.
111const unsigned int PRANGE_STORAGE_NINTS = 4;
112
113// Efficient memory storage for a prange.
114class GTY((tag ("VR_PRANGE"))) prange_storage : public vrange_storage
115{
116private:
117 // vrange_storage ends after four bytes but the first pointer member below
118 // needs eight-byte alignment, so there is a four-byte hole.
120 unsigned int m_has_bitmask : 1;
121 unsigned int m_points_to_p : 1;
122
123public:
124 friend void gt_ggc_mx_vrange_storage(void *);
125 friend void gt_pch_nx_vrange_storage(void *);
127 void *);
129 bool shared_p = true);
130 void set_prange (const prange &r);
131 void get_prange (prange &r, tree type) const;
132 bool equal_p (const prange &r) const;
133 bool fits_p (const prange &r) const;
134 void dump () const;
135
136 // The points-to solution for the SSA name is flow insensitive and is
137 // reached only through ssa_name_pt_solution.
139
140 // Alignment and misalignment of the pointer in bytes. Together
141 // align and misalign specify low known bits of the pointer.
142 // ptr & (align - 1) == misalign.
143 unsigned int align;
144 unsigned int misalign;
145
146private:
148 prange_storage (const prange &r);
149 static enum prange_kind prange_format (const prange &r, unsigned &num_words);
150
152
153 // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
154 // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
155 // const and return wide_int instead of trailing_wide_int.
156 wide_int get_word (unsigned i, tree) const
157 { return m_trailing_ints[i]; }
158 template <typename T> void set_word (unsigned i, const T &x, tree)
159 { m_trailing_ints[i] = x; }
160
162};
163
164// Efficient memory storage for an frange.
165
166class GTY((tag ("VR_FRANGE"))) frange_storage : public vrange_storage
167{
168 public:
170 void set_frange (const frange &r);
171 void get_frange (frange &r, tree type) const;
172 bool equal_p (const frange &r) const;
173 bool fits_p (const frange &) const;
174 private:
175 frange_storage (const frange &r);
177 static size_t size (const frange &r);
178
180 // The max number of sub-ranges that fit in this storage.
181 const unsigned char m_max_ranges;
182 unsigned char m_num_ranges;
186};
187
190 bool shared_p = true);
191
192#endif // GCC_VALUE_RANGE_STORAGE_H
static size_t size(const frange &r)
Definition value-range-storage.cc:512
void get_frange(frange &r, tree type) const
Definition value-range-storage.cc:548
bool fits_p(const frange &) const
Definition value-range-storage.cc:605
static frange_storage * alloc(vrange_internal_alloc &, const frange &r)
Definition value-range-storage.cc:520
bool m_neg_nan
Definition value-range-storage.h:184
bool m_pos_nan
Definition value-range-storage.h:183
DISABLE_COPY_AND_ASSIGN(frange_storage)
unsigned char m_num_ranges
Definition value-range-storage.h:182
const unsigned char m_max_ranges
Definition value-range-storage.h:181
bool equal_p(const frange &r) const
Definition value-range-storage.cc:594
enum value_range_kind m_kind
Definition value-range-storage.h:179
frange_pair m_pairs[1]
Definition value-range-storage.h:185
frange_storage(const frange &r)
Definition value-range-storage.cc:528
void set_frange(const frange &r)
Definition value-range-storage.cc:535
Definition value-range.h:603
static size_t size(const irange &r)
Definition value-range-storage.cc:439
irange_storage(const irange &r)
Definition value-range-storage.cc:299
static irange_storage * alloc(vrange_internal_alloc &, const irange &)
Definition value-range-storage.cc:289
bool equal_p(const irange &r) const
Definition value-range-storage.cc:422
unsigned short m_precision
Definition value-range-storage.h:78
HOST_WIDE_INT m_val[1]
Definition value-range-storage.h:89
const unsigned char m_max_ranges
Definition value-range-storage.h:81
void set_irange(const irange &r)
Definition value-range-storage.cc:318
unsigned short * write_lengths_address()
Definition value-range-storage.cc:274
const unsigned short * lengths_address() const
Definition value-range-storage.cc:281
bool fits_p(const irange &r) const
Definition value-range-storage.cc:455
enum value_range_kind m_kind
Definition value-range-storage.h:86
DISABLE_COPY_AND_ASSIGN(irange_storage)
void dump() const
Definition value-range-storage.cc:461
unsigned char m_num_ranges
Definition value-range-storage.h:84
void get_irange(irange &r, tree type) const
Definition value-range-storage.cc:364
Definition value-range.h:291
static prange_storage * alloc(vrange_internal_alloc &, const prange &, bool shared_p=true)
Definition value-range-storage.cc:615
tree m_pt
Definition value-range-storage.h:151
void dump() const
unsigned int m_points_to_p
Definition value-range-storage.h:121
wide_int get_word(unsigned i, tree) const
Definition value-range-storage.h:156
static enum prange_kind prange_format(const prange &r, unsigned &num_words)
Definition value-range-storage.cc:676
friend void gt_pch_p_14vrange_storage(void *, void *, gt_pointer_operator, void *)
void set_prange(const prange &r)
Definition value-range-storage.cc:715
bool fits_p(const prange &r) const
Definition value-range-storage.cc:874
bool equal_p(const prange &r) const
Definition value-range-storage.cc:817
trailing_wide_ints< PRANGE_STORAGE_NINTS > m_trailing_ints
Definition value-range-storage.h:161
friend void gt_ggc_mx_vrange_storage(void *)
prange_storage(const prange &r)
Definition value-range-storage.cc:639
DISABLE_COPY_AND_ASSIGN(prange_storage)
unsigned int align
Definition value-range-storage.h:143
enum prange_kind m_kind
Definition value-range-storage.h:119
void set_word(unsigned i, const T &x, tree)
Definition value-range-storage.h:158
unsigned int m_has_bitmask
Definition value-range-storage.h:120
void get_prange(prange &r, tree type) const
Definition value-range-storage.cc:755
struct pt_solution * pt
Definition value-range-storage.h:138
friend void gt_pch_nx_vrange_storage(void *)
unsigned int misalign
Definition value-range-storage.h:144
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:57
void get_vrange(vrange &r, tree type) const
Definition value-range-storage.cc:199
bool equal_p(const vrange &r) const
Definition value-range-storage.cc:249
void set_vrange(const vrange &r)
Definition value-range-storage.cc:159
vrange_storage(enum value_range_discriminator d)
Definition value-range-storage.h:56
bool fits_p(const vrange &r) const
Definition value-range-storage.cc:223
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
vrange_storage * ggc_alloc_vrange_storage(tree type)
Definition value-range-storage.cc:889
const unsigned int PRANGE_STORAGE_NINTS
Definition value-range-storage.h:111
prange_kind
Definition value-range-storage.h:103
@ PR_NONZERO
Definition value-range-storage.h:106
@ PR_VARYING
Definition value-range-storage.h:104
@ PR_ZERO
Definition value-range-storage.h:105
@ PR_OTHER
Definition value-range-storage.h:108
@ PR_UNDEFINED
Definition value-range-storage.h:103
@ PR_FULL
Definition value-range-storage.h:107
value_range_kind
Definition value-range.h:29
value_range_discriminator
Definition value-range.h:47
generic_wide_int< wide_int_storage > wide_int
Definition wide-int.h:343