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 
77  void goto_inline(
78  const goto_inlinet::call_listt &call_list,
79  goto_programt &goto_program,
80  const bool force_full = false);
81 
82  // handle all functions
83  void goto_inline(
84  const inline_mapt &inline_map,
85  const bool force_full=false);
86 
87  void output_inline_map(
88  std::ostream &out,
89  const inline_mapt &inline_map);
90 
91  void output_cache(std::ostream &out) const;
92 
93  // call after goto_functions.update()!
95  {
98  }
99 
100  // get call info of normal or bp call
101  static void get_call(
103  exprt &lhs,
104  exprt &function,
105  exprt::operandst &arguments);
106 
108  {
109  public:
111  {
112  public:
113  // original segment location numbers
116  unsigned call_location_number; // original call location number
117  irep_idt function; // function from which segment was inlined
119  };
120 
121  // remove segment that refer to the given goto program
122  void cleanup(const goto_programt &goto_program);
123 
124  void cleanup(const goto_functionst::function_mapt &function_map);
125 
126  void add_segment(
127  const goto_programt &goto_program,
128  const unsigned begin_location_number,
129  const unsigned end_location_number,
130  const unsigned call_location_number,
131  const irep_idt function);
132 
133  void copy_from(const goto_programt &from, const goto_programt &to);
134 
135  // call after goto_functions.update()!
137 
138  // map from segment start to inline info
139  typedef std::map<
144 
146  };
147 
148 protected:
151  const namespacet &ns;
152 
153  const bool adjust_function;
154  const bool caching;
155 
157 
159  const irep_idt identifier,
160  goto_functiont &goto_function,
161  const inline_mapt &inline_map,
162  const bool force_full);
163 
165  const irep_idt identifier,
166  const goto_functiont &goto_function,
167  const bool force_full);
168 
169  bool check_inline_map(const inline_mapt &inline_map) const;
170  bool check_inline_map(
171  const irep_idt identifier,
172  const inline_mapt &inline_map) const;
173 
174  bool is_ignored(const irep_idt id) const;
175 
176  void clear()
177  {
178  cache.clear();
179  finished_set.clear();
180  recursion_set.clear();
181  no_body_set.clear();
182  }
183 
185  goto_programt &dest,
186  const inline_mapt &inline_map,
187  const bool transitive,
188  const bool force_full,
189  goto_programt::targett target);
190 
192  const goto_functiont &f,
193  goto_programt &dest,
194  goto_programt::targett target,
195  const exprt &lhs,
196  const symbol_exprt &function,
197  const exprt::operandst &arguments);
198 
199  void replace_return(
200  goto_programt &body,
201  const exprt &lhs);
202 
204  const goto_programt::targett target,
205  const irep_idt &function_name,
206  const goto_functiont::parameter_identifierst &parameter_identifiers,
207  const exprt::operandst &arguments,
208  goto_programt &dest);
209 
211  const goto_programt::targett target,
212  const goto_functiont::parameter_identifierst &parameter_identifiers,
213  goto_programt &dest);
214 
215  // goto functions that were already inlined transitively
218 
219  typedef std::unordered_set<irep_idt> finished_sett;
221 
222  typedef std::unordered_set<irep_idt> recursion_sett;
224 
225  typedef std::unordered_set<irep_idt> no_body_sett;
227 };
228 
229 #endif // CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:38
Base class for all expressions.
Definition: expr.h:56
std::vector< exprt > operandst
Definition: expr.h:58
A collection of goto functions.
std::map< irep_idt, goto_functiont > function_mapt
::goto_functiont goto_functiont
A goto function, consisting of function body (see body) and parameter identifiers (see parameter_iden...
Definition: goto_function.h:24
std::vector< irep_idt > parameter_identifierst
Definition: goto_function.h:28
void copy_from(const goto_programt &from, const goto_programt &to)
std::map< goto_programt::const_targett, goto_inline_log_infot, goto_programt::target_less_than > log_mapt
void cleanup(const goto_programt &goto_program)
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)
bool is_ignored(const irep_idt id) const
void goto_inline_nontransitive(const irep_idt identifier, goto_functiont &goto_function, const inline_mapt &inline_map, const bool force_full)
std::list< callt > call_listt
goto_functionst & goto_functions
static void get_call(goto_programt::const_targett target, exprt &lhs, exprt &function, exprt::operandst &arguments)
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.
const bool caching
jsont output_inline_log_json()
no_body_sett no_body_set
const goto_functiont & goto_inline_transitive(const irep_idt identifier, const goto_functiont &goto_function, const bool force_full)
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.
recursion_sett recursion_set
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)
bool check_inline_map(const inline_mapt &inline_map) const
void parameter_destruction(const goto_programt::targett target, const goto_functiont::parameter_identifierst &parameter_identifiers, goto_programt &dest)
const bool adjust_function
goto_inline_logt inline_log
void output_inline_map(std::ostream &out, const inline_mapt &inline_map)
std::unordered_set< irep_idt > finished_sett
goto_functionst::goto_functiont goto_functiont
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)
std::pair< goto_programt::targett, bool > callt
std::map< irep_idt, call_listt > inline_mapt
std::unordered_set< irep_idt > no_body_sett
void replace_return(goto_programt &body, const exprt &lhs)
finished_sett finished_set
std::unordered_set< irep_idt > recursion_sett
const namespacet & ns
goto_functionst::function_mapt cachet
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.
void output_cache(std::ostream &out) const
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:73
instructionst::iterator targett
Definition: goto_program.h:614
instructionst::const_iterator const_targett
Definition: goto_program.h:615
Definition: json.h:27
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:155
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Expression to hold a symbol (variable)
Definition: std_expr.h:131
Goto Programs with Functions.
A total order over targett and const_targett.
Definition: goto_program.h:392