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 #include <util/json_expr.h>
18 
19 #include "goto_functions.h"
20 
21 class goto_inlinet:public messaget
22 {
23 public:
26  const namespacet &ns,
28  bool adjust_function,
29  bool caching=true):
32  ns(ns),
35  {
36  }
37 
39 
40  // call that should be inlined
41  // false: inline non-transitively
42  // true: inline transitively
43  typedef std::pair<goto_programt::targett, bool> callt;
44 
45  // list of calls that should be inlined
46  typedef std::list<callt> call_listt;
47 
48  // list of calls per function that should be inlined
49  typedef std::map<irep_idt, call_listt> inline_mapt;
50 
51  // handle given goto function
52  // force_full:
53  // - true: put skip on recursion and issue warning
54  // - false: leave call on recursion
55  void goto_inline(
56  const irep_idt identifier,
57  goto_functiont &goto_function,
58  const inline_mapt &inline_map,
59  const bool force_full=false);
60 
61  // handle all functions
62  void goto_inline(
63  const inline_mapt &inline_map,
64  const bool force_full=false);
65 
66  void output_inline_map(
67  std::ostream &out,
68  const inline_mapt &inline_map);
69 
70  void output_cache(std::ostream &out) const;
71 
72  // call after goto_functions.update()!
74  {
77  }
78 
79  // get call info of normal or bp call
80  static void get_call(
82  exprt &lhs,
83  exprt &function,
84  exprt::operandst &arguments);
85 
87  {
88  public:
90  {
91  public:
92  // original segment location numbers
95  unsigned call_location_number; // original call location number
96  irep_idt function; // function from which segment was inlined
98  };
99 
100  // remove segment that refer to the given goto program
101  void cleanup(const goto_programt &goto_program);
102 
103  void cleanup(const goto_functionst::function_mapt &function_map);
104 
105  void add_segment(
107  const unsigned begin_location_number,
108  const unsigned end_location_number,
109  const unsigned call_location_number,
110  const irep_idt function);
111 
112  void copy_from(const goto_programt &from, const goto_programt &to);
113 
114  // call after goto_functions.update()!
116 
117  // map from segment start to inline info
118  typedef std::map<
121 
123  };
124 
125 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 code_typet &code_type,
183  const exprt::operandst &arguments,
184  goto_programt &dest);
185 
187  const goto_programt::targett target,
188  const irep_idt &function_name,
189  const code_typet &code_type,
190  goto_programt &dest);
191 
192  // goto functions that were already inlined transitively
195 
196  typedef std::unordered_set<irep_idt> finished_sett;
198 
199  typedef std::unordered_set<irep_idt> recursion_sett;
201 
202  typedef std::unordered_set<irep_idt> no_body_sett;
204 };
205 
206 #endif // CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
std::pair< goto_programt::targett, bool > callt
std::list< callt > call_listt
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)
Base type of functions.
Definition: std_types.h:764
goto_inline_logt inline_log
bool is_ignored(const irep_idt id) const
Goto Programs with Functions.
Definition: json.h:23
void cleanup(const goto_programt &goto_program)
const bool caching
std::unordered_set< irep_idt > no_body_sett
void replace_return(goto_programt &body, const exprt &lhs)
void parameter_destruction(const goto_programt::targett target, const irep_idt &function_name, const code_typet &code_type, goto_programt &dest)
void goto_inline(const irep_idt identifier, goto_functiont &goto_function, const inline_mapt &inline_map, const bool force_full=false)
std::map< irep_idt, call_listt > inline_mapt
instructionst::iterator targett
Definition: goto_program.h:397
recursion_sett recursion_set
std::unordered_set< irep_idt > recursion_sett
Expressions in JSON.
instructionst::const_iterator const_targett
Definition: goto_program.h:398
TO_BE_DOCUMENTED.
Definition: namespace.h:74
void expand_function_call(goto_programt &dest, const inline_mapt &inline_map, const bool transitive, const bool force_full, goto_programt::targett target)
::goto_functiont goto_functiont
std::map< goto_programt::const_targett, goto_inline_log_infot > log_mapt
bool check_inline_map(const inline_mapt &inline_map) const
std::map< irep_idt, goto_functiont > function_mapt
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
Definition: dstring.h:33
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)
const goto_functiont & goto_inline_transitive(const irep_idt identifier, const goto_functiont &goto_function, const bool force_full)
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)
std::vector< exprt > operandst
Definition: expr.h:45
const bool adjust_function
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:70
goto_functionst & goto_functions
const namespacet & ns
finished_sett finished_set
no_body_sett no_body_set
void output_cache(std::ostream &out) const
goto_functionst::function_mapt cachet
void parameter_assignments(const goto_programt::targett target, const irep_idt &function_name, const code_typet &code_type, const exprt::operandst &arguments, goto_programt &dest)
Base class for all expressions.
Definition: expr.h:42
void copy_from(const goto_programt &from, const goto_programt &to)
goto_programt & goto_program
Definition: cover.cpp:63
Expression to hold a symbol (variable)
Definition: std_expr.h:90
void goto_inline_nontransitive(const irep_idt identifier, goto_functiont &goto_function, const inline_mapt &inline_map, const bool force_full)
goto_functionst::goto_functiont goto_functiont
std::unordered_set< irep_idt > finished_sett
message_handlert * message_handler
Definition: message.h:342
void output_inline_map(std::ostream &out, const inline_mapt &inline_map)
jsont output_inline_log_json()