GCC Middle and Back End API Reference
gimple-range-cache.h
Go to the documentation of this file.
1/* Header file for gimple ranger SSA cache.
2 Copyright (C) 2017-2026 Free Software Foundation, Inc.
3 Contributed by Andrew MacLeod <amacleod@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_SSA_RANGE_CACHE_H
22#define GCC_SSA_RANGE_CACHE_H
23
24#include "gimple-range-gori.h"
25#include "gimple-range-infer.h"
26#include "gimple-range-phi.h"
27
28// This class manages a vector of pointers to ssa_block ranges. It
29// provides the basis for the "range on entry" cache for all
30// SSA names.
31
33{
34public:
37
38 bool set_bb_range (tree name, const_basic_block bb, const vrange &v);
39 bool get_bb_range (vrange &v, tree name, const_basic_block bb);
40 bool bb_range_p (tree name, const_basic_block bb);
41 void clear (tree name);
42
43 void dump (FILE *f);
44 void dump (FILE *f, basic_block bb, bool print_varying = true);
45private:
51};
52
53// This global cache is used with the range engine as markers for what
54// has been visited during this incarnation. Once the ranger evaluates
55// a name, it is typically not re-evaluated again.
56
57class ssa_cache : public range_query
58{
59public:
60 ssa_cache ();
61 ~ssa_cache ();
62 virtual bool has_range (tree name) const;
63 virtual bool get_range (vrange &r, tree name) const;
64 virtual bool set_range (tree name, const vrange &r);
65 virtual bool merge_range (tree name, const vrange &r);
66 virtual void clear_range (tree name);
67 virtual void clear ();
68 void dump (FILE *f = stderr);
69 virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt = NULL);
70protected:
73};
74
75// This is the same as global cache, except it maintains an active bitmap
76// rather than depending on a zero'd out vector of pointers. This is better
77// for sparsely/lightly used caches.
78
80{
81public:
84 inline bool empty_p () const { return bitmap_empty_p (active_p); }
85 virtual bool has_range (tree name) const;
86 virtual bool set_range (tree name, const vrange &r);
87 virtual bool merge_range (tree name, const vrange &r);
88 virtual bool get_range (vrange &r, tree name) const;
89 virtual void clear_range (tree name);
90 virtual void clear ();
91 void merge (const ssa_lazy_cache &);
92protected:
96};
97
98// This class provides all the caches a global ranger may need, and makes
99// them available for gori-computes to query so outgoing edges can be
100// properly calculated.
101
103{
104public:
105 ranger_cache (int not_executable_flag, bool use_imm_uses);
106 ~ranger_cache ();
107
108 bool range_of_expr (vrange &r, tree name, gimple *stmt) final override;
109 bool range_on_edge (vrange &r, edge e, tree expr) final override;
110 bool block_range (vrange &r, basic_block bb, tree name, bool calc = true);
111
112 bool get_global_range (vrange &r, tree name) const;
113 bool get_global_range (vrange &r, tree name, bool &current_p);
114 void set_global_range (tree name, const vrange &r, bool changed = true);
115 void mark_stale (tree name);
116 void update_consumers (tree name);
118
120
121 void register_inferred_value (const vrange &r, tree name, basic_block bb);
123
124 void reset_range_info (tree name);
125
126 void dump_bb (FILE *f, basic_block bb);
127 virtual void dump (FILE *f) override;
128private:
132 void fill_block_cache (tree name, basic_block bb, basic_block def_bb);
133 void propagate_cache (tree name);
134
136 {
137 RFD_NONE, // Only look at current block cache.
138 RFD_READ_ONLY, // Scan DOM tree, do not write to cache.
139 RFD_FILL // Scan DOM tree, updating important nodes.
140 };
141 bool range_from_dom (vrange &r, tree name, basic_block bb, enum rfd_mode);
142 void resolve_dom (vrange &r, tree name, basic_block bb);
143 void range_of_def (vrange &r, tree name, basic_block bb = NULL);
144 void entry_range (vrange &r, tree expr, basic_block bb, enum rfd_mode);
145 void exit_range (vrange &r, tree expr, basic_block bb, enum rfd_mode);
146 bool edge_range (vrange &r, edge e, tree name, enum rfd_mode);
147
151};
152
153#endif // GCC_SSA_RANGE_CACHE_H
bool bitmap_empty_p(const_bitmap map)
Definition bitmap.h:392
Definition gimple-range-cache.h:33
~block_range_cache()
Definition gimple-range-cache.cc:376
vec< class ssa_block_ranges * > m_ssa_ranges
Definition gimple-range-cache.h:46
void clear(tree name)
Definition gimple-range-cache.cc:387
void dump(FILE *f)
Definition gimple-range-cache.cc:476
class vrange_allocator * m_range_allocator
Definition gimple-range-cache.h:49
bool get_bb_range(vrange &v, tree name, const_basic_block bb)
Definition gimple-range-cache.cc:454
bool set_bb_range(tree name, const_basic_block bb, const vrange &v)
Definition gimple-range-cache.cc:399
ssa_block_ranges & get_block_ranges(tree name)
block_range_cache()
Definition gimple-range-cache.cc:366
ssa_block_ranges * query_block_ranges(tree name)
Definition gimple-range-cache.cc:440
bool bb_range_p(tree name, const_basic_block bb)
Definition gimple-range-cache.cc:465
bitmap_obstack m_bitmaps
Definition gimple-range-cache.h:50
Definition genmatch.cc:1507
range_query()
Definition value-query.cc:296
bool range_from_dom(vrange &r, tree name, basic_block bb, enum rfd_mode)
Definition gimple-range-cache.cc:1795
void propagate_cache(tree name)
Definition gimple-range-cache.cc:1418
void entry_range(vrange &r, tree expr, basic_block bb, enum rfd_mode)
Definition gimple-range-cache.cc:1273
void register_inferred_value(const vrange &r, tree name, basic_block bb)
Definition gimple-range-cache.cc:1951
bool get_global_range(vrange &r, tree name) const
Definition gimple-range-cache.cc:1117
bool range_on_edge(vrange &r, edge e, tree expr) final override
Definition gimple-range-cache.cc:1364
ranger_cache(int not_executable_flag, bool use_imm_uses)
Definition gimple-range-cache.cc:1054
void fill_block_cache(tree name, basic_block bb, basic_block def_bb)
Definition gimple-range-cache.cc:1557
void apply_inferred_ranges(gimple *s)
Definition gimple-range-cache.cc:1970
vec< basic_block > m_workback
Definition gimple-range-cache.h:148
class update_list * m_update
Definition gimple-range-cache.h:149
rfd_mode
Definition gimple-range-cache.h:136
@ RFD_NONE
Definition gimple-range-cache.h:137
@ RFD_FILL
Definition gimple-range-cache.h:139
@ RFD_READ_ONLY
Definition gimple-range-cache.h:138
bitmap m_stale
Definition gimple-range-cache.h:150
virtual void dump(FILE *f) override
Definition gimple-range-cache.cc:1095
bool range_of_expr(vrange &r, tree name, gimple *stmt) final override
Definition gimple-range-cache.cc:1338
void set_global_range(tree name, const vrange &r, bool changed=true)
Definition gimple-range-cache.cc:1206
range_query & const_query()
Definition gimple-range-cache.h:117
void dump_bb(FILE *f, basic_block bb)
Definition gimple-range-cache.cc:1106
ssa_cache m_globals
Definition gimple-range-cache.h:129
void resolve_dom(vrange &r, tree name, basic_block bb)
Definition gimple-range-cache.cc:1758
void update_consumers(tree name)
Definition gimple-range-cache.cc:1198
block_range_cache m_on_entry
Definition gimple-range-cache.h:130
~ranger_cache()
Definition gimple-range-cache.cc:1081
bool edge_range(vrange &r, edge e, tree name, enum rfd_mode)
Definition gimple-range-cache.cc:1321
class temporal_cache * m_temporal
Definition gimple-range-cache.h:131
void range_of_def(vrange &r, tree name, basic_block bb=NULL)
Definition gimple-range-cache.cc:1252
void reset_range_info(tree name)
Definition gimple-range-cache.cc:2000
bool block_range(vrange &r, basic_block bb, tree name, bool calc=true)
Definition gimple-range-cache.cc:1376
void mark_stale(tree name)
Definition gimple-range-cache.cc:1128
void propagate_updated_value(tree name, basic_block bb)
Definition gimple-range-cache.cc:1514
void exit_range(vrange &r, tree expr, basic_block bb, enum rfd_mode)
Definition gimple-range-cache.cc:1300
Definition gimple-range-cache.cc:46
Definition gimple-range-cache.h:58
virtual bool has_range(tree name) const
Definition gimple-range-cache.cc:582
virtual void clear_range(tree name)
Definition gimple-range-cache.cc:658
vrange_allocator * m_range_allocator
Definition gimple-range-cache.h:72
ssa_cache()
Definition gimple-range-cache.cc:551
virtual bool set_range(tree name, const vrange &r)
Definition gimple-range-cache.cc:611
void dump(FILE *f=stderr)
Definition gimple-range-cache.cc:678
vec< vrange_storage * > m_tab
Definition gimple-range-cache.h:71
virtual bool get_range(vrange &r, tree name) const
Definition gimple-range-cache.cc:594
~ssa_cache()
Definition gimple-range-cache.cc:559
virtual bool range_of_expr(vrange &r, tree expr, gimple *stmt=NULL)
Definition gimple-range-cache.cc:569
virtual void clear()
Definition gimple-range-cache.cc:669
virtual bool merge_range(tree name, const vrange &r)
Definition gimple-range-cache.cc:629
Definition gimple-range-cache.h:80
virtual void clear_range(tree name)
Definition gimple-range-cache.cc:800
virtual bool has_range(tree name) const
Definition gimple-range-cache.cc:726
bitmap_obstack m_bitmaps
Definition gimple-range-cache.h:93
virtual void clear()
Definition gimple-range-cache.cc:808
bitmap_obstack * m_ob
Definition gimple-range-cache.h:94
virtual bool set_range(tree name, const vrange &r)
Definition gimple-range-cache.cc:735
~ssa_lazy_cache()
Definition gimple-range-cache.cc:715
void merge(const ssa_lazy_cache &)
Definition gimple-range-cache.cc:774
bool empty_p() const
Definition gimple-range-cache.h:84
bitmap active_p
Definition gimple-range-cache.h:95
virtual bool get_range(vrange &r, tree name) const
Definition gimple-range-cache.cc:790
ssa_lazy_cache(bitmap_obstack *ob=NULL)
Definition gimple-range-cache.cc:700
virtual bool merge_range(tree name, const vrange &r)
Definition gimple-range-cache.cc:754
Definition gimple-range-cache.cc:842
Definition gimple-range-cache.cc:977
Definition value-range-storage.h:28
Definition value-range.h:88
struct basic_block_def * basic_block
Definition coretypes.h:351
class edge_def * edge
Definition coretypes.h:348
const struct basic_block_def * const_basic_block
Definition coretypes.h:352
class bitmap_head * bitmap
Definition coretypes.h:51
union tree_node * tree
Definition coretypes.h:97
poly_int< N, C > r
Definition poly-int.h:774
static bitmap changed
Definition pta-andersen.cc:866
Definition bitmap.h:293
Definition gimple.h:224
Definition vec.h:450
#define NULL
Definition system.h:58