-
Notifications
You must be signed in to change notification settings - Fork 858
Use effects for indirect call expressions #8625
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
Open
stevenfontanella
wants to merge
7
commits into
main
Choose a base branch
from
expression-effects
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+289
−274
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
58eb5c2
Use effects for indirect call expressions
stevenfontanella 253c092
PR updates
stevenfontanella 2156d99
WIP
stevenfontanella 7facc2a
PR updates
stevenfontanella 5aac82a
Extract a common function for setting effects for function calls
stevenfontanella 63d5515
Extract out fix for future PR
stevenfontanella 2fd577a
PR updates
stevenfontanella 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| #include "ir/intrinsics.h" | ||
| #include "pass.h" | ||
| #include "support/name.h" | ||
| #include "support/utilities.h" | ||
| #include "wasm-traversal.h" | ||
| #include "wasm-type.h" | ||
| #include "wasm.h" | ||
|
|
@@ -716,71 +717,50 @@ class EffectAnalyzer { | |
| } | ||
|
|
||
| void visitCall(Call* curr) { | ||
| // call.without.effects has no effects. | ||
| if (Intrinsics(parent.module).isCallWithoutEffects(curr)) { | ||
| if (curr->isReturn) { | ||
| parent.branchesOut = true; | ||
| } | ||
|
stevenfontanella marked this conversation as resolved.
Outdated
|
||
| return; | ||
| } | ||
|
|
||
| // Get the target's effects, if they exist. Note that we must handle the | ||
| // case of the function not yet existing (we may be executed in the middle | ||
| // of a pass, which may have built up calls but not the targets of those | ||
| // calls; in such a case, we do not find the targets and therefore assume | ||
| // we know nothing about the effects, which is safe). | ||
| const EffectAnalyzer* targetEffects = nullptr; | ||
| if (auto* target = parent.module.getFunctionOrNull(curr->target)) { | ||
| targetEffects = target->effects.get(); | ||
| } | ||
|
|
||
| if (curr->isReturn) { | ||
| parent.branchesOut = true; | ||
| // When EH is enabled, any call can throw. | ||
| if (parent.features.hasExceptionHandling() && | ||
| (!targetEffects || targetEffects->throws())) { | ||
| parent.hasReturnCallThrow = true; | ||
| } | ||
| const EffectAnalyzer* bodyEffects = nullptr; | ||
| if (auto* target = parent.module.getFunctionOrNull(curr->target); | ||
| target && target->effects) { | ||
| bodyEffects = target->effects.get(); | ||
| } | ||
|
|
||
| if (targetEffects) { | ||
| // We have effect information for this call target, and can just use | ||
| // that. The one change we may want to make is to remove throws_, if the | ||
| // target function throws and we know that will be caught anyhow, the | ||
| // same as the code below for the general path. We can always filter out | ||
| // throws for return calls because they are already more precisely | ||
| // captured by `branchesOut`, which models the return, and | ||
| // `hasReturnCallThrow`, which models the throw that will happen after | ||
| // the return. | ||
| if (targetEffects->throws_ && (parent.tryDepth > 0 || curr->isReturn)) { | ||
| auto filteredEffects = *targetEffects; | ||
| filteredEffects.throws_ = false; | ||
| parent.mergeIn(filteredEffects); | ||
| } else { | ||
| // Just merge in all the effects. | ||
| parent.mergeIn(*targetEffects); | ||
| } | ||
| populateEffectsForCall(curr, bodyEffects); | ||
| } | ||
| void visitCallIndirect(CallIndirect* curr) { | ||
| auto* table = parent.module.getTable(curr->table); | ||
| if (!Type::isSubType(Type(curr->heapType, Nullability::Nullable), | ||
| table->type)) { | ||
| parent.trap = true; | ||
|
kripken marked this conversation as resolved.
|
||
| return; | ||
| } | ||
| if (table->type.isNullable()) { | ||
|
stevenfontanella marked this conversation as resolved.
Outdated
|
||
| parent.implicitTrap = true; | ||
|
kripken marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| parent.calls = true; | ||
| // When EH is enabled, any call can throw. Skip this for return calls | ||
| // because the throw is already more precisely captured by the combination | ||
| // of `hasReturnCallThrow` and `branchesOut`. | ||
| if (parent.features.hasExceptionHandling() && parent.tryDepth == 0 && | ||
| !curr->isReturn) { | ||
| parent.throws_ = true; | ||
| const EffectAnalyzer* bodyEffects = nullptr; | ||
| if (auto it = parent.module.typeEffects.find(curr->heapType); | ||
| it != parent.module.typeEffects.end() && it->second) { | ||
|
stevenfontanella marked this conversation as resolved.
Outdated
|
||
| bodyEffects = it->second.get(); | ||
| } | ||
| populateEffectsForCall(curr, bodyEffects); | ||
| } | ||
| void visitCallIndirect(CallIndirect* curr) { | ||
| parent.calls = true; | ||
| if (curr->isReturn) { | ||
| parent.branchesOut = true; | ||
| if (parent.features.hasExceptionHandling()) { | ||
| parent.hasReturnCallThrow = true; | ||
| } | ||
| void visitCallRef(CallRef* curr) { | ||
| if (trapOnNull(curr->target)) { | ||
| return; | ||
| } | ||
| if (parent.features.hasExceptionHandling() && | ||
| (parent.tryDepth == 0 && !curr->isReturn)) { | ||
| parent.throws_ = true; | ||
|
|
||
| const EffectAnalyzer* bodyEffects = nullptr; | ||
| if (auto it = | ||
| parent.module.typeEffects.find(curr->target->type.getHeapType()); | ||
| it != parent.module.typeEffects.end() && it->second) { | ||
| bodyEffects = it->second.get(); | ||
| } | ||
| populateEffectsForCall(curr, bodyEffects); | ||
|
stevenfontanella marked this conversation as resolved.
Outdated
|
||
| } | ||
| void visitLocalGet(LocalGet* curr) { | ||
| parent.localsRead.insert(curr->index); | ||
|
|
@@ -1038,22 +1018,6 @@ class EffectAnalyzer { | |
| void visitTupleExtract(TupleExtract* curr) {} | ||
| void visitRefI31(RefI31* curr) {} | ||
| void visitI31Get(I31Get* curr) { trapOnNull(curr->i31); } | ||
| void visitCallRef(CallRef* curr) { | ||
| if (trapOnNull(curr->target)) { | ||
| return; | ||
| } | ||
| if (curr->isReturn) { | ||
| parent.branchesOut = true; | ||
| if (parent.features.hasExceptionHandling()) { | ||
| parent.hasReturnCallThrow = true; | ||
| } | ||
| } | ||
| parent.calls = true; | ||
| if (parent.features.hasExceptionHandling() && | ||
| (parent.tryDepth == 0 && !curr->isReturn)) { | ||
| parent.throws_ = true; | ||
| } | ||
| } | ||
| void visitRefTest(RefTest* curr) {} | ||
|
|
||
| void visitRefCast(RefCast* curr) { | ||
|
|
@@ -1335,6 +1299,55 @@ class EffectAnalyzer { | |
| parent.throws_ = true; | ||
| } | ||
| } | ||
|
|
||
| private: | ||
| // Populate effects of the function's body that were computed from | ||
| // GlobalEffects. Note that calls may have other effects that aren't | ||
| // captured by the function body of the target (e.g. a call_ref may trap on | ||
| // null refs). | ||
| template<typename CallType> | ||
|
stevenfontanella marked this conversation as resolved.
|
||
| void populateFunctionBodyEffects(const CallType* curr, | ||
| const EffectAnalyzer& funcEffects) { | ||
| if (curr->isReturn) { | ||
|
stevenfontanella marked this conversation as resolved.
|
||
| if (funcEffects.throws()) { | ||
| parent.hasReturnCallThrow = true; | ||
| } | ||
| } | ||
|
|
||
| if (funcEffects.throws_ && (parent.tryDepth > 0 || curr->isReturn)) { | ||
| auto filteredEffects = funcEffects; | ||
| filteredEffects.throws_ = false; | ||
| parent.mergeIn(filteredEffects); | ||
| } else { | ||
| parent.mergeIn(funcEffects); | ||
| } | ||
| } | ||
|
Comment on lines
1311
to
1326
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. Can't we just blindly merge |
||
|
|
||
| template<typename CallType> | ||
| void | ||
| populateEffectsForCall(const CallType* curr, | ||
| NullablePtr<const EffectAnalyzer*> bodyEffects) { | ||
| if (curr->isReturn) { | ||
| parent.branchesOut = true; | ||
| } | ||
|
|
||
| if (bodyEffects) { | ||
| populateFunctionBodyEffects(curr, *bodyEffects); | ||
| return; | ||
| } | ||
|
|
||
| parent.calls = true; | ||
| // If EH is enabled and we don't have global effects information, | ||
| // assume that the call body may throw. | ||
| if (parent.features.hasExceptionHandling()) { | ||
| if (curr->isReturn) { | ||
| parent.hasReturnCallThrow = true; | ||
| } | ||
| if (parent.tryDepth == 0 && !curr->isReturn) { | ||
| parent.throws_ = true; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| public: | ||
|
|
||
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.