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;
212 patht &inserted_path)
234 inserted_path.push_back(
path_nodet(back_jump));
248 for(natural_loops_mutablet::natural_loopt::iterator it=loop.begin();
256 loop.insert(added.begin(), added.end());
260 t->make_assignment();
262 t->swap(*loop_header);
269 overflow_loc->
swap(*loop_end);
270 loop.insert(overflow_loc);
274 g.
targets.push_back(overflow_loc);
282 overflow_loc=loop_end;
290 for(subsumed_pathst::iterator it=
subsumed.begin();
294 if(!it->subsumed.empty())
298 std::cout <<
"Restricting path:\n";
305 patht double_accelerator;
306 patht::iterator jt=double_accelerator.begin();
307 double_accelerator.insert(
308 jt, it->accelerator.begin(), it->accelerator.end());
309 double_accelerator.insert(
310 jt, it->accelerator.begin(), it->accelerator.end());
314 std::cout <<
"Restricting path:\n";
317 automaton.
add_path(double_accelerator);
320 std::cout <<
"Building trace automaton...\n";
328 for(std::set<exprt>::iterator it=accelerator.
dirty_vars.begin();
344 dirty_var=jt->second;
348 std::cout <<
"Setting dirty flag " <<
expr2c(dirty_var,
ns)
349 <<
" for " <<
expr2c(*it,
ns) <<
'\n';
404 for(find_symbols_sett::iterator jt=read.begin();
425 for(std::set<exprt>::iterator it=accelerator.
dirty_vars.begin();
429 if(it->id()==ID_symbol && it->type() ==
bool_typet())
441 std::cout <<
"Underapproximate variable: " <<
expr2c(*it,
ns) <<
'\n';
481 assign->make_assignment();
501 <<
"Inserting trace automaton with " 503 << accept_states.size() <<
" accepting states and " 504 << transitions.size() <<
" transitions\n";
514 for(
const auto &sym : automaton.
alphabet)
527 trace_automatont::sym_mapt::iterator begin,
528 trace_automatont::sym_mapt::iterator end,
534 std::map<unsigned int, unsigned int> successor_counts;
535 unsigned int max_count=0;
536 unsigned int likely_next=0;
541 for(trace_automatont::sym_mapt::iterator p=begin; p!=end; ++p)
544 unsigned int to=state_pair.second;
545 unsigned int count=0;
547 if(successor_counts.find(to)==successor_counts.end())
553 count=successor_counts[to] + 1;
556 successor_counts[to]=count;
558 if(count > max_count)
567 if(successor_counts.size()==1)
569 if(accept_states.find(likely_next)!=accept_states.end())
576 state_machine.
assign(state,
583 state_machine.
assign(next_state,
586 for(trace_automatont::sym_mapt::iterator p=begin; p!=end; ++p)
589 unsigned int from=state_pair.first;
590 unsigned int to=state_pair.second;
608 state_machine.
assign(next_state, rhs);
612 state_machine.
assign(state, next_state);
614 for(state_sett::iterator it=accept_states.begin();
615 it!=accept_states.end();
625 int num_accelerated=0;
627 for(natural_loops_mutablet::loop_mapt::iterator it =
638 if(num_accelerated > 0)
640 std::cout <<
"Engaging crush mode...\n";
646 std::cout <<
"Crush mode engaged.\n";
649 return num_accelerated;
659 std::cout <<
"Accelerating function " << it->first <<
'\n';
661 it->second.body, goto_model, message_handler, use_z3);
665 if(num_accelerated > 0)
667 std::cout <<
"Added " << num_accelerated
668 <<
" accelerator(s)\n";
exprt guard
Guard for gotos, assume, assert.
void get_transitions(sym_mapt &transitions)
The type of an expression, extends irept.
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 instruction pointed-to by the given instruction iterator 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.
typet & type()
Return the type of the expression.
void accept_states(state_sett &states)
void set_dirty_vars(path_acceleratort &accelerator)
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 codet representing the 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
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool is_underapproximate(path_acceleratort &accelerator)
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
A side_effect_exprt that returns a non-deterministically chosen value.
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
std::list< patht > pathst
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
void add_path(patht &path)
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.
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
#define Forall_goto_functions(it, functions)
goto_programt pure_accelerator
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.
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 insert_accelerator(goto_programt::targett &loop_header, goto_programt::targett &back_jump, path_acceleratort &accelerator, subsumed_patht &subsumed_path)
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 documentation for namespace_baset::lookup().
A codet representing an assignment in the program.