1 /* Classes for purging state at function_points.
2 Copyright (C) 2019-2020 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
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/>. */
21 #ifndef GCC_ANALYZER_STATE_PURGE_H
22 #define GCC_ANALYZER_STATE_PURGE_H
24 /* Hash traits for function_point. */
26 template <> struct default_hash_traits
<function_point
>
27 : public pod_hash_traits
<function_point
>
29 static const bool empty_zero_p
= false;
34 pod_hash_traits
<function_point
>::hash (value_type v
)
41 pod_hash_traits
<function_point
>::equal (const value_type
&existing
,
42 const value_type
&candidate
)
44 return existing
== candidate
;
48 pod_hash_traits
<function_point
>::mark_deleted (value_type
&v
)
50 v
= function_point::deleted ();
54 pod_hash_traits
<function_point
>::mark_empty (value_type
&v
)
56 v
= function_point::empty ();
60 pod_hash_traits
<function_point
>::is_deleted (value_type v
)
62 return v
.get_kind () == PK_DELETED
;
66 pod_hash_traits
<function_point
>::is_empty (value_type v
)
68 return v
.get_kind () == PK_EMPTY
;
71 /* The result of analyzing which SSA names can be purged from state at
72 different points in the program, so that we can simplify program_state
73 objects, in the hope of reducing state-blowup. */
75 class state_purge_map
: public log_user
78 typedef ordered_hash_map
<tree
, state_purge_per_ssa_name
*> map_t
;
79 typedef map_t::iterator iterator
;
81 state_purge_map (const supergraph
&sg
, logger
*logger
);
84 const state_purge_per_ssa_name
&get_data_for_ssa_name (tree name
) const
86 gcc_assert (TREE_CODE (name
) == SSA_NAME
);
87 if (tree var
= SSA_NAME_VAR (name
))
88 if (TREE_CODE (var
) == VAR_DECL
)
89 gcc_assert (!VAR_DECL_IS_VIRTUAL_OPERAND (var
));
91 state_purge_per_ssa_name
**slot
92 = const_cast <map_t
&> (m_map
).get (name
);
96 const supergraph
&get_sg () const { return m_sg
; }
98 iterator
begin () const { return m_map
.begin (); }
99 iterator
end () const { return m_map
.end (); }
102 DISABLE_COPY_AND_ASSIGN (state_purge_map
);
104 const supergraph
&m_sg
;
108 /* The part of a state_purge_map relating to a specific SSA name.
110 The result of analyzing a given SSA name, recording which
111 function_points need to retain state information about it to handle
112 their successor states, so that we can simplify program_state objects,
113 in the hope of reducing state-blowup. */
115 class state_purge_per_ssa_name
118 state_purge_per_ssa_name (const state_purge_map
&map
,
122 bool needed_at_point_p (const function_point
&point
) const;
124 function
*get_function () const { return m_fun
; }
127 static function_point
before_use_stmt (const state_purge_map
&map
,
128 const gimple
*use_stmt
);
130 void add_to_worklist (const function_point
&point
,
131 auto_vec
<function_point
> *worklist
,
134 void process_point (const function_point
&point
,
135 auto_vec
<function_point
> *worklist
,
136 const state_purge_map
&map
);
138 typedef hash_set
<function_point
> point_set_t
;
139 point_set_t m_points_needing_name
;
144 /* Subclass of dot_annotator for use by -fdump-analyzer-state-purge.
145 Annotate the .dot output with state-purge information. */
147 class state_purge_annotator
: public dot_annotator
150 state_purge_annotator (const state_purge_map
*map
) : m_map (map
) {}
152 void add_node_annotations (graphviz_out
*gv
, const supernode
&n
)
153 const FINAL OVERRIDE
;
155 void add_stmt_annotations (graphviz_out
*gv
, const gimple
*stmt
)
156 const FINAL OVERRIDE
;
159 const state_purge_map
*m_map
;
162 #endif /* GCC_ANALYZER_STATE_PURGE_H */