Require target lra in gcc.c-torture/compile/asmgoto-6.c
[official-gcc.git] / gcc / value-range-pretty-print.cc
blobc95b09d55b85b44c3544986a05c7ddcf50377b9e
1 /* Pretty print support for value ranges.
2 Copyright (C) 2019-2023 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)
10 any later version.
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 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "backend.h"
25 #include "tree.h"
26 #include "gimple.h"
27 #include "ssa.h"
28 #include "tree-pretty-print.h"
29 #include "fold-const.h"
30 #include "gimple-range.h"
31 #include "value-range-pretty-print.h"
33 void
34 vrange_printer::visit (const unsupported_range &r) const
36 pp_string (pp, "[unsupported_range] ");
37 if (r.undefined_p ())
39 pp_string (pp, "UNDEFINED");
40 return;
42 if (r.varying_p ())
44 pp_string (pp, "VARYING");
45 return;
47 gcc_unreachable ();
50 void
51 vrange_printer::visit (const irange &r) const
53 pp_string (pp, "[irange] ");
54 if (r.undefined_p ())
56 pp_string (pp, "UNDEFINED");
57 return;
59 dump_generic_node (pp, r.type (), 0, TDF_NONE | TDF_NOUID, false);
60 pp_character (pp, ' ');
61 if (r.varying_p ())
63 pp_string (pp, "VARYING");
64 return;
66 for (unsigned i = 0; i < r.num_pairs (); ++i)
68 pp_character (pp, '[');
69 print_irange_bound (r.lower_bound (i), r.type ());
70 pp_string (pp, ", ");
71 print_irange_bound (r.upper_bound (i), r.type ());
72 pp_character (pp, ']');
74 print_irange_bitmasks (r);
77 void
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)
85 && bound == type_min
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");
90 else
91 pp_wide_int (pp, bound, TYPE_SIGN (type));
94 void
95 vrange_printer::print_irange_bitmasks (const irange &r) const
97 irange_bitmask bm = r.m_bitmask;
98 if (bm.unknown_p ())
99 return;
101 pp_string (pp, " MASK ");
102 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
103 print_hex (bm.mask (), buf);
104 pp_string (pp, buf);
105 pp_string (pp, " VALUE ");
106 print_hex (bm.value (), buf);
107 pp_string (pp, buf);
110 void
111 vrange_printer::print_real_value (tree type, const REAL_VALUE_TYPE &r) const
113 char s[100];
114 real_to_decimal_for_mode (s, &r, sizeof (s), 0, 1, TYPE_MODE (type));
115 pp_string (pp, s);
116 if (!DECIMAL_FLOAT_TYPE_P (type)
117 // real_to_hexadecimal prints infinities and NAN as text. No
118 // need to print them twice.
119 && !real_isinf (&r)
120 && !real_isnan (&r))
122 real_to_hexadecimal (s, &r, sizeof (s), 0, 1);
123 pp_printf (pp, " (%s)", s);
127 // Print an frange.
129 void
130 vrange_printer::visit (const frange &r) const
132 pp_string (pp, "[frange] ");
133 if (r.undefined_p ())
135 pp_string (pp, "UNDEFINED");
136 return;
138 tree type = r.type ();
139 dump_generic_node (pp, type, 0, TDF_NONE, false);
140 pp_string (pp, " ");
141 if (r.varying_p ())
143 pp_string (pp, "VARYING");
144 print_frange_nan (r);
145 return;
147 pp_character (pp, '[');
148 bool has_endpoints = !r.known_isnan ();
149 if (has_endpoints)
151 print_real_value (type, r.lower_bound ());
152 pp_string (pp, ", ");
153 print_real_value (type, r.upper_bound ());
155 pp_character (pp, ']');
156 print_frange_nan (r);
159 // Print the NAN info for an frange.
161 void
162 vrange_printer::print_frange_nan (const frange &r) const
164 if (r.maybe_isnan ())
166 if (r.m_pos_nan && r.m_neg_nan)
168 pp_string (pp, " +-NAN");
169 return;
171 bool nan_sign = r.m_neg_nan;
172 if (nan_sign)
173 pp_string (pp, " -NAN");
174 else
175 pp_string (pp, " +NAN");