1/*******************************************************************\
5Author: Daniel Kroening, kroening@kroening.com
7\*******************************************************************/
29 for(dependence_grapht::edgest::const_iterator
41 goto_functionst::function_mapt::const_iterator
f_it =
47 f_it->second.body.instructions.begin();
50 for(
const auto &
in_edge : entry.in)
66 for(find_symbols_sett::const_iterator
71 decl_deadt::iterator entry=
decl_dead.find(*it);
75 while(!entry->second.empty())
91 // On slicing programs with jump statements
92 // Hiralal Agrawal, PLDI'94
94 // Slice = the slice obtained using the conventional slicing algorithm;
96 // Traverse the postdominator tree using the preorder traversal,
97 // and for each jump statement, J, encountered that is
98 // (i) not in Slice and
99 // (ii) whose nearest postdominator in Slice is different from
100 // the nearest lexical successor in Slice) do {
102 // Add the transitive closure of the dependences of J to Slice;
104 // } until no new jump statements may be added to Slice;
105 // For each goto statement, Goto L, in Slice, if the statement
106 // labeled L is not in Slice then associate the label L with its
107 // nearest postdominator in Slice;
115 jumpst::iterator next=it;
120 // is j in the slice already?
128 // check nearest lexical successor in slice
146 // find the nearest post-dominator in slice
154 // check whether the nearest post-dominator is different from
158 for(cfg_dominatorst::target_sett::const_iterator d_it =
164 if(node.node_required)
168 "goto/jump expected to be within a single function");
203 // process queue until empty
204 while(!queue.empty())
206 while(!queue.empty())
212 // already done by some earlier iteration?
213 if(node.node_required)
217 node.node_required=
true;
219 // add data and control dependencies of node
222 // retain all calls of the containing function
225 // find all the symbols it uses to add declarations
229 // add any required jumps
236 // some variables are used during symbolic execution only
238 const irep_idt &statement = target->code().get_statement();
242 if(!target->is_assign())
260 // build the CFG data structure
268 // fill queue with according to slicing criterion
270 // gather all unconditional jumps as they may need to be included
272 // declarations or dead instructions may be necessary as well
284 (instruction->is_goto() && instruction->condition() ==
true) ||
285 instruction->is_throw())
287 else if(instruction->is_decl())
289 const auto &s = instruction->decl_symbol();
292 else if(instruction->is_dead())
294 const auto &s = instruction->dead_symbol();
299 // compute program dependence graph (and post-dominators)
303 // compute the fixedpoint
306 // now replace those instructions that are not needed
311 if(
gf_entry.second.body_available())
317 !
i_it->is_end_function() &&
// always retained
320 i_it->turn_into_skip();
322#ifdef DEBUG_FULL_SLICERT
325 std::string
c=
"ins:"+std::to_string(
i_it->location_number);
327 for(std::set<unsigned>::const_iterator
req_it =
336 i_it->source_location.set_column(
c);
// for show-goto-functions
337 i_it->source_location.set_comment(
c);
// for dump-c
376 const std::list<std::string> &properties,
385 const std::list<std::string> &properties,
irep_idt rounding_mode_identifier()
Return the identifier of the program symbol used to store the current rounding mode.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
const entry_mapt & entries() const
Get a map from program points to their corresponding node indices.
base_grapht::node_indext entryt
nodet & get_node(const goto_programt::const_targett &program_point)
Get the CFG graph node relating to program_point.
entryt get_node_index(const goto_programt::const_targett &program_point) const
Get the graph node index for program_point.
std::map< irep_idt, cfg_post_dominatorst > post_dominators_mapt
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
void add_function_calls(const cfgt::nodet &node, queuet &queue, const goto_functionst &goto_functions)
std::list< cfgt::entryt > jumpst
void add_to_queue(queuet &queue, const cfgt::entryt &entry, goto_programt::const_targett reason)
std::unordered_map< irep_idt, queuet > decl_deadt
void add_dependencies(const cfgt::nodet &node, queuet &queue, const dependence_grapht &dep_graph, const dep_node_to_cfgt &dep_node_to_cfg)
void fixedpoint(goto_functionst &goto_functions, queuet &queue, jumpst &jumps, decl_deadt &decl_dead, const dependence_grapht &dep_graph)
void add_decl_dead(const cfgt::nodet &node, queuet &queue, decl_deadt &decl_dead)
void operator()(goto_functionst &goto_functions, const namespacet &ns, const slicing_criteriont &criterion, message_handlert &message_handler)
std::stack< cfgt::entryt > queuet
std::vector< cfgt::entryt > dep_node_to_cfgt
void add_jumps(queuet &queue, jumpst &jumps, const dependence_grapht::post_dominators_mapt &post_dominators)
A collection of goto functions.
function_mapt function_map
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
instructionst::const_iterator const_targett
nodet::node_indext node_indext
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
virtual ~slicing_criteriont()
Expression to hold a symbol (variable)
void identifier(const irep_idt &identifier)
static bool find_symbols(symbol_kindt, const typet &, std::function< bool(const symbol_exprt &)>, std::unordered_set< irep_idt > &bindings, const std::vector< irep_idt > &subs_to_find)
Find identifiers with id ID_symbol of the sub expressions and the subs with ID in subs_to_find consid...
std::unordered_set< irep_idt > find_symbols_sett
static bool implicit(goto_programt::const_targett target)
void property_slicer(goto_functionst &goto_functions, const namespacet &ns, const std::list< std::string > &properties, message_handlert &message_handler)
void full_slicer(goto_functionst &goto_functions, const namespacet &ns, const slicing_criteriont &criterion, message_handlert &message_handler)
#define forall_goto_program_instructions(it, program)
#define Forall_goto_program_instructions(it, program)
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
#define CHECK_RETURN(CONDITION)
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.