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

Conversation

tautschnig
Copy link
Collaborator

@tautschnig tautschnig commented Feb 12, 2019

We don't need the contents of the source anymore. Running on SV-COMP's
ReachSafety-ECA, this saves 741s, which is approximately 9% of the runtime of merge_goto.

  • Each commit message has a non-empty body, explaining why the change was made.
  • n/a Methods or procedures I have added are documented, following the guidelines provided in CODING_STANDARD.md.
  • n/a The feature or user visible behaviour I have added or modified has been documented in the User Guide in doc/cprover-manual/
  • Regression or unit tests are included, or existing tests cover the modified code (in this case I have detailed which ones those are in the commit message).
  • My commit message includes data points confirming performance improvements (if claimed).
  • My PR is restricted to a single feature or bugfix.
  • n/a White-space or formatting changes outside the feature-related changed lines are in commits of their own.

@@ -251,9 +251,9 @@ class goto_symext
// gotos
void merge_gotos(statet &);

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

Choose a reason for hiding this comment

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

I'm not sure what's happening here because there is no documentation. If the goto_state is not supposed to be used afterwards then it would be good to make it clear, either by documenting or in the type, by forcing the argument to be movable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair, I'll work on adding documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Documentation added.

dest.value_set=src.value_set;
// we don't actually need dest.value_set anymore, leave cleanup to later
// cleanup of goto states
dest.value_set.swap(src.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.

Why swap and not move?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll try to take a look whether adding a move operator would be as easy.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done (just required also default-declaring a copy constructor).

@tautschnig tautschnig self-assigned this Feb 12, 2019
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

🚫
This PR failed Diffblue compatibility checks (cbmc commit: d951590).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100661522
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: 8a23c84).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100662229

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

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

Formalise this with a move-ref and this lgtm

You may also be interested in @JohnDumbell is currently separating the concepts of fresh-l2-name (global) and current-l2-name (local), so that the L2 renaming map can be straightfowardly moved as well.

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

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

If goto_state is indeed dying then we should pass a goto_statet &&

@tautschnig
Copy link
Collaborator Author

I have incorporated all the feedback and have now triggered another profiling run just to make sure this is still working as expected. @kroening @peterschrammel either of you will need to review this as well.

@@ -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 at the current
/// program point. It will apply \ref merge_goto for each goto state (each of
Copy link
Contributor

Choose a reason for hiding this comment

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

The end of the first sentence is repeated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, thanks, fixed.

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.

We don't need the contents of the source anymore. Running on SV-COMP's
ReachSafety-ECA, this saves 741s, which is approximately 9% of the runtime of
goto_symext::merge_goto.
Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

🚫
This PR failed Diffblue compatibility checks (cbmc commit: 6c9937c).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100793036
Status will be re-evaluated on next push.
Please contact @peterschrammel, @thk123, or @allredj for support.

Common spurious failures:

  • the cbmc commit has disappeared in the mean time (e.g. in a force-push)
  • the author is not in the list of contributors (e.g. first-time contributors).

The incompatibility may have been introduced by an earlier PR. In that case merging this
PR should be avoided unless it fixes the current incompatibility.

Copy link
Contributor

@allredj allredj left a comment

Choose a reason for hiding this comment

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

✔️
Passed Diffblue compatibility checks (cbmc commit: ad16b57).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/100800932

@tautschnig
Copy link
Collaborator Author

@kroening and/or @peterschrammel would you mind taking a look at this one? It's just +25/−21 and is already coming up in other PRs (#4199).

@tautschnig tautschnig merged commit b4f65c8 into diffblue:develop Mar 2, 2019
@tautschnig tautschnig deleted the opt-swap branch March 2, 2019 06:21
@tautschnig tautschnig restored the opt-swap branch December 27, 2020 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants