diff options
author | David Malcolm <dmalcolm@redhat.com> | 2023-06-09 17:58:33 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-06-09 17:58:33 -0400 |
commit | fe9771b59f576fb37e762013ef5d9b26162e3a88 (patch) | |
tree | b4fd74fa4aad827adca16432c35bdbeeef9f0064 /gcc/analyzer/region-model.cc | |
parent | 067a8c7cb897b6a1ea5b1d26df8e89ccc7f0659c (diff) | |
download | gcc-fe9771b59f576fb37e762013ef5d9b26162e3a88.zip gcc-fe9771b59f576fb37e762013ef5d9b26162e3a88.tar.gz gcc-fe9771b59f576fb37e762013ef5d9b26162e3a88.tar.bz2 |
analyzer: add caching to globals with initializers [PR110112]
PR analyzer/110112 notes that -fanalyzer is extremely slow on a source
file with large read-only static arrays, repeatedly building the
same compound_svalue representing the full initializer, and repeatedly
building svalues representing parts of the the full initialiazer.
This patch adds caches for both of these; together they reduce the time
taken by -fanalyzer -O2 on the testcase in the bug for an optimized
build:
91.2s : no caches (status quo)
32.4s : cache in decl_region::get_svalue_for_constructor
3.7s : cache in region::get_initial_value_at_main
3.1s : both caches (this patch)
gcc/analyzer/ChangeLog:
PR analyzer/110112
* region-model.cc (region_model::get_initial_value_for_global):
Move code to region::calc_initial_value_at_main.
* region.cc (region::get_initial_value_at_main): New function.
(region::calc_initial_value_at_main): New function, based on code
in region_model::get_initial_value_for_global.
(region::region): Initialize m_cached_init_sval_at_main.
(decl_region::get_svalue_for_constructor): Add a cache, splitting
out body to...
(decl_region::calc_svalue_for_constructor): ...this new function.
* region.h (region::get_initial_value_at_main): New decl.
(region::calc_initial_value_at_main): New decl.
(region::m_cached_init_sval_at_main): New field.
(decl_region::decl_region): Initialize m_ctor_svalue.
(decl_region::calc_svalue_for_constructor): New decl.
(decl_region::m_ctor_svalue): New field.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer/region-model.cc')
-rw-r--r-- | gcc/analyzer/region-model.cc | 25 |
1 files changed, 1 insertions, 24 deletions
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index fb96cd5..b11cc6c 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -2355,30 +2355,7 @@ region_model::get_initial_value_for_global (const region *reg) const the initial value of REG can be taken from the initialization value of the decl. */ if (called_from_main_p () || TREE_READONLY (decl)) - { - /* Attempt to get the initializer value for base_reg. */ - if (const svalue *base_reg_init - = base_reg->get_svalue_for_initializer (m_mgr)) - { - if (reg == base_reg) - return base_reg_init; - else - { - /* Get the value for REG within base_reg_init. */ - binding_cluster c (base_reg); - c.bind (m_mgr->get_store_manager (), base_reg, base_reg_init); - const svalue *sval - = c.get_any_binding (m_mgr->get_store_manager (), reg); - if (sval) - { - if (reg->get_type ()) - sval = m_mgr->get_or_create_cast (reg->get_type (), - sval); - return sval; - } - } - } - } + return reg->get_initial_value_at_main (m_mgr); /* Otherwise, return INIT_VAL(REG). */ return m_mgr->get_or_create_initial_value (reg); |