Commit Graph

532 Commits

Author SHA1 Message Date
Dan Gohman
e4ef2cbf22 Support ISA-specific settings in the --isa command-line option. 2017-10-05 10:06:40 -07:00
Jakob Stoklund Olesen
826d4062fb Apply register diversions during binemit tests.
When "binemit" tests encode instructions, keep track of the current set
of register diversions, and use the diverted locations to check operand
constraints.

This matches how constraints are applied during a real binemit phase.
2017-10-04 17:02:09 -07:00
Dan Gohman
196795017b Tidy up handling of the DummyRuntime. 2017-10-04 16:57:39 -07:00
Dan Gohman
d857aacec3 Sniff the wasm magic bytes, rather than relying on the filename extension. 2017-10-03 09:43:37 -07:00
Dan Gohman
ba14499fe9 Factor out the code for reading a file into a utility function. 2017-10-03 09:43:30 -07:00
Dan Gohman
f064418652 Refactor set/isa parsing into a utility function. 2017-10-03 09:43:27 -07:00
Dan Gohman
12ab4cd914 Add a cton-util compile command. 2017-10-03 09:42:50 -07:00
Dan Gohman
25b8b45a41 Avoid unnecessary BufReaders. 2017-10-03 09:34:41 -07:00
Dan Gohman
eba55cb1da Make the "wat2wasm" error message not panic. 2017-10-03 09:31:42 -07:00
Dan Gohman
1efa670f60 Do a full compile in 'cton-util wasm'.
This removes the `optimize` option, as one can do that with
`--set`, eg. `--set opt_level=best`. And it adds an option to
print the compilation output.
2017-10-03 09:30:45 -07:00
Dan Gohman
14d6d1117d Clean up unneeded '&'s. 2017-09-25 13:05:29 -07:00
Jakob Stoklund Olesen
76eb7df9f0 Add an isa::StackRef type.
This contains encoding details for a stack reference: The base register
and offset to use in the specific instruction encoding.

Generate StackRef objects called in_stk0 etc for the binemit recipe
code. All binemit recipes need to compute base pointer offsets for stack
references, so have the automatically generated code do it.
2017-09-22 13:34:33 -07:00
Angus Holder
3b66c0be40 Emit compressed instruction encodings for instructions where constraints allow 2017-09-22 07:54:26 -07:00
Dan Gohman
ed6630dc02 Move verify calls back into Context, using FlagsOrIsa.
With FlagsOrIsa, we can pass around the information we need to run
the verifier from the Context even when a TargetIsa is not available.
2017-09-20 16:42:13 -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
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
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
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
c7b1bb5f9e Simplify using map_err and expect. 2017-09-12 13:40:19 -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
ddd398b790 Remove a redundant copy of pretty_verifier_error. 2017-09-12 09:00:32 -07:00
Jakob Stoklund Olesen
dc2bee9cef Add a FuncEnvironment::make_direct_func() callback.
This allows the environment to control the signatures used for direct
function calls. The signature and calling convention may depend on
whether the function is imported or local.

Also add WasmRuntime::declare_func_{import,type} to notify the runtime
about imported and local functions. This is necessary so the runtime
knows what function indexes are referring to .

Since imported and local functions are now declared to the runtime, it
is no longer necessary to return hashes mapping between WebAssembly
indexes and Cretonne entities.

Also stop return null entries for the imported functions in the
TranslationResult. Just return a vector of local functions.
2017-09-06 12:36:19 -07:00
Dan Gohman
45b093ea59 Use write_all() to write to write an entire string rather than write().
https://github.com/rust-lang-nursery/rust-clippy/wiki#unused_io_amount
2017-09-06 11:02:17 -07:00
Dan Gohman
320c88f365 Rename cretonne_wasm to cton_wasm, for consistency with the other libraries. 2017-09-05 16:30:44 -07:00
Jakob Stoklund Olesen
52cbbcd069 Add a CtonError::InvalidInput variant.
This error code will be used to complain when a WebAssembly binary code
can't be parsed.
2017-09-01 13:08:07 -07:00
Dan Gohman
566c772e20 Eliminate more unnecessary calls to .iter(). 2017-08-31 17:03:12 -07:00
Dan Gohman
7be0abb442 Remove an unneeded extern crate. 2017-08-31 14:31:45 -07:00
Dan Gohman
9726bb7367 Avoid matching with reference patterns.
https://github.com/rust-lang-nursery/rust-clippy/wiki#match_ref_pats
2017-08-31 12:47:05 -07:00
Dan Gohman
2efdc0ed37 Update rustfmt to 0.9.0. 2017-08-31 10:44:59 -07:00
Dan Gohman
9ea5226b89 Add simple_gvn to the optimization pipeline for WebAssembly functions. 2017-08-30 14:32:42 -07:00
Dan Gohman
253f602a4c Fix a few warnings. 2017-08-28 17:17:41 -07:00
Denis Merigoux
ee9989c4b9 Dumped code from the wasm2cretonne repo.
Integrated wasm test suite translation as cretonne test

Fixes #146.
Fixes #143.
2017-08-28 15:57:43 -07:00
Jakob Stoklund Olesen
7e08b14cf6 Split EntityMap into entity::PrimaryMap and entity::EntityMap.
The new PrimaryMap replaces the primary EntityMap and the PrimaryEntityData
marker trait which was causing some confusion. We now have a clear
division between the two types of maps:

- PrimaryMap is used to assign entity numbers to the primary data for an
  entity.
- EntityMap is a secondary mapping adding additional info.

The split also means that the secondary EntityMap can now behave as if
all keys have a default value. This means that we can get rid of the
annoying ensure() and get_or_default() methods ther were used everywhere
instead of indexing. Just use normal indexing now; non-existent keys
will return the default value.
2017-08-18 16:04:43 -07:00
Jakob Stoklund Olesen
53d9232d39 Track regmove instruction during binemit.
Register locations can change throughout an EBB. Make sure the
emit_inst() function considers this when encoding instructions and
update the register diversion tracker.
2017-07-18 12:52:53 -07:00
Jakob Stoklund Olesen
2f7057b96f Add a Context::emit_to_memory function.
This function will emit the binary machine code into contiguous raw
memory while sending relocations to a RelocSink.

Add a MemoryCodeSink for generating machine code directly into memory
efficiently. Allow the TargetIsa to provide emit_function
implementations that are specialized to the MemoryCodeSink type to avoid
needless small virtual callbacks to put1() et etc.
2017-07-18 08:03:53 -07:00
Jakob Stoklund Olesen
9e3b6a6eba Add a Context::compile() function which runs all compiler passes.
This is the main entry point to the code generator. It returns the
computed size of the functions code.

Also add a 'test compile' command which runs the whole code generation
pipeline.
2017-07-12 12:22:49 -07:00
Jakob Stoklund Olesen
69f974ba5d Add an ISA argument to dfg.display_inst().
Include ISA-specific annotations in tracing and error messages.
2017-07-12 10:13:13 -07:00
Jakob Stoklund Olesen
e4da2e1f22 Include ISA-specific information in verifier errors.
When the test driver reports a verifier error, make sure to include the
TargetIsa when printing the failing function.
2017-07-12 10:13:13 -07:00
Jakob Stoklund Olesen
897c363714 Update docopt dependency to 0.8.0.
This breaks our depending on two different versions of the regex
library.

This updated docopt uses serde instead of rustc_serialize.
2017-06-14 10:38:06 -07:00
Denis Merigoux
e47f4a49fb LICM pass (#87)
* LICM pass

* Uses loop analysis to detect loop tree
* For each loop (starting with the inner ones), create a pre-header and move there loop-invariant instructions
* An instruction is loop invariant if it does not use as argument a value defined earlier in the loop
* File tests to check LICM's correctness
* Optimized pre-header creation
If the loop already has a natural pre-header, we use it instead of creating a new one.
The natural pre-header of a loop is the only predecessor of the header it doesn't dominate.
2017-06-07 11:27:22 -07:00
Dan Gohman
c826aefa0a Start a very simple GVN pass (#79)
* Skeleton simple_gvn pass.
* Basic testing infrastructure for simple-gvn.
* Add can_load and can_store flags to instructions.
* Move the replace_values function into the DataFlowGraph.
* Make InstructionData derive from Hash, PartialEq, and Eq.
* Make EntityList's hash and eq functions panic.
* Change Ieee32 and Ieee64 to store u32 and u64, respectively.
2017-05-18 18:18:57 -07:00
Benjamin Bouvier
29dc723e25 Update rustfmt to 0.8.4; (#81) 2017-05-15 15:10:47 -07:00
Dan Gohman
fb9d86f852 Fix rustfmt diffs. 2017-05-11 06:57:55 -07:00
Dan Gohman
ad9a942f52 Use write! in utility code, rather than calling write_function directly. 2017-05-11 06:57:55 -07:00
Jakob Stoklund Olesen
43304e9abc Upgrade to rustfmt 0.8.3. 2017-04-27 12:52:41 -07:00
Jakob Stoklund Olesen
ee5f035e31 Upgrade to Rust 1.17.
- Remove some uses of 'static in const and static globals that are no
  longer needed.
- Use the new struct initialization shorthand.
2017-04-27 12:46:44 -07:00