1 /* Pretty print support for value ranges.
2 Copyright (C) 2019-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/>. */
23 #include "coretypes.h"
28 #include "tree-pretty-print.h"
29 #include "fold-const.h"
30 #include "gimple-range.h"
31 #include "value-range-pretty-print.h"
34 vrange_printer::visit (const unsupported_range
&r
) const
36 pp_string (pp
, "[unsupported_range] ");
39 pp_string (pp
, "UNDEFINED");
44 pp_string (pp
, "VARYING");
51 vrange_printer::visit (const irange
&r
) const
53 pp_string (pp
, "[irange] ");
56 pp_string (pp
, "UNDEFINED");
59 dump_generic_node (pp
, r
.type (), 0, TDF_NONE
| TDF_NOUID
, false);
60 pp_character (pp
, ' ');
63 pp_string (pp
, "VARYING");
66 for (unsigned i
= 0; i
< r
.num_pairs (); ++i
)
68 pp_character (pp
, '[');
69 print_irange_bound (r
.lower_bound (i
), r
.type ());
71 print_irange_bound (r
.upper_bound (i
), r
.type ());
72 pp_character (pp
, ']');
74 print_irange_bitmasks (r
);
78 vrange_printer::print_irange_bound (const wide_int
&bound
, tree type
) const
80 wide_int type_min
= wi::min_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
81 wide_int type_max
= wi::max_value (TYPE_PRECISION (type
), TYPE_SIGN (type
));
83 if (INTEGRAL_TYPE_P (type
)
84 && !TYPE_UNSIGNED (type
)
86 && TYPE_PRECISION (type
) != 1)
87 pp_string (pp
, "-INF");
88 else if (bound
== type_max
&& TYPE_PRECISION (type
) != 1)
89 pp_string (pp
, "+INF");
91 pp_wide_int (pp
, bound
, TYPE_SIGN (type
));
95 vrange_printer::print_irange_bitmasks (const irange
&r
) const
97 irange_bitmask bm
= r
.m_bitmask
;
101 pp_string (pp
, " MASK ");
102 char buf
[WIDE_INT_PRINT_BUFFER_SIZE
], *p
;
103 unsigned len_mask
, len_val
;
104 if (print_hex_buf_size (bm
.mask (), &len_mask
)
105 | print_hex_buf_size (bm
.value (), &len_val
))
106 p
= XALLOCAVEC (char, MAX (len_mask
, len_val
));
109 print_hex (bm
.mask (), p
);
111 pp_string (pp
, " VALUE ");
112 print_hex (bm
.value (), p
);
117 vrange_printer::print_real_value (tree type
, const REAL_VALUE_TYPE
&r
) const
120 real_to_decimal_for_mode (s
, &r
, sizeof (s
), 0, 1, TYPE_MODE (type
));
122 if (!DECIMAL_FLOAT_TYPE_P (type
)
123 // real_to_hexadecimal prints infinities and NAN as text. No
124 // need to print them twice.
128 real_to_hexadecimal (s
, &r
, sizeof (s
), 0, 1);
129 pp_printf (pp
, " (%s)", s
);
136 vrange_printer::visit (const frange
&r
) const
138 pp_string (pp
, "[frange] ");
139 if (r
.undefined_p ())
141 pp_string (pp
, "UNDEFINED");
144 tree type
= r
.type ();
145 dump_generic_node (pp
, type
, 0, TDF_NONE
, false);
149 pp_string (pp
, "VARYING");
150 print_frange_nan (r
);
153 pp_character (pp
, '[');
154 bool has_endpoints
= !r
.known_isnan ();
157 print_real_value (type
, r
.lower_bound ());
158 pp_string (pp
, ", ");
159 print_real_value (type
, r
.upper_bound ());
161 pp_character (pp
, ']');
162 print_frange_nan (r
);
165 // Print the NAN info for an frange.
168 vrange_printer::print_frange_nan (const frange
&r
) const
170 if (r
.maybe_isnan ())
172 if (r
.m_pos_nan
&& r
.m_neg_nan
)
174 pp_string (pp
, " +-NAN");
177 bool nan_sign
= r
.m_neg_nan
;
179 pp_string (pp
, " -NAN");
181 pp_string (pp
, " +NAN");