1/* Support routines for vrange storage.
2 Copyright (C) 2022-2023 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
27class vrange_allocator
28{
29public:
30 // Use GC memory when GC is true, otherwise use obstacks.
31 vrange_allocator (bool gc = false);
32 ~vrange_allocator ();
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);
37 void free (void *);
38private:
39 DISABLE_COPY_AND_ASSIGN (vrange_allocator);
40 class vrange_internal_alloc *m_alloc;
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(()) vrange_storage
50{
51public:
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;
57protected:
58 // Stack initialization disallowed.
59 vrange_storage () { }
60};
61
62// Efficient memory storage for an irange.
63
64class irange_storage : public vrange_storage
65{
66public:
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;
72 void dump () const;
73private:
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 ();
78 friend void gt_ggc_mx_irange_storage (void *);
79 friend void gt_pch_p_14irange_storage (void *, void *,
80 gt_pointer_operator, void *);
81 friend void gt_pch_nx_irange_storage (void *);
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
92 enum value_range_kind m_kind : 3;
93
94 // The length of this is m_num_ranges * 2 + 2 to accomodate 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// Efficient memory storage for an frange.
106
107class frange_storage : public vrange_storage
108{
109 public:
110 static frange_storage *alloc (vrange_internal_alloc &, const frange &r);
111 void set_frange (const frange &r);
112 void get_frange (frange &r, tree type) const;
113 bool equal_p (const frange &r) const;
114 bool fits_p (const frange &) const;
115 private:
116 frange_storage (const frange &r) { set_frange (r); }
117 DISABLE_COPY_AND_ASSIGN (frange_storage);
118
119 enum value_range_kind m_kind;
120 REAL_VALUE_TYPE m_min;
121 REAL_VALUE_TYPE m_max;
122 bool m_pos_nan;
123 bool m_neg_nan;
124};
125
126extern vrange_storage *ggc_alloc_vrange_storage (tree type);
127extern vrange_storage *ggc_alloc_vrange_storage (const vrange &);
128
129#endif // GCC_VALUE_RANGE_STORAGE_H
130

source code of gcc/value-range-storage.h