Commit Graph

1125 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
1fdeddd0d3 Add Intel encodings for floating point load/store instructions.
Include wasm/*-memory64.cton tests too.
2017-09-19 09:32:54 -07:00
Jakob Stoklund Olesen
88348368a8 Add custom legalization for floating point constants.
Use the simplest expansion which materializes the bits of the floating
point constant as an integer and then bit-casts to the floating point
type. In the future, we may want to use constant pools instead. Either
way, we need custom legalization.

Also add a legalize_monomorphic() function to the Python targetISA class
which permits the configuration of a default legalization action for
monomorphic instructions, just like legalize_type() does for polymorphic
instructions.
2017-09-18 13:33:34 -07:00
Angus Holder
d2273c73ea Make the verifier accept any of the legal encodings of an instruction 2017-09-18 13:00:19 -07:00
Jakob Stoklund Olesen
da4cde8117 Always insert the entry EBB before translating any WASM.
The FuncEnvironment callbacks (make_global in particular) may need to
insert code in the entry EBB. We need to make sure the entry EBB has
been inserted in the layout before making those callbacks.
2017-09-18 11:53:32 -07:00
Dan Gohman
f5f37ac4a6 Use FlagsOrIsa to avoid requiring a --isa argument in cton-util wasm. 2017-09-15 15:43:47 -07:00
Jakob Stoklund Olesen
446fcdd7c5 Fix the REX bits for load/store instruction encodings.
The two registers were swapped in the REX encoding, and the tests didn't
have any high bit set registers.
2017-09-15 13:02:36 -07:00
Jakob Stoklund Olesen
cc3707706c Write and parse value locations for EBB arguments
Fixes #56.

We now have complete support for value location annotations in the
textual IL format. Values defined by instructions as well as EBB
arguments are covered.
2017-09-15 11:21:29 -07:00
Jakob Stoklund Olesen
24a5a02752 Add a RegDiversions::display() function.
Display the current register diversions for debugging purposes.
2017-09-15 10:48:53 -07:00
Jakob Stoklund Olesen
cba7a03275 Give better verifier errors for missing instruction encodings.
When possible, provide the ISA's default encoding as a suggesting for
the missing instruction encoding.
2017-09-15 09:32:56 -07:00
Jakob Stoklund Olesen
1349a6bdbc Always require a Flags reference for verifying functions.
Add a settings::FlagsOrIsa struct which represents a flags reference and
optionally the ISA it belongs to. Use this for passing flags/isa
information to the verifier.

The verify_function() and verify_context() functions are now generic so
they accept either a &Flags or a &TargetISa argument.

Fix the return_at_end verifier tests which no longer require an ISA
specified. The signle "set return_at_end" flag setting now makes it to
the verifier even when no ISA is present to carry it.
2017-09-14 17:51:15 -07:00
Dan Gohman
9e77af25a3 Add settings and isa command-line options to cton-util wasm. (#158)
* Add settings and isa command-line options to cton-util wasm.

* Use map_err to simplify error handling.

* Use `&*` instead of `.borrow()`.
2017-09-14 17:41:43 -07:00
Jakob Stoklund Olesen
0737aa48f2 Add legalization for imul_imm.
This is handled just like iadd_imm.
2017-09-14 16:06:06 -07:00
Dan Gohman
bbe056bf9d Make passes assert their dependencies consistently. (#156)
* Make passes assert their dependencies consistently.

This avoids ambiguity about whose responsibility it is to run
to compute cfg, domtree, and loop_analysis data.

* Reset the `valid` flag in DominatorTree's `clear()`.

* Remove the redundant assert from DominatorTree::with_function.

* Remove the message strings from obvious asserts.

This avoids having them spill out into multiple lines.

* Refactor calls to `compute` on `Context` objects into helper functions.
2017-09-14 14:38:53 -07:00
Jakob Stoklund Olesen
39992014e0 Make FuncEnvironment callbacks take an &mut self parameter.
The WasmRuntime trait already does this, and nothing in the function
translator requires the environment trait object to be non-mutable.
2017-09-14 12:25:59 -07:00
Dan Gohman
78c39ce078 Don't silently ignore argument or value locations. (#157)
No current tests actually rely on this, and it's surprising.
2017-09-14 09:26:37 -07:00
Jakob Stoklund Olesen
45f50120ef Handle special-purpose arguments in the Intel ABI.
The VMContext and SignatureId arguments are passed in fixed registers
for the spiderwasm calling convention.
2017-09-13 12:04:14 -07:00
Jakob Stoklund Olesen
eb42a2547e Add helper routines for special-purpose arguments.
- ArgumentType::special() creates a new special-purpose argument without
  assigning it to a register location.
- Signature::special_arg_index() funds a unique special-purpose
  argument.
- Function::special_arg() finds a special-purpose argument by value.

Also add a new "sigid" argument purpose which will be used for runtime
signature checks in WebAssembly indirect calls.
2017-09-13 11:35:33 -07:00
Jakob Stoklund Olesen
ef27c3daf0 Add an AsRef implementation to FuncName so we can read its contents. 2017-09-13 09:34:48 -07:00
Jakob Stoklund Olesen
5845f56cda Add x86-64 encodings for call instructions. 2017-09-13 09:34:48 -07:00
Dan Gohman
f5639a66e6 Flush stdout before writing to stderr.
In particular, terminal.reset() doesn't flush, so it ensures that stderr isn't
unintentionally printed in the color of the preceding line.
2017-09-12 16:58:56 -07:00
Dan Gohman
c7bd842ee3 Refactor code to use Context::verify instead of doing it manually. 2017-09-12 16:32:47 -07:00
Dan Gohman
e2f0fe58d1 Move logic out of cton-util wasm.
Give LoopAnalysis `is_valid` and `ensure` functions similar to
DominatorTree and others, so that it can be computed on demand in the
same way.

This removes the last need for src/wasm.rs to have embedded knowledge
of the dependencies of the passes it's running.
2017-09-12 16:32:47 -07:00
Dan Gohman
9d0d6b5a1b Move verify calls out of Context.
Also, move flowgraph() calls out of filetest and into the passes that
need them so that filetest doesn't have embedded knowledge of these
dependencies.

This resolves a TODO about the way Context was running the verifier, and
it makes the Context functions and the filetest runners more transparent.

This also fixes simple_gvn to use the existing dominator tree rather
than computing its own.
2017-09-12 16:32:47 -07:00
Dan Gohman
69f8174c03 Move ensure_domtree out of Context and into DominatorTree.
This also moves the calls to it out of Context and into the passes that
actually need it, so that Context's functions don't have any logic of
their own.
2017-09-12 16:32:47 -07:00
Dan Gohman
c7b1bb5f9e Simplify using map_err and expect. 2017-09-12 13:40:19 -07:00
Dan Gohman
ddf967962f Use --all in some scripts. (#154)
This avoids the need to list all the packages in test-all.sh.
2017-09-12 13:27:58 -07:00
Dan Gohman
1ab207b93c Add support for emitting code with a single return at the end. (#153)
This also enables testing of the wasmtests tests.

This also updates for wabt updating to the official "wat" filename
extension, as opposed to "wast".
2017-09-12 13:27:36 -07:00
Dan Gohman
2e046d68ce Remove obsolete derivations of Hash. 2017-09-12 12:28:25 -07:00
Jakob Stoklund Olesen
9b5295f3e2 Add a spiderwasm_prologue_words setting.
This makes the details of the spiderwasm prologue configurable so it is
easier to modify SpiderMonkey without having to change Cretonne.

Create a stack object representing the SpiderMonkey prologue words
before calculating the stack layout so they won't be overwritten by
Cretonne's stack objects.
2017-09-12 10:31:02 -07:00
Jakob Stoklund Olesen
cc35b5e724 Flush the debug trace file after each dbg!().
When debugging code built with panic=about, the debug trace buffer is
not flushed on a panic and important messages are lost.

This does slow down debug tracing a bit, but this is still better than
unbuffered or line buffered I/O since the dbg!() macro can write out
many lines like a whole function.
2017-09-12 10:31:02 -07:00
Dan Gohman
ddd398b790 Remove a redundant copy of pretty_verifier_error. 2017-09-12 09:00:32 -07:00
Dan Gohman
de27abcb2b Change translate_module to use FuncTranslator. 2017-09-11 18:01:50 -07:00
Dan Gohman
95e2566d6f Use TranslationState's popn/peekn functions. (#151)
This entailed reorganizing surrounding code to minimize the extent of
mutable borrows of the control-flow stack.
2017-09-11 13:58:49 -07:00
Dan Gohman
9bce21c17c Update to wasmparser 0.9.4 for a bugfix in create_binary_reader. 2017-09-11 11:34:39 -07:00
Dan Gohman
f8f6878b2c Switch to wasmparser's create_binary_reader() API for reading function bodies.
A subtle difference here is that the `end` at the end of a function body
now gets handled by translate_operator/translate_unreachable_operator, so we
no longer have to do as much special-case cleanup at the end of the function
body.

This is a preperatory step for converting module_translator.rs to use
the new FuncTranslator mechanism.
2017-09-11 11:27:02 -07:00
Jakob Stoklund Olesen
25af6d380b Add a return_at_end setting.
The flag guarantees that the generated function does not have any
internal return instructions. If the function returns at all, the return
must be the last instruction.

For now just implement a verifier check for this property. When we get
CFG simplifiers and block layout optimizations, they will need to heed
the flag.
2017-09-11 11:09:51 -07:00
Dan Gohman
7bf2747e1e Replace a match with a ?. 2017-09-11 08:47:41 -07:00
Dan Gohman
a2542ed71d Replace a match with a .unwrap_or_default(). 2017-09-11 08:47:38 -07:00
Dan Gohman
47bc963ba5 Add a JumpTableData::with_capacity and use it.
As with Vec::with_capacity, this helps reduce intermediate heap allocation.
2017-09-11 08:47:28 -07:00
Dan Gohman
620f1f49e2 Move several functions from FunctionBuilder to Function.
With FuncEnvironment using FuncCursors in place of full
FunctionBuilders, it's useful to move several of these convenience
functions from FunctionBuilder to Function.
2017-09-11 08:40:50 -07:00
Dan Gohman
2fa0a7a3a4 Fix a confusion between EndDataSectionEntry and EndDataSectionEntryBody. 2017-09-08 17:12:32 -07:00
Dan Gohman
3775fa4867 Update to wasmparser 0.9.3.
wasmparser's API is changing in anticipation of streaming decoding, so
it will now hand large data section initializers back in chunks rather
than all at once.
2017-09-08 16:17:31 -07:00
Jakob Stoklund Olesen
0c16f13c6b Add a Function::clear() method.
This makes it possible to clear out a Function data structure so it can
be reused for compiling multiple functions.

Also add clear() methods to various sub-structures.
2017-09-08 14:53:55 -07:00
Jakob Stoklund Olesen
439a40e5e4 Add a WebAssembly function translator.
The new FuncTranslator type can be used to translate binary WebAssembly
functions to Cretonne IL one at a time. It is independent of the
module-level parser also present in the cretonne-wasm crate.
2017-09-07 16:12:48 -07:00
Dan Gohman
c0f3eaafbc Publically declare GlobalValue.
It's used in the publically declared FuncEnvironment trait, so library
users should be able to name it.
2017-09-07 10:36:37 -07:00
Dan Gohman
388a96421b Add documentation comments to GlobalValue's fields. 2017-09-07 10:34:26 -07:00
Jakob Stoklund Olesen
d6f6af104b Make translate_operator() generic on FuncEnvironment.
This makes it clear that this function only uses the FuncEnvironment
trait and not WasmRuntime.

Also make the translate_{grow,current}_memory() methods take &self
instead of &mut self. The &mut was left on there by accident.
2017-09-06 16:24:55 -07:00
Jakob Stoklund Olesen
062dd41c93 Don't export the 'Local' type from cton_wasm.
This type is not longer used in any public interface, it has become an
internal implementation detail.

Also remove some unused exported types from the crate.
2017-09-06 15:56:39 -07:00
Jakob Stoklund Olesen
b10faca534 Move translate_grow_memory and translate_current_memory too.
This moves the last instruction-level callbacks into FuncEnvironment
such that the trait has all the information required to translate a
whole function.

Change the position argument to a FuncCursor. This eliminates all
exposure of FunctionBuilder<Local>, so its use properly becomes an
implementation detail.
2017-09-06 15:44:23 -07:00
Jakob Stoklund Olesen
26048c2ecc Move WasmRuntime::translate_call_indirect() into FuncEnvironment.
Add two new arguments:

- table_index is the WebAssembly table referenced in the indirect call.
- sig_index is the WebAssembly signature index. We still have the SigRef
  that was created by make_indirect_sig(), but the WebAssembly signature
  index may be needed for detecting type mismatches at runtime.

Change the insertion location to a plain FuncCursor rather than a
FunctionBuilder<Local>. The fact that cretonne-wasm uses FunctionBuilder
should be an implementation detail, and the callbacks don't need to
access WebAssembly locals, so they don't need the extended interface.

Add a FunctionBuilder::cursor() method which creates a FuncCursor for
inserting instructions in the current EBB.

Also add a FuncEnvironment::translate_call() method which allows the
environment to override direct calls the same way as indirect calls.
2017-09-06 15:18:55 -07:00