Commit Graph

3681 Commits

Author SHA1 Message Date
Chris Fallin
bc56ab743c ISLE build-script check logic: Canonicalize All The Things!
writeln!() to a string on Windows to generate the expected manifest
needs newline-character canonicalization, too.
2021-11-16 15:11:56 -08:00
Chris Fallin
6a4716f0f4 Two CI fixes: Windows line-endings in manifest file, and "meta deterministic check".
- The Windows line-ending canonicalization was incomplete: we need to
  canonicalize the manifest text itself too!

- The "meta deterministic check" runs the cranelift-codegen build script
  N times outside of the source tree, examining what it produces to
  ensure the output is always the same (is detministic). This works fine
  when everything comes from the internal DSL, but when reading ISLE,
  this breaks because we no longer have the ISLE source paths.

  The initial ISLE integration did not hit this because without the
  `rebuild-isle` feature, it simply did nothing in the build script;
  now, with the manifest check, we hit the issue.

  The fix for now is just to turn off all ISLE-specific behavior in the
  build script by setting a special-purpose Cargo feature in the
  specific CI job. Eventually IMHO we should remove or find a better way
  to do this check.
2021-11-16 15:02:41 -08:00
Alex Crichton
f787ce433d aarch64: Remove manual sign extension in lowering (#3538)
Currently the lowering for `iconst` will sign-extend the payload value
of the `iconst` instruction itself, but the payload is already
sign-extended to this isn't necessary. This commit removes the redundant
sign extension.
2021-11-16 16:47:12 -06:00
Chris Fallin
a2b9664bed ISLE: guard against stale generated source in default build config.
Currently, the `build.rs` script that generates Rust source from the
ISLE DSL will only do this generation if the `rebuild-isle` Cargo
feature is specified. By default, it is not. This is based on the
principle that we (the build script) do not modify the source tree as
managed by git; git-managed files are strictly a human-managed and
human-edited resource. By adding the opt-in Cargo feature, a developer
is requesting the build script to perform an explicit action. (In my
understanding at least, this principle comes from the general philosophy
of hermetic builds: the output should be a pure function of the input,
and part of this is that the input is read-only. If we modify the source
tree, then all bets are off.)

Unfortunately, requiring the opt-in feature also creates a footgun that
is easy to hit: if a developer modifies the ISLE DSL source, but forgets
to specify the Cargo feature, then the compiler will silently be built
successfully with stale source, and will silently exclude any changes
that were made.

The generated source is checked into git for a good reason: we want DSL
compiler to not affect build times for the overwhelmingly common case
that Cranelift is used as a dependency but the backends are not being
actively developed. (This overhead comes mainly from building `islec`
itself.)

So, what to do? This PR implements a middle ground first described in
[this conversation](https://github.com/bytecodealliance/wasmtime/pull/3506#discussion_r743113351), in which we:

- Generate a hash (SHA-512) of the ISLE DSL source and produce a
  "manifest" of ISLE inputs alongside the generated source; and
- Always read the ISLE DSL source, and see if the manifest is still
  valid, on builds that do not have the opt-in "rebuild" feature.

This allows us to know whether the ISLE compiler output would have been
the same (modulo changes to the DSL compiler itself, which are
out-of-scope here), without actually building the ISLE compiler and
running it.

If the compiler-backend developer modifies an ISLE source file and then
tries to build `cranelift-codegen` without adding the `rebuild-isle`
Cargo feature, they get the following output:

```text
  Error: the ISLE source files that resulted in the generated Rust source

        * src/isa/x64/lower/isle/generated_code.rs

  have changed but the generated source was not rebuilt! These ISLE source
  files are:

         * src/clif.isle
         * src/prelude.isle
         * src/isa/x64/inst.isle
         * src/isa/x64/lower.isle

  Please add `--features rebuild-isle` to your `cargo build` command
  if you wish to rebuild the generated source, then include these changes
  in any git commits you make that include the changes to the ISLE.

  For example:

    $ cargo build -p cranelift-codegen --features rebuild-isle

  (This build script cannot do this for you by default because we cannot
  modify checked-into-git source without your explicit opt-in.)
```

which will tell them exactly what they need to do to fix the problem!

Note that I am leaving the "Rebuild ISLE" CI job alone for now, because
otherwise, we are trusting whomever submits a PR to generate the correct
generated source. In other words, the manifest is a communication from
the checked-in tree to the developer, but we still need to verify that
the checked-in generated Rust source and the manifest are correct with
respect to the checked-in ISLE source.
2021-11-16 13:50:41 -08:00
Alex Crichton
f30c8eb464 isle: Migrate f32const/f64const to ISLE (#3537)
This moves the `f32const` and `f64const` instructions from `lower.rs` to
ISLE. I was originally going to add something else but due to the
`isle.rs`'s manual use of `constructor_imm(..)` it necessitated filling
out the `imm` cases for f32/f64 constants, so I figured I'd go ahead and
move these instructions as well.

The special case for 0 constants which use `xorp{s,d}` is preserved from
`lower.rs` today, but a special case isn't added for the all-ones
constant. The comment says to use `cmpeqp{s,d}` but as discovered on
other recent PRs that's not quite sufficient because comparing a
register against itself which happens to be NaN wouldn't work, so
something else will be required (perhaps `pcmpeq` or similar? I figured
I'd defer to later)
2021-11-16 14:19:53 -06:00
Nick Fitzgerald
306c96b461 Merge pull request #3536 from alexcrichton/swap-isle-order
isle: Move immediates to the end of extractors
2021-11-16 10:13:17 -08:00
Alex Crichton
1c13f62189 isle: Move immediates to the end of extractors
Otherwise I was getting type errors trying to match `insertlane`
instructions, so I think that this was the intended order.
2021-11-16 09:07:24 -08:00
Alex Crichton
92394566fc x64: Migrate fabs and bnot vector operations to ISLE
This was my first attempt at transitioning code to ISLE to originally
fix #3327 but that fix has since landed on `main`, so this is instead
now just porting a few operations to ISLE.

Closes #3336
2021-11-16 07:36:49 -08:00
Johnnie Birch
5d5629de60 Fix for issue 3327. Updates Bnot to handle case for NaN float 2021-11-15 18:47:23 -08:00
Nick Fitzgerald
b38a96955c Merge pull request #3506 from fitzgen/isle
Initial ISLE integration for x64
2021-11-15 15:38:09 -08:00
Nick Fitzgerald
0b1bf104c6 Update miette graphical-forcing comment to reference upstream issue 2021-11-15 14:53:51 -08:00
Nick Fitzgerald
48ef2c0b84 Clarify comment about force_graphical in miette 2021-11-15 11:26:41 -08:00
Nick Fitzgerald
6164ba3814 ISLE: match cranelift version 2021-11-15 11:17:31 -08:00
Nick Fitzgerald
f27b357702 ISLE: update repo in Cargo.toml 2021-11-15 11:16:24 -08:00
Nick Fitzgerald
4a34d2c55b Remove old ISLE-generated file 2021-11-15 11:14:06 -08:00
Nick Fitzgerald
b6fd3d0c40 Remove extra, unused Cargo.lock 2021-11-15 09:25:29 -08:00
Alex Crichton
1548ca3c47 Disable check_label_branch_invariants in fuzzing
This commit disables the `MachBuffer::check_label_branch_invariants`
debug check on the fuzzers due to it causing timeouts with the test case
from #3441. Fuzzing leads to a 20-30x slowdown of executed code and
locally the fuzz time it takes to instantiate #3441 drops from 3 minutes
to 6 seconds disabling this function. Note that this should still be
executed during our testing on CI since it's still enabled for debug
assertions.
2021-11-15 07:34:09 -08:00
Nick Fitzgerald
bfbf2f2f49 ISLE: implement x64 lowering for band_not in ISLE 2021-11-11 15:19:28 -08:00
Nick Fitzgerald
33fcd6b4a5 x64: special case 0 to use xor in Inst::gen_constant for i128s 2021-11-10 15:57:58 -08:00
Nick Fitzgerald
b5105c025c MachInst: always rematerialize constants, rather than assign them registers
There were a few previous code paths that attempted to handle this, but this new
check handles it for all callers.

Rematerializing constants, rather than assigning and reusing a register, allows
for lower register pressure.
2021-11-10 15:45:43 -08:00
Nick Fitzgerald
bbb4949128 ISLE: use lower_to_amode inside sink_load implementation 2021-11-10 13:21:48 -08:00
Nick Fitzgerald
7a568b19b4 ISLE: run rustfmt on generated code 2021-11-05 15:59:49 -07:00
Nick Fitzgerald
b8494822dc ISLE: finish porting imul lowering to ISLE 2021-11-05 15:41:24 -07:00
Nick Fitzgerald
30d206779e x64: Remove some unreachable code that's been ported to ISLE 2021-11-05 14:28:03 -07:00
Nick Fitzgerald
00e7ca206f ISLE: add a missing type check for whether terms used in expressions have a constructor 2021-11-05 14:05:38 -07:00
Benjamin Bouvier
c952969389 Remove unused dependencies (#3490)
* Remove unused dependencies in Cranelift

* add serde to the current workspace

* remove more unused dependencies in wasmtime?
2021-11-02 12:08:30 -05:00
Chris Fallin
5e96a447f0 Add back the ifcmp_sp CLIF opcode.
This opcode was removed as part of the old-backend cleanup in #3446.
While this opcode will definitely go away eventually, it is
unfortunately still used today in Lucet (as we just discovered while
working to upgrade Lucet's pinned Cranelift version). Lucet is
deprecated and slated to eventually be completely sunset in favor of
Wasmtime; but until that happens, we need to keep this opcode.
2021-11-01 13:34:31 -07:00
Chris Fallin
9e7760bd83 Merge pull request #3497 from bjorn3/misc_meta_simplifications
Misc meta crate cleanups
2021-11-01 11:24:44 -07:00
bjorn3
86d2ef8952 Fix CI 2021-11-01 18:19:59 +01:00
bjorn3
93e9bb02e4 Review comments 2021-11-01 18:17:57 +01:00
bjorn3
55f8f8ce05 Remove a bit of dead code 2021-10-31 19:57:04 +01:00
bjorn3
f84e1c16c7 Enforce all OperandKind have documentation 2021-10-31 19:57:04 +01:00
bjorn3
e8f3c0c6a9 Use InstructionFormat inside InstructionFormatBuilder 2021-10-31 19:57:04 +01:00
bjorn3
2fbd57e9e2 Remove imm_with_name
It is only used once to rename an imm field to mask
2021-10-31 19:57:04 +01:00
bjorn3
74261ccd79 Never use the first vararg as typevar operand
If an instruction only takes varargs as values, it may have no arguments
at all.
2021-10-31 19:57:04 +01:00
bjorn3
e4d42a1be4 Move arg unpacking for all remaining expand functions to simple_legalize 2021-10-31 18:26:25 +01:00
bjorn3
ce3175993a Inline expand_br_icmp, expand_stack_load and expand_stack_store 2021-10-31 18:00:39 +01:00
bjorn3
96b14ed8eb Match on InstructionData instead of Opcode
This should be faster by avoiding matching on InstructionData to get the
Opcode, then on Opcode and then finally on the InstructionData again to
get the arguments
2021-10-31 17:52:43 +01:00
Chris Fallin
e953c2dd4c Merge pull request #3480 from bjorn3/move_constant_hash_gen_table
Move generate_table from cranelift-codegen-shared to cranelift-codege…
2021-10-29 09:59:56 -07:00
wasmtime-publish
c1a6a0523d Release Wasmtime 0.31.0 (#3489)
* Bump Wasmtime to 0.31.0

[automatically-tag-and-release-this-commit]

* Update 0.31.0 release notes

Co-authored-by: Wasmtime Publish <wasmtime-publish@users.noreply.github.com>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2021-10-29 09:09:35 -05:00
bjorn3
91d4f36970 Move generate_table from cranelift-codegen-shared to cranelift-codegen-meta 2021-10-29 14:43:09 +02:00
Nick Fitzgerald
49133f62e6 Merge pull request #3476 from fitzgen/logging-in-cranelift-test-compile
cranelift: in `test_compile` filetest, log disasm not clif
2021-10-26 11:00:23 -07:00
Nick Fitzgerald
8aa8dfe26a cranelift: in test_compile filetest, log disasm not clif
With the old backends, this would log the lowered+legalized clif, but the log is
useles now with the new backends. Logging the disasm is the new moral
equivalent.
2021-10-26 10:21:31 -07:00
Alex Crichton
490d49a768 Adjust dependency directives between crates (#3420)
* Adjust dependency directives between crates

This commit is a preparation for the release process for Wasmtime. The
specific changes here are to delineate which crates are "public", and
all version requirements on non-public crates will now be done with
`=A.B.C` version requirements instead of today's `A.B.C` version
requirements.

The purpose for doing this is to assist with patch releases that might
happen in the future. Patch releases of wasmtime are already required to
not break the APIs of "public" crates, but no such guarantee is given
about "internal" crates. This means that a patch release runs the risk,
for example, of breaking an internal API. In doing so though we would
also need to release a new major version of the internal crate, but we
wouldn't have a great hole in the number scheme of major versions to do
so. By using `=A.B.C` requirements for internal crates it means we can
safely ignore strict semver-compatibility between releases of internal
crates for patch releases, since the only consumers of the crate will be
the corresponding patch release of the `wasmtime` crate itself (or other
public crates).

The `publish.rs` script has been updated with a check to verify that
dependencies on internal crates are all specified with an `=`
dependency, and dependnecies on all public crates are without a `=`
dependency. This will hopefully make it so we don't have to worry about
what to use where, we just let CI tell us what to do. Using this
modification all version dependency declarations have been updated.

Note that some crates were adjusted to simply remove their `version`
requirement in cases such as the crate wasn't published anyway (`publish
= false` was specified) or it's in the `dev-dependencies` section which
doesn't need version specifiers for path dependencies.

* Switch to normal sever deps for cranelift dependencies

These crates will now all be considered "public" where in patch releases
they will be guaranteed to not have breaking changes.
2021-10-26 09:06:03 -05:00
Nick Fitzgerald
e3a423c3e8 Remove some uses of foo.expect(&format!(...)) pattern
This eagerly evaluates the `format!` and produces a `String` with a heap
allocation, regardless whether `foo` is `Some`/`Ok` or `None`/`Err`. Using
`foo.unwrap_or_else(|| panic!(...))` makes it so that the error message
formatting is only evaluated if `foo` is `None`/`Err`.
2021-10-25 17:35:23 -07:00
Anton Kirilov
e9c4164b94 Call membarrier() after making JIT mappings executable on AArch64 Linux
The membarrier() system call ensures that no processor has fetched
a stale instruction stream.

Copyright (c) 2021, Arm Limited.
2021-10-25 13:25:35 +01:00
Michael Chesser
da51fae4c3 Rename executable to already_protected 2021-10-22 13:44:47 +01:00
Michael Chesser
61ecccf306 Avoid updating memory protection on allocations that have the right protection. 2021-10-22 13:44:47 +01:00
Chris Fallin
472b1b2e8a Avoid quadratic behavior in pathological label-alias case in MachBuffer.
Fixes #3468.

If a program has many instances of the pattern "goto next; next:" in a
row (i.e., no-op branches to the fallthrough address), the branch
simplification in `MachBuffer` would remove them all, as expected.
However, in order to work correctly, the algorithm needs to track all
labels that alias the current buffer tail, so that they can be adjusted
later if another branch chomp occurs.

When many thousands of this branch-to-next pattern occur, many thousands
of labels will reference the current buffer tail, and this list of
thousands of labels will be shuffled between the branch metadata struct
and the "labels at tail" struct as branches are appended and then
chomped immediately.

It's possible that with smarter data structure design, we could somehow
share the list of labels -- e.g., a single array of all labels, in order
they are bound, with ranges of indices in this array used to represent
lists of labels (actually, that seems like a better design in general);
but let's leave that to future optimization work.

For now, we can avoid the quadratic behavior by just "giving up" if the
list is too long; it's always valid to not optimize a branch. It is very
unlikely that the "normal" case will have more than 100 "goto next"
branches in a row, so this should not have any perf impact; if it does,
we will leave 1 out of every 100 such branches un-optimized in a long
sequence of thousands.

This takes total compilation time down on my machine from ~300ms to
~72ms for the `foo.wasm` case in #3441. For reference, the old backend
(now removed), built from arbitrarily-chosen-1-year-old commit
`c7fcc344`, takes 158ms, so we're ~twice as fast, which is what I would
expect.
2021-10-21 12:07:39 -07:00
Chris Fallin
e9921574d7 Update to regalloc.rs 0.0.32.
It appears that some allocation heuristics have changed slightly since
0.0.31, so some of the golden-output filetests are updated as well.
Ideally we would rely more on runtests rather than golden-compilation
tests; but for now this is sufficient. (I'm not sure exactly what in
regalloc.rs changed to alter these heuristics; it's actually been almost
a year since the 0.0.31 release with several refactorings and tweaks
merged since then.)

Fixes #3441.
2021-10-20 15:28:42 -07:00