]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/range.cc
Rewrite value_range constructors to the value_range_kind is at the end, and defaults...
[thirdparty/gcc.git] / gcc / range.cc
1 /* Misc range functions.
2 Copyright (C) 2017-2019 Free Software Foundation, Inc.
3 Contributed by Aldy Hernandez <aldyh@redhat.com>.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
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/>. */
20
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 "gimple-pretty-print.h"
28 #include "fold-const.h"
29 #include "ssa.h"
30 #include "range.h"
31
32 value_range
33 range_intersect (const value_range &r1, const value_range &r2)
34 {
35 value_range tmp (r1);
36 tmp.intersect (r2);
37 return tmp;
38 }
39
40 value_range
41 range_invert (const value_range &r1)
42 {
43 value_range tmp (r1);
44 tmp.invert ();
45 return tmp;
46 }
47
48 value_range
49 range_union (const value_range &r1, const value_range &r2)
50 {
51 value_range tmp (r1);
52 tmp.union_ (r2);
53 return tmp;
54 }
55
56 value_range
57 range_zero (tree type)
58 {
59 return value_range (build_zero_cst (type), build_zero_cst (type));
60 }
61
62 value_range
63 range_nonzero (tree type)
64 {
65 return value_range (build_zero_cst (type), build_zero_cst (type),
66 VR_ANTI_RANGE);
67 }
68
69 value_range
70 range_positives (tree type)
71 {
72 unsigned prec = TYPE_PRECISION (type);
73 signop sign = TYPE_SIGN (type);
74 return value_range (type, wi::zero (prec), wi::max_value (prec, sign));
75 }
76
77 value_range
78 range_negatives (tree type)
79 {
80 unsigned prec = TYPE_PRECISION (type);
81 signop sign = TYPE_SIGN (type);
82 value_range r;
83 if (sign == UNSIGNED)
84 r.set_undefined ();
85 else
86 r = value_range (type, wi::min_value (prec, sign), wi::minus_one (prec));
87 return r;
88 }