1 /* Header file for gimple ranger SSA cache. 2 Copyright (C) 2017-2021 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 26 // Class used to track non-null references of an SSA name. A vector 27 // of bitmaps indexed by SSA name is maintained. When indexed by 28 // basic block, an on-bit indicates there is a non-null dereference 29 // for that SSA in that block. 30 31 class non_null_ref 32 { 33 public: 34 non_null_ref (); 35 ~non_null_ref (); 36 bool non_null_deref_p (tree name, basic_block bb); 37 private: 38 vec <bitmap> m_nn; 39 void process_name (tree name); 40 bitmap_obstack m_bitmaps; 41 }; 42 43 // This class manages a vector of pointers to ssa_block ranges. It 44 // provides the basis for the "range on entry" cache for all 45 // SSA names. 46 47 class block_range_cache 48 { 49 public: 50 block_range_cache (); 51 ~block_range_cache (); 52 53 bool set_bb_range (tree name, const basic_block bb, const irange &r); 54 bool get_bb_range (irange &r, tree name, const basic_block bb); 55 bool bb_range_p (tree name, const basic_block bb); 56 57 void dump (FILE *f); 58 void dump (FILE *f, basic_block bb, bool print_varying = true); 59 private: 60 vec<class ssa_block_ranges *> m_ssa_ranges; 61 ssa_block_ranges &get_block_ranges (tree name); 62 ssa_block_ranges *query_block_ranges (tree name); 63 irange_allocator *m_irange_allocator; 64 bitmap_obstack m_bitmaps; 65 }; 66 67 // This global cache is used with the range engine as markers for what 68 // has been visited during this incarnation. Once the ranger evaluates 69 // a name, it is typically not re-evaluated again. 70 71 class ssa_global_cache 72 { 73 public: 74 ssa_global_cache (); 75 ~ssa_global_cache (); 76 bool get_global_range (irange &r, tree name) const; 77 bool set_global_range (tree name, const irange &r); 78 void clear_global_range (tree name); 79 void clear (); 80 void dump (FILE *f = stderr); 81 private: 82 vec<irange *> m_tab; 83 class irange_allocator *m_irange_allocator; 84 }; 85 86 // This class provides all the caches a global ranger may need, and makes 87 // them available for gori-computes to query so outgoing edges can be 88 // properly calculated. 89 90 class ranger_cache : public gori_compute 91 { 92 public: 93 ranger_cache (class gimple_ranger &q); 94 ~ranger_cache (); 95 96 virtual void ssa_range_in_bb (irange &r, tree name, basic_block bb); 97 bool block_range (irange &r, basic_block bb, tree name, bool calc = true); 98 99 bool get_global_range (irange &r, tree name) const; 100 bool get_non_stale_global_range (irange &r, tree name); 101 void set_global_range (tree name, const irange &r); 102 void register_dependency (tree name, tree dep); 103 104 non_null_ref m_non_null; 105 106 void dump (FILE *f, bool dump_gori = true); 107 void dump (FILE *f, basic_block bb); 108 private: 109 ssa_global_cache m_globals; 110 block_range_cache m_on_entry; 111 class temporal_cache *m_temporal; 112 void add_to_update (basic_block bb); 113 void fill_block_cache (tree name, basic_block bb, basic_block def_bb); 114 void propagate_cache (tree name); 115 116 void propagate_updated_value (tree name, basic_block bb); 117 118 bitmap m_propfail; 119 vec<basic_block> m_workback; 120 vec<basic_block> m_update_list; 121 122 // Iterative "poor value" calculations. 123 struct update_record 124 { 125 basic_block bb; // Block which value needs to be calculated in. 126 tree calc; // SSA_NAME which needs its value calculated. 127 }; 128 bool push_poor_value (basic_block bb, tree name); 129 vec<update_record> m_poor_value_list; 130 class gimple_ranger &query; 131 }; 132 133 #endif // GCC_SSA_RANGE_CACHE_H 134