41 for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin();
48 t->targets.size()==1 &&
49 t->targets.front()==loop_header &&
50 t->location_number > back_jump->location_number)
64 for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin();
70 if(t->is_backwards_goto())
72 if(t->targets.size()!=1 ||
73 t->get_target()!=loop_header)
91 pathst loop_paths, exit_paths;
93 int num_accelerated=0;
94 std::list<path_acceleratort> accelerators;
102 std::cout <<
"Not accelerating an outer loop\n";
137 std::cout <<
"Not inserting accelerator because of underapproximation\n";
143 accelerators.push_back(accelerator);
147 std::cout <<
"Accelerated path:\n";
150 std::cout <<
"Accelerator has " 152 <<
" instructions\n";
162 loop.insert(new_inst);
165 std::cout <<
"Overflow loc is " << overflow_loc->location_number <<
'\n';
166 std::cout <<
"Back jump is " << back_jump->location_number <<
'\n';
168 for(std::list<path_acceleratort>::iterator it=accelerators.begin();
169 it!=accelerators.end();
179 return num_accelerated;
209 patht &inserted_path)
231 inserted_path.push_back(
path_nodet(back_jump));
245 for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin();
253 loop.insert(added.begin(), added.end());
257 t->make_assignment();
259 t->swap(*loop_header);
266 overflow_loc->
swap(*loop_end);
267 loop.insert(overflow_loc);
271 g.
targets.push_back(overflow_loc);
279 overflow_loc=loop_end;
287 for(subsumed_pathst::iterator it=
subsumed.begin();
291 if(!it->subsumed.empty())
295 std::cout <<
"Restricting path:\n";
302 patht double_accelerator;
303 patht::iterator jt=double_accelerator.begin();
304 double_accelerator.insert(
305 jt, it->accelerator.begin(), it->accelerator.end());
306 double_accelerator.insert(
307 jt, it->accelerator.begin(), it->accelerator.end());
311 std::cout <<
"Restricting path:\n";
314 automaton.
add_path(double_accelerator);
317 std::cout <<
"Building trace automaton...\n";
325 for(std::set<exprt>::iterator it=accelerator.
dirty_vars.begin();
341 dirty_var=jt->second;
345 std::cout <<
"Setting dirty flag " <<
expr2c(dirty_var,
ns)
346 <<
" for " <<
expr2c(*it,
ns) <<
'\n';
401 for(find_symbols_sett::iterator jt=read.begin();
422 for(std::set<exprt>::iterator it=accelerator.
dirty_vars.begin();
426 if(it->id()==ID_symbol && it->type() ==
bool_typet())
438 std::cout <<
"Underapproximate variable: " <<
expr2c(*it,
ns) <<
'\n';
478 assign->make_assignment();
498 <<
"Inserting trace automaton with " 500 << accept_states.size() <<
" accepting states and " 501 << transitions.size() <<
" transitions\n";
511 for(
const auto &sym : automaton.
alphabet)
524 trace_automatont::sym_mapt::iterator begin,
525 trace_automatont::sym_mapt::iterator end,
531 std::map<unsigned int, unsigned int> successor_counts;
532 unsigned int max_count=0;
533 unsigned int likely_next=0;
538 for(trace_automatont::sym_mapt::iterator p=begin; p!=end; ++p)
541 unsigned int to=state_pair.second;
542 unsigned int count=0;
544 if(successor_counts.find(to)==successor_counts.end())
550 count=successor_counts[to] + 1;
553 successor_counts[to]=count;
555 if(count > max_count)
564 if(successor_counts.size()==1)
566 if(accept_states.find(likely_next)!=accept_states.end())
573 state_machine.
assign(state,
580 state_machine.
assign(next_state,
583 for(trace_automatont::sym_mapt::iterator p=begin; p!=end; ++p)
586 unsigned int from=state_pair.first;
587 unsigned int to=state_pair.second;
605 state_machine.
assign(next_state, rhs);
609 state_machine.
assign(state, next_state);
611 for(state_sett::iterator it=accept_states.begin();
612 it!=accept_states.end();
622 int num_accelerated=0;
624 for(natural_loops_mutablet::loop_mapt::iterator it =
635 if(num_accelerated > 0)
637 std::cout <<
"Engaging crush mode...\n";
643 std::cout <<
"Crush mode engaged.\n";
646 return num_accelerated;
656 std::cout <<
"Accelerating function " << it->first <<
'\n';
662 if(num_accelerated > 0)
664 std::cout <<
"Added " << num_accelerated
665 <<
" accelerator(s)\n";
exprt guard
Guard for gotos, assume, assert.
void get_transitions(sym_mapt &transitions)
The type of an expression.
irep_idt name
The unique identifier.
void insert_automaton(trace_automatont &automaton)
void update()
Update all indices.
void make_overflow_loc(goto_programt::targett loop_header, goto_programt::targett &loop_end, goto_programt::targett &overflow_loc)
void insert_before_swap(targett target)
Insertion that preserves jumps to "target".
std::list< targett > targetst
targett assign(const exprt &lhs, const exprt &rhs)
natural_loops_mutablet natural_loops
static const int accelerate_limit
targett insert_before(const_targett target)
Insertion before the given target.
void insert_looping_path(goto_programt::targett &loop_header, goto_programt::targett &back_jump, goto_programt &looping_path, patht &inserted_path)
goto_functionst & goto_functions
bool contains_nested_loops(goto_programt::targett &loop_header)
void add_overflow_checks()
const irep_idt & get_identifier() const
Goto Programs with Functions.
message_handlert & message_handler
std::set< goto_programt::targett > natural_loopt
int accelerate_loop(goto_programt::targett &loop_header)
The trinary if-then-else operator.
irep_idt module
Name of module the symbol belongs to.
irep_idt pretty_name
Language-specific display name.
void accept_states(state_sett &states)
void set_dirty_vars(path_acceleratort &accelerator)
Symbol table entry.This is a symbol in the symbol table, stored in an object of type symbol_tablet...
std::pair< statet, statet > state_pairt
symbol_tablet & symbol_table
targetst targets
The list of successor instructions.
goto_programt overflow_path
This class represents an instruction in the GOTO intermediate representation.
void accelerate_functions(goto_modelt &goto_model, message_handlert &message_handler, bool use_z3)
bool accelerate(path_acceleratort &accelerator)
std::pair< sym_mapt::iterator, sym_mapt::iterator > sym_range_pairt
class symbol_exprt symbol_expr() const
produces a symbol_exprt for a symbol
The boolean constant true.
unsignedbv_typet unsigned_poly_type()
instructionst::iterator targett
A declaration of a local variable.
targett assume(const exprt &guard)
symbolt fresh_symbol(std::string base, typet type)
instructionst instructions
The list of instructions in the goto program.
API to expression classes.
std::list< path_nodet > patht
bool is_underapproximate(path_acceleratort &accelerator)
targett insert_after(const_targett target)
Insertion after the given target.
A side effect that returns a non-deterministically chosen value.
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program at the given location.
std::list< patht > pathst
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast a generic exprt to a symbol_exprt.
void add_path(patht &path)
void insert_accelerator(goto_programt::targett &loop_header, goto_programt::targett &back_jump, path_acceleratort &accelerator, subsumed_patht &subsumed)
dstringt has one field, an unsigned integer no which is an index into a static table of strings...
std::set< statet > state_sett
The boolean constant false.
symbolt make_symbol(std::string name, typet type)
goto_programt::targett find_back_jump(goto_programt::targett loop_header)
const source_locationt & source_location() const
A generic container class for the GOTO intermediate representation of one function.
void decl(symbol_exprt &sym, goto_programt::targett t)
void output_path(const patht &path, const goto_programt &program, const namespacet &ns, std::ostream &str)
typet type
Type of symbol.
std::multimap< goto_programt::targett, state_pairt > sym_mapt
std::set< exprt > dirty_vars
targett add_instruction()
Adds an instruction at the end.
Base class for all expressions.
overflow_mapt overflow_locs
irep_idt base_name
Base (non-scoped) name.
#define Forall_goto_functions(it, functions)
goto_programt pure_accelerator
std::string expr2c(const exprt &expr, const namespacet &ns)
void swap(instructiont &instruction)
Swap two instructions.
void build_state_machine(trace_automatont::sym_mapt::iterator p, trace_automatont::sym_mapt::iterator end, state_sett &accept_states, symbol_exprt state, symbol_exprt next_state, scratch_programt &state_machine)
Expression to hold a symbol (variable)
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Compute natural loops in a goto_function.
goto_programt coverage_criteriont message_handlert & message_handler
std::unordered_set< irep_idt > find_symbols_sett
acceleration_utilst utils
const symbolt * lookup(const irep_idt &name) const
Find a symbol in the symbol table for read-only access.
void find_symbols(const exprt &src, find_symbols_sett &dest)
goto_functionst goto_functions
GOTO functions.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See namespace_baset::lookup().