-
Notifications
You must be signed in to change notification settings - Fork 117
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
Make GlobalStoreAndRef consistent in usage inside and outside of loops #904
Conversation
clang-tidy review says "All clean, LGTM! 👍" |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #904 +/- ##
==========================================
- Coverage 94.09% 94.05% -0.04%
==========================================
Files 53 53
Lines 7805 7722 -83
==========================================
- Hits 7344 7263 -81
+ Misses 461 459 -2
|
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
clang-tidy review says "All clean, LGTM! 👍" |
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 looks amazing.
I will review it in-depth soon.
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 looks good to me. Let's wait for @parth-07's review here.
…s (and consistent with StoreAndRef)
clang-tidy review says "All clean, LGTM! 👍" |
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 pull-request has simplified a lot of complicated codes. Looks good to me.
The purpose of this PR is to make
GlobalStoreAndRef
work more consistently inside and outside of loops. The issue is well described in #431. The solution proposed in this PR is as follows:When
GlobalStoreAndRef
is called inside a loop, it adds a push statement (clad::push(_t0, x)
) to the forward block and a pop statement (clad::pop(_t0)
) to the reverse block. The return type ofGlobalStoreAndRef
is changed fromStmtDiff
toclang::Expr*
. The return value is the top element on the tape (clad::back(_t0)
). WhenGlobalStoreAndRef
is called outside a loop, the behavior is essentially the same as before except now it returns a single reference to the created variableref
instead ofStmtDiff(ref, ref)
.For example (when used to store the condition of an if-stmt inside a loop):
With this approach, we automatically ensure safe tape pushes/pops when working with return/break/continue statements, which wasn't the case previously. Because of this a lot of the code used to handle those statements got simplified.
Also, the change of the return type makes
GlobalStoreAndRef
consistent in usage withStoreAndRef
.Note: I made
GlobalStoreAndRef
returnclad::back(_t0)
instead of stored values ofclad::push(_t0)
andclad::pop(_t0)
(as proposed by @parth-07 in #431) because in all use cases_r0 = clad::pop(_t0)
was added to the reverse block after_r0
was used (because reverse blocks are reversed). Getting the statement order right would makeGlobalStoreAndRef
a lot harder to use.Fixes #431.