This repository was archived by the owner on Jun 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
Add early-stage optimization crate #556
Merged
sunfishcode
merged 16 commits into
bytecodealliance:master
from
lachlansneff:constant-folding
Nov 7, 2018
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f60cc91
Add simple constant folding and folding tests
lachlansneff 4b6f468
Add missing newlines
lachlansneff 7d21712
Fix constant size array compile error
lachlansneff eda7621
Redesign binary operation constant folding
lachlansneff 13e52f9
Remove 'enable_constant_folding' setting and move into optimize method
lachlansneff c051993
Remove unsafe code
lachlansneff 80d8b4e
Add software float support to the constant folding pass
lachlansneff 87ad3f3
Update to non-broken apfloat version
lachlansneff 34f2b84
Move constant folding to lib/preopt
lachlansneff 6d91dd6
Save spot commit
lachlansneff 055662a
Remove rustc_apfloats for now
lachlansneff 072d8ff
Remove redundant dce pass
lachlansneff 642e716
Fix more suggestions
lachlansneff a08e726
Update to new preopt pass name
lachlansneff 6afb3bb
Add unary folding pass
lachlansneff 03c0f30
Formatting fixes
lachlansneff 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| test preopt | ||
| target x86_64 | ||
|
|
||
| function %brz_fold() -> i32 { | ||
| ebb0: | ||
| v0 = bconst.b1 false | ||
| brz v0, ebb2 | ||
| jump ebb1 | ||
| ebb1: | ||
| v1 = iconst.i32 42 | ||
| return v1 | ||
| ebb2: | ||
| v2 = iconst.i32 24 | ||
| return v2 | ||
| } | ||
| ; sameln: function %brz_fold | ||
| ; nextln: ebb0: | ||
| ; nextln: v0 = bconst.b1 false | ||
| ; nextln: jump ebb2 | ||
| ; nextln: | ||
| ; nextln: ebb1: | ||
| ; nextln: v1 = iconst.i32 42 | ||
| ; nextln: return v1 | ||
| ; nextln: | ||
| ; nextln: ebb2: | ||
| ; nextln: v2 = iconst.i32 24 | ||
| ; nextln: return v2 | ||
| ; nextln: } | ||
|
|
||
| function %brnz_fold() -> i32 { | ||
| ebb0: | ||
| v0 = bconst.b1 true | ||
| brnz v0, ebb2 | ||
| jump ebb1 | ||
| ebb1: | ||
| v1 = iconst.i32 42 | ||
| return v1 | ||
| ebb2: | ||
| v2 = iconst.i32 24 | ||
| return v2 | ||
| } | ||
| ; sameln: function %brnz_fold | ||
| ; nextln: ebb0: | ||
| ; nextln: v0 = bconst.b1 true | ||
| ; nextln: jump ebb2 | ||
| ; nextln: | ||
| ; nextln: ebb1: | ||
| ; nextln: v1 = iconst.i32 42 | ||
| ; nextln: return v1 | ||
| ; nextln: | ||
| ; nextln: ebb2: | ||
| ; nextln: v2 = iconst.i32 24 | ||
| ; nextln: return v2 | ||
| ; nextln: } |
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,36 @@ | ||
| test preopt | ||
| target x86_64 | ||
|
|
||
| function %iadd_fold() -> i32 { | ||
| ebb0: | ||
| v0 = iconst.i32 37 | ||
| v1 = iconst.i32 5 | ||
| v2 = iadd v0, v1 | ||
| v3 = iconst.i32 8 | ||
| v4 = iadd v2, v3 | ||
| return v4 | ||
| } | ||
| ; sameln: function %iadd_fold | ||
| ; nextln: ebb0: | ||
| ; nextln: v0 = iconst.i32 37 | ||
| ; nextln: v1 = iconst.i32 5 | ||
| ; nextln: v2 = iconst.i32 42 | ||
| ; nextln: v3 = iconst.i32 8 | ||
| ; nextln: v4 = iconst.i32 50 | ||
| ; nextln: return v4 | ||
| ; nextln: } | ||
|
|
||
| function %isub_fold() -> i32 { | ||
| ebb0: | ||
| v0 = iconst.i32 42 | ||
| v1 = iconst.i32 1 | ||
| v2 = isub v0, v1 | ||
| return v2 | ||
| } | ||
| ; sameln: function %isub_fold | ||
| ; nextln: ebb0: | ||
| ; nextln: v0 = iconst.i32 42 | ||
| ; nextln: v1 = iconst.i32 1 | ||
| ; nextln: v2 = iconst.i32 41 | ||
| ; nextln: return v2 | ||
| ; nextln: } |
2 changes: 1 addition & 1 deletion
2
filetests/preopt/div_by_const_indirect.clif → .../simple_preopt/div_by_const_indirect.clif
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| test preopt | ||
| test simple_preopt | ||
| target i686 baseline | ||
|
|
||
| ; Cases where the denominator is created by an iconst | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
...s/preopt/div_by_const_non_power_of_2.clif → ...e_preopt/div_by_const_non_power_of_2.clif
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| test preopt | ||
| test simple_preopt | ||
| target i686 baseline | ||
|
|
||
| ; -------- U32 -------- | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
...tests/preopt/div_by_const_power_of_2.clif → ...imple_preopt/div_by_const_power_of_2.clif
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| test preopt | ||
| test simple_preopt | ||
| target i686 baseline | ||
|
|
||
| ; -------- U32 -------- | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
...s/preopt/rem_by_const_non_power_of_2.clif → ...e_preopt/rem_by_const_non_power_of_2.clif
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| test preopt | ||
| test simple_preopt | ||
| target i686 baseline | ||
|
|
||
| ; -------- U32 -------- | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
...tests/preopt/rem_by_const_power_of_2.clif → ...imple_preopt/rem_by_const_power_of_2.clif
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| test preopt | ||
| test simple_preopt | ||
| target i686 baseline | ||
|
|
||
| ; -------- U32 -------- | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
filetests/preopt/simplify.clif → filetests/simple_preopt/simplify.clif
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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| test preopt | ||
| test simple_preopt | ||
| target i686 | ||
|
|
||
| function %iadd_imm(i32) -> i32 { | ||
|
|
||
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
File renamed without changes.
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,44 @@ | ||
| //! Test command for testing the preopt pass. | ||
| //! | ||
| //! The resulting function is sent to `filecheck`. | ||
|
|
||
| use cranelift_codegen; | ||
| use cranelift_codegen::ir::Function; | ||
| use cranelift_codegen::print_errors::pretty_error; | ||
| use cranelift_reader::TestCommand; | ||
| use std::borrow::Cow; | ||
| use subtest::{run_filecheck, Context, SubTest, SubtestResult}; | ||
|
|
||
| struct TestSimplePreopt; | ||
|
|
||
| pub fn subtest(parsed: &TestCommand) -> SubtestResult<Box<SubTest>> { | ||
| assert_eq!(parsed.command, "simple_preopt"); | ||
| if !parsed.options.is_empty() { | ||
| Err(format!("No options allowed on {}", parsed)) | ||
| } else { | ||
| Ok(Box::new(TestSimplePreopt)) | ||
| } | ||
| } | ||
|
|
||
| impl SubTest for TestSimplePreopt { | ||
| fn name(&self) -> &'static str { | ||
| "simple_preopt" | ||
| } | ||
|
|
||
| fn is_mutating(&self) -> bool { | ||
| true | ||
| } | ||
|
|
||
| fn run(&self, func: Cow<Function>, context: &Context) -> SubtestResult<()> { | ||
| let mut comp_ctx = cranelift_codegen::Context::for_function(func.into_owned()); | ||
| let isa = context.isa.expect("preopt needs an ISA"); | ||
|
|
||
| comp_ctx.flowgraph(); | ||
| comp_ctx | ||
| .preopt(isa) | ||
| .map_err(|e| pretty_error(&comp_ctx.func, context.isa, Into::into(e)))?; | ||
|
|
||
| let text = &comp_ctx.func.display(isa).to_string(); | ||
| run_filecheck(&text, context) | ||
| } | ||
| } |
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,27 @@ | ||
| [package] | ||
| authors = ["The Cranelift Project Developers"] | ||
| name = "cranelift-preopt" | ||
| version = "0.22.0" | ||
| description = "Support for optimizations in Cranelift" | ||
| license = "Apache-2.0 WITH LLVM-exception" | ||
| documentation = "https://cranelift.readthedocs.io/" | ||
| repository = "https://github.com/CraneStation/cranelift" | ||
| categories = ["no_std"] | ||
| readme = "README.md" | ||
| keywords = ["optimize", "compile", "compiler", "jit"] | ||
|
|
||
| [dependencies] | ||
| cranelift-codegen = { path = "../codegen", version = "0.22.0", default-features = false } | ||
| cranelift-entity = { path = "../entity", version = "0.22.0", default-features = false } | ||
| # This is commented out because it doesn't build on Rust 1.25.0, which | ||
| # cranelift currently supports. | ||
| # rustc_apfloat = { version = "0.1.2", default-features = false } | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = ["cranelift-codegen/std", "cranelift-entity/std"] | ||
| core = ["cranelift-codegen/core"] | ||
|
|
||
| [badges] | ||
| maintenance = { status = "experimental" } | ||
| travis-ci = { repository = "CraneStation/cranelift" } | ||
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.