aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer/program-point.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2022-06-24 13:44:48 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2022-06-24 13:44:48 -0400
commitbb8e93eb1acae30a5fbe7e13149493ce4ccd301a (patch)
tree85dff9a3f4aed9dc9fd2c6c4a2bf477760cfaa5c /gcc/analyzer/program-point.h
parent3752e21d8c180b197e33006b048eff812adfb4e1 (diff)
downloadgcc-bb8e93eb1acae30a5fbe7e13149493ce4ccd301a.zip
gcc-bb8e93eb1acae30a5fbe7e13149493ce4ccd301a.tar.gz
gcc-bb8e93eb1acae30a5fbe7e13149493ce4ccd301a.tar.bz2
analyzer: consolidate call_string instances
ana::call_string is a wrapper around an auto_vec of callsites, leading to non-trivial copying when copying around call_string instances, e.g. in ana::program_point. This patch consolidates call_string instances within the region_model_manager: it now owns the root/empty call_string, and each call_string instance tracks its children, lazily creating them on demand, so that the call_string instances form a tree-like hierarchy in memory. Doing this requires passing the region_model_manager to the various program_point factory methods, so that they can get at the root call_string. Instances of call_string become immutable (apart from their internal cache for looking up their children); operations that previously modified them now return the call_string for the result of the operation. I wasn't able to observe any performance impact of this, but it simplifies call_string and program_point management, and thus I hope will make it easier to improve call summarization. In particular, region_model_manager::log_stats will now print a hierarchical dump of all the call_string instances used in the analysis (in -fdump-analyzer and -fdump-analyzer-stderr). gcc/analyzer/ChangeLog: * call-string.cc: Add includes of "analyzer/analyzer.h" and "analyzer/analyzer-logging.h". (call_string::call_string): Delete copy ctor. (call_string::operator=): Delete. (call_string::operator==): Delete. (call_string::hash): Delete. (call_string::push_call): Make const, returning the resulting call_string. (call_string::pop): Delete. (call_string::cmp_ptr_ptr): New. (call_string::validate): Assert that m_parent is non-NULL, or m_elements is empty. (call_string::call_string): Move default ctor here from call-string.h and reimplement. Add ctor taking a parent and an element. (call_string::~call_string): New. (call_string::recursive_log): New. * call-string.h (call_string::call_string): Move default ctor's defn to call-string.cc. Delete copy ctor. Add ctor taking a parent and an element. (call_string::operator=): Delete. (call_string::operator==): Delete. (call_string::hash): Delete. (call_string::push_call): Make const, returning the resulting call_string. (call_string::pop): Delete decl. (call_string::get_parent): New. (call_string::cmp_ptr_ptr): New decl. (call_string::get_top_of_stack): New. (struct call_string::hashmap_traits_t): New. (class call_string): Add friend class region_model_manager. Add DISABLE_COPY_AND_ASSIGN. (call_string::~call_string): New decl. (call_string::recursive_log): New decl. (call_string::m_parent): New field. (call_string::m_children): New field. * constraint-manager.cc (selftest::test_many_constants): Pass model manager to program_point::origin. * engine.cc (exploded_graph::exploded_graph): Likewise. (exploded_graph::add_function_entry): Likewise for program_point::from_function_entry. (add_tainted_args_callback): Likewise. (exploded_graph::maybe_process_run_of_before_supernode_enodes): Update for change to program_point.get_call_string. (exploded_graph::process_node): Likewise. (class function_call_string_cluster): Convert m_cs from a call_string to a const call_string &. (struct function_call_string): Likewise. (pod_hash_traits<function_call_string>::hash): Use pointer_hash for m_cs. (pod_hash_traits<function_call_string>::equal): Update for change to m_cs. (root_cluster::add_node): Update for change to function_call_string. (viz_callgraph_node::dump_dot): Update for change to call_string. * exploded-graph.h (per_call_string_data::m_key): Convert to a reference. (struct eg_call_string_hash_map_traits): Delete. (exploded_graph::call_string_data_map_t): Remove traits class. * program-point.cc: Move include of "analyzer/call-string.h" to after "analyzer/analyzer-logging.h". (program_point::print): Update for conversion of m_call_string to a pointer. (program_point::to_json): Likewise. (program_point::push_to_call_stack): Update for immutability of call strings. (program_point::pop_from_call_stack): Likewise. (program_point::hash): Use pointer hashing for m_call_string. (program_point::get_function_at_depth): Update for change to m_call_string. (program_point::validate): Update for changes to call_string. (program_point::on_edge): Likewise. (program_point::origin): Move here from call-string.h. Add region_model_manager param and use it to get empty call string. (program_point::from_function_entry): Likewise. (selftest::test_function_point_ordering): Likewise. (selftest::test_function_point_ordering): Likewise. * program-point.h (program_point::program_point): Update for change to m_call_string. (program_point::get_call_string): Likewise. (program_point::get_stack_depth): Likewise. (program_point::origin): Add region_model_manager param, and move defn to call-string.cc. (program_point::from_function_entry): Likewise. (program_point::empty): Drop call_string. (program_point::deleted): Likewise. (program_point::program_point): New private ctor. (program_point::m_call_string): Convert from call_string to const call_string *. * program-state.cc (selftest::test_program_state_merging): Update for call_string changes. (selftest::test_program_state_merging_2): Likewise. * region-model-manager.cc (region_model_manager::region_model_manager): Construct m_empty_call_string. (region_model_manager::log_stats): Log the call strings. * region-model.cc (assert_region_models_merge): Pass the region_model_manager when creating program_point instances. (selftest::test_state_merging): Likewise. (selftest::test_constraint_merging): Likewise. (selftest::test_widening_constraints): Likewise. (selftest::test_iteration_1): Likewise. * region-model.h (region_model_manager::get_empty_call_string): New. (region_model_manager::m_empty_call_string): New. * sm-signal.cc (register_signal_handler::impl_transition): Update for changes to call_string. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer/program-point.h')
-rw-r--r--gcc/analyzer/program-point.h35
1 files changed, 16 insertions, 19 deletions
diff --git a/gcc/analyzer/program-point.h b/gcc/analyzer/program-point.h
index 6084c9e..63f7224 100644
--- a/gcc/analyzer/program-point.h
+++ b/gcc/analyzer/program-point.h
@@ -174,7 +174,7 @@ public:
program_point (const function_point &fn_point,
const call_string &call_string)
: m_function_point (fn_point),
- m_call_string (call_string)
+ m_call_string (&call_string)
{
}
@@ -197,7 +197,7 @@ public:
/* Accessors. */
const function_point &get_function_point () const { return m_function_point; }
- const call_string &get_call_string () const { return m_call_string; }
+ const call_string &get_call_string () const { return *m_call_string; }
const supernode *get_supernode () const
{
@@ -242,23 +242,14 @@ public:
{
if (get_kind () == PK_ORIGIN)
return 0;
- return m_call_string.length () + 1;
+ return get_call_string ().length () + 1;
}
/* Factory functions for making various kinds of program_point. */
- static program_point origin ()
- {
- return program_point (function_point (NULL, NULL,
- 0, PK_ORIGIN),
- call_string ());
- }
-
- static program_point from_function_entry (const supergraph &sg,
- function *fun)
- {
- return program_point (function_point::from_function_entry (sg, fun),
- call_string ());
- }
+ static program_point origin (const region_model_manager &mgr);
+ static program_point from_function_entry (const region_model_manager &mgr,
+ const supergraph &sg,
+ function *fun);
static program_point before_supernode (const supernode *supernode,
const superedge *from_edge,
@@ -288,11 +279,11 @@ public:
static program_point empty ()
{
- return program_point (function_point::empty (), call_string ());
+ return program_point (function_point::empty ());
}
static program_point deleted ()
{
- return program_point (function_point::deleted (), call_string ());
+ return program_point (function_point::deleted ());
}
bool on_edge (exploded_graph &eg, const superedge *succ);
@@ -306,8 +297,14 @@ public:
program_point get_next () const;
private:
+ program_point (const function_point &fn_point)
+ : m_function_point (fn_point),
+ m_call_string (NULL)
+ {
+ }
+
function_point m_function_point;
- call_string m_call_string;
+ const call_string *m_call_string;
};
} // namespace ana