ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
gcse.h
Go to the documentation of this file.
1#pragma once
2
3// GCSE - Global Common Subexpression Elimination
4
42
44{
45public:
46 cse_domaint() = default;
47
48 virtual void transform(
51 ai_baset &ai,
52 const namespacet &ns) override;
53
54 virtual void output(std::ostream &out) const override;
55
56 virtual void make_bottom() override
57 {
59 bottom = true;
60 }
61
66 virtual void make_entry() override
67 {
69 bottom = false;
70 };
71 virtual void make_top() override
72 {
73 // Theoretically there exists a TOP (all possible AE in the program).
74 // In practice, there is no need for it.
75 log_error("[CSE] Available Expressions does not implement make_top()");
76 abort();
77 };
78
79 virtual bool is_bottom() const override
80 {
81 return bottom;
82 }
83 virtual bool is_top() const override
84 {
85 // Not needed
86 return false;
87 }
88 virtual bool ai_simplify(expr2tc &, const namespacet &) const override
89 {
90 return false;
91 }
92
93public:
94 bool merge(
95 const cse_domaint &b,
99 std::unordered_set<expr2tc, irep2_hash> available_expressions;
100
103 bool bottom = true;
104
105protected:
108 void make_expression_available(const expr2tc &e);
109
112 void havoc_expr(const expr2tc &e, const goto_programt::const_targett &);
113
116 void havoc_symbol(const irep_idt &sym);
117
121
122 // Helper function to check whether `src` depends on `taint`
123 bool should_remove_expr(const expr2tc &taint, const expr2tc &src) const;
124 // Helper function to check whether `src` depends on symbol `sym`
125 bool should_remove_expr(const irep_idt &sym, const expr2tc &src) const;
126
127public:
128 // TODO: clearly this shouldn't be here. The proper way is to create a new
129 // Abstract Interpreter that contains a points-to analysis
130 static std::shared_ptr<value_setst> vsa;
131};
132
156{
157public:
158 goto_cse(contextt &ns, std::shared_ptr<value_setst> &vsa)
160 {
161 cse_domaint::vsa = vsa;
162 }
163
164 virtual bool runOnProgram(goto_functionst &) override;
165 virtual bool
166 runOnFunction(std::pair<const irep_idt, goto_functiont> &F) override;
167
168 // TODO: we should have a method to convert an cse_symbol back to the original
169 // expr for CE.
170
171protected:
174 expr2tc obtain_max_sub_expr(const expr2tc &e, const cse_domaint &state) const;
176 expr2tc &e,
177 const std::unordered_map<expr2tc, expr2tc, irep2_hash> &expr2symbol,
179 std::unordered_set<expr2tc, irep2_hash> &matched_expressions) const;
182 expr2tc &lhs,
183 const std::unordered_map<expr2tc, expr2tc, irep2_hash> &expr2symbol,
185 std::unordered_set<expr2tc, irep2_hash> &matched_expressions) const;
186
187 symbolt
189
190private:
191 unsigned symbol_counter = 0;
192 const std::string prefix = "__ESBMC_cse_symbol";
193};
Abstract Interpretation.
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition ai.h:27
ai_domain_baset()
The constructor is expected to produce 'false' or 'bottom'.
Definition ai_domain.h:19
Definition ai.h:177
Definition context.h:57
Abstract domain to obtain all available expressions (AE).
Definition gcse.h:44
static std::shared_ptr< value_setst > vsa
Definition gcse.h:130
cse_domaint()=default
void havoc_expr(const expr2tc &e, const goto_programt::const_targett &)
Remove expression e (and everything that it depends on) from available_expressions.
Definition gcse.cpp:360
bool bottom
Unreachable-so-far marker.
Definition gcse.h:103
virtual void make_entry() override
Entry has nothing available yet, but is reachable — distinct from bottom.
Definition gcse.h:66
virtual bool is_top() const override
Definition gcse.h:83
std::unordered_set< expr2tc, irep2_hash > available_expressions
All expressions available.
Definition gcse.h:99
bool merge(const cse_domaint &b, goto_programt::const_targett, goto_programt::const_targett)
Definition gcse.cpp:124
void make_expression_available(const expr2tc &e)
Add non-primitive expression e (and its sub-expressions) into available_expressions.
Definition gcse.cpp:165
virtual void output(std::ostream &out) const override
Definition gcse.cpp:108
bool should_remove_expr(const expr2tc &taint, const expr2tc &src) const
Definition gcse.cpp:217
virtual void make_bottom() override
no states
Definition gcse.h:56
virtual bool is_bottom() const override
Definition gcse.h:79
virtual bool ai_simplify(expr2tc &, const namespacet &) const override
also add
Definition gcse.h:88
void havoc_symbol(const irep_idt &sym)
Remove every expression from available_expressions that depends on symbol sym.
Definition gcse.cpp:252
virtual void make_top() override
all states – the analysis doesn't use this, and domains may refuse to implement it.
Definition gcse.h:71
void havoc_pointee(expr2tc ptr, const goto_programt::const_targett &)
Remove every expression that may read the object ptr points to, which is about to be deallocated.
Definition gcse.cpp:409
expr2tc obtain_max_sub_expr(const expr2tc &e, const cse_domaint &state) const
Definition gcse.cpp:439
void replace_in_lvalue(expr2tc &lhs, const std::unordered_map< expr2tc, expr2tc, irep2_hash > &expr2symbol, const goto_programt::const_targett &to, std::unordered_set< expr2tc, irep2_hash > &matched_expressions) const
Like replace_max_sub_expr, but only in the value operands of an lvalue.
Definition gcse.cpp:501
goto_cse(contextt &ns, std::shared_ptr< value_setst > &vsa)
Definition gcse.h:158
virtual bool runOnProgram(goto_functionst &) override
Definition gcse.cpp:425
symbolt create_cse_symbol(const type2tc &t, const goto_programt::const_targett &to)
Definition gcse.cpp:708
virtual bool runOnFunction(std::pair< const irep_idt, goto_functiont > &F) override
Definition gcse.cpp:548
void replace_max_sub_expr(expr2tc &e, const std::unordered_map< expr2tc, expr2tc, irep2_hash > &expr2symbol, const goto_programt::const_targett &to, std::unordered_set< expr2tc, irep2_hash > &matched_expressions) const
Definition gcse.cpp:464
contextt & context
Definition gcse.h:173
ait< cse_domaint > available_expressions
Definition gcse.h:172
goto_functions_algorithm(bool sideffect)
Definition goto_functions_algorithm.h:13
Definition goto_functions.h:56
instructionst::const_iterator const_targett
Definition goto_program.h:591
Definition irep_idt.h:12
Definition namespace.h:10
Definition symbol.h:12
irep_container< type2t > type2tc
Definition irep2.h:430
irep_container< expr2t > expr2tc
Definition irep2.h:431
#define log_error(fmt,...)
Definition message.h:83
Definition transform.py:1
#define true
Definition stdbool.h:11
void abort(void)
Definition stdlib.c:77