Skip to content

Option to disable caching for inlining #654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions regression/goto-instrument/inline_13/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

int x;

void g()
{
x = 1;
}

void f()
{
g();
}

int main()
{
f();
}

8 changes: 8 additions & 0 deletions regression/goto-instrument/inline_13/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--function-inline main --log -
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
23 changes: 23 additions & 0 deletions regression/goto-instrument/inline_14/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

int x;

void h()
{
x = 1;
}

void g()
{
h();
}

void f()
{
g();
}

int main()
{
f();
}

8 changes: 8 additions & 0 deletions regression/goto-instrument/inline_14/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--function-inline main --log - --no-caching
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
23 changes: 23 additions & 0 deletions regression/goto-instrument/inline_15/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

int x;

void h()
{
x = 1;
}

void g()
{
h();
}

void f()
{
g();
}

int main()
{
f();
}

8 changes: 8 additions & 0 deletions regression/goto-instrument/inline_15/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--function-inline main --log - --no-caching --verbosity 9
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
9 changes: 7 additions & 2 deletions src/goto-instrument/goto_instrument_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
std::string function=cmdline.get_value("function-inline");
assert(!function.empty());

bool caching=!cmdline.isset("no-caching");

do_indirect_call_and_rtti_removal();

status() << "Inlining calls of function `" << function << "'" << eom;
Expand All @@ -1063,7 +1065,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
function,
ns,
ui_message_handler,
true);
true,
caching);
}
else
{
Expand All @@ -1076,7 +1079,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
function,
ns,
ui_message_handler,
true);
true,
caching);

if(have_file)
{
Expand Down Expand Up @@ -1548,6 +1552,7 @@ void goto_instrument_parse_optionst::help()
" --inline perform full inlining\n"
" --partial-inline perform partial inlining\n"
" --function-inline <function> transitively inline all calls <function> makes\n" // NOLINT(*)
" --no-caching disable caching of intermediate results during transitive function inlining\n" // NOLINT(*)
" --log <file> log in json format which code segments were inlined, use with --function-inline\n" // NOLINT(*)
" --remove-function-pointers replace function pointers by case statement over function calls\n" // NOLINT(*)
" --add-library add models of C library functions\n"
Expand Down
2 changes: 1 addition & 1 deletion src/goto-instrument/goto_instrument_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Author: Daniel Kroening, [email protected]
"(show-struct-alignment)(interval-analysis)(show-intervals)" \
"(show-uninitialized)(show-locations)" \
"(full-slice)(reachability-slice)(slice-global-inits)" \
"(inline)(partial-inline)(function-inline):(log):" \
"(inline)(partial-inline)(function-inline):(log):(no-caching)" \
"(remove-function-pointers)" \
"(show-claims)(show-properties)(property):" \
"(show-symbol-table)(show-points-to)(show-rw-set)" \
Expand Down
13 changes: 9 additions & 4 deletions src/goto-programs/goto_inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,15 @@ void goto_function_inline(
const irep_idt function,
const namespacet &ns,
message_handlert &message_handler,
bool adjust_function)
bool adjust_function,
bool caching)
{
goto_inlinet goto_inline(
goto_functions,
ns,
message_handler,
adjust_function);
adjust_function,
caching);

goto_functionst::function_mapt::iterator f_it=
goto_functions.function_map.find(function);
Expand Down Expand Up @@ -327,13 +329,15 @@ jsont goto_function_inline_and_log(
const irep_idt function,
const namespacet &ns,
message_handlert &message_handler,
bool adjust_function)
bool adjust_function,
bool caching)
{
goto_inlinet goto_inline(
goto_functions,
ns,
message_handler,
adjust_function);
adjust_function,
caching);

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

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

goto_programt &goto_program=goto_function.body;
Expand Down
9 changes: 6 additions & 3 deletions src/goto-programs/goto_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,23 @@ void goto_function_inline(
goto_modelt &goto_model,
const irep_idt function,
message_handlert &message_handler,
bool adjust_function=false);
bool adjust_function=false,
bool caching=true);

void goto_function_inline(
goto_functionst &goto_functions,
const irep_idt function,
const namespacet &ns,
message_handlert &message_handler,
bool adjust_function=false);
bool adjust_function=false,
bool caching=true);

jsont goto_function_inline_and_log(
goto_functionst &goto_functions,
const irep_idt function,
const namespacet &ns,
message_handlert &message_handler,
bool adjust_function=false);
bool adjust_function=false,
bool caching=true);

#endif // CPROVER_GOTO_PROGRAMS_GOTO_INLINE_H
45 changes: 44 additions & 1 deletion src/goto-programs/goto_inline_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,20 @@ void goto_inlinet::expand_function_call(
function,
arguments,
constrain);

progress() << "Inserting " << identifier << " into caller" << eom;
progress() << "Number of instructions: "
<< cached.body.instructions.size() << eom;

if(!caching)
{
progress() << "Removing " << identifier << " from cache" << eom;
progress() << "Number of instructions: "
<< cached.body.instructions.size() << eom;

inline_log.cleanup(cached.body);
cache.erase(identifier);
}
}
else
{
Expand Down Expand Up @@ -944,6 +958,11 @@ const goto_inlinet::goto_functiont &goto_inlinet::goto_inline_transitive(

goto_functiont &cached=cache[identifier];
assert(cached.body.empty());

progress() << "Creating copy of " << identifier << eom;
progress() << "Number of instructions: "
<< goto_function.body.instructions.size() << eom;

cached.copy_from(goto_function); // location numbers not changed
inline_log.copy_from(goto_function.body, cached.body);

Expand Down Expand Up @@ -1146,6 +1165,29 @@ void goto_inlinet::output_inline_map(

/*******************************************************************\

Function: output_cache

Inputs:

Outputs:

Purpose:

\*******************************************************************/

void goto_inlinet::output_cache(std::ostream &out) const
{
for(auto it=cache.begin(); it!=cache.end(); it++)
{
if(it!=cache.begin())
out << ", ";

out << it->first << "\n";
}
}

/*******************************************************************\

Function: cleanup

Inputs:
Expand Down Expand Up @@ -1257,8 +1299,9 @@ void goto_inlinet::goto_inline_logt::copy_from(
assert(it1->location_number==it2->location_number);

log_mapt::const_iterator l_it=log_map.find(it1);
if(l_it!=log_map.end())
if(l_it!=log_map.end()) // a segment starts here
{
// as 'to' is a fresh copy
assert(log_map.find(it2)==log_map.end());

goto_inline_log_infot info=l_it->second;
Expand Down
10 changes: 8 additions & 2 deletions src/goto-programs/goto_inline_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ class goto_inlinet:public messaget
goto_functionst &goto_functions,
const namespacet &ns,
message_handlert &message_handler,
bool adjust_function):
bool adjust_function,
bool caching=true):
messaget(message_handler),
goto_functions(goto_functions),
ns(ns),
adjust_function(adjust_function)
adjust_function(adjust_function),
caching(caching)
{
}

Expand Down Expand Up @@ -64,6 +66,8 @@ class goto_inlinet:public messaget
std::ostream &out,
const inline_mapt &inline_map);

void output_cache(std::ostream &out) const;

// call after goto_functions.update()!
jsont output_inline_log_json()
{
Expand Down Expand Up @@ -127,6 +131,8 @@ class goto_inlinet:public messaget
const namespacet &ns;

const bool adjust_function;
const bool caching;

goto_inline_logt inline_log;

void goto_inline_nontransitive(
Expand Down