Commit Graph

927 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
ab1e51002d 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
13b0046ed7 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
d2f575b54a Add jump encodings to RISC-V.
Fix a bug in gen_encoding.py when dealing with non-polymorphic
instructions where the type variable is None in Python, VOID in Rust.
2017-04-06 15:17:57 -07:00
Jakob Stoklund Olesen
e5e5b30315 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
c6e027207c Add an iterators module with extra Iterator methods.
Start with an adjacent_pairs() iterator adapter.
2017-04-06 14:00:56 -07:00
Jakob Stoklund Olesen
1440b673fc Use EBB offsets for encoding RISC-V branches.
Stop emitting EBB relocations. Use the offsets computed by
relax_branches() to encode the correct displacements immediately.
2017-04-06 12:55:57 -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
eb1052718b Add encoding size information to EncInfo.
Two new pieces of information are available for all encoding recipes:

- The size in bytes of an encoded instruction, and
- The range of a branch encoded with the recipe, if any.

In the meta language, EncRecipe takes two new constructor arguments. The
size is required for all encodings and branch_range is required for all
recipes used to encode branches.
2017-04-05 11:46:19 -07:00
Jakob Stoklund Olesen
6ab35e54b8 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
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
3a47b40ff8 Add RISC-V encodings for brz and brnz.
These branches compare a register to zero. RISC-V implements this with
the %x0 hard-coded zero register.
2017-04-03 15:20:57 -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
d2ddc700a8 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
175b269760 Add RISC-V encodings for lui.
This instruction can materialize constants with the low 12 bits clear.
2017-04-03 12:27:22 -07:00
Jakob Stoklund Olesen
c13c318ec4 Add icmp_imm encodings for RISC-V.
The ISA has icmp_imm slt/ult with 12-bit signed immediate operands.
2017-04-03 10:59:28 -07:00
Jakob Stoklund Olesen
d4d76c8d76 Give singleton type variables the type's doc string.
This reads better than "typeof(b1)".
2017-04-03 10:06:08 -07:00
Jakob Stoklund Olesen
ec29283abb 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
2e45365ee1 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
6532cbab6c Skip the Python checks if the Python files haven't changed. 2017-03-31 15:45:21 -07:00
Jakob Stoklund Olesen
8187fd7371 Emit Rshamt-type instructions for RISC-V.
These are the shift-by-immediate instructions.
2017-03-31 15:33:21 -07:00
Jakob Stoklund Olesen
7c9d187b6d Emit I-type instructions for RISC-V.
These are the BinaryImm formats.
2017-03-31 15:15:20 -07:00
Jakob Stoklund Olesen
39fc0eb3cf Add RISC-V encodings for supported icmp variants.
Only slt and ult variants are in the instruction set. Other condition
codes must be synthesized.
2017-03-31 13:47:07 -07:00
Jakob Stoklund Olesen
ebc418d25e Allow for instructions with operands in encodings.
When defining an instruction encoding, allow part of the instruction
predicate to be provided as operands on the instruction opcode:

    icmp.i32(intcc.ult, x, y)

This generates an instruction predicate that checks

    IntCompare.cond == IntCC::UnsignedLessThan
2017-03-31 13:46:39 -07:00
Jakob Stoklund Olesen
3c3d068379 Add Apply.inst_predicate().
Compute an instruction predicate from any constant values given as
arguments for the immediate operands in an instruction pattern.

Allows for patterns like icmp.i32(intcc.ugt, x, y) or iadd_imm.i32(x, 1)

Trap these predicates in the legalizer code generator since we can't
actually handle them yet.
2017-03-31 13:46:39 -07:00
Jakob Stoklund Olesen
89ff979d75 Add InstructionFormat.imm_fields.
Consolidate the imm_members and imm_kinds into this list so the
FormatField is the single definition of these properties.

This makes it easier to access the precomputed FormatFields
parametrically, avoiding going through getattr().

This is better for type checking too.
2017-03-31 13:46:39 -07:00
Jakob Stoklund Olesen
b31ca83b91 Add an IsEqual FieldPredicate.
Compare an immediate operand to a constant value.
2017-03-31 13:46:38 -07:00
Jakob Stoklund Olesen
3b0ac20ce2 Add a mypy.ini file and enable some more warnings.
Also require all Python functions to have a type declaration.
2017-03-30 19:52:49 -07:00
Jakob Stoklund Olesen
a9ec28ab7c Add mypy types for gen_settings.py. 2017-03-30 18:42:06 -07:00
Jakob Stoklund Olesen
49766bae12 Add mypy types for gen_encoding.py. 2017-03-30 17:07:24 -07:00
Jakob Stoklund Olesen
c5f2ef8edb Add mypy types for gen_instr.py.
Declare the Instruction.number opcode number field.
2017-03-30 16:20:40 -07:00
Angus Holder
b94d01f892 Verify integrity of the existing control flow graph of the context. (#70)
* Verify integrity of the existing control flow graph of the context.

* Make checking more thorough.
2017-03-30 15:34:50 -07:00
Jakob Stoklund Olesen
a82e521291 Add more mypy annotations. 2017-03-30 15:16:44 -07:00
Jakob Stoklund Olesen
ae12c94d04 Add mypy annotations to cdsl.predicates, settings.
Wherein we learned that only BoolSettings can be used as predicates.
2017-03-30 14:11:19 -07:00
Jakob Stoklund Olesen
d2eb745265 Allow dot syntax notation for enumerated immediate operands.
The meta language patterns sometimes need to refer to specific values of
enumerated immediate operands. The dot syntax provides a namespaced,
typed way of doing that: icmp(intcc.ult, a, x).

Add an ast.Enumerator class for representing this kind of AST leaf node.

Add value definitions for the intcc and floatcc immediate operand kinds.
2017-03-30 11:37:05 -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
de543bb308 Allow vector types for isplit and iconcat.
These two instructions make sense for vector types by simply performing
the same operation on each lane, like most other vector operations.

Problem found by @angusholder's verifier.
2017-03-29 15:18:39 -07:00
Jakob Stoklund Olesen
62641d4553 Fix a type error in the legalizer patterns.
The carry and borrow values are boolean, so we have to convert them to
an integer type with bint(c) before we can add them to the result.

Also tweak the default legalizer action for unsupported types: Only
attempt a narrowing pattern for lane types > 32 bits.

This was found by @angusholder's new type checks in the verifier.
2017-03-29 15:00:27 -07:00
Jakob Stoklund Olesen
a5d4839002 Test binary encodings of some RV32I instructions.
These are the R-format instructions in RV32I.
2017-03-29 13:16:12 -07:00
Jakob Stoklund Olesen
f968c60724 Add Vim syntax support for Name and HexSequence tokens.
Also disable spell checking for .cton files. They tend to contain very
few words, and even comments are pretty cryptic.
2017-03-29 13:16:12 -07:00
Angus Holder
b5fda64b49 Type checking and Dominator Tree integrity checks in Verifier (#66)
* Verify that a recomputed dominator tree is identical to the existing one.
* The verifier now typechecks instruction results and arguments.
* The verifier now typechecks instruction results and arguments.
* The verifier now typechecks instruction results and arguments.
* Added `inst_{fixed,variable}_args` accessor functions.
* Improved error messages in verifier.
* Type check return statements against the function signature.
2017-03-29 13:14:42 -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
ca2b1c79d7 Generate binemit::emit_inst() functions.
Use the meta language encoding recipes to generate an emit_inst()
function for each ISA. The generated calls into recipe_*() functions
that must be implemented by hand.

Implement recipe_*() functions for the RISC-V recipes.

Add the TargetIsa::emit_inst() entry point which emits an instruction to
a CodeSink trait object.
2017-03-28 14:44:36 -07:00
Jakob Stoklund Olesen
bbbae4dc47 Start the binemit module.
This module will provide supporting code for emitting binary machine
code with relocations.
2017-03-23 15:18:11 -07:00
Jakob Stoklund Olesen
f710f13949 Add dfg.inst_args(_mut) methods.
A shortcut for calling arguments() directly that goes with the existing
inst_results() method.
2017-03-23 15:07:22 -07:00
Jakob Stoklund Olesen
c5c9f211df Legalize EBBs in a reverse post-order.
This means that whenever we need to split a value, it is either already
defined by a concatenation instruction in a previously processed EBB, or
it's an EBB argument.
2017-03-23 09:50:26 -07:00
Jakob Stoklund Olesen
cd52b671e6 Remove spurious shell redirections from install commands. 2017-03-23 09:42:36 -07:00