42 for(patht::iterator it=loop.begin();
46 body.push_back(*(it->loc));
50 std::map<exprt, polynomialt> polynomials;
57 std::cout <<
"Polynomial accelerating program:\n";
59 for(goto_programt::instructionst::iterator it=body.begin();
63 it->output(std::cout);
66 std::cout <<
"Modified:\n";
68 for(expr_sett::iterator it=targets.begin();
72 std::cout <<
expr2c(*it,
ns) <<
'\n';
76 for(goto_programt::instructionst::iterator it=body.begin();
80 if(it->is_assign() || it->is_decl())
82 assigns.push_back(*it);
93 for(expr_sett::iterator it=targets.begin();
110 if(influence.find(target)==influence.end())
113 std::cout <<
"Found nonrecursive expression: "
121 if(target.
id()==ID_index ||
122 target.
id()==ID_dereference)
131 std::map<exprt, polynomialt> this_poly;
132 this_poly[target]=poly;
136 polynomials.insert(std::make_pair(target, poly));
142 std::cout <<
"Failed to fit a polynomial for "
150 if(polynomials.empty())
167 bool path_is_monotone;
174 catch(
const std::string &s)
177 std::cout <<
"Assumptions error: " << s <<
'\n';
183 for(std::map<exprt, polynomialt>::iterator it=polynomials.begin();
184 it!=polynomials.end();
187 replace_expr(it->first, it->second.to_expr(), guard_last);
236 for(std::map<exprt, polynomialt>::iterator it=polynomials.begin();
237 it!=polynomials.end();
240 program.assign(it->first, it->second.to_expr());
250 std::cout <<
"Failed to accelerate a nonrecursive expression\n";
275 std::vector<expr_listt> parameters;
276 std::set<std::pair<expr_listt, exprt> > coefficients;
284 std::cout <<
"Fitting a polynomial for " <<
expr2c(var,
ns)
285 <<
", which depends on:\n";
287 for(expr_sett::iterator it=influence.begin();
291 std::cout <<
expr2c(*it,
ns) <<
'\n';
295 for(expr_sett::iterator it=influence.begin();
299 if(it->id()==ID_index ||
300 it->id()==ID_dereference)
308 exprs.push_back(*it);
309 parameters.push_back(exprs);
312 parameters.push_back(exprs);
318 parameters.push_back(exprs);
326 parameters.push_back(exprs);
337 for(std::vector<expr_listt>::iterator it=parameters.begin();
338 it!=parameters.end();
343 coefficients.insert(std::make_pair(*it, coeff.
symbol_expr()));
355 std::map<exprt, int> values;
357 for(expr_sett::iterator it=influence.begin();
365 std::cout <<
"Fitting polynomial over " << values.size()
369 for(
int n=0; n<=2; n++)
371 for(expr_sett::iterator it=influence.begin();
385 for(expr_sett::iterator it=influence.begin();
395 std::cout <<
"Fitting polynomial with program:\n";
412 catch(
const std::string &s)
414 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
418 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
459 std::cout <<
"Fitting constant, eval'd to: "
469 mon.
terms.push_back(term);
470 mon.
coeff=mp.to_long();
477 catch(
const std::string &s)
479 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
483 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
492 std::map<exprt, int> &values,
493 std::set<std::pair<expr_listt, exprt> > &coefficients,
500 std::optional<typet> expr_type;
502 for(std::map<exprt, int>::iterator it=values.begin();
506 typet this_type=it->first.type();
507 if(this_type.
id()==ID_pointer)
510 std::cout <<
"Overriding pointer type\n";
515 if(!expr_type.has_value())
521 expr_type =
join_types(*expr_type, this_type);
527 "joined types must be non-empty bitvector types");
530 for(std::map<exprt, int>::iterator it=values.begin();
538 for(
int i=0; i < num_unwindings; i++)
540 program.
append(loop_body);
546 for(std::set<std::pair<expr_listt, exprt> >::iterator it=coefficients.begin();
547 it!=coefficients.end();
550 int concrete_value=1;
552 for(expr_listt::const_iterator e_it=it->first.begin();
553 e_it!=it->first.end();
560 concrete_value *= num_unwindings;
564 std::map<exprt, int>::iterator v_it=values.
find(e);
566 if(v_it!=values.end())
568 concrete_value *= v_it->second;
612 for(goto_programt::instructionst::reverse_iterator r_it=orig_body.rbegin();
613 r_it!=orig_body.rend();
616 if(r_it->is_assign())
622 exprt assignment_lhs = r_it->assign_lhs();
623 exprt assignment_rhs = r_it->assign_rhs();
628 for(expr_sett::iterator s_it=lhs_syms.begin();
629 s_it!=lhs_syms.end();
632 if(cone.find(*s_it)!=cone.end())
636 body.push_front(*r_it);
637 cone.erase(assignment_lhs);
647 std::map<exprt, polynomialt> polynomials,
662 std::vector<exprt> polynomials_hold;
667 for(std::map<exprt, polynomialt>::iterator it=polynomials.begin();
668 it!=polynomials.end();
671 const equal_exprt holds(it->first, it->second.to_expr());
674 polynomials_hold.push_back(holds);
677 program.append(body);
684 for(std::vector<exprt>::iterator it=polynomials_hold.begin();
685 it!=polynomials_hold.end();
692 std::cout <<
"Checking following program for inductiveness:\n";
702 std::cout <<
"Not inductive!\n";
711 catch(
const std::string &s)
713 std::cout <<
"Error in inductiveness SAT check: " << s <<
'\n';
718 std::cout <<
"Error in inductiveness SAT check: " << s <<
'\n';
725 std::map<exprt, polynomialt> &polynomials,
733 for(std::map<exprt, polynomialt>::iterator it=polynomials.begin();
734 it!=polynomials.end();
737 it->second.substitute(substitution);
753 for(patht::reverse_iterator r_it=path.rbegin();
762 const exprt &lhs = t->assign_lhs();
763 const exprt &rhs = t->assign_rhs();
765 if(lhs.
id()==ID_symbol)
769 else if(lhs.
id()==ID_index ||
770 lhs.
id()==ID_dereference)
779 else if(t->is_assume() || t->is_assert())
788 if(!r_it->guard.is_true() && !r_it->guard.is_nil())
std::list< exprt > expr_listt
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
static exprt guard(const exprt::operandst &guards, exprt cond)
void find_modified(const patht &path, expr_sett &modified)
bool do_nonrecursive(goto_programt::instructionst &loop_body, std::map< exprt, polynomialt > &polynomials, substitutiont &substitution, expr_sett &nonrecursive, scratch_programt &program)
void extract_polynomial(scratch_programt &program, std::set< std::pair< expr_listt, exprt >> &coefficients, polynomialt &polynomial)
bool check_inductive(std::map< exprt, polynomialt > polynomials, patht &path, guard_managert &guard_manager)
void gather_rvalues(const exprt &expr, expr_sett &rvalues)
symbolt fresh_symbol(std::string base, typet type)
bool do_assumptions(std::map< exprt, polynomialt > polynomials, patht &body, exprt &guard, guard_managert &guard_manager)
void ensure_no_overflows(scratch_programt &program)
void stash_variables(scratch_programt &program, expr_sett modified, substitutiont &substitution)
A base class for relations, i.e., binary predicates whose two operands have the same type.
std::size_t get_width() const
A goto_instruction_codet representing an assignment in the program.
A constant literal expression.
const irep_idt & get_value() const
const char * c_str() const
Base class for all expressions.
const source_locationt & source_location() const
typet & type()
Return the type of the expression.
The Boolean constant false.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
instructionst::const_iterator const_targett
targett add_instruction()
Adds an instruction at the end.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
std::list< instructiont > instructionst
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
const irept & find(const irep_idt &name) const
const irep_idt & id() const
std::vector< termt > terms
Binary multiplication Associativity is not specified.
void overflow_expr(const exprt &expr, expr_sett &cases)
std::set< exprt > dirty_vars
goto_programt pure_accelerator
The plus expression Associativity is not specified.
acceleration_utilst utils
symbol_table_baset & symbol_table
void stash_polynomials(scratch_programt &program, std::map< exprt, polynomialt > &polynomials, std::map< exprt, exprt > &stashed, goto_programt::instructionst &body)
bool fit_polynomial_sliced(goto_programt::instructionst &sliced_body, exprt &target, expr_sett &influence, polynomialt &polynomial)
bool accelerate(patht &loop, path_acceleratort &accelerator)
bool check_inductive(std::map< exprt, polynomialt > polynomials, goto_programt::instructionst &body)
void assert_for_values(scratch_programt &program, std::map< exprt, int > &values, std::set< std::pair< expr_listt, exprt >> &coefficients, int num_unwindings, goto_programt::instructionst &loop_body, exprt &target, overflow_instrumentert &overflow)
bool fit_const(goto_programt::instructionst &loop_body, exprt &target, polynomialt &polynomial)
void cone_of_influence(goto_programt::instructionst &orig_body, exprt &target, goto_programt::instructionst &body, expr_sett &influence)
bool fit_polynomial(goto_programt::instructionst &loop_body, exprt &target, polynomialt &polynomial)
guard_managert & guard_manager
exprt precondition(patht &path)
message_handlert & message_handler
std::vector< monomialt > monomials
bool check_sat(bool do_slice, guard_managert &guard_manager)
targett assign(const exprt &lhs, const exprt &rhs)
void append(goto_programt::instructionst &instructions)
exprt eval(const exprt &e)
A side_effect_exprt that returns a non-deterministically chosen value.
Fixed-width bit-vector with two's complement interpretation.
Expression to hold a symbol (variable)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
Semantic type conversion.
The type of an expression, extends irept.
std::unordered_set< exprt, irep_hash > expr_sett
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
const mp_integer binary2integer(const std::string &n, bool is_signed)
convert binary string representation to mp_integer
std::list< path_nodet > patht
std::map< exprt, exprt > substitutiont
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
bool simplify(exprt &expr, const namespacet &ns)
#define CHECK_RETURN(CONDITION)
const constant_exprt & to_constant_expr(const exprt &expr)
Cast an exprt to a constant_exprt.
typet join_types(const typet &t1, const typet &t2)
Return the smallest type that both t1 and t2 can be cast to without losing information.
unsignedbv_typet unsigned_poly_type()
bool is_bitvector(const typet &t)
Convenience function – is the type a bitvector of some kind?