-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Relay] Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. #9542
Conversation
3ba6e79
to
16c2342
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.
It would be good to get a second set of eyes but looks good to me. Modulo my comment.
LGTM |
As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl.
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.
Really nice and readable! Caught a few spelling errors though.
Also, one clarifying Q
16c2342
to
3f73bbc
Compare
Thank you @mbs-octoml @mikepapadim @electriclilies @jroesch ; the PR has been merged |
…festAlloc. (apache#9542) * Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl. * [checkpoint] Merge Lily's suggestions.
…festAlloc. (apache#9542) * Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl. * [checkpoint] Merge Lily's suggestions.
…festAlloc. (apache#9542) * Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl. * [checkpoint] Merge Lily's suggestions.
…festAlloc. (apache#9542) * Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl. * [checkpoint] Merge Lily's suggestions.
…festAlloc. (apache#9542) * Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl. * [checkpoint] Merge Lily's suggestions.
…festAlloc. (apache#9542) * Prepare DeadCodeElimination for running post LowerTEPass/ManifestAlloc. As part of apache#9483 we need to prepare some critical Relay passes for running after lowering and conversion to DPS. For DCE we need to make sure we never remove side-effecting let-bound expressions, such as for allocation or evaluation of an external function with unknown effectfulness. Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting for functions by tracking both 'eval' and 'call' purity, but must fallback to assuming call-impurity in more difficult cases (eg calling a function passed as a parameter, calling a function projected from a tuple, etc). However it seems plenty good enough. Purity must also be accounted for when determining the usage count of let-bound variables, so reworked that. Collapsed the let-bound value accumulation pass into the usage counting pass to make up for inserting the new purity analysis pass. A few tests assume DCE eliminates dead reference writes. The previous implementation certainly did that, but by eliminating *all* writes. Filed CORE-118 to extend DCE to soundly elim dead writes (a very simple-minded analysis would probably do just fine and we don't need to get hung up on alias analysis). In the meantime, added an 'ignore_impurity' flag (default False) and set to true just in the few unit tests which rely on the unsound impl. * [checkpoint] Merge Lily's suggestions.
As part of #9483 we need to prepare some critical Relay passes for running after
lowering and conversion to DPS. For DCE we need to make sure we never remove
side-effecting let-bound expressions, such as for allocation or evaluation of
an external function with unknown effectfulness.
Introduce a new purity pre-pass. It makes a half-hearted attempt at accounting
for functions by tracking both 'eval' and 'call' purity, but must fallback to
assuming call-impurity in more difficult cases (eg calling a function passed as
a parameter, calling a function projected from a tuple, etc). However it seems
plenty good enough.
Purity must also be accounted for when determining the usage count of let-bound
variables, so reworked that. Collapsed the let-bound value accumulation pass into
the usage counting pass to make up for inserting the new purity analysis pass.
Note that some unit tests assume DCE eliminates dead writes to references. The
previous implementation certainly did that, but also eliminated all writes. To do this
soundly will require a bit of liveness analysis. Rather than doing that now I've added
an 'ignore_impurity' flag to DeadCodeElimination() to recover the (unsound) legacy
behavior.