Commit Graph

1589 Commits

Author SHA1 Message Date
Dan Gohman
d394ae0902 Enable "set -euo pipefail" in all bash scripts.
This enables "set -e", "set -u", and "set -o pipefail", which
catch common errors.
2018-02-27 15:32:21 -08:00
Dan Gohman
6a962e8b2c Add links to the docs.rs API documentation. 2018-02-27 15:26:06 -08:00
Dan Gohman
af154655d7 Replace as casts with type-conversion functions.
https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_lossless
2018-02-26 15:25:46 -08:00
Dan Gohman
e943d932b9 Change match self to match *self to avoid adding & to all patterns in a match.
https://rust-lang-nursery.github.io/rust-clippy/v0.0.186/index.html#match_ref_pats
2018-02-26 15:25:39 -08:00
Dan Gohman
234d097f65 Change println!("") to println!().
https://rust-lang-nursery.github.io/rust-clippy/v0.0.186/index.html#print_with_newline
2018-02-26 15:25:37 -08:00
Dan Gohman
0e22c74085 Track wasm reachability explicitly.
Maintain an explicit "reachable" flag when decoding wasm. Push placeholder
frames on the control-flow stack instead of just maintaining a count of
the stack depth in unreachable code, so that we can whether If blocks
have Elses, and whether block exits are branched to, in all contexts.

Fixes #217.
2018-02-26 15:24:33 -08:00
Dan Gohman
81c126619b Ignore unknown custom wasm sections. 2018-02-26 15:24:25 -08:00
Dan Gohman
2a26b70854 Update URLs. 2018-02-23 16:16:44 -08:00
Jakob Stoklund Olesen
ec746c3359 Add a publish-all.sh script.
Set identical version numbers on all cretonne-* crates and print "cargo
publish" commands.

Update all crates to version 0.1.0.
2018-02-23 12:51:14 -08:00
Benjamin Bouvier
f02c8fd1ff Fixes #244: Prints the generated code size and wasm bytecode size in wasm command; 2018-02-23 08:46:09 -08:00
Dan Gohman
c7655c4928 Add minimal README.md files to published crates.
This will put descriptions on the packages' crates.io pages.
2018-02-21 20:50:03 -08:00
Dan Gohman
8e6e976e68 Add .swx to .gitignore to hide vim files from cargo watch. 2018-02-21 19:04:35 -08:00
Dan Gohman
c3c31e5cdc Add an empty .rustfmt.toml.
The existence of this file signals to some editors that this repository
wishes to be formatted with rustfmt.
2018-02-21 15:14:03 -08:00
Dan Gohman
a55a582d4e Suppress printing of placeholder external functions.
With the change to the parser to preserve indices, it now inserts
placeholders to pad out index spaces as needed. Placeholder functions
use reserved signature indices, so skip them when writing them out,
to avoid writing them out as "sig4294967295".
2018-02-21 13:10:58 -08:00
Dan Gohman
20500913ad Change tabs to spaces, for consistency with rustfmt.
This code is in a macro, which is presumably why rustfmt itself doesn't
reformat it.
2018-02-21 12:32:26 -08:00
Jakob Stoklund Olesen
043d80f7e1 Make the bitset module private.
This is just an implementation detail.
2018-02-21 12:14:50 -08:00
Jakob Stoklund Olesen
eae8261b07 Make the regalloc module private.
Cretonne clients don't need to know how the register allocator works.

Export the RegDiversions type from the binemit module instead. It is
used by the "test binemit" driver.
2018-02-21 12:11:50 -08:00
Jakob Stoklund Olesen
2f58c371bc Make specific ISA sub-modules private.
We don't want ISA-specific details exposed in the public Cretonne APIs.
2018-02-21 12:06:58 -08:00
Jakob Stoklund Olesen
8d388b2218 Fix stack pointer offsets for outgoing arguments.
StackSlotKind::OutgoingArg stack slots have an offset that is relative
to our own stack pointer, while all other stack slot kinds have offsets
that are relative to the caller's stack pointer.

Make sure we generate the right sp-relative offsets for outgoing
arguments too.
2018-02-21 10:34:41 -08:00
Dan Gohman
69cc6c8af3 Clean up more comments referring to "source numbers". 2018-02-20 17:27:46 -08:00
Dan Gohman
10dcfcacdb Remove support for entity variables in filecheck.
Now that the parser doesn't renumber indices, there's no need for entity
variables like $v0.
2018-02-20 17:27:46 -08:00
Dan Gohman
a5b00b173e Don't renumber entities in the parser.
This makes it easier to debug testcases:
 - the entity numbers in a .cton file match the entity numbers used
   within Cretonne.
 - serializing and deserializing doesn't cause indices to change.

One disadvantage is that if a .cton file uses sparse entity numbers,
deserializing to the in-memory form doesn't compact it. However, the
text format is not intended to be performance-critical, so this isn't
expected to be a big burden.
2018-02-20 17:27:46 -08:00
Jakob Stoklund Olesen
c846ec1626 Catch NaN explicitly in expand_fcvt_to_uint().
When the input is a NaN, we need to generate a different trap code, so
use the new trapff instruction to generate such a trap after the first
floating point comparison.
2018-02-20 14:44:57 -08:00
Jakob Stoklund Olesen
b9b1d0fcd5 Add a trapff instruction.
This is the floating point equivalent of trapif: Trap when a given
condition is in the floating-point flags.

Define Intel encodings comparable to the trapif encodings.
2018-02-20 14:35:41 -08:00
Jakob Stoklund Olesen
1e56d44465 Remember the positive numbers in expand_fcvt_to_sint.
We can get an INT_MIN result when converting a positive number that is
too large to fit in an integer too.
2018-02-20 14:01:13 -08:00
Dan Gohman
21215529fe Simplify the code in make_inst_results_reusing; NFC. 2018-02-20 12:15:23 -08:00
Jakob Stoklund Olesen
ad896d9790 Add more legalization patterns for *_imm instructions.
When the imediate value is out of range for the legal encodings, convert
these instructions to an iconst followed by their register counterparts.
2018-02-20 10:47:46 -08:00
Jakob Stoklund Olesen
a6ab90f205 Legalize irsub_imm. 2018-02-16 15:50:36 -08:00
Jakob Stoklund Olesen
a9e799debb Add an avoid_div_traps setting.
This enables code generation that never causes a SIGFPE signal to be
raised from a division instruction. Instead, division and remainder
calculations are protected by explicit traps.
2018-02-16 13:10:29 -08:00
Pat Hickey
ed24320eda gen_settings: dont try to display a Preset descriptor in Flags (#241)
* gen_settings: dont try to display a Preset descriptor in Flags

Trying to display a preset doesnt make sense, and before this commit it
does not display anything meaningful - the printout just says e.g.
"haswell =\n".

The offset byte a preset descriptor isnt a valid offset into the
flag bytes, it is actually an offset into the PRESETS table. It will
cause a panic when the offset is out of bounds for the flag bytes,
which happens in the intel isa as of this commit.

* intel settings: test that display impl doesnt panic
2018-02-14 11:51:40 -08:00
Dan Gohman
42e1616b82 Update to wasmparser 0.14.1. 2018-02-13 20:14:54 -08:00
Jakob Stoklund Olesen
3ccc3f4f9b Add a stack_check instruction.
This instruction loads a stack limit from a global variable and compares
it to the stack pointer, trapping if the stack has grown beyond the
limit.

Also add a expand_flags transform group containing legalization patterns
for ISAs with CPU flags.

Fixes #234.
2018-02-13 10:48:06 -08:00
Jakob Stoklund Olesen
a73fcb2691 Pass an ISA argument to legalization functions.
This lets them look at the ISA flags.
2018-02-13 10:42:00 -08:00
Jakob Stoklund Olesen
60e70da0e6 Add Intel encodings for ifcmp_imm.
The instruction set has variants with 8-bit and 32-bit signed immediate
operands.

Add a TODO to use a TEST instruction for the special case ifcmp_imm x, 0.
2018-02-13 10:38:46 -08:00
Jakob Stoklund Olesen
788a78caf4 Add Intel encodings for ifcmp_sp.
Also generate an Into<RegUnit> implementation for the RU enums.
2018-02-09 14:32:29 -08:00
Jakob Stoklund Olesen
73c4c356c9 Add an ifcmp_sp instruction.
This will be used to implement the stack_check macro.
2018-02-09 13:59:49 -08:00
Jakob Stoklund Olesen
69f70fc61d Add Intel encodings for trapif.
This is implemented as a macro with a conditional jump over a ud2. This
way, we don't have to split up EBBs at every conditional trap.
2018-02-08 15:15:15 -08:00
Jakob Stoklund Olesen
11c721934c Add a trapif instruction.
This is a conditional trap controlled by integer CPU flags.
Compare to brif.
2018-02-08 14:40:46 -08:00
Jakob Stoklund Olesen
3eeef1c752 Add some missing instructions to the language reference. 2018-02-06 09:55:53 -08:00
Julian Seward
6f8a54b6a5 Adds support for legalizing CLZ, CTZ and POPCOUNT on baseline x86_64 targets.
Changes:

* Adds a new generic instruction, SELECTIF, that does value selection (a la
  conditional move) similarly to existing SELECT, except that it is
  controlled by condition code input and flags-register inputs.

* Adds a new Intel x86_64 variant, 'baseline', that supports SSE2 and
  nothing else.

* Adds new Intel x86_64 instructions BSR and BSF.

* Implements generic CLZ, CTZ and POPCOUNT on x86_64 'baseline' targets
  using the new BSR, BSF and SELECTIF instructions.

* Implements SELECTIF on x86_64 targets using conditional-moves.

* new test filetests/isa/intel/baseline_clz_ctz_popcount.cton
  (for legalization)

* new test filetests/isa/intel/baseline_clz_ctz_popcount_encoding.cton
  (for encoding)

* Allow lib/cretonne/meta/gen_legalizer.py to generate non-snake-caseified
  Rust without rustc complaining.

Fixes #238.
2018-02-06 09:43:00 -08:00
Jakob Stoklund Olesen
e3714ddd10 Add a func.inst_offsets() iterator.
This Function method can be used after the final code layout has been
computed. It returns all the instructions in an EBB along with their
encoded size and offset from the beginning of the function.

This is useful for extracting additional metadata about trapping
instructions and other things that may be needed by a VM.
2018-02-01 17:19:05 -08:00
Jakob Stoklund Olesen
429027e2f2 Stack alignment is 16 bytes on x86_64.
Make sure that the stack frame size is always a multiple of 16 as
specified by the x86_64 ABI.

Heads up @pchickey
2018-01-31 16:19:35 -08:00
Tyler McMullen
ff16583c59 Remove RSP from deref safe register class as well. 2018-01-29 14:18:08 -08:00
Pat Hickey
099b959d57 TargetIsa implies a Display of shared and isa-specific flags 2018-01-29 13:53:08 -08:00
Tyler McMullen
21f0fc39ad Further restrict Intel register classes to prevent incorrect encoding of R12 derefs. 2018-01-29 13:42:11 -08:00
Jakob Stoklund Olesen
584a33bca7 Give better error messages in "test binemit".
When an instruction can't be encoded, provide a bit more help:

- Detect missing register assignments for input and output operands.
- List encodings that where considered and rejected.
2018-01-29 09:16:33 -08:00
Pat Hickey
3f69581d03 cretonne::Context: add for_function constructor 2018-01-25 18:14:57 -08:00
Jakob Stoklund Olesen
ef2640d8a4 Add information about SpiderMonkey and rustc plans. 2018-01-25 15:48:28 -08:00
Jakob Stoklund Olesen
d56ce9e8bf Optimize DomForest::push_node().
The dominator tree pre-order is defined at the EBB granularity, but we
are looking for dominating nodes at the instruction level. This means
that we sometimes need to look higher up the DomForest stack for a
dominating node, using DominatorTree::dominates() instead of
DominatorTreePreorder::dominates().

Each dominance check involves the domtree.last_dominator() function
scanning up the dominator tree, starting from the new node that was
pushed. We can eliminate this duplicate work by exposing the
last_dominator() function to push_node().

As we are searching through nodes on the stack, maintain a last_dom
program point representing the previous return value from
last_dominator(). This way, we're only scanning the dominator tree once.
2018-01-24 15:01:58 -08:00
Jakob Stoklund Olesen
416b21c18d Pairwise virtual register coalescing.
Use a better algorithm for resolving interferences in virtual registers.
This improves code quality by generating much fewer copies on some
complicated functions.

After the initial union-find phase, the check_vreg() function uses a
Budimlic forest to check for interference between the values in the
virtual registers, as before. All the interference-free vregs are done.
Others are passed to synthesize_vreg() which dissolves the vreg and then
attempts to rebuild one or more vregs from the contained values.

The pairwise interference checks use *virtual copies* to make sure that
any future conflicts can be resolved by inserting a copy instruction.
This technique was not present in the old coalescer which caused some
correctness issues.

This coalescing algorithm makes much better code, and it is generally a
bit slower than before. Some of the slowdown is made up by the following
passes being faster because they have to process less code.

Example 1, the Python interpreter which contains a very large function
with a lot of variables.

Before:
  15.664    0.011  Register allocation
   1.535    1.535  RA liveness analysis
   2.872    1.911  RA coalescing CSSA
   4.436    4.436  RA spilling
   2.610    2.598  RA reloading
   4.200    4.199  RA coloring

After:
   9.795    0.013  Register allocation
   1.372    1.372  RA liveness analysis
   6.231    6.227  RA coalescing CSSA
   0.712    0.712  RA spilling
   0.598    0.598  RA reloading
   0.869    0.869  RA coloring

Coalescing is more than twice as slow, but because of the vastly better
code quality, overall register allocation time is improved by 37%.

Example 2, the clang compiler.

Before:
  57.148    0.035  Register allocation
   9.630    9.630  RA liveness analysis
   7.210    7.169  RA coalescing CSSA
   9.972    9.972  RA spilling
  11.602   11.572  RA reloading
  18.698   18.672  RA coloring

After:
  64.792    0.042  Register allocation
   8.630    8.630  RA liveness analysis
  22.937   22.928  RA coalescing CSSA
   8.684    8.684  RA spilling
   9.559    9.551  RA reloading
  14.939   14.936  RA coloring

Here coalescing is 3x slower, but overall regalloc time only regresses
by 13%.

Most examples are less extreme than these two. They just get better code
at about the same compile time.
2018-01-24 14:54:32 -08:00