Commit Graph

1829 Commits

Author SHA1 Message Date
Dan Gohman
9e4ab7dc86 Rename CallConv::Native to CallConv::SystemV. (#291)
To keep cross-compiling straightforward, Cretonne shouldn't have any
behavior that depends on the host. This renames the "Native" calling
convention to "SystemV", which has a defined meaning for each target,
so that it's clear that the calling convention doesn't change
depending on what host Cretonne is running on.
2018-03-30 12:32:14 -07:00
Dan Gohman
6606b88136 Optimize immediates and compare and branch sequences (#286)
* Add a pre-opt optimization to change constants into immediates.

This converts 'iadd' + 'iconst' into 'iadd_imm', and so on.

* Optimize away redundant `bint` instructions.

Cretonne has a concept of "Testable" values, which can be either boolean
or integer. When the an instruction needing a "Testable" value receives
the result of a `bint`, converting boolean to integer, eliminate the
`bint`, as it's redundant.

* Postopt: Optimize using CPU flags.

This introduces a post-legalization optimization pass which converts
compare+branch sequences to use flags values on CPUs which support it.

* Define a form of x86's `urm` that doesn't clobber FLAGS.

movzbl/movsbl/etc. don't clobber FLAGS; define a form of the `urm`
recipe that represents this.

* Implement a DCE pass.

This pass deletes instructions with no side effects and no results that
are used.

* Clarify ambiguity about "32-bit" and "64-bit" in comments.

* Add x86 encodings for icmp_imm.

* Add a testcase for postopt CPU flags optimization.

This covers the basic functionality of transforming compare+branch
sequences to use CPU flags.

* Pattern-match irsub_imm in preopt.
2018-03-30 12:30:07 -07:00
Dan Gohman
5377092e5b Use #[cold] rather than #[inline(never)].
This gives optimizers more information about likely branch
probabilities.
2018-03-28 22:48:30 -07:00
Dan Gohman
4af95e37a6 Convert regular comments to documentation comments. 2018-03-28 22:48:30 -07:00
Dan Gohman
68b2040ba2 Document that opcodes.rs contains InstructionData. 2018-03-28 22:48:30 -07:00
Tyler McMullen
951ff11f85 [WIP] Add a Trap sink to code generation (#279)
* First draft of TrapSink implementation.

* Add trap sink calls to 'trapif' and 'trapff' recipes.

* Add SourceLoc to trap sink calls, and add trap sink calls to all loads and stores.

* Add IntegerDivisionByZero trap to div recipe.

* Only emit load/store traps if 'notrap' flag is not set on the instruction.

* Update filetest machinery to add new trap sink functionality.

* Update filetests to include traps in output.

* Add a few more trap outputs to filetests.

* Add trap output to CLI tool.
2018-03-28 22:48:03 -07:00
Dan Gohman
d566faa8fb Disable preopt at opt_level=fastest. 2018-03-28 22:13:13 -07:00
Dan Gohman
57cd69d8b4 Say "IR" instead of "IL".
While the specifics of these terms are debatable, "IR" generally
isn't incorrect in this context, and is the more widely recognized
term at this time.

See also the discussion in #267.

Fixes #267.
2018-03-28 22:07:26 -07:00
Dan Gohman
a297465c25 Tidy up comment formatting.
Convert several normal comments to documentation comments, and make
separator comments consistent with other files.
2018-03-28 22:07:23 -07:00
Dan Gohman
592db1de7a Tighten up the parser's verification of value aliases.
This prevents uses of undefined values from passsing through
unnoticed, and ensures that all aliases are ultimately resolved,
regardless of where they are defined.
2018-03-28 22:07:08 -07:00
Dan Gohman
e5ec7242cc Fix handling of value aliases, and re-enable LICM.
Value aliases aren't instructions, so they don't have a location in the
CFG, so it's not meaningful to query whether a value alias is defined
within a loop.
2018-03-28 22:06:52 -07:00
Dan Gohman
db2be8ee01 Verifier: Diagnose an instruction using its own result values. 2018-03-28 21:27:05 -07:00
Dan Gohman
23ab07b54e Support legalizing bconst instructions on x86. 2018-03-28 14:11:16 -07:00
Dan Gohman
c3f044ff46 Note that the "widen" legalization group is not yet implemented. 2018-03-28 13:44:54 -07:00
Dan Gohman
8d560cf8ba Fix Rust syntax in generated code.
This code is not currently emitted, though it will be when there
are more legalization rules.
2018-03-28 12:58:31 -07:00
Dan Gohman
7b51edd285 Fix spelling in a comment to be consistent with the code. 2018-03-28 08:58:58 -07:00
Dan Gohman
7cce4be96a Fix an incorrect index in "cton-util wasm -s". 2018-03-27 21:11:24 -07:00
Dan Gohman
0b5bb313cb Mark CondCode's functions #[must_use].
It's easy to forget whether they mutate the value in place or return a
new value. Marking them #[must_use] will catch cases where they are used
incorrectly.
2018-03-27 14:16:55 -07:00
Dan Gohman
79f02e42dd Use movss/movsd rather than movd/movq for floating-point loads and stores.
While there may be CPUs that have a domain crossing penalty here,
this also helps the generated code look more like the code produced
by other compilers.
2018-03-27 11:53:59 -07:00
Dan Gohman
3b0a9b9ecf Remove an unused argument. 2018-03-27 11:53:10 -07:00
Dan Gohman
a661a8a9bb Factor out common ways to call encode from a dfg or func. 2018-03-27 11:53:03 -07:00
Dan Gohman
ffe89cdc0a Rename %eflags to %rflags.
EFLAGS is a subregister of RFLAGS. For consistency with GPRs where we
use the 64-bit names to refer to the registers, use the 64-bit name for
RFLAGS as well.
2018-03-27 11:52:57 -07:00
Dan Gohman
14faef7374 Derive Debug for LiveValue. 2018-03-26 21:21:54 -07:00
Dan Gohman
685cde98a4 Mark loads from globals aligned and notrap.
Mark loads from globals generated by cton_wasm or by legalization as
`aligned` and `notrap`, since memory for these globals should be
allocated by the runtime environment for that purpose. This reduces
the number of potentially trapping instructions, which can reduce
the amount of metadata required by embedding environments.
2018-03-26 21:21:54 -07:00
Dan Gohman
bcd3309c15 Mention `reserved_reg` being unimplemented in the docs too. 2018-03-26 21:21:54 -07:00
Pat Hickey
80d2c5d9bf Implement shift-immediate encodings for x86 (#283)
* add x86 encodings for shift-immediate instructions

implements encodings for ishl_imm, sshr_imm, and ushr_imm. uses 8-bit immediates.

added tests for the encodings to intel/binary64.cton. Canonical versions
come from llvm-mc.

* translate test to use shift-immediates

* shift immediate encodings: use enc_i32_i64

and note why the regular shift encodings cant use it above

* add additional encoding tests for shift immediates

this covers 32 bit mode, and 64 bit operations in 64 bit mode.
2018-03-26 16:48:20 -07:00
Dan Gohman
51eea8b89d Add some comments noting unimplemented features.
While use of these features will trigger an `unimplemented!()`, it is
nice to let users know in advance about features which aren't yet
implemented.
2018-03-23 12:46:23 -07:00
Dan Gohman
aa73de8ca1 Make code that tests for specific opcode families more consistent. 2018-03-23 11:38:11 -07:00
Dan Gohman
9602b78320 Disable the LICM pass for now.
There appear to be underlying problems with the way Cretonne handles value
aliases, which are causing problems for LICM. Disable LICM until we have
a chance to fix the underlying issues.

Fixes #275.
2018-03-22 16:55:18 -07:00
Dan Gohman
fc7b0a7e51 Rename the no_std feature to core.
See
https://github.com/yurydelendik/wasmparser.rs/pull/49#issuecomment-375436225
for more details.
2018-03-22 13:43:06 -07:00
Dan Gohman
af8ac8f8ca Avoid calling analyze_branch() when the BranchInfo is not needed.
It's faster to just call `opcode().is_branch()`.
2018-03-22 13:18:25 -07:00
Dan Gohman
3ec7918ba1 Tidy up a redundant import. 2018-03-22 13:18:25 -07:00
Dan Gohman
e787357520 Wrap build.py's contents in a main function.
This prevents its local variables from becoming global variables.
2018-03-22 13:18:25 -07:00
Pat Hickey
03ee007624 Use clippy (#276)
* cton-util: fix some clippy unnecessary pass-by-value warnings

* clippy: ignore too many arguments / cyclomatic complexity in module

since these functions are taking args coming from the command line, i
dont think this is actually a valid lint, morally the arguments are all
from one structure

* cton-util: take care of remaining clippy warnings

* cton-reader: fix all non-suspicious clippy warnings

* cton-reader: disable clippy at site of suspicious lint

* cton-frontend: disable clippy at the site of an invalid lint

* cton-frontend: fix clippy warnings, or ignore benign ones

* clippy: ignore the camelcase word WebAssembly in docs

* cton-wasm: fix clippy complaints or ignore benign ones

* cton-wasm tests: fix clippy complaints

* cretonne: starting point turns off all clippy warnings

* cretonne: clippy fixes, or lower allow() to source of problem

* cretonne: more clippy fixes

* cretonne: fix or disable needless_lifetimes lint

this linter is buggy when the declared lifetime is used for another type
constraint.

* cretonne: fix clippy complaint about Pass::NoPass

* rustfmt

* fix prev minor api changes clippy suggested

* add clippy to test-all

* cton-filetests: clippy fixes

* simplify clippy reporting in test-all

* cretonne: document clippy allows better

* cretonne: fix some more clippy lints

* cretonne: fix clippy lints (mostly doc comments)

* cretonne: allow all needless_lifetimes clippy warnings

remove overrides at the false positives

* rustfmt
2018-03-22 13:10:41 -07:00
Dan Gohman
2b3df1a506 Add use declarations for std features.
Merge the `use` parts of the `no_std` branch. This reduces the diffs
between master and the `no_std` branch, making it easier to maintain.

Most of these changes are derived from patches by @lachlansneff in
https://github.com/Cretonne/cretonne/tree/no_std.
2018-03-20 14:07:05 -07:00
Dan Gohman
da4cf27780 Update to filecheck 0.3.0. 2018-03-20 13:28:35 -07:00
Dan Gohman
ca4582ae82 Rename the recipes for x86 spill/fill instructions.
Both "sp" and "fi" have multiple meanings in this context, so use slightly
longer but less ambiguous names.
2018-03-20 13:28:35 -07:00
Dan Gohman
f6b8cf86a5 Factor out br_if translation into helper functions. 2018-03-20 13:28:32 -07:00
Dan Gohman
c333a52e3e Factor out fcmp and icmp translation into helper functions. 2018-03-20 13:27:45 -07:00
Dan Gohman
2d1f9f874c Bump version to 0.4.1 2018-03-18 14:56:30 -07:00
Dan Gohman
d99b43e4b7 Add a hook to the wasm FuncEnvironment for emitting loop headers.
This will allow wasm implementations that wish to insert code into
every loop, for example to insert an interrupt check or a safepoint.
do so without relying on asynchronous signals.
2018-03-18 14:54:05 -07:00
Dan Gohman
492fa1283c Define an "interrupt" trap code.
This is a trap code for interrupting the running code, to allow
timeouts and safepoints to be implemented. It is resumable.
2018-03-18 14:54:05 -07:00
Dan Gohman
832d9d9a0d Minor code simplification. 2018-03-18 14:54:05 -07:00
Sergey Pepyakin
c161b0d103 Fix check-rustfmt.sh for macOS (#273)
There are two cases:

1. It seems that grep on macOS exits as soon as it finds the first match. This makes cargo unhappy and it prints message like "failed printing to stdout: Broken pipe (os error 32)". The solution is to fully consume the output from cargo. I choose to use tee for this task.

2. When in a strict mode, bash complains that $1 is not defined (when it's actually not defined in case of omitting --install). The solution is to apply bash substitution magic: when $1 is undefined or set to null substitute it with empty string.
2018-03-18 13:53:02 -07:00
Afnan Enayet
9a49bc2ec9 Rename I32 -> X86_32 and I64 -> X86_64 (#271)
* Rename `I32` -> `X86_32` and `I64` -> `X86_64`

* Format file to pass flake8 tests

* Fix comment so lines are under 80 char limit

* Remove trailing whitespace from comment

* Renamed `enc_i64` to `enc_x86_64` as per suggestion from PR
2018-03-18 13:50:51 -07:00
Dan Gohman
921cea2845 Bump version to 0.4.0 2018-03-16 16:12:56 -07:00
Dan Gohman
5e21ac1a30 Use whitespace more consistently in Cargo.toml files. 2018-03-16 16:01:15 -07:00
Dan Gohman
a4c51d66a8 Remove uses of println! in tests.
In this case, it's a little nicer to just use more assertions,
which will print their line number indicating how far the test
got, when they fail.

And this allows the tests to be run in no_std configurations.
2018-03-15 22:45:09 -07:00
Dan Gohman
06fe3b654f Avoid match expressions with reference patterns.
https://github.com/rust-lang-nursery/rust-clippy/wiki#match_ref_pats
2018-03-15 22:44:54 -07:00
Dan Gohman
99f7cb5b8d Use debug_assert_ne rather than debug_assert with a !=.
https://github.com/rust-lang-nursery/rust-clippy/wiki#should_assert_eq
2018-03-15 22:44:33 -07:00