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(
106  const goto_programt &goto_program,
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
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition: message.h:144
goto_inlinet::goto_inline_logt::goto_inline_log_infot::begin_location_number
unsigned begin_location_number
Definition: goto_inline_class.h:93
dstringt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition: dstring.h:35
goto_inlinet::parameter_destruction
void parameter_destruction(const goto_programt::targett target, const irep_idt &function_name, const code_typet &code_type, goto_programt &dest)
Definition: goto_inline_class.cpp:146
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:260
goto_inlinet::output_inline_log_json
jsont output_inline_log_json()
Definition: goto_inline_class.h:73
goto_inlinet::call_listt
std::list< callt > call_listt
Definition: goto_inline_class.h:46
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:804
goto_inlinet::goto_inline_logt::goto_inline_log_infot::call_location_number
unsigned call_location_number
Definition: goto_inline_class.h:95
goto_inlinet::replace_return
void replace_return(goto_programt &body, const exprt &lhs)
Definition: goto_inline_class.cpp:182
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:497
goto_inlinet::recursion_sett
std::unordered_set< irep_idt > recursion_sett
Definition: goto_inline_class.h:199
exprt
Base class for all expressions.
Definition: expr.h:54
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)
Definition: goto_inline_class.cpp:531
goto_inlinet::goto_inline_logt::cleanup
void cleanup(const goto_programt &goto_program)
Definition: goto_inline_class.cpp:783
symbol_exprt
Expression to hold a symbol (variable)
Definition: std_expr.h:143
goto_inlinet::goto_inline_logt::goto_inline_log_infot::end_location_number
unsigned end_location_number
Definition: goto_inline_class.h:94
jsont
Definition: json.h:23
goto_inlinet::callt
std::pair< goto_programt::targett, bool > callt
Definition: goto_inline_class.h:43
goto_inlinet::goto_inline_logt
Definition: goto_inline_class.h:86
goto_inlinet::adjust_function
const bool adjust_function
Definition: goto_inline_class.h:129
goto_inlinet::no_body_set
no_body_sett no_body_set
Definition: goto_inline_class.h:203
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:546
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:93
goto_inlinet::recursion_set
recursion_sett recursion_set
Definition: goto_inline_class.h:200
goto_inlinet::cachet
goto_functionst::function_mapt cachet
Definition: goto_inline_class.h:193
goto_inlinet::clear
void clear()
Definition: goto_inline_class.h:152
goto_functionst::function_mapt
std::map< irep_idt, goto_functiont > function_mapt
Definition: goto_functions.h:26
goto_inlinet::goto_inline_logt::log_mapt
std::map< goto_programt::const_targett, goto_inline_log_infot > log_mapt
Definition: goto_inline_class.h:120
goto_inlinet::goto_inline_logt::output_inline_log_json
jsont output_inline_log_json() const
Definition: goto_inline_class.cpp:879
goto_inlinet::caching
const bool caching
Definition: goto_inline_class.h:130
goto_inlinet::no_body_sett
std::unordered_set< irep_idt > no_body_sett
Definition: goto_inline_class.h:202
goto_inlinet::goto_inline_logt::log_map
log_mapt log_map
Definition: goto_inline_class.h:122
json_expr.h
goto_inlinet::goto_inlinet
goto_inlinet(goto_functionst &goto_functions, const namespacet &ns, message_handlert &message_handler, bool adjust_function, bool caching=true)
Definition: goto_inline_class.h:24
goto_inlinet::cache
cachet cache
Definition: goto_inline_class.h:194
goto_inlinet::goto_inline_logt::goto_inline_log_infot::end
goto_programt::const_targett end
Definition: goto_inline_class.h:97
code_typet
Base type of functions.
Definition: std_types.h:751
message_handlert
Definition: message.h:24
goto_inlinet::goto_functions
goto_functionst & goto_functions
Definition: goto_inline_class.h:126
goto_inlinet::ns
const namespacet & ns
Definition: goto_inline_class.h:127
goto_functiont
A goto function, consisting of function type (see type), function body (see body),...
Definition: goto_function.h:26
exprt::operandst
std::vector< exprt > operandst
Definition: expr.h:57
goto_inlinet::finished_sett
std::unordered_set< irep_idt > finished_sett
Definition: goto_inline_class.h:196
goto_inlinet::goto_inline_logt::goto_inline_log_infot
Definition: goto_inline_class.h:89
goto_inlinet::output_inline_map
void output_inline_map(std::ostream &out, const inline_mapt &inline_map)
Definition: goto_inline_class.cpp:726
goto_inlinet::inline_mapt
std::map< irep_idt, call_listt > inline_mapt
Definition: goto_inline_class.h:49
goto_functionst::goto_functiont
::goto_functiont goto_functiont
Definition: goto_functions.h:25
goto_functionst
A collection of goto functions.
Definition: goto_functions.h:22
messaget::message_handler
message_handlert * message_handler
Definition: message.h:426
goto_inlinet::finished_set
finished_sett finished_set
Definition: goto_inline_class.h:197
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:598
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)
Definition: goto_inline_class.cpp:371
json.h
goto_inlinet::check_inline_map
bool check_inline_map(const inline_mapt &inline_map) const
Definition: goto_inline_class.cpp:715
goto_inlinet::parameter_assignments
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)
Definition: goto_inline_class.cpp:31
goto_functions.h
goto_inlinet::inline_log
goto_inline_logt inline_log
Definition: goto_inline_class.h:132
goto_programt
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:72
goto_programt::const_targett
instructionst::const_iterator const_targett
Definition: goto_program.h:415
goto_inlinet::is_ignored
bool is_ignored(const irep_idt id) const
Definition: goto_inline_class.cpp:660
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:833
goto_inlinet::output_cache
void output_cache(std::ostream &out) const
Definition: goto_inline_class.cpp:771
goto_programt::targett
instructionst::iterator targett
Definition: goto_program.h:414
goto_inlinet
Definition: goto_inline_class.h:21
goto_inlinet::goto_functiont
goto_functionst::goto_functiont goto_functiont
Definition: goto_inline_class.h:38