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);
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
50{
51public:
53 void get_vrange (vrange &r, tree type) const;
54 void set_vrange (const vrange &r);
55 bool fits_p (const vrange &r) const;
56 bool equal_p (const vrange &r) const;
57protected:
58 // Stack initialization disallowed.
60};
61
62// Efficient memory storage for an irange.
63
65{
66public:
68 void set_irange (const irange &r);
69 void get_irange (irange &r, tree type) const;
70 bool equal_p (const irange &r) const;
71 bool fits_p (const irange &r) const;
72 void dump () const;
73private:
75 static size_t size (const irange &r);
76 const unsigned short *lengths_address () const;
77 unsigned short *write_lengths_address ();
78
79 // The shared precision of each number.
80 unsigned short m_precision;
81
82 // The max number of sub-ranges that fit in this storage.
83 const unsigned char m_max_ranges;
84
85 // The number of stored sub-ranges.
86 unsigned char m_num_ranges;
87
89
90 // The length of this is m_num_ranges * 2 + 2 to accommodate the bitmask.
91 HOST_WIDE_INT m_val[1];
92
93 // Another variable-length part of the structure following the HWIs.
94 // This is the length of each wide_int in m_val.
95 //
96 // unsigned short m_len[];
97
98 irange_storage (const irange &r);
99};
100
101// Efficient memory storage for a prange.
102
104{
105public:
107 void set_prange (const prange &r);
108 void get_prange (prange &r, tree type) const;
109 bool equal_p (const prange &r) const;
110 bool fits_p (const prange &r) const;
111 void dump () const;
112private:
114 prange_storage (const prange &r);
115
116 // A prange_format class summarizes the storage requirements for a prange
117 // which are then used to initialize the prange_storage fields.
118 enum prange_kind { PR_UNDEFINED, // VR_UNDEFINED
119 PR_VARYING, // VR_VARYING
120 PR_ZERO, // [0, 0]
121 PR_NONZERO, // [1, +INF]
122 PR_FULL, // [0, +INF] (Must have bitmask)
123 PR_OTHER }; // [x, y]
125 {
126 public:
127 prange_format (const prange &r);
131 unsigned short precision;
132 unsigned num_words;
133 };
134
137
138 // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
139 // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
140 // const and return wide_int instead of trailing_wide_int.
141 wide_int get_word (unsigned i, tree) const
142 { return m_trailing_ints[i]; }
143 template <typename T> void set_word (unsigned i, const T &x, tree)
144 { m_trailing_ints[i] = x; }
145
146 static const unsigned int NINTS = 4;
148};
149
150// Efficient memory storage for an frange.
151
153{
154 public:
156 void set_frange (const frange &r);
157 void get_frange (frange &r, tree type) const;
158 bool equal_p (const frange &r) const;
159 bool fits_p (const frange &) const;
160 private:
163
169};
170
173
174#endif // GCC_VALUE_RANGE_STORAGE_H
void get_frange(frange &r, tree type) const
Definition value-range-storage.cc:532
bool fits_p(const frange &) const
Definition value-range-storage.cc:584
static frange_storage * alloc(vrange_internal_alloc &, const frange &r)
Definition value-range-storage.cc:511
bool m_neg_nan
Definition value-range-storage.h:168
REAL_VALUE_TYPE m_min
Definition value-range-storage.h:165
bool m_pos_nan
Definition value-range-storage.h:167
DISABLE_COPY_AND_ASSIGN(frange_storage)
bool equal_p(const frange &r) const
Definition value-range-storage.cc:573
enum value_range_kind m_kind
Definition value-range-storage.h:164
REAL_VALUE_TYPE m_max
Definition value-range-storage.h:166
frange_storage(const frange &r)
Definition value-range-storage.h:161
void set_frange(const frange &r)
Definition value-range-storage.cc:520
Definition value-range.h:548
static size_t size(const irange &r)
Definition value-range-storage.cc:438
irange_storage(const irange &r)
Definition value-range-storage.cc:298
static irange_storage * alloc(vrange_internal_alloc &, const irange &)
Definition value-range-storage.cc:288
bool equal_p(const irange &r) const
Definition value-range-storage.cc:421
unsigned short m_precision
Definition value-range-storage.h:80
HOST_WIDE_INT m_val[1]
Definition value-range-storage.h:91
const unsigned char m_max_ranges
Definition value-range-storage.h:83
void set_irange(const irange &r)
Definition value-range-storage.cc:317
unsigned short * write_lengths_address()
Definition value-range-storage.cc:273
const unsigned short * lengths_address() const
Definition value-range-storage.cc:280
bool fits_p(const irange &r) const
Definition value-range-storage.cc:454
enum value_range_kind m_kind
Definition value-range-storage.h:88
DISABLE_COPY_AND_ASSIGN(irange_storage)
void dump() const
Definition value-range-storage.cc:460
unsigned char m_num_ranges
Definition value-range-storage.h:86
void get_irange(irange &r, tree type) const
Definition value-range-storage.cc:363
Definition value-range.h:289
enum prange_kind kind
Definition value-range-storage.h:128
unsigned short precision
Definition value-range-storage.h:131
unsigned num_words
Definition value-range-storage.h:132
size_t extra_size
Definition value-range-storage.h:130
bool has_bitmask
Definition value-range-storage.h:129
prange_format(const prange &r)
Definition value-range-storage.cc:614
prange_kind
Definition value-range-storage.h:118
@ PR_FULL
Definition value-range-storage.h:122
@ PR_OTHER
Definition value-range-storage.h:123
@ PR_VARYING
Definition value-range-storage.h:119
@ PR_UNDEFINED
Definition value-range-storage.h:118
@ PR_NONZERO
Definition value-range-storage.h:121
@ PR_ZERO
Definition value-range-storage.h:120
trailing_wide_ints< NINTS > m_trailing_ints
Definition value-range-storage.h:147
void dump() const
static prange_storage * alloc(vrange_internal_alloc &, const prange &)
Definition value-range-storage.cc:594
wide_int get_word(unsigned i, tree) const
Definition value-range-storage.h:141
void set_prange(const prange &r)
Definition value-range-storage.cc:667
bool fits_p(const prange &r) const
Definition value-range-storage.cc:771
bool equal_p(const prange &r) const
Definition value-range-storage.cc:760
prange_storage(const prange &r)
Definition value-range-storage.cc:605
static const unsigned int NINTS
Definition value-range-storage.h:146
DISABLE_COPY_AND_ASSIGN(prange_storage)
enum prange_kind m_kind
Definition value-range-storage.h:135
void set_word(unsigned i, const T &x, tree)
Definition value-range-storage.h:143
void get_prange(prange &r, tree type) const
Definition value-range-storage.cc:701
bool m_has_bitmask
Definition value-range-storage.h:136
Definition value-range.h:403
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
class vrange_storage * clone(const vrange &r)
Definition value-range-storage.cc:111
~vrange_allocator()
Definition value-range-storage.cc:90
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:50
vrange_storage()
Definition value-range-storage.h:59
static vrange_storage * alloc(vrange_internal_alloc &, const vrange &)
Definition value-range-storage.cc:144
void get_vrange(vrange &r, tree type) const
Definition value-range-storage.cc:198
bool equal_p(const vrange &r) const
Definition value-range-storage.cc:248
void set_vrange(const vrange &r)
Definition value-range-storage.cc:158
bool fits_p(const vrange &r) const
Definition value-range-storage.cc:222
Definition value-range.h:88
#define GTY(x)
Definition coretypes.h:41
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:788
value_range_kind
Definition value-range.h:29
generic_wide_int< wide_int_storage > wide_int
Definition wide-int.h:343