Line data Source code
1 : /* Classes for working with summaries of function calls.
2 : Copyright (C) 2022 David Malcolm <dmalcolm@redhat.com>.
3 :
4 : This file is part of GCC.
5 :
6 : GCC is free software; you can redistribute it and/or modify it
7 : under the terms of the GNU General Public License as published by
8 : the Free Software Foundation; either version 3, or (at your option)
9 : any later version.
10 :
11 : GCC is distributed in the hope that it will be useful, but
12 : WITHOUT ANY WARRANTY; without even the implied warranty of
13 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : General Public License for more details.
15 :
16 : You should have received a copy of the GNU General Public License
17 : along with GCC; see the file COPYING3. If not see
18 : <http://www.gnu.org/licenses/>. */
19 :
20 : #ifndef GCC_ANALYZER_CALL_SUMMARY_H
21 : #define GCC_ANALYZER_CALL_SUMMARY_H
22 :
23 : #include "call-details.h"
24 :
25 : namespace ana {
26 :
27 : /* A class summarizing one particular outcome of a function that
28 : we've already analyzed.
29 : This lets us efficiently replay the analysis when we see calls
30 : to the function, providing an approximation of the behavior of
31 : the function without having to execute within the function itself. */
32 :
33 : class call_summary
34 : {
35 : public:
36 632 : call_summary (per_function_data *per_fn_data,
37 : const exploded_node *enode)
38 632 : : m_per_fn_data (per_fn_data),
39 632 : m_enode (enode)
40 : {}
41 : const program_state &get_state () const;
42 : tree get_fndecl () const;
43 :
44 : label_text get_desc () const;
45 :
46 : void dump_to_pp (const extrinsic_state &ext_state,
47 : pretty_printer *pp,
48 : bool simple) const;
49 : void dump (const extrinsic_state &ext_state, FILE *fp, bool simple) const;
50 : void dump (const extrinsic_state &ext_state, bool simple) const;
51 :
52 : private:
53 : void get_user_facing_desc (pretty_printer *pp) const;
54 :
55 : per_function_data *const m_per_fn_data;
56 : const exploded_node *const m_enode;
57 : };
58 :
59 : /* A class for handling replaying a specific call summary at
60 : a specific call site.
61 :
62 : Supports remapping svalues and regions, e.g. remapping
63 : INIT_VAL(param of callee)
64 : to:
65 : whatever that argument is at the call site. */
66 :
67 1629 : class call_summary_replay
68 : {
69 : public:
70 : call_summary_replay (const call_details &cd,
71 : const function &called_fn,
72 : call_summary &summary,
73 : const extrinsic_state &ext_state);
74 :
75 12368 : const call_details &get_call_details () const { return m_cd; }
76 40 : const gcall &get_call_stmt () const { return m_cd.get_call_stmt (); }
77 32220 : region_model_manager *get_manager () const { return m_cd.get_manager (); }
78 40 : store_manager *get_store_manager () const
79 : {
80 40 : return get_manager ()->get_store_manager ();
81 : }
82 4362 : region_model_context *get_ctxt () const { return m_cd.get_ctxt (); }
83 4636 : region_model *get_caller_model () const { return m_cd.get_model (); }
84 :
85 : const svalue *convert_svalue_from_summary (const svalue *);
86 : const region *convert_region_from_summary (const region *);
87 : const binding_key *convert_key_from_summary (const binding_key *);
88 :
89 : void add_svalue_mapping (const svalue *summary_sval,
90 : const svalue *caller_sval);
91 : void add_region_mapping (const region *summary_sval,
92 : const region *caller_sval);
93 :
94 : void dump_to_pp (pretty_printer *pp, bool simple) const;
95 : void dump (FILE *fp, bool simple) const;
96 : void dump (bool simple) const;
97 :
98 : private:
99 : DISABLE_COPY_AND_ASSIGN (call_summary_replay);
100 :
101 : const svalue *convert_svalue_from_summary_1 (const svalue *);
102 : const region *convert_region_from_summary_1 (const region *);
103 :
104 : const call_details &m_cd;
105 : call_summary &m_summary;
106 : const extrinsic_state &m_ext_state;
107 :
108 : // Mapping from svalues in summary to svalues for callsite:
109 : typedef hash_map <const svalue *, const svalue *> svalue_map_t;
110 : svalue_map_t m_map_svalue_from_summary_to_caller;
111 :
112 : // Mapping from regions in summary to regions for callsite:
113 : typedef hash_map <const region *, const region *> region_map_t;
114 : region_map_t m_map_region_from_summary_to_caller;
115 : };
116 :
117 : } // namespace ana
118 :
119 : #endif /* GCC_ANALYZER_CALL_SUMMARY_H */
|