Skip to content

Commit b4f65c8

Browse files
authored
Merge pull request #4169 from tautschnig/opt-swap
merge_value_sets: Avoid assignment when actually values can be moved
2 parents ee11014 + ad16b57 commit b4f65c8

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

src/goto-checker/symex_bmc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ void symex_bmct::symex_step(
8686
}
8787
}
8888

89-
void symex_bmct::merge_goto(const goto_statet &goto_state, statet &state)
89+
void symex_bmct::merge_goto(goto_statet &&goto_state, statet &state)
9090
{
9191
const goto_programt::const_targett prev_pc = goto_state.source.pc;
9292
const guardt prev_guard = goto_state.guard;
9393

94-
goto_symext::merge_goto(goto_state, state);
94+
goto_symext::merge_goto(std::move(goto_state), state);
9595

9696
PRECONDITION(prev_pc->is_goto());
9797
if(

src/goto-checker/symex_bmc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class symex_bmct : public goto_symext
9494
void symex_step(const get_goto_functiont &get_goto_function, statet &state)
9595
override;
9696

97-
void merge_goto(const goto_statet &goto_state, statet &state) override;
97+
void merge_goto(goto_statet &&goto_state, statet &state) override;
9898

9999
bool should_stop_unwind(
100100
const symex_targett::sourcet &source,

src/goto-symex/goto_symex.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,15 @@ class goto_symext
230230

231231
virtual void symex_assume(statet &, const exprt &cond);
232232

233-
// gotos
233+
/// Merge all branches joining at the current program point. Applies
234+
/// \ref merge_goto for each goto state (each of which corresponds to previous
235+
/// branch).
234236
void merge_gotos(statet &);
235237

236-
virtual void merge_goto(const goto_statet &goto_state, statet &);
237-
238-
void merge_value_sets(const goto_statet &goto_state, statet &dest);
238+
/// Merge a single branch, the symbolic state of which is held in \p
239+
/// goto_state, into the current overall symbolic state. \p goto_state is no
240+
/// longer expected to be valid afterwards.
241+
virtual void merge_goto(goto_statet &&goto_state, statet &);
239242

240243
void phi_function(const goto_statet &goto_state, statet &);
241244

src/goto-symex/symex_goto.cpp

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ void goto_symext::merge_gotos(statet &state)
308308

309309
for(auto list_it = state_list.rbegin(); list_it != state_list.rend();
310310
++list_it)
311-
merge_goto(*list_it, state);
311+
merge_goto(std::move(*list_it), state);
312312

313313
// clean up to save some memory
314314
frame.goto_state_map.erase(state_map_it);
315315
}
316316

317-
void goto_symext::merge_goto(const goto_statet &goto_state, statet &state)
317+
void goto_symext::merge_goto(goto_statet &&goto_state, statet &state)
318318
{
319319
// check atomic section
320320
if(state.atomic_section_id != goto_state.atomic_section_id)
@@ -325,7 +325,11 @@ void goto_symext::merge_goto(const goto_statet &goto_state, statet &state)
325325
// do SSA phi functions
326326
phi_function(goto_state, state);
327327

328-
merge_value_sets(goto_state, state);
328+
// merge value sets
329+
if(state.guard.is_false() && !goto_state.guard.is_false())
330+
state.value_set = std::move(goto_state.value_set);
331+
else if(!goto_state.guard.is_false())
332+
state.value_set.make_union(goto_state.value_set);
329333

330334
// adjust guard
331335
state.guard|=goto_state.guard;
@@ -334,17 +338,6 @@ void goto_symext::merge_goto(const goto_statet &goto_state, statet &state)
334338
state.depth=std::min(state.depth, goto_state.depth);
335339
}
336340

337-
void goto_symext::merge_value_sets(const goto_statet &src, statet &dest)
338-
{
339-
if(dest.guard.is_false())
340-
{
341-
dest.value_set=src.value_set;
342-
return;
343-
}
344-
345-
dest.value_set.make_union(src.value_set);
346-
}
347-
348341
/// Applies f to `(k, ssa, i, j)` if the first map maps k to (ssa, i) and
349342
/// the second to (ssa', j). If the first map has an entry for k but not the
350343
/// second one then j is 0, and when the first map has no entry for k then i = 0

src/pointer-analysis/value_set.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class value_sett
4747

4848
virtual ~value_sett() = default;
4949

50+
value_sett(const value_sett &other) = default;
51+
52+
value_sett &operator=(value_sett &&other)
53+
{
54+
values = std::move(other.values);
55+
return *this;
56+
}
57+
5058
static bool field_sensitive(const irep_idt &id, const typet &type);
5159

5260
/// Matches the location_number field of the instruction that corresponds

0 commit comments

Comments
 (0)