]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/value-range-storage.h
1 /* Support routines for vrange storage.
2 Copyright (C) 2022-2024 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_VALUE_RANGE_STORAGE_H
22 #define GCC_VALUE_RANGE_STORAGE_H
24 // This class is used to allocate chunks of memory that can store
25 // ranges as memory efficiently as possible.
27 class vrange_allocator
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
);
34 vrange_storage
*clone_varying (tree type
);
35 vrange_storage
*clone_undefined (tree type
);
36 void *alloc (size_t size
);
39 DISABLE_COPY_AND_ASSIGN (vrange_allocator
);
40 class vrange_internal_alloc
*m_alloc
;
43 // Efficient memory storage for a vrange.
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.
49 class GTY(()) vrange_storage
52 static vrange_storage
*alloc (vrange_internal_alloc
&, const vrange
&);
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;
58 // Stack initialization disallowed.
62 // Efficient memory storage for an irange.
64 class irange_storage
: public vrange_storage
67 static irange_storage
*alloc (vrange_internal_alloc
&, const irange
&);
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;
74 DISABLE_COPY_AND_ASSIGN (irange_storage
);
75 static size_t size (const irange
&r
);
76 const unsigned short *lengths_address () const;
77 unsigned short *write_lengths_address ();
79 // The shared precision of each number.
80 unsigned short m_precision
;
82 // The max number of sub-ranges that fit in this storage.
83 const unsigned char m_max_ranges
;
85 // The number of stored sub-ranges.
86 unsigned char m_num_ranges
;
88 enum value_range_kind m_kind
: 3;
90 // The length of this is m_num_ranges * 2 + 2 to accomodate the bitmask.
91 HOST_WIDE_INT m_val
[1];
93 // Another variable-length part of the structure following the HWIs.
94 // This is the length of each wide_int in m_val.
96 // unsigned short m_len[];
98 irange_storage (const irange
&r
);
101 // Efficient memory storage for a prange.
103 class prange_storage
: public vrange_storage
106 static prange_storage
*alloc (vrange_internal_alloc
&, const prange
&);
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;
113 DISABLE_COPY_AND_ASSIGN (prange_storage
);
114 prange_storage (const prange
&r
);
116 enum value_range_kind m_kind
: 3;
118 // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
119 // must be const. Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
120 // const and return wide_int instead of trailing_wide_int.
121 wide_int
get_low () const { return m_trailing_ints
[0]; }
122 wide_int
get_high () const { return m_trailing_ints
[1]; }
123 wide_int
get_value () const { return m_trailing_ints
[2]; }
124 wide_int
get_mask () const { return m_trailing_ints
[3]; }
125 template <typename T
> void set_low (const T
&x
) { m_trailing_ints
[0] = x
; }
126 template <typename T
> void set_high (const T
&x
) { m_trailing_ints
[1] = x
; }
127 template <typename T
> void set_value (const T
&x
) { m_trailing_ints
[2] = x
; }
128 template <typename T
> void set_mask (const T
&x
) { m_trailing_ints
[3] = x
; }
130 static const unsigned int NINTS
= 4;
131 trailing_wide_ints
<NINTS
> m_trailing_ints
;
134 // Efficient memory storage for an frange.
136 class frange_storage
: public vrange_storage
139 static frange_storage
*alloc (vrange_internal_alloc
&, const frange
&r
);
140 void set_frange (const frange
&r
);
141 void get_frange (frange
&r
, tree type
) const;
142 bool equal_p (const frange
&r
) const;
143 bool fits_p (const frange
&) const;
145 frange_storage (const frange
&r
) { set_frange (r
); }
146 DISABLE_COPY_AND_ASSIGN (frange_storage
);
148 enum value_range_kind m_kind
;
149 REAL_VALUE_TYPE m_min
;
150 REAL_VALUE_TYPE m_max
;
155 extern vrange_storage
*ggc_alloc_vrange_storage (tree type
);
156 extern vrange_storage
*ggc_alloc_vrange_storage (const vrange
&);
158 #endif // GCC_VALUE_RANGE_STORAGE_H