Skip to content

merge_value_sets: Avoid assignment when actually values can be moved #4169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/goto-checker/symex_bmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ void symex_bmct::symex_step(
}
}

void symex_bmct::merge_goto(const goto_statet &goto_state, statet &state)
void symex_bmct::merge_goto(goto_statet &&goto_state, statet &state)
{
const goto_programt::const_targett prev_pc = goto_state.source.pc;
const guardt prev_guard = goto_state.guard;

goto_symext::merge_goto(goto_state, state);
goto_symext::merge_goto(std::move(goto_state), state);

PRECONDITION(prev_pc->is_goto());
if(
Expand Down
2 changes: 1 addition & 1 deletion src/goto-checker/symex_bmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class symex_bmct : public goto_symext
void symex_step(const get_goto_functiont &get_goto_function, statet &state)
override;

void merge_goto(const goto_statet &goto_state, statet &state) override;
void merge_goto(goto_statet &&goto_state, statet &state) override;

bool should_stop_unwind(
const symex_targett::sourcet &source,
Expand Down
11 changes: 7 additions & 4 deletions src/goto-symex/goto_symex.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,15 @@ class goto_symext

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

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

virtual void merge_goto(const goto_statet &goto_state, statet &);

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

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

Expand Down
21 changes: 7 additions & 14 deletions src/goto-symex/symex_goto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ void goto_symext::merge_gotos(statet &state)

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

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

void goto_symext::merge_goto(const goto_statet &goto_state, statet &state)
void goto_symext::merge_goto(goto_statet &&goto_state, statet &state)
{
// check atomic section
if(state.atomic_section_id != goto_state.atomic_section_id)
Expand All @@ -329,7 +329,11 @@ void goto_symext::merge_goto(const goto_statet &goto_state, statet &state)
// do SSA phi functions
phi_function(goto_state, state);

merge_value_sets(goto_state, state);
// merge value sets
if(state.guard.is_false() && !goto_state.guard.is_false())
state.value_set = std::move(goto_state.value_set);
else if(!goto_state.guard.is_false())
state.value_set.make_union(goto_state.value_set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would also make sense for make_union to not take a const ref, and use move instead. But that's maybe for another pull request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this impactful is a bigger task, because the internal representation of a value set is reference counted. I'll leave this for another time.


// adjust guard
state.guard|=goto_state.guard;
Expand All @@ -338,17 +342,6 @@ void goto_symext::merge_goto(const goto_statet &goto_state, statet &state)
state.depth=std::min(state.depth, goto_state.depth);
}

void goto_symext::merge_value_sets(const goto_statet &src, statet &dest)
{
if(dest.guard.is_false())
{
dest.value_set=src.value_set;
return;
}

dest.value_set.make_union(src.value_set);
}

/// Applies f to `(k, ssa, i, j)` if the first map maps k to (ssa, i) and
/// the second to (ssa', j). If the first map has an entry for k but not the
/// second one then j is 0, and when the first map has no entry for k then i = 0
Expand Down
8 changes: 8 additions & 0 deletions src/pointer-analysis/value_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ class value_sett

virtual ~value_sett() = default;

value_sett(const value_sett &other) = default;

value_sett &operator=(value_sett &&other)
{
values = std::move(other.values);
return *this;
}

static bool field_sensitive(const irep_idt &id, const typet &type);

/// Matches the location_number field of the instruction that corresponds
Expand Down