Commit Graph

513 Commits

Author SHA1 Message Date
Dan Gohman
fc857a758e Remove an unneeded block. 2017-10-04 12:22:32 -07:00
Dan Gohman
b4e7e918cc Use the correct index for printing function definitions when imports are present. 2017-10-04 12:22:07 -07:00
Dan Gohman
23bafd1218 Split the runtime and execution code into separate crates. 2017-10-03 14:57:52 -07:00
Dan Gohman
865a3d9f31 Rename wasmstandalone::StandaloneRuntime to wasmstandalone::Runtime. 2017-10-03 13:01:31 -07:00
Dan Gohman
6c4bbc643c Set the faerie target based on the cretonne target. 2017-10-03 12:39:52 -07:00
Dan Gohman
a68b2619bd Sniff the wasm magic bytes, rather than relying on the filename extension. 2017-10-03 12:23:59 -07:00
Dan Gohman
e5ed1517ce Fix the command name in the usage message. 2017-10-03 12:21:09 -07:00
Dan Gohman
324a395a95 Make the "wat2wasm" error message not panic. 2017-10-03 12:20:37 -07:00
Dan Gohman
5b0a083124 Avoid unnecessary BufReaders. 2017-10-03 06:56:23 -07:00
Dan Gohman
e64eb79aaf Fix dependency paths. wasmstandalone no longer depends on out-of-tree patches. 2017-09-23 15:38:38 -07:00
Dan Gohman
0c78a2f298 Import the wasm2obj experiment and minimally update it. 2017-09-23 15:38:38 -07:00
Dan Gohman
b583d75c7a Fix redundant borrows. 2017-09-22 16:11:11 -07:00
Dan Gohman
382415ed0c Fix a useless format!. 2017-09-22 16:09:10 -07:00
Dan Gohman
b89277d9ce Rename "wast" to "wat". 2017-09-22 15:57:32 -07:00
Dan Gohman
cdffc1b50a Roughly update for the recent Cretonne API changes.
Everything builds and simple modules run, though there's still lots more
to do.
2017-09-22 15:56:18 -07:00
Dan Gohman
73f5adb19d Clippy cleanups. 2017-09-06 09:56:14 -07:00
Dan Gohman
3868467917 Format with rustfmt 0.9.0. 2017-09-06 08:37:12 -07:00
Dan Gohman
d0fe50a2a8 Check in the wasmstandalone code.
This is based on the code in https://github.com/denismerigoux/cretonne/commits/wasm2cretonne
before wasmstandalone was removed, with minor updates for the new library structure.
It is not yet updated for the latest cretonne API changes.
2017-09-05 17:06:51 -07:00
Jakob Stoklund Olesen
2927878707 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
28457f82c3 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
6cc729a69b 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
b6d4b884ad 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
71af555e6f 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
e7c6efa31e 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
9b06f76057 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
dc809628f4 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
a2fd9cf0cc Update rustfmt to 0.8.4; (#81) 2017-05-15 15:10:47 -07:00
Dan Gohman
526feb161a Fix rustfmt diffs. 2017-05-11 06:57:55 -07:00
Dan Gohman
c571975a5c Use write! in utility code, rather than calling write_function directly. 2017-05-11 06:57:55 -07:00
Jakob Stoklund Olesen
15606fa735 Upgrade to rustfmt 0.8.3. 2017-04-27 12:52:41 -07:00
Jakob Stoklund Olesen
962a3a6a5e 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
Jakob Stoklund Olesen
c36aedfd03 Add an EntityMap::get_or_default() method.
This covers a common pattern for secondary entity maps: Get the value in
the map or the default value for out-of-range keys.
2017-04-25 15:53:30 -07:00
Eric Anholt
100666e300 Verify that the instruction encoding matches what the ISA would encode.
Fixes #69
2017-04-23 17:21:32 -07:00
Jakob Stoklund Olesen
85f277a2fb Add a liveness verifier.
The liveness verifier will check that the live ranges are consistent
with the function. It runs as part of the register allocation pipeline
when enable_verifier is set.

The initial implementation checks the live ranges, but not the
ISA-specific constraints and affinities.
2017-04-21 16:01:08 -07:00
Jakob Stoklund Olesen
225ed39fbd Run the verifier in the Context methods when it is enabled.
The test drivers can stop calling comp_ctx.verify because legalize() and
regalloc() do it themselves now.

This also makes it possible for those two passes to return other
CtonError codes in the future, not just verifier errors.
2017-04-21 12:36:35 -07:00
Jakob Stoklund Olesen
9c6a36d36d Move the ctrl_typevar function into dfg.
Soon, InstructionData won't have sufficient information to compute this.

Give TargetIsa::encode() an explicit ctrl_typevar argument. This
function does not require the instruction to be inserted in the DFG
tables.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
e56482d0fd Fix a bug in the binemit file test.
Only emit each instruction once, or the offset computations go all
wrong.
2017-04-06 11:17:46 -07:00
Jakob Stoklund Olesen
b5c74fdc25 Add a branch relaxation pass for #72.
Compute exact EBB header offsets and check that branches are in range.

Not implemented yet: Relax branches that are not in range.

Invoke the relax_branches() pass from the 'test binemit' file tests so
they can verify the proper encoding of branch instructions too.
2017-04-05 15:11:39 -07:00
Jakob Stoklund Olesen
847c8045fd Add a CodeOffset type and CodeSink::offset() method.
We need to keep track of code offsets in order to compute accurate
branch displacements.
2017-04-05 09:12:12 -07:00
Jakob Stoklund Olesen
8353651559 rustfmt 0.8.1 2017-04-05 09:00:11 -07:00
Jakob Stoklund Olesen
39e102b155 Add conditional branch encodings for RISC-V.
Not all br_icmp opcodes are present in the ISA. The missing ones can be
reached by commuting operands.

Don't attempt to encode EBB offsets yet. For now just emit an EBB
relocation for the branch instruction.
2017-04-03 15:16:25 -07:00
Jakob Stoklund Olesen
ffeeba7c93 Use pretty_verifier_error in runone too. 2017-03-29 15:30:44 -07:00
Jakob Stoklund Olesen
e1711f42f6 Run verifier after legalizer and regalloc file tests.
Run the verify_contexti() function after invoking the legalize() and
regalloc() context functions. This will help catch bad code produced by
these passes.
2017-03-29 15:19:03 -07:00
Jakob Stoklund Olesen
1d6049b8f8 Allow for unencoded instructions in the binemit tests.
If an instruction doesn't have an associated encoding, use the standard
TargetIsa hook to encode it.

The test still fails if an instruction can't be encoded. There is no
legalization step.
2017-03-29 09:55:49 -07:00
Jakob Stoklund Olesen
36eb39a1f8 Add a binemit test command.
This makes it possible to write file tests that verify the binary
encoding of machine code.
2017-03-28 15:56:30 -07:00
Jakob Stoklund Olesen
e941a7db5f Add a ControlFlowGraph argument to legalize_function.
Legalizing some instructions may require modifications to the control
flow graph, and some operations need to use the CFG analysis.

The CFG reference is threaded through all the legalization functions to
reach the generated expansion functions as well as the legalizer::split
module where it will be used first.
2017-03-21 16:00:28 -07:00
Jakob Stoklund Olesen
f84e218a93 Rename the 'cfg' module to 'flowgraph'.
The 'cfg' name was easy to confuse with 'configuration'.
2017-03-21 15:33:23 -07:00
Jakob Stoklund Olesen
210530da9c Add a primitive debug tracing facility.
When the CRETONNE_DBG environment variable is set, send debug messages
to a file named cretonne.dbg.*.

The trace facility is only enabled when debug assertions are on.
2017-03-15 11:32:01 -07:00
Jakob Stoklund Olesen
32709a56ca Upgrade to rustfmt 0.8.0.
Lots of changes this time.

Worked around what looks like a rustfmt bug in parse_inst_operands where
a large match was nested inside Ok().
2017-03-14 10:48:05 -07:00
Jakob Stoklund Olesen
1135a89af9 Convert the Branch and Jump instruction formats to value_list.
The Branch format also stores its fixed argument in the value list. This
requires the value pool to be passed to a few more functions.

Note that this actually makes the Branch and Jump variants of
InstructionData identical. The instruction format hashing does not yet
understand that all value operands are stored in the value list. We'll
fix that in a later patch.

Also convert IndirectCall, noting that Call and IndirectCall remain
separate instruction formats because they have different immediate
fields.
2017-03-09 15:38:12 -08:00