Skip to content

Commit f847fcd

Browse files
authored
Merge pull request #6136 from martin-cs/fix/inline-documentation
Expand the documentation for goto-inline
2 parents 1ff5344 + 2bd6f72 commit f847fcd

File tree

4 files changed

+60
-6
lines changed

4 files changed

+60
-6
lines changed

src/goto-programs/goto_inline.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Author: Daniel Kroening, [email protected]
1616
#include "goto_inline_class.h"
1717
#include "goto_model.h"
1818

19+
/// Inline every function call into the entry_point() function.
20+
/// Then delete the bodies of all of the other functions.
21+
/// This is pretty drastic and can result in a very large program.
22+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
23+
/// \param goto_model: Source of the symbol table and function map to use.
24+
/// \param message_handler: Message handler used by goto_inlinet.
25+
/// \param adjust_function: Replace location in inlined function with call site.
1926
void goto_inline(
2027
goto_modelt &goto_model,
2128
message_handlert &message_handler,
@@ -29,6 +36,14 @@ void goto_inline(
2936
adjust_function);
3037
}
3138

39+
/// Inline every function call into the entry_point() function.
40+
/// Then delete the bodies of all of the other functions.
41+
/// This is pretty drastic and can result in a very large program.
42+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
43+
/// \param goto_functions: The function map to use.
44+
/// \param ns : The namespace to use.
45+
/// \param message_handler: Message handler used by goto_inlinet.
46+
/// \param adjust_function: Replace location in inlined function with call site.
3247
void goto_inline(
3348
goto_functionst &goto_functions,
3449
const namespacet &ns,
@@ -96,11 +111,14 @@ void goto_inline(
96111

97112
/// Inline all function calls to functions either marked as "inlined" or
98113
/// smaller than smallfunc_limit (by instruction count).
114+
/// Unlike the goto_inline functions, this doesn't remove function
115+
/// bodies after inlining.
116+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
99117
/// \param goto_model: Source of the symbol table and function map to use.
100118
/// \param message_handler: Message handler used by goto_inlinet.
101119
/// \param smallfunc_limit: The maximum number of instructions in functions to
102120
/// be inlined.
103-
/// \param adjust_function: Tell goto_inlinet to adjust function.
121+
/// \param adjust_function: Replace location in inlined function with call site.
104122
void goto_partial_inline(
105123
goto_modelt &goto_model,
106124
message_handlert &message_handler,
@@ -118,13 +136,16 @@ void goto_partial_inline(
118136

119137
/// Inline all function calls to functions either marked as "inlined" or
120138
/// smaller than smallfunc_limit (by instruction count).
139+
/// Unlike the goto_inline functions, this doesn't remove function
140+
/// bodies after inlining.
141+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
121142
/// \param goto_functions: The function map to use to find functions containing
122143
/// calls and function bodies.
123144
/// \param ns: Namespace used by goto_inlinet.
124145
/// \param message_handler: Message handler used by goto_inlinet.
125146
/// \param smallfunc_limit: The maximum number of instructions in functions to
126147
/// be inlined.
127-
/// \param adjust_function: Tell goto_inlinet to adjust function.
148+
/// \param adjust_function: Replace location in inlined function with call site.
128149
void goto_partial_inline(
129150
goto_functionst &goto_functions,
130151
const namespacet &ns,
@@ -153,6 +174,9 @@ void goto_partial_inline(
153174
if(gf_entry.first == goto_functions.entry_point())
154175
{
155176
// Don't inline any function calls made from the _start function.
177+
// This is so that the convention of __CPROVER_start
178+
// calling __CPROVER_initialize is maintained, so these can be
179+
// augmented / replaced by later passes.
156180
continue;
157181
}
158182

@@ -205,11 +229,12 @@ void goto_partial_inline(
205229
goto_inline.goto_inline(inline_map, false);
206230
}
207231

208-
/// Inline all function calls made from a particular function
232+
/// Transitively inline all function calls made from a particular function.
233+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
209234
/// \param goto_model: Source of the symbol table and function map to use.
210235
/// \param function: The function whose calls to inline.
211236
/// \param message_handler: Message handler used by goto_inlinet.
212-
/// \param adjust_function: Tell goto_inlinet to adjust function.
237+
/// \param adjust_function: Replace location in inlined function with call site.
213238
/// \param caching: Tell goto_inlinet to cache.
214239
void goto_function_inline(
215240
goto_modelt &goto_model,
@@ -228,12 +253,13 @@ void goto_function_inline(
228253
caching);
229254
}
230255

231-
/// Inline all function calls made from a particular function
256+
/// Transitively inline all function calls made from a particular function.
257+
/// Caller is responsible for calling update(), compute_loop_numbers(), etc.
232258
/// \param goto_functions: The function map to use to find function bodies.
233259
/// \param function: The function whose calls to inline.
234260
/// \param ns: Namespace used by goto_inlinet.
235261
/// \param message_handler: Message handler used by goto_inlinet.
236-
/// \param adjust_function: Tell goto_inlinet to adjust function.
262+
/// \param adjust_function: Replace location in inlined function with call site.
237263
/// \param caching: Tell goto_inlinet to cache.
238264
void goto_function_inline(
239265
goto_functionst &goto_functions,

src/goto-programs/goto_inline.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Author: Daniel Kroening, [email protected]
88

99
/// \file
1010
/// Function Inlining
11+
/// This gives a number of different interfaces to the function
12+
/// inlining functionality of goto_inlinet.
1113

1214
#ifndef CPROVER_GOTO_PROGRAMS_GOTO_INLINE_H
1315
#define CPROVER_GOTO_PROGRAMS_GOTO_INLINE_H

src/goto-programs/goto_inline_class.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ void goto_inlinet::insert_function_body(
296296
dest.destructive_insert(target, tmp);
297297
}
298298

299+
/// Inlines a single function call
300+
/// Calls out to goto_inline_transitive or goto_inline_nontransitive
299301
void goto_inlinet::expand_function_call(
300302
goto_programt &dest,
301303
const inline_mapt &inline_map,
@@ -441,6 +443,11 @@ void goto_inlinet::get_call(
441443
arguments=call.arguments();
442444
}
443445

446+
/// Inline all of the given call locations.
447+
/// This is the highest-level interface and calls the other goto_inline
448+
/// \param inline_map : which call locations to inline.
449+
/// \param force_full : true to break recursion with a SKIP,
450+
/// false means detecting recursion is an error.
444451
void goto_inlinet::goto_inline(
445452
const inline_mapt &inline_map,
446453
const bool force_full)
@@ -460,6 +467,13 @@ void goto_inlinet::goto_inline(
460467
}
461468
}
462469

470+
/// Inline all of the chosen calls in a given function.
471+
/// This is main entry point for the functionality
472+
/// \param identifier : the name of the caller function.
473+
/// \param goto_function : the caller function itself.
474+
/// \param inline_map : which call locations to inline.
475+
/// \param force_full : true to break recursion with a SKIP,
476+
/// false means detecting recursion is an error.
463477
void goto_inlinet::goto_inline(
464478
const irep_idt identifier,
465479
goto_functiont &goto_function,

src/goto-programs/goto_inline_class.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9+
/// \file
10+
/// Function Inlining
11+
/// This is a class that encapsulates the state and functionality needed
12+
/// to do inline multiple function calls.
13+
/// goto_inline.h provides a number of more convenient interfaces.
914

1015
#ifndef CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
1116
#define CPROVER_GOTO_PROGRAMS_GOTO_INLINE_CLASS_H
@@ -20,6 +25,13 @@ Author: Daniel Kroening, [email protected]
2025
class goto_inlinet
2126
{
2227
public:
28+
/// Sets up the class with the program to operate on.
29+
///
30+
/// \param goto_functions : The map of functions to work on
31+
/// \param ns : The corresponding namespace
32+
/// \param message_handler : Used to log what is being inlined
33+
/// \param adjust_function: Replace location in caller location.
34+
/// \param caching : cache functions when in transitive mode
2335
goto_inlinet(
2436
goto_functionst &goto_functions,
2537
const namespacet &ns,

0 commit comments

Comments
 (0)