Commit Graph

1642 Commits

Author SHA1 Message Date
Dan Gohman
9fdf44afd4 Clean up a stale comment. 2017-10-20 11:37:25 -07:00
Dan Gohman
f5e4058eb8 Update a stale comment. 2017-10-20 11:37:25 -07:00
Dan Gohman
d3077acf1c TranslationState can assert that its stacks are empty between functions. 2017-10-20 11:37:25 -07:00
Jakob Stoklund Olesen
8e9ac361bd Remove the CFG entry_block member.
It was not used.
2017-10-20 09:40:28 -07:00
Dan Gohman
2569ef4c42 Clarify undefined behavior and notrap. (#170)
* Clarify undefined behavior and notrap.

Remove the "No undefined behavior" paragraph from the README. The other
paragraphs, specifically "Portable semantics" and
"Fast sandbox verification", describe Cretonne's goals in this area.

Define *addressable* and *accessible* memory, so that trapping remains a fully defined part of the semantics, and we have a clear boundary around undefined behavior, and use these terms to describe related constructs.
2017-10-20 09:38:52 -07:00
Julien Wajsberg
e5c0e06fa8 Fix typo in README.rst 2017-10-20 09:27:18 -07:00
Jakob Stoklund Olesen
b3fb41087e Use the term "Function parameter" instead of "argument".
Rename the ArgumentType type to AbiParam since it describes the ABI
characteristics of a parameter or return value, not just the value type.

In Signature, rename members argument_types and return_types to "params"
and "returns". Again, they are not just types.

Fix a couple lingering references to "EBB arguments".
2017-10-19 17:39:23 -07:00
Jakob Stoklund Olesen
921bcc6c25 Use the term "EBB parameter" everywhere.
Add EBB parameter and EBB argument to the langref glossary to clarify
the distinction between formal EBB parameter values and arguments passed
to branches.

- Replace "ebb_arg" with "ebb_param" in function names that deal with
  EBB parameters.
- Rename the ValueDef variants to Result and Param.
- A bunch of other small langref fixes.

No functional changes intended.
2017-10-19 16:17:09 -07:00
Jakob Stoklund Olesen
ea68a69f8b Fix a flake8 lint.
Also don't infer writes_cpu_flags if it is specified explicitly.
2017-10-19 16:17:09 -07:00
Dan Gohman
7c9b9e3d27 Mark spill and fill as can_store and can_load.
This allows GVN to avoid hoisting them. These will be to coarse for
things that want more precise dependence information, however we can
work that out when we build such things.
2017-10-19 13:11:33 -07:00
Dan Gohman
cc0bb70c5d Make GVN aware of instructions that write to CPU flags. 2017-10-19 12:59:10 -07:00
Dan Gohman
bce3c38042 Clarify the todo about minimum / maximum. 2017-10-19 12:59:10 -07:00
Dan Gohman
3ccee371a7 Remove the todo for smod.
It's not present in either WebAssembly or Rust, for example. We can
still add smod in the future if future use cases need it.
2017-10-19 12:59:10 -07:00
Dan Gohman
79a81d98c1 Mention cton_frontend when discussing SSA construction. 2017-10-19 12:59:10 -07:00
Dan Gohman
1a1774af15 Fix a typo in a comment. 2017-10-19 12:59:10 -07:00
Jakob Stoklund Olesen
57b81a179e Move the CursorBase trait into the cursor module.
Also move the CursorPosition type into the cursor module.

Move layout::cursor into the tests module as LayoutCursor and remove its
ability to insert instructions via the dfg.ins() method. This cursor
type is only used in the layout unit tests now.

The FuncCursor and EncCursor types are the commonly used cursors now.
2017-10-19 12:15:43 -07:00
Dan Gohman
6d44508055 Sort the glossary alphabetically. 2017-10-18 17:01:01 -07:00
Dan Gohman
ee0f061ee8 Rename "runtime" to "environment". 2017-10-18 16:55:32 -07:00
Dan Gohman
55bc368bf8 Remove minnum/maxnum. 2017-10-18 15:44:17 -07:00
Dan Gohman
a57a05cb92 Expand on the floating-point section and provide the NaN rules. 2017-10-18 15:44:17 -07:00
Jakob Stoklund Olesen
b948de1693 Add a verifier pass for CPU flags.
Only one CPU flags value can be live at a time, and some instructions
clobber the flags.
2017-10-18 15:07:19 -07:00
Jakob Stoklund Olesen
c3446ee472 Add CPU flags value types to the language reference manual.
Clean up a few other things in the value types section too.
2017-10-18 15:07:19 -07:00
Dan Gohman
6f33066daa Add another link to the documentation. 2017-10-18 12:35:59 -07:00
Dan Gohman
35989f4069 Tidy up unneeded references. 2017-10-17 11:48:57 -07:00
Dan Gohman
e6c6f09e41 Tidy some formatting in the generated legalizer.rs. 2017-10-17 11:48:57 -07:00
Jakob Stoklund Olesen
620eb7effe Add a "clobbers_flags" flag to encoding recipes.
On some ISAs like Intel's, all arithmetic instructions set all or some
of the CPU flags, so flag values can't be live across these
instructions. On ISAs like ARM's Aarch32, flags are clobbered by compact
16-bit encodings but not necessarily by 32-bit encodings of the same
instruction.

The "clobbers_flags" bit on the encoding recipe is used to indicate if
CPU flag values can be live across an instruction, or conversely whether
the encoding can be used where flag values are live.
2017-10-16 14:40:28 -07:00
Jakob Stoklund Olesen
5d065c4d8f Add encodings for CPU flags instructions.
Branch on flags: brif, brff,
Compare integers to flags: ifcmp
Compare floats to flags: ffcmp
Convert flags to b1: trueif, trueff
2017-10-16 13:07:23 -07:00
Jakob Stoklund Olesen
0f4f663584 Add register banks for CPU flags to Intel and ARM ISAs.
The arm32 ISA technically has separate floating point and integer flags,
but the only useful thing you can do with the floating point flags is to
copy them ti the integer flags, so there is not need to model them.

The arm64 ISA fixes this and the fcmp instruction writes the integer
nzcv flags directly.

RISC-V does not have CPU flags.
2017-10-13 14:02:09 -07:00
Jakob Stoklund Olesen
1dbc55dadf Add a pressure_tracking flag to register banks.
This makes it possible to define register banks that opt out of register
pressure tracking. This will be used to define banks for special-purpose
registers like the CPU flags.

The pressure tracker does not need to use resources for a top-level
register class in a non-tracked bank. The constant MAX_TOPRCS is renamed
to MAX_TRACKED_TOPRCS to indicate that there may be top-level register
classes with higher numbers, but they won't require pressure tracking.

We won't be tracking register pressure for CPU flags since only one
value is allowed to be live at a time.
2017-10-13 13:46:16 -07:00
Dan Gohman
c808447468 Have declare_table_elements consume its elements argument.
The producer is already allocating a new Vec, so no need to require the
consumer to allocate one too.
2017-10-13 12:43:15 -07:00
Dan Gohman
bd94a3b202 Move the 'data lifetime parameter to the ModuleEnvironment trait.
This is needed to allow implementations to have 'data-lifetime
references if they choose to. The DummyEnvironment is an example of an
implementation that doesn't choose to.
2017-10-13 12:43:15 -07:00
Dan Gohman
d6ab7e3abf Minor comment cleanup. 2017-10-13 12:43:15 -07:00
Dan Gohman
ad2ffcd7fc Update to wasmparser 0.13.0. 2017-10-13 12:43:04 -07:00
Jakob Stoklund Olesen
1f98fc491c Add instructions using CPU flags.
Add integer and floating comparison instructions that return CPU flags:
ifcmp, ifcmp_imm, and ffcmp.

Add conditional branch instructions that check CPU flags: brif, brff

Add instructions that check a condition in the CPU flags and return a
b1: trueif, trueff.
2017-10-12 19:12:28 -07:00
Jakob Stoklund Olesen
15461c1e4b Add two new value types: iflags and fflags.
These two value types represent the state of CPU flags after an integer
comparison and a floating point comparison respectively.

Instructions using these types TBD.
2017-10-12 19:05:24 -07:00
Jakob Stoklund Olesen
dbaa919ca9 Make room for SpecialType in the value type numbering.
The value types are now classified into three groups:

1. Lane types are scalar types that can also be used to form vectors.
2. Vector types 2-256 copies of a lane type.
3. Special types. This is where the CPU flag types will go.

The special types can't be used to form vectors.

Change the numbering scheme for value types to make room for the special
types and add `is_lane()` and `is_special()` classification methods.

The VOID type still has number 0, but it can no longer appear as a
vector lane. It classifies as special now.
2017-10-12 12:48:55 -07:00
Jakob Stoklund Olesen
89a24b2f13 Rename ScalarType to LaneType.
The word "scalar" is a bit vague and tends to mean "non-vector". Since
we are about to add new CPU flag value types that can't appear as vector
lanes, make the distinction clear: LaneType represents value types that
can appear as a vector lane.

Also replace the Type::is_scalar() method with an is_vector() method.
2017-10-12 10:39:12 -07:00
Jakob Stoklund Olesen
994af598f5 Avoid interference on CFG edges.
Track allocatable registers both locally and globally: Add a second
AllocatableSet which tracks registers allocated to global values without
accounting for register diversions. Since diversions are only local to
an EBB, global values must be assigned un-diverted locations that don't
interfere.

Handle the third "global" interference domain in the constraint solver in
addition to the existing "input" and "output" domains.

Extend the solver error code to indicate when a global define just can't
be allocated because there are not enough available global registers.
Resolve this problem by replacing the instruction's global defines with
local defines that are copied into their global destinations
afterwards.
2017-10-11 15:38:30 -07:00
Jakob Stoklund Olesen
ba52a38597 Add a t8jccd_long encoding recipe for brz.b1 and brnz.b1 in 32-bit mode.
The register allocator can't handle branches with constrained register
operands, and the brz.b1/brnz.b1 instructions only have the t8jccd_abcd
in 32-bit mode where no REX prefixes are possible.

This adds a worst case encoding for those cases where a b1 value lives
in a non-ABCD register.
2017-10-11 14:20:43 -07:00
Jakob Stoklund Olesen
ece09f2df2 Add encodings for spill.b1, fill.b1 etc.
These spills and fills use 32-bit writes, knowing that the spill slot is
minimum 4 bytes which makes it safe.

Also simplify the definition of load/store encodings a bit by
introducing loops.
2017-10-11 14:20:43 -07:00
Jakob Stoklund Olesen
699cb9895e Enforce a 4-byte minimum spill slot size.
This is primarily for the benefit of 32-bit x86 code which can't spill
1-byte types from arbitrary registers. This makes it possible to use
32-bit writes to spill types like b1 and i8.

These small types are expected to be very rare since WebAssembly doesn't
have then, and we tend to push integer arithmetic to at least i32. The
effect of frame sizes should be minimal.
2017-10-11 14:20:43 -07:00
Jakob Stoklund Olesen
1a04c4260f Remove an unused import to silence a compiler warning. 2017-10-11 14:20:43 -07:00
Dan Gohman
ac85ba0d68 Update to wasmparser 0.12.1. 2017-10-11 11:33:02 -07:00
Dan Gohman
3f30171b79 Actually disable simple_gvn and licm by default.
See

https://github.com/stoklund/cretonne/pull/164#discussion_r142449999

for details.
2017-10-10 16:28:29 -07:00
Dan Gohman
733870aee4 Make FuncEnvironment independent from ModuleEnvironment (formerly WasmRuntime).
This renames WasmRuntime to ModuleEnvironment, and makes several changes
to allow for more flexible compilation.

ModuleEnvironment no longer derives from FuncEnvironment, and no longer
has the `begin_translation` and `next_translation` functions, so that
independent `FuncEnvironment` instances can operate within the same
module.

Also, this obviates the rest of TranslationResult, as it moves processing
of function bodies into the environment. The DummyEnvironment implementation
gives an example of decoding the function bodies as they are parsed, however
other implementation strategies are now possible.
2017-10-10 15:50:24 -07:00
Dan Gohman
d4c0c5babc Rename WasmRuntime's get_name to get_func_name. 2017-10-10 10:21:06 -07:00
Dan Gohman
8e1ba080c0 Complete support for global init expressions. 2017-10-10 09:35:10 -07:00
Dan Gohman
653e8bb563 Declare exports via the WasmRuntime.
Also, redo how functions are named in the DummyRuntime. Use the FunctionName
field to just encode the wasm function index rather than trying to shoehorn
a printable name into it. And to make up for that, teach the wasm printer
to print export names as comments next to the function definitions.

This also makes the fields of DummyRuntime public, in preparation for
the DummyRuntime to have a more general-purpose debugging role, as well
as possibly to allow it to serve as a base for other implementations.
2017-10-10 08:46:10 -07:00
Dan Gohman
2c9d03f9bd Let the runtime provide the number of imported functions.
This obviates the need to keep a separate running total of the number of
functions seen.
2017-10-09 17:29:39 -07:00
Dan Gohman
e74bc06380 Move start_index out of TranslationResult and into the WasmRuntime.
This makes it more consistent with how all the rest of the content of
a wasm module is handled. And, now TranslationResult just has a Vec
of translated functions, which will make it easier to refactor further.
2017-10-09 17:29:39 -07:00