Commit Graph

82 Commits

Author SHA1 Message Date
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
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
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
0cacba15b9 Replace as casts with type-conversion functions.
https://github.com/rust-lang-nursery/rust-clippy/wiki#cast_lossless
2017-08-31 14:31:23 -07:00
Dan Gohman
dc79d155ff Comment wording cleanups. 2017-08-31 12:47:05 -07:00
Dan Gohman
a7d629c368 Use the Self keyword where applicable.
https://github.com/rust-lang-nursery/rust-clippy/wiki#use_self
2017-08-31 12:47:05 -07:00
Dan Gohman
55ae51acfe Add an underscore between a literal value and its suffix.
https://github.com/rust-lang-nursery/rust-clippy/wiki#unseparated_literal_suffix
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
Jakob Stoklund Olesen
3b71a27632 Add heaps to the Cretonne IL.
Add preamble syntax for declaring static and dynamic heaps, and update
the langref section on heaps. Add IR support for heap references.

Remove the heap_load and heap_store as discussed in #144. We will use
heap_addr along with native load and store instructions in their place.

Add the heap_addr instruction and document its bounds checking
semantics.
2017-08-23 14:15:59 -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
8599372098 Rename the entity_ref module to 'entity'.
This is in preparation for moving a number of data structures into
sub-modules of the 'entity' module:

- EntityList
- EntityMap
- SparseMap
2017-08-18 15:07:21 -07:00
Jakob Stoklund Olesen
bf4ae3bb2e Add global variables to Cretonne IL.
See #144 for discussion.

- Add a new GlobalVar entity type both in Python and Rust.
- Define a UnaryGlobalVar instruction format containing a GlobalVar
  reference.
- Add a globalvar.rs module defining the GlobalVarData with support for
  'vmctx' and 'deref' global variable kinds.

Langref:
    Add a section about global variables and the global_addr
    instruction.

Parser:
    Add support for the UnaryGlobalVar instruction format as well as
    global variable declarations in the preamble.
2017-08-17 14:41:27 -07:00
Jakob Stoklund Olesen
c96d4daa20 Add a calling convention to all function signatures.
A CallConv enum on every function signature makes it possible to
generate calls to functions with different calling conventions within
the same ISA / within a single function.

The calling conventions also serve as a way of customizing Cretonne's
behavior when embedded inside a VM. As an example, the SpiderWASM
calling convention is used to compile WebAssembly functions that run
inside the SpiderMonkey virtual machine.

All function signatures must have a calling convention at the end, so
this changes the textual IL syntax.

Before:

    sig1 = signature(i32, f64) -> f64

After

    sig1 = (i32, f64) -> f64 native
    sig2 = (i32) spiderwasm

When printing functions, the signature goes after the return types:

    function %r1() -> i32, f32 spiderwasm {
    ebb1:
        ...
    }

In the parser, this calling convention is optional and defaults to
"native". This is mostly to avoid updating all the existing test cases
under filetests/. When printing a function, the calling convention is
always included, including for "native" functions.
2017-08-03 11:40:24 -07:00
Aleksey Kuznetsov
5fa991e325 Apply conditional compilation of isa targets 2017-08-03 06:28:16 -07:00
Jakob Stoklund Olesen
f91d747bda Add support for setting presets.
Fixes #11.

Presets are groups of settings and values applied at once. This is used
as a shorthand in test files, so for example "isa intel nehalem" enables
all of the CPUID bits that the Nehalem micro-architecture provides.
2017-07-14 13:57:44 -07:00
Dan Gohman
5a4aa11274 Add a bconst instruction. (#116)
* Add a bconst instruction.
2017-07-13 10:12:25 -07:00
Jakob Stoklund Olesen
05cf44a156 Add an offset to StackSlotData.
The offset is relative to the stack pointer in the calling function, so
it excludes the return address pushed by the call instruction itself on
Intel ISAs.

Change the ArgumentLoc::Stack offset to an i32, so it matches the stack
slot offsets.
2017-06-28 14:38:13 -07:00
Dan Gohman
4a5d48fe11 Documentation fixes (#103)
* Clarify that extended basic blocks are abbreviated as EBB.

* Fix typo.

* Fix a typo.

* Fix typos.

* Use the same phrase to indicate scalar-only as other places in the doc.

* Mention that `band_imm` and friends are scalar-only.

And mention that they're equivalent to their respective
non-immediate-form counterparts.
2017-06-22 12:01:32 -07:00
Dan Gohman
0c7316ae28 Lint fixes (#99)
* Replace a single-character string literal with a character literal.

* Use is_some() instead of comparing with Some(_).

* Add code-quotes around type names in comments.

* Use !...is_empty() instead of len() != 0.

* Tidy up redundant returns.

* Remove redundant .clone() calls.

* Remove unnecessary explicit lifetime parameters.

* Tidy up unnecessary '&'s.

* Add parens to make operator precedence explicit.

* Use debug_assert_eq instead of debug_assert with ==.

* Replace a &Vec argument with a &[...].

* Replace `a = a op b` with `a op= b`.

* Avoid unnecessary closures.

* Avoid .iter() and .iter_mut() for iterating over containers.

* Remove unneeded qualification.
2017-06-19 16:24:10 -07:00
Jakob Stoklund Olesen
7b97933996 Track stack slot kinds.
Add a StackSlotKind enumeration to help keep track of the different
kinds of stack slots supported:

- Incoming and outgoing function arguments on the stack.
- Spill slots and locals.

Change the text format syntax for declaring a stack slot to use a kind
keyword rather than just 'stack_slot'.
2017-06-16 11:01:22 -07:00
Aleksey Kuznetsov
706eef23d3 Binary function names (#91)
* Function names should start with %

* Create FunctionName from string

* Implement displaying of FunctionName as %nnnn with fallback to #xxxx

* Run rustfmt and fix FunctionName::with_string in parser

* Implement FunctionName::new as a generic function

* Binary function names should start with #

* Implement NameRepr for function name

* Fix examples in docs to reflect that function names start with %

* Rebase and fix filecheck tests
2017-06-10 10:30:37 -07:00
Aleksey Kuznetsov
4f26764e71 Remove unnecessary cloned() in reader::lexer::trailing_digits() 2017-06-02 10:29:13 -07:00
Benjamin Bouvier
29dc723e25 Update rustfmt to 0.8.4; (#81) 2017-05-15 15:10:47 -07:00
Jakob Stoklund Olesen
950838c489 Add a regmove instruction.
This will be used to locally change the register locations of values in
order to satisfy instruction constraints.
2017-05-02 11:32:12 -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
Jakob Stoklund Olesen
866efd91b7 Add an enable_verifier setting.
This is off by default, but enabled by the parser when reading a textual
IL file. Test files can still override the default to turn off
verification.

The setting enables IL verifier passes at critical points of the
compilation pipeline.
2017-04-21 09:49:03 -07:00
Jakob Stoklund Olesen
d424589daa Allow for special purpose function arguments and return values.
Enumerate a set of special purposes for function arguments that general
purpose code needs to know about. Some of these argument purposes will
only appear in the signature of the current function, representing
things the prologue and epilogues need to know about like the link
register and callee-saved registers.

Get rid of the 'inreg' argument flag. Arguments can be pre-assigned to a
specific register instead.
2017-04-17 15:06:30 -07:00
Jakob Stoklund Olesen
b151e942d9 Stop tracking if instruction formats have multiple results.
All instruction formats can represent multiple results now, so a few
redundant formats can be removed: UnarySplit and BinaryOverflow.
2017-04-13 12:27:39 -07:00
Jakob Stoklund Olesen
18b567f88e Flatten the Value reference representation.
All values are now references into the value table, so drop the
distinction between direct and table values. Direct values don't exist
any more.

Also remove the parser support for the 'vxNN' syntax. Only 'vNN' values
can be parsed now.
2017-04-12 14:45:22 -07:00
Jakob Stoklund Olesen
b165d9a313 Remove the first_type() methods from InstructionData.
Also remove the type field from all the variants. The type of the first
result value can be recovered from the value table now.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
8a2398be08 Stop calling Value::new_direct.
We only ever create table values now.

Simplify legalizer::legalize_inst_results. Instead of calling
detach_secondary_results, just detach all the results and don't treat
the first result specially.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
78a036fa51 Remove the second_result field from instructions.
Now that result values are stored in value lists in the DFG, these
head-of-list pointers are no longer needed.
2017-04-12 09:14:39 -07:00
Jakob Stoklund Olesen
322a8db839 Change dfg.inst_results to return a slice.
Now we can access instruction results and arguments as well as EBB
arguments as slices.

Delete the Values iterator which was traversing the linked lists of
values. It is no longer needed.
2017-04-11 16:57:15 -07:00
Jakob Stoklund Olesen
fe0d986110 Make the dfg.insts table private again.
- Add a dfg.is_inst_valid() method for the verifier.
- Use the inst_args_mut() method when rewriting values in the parser.
- Add a new branch_destination_mut() to use when rewriting EBBs.

This also gets rid of one of the large instruction format switches in
the parser.
2017-04-11 15:03:43 -07:00
Jakob Stoklund Olesen
dd0a61cc91 Keep EBB arguments in a ValueList.
This is the first step of the value list refactoring which will replace
linked lists of values with value lists.

- Keep a ValueList in the EbbData struct containing all the EBB
  arguments.
- Change dfg.ebb_args() to return a slice instead of an iterator.

This leaves us in a temporary hybrid state where we maintain both a
linked list and a ValueList vector of the EBB arguments.
2017-04-11 11:36:50 -07:00
Jakob Stoklund Olesen
aad6ebebb5 Add load and store instructions.
Define a MemFlags class, currently holding a notrap and aligned flag.
2017-04-11 09:54:55 -07:00
Jakob Stoklund Olesen
b474485c0d Add heap_load, heap_store, and heap_addr instructions.
These are used when lowering WebAssembly sandbox code.
2017-04-10 15:04:33 -07:00
Jakob Stoklund Olesen
e78e4ea4ec Add a Uoffset32 immediate operand kind.
WebAssembly memory instructions encode a 32-bit unsigned offset that is
used to compute an effective address.
2017-04-10 15:04:33 -07:00
Jakob Stoklund Olesen
222ae8af22 Define stack_load, stack_store, and stack_addr instructions. 2017-04-10 13:56:57 -07:00
Jakob Stoklund Olesen
7c3bc9d19f Add Offset32 support to the parser. 2017-04-10 13:56:57 -07:00
Jakob Stoklund Olesen
51dea9f784 Syntax tweak: Omit comma after an initial enum immediate.
This affects the comparison instructions which now read "icmp ult a, b".
This mimics LLVM's style and makes it simpler to add instruction flags
in the future, such as "load v1" -> "load aligned v1".

These enumerated operands and flags feel like opcode modifiers rather
than value operands, so displaying them differently makes sense.

Value and numeric operands are still comma separated.
2017-04-10 10:28:37 -07:00
Jakob Stoklund Olesen
f47c62ba8c Move encoding-related information into an EncInfo struct.
The tables returned by recipe_names() and recipe_constraints() are now
collected into an EncInfo struct that is available from
TargetIsa::encoding_info(). This is equivalent to the register bank
tables available fro TargetIsa::register_info().

This cleans of the TargetIsa interface and makes it easier to add
encoding-related information.
2017-04-05 10:07:19 -07:00
Jakob Stoklund Olesen
1984c96f7c rustfmt 0.8.1 2017-04-05 09:00:11 -07:00
Jakob Stoklund Olesen
1b6a6f4e48 Add the br_icmp instruction.
This instruction behaves like icmp fused with brnz, and it can be used
to represent fused compare+branch instruction on Intel when optimizing
for macro-op fusion.

RISC-V provides compare-and-branch instructions directly, and it is
needed there too.
2017-04-03 15:04:42 -07:00
Jakob Stoklund Olesen
e23d12bbc7 Add an icmp_imm instruction.
Compare a scalar integer to an immediate constant. Both Intel and RISC-V
ISAs have this operation.

This requires the addition of a new IntCompareImm instruction format.
2017-04-03 09:49:44 -07:00
Keith Yeung
98e8a96412 Add unit test for value aliasing 2017-03-14 11:56:09 -07:00
Keith Yeung
f18eddc9ed Allow type inference to go through value aliasing 2017-03-14 11:56:09 -07:00
Keith Yeung
d93c37a826 Make value aliases during references rewriting 2017-03-14 11:56:09 -07:00
Keith Yeung
8e38c7907d Create alias HashMap in parser context 2017-03-14 11:56:09 -07:00
Keith Yeung
50e043477e Parse instruction results separately from instructions 2017-03-14 11:56:09 -07:00