Commit Graph

231 Commits

Author SHA1 Message Date
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
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
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
dda3efcbdd Add regspill and regfill instructions.
These are parallels to the existing regmove instruction, but the divert
the value to and from a stack slot.

Like regmove diversions, this is a temporary diversion that must be
local to the EBB.
2017-10-04 17:02:09 -07:00
Jakob Stoklund Olesen
d92686d1cd Add a func_addr instruction.
Get the callable address of a function. Use for long distance calls and
for creating arguments to call_indirect in general.
2017-09-19 15:54:02 -07:00
Jakob Stoklund Olesen
aae946128b Add heap_addr custom legalization.
The expansion of a heap_addr instruction depends on the type of heap and
its configuration, so this is handled by custom code.

Add a couple examples of heap access code to the language reference
manual.
2017-08-24 14:44:47 -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
f2ebabaf5f Custom legalization for global_addr.
The code to compute the address of a global variable depends on the kind
of variable, so custom legalization is required.

- Add a legalizer::globalvar module which exposes an
  expand_global_addr() function. This module is likely to grow as we add
  more types of global variables.
- Add a ArgumentPurpose::VMContext enumerator. This is used to represent
  special 'vmctx' arguments that are used as base pointers for vmctx
  globals.
2017-08-18 10:08:06 -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
7e402a6104 Document memory operation flags.
Also move the extending loads and truncating stores into the bulkier
"Operations" section to improve the flow of the "Memory" section in the
language reference.
2017-08-17 10:42:43 -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
Jakob Stoklund Olesen
a42eaa77b4 Add bitwise ops that invert the second operand.
ARM has all of these as scalar integer instructions. Intel has band_not
in SSE and as a scalar in BMI1.

Add the trivial legalization patterns that use a bnot instruction.
2017-07-20 11:20:06 -07:00
Jakob Stoklund Olesen
c4db4c124b Begin an Intel-specific instruction group.
Add instructions representing Intel's division instructions which use a
numerator that is twice as wide as the denominator and produce both the
quotient and remainder.

Add encodings for the x86_[su]divmodx instructions.
2017-07-18 11:20:00 -07:00
Dan Gohman
130b7fa2fa Add documentation for immediates with type bool.
This makes the documentation for the new bconst instruction more complete.
2017-07-13 16:23:41 -07:00
Dan Gohman
5a4aa11274 Add a bconst instruction. (#116)
* Add a bconst instruction.
2017-07-13 10:12:25 -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
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
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
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
0cb36c9031 Remove the return_reg instruction.
RISC architectures that take a return address in a register can use a
special-purpose `link` return value to do so.
2017-04-19 16:08:16 -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
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
b4ac520332 Extending loads and truncating stores 2017-04-11 10:30:03 -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
0c3771bccb Ensure that the docs examples verify as Cretonne IL.
Any *.cton files in the docs directory are now included when running the
test-all.sh script. This is to ensure that the examples are in fact
correct IL.

Always print NaN and Inf floats with a sign. Print the positive ones as
+NaN and +Inf to make them easier to parse.
2017-04-10 15:28:24 -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
222ae8af22 Define stack_load, stack_store, and stack_addr instructions. 2017-04-10 13:56:57 -07:00
Jakob Stoklund Olesen
eccc2d0dae Add an Offset32 immediate operand kind.
This will be used to represent an immediate 32-bit signed address offset
for load/store instructions.
2017-04-10 11:53:46 -07:00
Jakob Stoklund Olesen
fa4f151b9b Add a fallthrough instruction.
Change jumps to fallthroughs in the branch relaxation pass before
computing the EBB offsets.
2017-04-06 14:22:32 -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
3176ccd131 Use the right operand when documenting type variable inference.
The meaning of format.typevar_operand changes recently to be relative to
value operands only instead of all operands. The Sphinx cton domain
wasn't updated.
2017-04-03 09:56:47 -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
Jakob Stoklund Olesen
6ad34f90aa 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
f540cb0664 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
2a321f42fb Strip the _lohi suffix from the isplit instructions.
For symmetry with the vector splitting instructions, we now have:

    isplit iconcat
    vsplit vconcat

No functional change.
2017-03-21 13:22:50 -07:00
Angus Holder
11a0daa7fd Define boolean conversion instructions. 2017-03-11 10:25:55 -08:00
Jakob Stoklund Olesen
9fbfd0d2a6 Remove the vconst instruction and the UnaryImmVector format.
No instruction sets actually have single instructions for materializing
vector constants. You always need to use a constant pool.

Cretonne doesn't have constant pools yet, but it will in the future, and
that is how vector constants should be represented.
2017-03-10 11:57:49 -08:00
Jakob Stoklund Olesen
c50e5f3f66 Separate immediate and value operands in the instruction format.
Instruction formats are now identified by a signature that doesn't
include the ordering of value operands relative to immediate operands.

This means that the BinaryRev instruction format becomes redundant, so
delete it. The isub_imm instruction was the only one using that format.
Rename it to irsub_imm to make it clear what it does now that it is
printed as 'irsub_imm v2, 45'.
2017-03-10 11:20:39 -08:00
Jakob Stoklund Olesen
cfe58d7994 Upgrade to Sphinx 1.5.3
Read the Docs is now using the latest version of Sphinx, so upgrade our
recommended version too.

As of Sphinx 1.4, index entries are 5-tuples instead of 4-tuples. Update
the Cretonne Sphinx domain to generate the new 5-tuples.

Since we're over this compatibility bump, there's no reason to recommend
a specific Sphinx version, so just go back to 'current'.
2017-03-09 10:11:37 -08:00
Jakob Stoklund Olesen
fd58b7cc29 Add vsplit and vconcat instructions.
Add support for two new type variable functions: half_vector() and
double_vector().

Use these two instructions to break down unsupported SIMD types and
build them up again.
2017-03-07 14:31:57 -08:00
Jakob Stoklund Olesen
cf5701b137 Add ABI annotations to function signatures.
Specify the location of arguments as well as the size of stack argument
array needed. The ABI annotations are optional, just like the value
locations.

Remove the Eq implementation for Signature which was only used by a
single parser test.
2017-02-24 13:53:46 -08:00
Jakob Stoklund Olesen
aa7e349134 Add a section about implementation limits.
Fix a few other minor issues with the documentation.
2017-02-24 11:08:15 -08:00
Jakob Stoklund Olesen
04bddd73ba Add a 'regalloc' filetest command.
Run functions through the register allocator, and then filecheck.
2017-02-22 11:53:01 -08:00
Jakob Stoklund Olesen
b6fa40d6a3 Add a return_reg instruction to the base instruction set.
Register-style return is used by all RISC architectures, so it is
natural to have a shared instruction representation.
2017-02-21 13:05:17 -08:00
Andrea Canciani
fd3cd153ed Fix some typos in the documentation
These were found by the spellchecker.
2017-01-27 09:51:22 -08:00
Jakob Stoklund Olesen
2390e3e3f0 Add operand register constraints.
Every encoding recipe must specify register constraints on input and
output values.

Generate recipe constraint tables along with the other encoding tables.
2017-01-25 13:35:18 -08:00