CBMC
letify.h
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Introduce LET for common subexpressions
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #ifndef CPROVER_SOLVERS_SMT2_LETIFY_H
10 #define CPROVER_SOLVERS_SMT2_LETIFY_H
11 
12 #include <util/std_expr.h>
13 
15 class letifyt
16 {
17 public:
18  exprt operator()(const exprt &);
19 
20 protected:
21  // to produce a fresh ID for each new let
22  std::size_t let_id_count = 0;
23 
25  {
26  let_count_idt(std::size_t _count, const symbol_exprt &_let_symbol)
27  : count(_count), let_symbol(_let_symbol)
28  {
29  }
30 
31  std::size_t count;
33  };
34 
35 #if HASH_CODE
36  using seen_expressionst = std::unordered_map<exprt, let_count_idt, irep_hash>;
37 #else
39 #endif
40 
41  void collect_bindings(
42  const exprt &expr,
43  seen_expressionst &map,
44  std::vector<exprt> &let_order);
45 
46  static exprt letify(
47  const exprt &expr,
48  const std::vector<exprt> &let_order,
49  const seen_expressionst &map);
50 
51  static exprt substitute_let(const exprt &expr, const seen_expressionst &map);
52 };
53 
54 #endif // CPROVER_SOLVERS_SMT2_LETIFY_H
Base class for all expressions.
Definition: expr.h:56
Introduce LET for common subexpressions.
Definition: letify.h:16
static exprt letify(const exprt &expr, const std::vector< exprt > &let_order, const seen_expressionst &map)
Construct a nested let expression for expressions in let_order that are used more than once.
Definition: letify.cpp:53
std::size_t let_id_count
Definition: letify.h:22
void collect_bindings(const exprt &expr, seen_expressionst &map, std::vector< exprt > &let_order)
Definition: letify.cpp:16
std::unordered_map< exprt, let_count_idt, irep_hash > seen_expressionst
Definition: letify.h:36
static exprt substitute_let(const exprt &expr, const seen_expressionst &map)
Definition: letify.cpp:89
exprt operator()(const exprt &)
Definition: letify.cpp:79
Expression to hold a symbol (variable)
Definition: std_expr.h:131
API to expression classes.
let_count_idt(std::size_t _count, const symbol_exprt &_let_symbol)
Definition: letify.h:26
symbol_exprt let_symbol
Definition: letify.h:32
std::size_t count
Definition: letify.h:31