GCC Middle and Back End API Reference
value-query.h
Go to the documentation of this file.
1/* Support routines for value queries.
2 Copyright (C) 2020-2025 Free Software Foundation, Inc.
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
25#include "value-relation.h"
26
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 need
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
40// The range_query class is used by optimization passes which are
41// range aware.
42//
43// range_of_expr must be provided. The default for range_on_edge and
44// range_of_stmt is to call range_of_expr. If a pass can make use of
45// more specific information, then it can override the other queries.
46//
47// The default for the value_* routines is to call the equivalent
48// range_* routines, check if the range is a singleton, and return it
49// if so.
50//
51// The get_value_range method is currently provided for compatibility
52// with vr-values. It will be deprecated when possible.
53
55{
56public:
57 range_query ();
58 virtual ~range_query ();
59
60 virtual tree value_of_expr (tree expr, gimple * = NULL);
61 virtual tree value_on_edge (edge, tree expr);
62 virtual tree value_of_stmt (gimple *, tree name = NULL);
65
66 // These are the range equivalents of the value_* methods. Instead
67 // of returning a singleton, they calculate a range and return it in
68 // R. TRUE is returned on success or FALSE if no range was found.
69 //
70 // Note that range_of_expr must always return TRUE unless ranges are
71 // unsupported for EXPR's type (supports_type_p is false).
72 virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL) = 0;
73 virtual bool range_on_edge (vrange &r, edge, tree expr);
74 virtual bool range_of_stmt (vrange &r, gimple *, tree name = NULL);
75 virtual bool range_on_entry (vrange &r, basic_block bb, tree expr);
76 virtual bool range_on_exit (vrange &r, basic_block bb, tree expr);
77
78 virtual void update_range_info (tree name, const vrange &r);
79
80 inline class relation_oracle &relation () const { return *m_relation; }
81 void create_relation_oracle (bool do_trans_p = true);
83
84 inline class infer_range_oracle &infer_oracle () const { return *m_infer; }
85 void create_infer_oracle (range_query *q = NULL, bool do_search = true);
87
88 inline class gimple_outgoing_range &gori () const { return *m_gori; }
89 inline class gori_map *gori_ssa () const { return m_map; }
90 void create_gori (int not_executable_flag = 0, int sw_max_edges = INT_MAX);
91 void destroy_gori ();
92
93 virtual void dump (FILE *);
94
95protected:
96 bool get_tree_range (vrange &v, tree expr, gimple *stmt,
97 basic_block bbentry = NULL, basic_block bbexit = NULL,
98 edge e = NULL);
100 basic_block bbentry, basic_block bbexit, edge e);
106 // When multiple related range queries wish to share oracles.
107 // This is an internal interface
108 void share_query (range_query &q);
110};
111
112// Global ranges for SSA names using SSA_NAME_RANGE_INFO.
113
115{
116public:
117 bool range_of_expr (vrange &r, tree expr, gimple * = NULL) override;
118};
119
121
122inline range_query *
124{
125 return &global_ranges;
126}
127
128/* Returns the currently active range access class. When there is no active
129 range class, global ranges are used. Never returns null. */
130
131ATTRIBUTE_RETURNS_NONNULL inline range_query *
132get_range_query (const struct function *fun)
133{
134 return (fun && fun->x_range_query) ? fun->x_range_query : &global_ranges;
135}
136
137// Query the global range of NAME in function F. Default to cfun.
138extern void gimple_range_global (vrange &v, tree name,
139 struct function *f = cfun);
140#endif // GCC_QUERY_H
Definition genmatch.cc:1506
Definition gimple-range-edge.h:48
Definition value-query.h:115
bool range_of_expr(vrange &r, tree expr, gimple *=NULL) override
Definition value-query.cc:550
Definition gimple-range-gori.h:94
Definition gimple-range-infer.h:84
Definition value-query.h:55
class infer_range_oracle & infer_oracle() const
Definition value-query.h:84
virtual tree value_of_expr(tree expr, gimple *=NULL)
Definition value-query.cc:79
virtual bool range_on_edge(vrange &r, edge, tree expr)
Definition value-query.cc:39
bool get_tree_range(vrange &v, tree expr, gimple *stmt, basic_block bbentry=NULL, basic_block bbexit=NULL, edge e=NULL)
Definition value-query.cc:330
class relation_oracle & relation() const
Definition value-query.h:80
virtual bool range_on_entry(vrange &r, basic_block bb, tree expr)
Definition value-query.cc:45
gimple_outgoing_range * m_gori
Definition value-query.h:104
class gori_map * gori_ssa() const
Definition value-query.h:89
virtual ~range_query()
Definition value-query.cc:286
infer_range_oracle * m_infer
Definition value-query.h:103
void destroy_infer_oracle()
Definition value-query.cc:230
void create_gori(int not_executable_flag=0, int sw_max_edges=INT_MAX)
Definition value-query.cc:194
bool get_arith_expr_range(vrange &r, tree expr, gimple *stmt)
relation_oracle * m_relation
Definition value-query.h:102
void create_infer_oracle(range_query *q=NULL, bool do_search=true)
Definition value-query.cc:222
virtual bool range_of_expr(vrange &r, tree expr, gimple *=NULL)=0
range_query()
Definition value-query.cc:277
void create_relation_oracle(bool do_trans_p=true)
Definition value-query.cc:242
virtual bool range_of_stmt(vrange &r, gimple *, tree name=NULL)
Definition value-query.cc:57
void share_query(range_query &q)
Definition value-query.cc:268
virtual void update_range_info(tree name, const vrange &r)
Definition value-query.cc:71
virtual tree value_on_edge(edge, tree expr)
Definition value-query.cc:104
bool m_shared_copy_p
Definition value-query.h:109
virtual tree value_on_entry(basic_block, tree expr)
Definition value-query.cc:148
gori_map * m_map
Definition value-query.h:105
virtual bool range_on_exit(vrange &r, basic_block bb, tree expr)
Definition value-query.cc:51
virtual tree value_on_exit(basic_block, tree expr)
Definition value-query.cc:167
void destroy_relation_oracle()
Definition value-query.cc:256
virtual void dump(FILE *)
Definition value-query.cc:183
void destroy_gori()
Definition value-query.cc:205
bool invoke_range_of_expr(vrange &v, tree expr, gimple *stmt, basic_block bbentry, basic_block bbexit, edge e)
Definition value-query.cc:302
virtual tree value_of_stmt(gimple *, tree name=NULL)
Definition value-query.cc:127
class gimple_outgoing_range & gori() const
Definition value-query.h:88
Definition value-relation.h:98
Definition value-range.h:78
struct basic_block_def * basic_block
Definition coretypes.h:372
class edge_def * edge
Definition coretypes.h:369
union tree_node * tree
Definition coretypes.h:97
#define cfun
Definition function.h:480
#define INT_MAX
Definition glimits.h:85
poly_int< N, C > r
Definition poly-int.h:774
Definition function.h:249
range_query * x_range_query
Definition function.h:314
Definition gimple.h:221
#define NULL
Definition system.h:50
global_range_query global_ranges
Definition value-query.cc:547
void gimple_range_global(vrange &v, tree name, struct function *f=cfun)
Definition value-query.cc:493
range_query * get_global_range_query()
Definition value-query.h:123
ATTRIBUTE_RETURNS_NONNULL range_query * get_range_query(const struct function *fun)
Definition value-query.h:132