40 std::map<exprt, polynomialt> polynomials;
46 std::cout <<
"Polynomial accelerating program:\n";
48 for(goto_programt::instructionst::iterator
54 it->output(std::cout);
57 std::cout <<
"Modified:\n";
59 for(expr_sett::iterator it=
modified.begin();
63 std::cout <<
format(*it) <<
'\n';
84 for(expr_sett::iterator it=
modified.begin();
97 if(target.
id()==ID_index ||
98 target.
id()==ID_dereference)
106 std::map<exprt, polynomialt> this_poly;
107 this_poly[target]=poly;
112 std::cout <<
"Fitted a polynomial for " <<
format(target)
115 polynomials[target]=poly;
122 if(polynomials.empty())
135 for(patht::iterator it=accelerator.
path.begin();
136 it!=accelerator.
path.end();
139 if(it->loc->is_assign() || it->loc->is_decl())
141 assigns.push_back(*(it->loc));
145 for(expr_sett::iterator it=dirty.begin();
150 std::cout <<
"Trying to accelerate " <<
format(*it) <<
'\n';
158 std::cout <<
"Ignoring boolean\n";
163 if(it->id()==ID_index ||
164 it->id()==ID_dereference)
167 std::cout <<
"Ignoring array reference\n";
176 std::cout <<
"We've accelerated it already\n";
187 std::cout <<
"Ignoring because it depends on an array\n";
198 std::map<exprt, polynomialt> this_poly;
199 this_poly[target]=poly;
203 polynomials[target]=poly;
210 std::cout <<
"Failed to accelerate " <<
format(*it) <<
'\n';
230 bool path_is_monotone;
237 catch(
const std::string &s)
240 std::cout <<
"Assumptions error: " << s <<
'\n';
246 for(std::map<exprt, polynomialt>::iterator it=polynomials.begin();
247 it!=polynomials.end();
296 for(std::map<exprt, polynomialt>::iterator it=polynomials.begin();
297 it!=polynomials.end();
300 program.assign(it->first, it->second.to_expr());
329 program.append(
fixed);
330 program.append(
fixed);
339 for(distinguish_valuest::iterator jt=it->begin();
343 exprt distinguisher=jt->first;
344 bool taken=jt->second;
349 distinguisher.
swap(negated);
352 or_exprt disjunct(new_path, distinguisher);
353 new_path.
swap(disjunct);
356 program.assume(new_path);
366 std::cout <<
"Found a path\n";
374 catch(
const std::string &s)
376 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
380 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
392 std::vector<expr_listt> parameters;
393 std::set<std::pair<expr_listt, exprt> > coefficients;
401 std::cout <<
"Fitting a polynomial for " <<
format(var)
402 <<
", which depends on:\n";
404 for(expr_sett::iterator it=influence.begin();
408 std::cout <<
format(*it) <<
'\n';
412 for(expr_sett::iterator it=influence.begin();
416 if(it->id()==ID_index ||
417 it->id()==ID_dereference)
426 exprs.push_back(*it);
427 parameters.push_back(exprs);
430 parameters.push_back(exprs);
436 parameters.push_back(exprs);
440 parameters.push_back(exprs);
444 parameters.push_back(exprs);
446 for(std::vector<expr_listt>::iterator it=parameters.begin();
447 it!=parameters.end();
451 coefficients.insert(make_pair(*it, coeff.
symbol_expr()));
472 std::map<exprt, exprt> ivals1;
473 std::map<exprt, exprt> ivals2;
474 std::map<exprt, exprt> ivals3;
476 for(expr_sett::iterator it=influence.begin();
525 std::map<exprt, exprt> values;
527 for(expr_sett::iterator it=influence.begin();
531 values[*it]=ivals1[*it];
536 for(std::list<symbol_exprt>::iterator it =
distinguishers.begin();
546 for(
int n=0; n <= 1; n++)
548 for(expr_sett::iterator it=influence.begin();
552 values[*it]=ivals2[*it];
555 values[*it]=ivals3[*it];
558 values[*it]=ivals1[*it];
562 for(expr_sett::iterator it=influence.begin();
566 values[*it]=ivals3[*it];
580 for(distinguish_valuest::iterator jt=it->begin();
584 exprt distinguisher=jt->first;
585 bool taken=jt->second;
590 distinguisher.
swap(negated);
593 or_exprt disjunct(new_path, distinguisher);
594 new_path.
swap(disjunct);
597 program.assume(new_path);
612 std::cout <<
"Found a polynomial\n";
622 catch(
const std::string &s)
624 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
628 std::cout <<
"Error in fitting polynomial SAT check: " << s <<
'\n';
636 std::map<exprt, exprt> &values,
637 std::set<std::pair<expr_listt, exprt> > &coefficients,
643 std::optional<typet> expr_type;
645 for(std::map<exprt, exprt>::iterator it=values.begin();
649 if(!expr_type.has_value())
651 expr_type=it->first.type();
655 expr_type =
join_types(*expr_type, it->first.type());
660 for(std::map<exprt, exprt>::iterator it=values.begin();
664 program.
assign(it->first, it->second);
668 for(
int i=0; i<num_unwindings; i++)
670 program.
append(loop_body);
676 for(std::set<std::pair<expr_listt, exprt> >::iterator it=coefficients.begin();
677 it!=coefficients.end();
682 for(expr_listt::const_iterator e_it=it->first.begin();
683 e_it!=it->first.end();
691 from_integer(num_unwindings, *expr_type), concrete_value);
692 mult.
swap(concrete_value);
696 std::map<exprt, exprt>::iterator v_it=values.find(e);
700 mult_exprt mult(concrete_value, v_it->second);
701 mult.
swap(concrete_value);
741 for(
const auto &loop_instruction :
loop)
749 for(
const auto &jt : succs)
774 "we should have a looping path, so we should never hit a location "
775 "with no successors.");
787 bool found_branch=
false;
789 for(
const auto &succ : succs)
792 bool taken=scratch_program.
eval(distinguisher).
is_true();
797 (succ->location_number < next->location_number))
817 for(goto_programt::targetst::iterator it=t->targets.begin();
818 it!=t->targets.end();
823 cond = t->condition();
843 std::map<exprt, exprt> shadow_distinguishers;
849 if(instruction.is_assert())
850 instruction.turn_into_assume();
872 for(std::list<symbol_exprt>::iterator it =
distinguishers.begin();
876 exprt &distinguisher=*it;
880 shadow_distinguishers[distinguisher]=shadow;
899 fixedt->turn_into_skip();
907 exprt &distinguisher=d->second;
908 exprt &shadow=shadow_distinguishers[distinguisher];
914 assign->swap(*fixedt);
930 for(
const auto &target : t->targets)
932 if(target->location_number > t->location_number)
943 fixedt->targets.clear();
944 fixedt->targets.push_back(
kill);
954 fixedt->targets.clear();
955 fixedt->targets.push_back(end);
960 fixedt->targets.clear();
961 fixedt->targets.push_back(
kill);
974 const exprt &shadow=shadow_distinguishers[expr];
991 for(std::list<symbol_exprt>::iterator it =
distinguishers.begin();
1009 for(expr_sett::iterator it=influence.begin();
1010 it!=influence.end();
1013 if(it->id()==ID_index ||
1014 it->id()==ID_dereference)
std::list< exprt > expr_listt
static exprt guard(const exprt::operandst &guards, exprt cond)
void find_modified(const patht &path, expr_sett &modified)
bool do_arrays(goto_programt::instructionst &loop_body, std::map< exprt, polynomialt > &polynomials, substitutiont &substitution, scratch_programt &program)
void stash_polynomials(scratch_programt &program, std::map< exprt, polynomialt > &polynomials, std::map< exprt, exprt > &stashed, patht &path)
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)
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)
A base class for relations, i.e., binary predicates whose two operands have the same type.
A goto_instruction_codet representing an assignment in the program.
void cone_of_influence(const expr_sett &targets, expr_sett &cone)
goto_functionst & goto_functions
std::list< distinguish_valuest > accelerated_paths
guard_managert & guard_manager
std::list< symbol_exprt > distinguishers
bool depends_on_array(const exprt &e, exprt &array)
symbol_table_baset & symbol_table
message_handlert & message_handler
void assert_for_values(scratch_programt &program, std::map< exprt, exprt > &values, std::set< std::pair< expr_listt, exprt > > &coefficients, int num_unwindings, goto_programt &loop_body, exprt &target)
natural_loops_mutablet::natural_loopt & loop
void record_path(scratch_programt &scratch_program)
goto_programt::targett loop_header
goto_programt & goto_program
bool fit_polynomial(exprt &target, polynomialt &polynomial, patht &path)
bool accelerate(path_acceleratort &accelerator)
bool find_path(patht &path)
distinguish_mapt distinguishing_points
void cone_of_influence(const exprt &target, expr_sett &cone)
void find_distinguishing_points()
void build_path(scratch_programt &scratch_program, patht &path)
acceleration_utilst utils
std::map< exprt, bool > distinguish_valuest
Base class for all expressions.
bool is_true() const
Return whether the expression is a constant representing true.
typet & type()
Return the type of the expression.
The Boolean constant false.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
void copy_from(const goto_programt &src)
Copy a full goto program, preserving targets.
void update()
Update all indices.
instructionst::iterator targett
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
std::list< instructiont > instructionst
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
targett insert_after(const_targett target)
Insertion after the instruction pointed-to by the given instruction iterator target.
std::list< Target > get_successors(Target target) const
Get control-flow successors of a given instruction.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_decl(const symbol_exprt &symbol, const source_locationt &l=source_locationt::nil())
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
targett insert_before(const_targett target)
Insertion before the instruction pointed-to by the given instruction iterator target.
const irep_idt & id() const
irept & add(const irep_idt &name)
virtual bool contains(const T instruction) const
Returns true if instruction is in this loop.
Binary multiplication Associativity is not specified.
std::set< exprt > changed_vars
std::set< exprt > dirty_vars
goto_programt pure_accelerator
The plus expression Associativity is not specified.
bool fit_polynomial(goto_programt::instructionst &loop_body, exprt &target, polynomialt &polynomial)
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.
The Boolean constant true.
Semantic type conversion.
std::unordered_set< exprt, irep_hash > expr_sett
std::list< path_nodet > patht
std::map< exprt, exprt > substitutiont
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
int kill(pid_t pid, int sig)
bool simplify(exprt &expr, const namespacet &ns)
#define PRECONDITION(CONDITION)
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()
signedbv_typet signed_poly_type()