]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/value-query.h
Correct a function pre/postcondition [PR102403].
[thirdparty/gcc.git] / gcc / value-query.h
CommitLineData
6eda9fa5 1/* Support routines for value queries.
99dee823 2 Copyright (C) 2020-2021 Free Software Foundation, Inc.
6eda9fa5
AH
3 Contributed by Aldy Hernandez <aldyh@redhat.com> and
4 Andrew Macleod <amacleod@redhat.com>.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 3, or (at your option)
11any later version.
12
13GCC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GCC; see the file COPYING3. If not see
20<http://www.gnu.org/licenses/>. */
21
22#ifndef GCC_QUERY_H
23#define GCC_QUERY_H
24
3aaa69e5
AM
25#include "value-relation.h"
26
6eda9fa5
AH
27// The value_query class is used by optimization passes that require
28// valueizing SSA names in terms of a tree value, but have no neeed
29// for ranges.
30//
31// value_of_expr must be provided. The default for value_on_edge and
32// value_of_stmt is to call value_of_expr.
33//
34// This implies the valuation is global in nature. If a pass can make
35// use of more specific information, it can override the other queries.
36//
37// Proper usage of the correct query in passes will enable other
38// valuation mechanisms to produce more precise results.
39
40class value_query
41{
42public:
43 value_query () { }
7c097d18 44 // Return the singleton expression for EXPR at a gimple statement,
6eda9fa5 45 // or NULL if none found.
7c097d18
AH
46 virtual tree value_of_expr (tree expr, gimple * = NULL) = 0;
47 // Return the singleton expression for EXPR at an edge, or NULL if
6eda9fa5 48 // none found.
7c097d18 49 virtual tree value_on_edge (edge, tree expr);
6eda9fa5
AH
50 // Return the singleton expression for the LHS of a gimple
51 // statement, assuming an (optional) initial value of NAME. Returns
52 // NULL if none found.
53 //
54 // Note that this method calculates the range the LHS would have
55 // *after* the statement has executed.
56 virtual tree value_of_stmt (gimple *, tree name = NULL);
57
58private:
59 DISABLE_COPY_AND_ASSIGN (value_query);
60};
61
62// The range_query class is used by optimization passes which are
63// range aware.
64//
65// range_of_expr must be provided. The default for range_on_edge and
66// range_of_stmt is to call range_of_expr. If a pass can make use of
67// more specific information, then it can override the other queries.
68//
69// The default for the value_* routines is to call the equivalent
70// range_* routines, check if the range is a singleton, and return it
71// if so.
72//
73// The get_value_range method is currently provided for compatibility
74// with vr-values. It will be deprecated when possible.
75
76class range_query : public value_query
77{
78public:
79 range_query ();
80 virtual ~range_query ();
81
7c097d18
AH
82 virtual tree value_of_expr (tree expr, gimple * = NULL) OVERRIDE;
83 virtual tree value_on_edge (edge, tree expr) OVERRIDE;
6eda9fa5
AH
84 virtual tree value_of_stmt (gimple *, tree name = NULL) OVERRIDE;
85
86 // These are the range equivalents of the value_* methods. Instead
87 // of returning a singleton, they calculate a range and return it in
88 // R. TRUE is returned on success or FALSE if no range was found.
89 //
90 // Note that range_of_expr must always return TRUE unless ranges are
7c097d18
AH
91 // unsupported for EXPR's type (supports_type_p is false).
92 virtual bool range_of_expr (irange &r, tree expr, gimple * = NULL) = 0;
93 virtual bool range_on_edge (irange &r, edge, tree expr);
6eda9fa5
AH
94 virtual bool range_of_stmt (irange &r, gimple *, tree name = NULL);
95
3aaa69e5
AM
96 // Query if there is any relation between SSA1 and SSA2.
97 relation_kind query_relation (gimple *s, tree ssa1, tree ssa2,
98 bool get_range = true);
99 relation_kind query_relation (edge e, tree ssa1, tree ssa2,
100 bool get_range = true);
101 // If present, Access relation oracle for more advanced uses.
102 inline relation_oracle *oracle () const { return m_oracle; }
103
6eda9fa5
AH
104 // DEPRECATED: This method is used from vr-values. The plan is to
105 // rewrite all uses of it to the above API.
106 virtual const class value_range_equiv *get_value_range (const_tree,
107 gimple * = NULL);
586d6f7a 108 virtual void dump (FILE *);
6eda9fa5
AH
109
110protected:
111 class value_range_equiv *allocate_value_range_equiv ();
112 void free_value_range_equiv (class value_range_equiv *);
caa60c12
AH
113 bool get_tree_range (irange &r, tree expr, gimple *stmt);
114 bool get_arith_expr_range (irange &r, tree expr, gimple *stmt);
3aaa69e5 115 relation_oracle *m_oracle;
6eda9fa5
AH
116
117private:
118 class equiv_allocator *equiv_alloc;
119};
120
13dbaefe
AH
121// Global ranges for SSA names using SSA_NAME_RANGE_INFO.
122
123class global_range_query : public range_query
124{
125public:
126 bool range_of_expr (irange &r, tree expr, gimple * = NULL) OVERRIDE;
127};
128
129extern global_range_query global_ranges;
130extern value_range gimple_range_global (tree name);
160fe603 131extern bool update_global_range (irange &r, tree name);
13dbaefe 132
6eda9fa5 133#endif // GCC_QUERY_H