cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
remove_unused_functions.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Unused function removal
4
5
Author: CM Wintersteiger
6
7
\*******************************************************************/
8
11
12
#include "
remove_unused_functions.h
"
13
14
#include <
util/message.h
>
15
16
#include "
goto_model.h
"
17
18
void
remove_unused_functions
(
19
goto_modelt
&goto_model,
20
message_handlert
&message_handler)
21
{
22
remove_unused_functions
(goto_model.
goto_functions
, message_handler);
23
}
24
25
void
remove_unused_functions
(
26
goto_functionst
&functions,
27
message_handlert
&message_handler)
28
{
29
std::set<irep_idt> used_functions;
30
std::list<goto_functionst::function_mapt::iterator> unused_functions;
31
find_used_functions
(
32
goto_functionst::entry_point
(), functions, used_functions);
33
34
for
(goto_functionst::function_mapt::iterator it=
35
functions.
function_map
.begin();
36
it!=functions.
function_map
.end();
37
it++)
38
{
39
if
(used_functions.find(it->first)==used_functions.end())
40
unused_functions.push_back(it);
41
}
42
43
messaget
message(message_handler);
44
45
if
(!unused_functions.empty())
46
{
47
message.
statistics
()
48
<<
"Dropping "
<< unused_functions.size() <<
" of "
<<
49
functions.
function_map
.size() <<
" functions ("
<<
50
used_functions.size() <<
" used)"
<<
messaget::eom
;
51
}
52
53
for
(
const
auto
&f : unused_functions)
54
functions.
function_map
.erase(f);
55
}
56
57
void
find_used_functions
(
58
const
irep_idt
&start,
59
goto_functionst
&functions,
60
std::set<irep_idt> &seen)
61
{
62
std::pair<std::set<irep_idt>::const_iterator,
bool
> res =
63
seen.insert(start);
64
65
if
(!res.second)
66
return
;
67
else
68
{
69
goto_functionst::function_mapt::const_iterator f_it =
70
functions.
function_map
.find(start);
71
72
if
(f_it!=functions.
function_map
.end())
73
{
74
for
(
const
auto
&instruction : f_it->second.body.instructions)
75
{
76
if
(instruction.is_function_call())
77
{
78
const
auto
&function = instruction.call_function();
79
80
const
irep_idt
&identifier =
81
to_symbol_expr
(function).
get_identifier
();
82
83
find_used_functions
(identifier, functions, seen);
84
}
85
}
86
}
87
}
88
}
goto_functionst
A collection of goto functions.
Definition
goto_functions.h:25
goto_functionst::function_map
function_mapt function_map
Definition
goto_functions.h:29
goto_functionst::entry_point
static irep_idt entry_point()
Get the identifier of the entry point to a goto model.
Definition
goto_functions.h:97
goto_modelt
Definition
goto_model.h:27
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition
goto_model.h:34
message_handlert
Definition
message.h:27
messaget
Class that provides messages with a built-in verbosity 'level'.
Definition
message.h:154
messaget::statistics
mstreamt & statistics() const
Definition
message.h:411
messaget::eom
static eomt eom
Definition
message.h:289
symbol_exprt::get_identifier
const irep_idt & get_identifier() const
Definition
std_expr.h:161
goto_model.h
Symbol Table + CFG.
remove_unused_functions
void remove_unused_functions(goto_modelt &goto_model, message_handlert &message_handler)
Definition
remove_unused_functions.cpp:18
find_used_functions
void find_used_functions(const irep_idt &start, goto_functionst &functions, std::set< irep_idt > &seen)
Definition
remove_unused_functions.cpp:57
remove_unused_functions.h
Unused function removal.
message.h
to_symbol_expr
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition
std_expr.h:211
irep_idt
dstringt irep_idt
Definition
verification_result.h:16
goto-programs
remove_unused_functions.cpp
Generated by
1.17.0