GCC Middle and Back End API Reference
gimple-range-fold.h
Go to the documentation of this file.
1/* Header file for the GIMPLE fold_using_range interface.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>
4 and Aldy Hernandez <aldyh@redhat.com>.
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 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_GIMPLE_RANGE_FOLD_H
23#define GCC_GIMPLE_RANGE_FOLD_H
24
25// This file is the main include point for gimple range folding.
26// These routines will fold stmt S into the result range R.
27// Any ssa_names on the stmt will be calculated using the range_query
28// parameter via a call to range_of_expr.
29// If no range_query is provided, current global range info will be used.
30// The second variation specifies an edge, and stmt S is recalculated as if
31// it appeared on that edge.
32
33// Fold stmt S into range R using range query Q.
34bool fold_range (vrange &r, gimple *s, range_query *q = NULL);
35// Recalculate stmt S into R using range query Q as if it were on edge ON_EDGE.
36bool fold_range (vrange &v, gimple *s, edge on_edge, range_query *q = NULL);
37
38// These routines the operands to be specified when manually folding.
39// Any excess queries will be drawn from the current range_query.
40bool fold_range (vrange &r, gimple *s, vrange &r1, range_query *q = NULL);
41bool fold_range (vrange &r, gimple *s, vrange &r1, vrange &r2,
42 range_query *q = NULL);
43bool fold_range (vrange &r, gimple *s, unsigned num_elements, vrange **vector,
44 range_query *q = NULL);
45
46// This routine will return a relation trio for stmt S.
48
49// Return the type of range which statement S calculates. If the type is
50// unsupported or no type can be determined, return NULL_TREE.
51
52inline tree
54{
55 tree lhs = gimple_get_lhs (s);
57 if (lhs)
58 type = TREE_TYPE (lhs);
59 else
60 {
61 enum gimple_code code = gimple_code (s);
62 if (code == GIMPLE_COND)
64 else if (code == GIMPLE_PHI)
66 else if (code == GIMPLE_CALL)
67 {
69 // If it has a type, get the return type.
70 if (type)
72 }
73 }
75 return type;
76 return NULL_TREE;
77}
78
79// Return EXP if it is an SSA_NAME with a type supported by gimple ranges.
80
81inline tree
91
92// Source of all operands for fold_using_range and gori_compute.
93// It abstracts out the source of an operand so it can come from a stmt or
94// and edge or anywhere a derived class of fur_source wants.
95// The default simply picks up ranges from the current range_query.
96
98{
99public:
101 inline range_query *query () { return m_query; }
102 inline class gori_compute *gori () { return m_gori; };
103 virtual bool get_operand (vrange &r, tree expr);
104 virtual bool get_phi_operand (vrange &r, tree expr, edge e);
105 virtual relation_kind query_relation (tree op1, tree op2);
106 virtual void register_relation (gimple *stmt, relation_kind k, tree op1,
107 tree op2);
108 virtual void register_relation (edge e, relation_kind k, tree op1,
109 tree op2);
111protected:
114};
115
116// fur_stmt is the specification for drawing an operand from range_query Q
117// via a range_of_Expr call on stmt S.
118
119class fur_stmt : public fur_source
120{
121public:
122 fur_stmt (gimple *s, range_query *q = NULL);
123 virtual bool get_operand (vrange &r, tree expr) override;
124 virtual bool get_phi_operand (vrange &r, tree expr, edge e) override;
125 virtual relation_kind query_relation (tree op1, tree op2) override;
126private:
128};
129
130// This version of fur_source will pick a range from a stmt, and also register
131// dependencies via a gori_compute object. This is mostly an internal API.
132
133class fur_depend : public fur_stmt
134{
135public:
137 virtual void register_relation (gimple *stmt, relation_kind k, tree op1,
138 tree op2) override;
139 virtual void register_relation (edge e, relation_kind k, tree op1,
140 tree op2) override;
141protected:
143};
144
145// This class uses ranges to fold a gimple statement producing a range for
146// the LHS. The source of all operands is supplied via the fur_source class
147// which provides a range_query as well as a source location and any other
148// required information.
149
151{
152public:
153 bool fold_stmt (vrange &r, gimple *s, class fur_source &src,
154 tree name = NULL_TREE);
155protected:
157 fur_source &src);
158 bool range_of_call (vrange &r, gcall *call, fur_source &src);
159 bool range_of_cond_expr (vrange &r, gassign* cond, fur_source &src);
160 bool range_of_address (irange &r, gimple *s, fur_source &src);
161 bool range_of_phi (vrange &r, gphi *phi, fur_source &src);
163 fur_source &src);
165 vrange &op1, vrange &op2);
166};
167#endif // GCC_GIMPLE_RANGE_FOLD_H
static bool supports_type_p(const_tree type)
Definition value-range.h:866
Definition genmatch.cc:845
Definition gimple-range-fold.h:151
bool range_of_call(vrange &r, gcall *call, fur_source &src)
Definition gimple-range-fold.cc:1006
bool range_of_cond_expr(vrange &r, gassign *cond, fur_source &src)
Definition gimple-range-fold.cc:1056
bool range_of_address(irange &r, gimple *s, fur_source &src)
Definition gimple-range-fold.cc:760
bool range_of_range_op(vrange &r, gimple_range_op_handler &handler, fur_source &src)
Definition gimple-range-fold.cc:647
void range_of_ssa_name_with_loop_info(vrange &, tree, class loop *, gphi *, fur_source &src)
Definition gimple-range-fold.cc:1109
void relation_fold_and_or(irange &lhs_range, gimple *s, fur_source &src, vrange &op1, vrange &op2)
Definition gimple-range-fold.cc:1128
bool fold_stmt(vrange &r, gimple *s, class fur_source &src, tree name=NULL_TREE)
Definition gimple-range-fold.cc:587
bool range_of_phi(vrange &r, gphi *phi, fur_source &src)
Definition gimple-range-fold.cc:848
Definition gimple-range-fold.h:134
fur_depend(gimple *s, gori_compute *gori, range_query *q=NULL)
Definition gimple-range-fold.cc:187
virtual void register_relation(gimple *stmt, relation_kind k, tree op1, tree op2) override
Definition gimple-range-fold.cc:201
relation_oracle * m_oracle
Definition gimple-range-fold.h:142
Definition gimple-range-fold.h:98
gori_compute * m_gori
Definition gimple-range-fold.h:113
class gori_compute * gori()
Definition gimple-range-fold.h:102
range_query * query()
Definition gimple-range-fold.h:101
fur_source(range_query *q=NULL)
Definition gimple-range-fold.cc:56
void register_outgoing_edges(gcond *, irange &lhs_range, edge e0, edge e1)
Definition gimple-range-fold.cc:1227
virtual bool get_operand(vrange &r, tree expr)
Definition gimple-range-fold.cc:68
virtual bool get_phi_operand(vrange &r, tree expr, edge e)
Definition gimple-range-fold.cc:77
range_query * m_query
Definition gimple-range-fold.h:112
virtual void register_relation(gimple *stmt, relation_kind k, tree op1, tree op2)
Definition gimple-range-fold.cc:94
virtual relation_kind query_relation(tree op1, tree op2)
Definition gimple-range-fold.cc:85
Definition gimple-range-fold.h:120
gimple * m_stmt
Definition gimple-range-fold.h:127
virtual bool get_phi_operand(vrange &r, tree expr, edge e) override
Definition gimple-range-fold.cc:169
fur_stmt(gimple *s, range_query *q=NULL)
Definition gimple-range-fold.cc:152
virtual bool get_operand(vrange &r, tree expr) override
Definition gimple-range-fold.cc:160
virtual relation_kind query_relation(tree op1, tree op2) override
Definition gimple-range-fold.cc:179
Definition gimple-range-op.h:29
Definition gimple-range-gori.h:165
Definition value-range.h:276
Definition cfgloop.h:120
Definition value-query.h:55
Definition value-relation.h:98
Definition value-relation.h:331
Definition value-range.h:76
class edge_def * edge
Definition coretypes.h:342
union tree_node * tree
Definition coretypes.h:97
double exp(double)
static type_p type(options_p *optsp, bool nested)
Definition gengtype-parse.cc:883
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
tree gimple_range_ssa_p(tree exp)
Definition gimple-range-fold.h:82
tree gimple_range_type(const gimple *s)
Definition gimple-range-fold.h:53
bool fold_range(vrange &r, gimple *s, range_query *q=NULL)
Definition gimple-range-fold.cc:320
relation_trio fold_relations(gimple *s, range_query *q=NULL)
Definition gimple-range-fold.cc:425
tree gimple_get_lhs(const gimple *stmt)
Definition gimple.cc:1938
gimple_code
Definition gimple.h:30
tree gimple_phi_result(const gphi *gs)
Definition gimple.h:4559
tree gimple_call_fntype(const gcall *gs)
Definition gimple.h:3119
poly_int< N, C > r
Definition poly-int.h:770
Definition gimple.h:903
Definition gimple.h:352
Definition gimple.h:857
Definition gimple.h:225
Definition gimple.h:461
Definition gengtype.h:252
#define NULL
Definition system.h:50
#define TREE_CODE(NODE)
Definition tree.h:324
#define boolean_type_node
Definition tree.h:4514
#define TREE_TYPE(NODE)
Definition tree.h:512
#define SSA_NAME_IS_VIRTUAL_OPERAND(NODE)
Definition tree.h:2064
#define SSA_NAME_OCCURS_IN_ABNORMAL_PHI(NODE)
Definition tree.h:2106
#define NULL_TREE
Definition tree.h:317
enum relation_kind_t relation_kind