[Unity] Remove unused local function definitions#15507
[Unity] Remove unused local function definitions#15507kparzysz-quic merged 1 commit intoapache:unityfrom
Conversation
Prior to this commit, the `relax.analysis.remove_all_unused` utility only removed variable bindings that occur within a dataflow block. This satisfies that the condition that a variable can be removed if is unused and if its computation has no side effects. However, it doesn't include any values from a `BindingBlock`. This commit updates the `RemoveUnusedVars` pass to also inspect `BindingBlock` instances for removeable variables. Currently, this is limited to unused local function definitions.
|
Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.
Generated by tvm-bot |
|
|
||
| optimized = remove_all_unused(IdentityUnused["main"]) | ||
|
|
||
| GroundTruth = IdentityUnused |
There was a problem hiding this comment.
Shouldn't the two unuseds be removed? I think this whole algorithm (not your change specifically) is somewhat deficient if it doesn't keep track of newly-unused objects.
There was a problem hiding this comment.
For this specific change, because (to my understanding), the call_dps_packed doesn't guarantee that it has no side effects. Within a R.dataflow() environment, the expression may not have side effects, so it is safe to remove.
For newly-unused objects, I believe that is handled by the GetUnusedVars function, called during construction. It iteratively walks from the function outputs to the predecessors required to generate those outputs, finding the set of all variables required to generate the output. Anything not within that set is considered unused and can be removed, even it occurs within another expression (because that expression is also going to be removed).
Prior to this commit, the
relax.analysis.remove_all_unusedutility only removed variable bindings that occur within a dataflow block. This satisfies that the condition that a variable can be removed if is unused and if its computation has no side effects. However, it doesn't include any values from aBindingBlock.This commit updates the
RemoveUnusedVarspass to also inspectBindingBlockinstances for removeable variables. Currently, this is limited to unused local function definitions.