-
Notifications
You must be signed in to change notification settings - Fork 835
RemoveUnusedModuleElements: Optimize indirect calls when the table is immutable #8107
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
Changes from 6 commits
f0694a8
34d0f8a
c9189a1
3f15228
95eb651
35b6d43
73a4b08
d2f9a8c
774ea7d
5e884b2
34bffd3
f06c16f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,6 +120,40 @@ std::set<Name> getFunctionsNeedingElemDeclare(Module& wasm); | |
| // do so, and some do not, depending on their type and use.) | ||
| bool usesExpressions(ElementSegment* curr, Module* module); | ||
|
|
||
| // Information about a table's optimizability. | ||
| struct TableInfo { | ||
| // Whether the table may be modifed at runtime, either because it is imported | ||
| // or exported, or table.set operations exist for it in the code. | ||
| bool mayBeModified = false; | ||
|
|
||
| // Whether we can assume that the initial contents are immutable. See the | ||
| // toplevel comment. | ||
| bool initialContentsImmutable = false; | ||
|
||
|
|
||
| std::unique_ptr<TableUtils::FlatTable> flatTable; | ||
|
|
||
| // Whether we can optimize using this table's data, that is, we know something | ||
| // useful about the data there at compile time. The specifics about what we | ||
| // know are in the above fields. | ||
| bool canOptimize() const { | ||
| // We can optimize if: | ||
| // * Either the table can't be modified at all, or it can be modified but | ||
| // the initial contents are immutable (so we can optimize those | ||
| // contents, even if other things might be appended later). | ||
| // * The table is flat (so we can see what is in it). | ||
| return (!mayBeModified || initialContentsImmutable) && flatTable->valid; | ||
| } | ||
| }; | ||
|
|
||
| // A map of tables to their info. | ||
| using TableInfoMap = std::unordered_map<Name, TableInfo>; | ||
|
|
||
| // Compute a map with table optimizability info. We can be told that the initial | ||
| // contents of the tables are immutable (that is, existing data is not | ||
| // overwritten, but new things may be appended). | ||
| TableInfoMap computeTableInfo(Module& wasm, | ||
| bool initialContentsImmutable = false); | ||
|
|
||
| } // namespace wasm::TableUtils | ||
|
|
||
| #endif // wasm_ir_table_h | ||
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.
Let's do an early return here when
!hasUnmodifiableTableto decrease the indentation below.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.
Done.