-
Notifications
You must be signed in to change notification settings - Fork 277
Enable perfect forwarding with irept/exprt/typet constructors #3502
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n/a My commit message includes data points confirming performance improvements (if claimed)
Isn't your commit message claiming exactly that? ;)
No, I'm not yet claiming that: I'm working on a PR that will actually start making serious use of these functions, at which point I should likely do a proper evaluation. |
Although I have a fix for the test failures I'm marking this do-not-merge as I'll add the corresponding changes to *typet/*exprt/code*t in a single branch to do performance benchmarking. (Also, the failing tests did confirm that the functions are used.) |
e7c4998
to
0960485
Compare
Rvalue constructors added. I will now start testing and benchmarking. Various preparatory changes have been factored out into other PRs, and there is a lot that could and should be done on top of this one. |
0960485
to
f2878f2
Compare
src/util/irep.cpp
Outdated
|
||
return it->second; | ||
#else | ||
named_subt::iterator entry = s.find(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just s[name] = std::move(irep);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also want to return a reference to the newly added irept
.
src/util/std_code.h
Outdated
@@ -479,6 +494,11 @@ class code_assumet:public codet | |||
add_to_operands(expr); | |||
} | |||
|
|||
explicit code_assumet(exprt &&expr):codet(ID_assume) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: spacing of :
(here and below)
Paging @NathanJPhillips for C++ wizardry: If you have a function with overloads
But, (a) it's annoying to duplicate every method like I'd like a case like
But it seems odd to have A, B and C be that general when actually I only want to allow |
f2878f2
to
a22b7c4
Compare
d757405
to
2649b30
Compare
10286d6
to
1ddd740
Compare
0b0b19b
to
9f0bdad
Compare
5547be1
to
f0dc891
Compare
f0dc891
to
8cc4c5e
Compare
There was a problem hiding this 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: 8cc4c5e).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/103558660
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.
4b20ea0
to
0520791
Compare
@@ -18,7 +18,7 @@ class ssa_exprt:public symbol_exprt | |||
public: | |||
/// Constructor | |||
/// \param expr: Expression to be converted to SSA symbol | |||
explicit ssa_exprt(const exprt &expr) : symbol_exprt(irep_idt(), expr.type()) | |||
explicit ssa_exprt(const exprt &expr) : symbol_exprt(expr.type()) | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of liked that symbol_exprt
now enforces that you set the identifier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think symbol_exprt
actually does? This change here just removes an unnecessary call to set_identifier
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't, but I was hoping it would eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can certainly put the irep_idt()
back if and when we do.
{ | ||
arguments() = _arguments; | ||
arguments() = std::move(_arguments); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could make the above multi_ary_exprt(ID_arguments, std::move(_arguments))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
These do not actually destroy the source object, but ensure that using dstringt with std::move is as efficient as a regular copy/assignment.
This should enable use (with performance benefit) of rvalue references in higher-level APIs.
Uses the recently added irept constructor to move all arguments in place.
Also don't use subtype() in the constructor as that would unnecessarily construct a blank irept first.
There was a problem hiding this 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: 4b20ea0).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104425235
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.
{ | ||
PRECONDITION(op.type().id()==ID_bool); | ||
PRECONDITION(op().type().id() == ID_bool); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, but then I should really add Edit: Done.as_const()
in there ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, this doesn't do the job -- the mere access to operands()
is enough to wreck the sharing.
This needs to be as_const(*this).type().id()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for failing to take into account this remark right here, the fix is now in #4391.
Profiling does not show any advantage of using rvalue constructors over passing by value (and then moving in place), and this requires at most as many copies as the previous const-reference case. Also make use of the new exprt constructors to set up operands without an additional add_to_operands call.
Profiling does not show any advantage of using rvalue constructors over passing by value (and then moving in place), and this requires at most as many copies as the previous const-reference case.
0520791
to
8e1191f
Compare
There was a problem hiding this 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: 0520791).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104426210
Status will be re-evaluated on next push.
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 compatibility was already broken by an earlier merge.
Profiling does not show any advantage of using rvalue constructors over passing by value (and then moving in place), and this requires at most as many copies as the previous const-reference case. Also make use of the new exprt constructors to set up operands without an additional add_to_operands call.
8e1191f
to
83ed9a5
Compare
There was a problem hiding this 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: 83ed9a5).
Build URL: https://travis-ci.com/diffblue/test-gen/builds/104448810
This should enable use (with performance benefit) of rvalue references in
higher-level APIs.