cprover
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 
9 
10 #ifndef CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
11 #define CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
12 
13 #include <unordered_set>
14 
15 #include <util/message.h>
16 #include <util/json.h>
17 
18 #include "goto_functions.h"
19 
21 {
22 public:
25  const namespacet &ns,
26  message_handlert &message_handler,
27  bool adjust_function,
28  bool caching = true)
29  : log(message_handler),
31  ns(ns),
34  {
35  }
36 
38 
39  // call that should be inlined
40  // false: inline non-transitively
41  // true: inline transitively
42  typedef std::pair<goto_programt::targett, bool> callt;
43 
44  // list of calls that should be inlined
45  typedef std::list<callt> call_listt;
46 
47  // list of calls per function that should be inlined
48  typedef std::map<irep_idt, call_listt> inline_mapt;
49 
50  // handle given goto function
51  // force_full:
52  // - true: put skip on recursion and issue warning
53  // - false: leave call on recursion
54  void goto_inline(
55  const irep_idt identifier,
56  goto_functiont &goto_function,
57  const inline_mapt &inline_map,
58  const bool force_full=false);
59 
60  // handle all functions
61  void goto_inline(
62  const inline_mapt &inline_map,
63  const bool force_full=false);
64 
65  void output_inline_map(
66  std::ostream &out,
67  const inline_mapt &inline_map);
68 
69  void output_cache(std::ostream &out) const;
70 
71  // call after goto_functions.update()!
73  {
76  }
77 
78  // get call info of normal or bp call
79  static void get_call(
81  exprt &lhs,
82  exprt &function,
83  exprt::operandst &arguments);
84 
86  {
87  public:
89  {
90  public:
91  // original segment location numbers
94  unsigned call_location_number; // original call location number
95  irep_idt function; // function from which segment was inlined
97  };
98 
99  // remove segment that refer to the given goto program
100  void cleanup(const goto_programt &goto_program);
101 
102  void cleanup(const goto_functionst::function_mapt &function_map);
103 
104  void add_segment(
105  const goto_programt &goto_program,
106  const unsigned begin_location_number,
107  const unsigned end_location_number,
108  const unsigned call_location_number,
109  const irep_idt function);
110 
111  void copy_from(const goto_programt &from, const goto_programt &to);
112 
113  // call after goto_functions.update()!
115 
116  // map from segment start to inline info
117  typedef std::map<
120 
122  };
123 
124 protected:
127  const namespacet &ns;
128 
129  const bool adjust_function;
130  const bool caching;
131 
133 
135  const irep_idt identifier,
136  goto_functiont &goto_function,
137  const inline_mapt &inline_map,
138  const bool force_full);
139 
141  const irep_idt identifier,
142  const goto_functiont &goto_function,
143  const bool force_full);
144 
145  bool check_inline_map(const inline_mapt &inline_map) const;
146  bool check_inline_map(
147  const irep_idt identifier,
148  const inline_mapt &inline_map) const;
149 
150  bool is_ignored(const irep_idt id) const;
151 
152  void clear()
153  {
154  cache.clear();
155  finished_set.clear();
156  recursion_set.clear();
157  no_body_set.clear();
158  }
159 
161  goto_programt &dest,
162  const inline_mapt &inline_map,
163  const bool transitive,
164  const bool force_full,
165  goto_programt::targett target);
166 
168  const goto_functiont &f,
169  goto_programt &dest,
170  goto_programt::targett target,
171  const exprt &lhs,
172  const symbol_exprt &function,
173  const exprt::operandst &arguments);
174 
175  void replace_return(
176  goto_programt &body,
177  const exprt &lhs);
178 
180  const goto_programt::targett target,
181  const irep_idt &function_name,
182  const goto_functiont::parameter_identifierst &parameter_identifiers,
183  const exprt::operandst &arguments,
184  goto_programt &dest);
185 
187  const goto_programt::targett target,
188  const goto_functiont::parameter_identifierst &parameter_identifiers,
189  goto_programt &dest);
190 
191  // goto functions that were already inlined transitively
194 
195  typedef std::unordered_set<irep_idt> finished_sett;
197 
198  typedef std::unordered_set<irep_idt> recursion_sett;
200 
201  typedef std::unordered_set<irep_idt> no_body_sett;
203 };
204 
205 #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:37
Base class for all expressions.
Definition: expr.h:54
std::vector< exprt > operandst
Definition: expr.h:56
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:27
std::vector< irep_idt > parameter_identifierst
Definition: goto_function.h:31
std::map< goto_programt::const_targett, goto_inline_log_infot > log_mapt
void copy_from(const goto_programt &from, const goto_programt &to)
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)
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)
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)
void output_cache(std::ostream &out) const
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:74
instructionst::iterator targett
Definition: goto_program.h:550
instructionst::const_iterator const_targett
Definition: goto_program.h:551
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:92
Expression to hold a symbol (variable)
Definition: std_expr.h:81
Goto Programs with Functions.