-
Notifications
You must be signed in to change notification settings - Fork 273
Remove functions that are not reachable from the entry point #486
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
/*******************************************************************\ | ||
|
||
Function: call_grapht::call_grapht | ||
Function: call_grapht::operator() | ||
|
||
Inputs: | ||
|
||
|
@@ -23,23 +23,7 @@ Function: call_grapht::call_grapht | |
|
||
\*******************************************************************/ | ||
|
||
call_grapht::call_grapht() | ||
{ | ||
} | ||
|
||
/*******************************************************************\ | ||
|
||
Function: call_grapht::call_grapht | ||
|
||
Inputs: | ||
|
||
Outputs: | ||
|
||
Purpose: | ||
|
||
\*******************************************************************/ | ||
|
||
call_grapht::call_grapht(const goto_functionst &goto_functions) | ||
void call_grapht::operator()() | ||
{ | ||
forall_goto_functions(f_it, goto_functions) | ||
{ | ||
|
@@ -96,6 +80,53 @@ void call_grapht::add( | |
|
||
/*******************************************************************\ | ||
|
||
Function: call_grapht::compute_reachable | ||
|
||
Inputs: | ||
|
||
Outputs: | ||
|
||
Purpose: | ||
|
||
\*******************************************************************/ | ||
|
||
void call_grapht::compute_reachable( | ||
const irep_idt entry_point, | ||
std::unordered_set<irep_idt, irep_id_hash> &reachable_functions) | ||
{ | ||
assert(reachable_functions.empty()); | ||
|
||
std::list<irep_idt> worklist; | ||
|
||
const goto_functionst::function_mapt::const_iterator e_it= | ||
goto_functions.function_map.find(entry_point); | ||
|
||
assert(e_it!=goto_functions.function_map.end()); | ||
|
||
worklist.push_back(entry_point); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add: |
||
|
||
do | ||
{ | ||
const irep_idt id=worklist.front(); | ||
worklist.pop_front(); | ||
|
||
reachable_functions.insert(id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this one. |
||
|
||
const auto &p=graph.equal_range(id); | ||
|
||
for(auto it=p.first; it!=p.second; it++) | ||
{ | ||
const irep_idt callee=it->second; | ||
|
||
if(reachable_functions.find(callee)==reachable_functions.end()) | ||
worklist.push_back(callee); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace by
to avoid duplicate lookups. |
||
} | ||
} | ||
while(!worklist.empty()); | ||
} | ||
|
||
/*******************************************************************\ | ||
|
||
Function: call_grapht::output_dot | ||
|
||
Inputs: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,14 +11,17 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <iosfwd> | ||
#include <map> | ||
#include <unordered_set> | ||
|
||
#include <goto-programs/goto_functions.h> | ||
|
||
class call_grapht | ||
{ | ||
public: | ||
call_grapht(); | ||
explicit call_grapht(const goto_functionst &); | ||
explicit call_grapht(const goto_functionst &goto_functions) : | ||
goto_functions(goto_functions) {} | ||
|
||
void operator()(); | ||
|
||
void output_dot(std::ostream &out) const; | ||
void output(std::ostream &out) const; | ||
|
@@ -29,7 +32,13 @@ class call_grapht | |
|
||
void add(const irep_idt &caller, const irep_idt &callee); | ||
|
||
void compute_reachable( | ||
const irep_idt entry_point, | ||
std::unordered_set<irep_idt, irep_id_hash> &reachable_functions); | ||
|
||
protected: | ||
const goto_functionst &goto_functions; | ||
|
||
void add(const irep_idt &function, | ||
const goto_programt &body); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +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)" \ | ||
"(remove-unreachable-functions)" \ | ||
"(inline)(partial-inline)(function-inline):(log):" \ | ||
"(remove-function-pointers)" \ | ||
"(show-claims)(show-properties)(property):" \ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is goto-programs/compute_called_functions.cpp - the code of which will also take into account functions the address of which is taken.