Skip to content

Commit f14d301

Browse files
committed
Remove shared_read entries from target equation when simplify removes them from an expression
1 parent 724cae8 commit f14d301

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

src/goto-symex/symex_assign.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,11 @@ void goto_symext::symex_assign_symbol(
280280
tmp_ssa_rhs.swap(ssa_rhs);
281281
}
282282

283+
target.set_mark();
283284
state.rename(ssa_rhs, ns);
284285
do_simplify(ssa_rhs);
286+
std::cerr << from_expr(ns, "", ssa_rhs) << std::endl;
287+
target.remove_unused_reads(ssa_rhs);
285288

286289
ssa_exprt ssa_lhs=lhs;
287290
bool required=
@@ -526,9 +529,11 @@ void goto_symext::symex_assign_if(
526529

527530
guardt old_guard=guard;
528531

532+
target.set_mark();
529533
exprt renamed_guard=lhs.cond();
530534
state.rename(renamed_guard, ns);
531535
do_simplify(renamed_guard);
536+
target.remove_unused_reads(renamed_guard);
532537

533538
if(!renamed_guard.is_false())
534539
{

src/goto-symex/symex_goto.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void goto_symext::symex_goto(statet &state)
3939
exprt old_guard=instruction.guard;
4040
clean_expr(old_guard, state, false);
4141

42+
target.set_mark();
4243
exprt new_guard=old_guard;
4344
state.rename(new_guard, ns);
4445
++four_times;
@@ -50,6 +51,7 @@ void goto_symext::symex_goto(statet &state)
5051
//if(four_times>LB && four_times<UB)
5152
//std::cerr << "simplified_new_guard: " << from_expr(ns, "", new_guard) << std::endl;
5253
//assert(four_times<UB);
54+
target.remove_unused_reads(new_guard);
5355

5456
if(new_guard.is_false() ||
5557
state.guard.is_false())
@@ -204,12 +206,14 @@ void goto_symext::symex_step_goto(statet &state, bool taken)
204206

205207
exprt guard(instruction.guard);
206208
dereference(guard, state, false);
209+
target.set_mark();
207210
state.rename(guard, ns);
208211

209212
if(!taken) guard.make_not();
210213

211214
state.guard.guard_expr(guard);
212215
do_simplify(guard);
216+
target.remove_unused_reads(guard);
213217

214218
target.assumption(state.guard.as_expr(), guard, state.source);
215219
}

src/goto-symex/symex_main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void goto_symext::vcc(
6262
rewrite_quantifiers(expr, state);
6363

6464
// now rename, enables propagation
65+
target.set_mark();
6566
state.rename(expr, ns);
6667

6768
// now try simplifier on it
@@ -71,6 +72,7 @@ void goto_symext::vcc(
7172
do_simplify(expr);
7273
//if(three_times<4)
7374
//std::cerr << "simplified_vcc: " << from_expr(ns, "", expr) << std::endl;
75+
target.remove_unused_reads(expr);
7476

7577
if(expr.is_true()) return;
7678

@@ -493,8 +495,10 @@ void goto_symext::symex_step(
493495
{
494496
exprt tmp=instruction.guard;
495497
clean_expr(tmp, state, false);
498+
target.set_mark();
496499
state.rename(tmp, ns);
497500
symex_assume(state, tmp);
501+
target.remove_unused_reads(tmp);
498502
}
499503

500504
state.source.pc++;

src/goto-symex/symex_target.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ class symex_targett
182182
const exprt &guard,
183183
unsigned atomic_section_id,
184184
const sourcet &source)=0;
185+
186+
// cleanup unused shared memory reads
187+
virtual void set_mark() {}
188+
virtual void remove_unused_reads(const exprt &expr) {}
185189
};
186190

187191
bool operator < (

src/goto-symex/symex_target_equation.cpp

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#include <util/i2string.h>
1212
#include <util/std_expr.h>
1313
#include <util/expr_util.h>
14+
#include <util/find_symbols.h>
1415

1516
#include <langapi/language_util.h>
1617
#include <solvers/prop/prop_conv.h>
@@ -33,7 +34,7 @@ Function: symex_target_equationt::symex_target_equationt
3334
\*******************************************************************/
3435

3536
symex_target_equationt::symex_target_equationt(
36-
const namespacet &_ns):ns(_ns)
37+
const namespacet &_ns):ns(_ns), mark(SSA_steps.end())
3738
{
3839
}
3940

@@ -115,6 +116,42 @@ void symex_target_equationt::shared_read(
115116

116117
/*******************************************************************\
117118
119+
Function: symex_target_equationt::remove_unused_reads
120+
121+
Inputs:
122+
123+
Outputs:
124+
125+
Purpose:
126+
127+
\*******************************************************************/
128+
129+
void symex_target_equationt::remove_unused_reads(const exprt &expr)
130+
{
131+
find_symbols_sett symbols;
132+
find_symbols(expr, symbols);
133+
134+
for(SSA_stepst::iterator it=mark;
135+
it!=SSA_steps.end();
136+
) // no ++it
137+
{
138+
if(it==mark ||
139+
!it->is_shared_read() ||
140+
symbols.find(it->ssa_lhs.get_identifier())!=symbols.end())
141+
{
142+
++it;
143+
continue;
144+
}
145+
146+
SSA_stepst::iterator next=it;
147+
++next;
148+
SSA_steps.erase(it);
149+
it=next;
150+
}
151+
}
152+
153+
/*******************************************************************\
154+
118155
Function: symex_target_equationt::shared_write
119156
120157
Inputs:

src/goto-symex/symex_target_equation.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ class symex_target_equationt:public symex_targett
159159
unsigned atomic_section_id,
160160
const sourcet &source);
161161

162+
// cleanup unused shared memory reads
163+
virtual void set_mark()
164+
{
165+
mark=SSA_steps.end();
166+
if(!SSA_steps.empty()) --mark;
167+
}
168+
virtual void remove_unused_reads(const exprt &expr);
169+
162170
void convert(prop_convt &prop_conv);
163171
void convert_assignments(decision_proceduret &decision_procedure) const;
164172
void convert_decls(prop_convt &prop_conv) const;
@@ -304,6 +312,7 @@ class symex_target_equationt:public symex_targett
304312

305313
protected:
306314
const namespacet &ns;
315+
SSA_stepst::iterator mark;
307316

308317
// for enforcing sharing in the expressions stored
309318
merged_irepst merge_irep;

0 commit comments

Comments
 (0)