1 /* Header file for the GIMPLE range interface.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4 and Aldy Hernandez <aldyh@redhat.com>.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
22 #ifndef GCC_GIMPLE_RANGE_STMT_H
23 #define GCC_GIMPLE_RANGE_STMT_H
28 #include "gimple-range-edge.h"
29 #include "gimple-range-gori.h"
30 #include "gimple-range-cache.h"
31 #include "value-query.h"
33 // This is the basic range generator interface.
35 // This base class provides all the API entry points, but only provides
36 // functionality at the statement level. Ie, it can calculate ranges on
37 // statements, but does no additonal lookup.
39 // All the range_of_* methods will return a range if the types is
40 // supported by the range engine. It may be the full range for the
41 // type, AKA varying_p or it may be a refined range. If the range
42 // type is not supported, then false is returned. Non-statement
43 // related methods return whatever the current global value is.
46 class gimple_ranger
: public range_query
49 gimple_ranger () : m_cache (*this) { }
50 virtual bool range_of_stmt (irange
&r
, gimple
*, tree name
= NULL
) OVERRIDE
;
51 virtual bool range_of_expr (irange
&r
, tree name
, gimple
* = NULL
) OVERRIDE
;
52 virtual bool range_on_edge (irange
&r
, edge e
, tree name
) OVERRIDE
;
53 virtual void range_on_entry (irange
&r
, basic_block bb
, tree name
);
54 virtual void range_on_exit (irange
&r
, basic_block bb
, tree name
);
55 void export_global_ranges ();
58 bool calc_stmt (irange
&r
, gimple
*s
, tree name
= NULL_TREE
);
59 bool range_of_range_op (irange
&r
, gimple
*s
);
60 bool range_of_call (irange
&r
, gcall
*call
);
61 bool range_of_cond_expr (irange
&r
, gassign
* cond
);
64 bool range_of_phi (irange
&r
, gphi
*phi
);
65 bool range_of_non_trivial_assignment (irange
&r
, gimple
*s
);
66 bool range_of_builtin_call (irange
&r
, gcall
*call
);
67 void range_of_builtin_ubsan_call (irange
&r
, gcall
*call
, tree_code code
);
68 bool range_with_loop_info (irange
&r
, tree name
);
69 void range_of_ssa_name_with_loop_info (irange
&, tree
, class loop
*,
73 // Calculate a basic range for a tree expression.
74 extern bool get_tree_range (irange
&r
, tree expr
);
76 // These routines provide a GIMPLE interface to the range-ops code.
77 extern tree
gimple_range_operand1 (const gimple
*s
);
78 extern tree
gimple_range_operand2 (const gimple
*s
);
79 extern tree
gimple_range_base_of_assignment (const gimple
*s
);
80 extern bool gimple_range_fold (irange
&res
, const gimple
*s
,
82 extern bool gimple_range_fold (irange
&res
, const gimple
*s
,
85 extern bool gimple_range_calc_op1 (irange
&r
, const gimple
*s
,
86 const irange
&lhs_range
);
87 extern bool gimple_range_calc_op1 (irange
&r
, const gimple
*s
,
88 const irange
&lhs_range
,
89 const irange
&op2_range
);
90 extern bool gimple_range_calc_op2 (irange
&r
, const gimple
*s
,
91 const irange
&lhs_range
,
92 const irange
&op1_range
);
95 // Return the range_operator pointer for this statement. This routine
96 // can also be used to gate whether a routine is range-ops enabled.
98 static inline range_operator
*
99 gimple_range_handler (const gimple
*s
)
101 if ((gimple_code (s
) == GIMPLE_ASSIGN
) || (gimple_code (s
) == GIMPLE_COND
))
102 return range_op_handler (gimple_expr_code (s
), gimple_expr_type (s
));
106 // Return EXP if it is an SSA_NAME with a type supported by gimple ranges.
109 gimple_range_ssa_p (tree exp
)
111 if (exp
&& TREE_CODE (exp
) == SSA_NAME
&&
112 !SSA_NAME_IS_VIRTUAL_OPERAND (exp
) &&
113 irange::supports_type_p (TREE_TYPE (exp
)))
118 // Return the legacy GCC global range for NAME if it has one, otherwise
121 static inline value_range
122 gimple_range_global (tree name
)
124 gcc_checking_assert (gimple_range_ssa_p (name
));
125 tree type
= TREE_TYPE (name
);
127 // Reenable picking up global ranges when we are OK failing tests that look
128 // for builtin_unreachable in the code, like
129 // RUNTESTFLAGS=dg.exp=pr61034.C check-g++
130 // pre-optimizations (inlining) set a global range which causes the ranger
131 // to remove the condition which leads to builtin_unreachable.
132 if (!POINTER_TYPE_P (type
) && SSA_NAME_RANGE_INFO (name
))
134 // Return a range from an SSA_NAME's available range.
136 enum value_range_kind kind
= get_range_info (name
, &min
, &max
);
137 return value_range (type
, min
, max
, kind
);
140 // Otherwise return range for the type.
141 return value_range (type
);
145 // This class overloads the ranger routines to provide tracing facilties
146 // Entry and exit values to each of the APIs is placed in the dumpfile.
148 class trace_ranger
: public gimple_ranger
152 virtual bool range_of_stmt (irange
&r
, gimple
*s
, tree name
= NULL_TREE
);
153 virtual bool range_of_expr (irange
&r
, tree name
, gimple
*s
= NULL
);
154 virtual bool range_on_edge (irange
&r
, edge e
, tree name
);
155 virtual void range_on_entry (irange
&r
, basic_block bb
, tree name
);
156 virtual void range_on_exit (irange
&r
, basic_block bb
, tree name
);
158 static const unsigned bump
= 2;
160 unsigned trace_count
; // Current trace index count.
162 bool dumping (unsigned counter
, bool trailing
= false);
163 bool trailer (unsigned counter
, const char *caller
, bool result
, tree name
,
167 // Flag to enable debugging the various internal Caches.
168 #define DEBUG_RANGE_CACHE (dump_file && (param_evrp_mode & EVRP_MODE_DEBUG))
170 #endif // GCC_GIMPLE_RANGE_STMT_H