1/* Header file for the GIMPLE range interface.
2 Copyright (C) 2019-2023 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_H
23#define GCC_GIMPLE_RANGE_H
24
25#include "ssa.h"
26#include "range.h"
27#include "value-query.h"
28#include "gimple-range-op.h"
29#include "gimple-range-trace.h"
30#include "gimple-range-edge.h"
31#include "gimple-range-fold.h"
32#include "gimple-range-gori.h"
33#include "gimple-range-cache.h"
34
35// This is the basic range generator interface.
36//
37// This base class provides all the API entry points, but only provides
38// functionality at the statement level. Ie, it can calculate ranges on
39// statements, but does no additional lookup.
40//
41// All the range_of_* methods will return a range if the types is
42// supported by the range engine. It may be the full range for the
43// type, AKA varying_p or it may be a refined range. If the range
44// type is not supported, then false is returned. Non-statement
45// related methods return whatever the current global value is.
46
47class gimple_ranger : public range_query
48{
49public:
50 gimple_ranger (bool use_imm_uses = true);
51 ~gimple_ranger ();
52 virtual bool range_of_stmt (vrange &r, gimple *, tree name = NULL) override;
53 virtual bool range_of_expr (vrange &r, tree name, gimple * = NULL) override;
54 virtual bool range_on_edge (vrange &r, edge e, tree name) override;
55 virtual void update_stmt (gimple *) override;
56 void range_on_entry (vrange &r, basic_block bb, tree name);
57 void range_on_exit (vrange &r, basic_block bb, tree name);
58 void export_global_ranges ();
59 inline gori_compute &gori () { return m_cache.m_gori; }
60 virtual void dump (FILE *f) override;
61 void debug ();
62 void dump_bb (FILE *f, basic_block bb);
63 auto_edge_flag non_executable_edge_flag;
64 bool fold_stmt (gimple_stmt_iterator *gsi, tree (*) (tree));
65 void register_inferred_ranges (gimple *s);
66 void register_transitive_inferred_ranges (basic_block bb);
67 range_query &const_query ();
68protected:
69 bool fold_range_internal (vrange &r, gimple *s, tree name);
70 void prefill_name (vrange &r, tree name);
71 void prefill_stmt_dependencies (tree ssa);
72 ranger_cache m_cache;
73 range_tracer tracer;
74 basic_block current_bb;
75 vec<tree> m_stmt_list;
76 friend class path_range_query;
77};
78
79/* Create a new ranger instance and associate it with a function.
80 Each call must be paired with a call to disable_ranger to release
81 resources. If USE_IMM_USES is true, pre-calculate side effects like
82 non-null uses as required using the immediate use chains. */
83extern gimple_ranger *enable_ranger (struct function *m,
84 bool use_imm_uses = true);
85extern void disable_ranger (struct function *);
86
87class assume_query : public range_query
88{
89public:
90 assume_query ();
91 bool assume_range_p (vrange &r, tree name);
92 virtual bool range_of_expr (vrange &r, tree expr, gimple * = NULL);
93 void dump (FILE *f);
94protected:
95 void calculate_stmt (gimple *s, vrange &lhs_range, fur_source &src);
96 void calculate_op (tree op, gimple *s, vrange &lhs, fur_source &src);
97 void calculate_phi (gphi *phi, vrange &lhs_range, fur_source &src);
98 void check_taken_edge (edge e, fur_source &src);
99
100 ssa_lazy_cache global;
101 gori_compute m_gori;
102};
103
104// DOM based ranger for fast VRP.
105// This must be processed in DOM order, and does only basic range operations.
106
107class dom_ranger : public range_query
108{
109public:
110 dom_ranger ();
111 ~dom_ranger ();
112
113 virtual bool range_of_expr (vrange &r, tree expr, gimple *s = NULL) override;
114 virtual bool range_on_edge (vrange &r, edge e, tree expr) override;
115 virtual bool range_of_stmt (vrange &r, gimple *s, tree name = NULL) override;
116
117 bool edge_range (vrange &r, edge e, tree name);
118 void range_in_bb (vrange &r, basic_block bb, tree name);
119
120 void pre_bb (basic_block bb);
121 void post_bb (basic_block bb);
122protected:
123 DISABLE_COPY_AND_ASSIGN (dom_ranger);
124 void maybe_push_edge (edge e, bool edge_0);
125 ssa_cache m_global;
126 gimple_outgoing_range m_out;
127 vec<ssa_lazy_cache *> m_freelist;
128 vec<ssa_lazy_cache *> m_e0;
129 vec<ssa_lazy_cache *> m_e1;
130 bitmap m_pop_list;
131 range_tracer tracer;
132};
133#endif // GCC_GIMPLE_RANGE_H
134

source code of gcc/gimple-range.h