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 442 : call_summary (per_function_data *per_fn_data,
37 : const exploded_node *enode)
38 442 : : m_per_fn_data (per_fn_data),
39 442 : 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_logger (logger &) const;
47 : void dump () const;
48 :
49 : std::unique_ptr<text_art::tree_widget>
50 : make_dump_widget (symbolic::node_dump_state &nds) 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 677 : 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 1775 : 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 5496 : region_model_manager *get_manager () const { return m_cd.get_manager (); }
78 1083 : region_model_context *get_ctxt () const { return m_cd.get_ctxt (); }
79 4818 : region_model *get_caller_model () const { return m_cd.get_model (); }
80 :
81 234 : const extrinsic_state &get_ext_state () const { return m_ext_state; }
82 :
83 : const svalue *convert_svalue_from_summary (const svalue *);
84 : const region *convert_region_from_summary (const region *);
85 :
86 : const symbolic::bit_contents *
87 : convert_bit_contents_from_summary (const symbolic::bit_contents &);
88 :
89 : const symbolic::bit_vector *
90 : convert_bit_vector_from_summary (const symbolic::bit_vector &);
91 :
92 : template <typename ConcreteValueType>
93 : const symbolic::scalar<ConcreteValueType> *
94 : convert_scalar_from_summary (const symbolic::scalar<ConcreteValueType> &);
95 :
96 : void add_svalue_mapping (const svalue *summary_sval,
97 : const svalue *caller_sval);
98 : void add_region_mapping (const region *summary_sval,
99 : const region *caller_sval);
100 :
101 : void dump_to_logger (logger &) const;
102 : void dump () const;
103 :
104 : std::unique_ptr<text_art::tree_widget>
105 : make_dump_widget (symbolic::node_dump_state &nds) const;
106 :
107 : private:
108 : DISABLE_COPY_AND_ASSIGN (call_summary_replay);
109 :
110 : const svalue *convert_svalue_from_summary_1 (const svalue *);
111 : const region *convert_region_from_summary_1 (const region *);
112 :
113 : template <typename ConcreteValueType>
114 : const symbolic::scalar<ConcreteValueType> *
115 : impl_bits_from_bytes (const symbolic::scalar<ConcreteValueType> &summary_scalar);
116 :
117 : const call_details &m_cd;
118 : call_summary &m_summary;
119 : const extrinsic_state &m_ext_state;
120 :
121 : // Mapping from svalues in summary to svalues for callsite:
122 : typedef hash_map <const svalue *, const svalue *> svalue_map_t;
123 : svalue_map_t m_map_svalue_from_summary_to_caller;
124 :
125 : // Mapping from regions in summary to regions for callsite:
126 : typedef hash_map <const region *, const region *> region_map_t;
127 : region_map_t m_map_region_from_summary_to_caller;
128 : };
129 :
130 : } // namespace ana
131 :
132 : #endif /* GCC_ANALYZER_CALL_SUMMARY_H */
|