1 /* Header file for gimple ranger SSA cache.
2 Copyright (C) 2017-2023 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
27 // This class manages a vector of pointers to ssa_block ranges. It
28 // provides the basis for the "range on entry" cache for all
29 // SSA names.
30
31 class block_range_cache
32 {
33 public:
34 block_range_cache ();
35 ~block_range_cache ();
36
37 bool set_bb_range (tree name, const_basic_block bb, const vrange &v);
38 bool get_bb_range (vrange &v, tree name, const_basic_block bb);
39 bool bb_range_p (tree name, const_basic_block bb);
40
41 void dump (FILE *f);
42 void dump (FILE *f, basic_block bb, bool print_varying = true);
43 private:
44 vec<class ssa_block_ranges *> m_ssa_ranges;
45 ssa_block_ranges &get_block_ranges (tree name);
46 ssa_block_ranges *query_block_ranges (tree name);
47 class vrange_allocator *m_range_allocator;
48 bitmap_obstack m_bitmaps;
49 };
50
51 // This global cache is used with the range engine as markers for what
52 // has been visited during this incarnation. Once the ranger evaluates
53 // a name, it is typically not re-evaluated again.
54
55 class ssa_global_cache
56 {
57 public:
58 ssa_global_cache ();
59 ~ssa_global_cache ();
60 bool get_global_range (vrange &r, tree name) const;
61 bool set_global_range (tree name, const vrange &r);
62 void clear_global_range (tree name);
63 void clear ();
64 void dump (FILE *f = stderr);
65 private:
66 vec<vrange *> m_tab;
67 vrange_allocator *m_range_allocator;
68 };
69
70 // This class provides all the caches a global ranger may need, and makes
71 // them available for gori-computes to query so outgoing edges can be
72 // properly calculated.
73
74 class ranger_cache : public range_query
75 {
76 public:
77 ranger_cache (int not_executable_flag, bool use_imm_uses);
78 ~ranger_cache ();
79
80 bool range_of_expr (vrange &r, tree name, gimple *stmt) final override;
81 bool range_on_edge (vrange &r, edge e, tree expr) final override;
82 bool block_range (vrange &r, basic_block bb, tree name, bool calc = true);
83
84 bool get_global_range (vrange &r, tree name) const;
85 bool get_global_range (vrange &r, tree name, bool ¤t_p);
86 void set_global_range (tree name, const vrange &r);
87
88 void propagate_updated_value (tree name, basic_block bb);
89
90 void register_inferred_value (const vrange &r, tree name, basic_block bb);
91 void apply_inferred_ranges (gimple *s);
92 gori_compute m_gori;
93 infer_range_manager m_exit;
94
95 void dump_bb (FILE *f, basic_block bb);
96 virtual void dump (FILE *f) override;
97 private:
98 ssa_global_cache m_globals;
99 block_range_cache m_on_entry;
100 class temporal_cache *m_temporal;
101 void fill_block_cache (tree name, basic_block bb, basic_block def_bb);
102 void propagate_cache (tree name);
103
104 enum rfd_mode
105 {
106 RFD_NONE, // Only look at current block cache.
107 RFD_READ_ONLY, // Scan DOM tree, do not write to cache.
108 RFD_FILL // Scan DOM tree, updating important nodes.
109 };
110 bool range_from_dom (vrange &r, tree name, basic_block bb, enum rfd_mode);
111 void resolve_dom (vrange &r, tree name, basic_block bb);
112 void range_of_def (vrange &r, tree name, basic_block bb = NULL);
113 void entry_range (vrange &r, tree expr, basic_block bb, enum rfd_mode);
114 void exit_range (vrange &r, tree expr, basic_block bb, enum rfd_mode);
115 bool edge_range (vrange &r, edge e, tree name, enum rfd_mode);
116
117 vec<basic_block> m_workback;
118 class update_list *m_update;
119 };
120
121 #endif // GCC_SSA_RANGE_CACHE_H