cprover
polynomial_accelerator.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Loop Acceleration
4 
5 Author: Matt Lewis
6 
7 \*******************************************************************/
8 
11 
12 #ifndef CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_ACCELERATOR_H
13 #define CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_ACCELERATOR_H
14 
15 #include <map>
16 #include <set>
17 
18 #include <util/symbol_table.h>
19 
22 
23 #include "scratch_program.h"
24 #include "polynomial.h"
25 #include "path.h"
26 #include "accelerator.h"
27 #include "acceleration_utils.h"
28 #include "cone_of_influence.h"
29 #include "overflow_instrumenter.h"
30 
32 {
33 public:
36  const symbol_tablet &_symbol_table,
37  const goto_functionst &_goto_functions)
39  symbol_table(const_cast<symbol_tablet &>(_symbol_table)),
41  goto_functions(_goto_functions),
43  {
45  }
46 
49  const symbol_tablet &_symbol_table,
50  const goto_functionst &_goto_functions,
51  exprt &_loop_counter)
53  symbol_table(const_cast<symbol_tablet &>(_symbol_table)),
55  goto_functions(_goto_functions),
57  loop_counter(_loop_counter)
58  {
59  }
60 
61  virtual bool accelerate(patht &loop, path_acceleratort &accelerator);
62 
63  bool fit_polynomial(
65  exprt &target,
66  polynomialt &polynomial);
67 
68 protected:
70 
72  goto_programt::instructionst &sliced_body,
73  exprt &target,
74  expr_sett &influence,
75  polynomialt &polynomial);
76 
77  void assert_for_values(
78  scratch_programt &program,
79  std::map<exprt, int> &values,
80  std::set<std::pair<expr_listt, exprt>> &coefficients,
81  int num_unwindings,
83  exprt &target,
84  overflow_instrumentert &overflow);
85  void extract_polynomial(
86  scratch_programt &program,
87  std::set<std::pair<expr_listt, exprt>> &coefficients,
88  polynomialt &polynomial);
89  void cone_of_influence(
91  exprt &target,
93  expr_sett &influence);
94 
95  bool fit_const(
97  exprt &target,
98  polynomialt &polynomial);
99 
100  bool check_inductive(
101  std::map<exprt, polynomialt> polynomials,
103  void stash_variables(
104  scratch_programt &program,
105  expr_sett modified,
106  substitutiont &substitution);
107  void stash_polynomials(
108  scratch_programt &program,
109  std::map<exprt, polynomialt> &polynomials,
110  std::map<exprt, exprt> &stashed,
112 
113  exprt precondition(patht &path);
114 
115  bool do_assumptions(
116  std::map<exprt, polynomialt> polynomials,
117  patht &body,
118  exprt &guard);
119 
120  typedef std::pair<exprt, exprt> expr_pairt;
121  typedef std::vector<expr_pairt> expr_pairst;
122 
124  {
129 
130  typedef std::vector<polynomial_array_assignmentt>
132 
133  bool do_arrays(
134  goto_programt::instructionst &loop_body,
135  std::map<exprt, polynomialt> &polynomials,
137  substitutiont &substitution,
138  scratch_programt &program);
140  goto_programt::instructionst &loop_body,
141  expr_sett &arrays_written);
143  expr_pairst &array_assignments,
144  std::map<exprt, polynomialt> &polynomials,
145  polynomial_array_assignmentst &array_polynomials,
146  polynomialst &nondet_indices);
147  bool expr2poly(
148  exprt &expr,
149  std::map<exprt, polynomialt> &polynomials,
150  polynomialt &poly);
151 
152  void ensure_no_overflows(goto_programt &program);
153 
155  const namespacet ns;
158 
160 
162 };
163 
165 
166 #endif // CPROVER_GOTO_INSTRUMENT_ACCELERATE_POLYNOMIAL_ACCELERATOR_H
std::vector< expr_pairt > expr_pairst
void ensure_no_overflows(goto_programt &program)
struct polynomial_acceleratort::polynomial_array_assignment polynomial_array_assignmentt
Goto Programs with Functions.
std::vector< polynomialt > polynomialst
Definition: polynomial.h:63
expr_sett find_modified(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)
Loop Acceleration.
void extract_polynomial(scratch_programt &program, std::set< std::pair< expr_listt, exprt >> &coefficients, polynomialt &polynomial)
std::list< instructiont > instructionst
Definition: goto_program.h:395
const goto_functionst & goto_functions
bool array_assignments2polys(expr_pairst &array_assignments, std::map< exprt, polynomialt > &polynomials, polynomial_array_assignmentst &array_polynomials, polynomialst &nondet_indices)
std::vector< polynomial_array_assignmentt > polynomial_array_assignmentst
std::unordered_set< exprt, irep_hash > expr_sett
The NIL expression.
Definition: std_expr.h:4510
virtual bool accelerate(patht &loop, path_acceleratort &accelerator)
Loop Acceleration.
std::list< path_nodet > patht
Definition: path.h:45
The symbol table.
Definition: symbol_table.h:19
bool check_inductive(std::map< exprt, polynomialt > polynomials, goto_programt::instructionst &body)
TO_BE_DOCUMENTED.
Definition: namespace.h:74
Loop Acceleration.
message_handlert & message_handler
void stash_polynomials(scratch_programt &program, std::map< exprt, polynomialt > &polynomials, std::map< exprt, exprt > &stashed, goto_programt::instructionst &body)
Author: Diffblue Ltd.
bool fit_polynomial(goto_programt::instructionst &loop_body, exprt &target, polynomialt &polynomial)
A generic container class for the GOTO intermediate representation of one function.
Definition: goto_program.h:70
Loop Acceleration.
polynomial_acceleratort(message_handlert &message_handler, const symbol_tablet &_symbol_table, const goto_functionst &_goto_functions)
Loop Acceleration.
Loop Acceleration.
void cone_of_influence(goto_programt::instructionst &orig_body, exprt &target, goto_programt::instructionst &body, expr_sett &influence)
bool expr2poly(exprt &expr, std::map< exprt, polynomialt > &polynomials, polynomialt &poly)
Loop Acceleration.
Base class for all expressions.
Definition: expr.h:42
std::pair< exprt, exprt > expr_pairt
std::map< exprt, exprt > substitutiont
Definition: polynomial.h:39
bool fit_const(goto_programt::instructionst &loop_body, exprt &target, polynomialt &polynomial)
void stash_variables(scratch_programt &program, expr_sett modified, substitutiont &substitution)
expr_pairst gather_array_assignments(goto_programt::instructionst &loop_body, expr_sett &arrays_written)
bool do_assumptions(std::map< exprt, polynomialt > polynomials, patht &body, exprt &guard)
bool do_arrays(goto_programt::instructionst &loop_body, std::map< exprt, polynomialt > &polynomials, exprt &loop_counter, substitutiont &substitution, scratch_programt &program)
Concrete Goto Program.
bool fit_polynomial_sliced(goto_programt::instructionst &sliced_body, exprt &target, expr_sett &influence, polynomialt &polynomial)
polynomial_acceleratort(message_handlert &message_handler, const symbol_tablet &_symbol_table, const goto_functionst &_goto_functions, exprt &_loop_counter)