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//
45// The GTY marker here does nothing but get gengtype to generate the
46// ggc_test_and_set_mark calls. We ignore the derived classes, since
47// they don't contain any pointers.
48
49class GTY((desc ("%h.m_discriminator"), tag("VR_UNKNOWN"))) vrange_storage
50{
51public:
53 bool shared_p = true);
54 void get_vrange (vrange &r, tree type) const;
55 void set_vrange (const vrange &r);
56 bool fits_p (const vrange &r) const;
57 bool equal_p (const vrange &r) const;
58
59 // Stack initialization disallowed.
62};
63
64// Efficient memory storage for an irange.
65
66class GTY((tag ("VR_IRANGE"))) irange_storage: public vrange_storage
67{
68public:
70 void set_irange (const irange &r);
71 void get_irange (irange &r, tree type) const;
72 bool equal_p (const irange &r) const;
73 bool fits_p (const irange &r) const;
74 void dump () const;
75private:
77 static size_t size (const irange &r);
78 const unsigned short *lengths_address () const;
79 unsigned short *write_lengths_address ();
80
81 // The shared precision of each number.
82 unsigned short m_precision;
83
84 // The max number of sub-ranges that fit in this storage.
85 const unsigned char m_max_ranges;
86
87 // The number of stored sub-ranges.
88 unsigned char m_num_ranges;
89
91
92 // The length of this is m_num_ranges * 2 + 2 to accommodate the bitmask.
93 HOST_WIDE_INT m_val[1];
94
95 // Another variable-length part of the structure following the HWIs.
96 // This is the length of each wide_int in m_val.
97 //
98 // unsigned short m_len[];
99
100 irange_storage (const irange &r);
101};
102
103
104// A prange_kind summarizes some common variations for a prange, and is used
105// in a prange_storage clas for efficiency.
106
107enum prange_kind { PR_UNDEFINED, // VR_UNDEFINED
108 PR_VARYING, // VR_VARYING
109 PR_ZERO, // [0, 0]
110 PR_NONZERO, // [1, +INF] (May have bitmask)
111 PR_FULL, // [0, +INF] (Must have bitmask)
112 PR_OTHER }; // [x, y] (MAy have bitmask)
113
114// Maximum number of words that may be allocated by a prange_storage class.
115const unsigned int PRANGE_STORAGE_NINTS = 4;
116
117// Efficient memory storage for a prange.
118class GTY((tag ("VR_PRANGE"))) prange_storage : public vrange_storage
119{
120public:
121 friend void gt_ggc_mx_vrange_storage(void *);
122 friend void gt_pch_nx_vrange_storage(void *);
124 void *);
126 bool shared_p = true);
127 void set_prange (const prange &r);
128 void get_prange (prange &r, tree type) const;
129 bool equal_p (const prange &r) const;
130 bool fits_p (const prange &r) const;
131 void dump () const;
132
133private:
135 prange_storage (const prange &r);
136 static enum prange_kind prange_format (const prange &r, unsigned &num_words);
137
142
143 // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
144 // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
145 // const and return wide_int instead of trailing_wide_int.
146 wide_int get_word (unsigned i, tree) const
147 { return m_trailing_ints[i]; }
148 template <typename T> void set_word (unsigned i, const T &x, tree)
149 { m_trailing_ints[i] = x; }
150
152};
153
154// Efficient memory storage for an frange.
155
156class GTY((tag ("VR_FRANGE"))) frange_storage : public vrange_storage
157{
158 public:
160 void set_frange (const frange &r);
161 void get_frange (frange &r, tree type) const;
162 bool equal_p (const frange &r) const;
163 bool fits_p (const frange &) const;
164 private:
168
174};
175
178 bool shared_p = true);
179
180#endif // GCC_VALUE_RANGE_STORAGE_H
void get_frange(frange &r, tree type) const
Definition value-range-storage.cc:534
bool fits_p(const frange &) const
Definition value-range-storage.cc:586
static frange_storage * alloc(vrange_internal_alloc &, const frange &r)
Definition value-range-storage.cc:513
bool m_neg_nan
Definition value-range-storage.h:173
REAL_VALUE_TYPE m_min
Definition value-range-storage.h:170
bool m_pos_nan
Definition value-range-storage.h:172
DISABLE_COPY_AND_ASSIGN(frange_storage)
bool equal_p(const frange &r) const
Definition value-range-storage.cc:575
enum value_range_kind m_kind
Definition value-range-storage.h:169
REAL_VALUE_TYPE m_max
Definition value-range-storage.h:171
frange_storage(const frange &r)
Definition value-range-storage.h:165
void set_frange(const frange &r)
Definition value-range-storage.cc:522
Definition value-range.h:593
static size_t size(const irange &r)
Definition value-range-storage.cc:440
irange_storage(const irange &r)
Definition value-range-storage.cc:300
static irange_storage * alloc(vrange_internal_alloc &, const irange &)
Definition value-range-storage.cc:290
bool equal_p(const irange &r) const
Definition value-range-storage.cc:423
unsigned short m_precision
Definition value-range-storage.h:82
HOST_WIDE_INT m_val[1]
Definition value-range-storage.h:93
const unsigned char m_max_ranges
Definition value-range-storage.h:85
void set_irange(const irange &r)
Definition value-range-storage.cc:319
unsigned short * write_lengths_address()
Definition value-range-storage.cc:275
const unsigned short * lengths_address() const
Definition value-range-storage.cc:282
bool fits_p(const irange &r) const
Definition value-range-storage.cc:456
enum value_range_kind m_kind
Definition value-range-storage.h:90
DISABLE_COPY_AND_ASSIGN(irange_storage)
void dump() const
Definition value-range-storage.cc:462
unsigned char m_num_ranges
Definition value-range-storage.h:88
void get_irange(irange &r, tree type) const
Definition value-range-storage.cc:365
Definition value-range.h:289
static prange_storage * alloc(vrange_internal_alloc &, const prange &, bool shared_p=true)
Definition value-range-storage.cc:596
tree m_pt
Definition value-range-storage.h:141
void dump() const
wide_int get_word(unsigned i, tree) const
Definition value-range-storage.h:146
static enum prange_kind prange_format(const prange &r, unsigned &num_words)
Definition value-range-storage.cc:633
friend void gt_pch_p_14vrange_storage(void *, void *, gt_pointer_operator, void *)
void set_prange(const prange &r)
Definition value-range-storage.cc:672
bool fits_p(const prange &r) const
Definition value-range-storage.cc:827
bool equal_p(const prange &r) const
Definition value-range-storage.cc:771
trailing_wide_ints< PRANGE_STORAGE_NINTS > m_trailing_ints
Definition value-range-storage.h:151
friend void gt_ggc_mx_vrange_storage(void *)
prange_storage(const prange &r)
Definition value-range-storage.cc:620
bool m_points_to_p
Definition value-range-storage.h:140
DISABLE_COPY_AND_ASSIGN(prange_storage)
enum prange_kind m_kind
Definition value-range-storage.h:138
void set_word(unsigned i, const T &x, tree)
Definition value-range-storage.h:148
void get_prange(prange &r, tree type) const
Definition value-range-storage.cc:709
bool m_has_bitmask
Definition value-range-storage.h:139
friend void gt_pch_nx_vrange_storage(void *)
Definition value-range.h:403
class vrange_storage * clone(const vrange &r, bool shared_p=true)
Definition value-range-storage.cc:112
class vrange_internal_alloc * m_alloc
Definition value-range-storage.h:40
vrange_storage * clone_varying(tree type)
Definition value-range-storage.cc:118
void * alloc(size_t size)
Definition value-range-storage.cc:97
~vrange_allocator()
Definition value-range-storage.cc:91
DISABLE_COPY_AND_ASSIGN(vrange_allocator)
vrange_allocator(bool gc=false)
Definition value-range-storage.cc:83
void free(void *)
Definition value-range-storage.cc:103
vrange_storage * clone_undefined(tree type)
Definition value-range-storage.cc:130
Definition value-range-storage.cc:38
Definition value-range-storage.h:50
static vrange_storage * alloc(vrange_internal_alloc &, const vrange &, bool shared_p=true)
Definition value-range-storage.cc:145
enum value_range_discriminator m_discriminator
Definition value-range-storage.h:61
void get_vrange(vrange &r, tree type) const
Definition value-range-storage.cc:200
bool equal_p(const vrange &r) const
Definition value-range-storage.cc:250
void set_vrange(const vrange &r)
Definition value-range-storage.cc:160
vrange_storage(enum value_range_discriminator d)
Definition value-range-storage.h:60
bool fits_p(const vrange &r) const
Definition value-range-storage.cc:224
Definition value-range.h:88
#define GTY(x)
Definition coretypes.h:41
void(* gt_pointer_operator)(void *, void *, void *)
Definition coretypes.h:466
union tree_node * tree
Definition coretypes.h:97
static struct token T
Definition gengtype-parse.cc:45
poly_int< N, C > r
Definition poly-int.h:774
i
Definition poly-int.h:776
#define REAL_VALUE_TYPE
Definition real.h:68
Definition wide-int.h:1758
Definition gengtype.h:252
vrange_storage * ggc_alloc_vrange_storage(tree type)
Definition value-range-storage.cc:842
const unsigned int PRANGE_STORAGE_NINTS
Definition value-range-storage.h:115
prange_kind
Definition value-range-storage.h:107
@ PR_NONZERO
Definition value-range-storage.h:110
@ PR_VARYING
Definition value-range-storage.h:108
@ PR_ZERO
Definition value-range-storage.h:109
@ PR_OTHER
Definition value-range-storage.h:112
@ PR_UNDEFINED
Definition value-range-storage.h:107
@ PR_FULL
Definition value-range-storage.h:111
value_range_kind
Definition value-range.h:29
value_range_discriminator
Definition value-range.h:47
@ VR_FRANGE
Definition value-range.h:53
generic_wide_int< wide_int_storage > wide_int
Definition wide-int.h:343