c++: top level bind when rewriting coroutines [PR106188]
[official-gcc.git] / gcc / value-range-pretty-print.cc
blob93e18d3c1b6339828db14b58fd3ec5a6e5b538a8
1 /* Pretty print support for value ranges.
2 Copyright (C) 2019-2022 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, false);
60 pp_character (pp, ' ');
61 if (r.varying_p ())
63 pp_string (pp, "VARYING");
64 return;
66 // Handle legacy symbolics.
67 if (!r.constant_p ())
69 if (r.kind () == VR_ANTI_RANGE)
70 pp_character (pp, '~');
71 pp_character (pp, '[');
72 dump_generic_node (pp, r.min (), 0, TDF_NONE, false);
73 pp_string (pp, ", ");
74 dump_generic_node (pp, r.max (), 0, TDF_NONE, false);
75 pp_character (pp, ']');
76 print_irange_bitmasks (r);
77 return;
79 for (unsigned i = 0; i < r.num_pairs (); ++i)
81 pp_character (pp, '[');
82 print_irange_bound (r.lower_bound (i), r.type ());
83 pp_string (pp, ", ");
84 print_irange_bound (r.upper_bound (i), r.type ());
85 pp_character (pp, ']');
87 print_irange_bitmasks (r);
90 void
91 vrange_printer::print_irange_bound (const wide_int &bound, tree type) const
93 wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
94 wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
96 if (INTEGRAL_TYPE_P (type)
97 && !TYPE_UNSIGNED (type)
98 && bound == type_min
99 && TYPE_PRECISION (type) != 1)
100 pp_string (pp, "-INF");
101 else if (bound == type_max && TYPE_PRECISION (type) != 1)
102 pp_string (pp, "+INF");
103 else
104 pp_wide_int (pp, bound, TYPE_SIGN (type));
107 void
108 vrange_printer::print_irange_bitmasks (const irange &r) const
110 wide_int nz = r.get_nonzero_bits ();
111 if (nz == -1)
112 return;
114 pp_string (pp, " NONZERO ");
115 char buf[WIDE_INT_PRINT_BUFFER_SIZE];
116 print_hex (nz, buf);
117 pp_string (pp, buf);
120 // Print an frange.
122 void
123 vrange_printer::visit (const frange &r) const
125 tree type = r.type ();
127 pp_string (pp, "[frange] ");
128 if (r.undefined_p ())
130 pp_string (pp, "UNDEFINED");
131 return;
133 dump_generic_node (pp, type, 0, TDF_NONE, false);
134 pp_string (pp, " ");
135 if (r.varying_p ())
137 pp_string (pp, "VARYING");
138 return;
140 pp_character (pp, '[');
141 dump_generic_node (pp,
142 build_real (type, r.lower_bound ()), 0, TDF_NONE, false);
143 pp_string (pp, ", ");
144 dump_generic_node (pp,
145 build_real (type, r.upper_bound ()), 0, TDF_NONE, false);
146 pp_string (pp, "] ");
148 print_frange_prop ("NAN", r.get_nan ());
149 print_frange_prop ("SIGN", r.get_signbit ());
152 // Print the FP properties in an frange.
154 void
155 vrange_printer::print_frange_prop (const char *str, const fp_prop &prop) const
157 if (prop.varying_p ())
158 return;
160 if (prop.yes_p ())
161 pp_string (pp, str);
162 else if (prop.no_p ())
164 pp_character (pp, '!');
165 pp_string (pp, str);
167 pp_character (pp, ' ');