diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2020-11-02 13:06:46 -0500 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2020-11-03 10:17:39 -0500 |
commit | 220929c067717605cab96a9c5fe93e2e01532e51 (patch) | |
tree | 8c765d51a3957f50fe64638e064b3a5a9eb23f69 /gcc/gimple-range-cache.cc | |
parent | c2856ceec2e7542fe9b0bf104afeeeeb57d6996d (diff) | |
download | gcc-220929c067717605cab96a9c5fe93e2e01532e51.zip gcc-220929c067717605cab96a9c5fe93e2e01532e51.tar.gz gcc-220929c067717605cab96a9c5fe93e2e01532e51.tar.bz2 |
Tweaks to ranger cache
Add some bounds checking to ssa_block_ranges, and privatize the
ranges block cache and global cache, adding API points for accessing them.
* gimple-range-cache.h (block_range_cache): Add new entry point.
(ranger_cache): Privatize global abnd block cache members.
* gimple-range-cache.cc (ssa_block_ranges::set_bb_range): Add bounds
check.
(ssa_block_ranges::set_bb_varying): Ditto.
(ssa_block_ranges::get_bb_range): Ditto.
(ssa_block_ranges::bb_range_p): Ditto.
(block_range_cache::get_block_ranges): Fix formatting.
(block_range_cache::query_block_ranges): New.
(block_range_cache::get_bb_range): Use Query_block_ranges.
(block_range_cache::bb_range_p): Ditto.
(ranger_cache::dump): New.
(ranger_cache::get_global_range): New.
(ranger_cache::set_global_range): New.
* gimple-range.cc (gimple_ranger::range_of_expr): Use new API.
(gimple_ranger::range_of_stmt): Ditto.
(gimple_ranger::export_global_ranges): Ditto.
(gimple_ranger::dump): Ditto.
Diffstat (limited to 'gcc/gimple-range-cache.cc')
-rw-r--r-- | gcc/gimple-range-cache.cc | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index bc9243c..574debb 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -165,6 +165,7 @@ ssa_block_ranges::~ssa_block_ranges () void ssa_block_ranges::set_bb_range (const basic_block bb, const irange &r) { + gcc_checking_assert ((unsigned) bb->index < m_tab.length ()); irange *m = m_irange_allocator->allocate (r); m_tab[bb->index] = m; } @@ -174,6 +175,7 @@ ssa_block_ranges::set_bb_range (const basic_block bb, const irange &r) void ssa_block_ranges::set_bb_varying (const basic_block bb) { + gcc_checking_assert ((unsigned) bb->index < m_tab.length ()); m_tab[bb->index] = m_type_range; } @@ -183,6 +185,7 @@ ssa_block_ranges::set_bb_varying (const basic_block bb) bool ssa_block_ranges::get_bb_range (irange &r, const basic_block bb) { + gcc_checking_assert ((unsigned) bb->index < m_tab.length ()); irange *m = m_tab[bb->index]; if (m) { @@ -197,6 +200,7 @@ ssa_block_ranges::get_bb_range (irange &r, const basic_block bb) bool ssa_block_ranges::bb_range_p (const basic_block bb) { + gcc_checking_assert ((unsigned) bb->index < m_tab.length ()); return m_tab[bb->index] != NULL; } @@ -244,8 +248,8 @@ block_range_cache::~block_range_cache () m_ssa_ranges.release (); } -// Return a reference to the m_block_cache for NAME. If it has not been -// accessed yet, allocate it. +// Return a reference to the ssa_block_cache for NAME. If it has not been +// accessed yet, allocate it first. ssa_block_ranges & block_range_cache::get_block_ranges (tree name) @@ -255,11 +259,24 @@ block_range_cache::get_block_ranges (tree name) m_ssa_ranges.safe_grow_cleared (num_ssa_names + 1); if (!m_ssa_ranges[v]) - m_ssa_ranges[v] = new ssa_block_ranges (TREE_TYPE (name), m_irange_allocator); - + m_ssa_ranges[v] = new ssa_block_ranges (TREE_TYPE (name), + m_irange_allocator); return *(m_ssa_ranges[v]); } + +// Return a pointer to the ssa_block_cache for NAME. If it has not been +// accessed yet, return NULL. + +ssa_block_ranges * +block_range_cache::query_block_ranges (tree name) +{ + unsigned v = SSA_NAME_VERSION (name); + if (v >= m_ssa_ranges.length () || !m_ssa_ranges[v]) + return NULL; + return m_ssa_ranges[v]; +} + // Set the range for NAME on entry to block BB to R. void @@ -283,7 +300,10 @@ block_range_cache::set_bb_varying (tree name, const basic_block bb) bool block_range_cache::get_bb_range (irange &r, tree name, const basic_block bb) { - return get_block_ranges (name).get_bb_range (r, bb); + ssa_block_ranges *ptr = query_block_ranges (name); + if (ptr) + return ptr->get_bb_range (r, bb); + return false; } // Return true if NAME has a range set in block BB. @@ -291,7 +311,10 @@ block_range_cache::get_bb_range (irange &r, tree name, const basic_block bb) bool block_range_cache::bb_range_p (tree name, const basic_block bb) { - return get_block_ranges (name).bb_range_p (bb); + ssa_block_ranges *ptr = query_block_ranges (name); + if (ptr) + return ptr->bb_range_p (bb); + return false; } // Print all known block caches to file F. @@ -472,6 +495,46 @@ ranger_cache::~ranger_cache () m_update_list.release (); } +// Dump the global caches to file F. if GORI_DUMP is true, dump the +// gori map as well. + +void +ranger_cache::dump (FILE *f, bool gori_dump) +{ + m_globals.dump (f); + if (gori_dump) + { + fprintf (f, "\nDUMPING GORI MAP\n"); + gori_compute::dump (f); + } + fprintf (f, "\n"); +} + +// Dump the caches for basic block BB to file F. + +void +ranger_cache::dump (FILE *f, basic_block bb) +{ + m_on_entry.dump (f, bb); +} + +// Get the global range for NAME, and return in R. Return false if the +// global range is not set. + +bool +ranger_cache::get_global_range (irange &r, tree name) const +{ + return m_globals.get_global_range (r, name); +} + +// Set the global range of NAME to R. + +void +ranger_cache::set_global_range (tree name, const irange &r) +{ + m_globals.set_global_range (name, r); +} + // Push a request for a new lookup in block BB of name. Return true if // the request is actually made (ie, isn't a duplicate). @@ -869,5 +932,4 @@ ranger_cache::fill_block_cache (tree name, basic_block bb, basic_block def_bb) iterative_cache_update (name); } } - } |