-
Notifications
You must be signed in to change notification settings - Fork 873
Add a extract-function-index pass #3939
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
2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Copyright 2021 WebAssembly Community Group participants | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| import sys | ||
| import subprocess | ||
|
|
||
| from test import support | ||
|
|
||
|
|
||
| # Usage: foreach infile tempfile cmd... | ||
| # | ||
| # Split 'infile', which contains multiple text modules, into separate temp files | ||
| # containing one text module each and named `tempfile`.0, `tempfile`.1, etc. Run | ||
| # `cmd` with the current temp file appended to it on all the temp files in | ||
| # sequence. Exit with code 0 only if all of the subprocesses exited with code 0. | ||
| def main(): | ||
| infile = sys.argv[1] | ||
| tempfile = sys.argv[2] | ||
| cmd = sys.argv[3:] | ||
| returncode = 0 | ||
| for i, (module, asserts) in enumerate(support.split_wast(infile)): | ||
| tempname = tempfile + '.' + str(i) | ||
| with open(tempname, 'w') as temp: | ||
| print(module, file=temp) | ||
| new_cmd = cmd + [tempname] | ||
| result = subprocess.run(new_cmd) | ||
| if result.returncode != 0: | ||
| returncode = result.returncode | ||
| sys.exit(returncode) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| ;; RUN: foreach %s %t wasm-opt --extract-function=foo -S -o - | filecheck %s | ||
| ;; RUN: foreach %s %t wasm-opt --extract-function --pass-arg=extract-function@foo -S -o - | filecheck %s | ||
| ;; RUN: foreach %s %t wasm-opt --extract-function-index=0 -S -o - | filecheck %s | ||
| ;; RUN: foreach %s %t wasm-opt --extract-function-index --pass-arg=extract-function-index@0 -S -o - | filecheck %s | ||
|
|
||
| ;; CHECK: (module | ||
| ;; CHECK-NEXT: (type $none_=>_none (func)) | ||
| ;; CHECK-NEXT: (import "env" "bar" (func $bar)) | ||
| ;; CHECK-NEXT: (export "foo" (func $foo)) | ||
| ;; CHECK-NEXT: (func $foo | ||
| ;; CHECK-NEXT: (call $bar) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (module | ||
| (func $foo | ||
| (call $bar) | ||
| ) | ||
| (func $bar | ||
| (call $foo) | ||
| ) | ||
| (func $other | ||
| (drop (i32.const 1)) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (module | ||
| ;; CHECK-NEXT: (type $none_=>_none (func)) | ||
| ;; CHECK-NEXT: (import "env" "other" (func $other)) | ||
| ;; CHECK-NEXT: (export "foo" (func $foo)) | ||
| ;; CHECK-NEXT: (func $foo | ||
| ;; CHECK-NEXT: (nop) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (module | ||
| ;; Use another function in the table, but the table is not used in the | ||
| ;; extracted function | ||
| (table $t 10 funcref) | ||
| (elem $0 (table $t) (i32.const 0) func $other) | ||
| (func $foo | ||
| (nop) | ||
| ) | ||
| (func $other | ||
| (drop (i32.const 1)) | ||
| ) | ||
| ) | ||
|
|
||
| ;; CHECK: (module | ||
| ;; CHECK-NEXT: (type $none (func)) | ||
| ;; CHECK-NEXT: (import "env" "other" (func $other)) | ||
| ;; CHECK-NEXT: (table $t 10 funcref) | ||
| ;; CHECK-NEXT: (elem $0 (i32.const 0) $other) | ||
| ;; CHECK-NEXT: (export "foo" (func $foo)) | ||
| ;; CHECK-NEXT: (func $foo | ||
| ;; CHECK-NEXT: (call_indirect (type $none) | ||
| ;; CHECK-NEXT: (i32.const 10) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| ;; CHECK-NEXT: ) | ||
| (module | ||
| ;; Use another function in the table, and the table *is* used. As a result, | ||
| ;; the table and its elements will remain. The called function, $other, will | ||
| ;; remain as an import that is placed in the table. | ||
| (type $none (func)) | ||
| (table $t 10 funcref) | ||
| (elem $0 (table $t) (i32.const 0) func $other) | ||
| (func $foo | ||
| (call_indirect (type $none) (i32.const 10)) | ||
| ) | ||
| (func $other | ||
| (drop (i32.const 1)) | ||
| ) | ||
| ) | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
test/passes/extract-function_pass-arg=extract-function@foo.txt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
test/passes/extract-function_pass-arg=extract-function@foo.wast
This file was deleted.
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.
These are manually-created, correct? I worry about us accumulating a lot of those and having a bad time some day when we need to update them. Adding
foreachseems like it would increase the amount of such test code... How hard would it be to support auto updating in these eventually?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.
Yes, these are manually created for now. I think it would be reasonable to update the auto update script in the near future to handle multiple multiple modules in a file and also to give it an option to emit checks on a per-module rather than a per-function basis.