Skip to content

Support bounds widening for conditionals with while loops #803

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 4 commits into from
Mar 20, 2020
Merged

Conversation

mgrang
Copy link

@mgrang mgrang commented Mar 6, 2020

Added support for widenening bounds for nt_array_ptr dereferences in while
loops. For example, "while (*p) {}" would widen the bounds of p upon
entry to the loop.

To compute In[B] we compute the intersection of Out[B*->B], where B* are all
preds of B. When there is a back edge from block B' to B (for example in
loops), the Out set for block B' will be empty when we first enter B. As a
result, the intersection operation would always result in an empty In set for
B.

So to handle this, we consider the In and Out sets for all blocks to have a
default value of "Top" which indicates a set of all members of the Gen set. In
this way we ensure that the intersection does not result in an empty set even
if the Out set for a block is actually empty.

But we also need to handle the case where there is an unconditional jump into a
block (for example, as a result of a goto). In this case, we cannot widen the
bounds because we would not have checked for the ptr dereference. So in this
case we want the intersection to result in an empty set.

So we initialize the In and Out sets of all blocks, except the Entry block, as
"Top".

Top represents the union of the Gen sets of all edges. We have chosen the
offsets of ptr variables in Top to be the max unsigned int. The reason behind
this is that in order to compute the actual In sets for blocks we are going to
intersect the Out sets on all the incoming edges of the block. And in that case
we would always pick the ptr with the smaller offset. Chosing max unsigned int
also makes handling Top much easier as we do not need to explicitly store edge
info.

Added support for widenening bounds for nt_array_ptr dereferences in while
loops. For example, "while (*p) {}" would widen the bounds of p upon
entry to the loop.

In order to handle loops we initialize the In and Out sets of the entry block
as empty. This is done so that we can handle loop back edges and unconditional
jumps.
Mandeep Singh Grang added 2 commits March 5, 2020 19:00
@mgrang
Copy link
Author

mgrang commented Mar 6, 2020

Here's a follow-up PR for "for" loops: #804

To compute In[B] we compute the intersection of Out[B*->B], where B* are all
preds of B. When there is a back edge from block B' to B (for example in
loops), the Out set for block B' will be empty when we first enter B. As a
result, the intersection operation would always result in an empty In set for
B.

So to handle this, we consider the In and Out sets for all blocks to have a
default value of "Top" which indicates a set of all members of the Gen set. In
this way we ensure that the intersection does not result in an empty set even
if the Out set for a block is actually empty.

But we also need to handle the case where there is an unconditional jump into a
block (for example, as a result of a goto). In this case, we cannot widen the
bounds because we would not have checked for the ptr dereference. So in this
case we want the intersection to result in an empty set.

So we initialize the In and Out sets of all blocks, except the Entry block, as
"Top".

Top represents the union of the Gen sets of all edges. We have chosen the
offsets of ptr variables in Top to be the max unsigned int. The reason behind
this is that in order to compute the actual In sets for blocks we are going to
intersect the Out sets on all the incoming edges of the block. And in that case
we would always pick the ptr with the smaller offset. Chosing max unsigned int
also makes handling Top much easier as we do not need to explicitly store edge
info.
@mgrang
Copy link
Author

mgrang commented Mar 16, 2020

@dtarditi My latest updated PR computes Top and initializes In and Out sets to Top. Please review.

@mgrang mgrang self-assigned this Mar 19, 2020
Copy link
Member

@dtarditi dtarditi left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants