Skip to content

Commit 7b8a4e6

Browse files
author
Daniel Kroening
authored
Merge pull request #654 from danpoe/inlining-no-caching
Option to disable caching for inlining
2 parents 7a8961e + 0f0ab68 commit 7b8a4e6

File tree

12 files changed

+163
-13
lines changed

12 files changed

+163
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
int x;
3+
4+
void g()
5+
{
6+
x = 1;
7+
}
8+
9+
void f()
10+
{
11+
g();
12+
}
13+
14+
int main()
15+
{
16+
f();
17+
}
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function-inline main --log -
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
int x;
3+
4+
void h()
5+
{
6+
x = 1;
7+
}
8+
9+
void g()
10+
{
11+
h();
12+
}
13+
14+
void f()
15+
{
16+
g();
17+
}
18+
19+
int main()
20+
{
21+
f();
22+
}
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function-inline main --log - --no-caching
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
int x;
3+
4+
void h()
5+
{
6+
x = 1;
7+
}
8+
9+
void g()
10+
{
11+
h();
12+
}
13+
14+
void f()
15+
{
16+
g();
17+
}
18+
19+
int main()
20+
{
21+
f();
22+
}
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--function-inline main --log - --no-caching --verbosity 9
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/goto-instrument/goto_instrument_parse_options.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10521052
std::string function=cmdline.get_value("function-inline");
10531053
assert(!function.empty());
10541054

1055+
bool caching=!cmdline.isset("no-caching");
1056+
10551057
do_indirect_call_and_rtti_removal();
10561058

10571059
status() << "Inlining calls of function `" << function << "'" << eom;
@@ -1063,7 +1065,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10631065
function,
10641066
ns,
10651067
ui_message_handler,
1066-
true);
1068+
true,
1069+
caching);
10671070
}
10681071
else
10691072
{
@@ -1076,7 +1079,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
10761079
function,
10771080
ns,
10781081
ui_message_handler,
1079-
true);
1082+
true,
1083+
caching);
10801084

10811085
if(have_file)
10821086
{
@@ -1548,6 +1552,7 @@ void goto_instrument_parse_optionst::help()
15481552
" --inline perform full inlining\n"
15491553
" --partial-inline perform partial inlining\n"
15501554
" --function-inline <function> transitively inline all calls <function> makes\n" // NOLINT(*)
1555+
" --no-caching disable caching of intermediate results during transitive function inlining\n" // NOLINT(*)
15511556
" --log <file> log in json format which code segments were inlined, use with --function-inline\n" // NOLINT(*)
15521557
" --remove-function-pointers replace function pointers by case statement over function calls\n" // NOLINT(*)
15531558
" --add-library add models of C library functions\n"

src/goto-instrument/goto_instrument_parse_options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Author: Daniel Kroening, [email protected]
5353
"(show-struct-alignment)(interval-analysis)(show-intervals)" \
5454
"(show-uninitialized)(show-locations)" \
5555
"(full-slice)(reachability-slice)(slice-global-inits)" \
56-
"(inline)(partial-inline)(function-inline):(log):" \
56+
"(inline)(partial-inline)(function-inline):(log):(no-caching)" \
5757
"(remove-function-pointers)" \
5858
"(show-claims)(show-properties)(property):" \
5959
"(show-symbol-table)(show-points-to)(show-rw-set)" \

src/goto-programs/goto_inline.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,15 @@ void goto_function_inline(
273273
const irep_idt function,
274274
const namespacet &ns,
275275
message_handlert &message_handler,
276-
bool adjust_function)
276+
bool adjust_function,
277+
bool caching)
277278
{
278279
goto_inlinet goto_inline(
279280
goto_functions,
280281
ns,
281282
message_handler,
282-
adjust_function);
283+
adjust_function,
284+
caching);
283285

284286
goto_functionst::function_mapt::iterator f_it=
285287
goto_functions.function_map.find(function);
@@ -327,13 +329,15 @@ jsont goto_function_inline_and_log(
327329
const irep_idt function,
328330
const namespacet &ns,
329331
message_handlert &message_handler,
330-
bool adjust_function)
332+
bool adjust_function,
333+
bool caching)
331334
{
332335
goto_inlinet goto_inline(
333336
goto_functions,
334337
ns,
335338
message_handler,
336-
adjust_function);
339+
adjust_function,
340+
caching);
337341

338342
goto_functionst::function_mapt::iterator f_it=
339343
goto_functions.function_map.find(function);
@@ -349,6 +353,7 @@ jsont goto_function_inline_and_log(
349353
// gather all calls
350354
goto_inlinet::inline_mapt inline_map;
351355

356+
// create empty call list
352357
goto_inlinet::call_listt &call_list=inline_map[f_it->first];
353358

354359
goto_programt &goto_program=goto_function.body;

src/goto-programs/goto_inline.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,23 @@ void goto_function_inline(
5050
goto_modelt &goto_model,
5151
const irep_idt function,
5252
message_handlert &message_handler,
53-
bool adjust_function=false);
53+
bool adjust_function=false,
54+
bool caching=true);
5455

5556
void goto_function_inline(
5657
goto_functionst &goto_functions,
5758
const irep_idt function,
5859
const namespacet &ns,
5960
message_handlert &message_handler,
60-
bool adjust_function=false);
61+
bool adjust_function=false,
62+
bool caching=true);
6163

6264
jsont goto_function_inline_and_log(
6365
goto_functionst &goto_functions,
6466
const irep_idt function,
6567
const namespacet &ns,
6668
message_handlert &message_handler,
67-
bool adjust_function=false);
69+
bool adjust_function=false,
70+
bool caching=true);
6871

6972
#endif // CPROVER_GOTO_PROGRAMS_GOTO_INLINE_H

src/goto-programs/goto_inline_class.cpp

+44-1
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,20 @@ void goto_inlinet::expand_function_call(
682682
function,
683683
arguments,
684684
constrain);
685+
686+
progress() << "Inserting " << identifier << " into caller" << eom;
687+
progress() << "Number of instructions: "
688+
<< cached.body.instructions.size() << eom;
689+
690+
if(!caching)
691+
{
692+
progress() << "Removing " << identifier << " from cache" << eom;
693+
progress() << "Number of instructions: "
694+
<< cached.body.instructions.size() << eom;
695+
696+
inline_log.cleanup(cached.body);
697+
cache.erase(identifier);
698+
}
685699
}
686700
else
687701
{
@@ -944,6 +958,11 @@ const goto_inlinet::goto_functiont &goto_inlinet::goto_inline_transitive(
944958

945959
goto_functiont &cached=cache[identifier];
946960
assert(cached.body.empty());
961+
962+
progress() << "Creating copy of " << identifier << eom;
963+
progress() << "Number of instructions: "
964+
<< goto_function.body.instructions.size() << eom;
965+
947966
cached.copy_from(goto_function); // location numbers not changed
948967
inline_log.copy_from(goto_function.body, cached.body);
949968

@@ -1146,6 +1165,29 @@ void goto_inlinet::output_inline_map(
11461165

11471166
/*******************************************************************\
11481167
1168+
Function: output_cache
1169+
1170+
Inputs:
1171+
1172+
Outputs:
1173+
1174+
Purpose:
1175+
1176+
\*******************************************************************/
1177+
1178+
void goto_inlinet::output_cache(std::ostream &out) const
1179+
{
1180+
for(auto it=cache.begin(); it!=cache.end(); it++)
1181+
{
1182+
if(it!=cache.begin())
1183+
out << ", ";
1184+
1185+
out << it->first << "\n";
1186+
}
1187+
}
1188+
1189+
/*******************************************************************\
1190+
11491191
Function: cleanup
11501192
11511193
Inputs:
@@ -1257,8 +1299,9 @@ void goto_inlinet::goto_inline_logt::copy_from(
12571299
assert(it1->location_number==it2->location_number);
12581300

12591301
log_mapt::const_iterator l_it=log_map.find(it1);
1260-
if(l_it!=log_map.end())
1302+
if(l_it!=log_map.end()) // a segment starts here
12611303
{
1304+
// as 'to' is a fresh copy
12621305
assert(log_map.find(it2)==log_map.end());
12631306

12641307
goto_inline_log_infot info=l_it->second;

src/goto-programs/goto_inline_class.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ class goto_inlinet:public messaget
2424
goto_functionst &goto_functions,
2525
const namespacet &ns,
2626
message_handlert &message_handler,
27-
bool adjust_function):
27+
bool adjust_function,
28+
bool caching=true):
2829
messaget(message_handler),
2930
goto_functions(goto_functions),
3031
ns(ns),
31-
adjust_function(adjust_function)
32+
adjust_function(adjust_function),
33+
caching(caching)
3234
{
3335
}
3436

@@ -64,6 +66,8 @@ class goto_inlinet:public messaget
6466
std::ostream &out,
6567
const inline_mapt &inline_map);
6668

69+
void output_cache(std::ostream &out) const;
70+
6771
// call after goto_functions.update()!
6872
jsont output_inline_log_json()
6973
{
@@ -127,6 +131,8 @@ class goto_inlinet:public messaget
127131
const namespacet &ns;
128132

129133
const bool adjust_function;
134+
const bool caching;
135+
130136
goto_inline_logt inline_log;
131137

132138
void goto_inline_nontransitive(

0 commit comments

Comments
 (0)