-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Optimizer: Re-use CFG from type inference #50924
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -551,9 +551,9 @@ function finish(me::InferenceState, interp::AbstractInterpreter) | |
| # annotate fulltree with type information, | ||
| # either because we are the outermost code, or we might use this later | ||
| doopt = (me.cached || me.parent !== nothing) | ||
| recompute_cfg = type_annotate!(interp, me, doopt) | ||
| type_annotate!(interp, me, doopt) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can eliminate anything related to |
||
| if doopt && may_optimize(interp) | ||
| me.result.src = OptimizationState(me, interp, recompute_cfg) | ||
| me.result.src = OptimizationState(me, interp) | ||
| else | ||
| me.result.src = me.src::CodeInfo # stash a convenience copy of the code (e.g. for reflection) | ||
| end | ||
|
|
@@ -713,20 +713,31 @@ function type_annotate!(interp::AbstractInterpreter, sv::InferenceState, run_opt | |
| # 3. mark unreached statements for a bulk code deletion (see issue #7836) | ||
| # 4. widen slot wrappers (`Conditional` and `MustAlias`) and remove `NOT_FOUND` from `ssavaluetypes` | ||
| # NOTE because of this, `was_reached` will no longer be available after this point | ||
| # 5. eliminate GotoIfNot if either branch target is unreachable | ||
| # 5. eliminate GotoIfNot if either or both branches are statically unreachable | ||
| changemap = nothing # initialized if there is any dead region | ||
| for i = 1:nstmt | ||
| expr = stmts[i] | ||
| if was_reached(sv, i) | ||
| if run_optimizer | ||
| if isa(expr, GotoIfNot) && widenconst(argextype(expr.cond, src, sv.sptypes)) === Bool | ||
| if isa(expr, GotoIfNot) | ||
| # 5: replace this live GotoIfNot with: | ||
| # - GotoNode if the fallthrough target is unreachable | ||
| # - no-op if the branch target is unreachable | ||
| if !was_reached(sv, i+1) | ||
| expr = GotoNode(expr.dest) | ||
| elseif !was_reached(sv, expr.dest) | ||
| expr = nothing | ||
| # - no-op if :nothrow and the branch target is unreachable | ||
| # - cond if :nothrow and both targets are unreachable | ||
| # - typeassert if must-throw | ||
| if widenconst(argextype(expr.cond, src, sv.sptypes)) === Bool | ||
| block = block_for_inst(sv.cfg, i) | ||
| if !was_reached(sv, i+1) | ||
| cfg_delete_edge!(sv.cfg, block, block + 1) | ||
| expr = GotoNode(expr.dest) | ||
| elseif !was_reached(sv, expr.dest) | ||
| cfg_delete_edge!(sv.cfg, block, block_for_inst(sv.cfg, expr.dest)) | ||
| expr = nothing | ||
| end | ||
| elseif ssavaluetypes[i] === Bottom | ||
| block = block_for_inst(sv.cfg, i) | ||
| cfg_delete_edge!(sv.cfg, block, block + 1) | ||
| cfg_delete_edge!(sv.cfg, block, block_for_inst(sv.cfg, expr.dest)) | ||
| expr = Expr(:call, Core.typeassert, expr.cond, Bool) | ||
| end | ||
| end | ||
| end | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe we want to set up a special and explicit marker type instead of
Constto indicate a statement is known to be unreachable, e.g.