CBMC
goto_inline_class.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
14 
15 #ifndef CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
16 #define CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
17 
18 #include <unordered_set>
19 
20 #include <util/message.h>
21 #include <util/json.h>
22 
23 #include "goto_functions.h"
24 
26 {
27 public:
37  const namespacet &ns,
38  message_handlert &message_handler,
39  bool adjust_function,
40  bool caching = true)
41  : log(message_handler),
43  ns(ns),
46  {
47  }
48 
50 
51  // call that should be inlined
52  // false: inline non-transitively
53  // true: inline transitively
54  typedef std::pair<goto_programt::targett, bool> callt;
55 
56  // list of calls that should be inlined
57  typedef std::list<callt> call_listt;
58 
59  // list of calls per function that should be inlined
60  typedef std::map<irep_idt, call_listt> inline_mapt;
61 
62  // handle given goto function
63  // force_full:
64  // - true: put skip on recursion and issue warning
65  // - false: leave call on recursion
66  void goto_inline(
67  const irep_idt identifier,
68  goto_functiont &goto_function,
69  const inline_mapt &inline_map,
70  const bool force_full=false);
71 
72  // handle all functions
73  void goto_inline(
74  const inline_mapt &inline_map,
75  const bool force_full=false);
76 
77  void output_inline_map(
78  std::ostream &out,
79  const inline_mapt &inline_map);
80 
81  void output_cache(std::ostream &out) const;
82 
83  // call after goto_functions.update()!
85  {
88  }
89 
90  // get call info of normal or bp call
91  static void get_call(
93  exprt &lhs,
94  exprt &function,
95  exprt::operandst &arguments);
96 
98  {
99  public:
101  {
102  public:
103  // original segment location numbers
106  unsigned call_location_number; // original call location number
107  irep_idt function; // function from which segment was inlined
109  };
110 
111  // remove segment that refer to the given goto program
112  void cleanup(const goto_programt &goto_program);
113 
114  void cleanup(const goto_functionst::function_mapt &function_map);
115 
116  void add_segment(
117  const goto_programt &goto_program,
118  const unsigned begin_location_number,
119  const unsigned end_location_number,
120  const unsigned call_location_number,
121  const irep_idt function);
122 
123  void copy_from(const goto_programt &from, const goto_programt &to);
124 
125  // call after goto_functions.update()!
127 
128  // map from segment start to inline info
129  typedef std::map<
132 
134  };
135 
136 protected:
139  const namespacet &ns;
140 
141  const bool adjust_function;
142  const bool caching;
143 
145 
147  const irep_idt identifier,
148  goto_functiont &goto_function,
149  const inline_mapt &inline_map,
150  const bool force_full);
151 
153  const irep_idt identifier,
154  const goto_functiont &goto_function,
155  const bool force_full);
156 
157  bool check_inline_map(const inline_mapt &inline_map) const;
158  bool check_inline_map(
159  const irep_idt identifier,
160  const inline_mapt &inline_map) const;
161 
162  bool is_ignored(const irep_idt id) const;
163 
164  void clear()
165  {
166  cache.clear();
167  finished_set.clear();
168  recursion_set.clear();
169  no_body_set.clear();
170  }
171 
173  goto_programt &dest,
174  const inline_mapt &inline_map,
175  const bool transitive,
176  const bool force_full,
177  goto_programt::targett target);
178 
180  const goto_functiont &f,
181  goto_programt &dest,
182  goto_programt::targett target,
183  const exprt &lhs,
184  const symbol_exprt &function,
185  const exprt::operandst &arguments);
186 
187  void replace_return(
188  goto_programt &body,
189  const exprt &lhs);
190 
192  const goto_programt::targett target,
193  const irep_idt &function_name,
194  const goto_functiont::parameter_identifierst &parameter_identifiers,
195  const exprt::operandst &arguments,
196  goto_programt &dest);
197 
199  const goto_programt::targett target,
200  const goto_functiont::parameter_identifierst &parameter_identifiers,
201  goto_programt &dest);
202 
203  // goto functions that were already inlined transitively
206 
207  typedef std::unordered_set<irep_idt> finished_sett;
209 
210  typedef std::unordered_set<irep_idt> recursion_sett;
212 
213  typedef std::unordered_set<irep_idt> no_body_sett;
215 };
216 
217 #endif // CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:154
goto_inlinet::goto_inline_logt::goto_inline_log_infot::begin_location_number
unsigned begin_location_number
Definition: goto_inline_class.h:104
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:36
goto_inlinet::log
messaget log
Definition: goto_inline_class.h:137
goto_inlinet::insert_function_body
void insert_function_body(const goto_functiont &f, goto_programt &dest, goto_programt::targett target, const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments)
Definition: goto_inline_class.cpp:213
goto_inlinet::output_inline_log_json
jsont output_inline_log_json()
Definition: goto_inline_class.h:84
goto_inlinet::call_listt
std::list< callt > call_listt
Definition: goto_inline_class.h:57
goto_inlinet::goto_inline_logt::add_segment
void add_segment(const goto_programt &goto_program, const unsigned begin_location_number, const unsigned end_location_number, const unsigned call_location_number, const irep_idt function)
Definition: goto_inline_class.cpp:744
goto_inlinet::goto_inline_logt::goto_inline_log_infot::call_location_number
unsigned call_location_number
Definition: goto_inline_class.h:106
goto_inlinet::replace_return
void replace_return(goto_programt &body, const exprt &lhs)
Definition: goto_inline_class.cpp:150
goto_inlinet::get_call
static void get_call(goto_programt::const_targett target, exprt &lhs, exprt &function, exprt::operandst &arguments)
Definition: goto_inline_class.cpp:431
goto_inlinet::recursion_sett
std::unordered_set< irep_idt > recursion_sett
Definition: goto_inline_class.h:210
exprt
Base class for all expressions.
Definition: expr.h:55
goto_inlinet::goto_inline
void goto_inline(const irep_idt identifier, goto_functiont &goto_function, const inline_mapt &inline_map, const bool force_full=false)
Inline all of the chosen calls in a given function.
Definition: goto_inline_class.cpp:475
goto_inlinet::goto_inline_logt::cleanup
void cleanup(const goto_programt &goto_program)
Definition: goto_inline_class.cpp:723
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:112
goto_inlinet::goto_inline_logt::goto_inline_log_infot::end_location_number
unsigned end_location_number
Definition: goto_inline_class.h:105
jsont
Definition: json.h:26
goto_inlinet::callt
std::pair< goto_programt::targett, bool > callt
Definition: goto_inline_class.h:54
goto_inlinet::goto_inline_logt
Definition: goto_inline_class.h:97
goto_inlinet::adjust_function
const bool adjust_function
Definition: goto_inline_class.h:141
goto_inlinet::no_body_set
no_body_sett no_body_set
Definition: goto_inline_class.h:214
goto_inlinet::goto_inline_nontransitive
void goto_inline_nontransitive(const irep_idt identifier, goto_functiont &goto_function, const inline_mapt &inline_map, const bool force_full)
Definition: goto_inline_class.cpp:490
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:90
goto_inlinet::recursion_set
recursion_sett recursion_set
Definition: goto_inline_class.h:211
goto_inlinet::cachet
goto_functionst::function_mapt cachet
Definition: goto_inline_class.h:204
goto_inlinet::clear
void clear()
Definition: goto_inline_class.h:164
goto_functionst::function_mapt
std::map< irep_idt, goto_functiont > function_mapt
Definition: goto_functions.h:28
goto_inlinet::goto_inline_logt::log_mapt
std::map< goto_programt::const_targett, goto_inline_log_infot > log_mapt
Definition: goto_inline_class.h:131
goto_inlinet::goto_inline_logt::output_inline_log_json
jsont output_inline_log_json() const
Definition: goto_inline_class.cpp:819
goto_inlinet::caching
const bool caching
Definition: goto_inline_class.h:142
goto_inlinet::no_body_sett
std::unordered_set< irep_idt > no_body_sett
Definition: goto_inline_class.h:213
goto_inlinet::goto_inline_logt::log_map
log_mapt log_map
Definition: goto_inline_class.h:133
goto_inlinet::goto_inlinet
goto_inlinet(goto_functionst &goto_functions, const namespacet &ns, message_handlert &message_handler, bool adjust_function, bool caching=true)
Sets up the class with the program to operate on.
Definition: goto_inline_class.h:35
goto_inlinet::cache
cachet cache
Definition: goto_inline_class.h:205
goto_inlinet::parameter_destruction
void parameter_destruction(const goto_programt::targett target, const goto_functiont::parameter_identifierst &parameter_identifiers, goto_programt &dest)
Definition: goto_inline_class.cpp:124
goto_inlinet::goto_inline_logt::goto_inline_log_infot::end
goto_programt::const_targett end
Definition: goto_inline_class.h:108
message_handlert
Definition: message.h:27
goto_inlinet::goto_functions
goto_functionst & goto_functions
Definition: goto_inline_class.h:138
goto_inlinet::ns
const namespacet & ns
Definition: goto_inline_class.h:139
goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:23
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:58
goto_inlinet::finished_sett
std::unordered_set< irep_idt > finished_sett
Definition: goto_inline_class.h:207
goto_inlinet::goto_inline_logt::goto_inline_log_infot
Definition: goto_inline_class.h:100
goto_inlinet::output_inline_map
void output_inline_map(std::ostream &out, const inline_mapt &inline_map)
Definition: goto_inline_class.cpp:670
goto_inlinet::inline_mapt
std::map< irep_idt, call_listt > inline_mapt
Definition: goto_inline_class.h:60
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:27
goto_inlinet::parameter_assignments
void parameter_assignments(const goto_programt::targett target, const irep_idt &function_name, const goto_functiont::parameter_identifierst &parameter_identifiers, const exprt::operandst &arguments, goto_programt &dest)
Definition: goto_inline_class.cpp:23
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:24
goto_inlinet::finished_set
finished_sett finished_set
Definition: goto_inline_class.h:208
goto_inlinet::goto_inline_transitive
const goto_functiont & goto_inline_transitive(const irep_idt identifier, const goto_functiont &goto_function, const bool force_full)
Definition: goto_inline_class.cpp:542
goto_inlinet::expand_function_call
void expand_function_call(goto_programt &dest, const inline_mapt &inline_map, const bool transitive, const bool force_full, goto_programt::targett target)
Inlines a single function call Calls out to goto_inline_transitive or goto_inline_nontransitive.
Definition: goto_inline_class.cpp:301
json.h
goto_inlinet::check_inline_map
bool check_inline_map(const inline_mapt &inline_map) const
Definition: goto_inline_class.cpp:659
goto_functions.h
goto_inlinet::inline_log
goto_inline_logt inline_log
Definition: goto_inline_class.h:144
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:72
goto_functiont::parameter_identifierst
std::vector< irep_idt > parameter_identifierst
Definition: goto_function.h:28
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition: goto_program.h:587
goto_inlinet::is_ignored
bool is_ignored(const irep_idt id) const
Definition: goto_inline_class.cpp:604
message.h
goto_inlinet::goto_inline_logt::copy_from
void copy_from(const goto_programt &from, const goto_programt &to)
Definition: goto_inline_class.cpp:773
goto_inlinet::output_cache
void output_cache(std::ostream &out) const
Definition: goto_inline_class.cpp:711
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:586
goto_inlinet
Definition: goto_inline_class.h:25
goto_inlinet::goto_functiont
goto_functionst::goto_functiont goto_functiont
Definition: goto_inline_class.h:49