Line data Source code
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 :
5 : This file is part of GCC.
6 :
7 : GCC is free software; you can redistribute it and/or modify it under
8 : the terms of the GNU General Public License as published by the Free
9 : Software Foundation; either version 3, or (at your option) any later
10 : version.
11 :
12 : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : for more details.
16 :
17 : You should have received a copy of the GNU General Public License
18 : along 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 :
32 : class block_range_cache
33 : {
34 : public:
35 : block_range_cache ();
36 : ~block_range_cache ();
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 :
42 : void dump (FILE *f);
43 : void dump (FILE *f, basic_block bb, bool print_varying = true);
44 : private:
45 : vec<class ssa_block_ranges *> m_ssa_ranges;
46 : ssa_block_ranges &get_block_ranges (tree name);
47 : ssa_block_ranges *query_block_ranges (tree name);
48 : class vrange_allocator *m_range_allocator;
49 : bitmap_obstack m_bitmaps;
50 : };
51 :
52 : // This global cache is used with the range engine as markers for what
53 : // has been visited during this incarnation. Once the ranger evaluates
54 : // a name, it is typically not re-evaluated again.
55 :
56 : class ssa_cache : public range_query
57 : {
58 : public:
59 : ssa_cache ();
60 : ~ssa_cache ();
61 : virtual bool has_range (tree name) const;
62 : virtual bool get_range (vrange &r, tree name) const;
63 : virtual bool set_range (tree name, const vrange &r);
64 : virtual bool merge_range (tree name, const vrange &r);
65 : virtual void clear_range (tree name);
66 : virtual void clear ();
67 : void dump (FILE *f = stderr);
68 : virtual bool range_of_expr (vrange &r, tree expr, gimple *stmt = NULL);
69 : protected:
70 : vec<vrange_storage *> m_tab;
71 : vrange_allocator *m_range_allocator;
72 : };
73 :
74 : // This is the same as global cache, except it maintains an active bitmap
75 : // rather than depending on a zero'd out vector of pointers. This is better
76 : // for sparsely/lightly used caches.
77 :
78 : class ssa_lazy_cache : public ssa_cache
79 : {
80 : public:
81 : ssa_lazy_cache (bitmap_obstack *ob = NULL);
82 : ~ssa_lazy_cache ();
83 64 : inline bool empty_p () const { return bitmap_empty_p (active_p); }
84 : virtual bool has_range (tree name) const;
85 : virtual bool set_range (tree name, const vrange &r);
86 : virtual bool merge_range (tree name, const vrange &r);
87 : virtual bool get_range (vrange &r, tree name) const;
88 : virtual void clear_range (tree name);
89 : virtual void clear ();
90 : void merge (const ssa_lazy_cache &);
91 : protected:
92 : bitmap_obstack m_bitmaps;
93 : bitmap_obstack *m_ob;
94 : bitmap active_p;
95 : };
96 :
97 : // This class provides all the caches a global ranger may need, and makes
98 : // them available for gori-computes to query so outgoing edges can be
99 : // properly calculated.
100 :
101 : class ranger_cache : public range_query
102 : {
103 : public:
104 : ranger_cache (int not_executable_flag, bool use_imm_uses);
105 : ~ranger_cache ();
106 :
107 : bool range_of_expr (vrange &r, tree name, gimple *stmt) final override;
108 : bool range_on_edge (vrange &r, edge e, tree expr) final override;
109 : bool block_range (vrange &r, basic_block bb, tree name, bool calc = true);
110 :
111 : bool get_global_range (vrange &r, tree name) const;
112 : bool get_global_range (vrange &r, tree name, bool ¤t_p);
113 : void set_global_range (tree name, const vrange &r, bool changed = true);
114 : void update_consumers (tree name);
115 0 : range_query &const_query () { return m_globals; }
116 :
117 : void propagate_updated_value (tree name, basic_block bb);
118 :
119 : void register_inferred_value (const vrange &r, tree name, basic_block bb);
120 : void apply_inferred_ranges (gimple *s);
121 :
122 : void dump_bb (FILE *f, basic_block bb);
123 : virtual void dump (FILE *f) override;
124 : private:
125 : ssa_cache m_globals;
126 : block_range_cache m_on_entry;
127 : class temporal_cache *m_temporal;
128 : void fill_block_cache (tree name, basic_block bb, basic_block def_bb);
129 : void propagate_cache (tree name);
130 :
131 : enum rfd_mode
132 : {
133 : RFD_NONE, // Only look at current block cache.
134 : RFD_READ_ONLY, // Scan DOM tree, do not write to cache.
135 : RFD_FILL // Scan DOM tree, updating important nodes.
136 : };
137 : bool range_from_dom (vrange &r, tree name, basic_block bb, enum rfd_mode);
138 : void resolve_dom (vrange &r, tree name, basic_block bb);
139 : void range_of_def (vrange &r, tree name, basic_block bb = NULL);
140 : void entry_range (vrange &r, tree expr, basic_block bb, enum rfd_mode);
141 : void exit_range (vrange &r, tree expr, basic_block bb, enum rfd_mode);
142 : bool edge_range (vrange &r, edge e, tree name, enum rfd_mode);
143 :
144 : vec<basic_block> m_workback;
145 : class update_list *m_update;
146 : };
147 :
148 : #endif // GCC_SSA_RANGE_CACHE_H
|