Remove unused results in DAE2#8903
Conversation
Extend DeadArgumentElimination2.cpp to track and eliminate unused function return values in addition to dead parameters. Generalize the analysis graph by introducing a unified `Location` variant that handles both parameter and result locations across functions and function type trees (`FuncResultLoc` and `TypeResultLoc`). Extend value-flow tracking to follow return values flowing into function returns, including tracking tail calls (`tailCallees` and `tailCalleeTypes`) so that result usage constraints propagate correctly from callees to tail-callers. Update the fixed-point solver to propagate result usage bidirectionally across function implementations and type trees. When a function or type result is determined to be unused, update its signature result to `Type::none` during type rewriting and strip the return expressions and call site result types during optimization.
| // Function index and parameter index. | ||
| using FuncParamLoc = std::pair<Index, Index>; | ||
|
|
||
| // Function index identifying the function' result (we treat result tuples as a |
There was a problem hiding this comment.
| // Function index identifying the function' result (we treat result tuples as a | |
| // Function index identifying the function's result (we treat result tuples as a |
Also, how does an Index identify a result? Is this just the arity? Or is this mapping types to an Index in some manner?
There was a problem hiding this comment.
Reading above, I see parameters are also mapped to an Index, but I don't remember how that works. Might be worth a general comment here?
There was a problem hiding this comment.
The index is the index of the function whose result is being identified. That's the same as the first Index in FuncParamLoc, but we don't need a second index because there is at most one result.
There was a problem hiding this comment.
Wait, the comment already says "function index" in both locations 😆
There was a problem hiding this comment.
I did miss "function index" here, but the comment above says just "parameter index". Or, more fully, it says "Function index and parameter index". What is the "parameter index"? (it can't be equal to the function index, can it..?)
And, if we use a function index to identify a function's result, why not just call it a function index? Something in the design here seems confusing to me - I'm probably not remembering something basic, but I think that might be a good reason to explain the design more in a comment?
There was a problem hiding this comment.
Also, if "param index" means "the index in the list of parameters", then does "result loc" mean the same?
There was a problem hiding this comment.
(That is, maybe Index/Loc is part of my confusion here.)
Extend DeadArgumentElimination2.cpp to track and eliminate unused function return values in addition to dead parameters.
Generalize the analysis graph by introducing a unified
Locationvariant that handles both parameter and result locations across functions and function type trees (FuncResultLocandTypeResultLoc). Extend value-flow tracking to follow return values flowing into function returns, including tracking tail calls (tailCalleesandtailCalleeTypes) so that result usage constraints propagate correctly from callees to tail-callers.Update the fixed-point solver to propagate result usage bidirectionally across function implementations and type trees. When a function or type result is determined to be unused, update its signature result to
Type::noneduring type rewriting and strip the return expressions and call site result types during optimization.