Commit Graph

153 Commits

Author SHA1 Message Date
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
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
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
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
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
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
12b2af3f8a Simplify branch arguments after splitting EBB arguments.
The EBB argument splitting may generate concat-split dependencies when
it repairs branch arguments in EBBs that have not yet been fully
legalized. Add a branch argument simplification step that can resolve
these dependency chains.

This means that all split and concatenation instructions will be dead
after legalization for types that have no legal instructions using them.
2017-03-22 15:29:06 -07:00
Keith Yeung
07740b5e3c Limit type inference for controlling type variables in write.rs 2017-03-22 14:45:38 -07:00
Jakob Stoklund Olesen
19db81f6a8 Iteratively split EBB arguments.
When the legalizer splits a value into halves, it would previously stop
if the value was an EBB argument. With this change, we also split EBB
arguments and iteratively split arguments on branches to the EBB.

The iterative splitting stops when we hit the entry block arguments or
an instruction that isn't one of the concatenation instructions.
2017-03-22 13:12:19 -07:00
Jakob Stoklund Olesen
22334bcb54 Avoid generating value split instructions.
The legalizer often splits values into parts with the vsplit and
isplit_lohi instructions. Avoid doing that for values that are already
defined by the corresponding concatenation instructions.

This reduces the number of instructions created during legalization, and
it simplifies later optimizations. A number of dead concatenation
instructions are left behind. They can be trivially cleaned up by a dead
code elimination pass.
2017-03-21 15:10:50 -07:00
Jakob Stoklund Olesen
a44a4d2718 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
Jakob Stoklund Olesen
e83cccb6fc Fix a bug in analyze_call().
The call arguments on call_indirect should not include the fixed callee
argument.

Add legalizer assertions to verify that signatures are actually valid
after legalization. If not, we would get infinite legalizer loops.
2017-03-17 12:34:03 -07:00
Jakob Stoklund Olesen
a8a7cebe8c Legalize return values from call instructions.
Like the entry block arguments, the return values from a call
instruction need to be converted back from their ABI representation.

Add tests of call instruction legalization.
2017-03-17 11:03:32 -07:00
Jakob Stoklund Olesen
e4a83c8063 Break out differently purposed tests from abi.cton.
- abi.cton is for testing the actual RISC-V ABI.
- legalize-abi.cton is for testing the legalizer around ABI boundaries.
- parse-encoding.cton is for testing the parser's handling of RISC-V
  encoding and register annotations.
2017-03-17 10:07:32 -07:00
Jakob Stoklund Olesen
28153c97ea Legalize ABI arguments to call and return instructions.
The type signatures of functions can change when they are legalized for
a specific ABI. This means that all call and return instructions need to
be rewritten to use the correct arguments.

- Fix arguments to call instructions.
- Fix arguments to return instructions.

TBD:

- Fix return values from call instructions.
2017-03-15 14:35:22 -07:00
Jakob Stoklund Olesen
60daf3e76b 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
Angus Holder
81f26cfbba Added parsing of argument locations for functions and signatures. 2017-03-09 13:55:11 -08:00
Angus Holder
cfdecfdcbf We now parse and record a ValueLoc for each SSA value result of each instruction. Code currently not passing tests. 2017-03-09 07:19:28 -08:00
Jakob Stoklund Olesen
7a45aeebeb Use a unique ISA in 'test cat' file tests.
Add a Function::display() method which can include ISA-specific
information when printing the function.

If a test file has a unique ISA, use that in the `test cat`
implementation.
2017-03-08 13:04:30 -08:00
Angus Holder
10f86baf63 Added tests, some refactoring, fixed a parsing bug. 2017-03-08 13:01:32 -08:00
Jakob Stoklund Olesen
83d3a1020d Heed uext and sext annotations on RISC-V arguments.
Translate the small integer arguments to i32 or i64 with the appropriate
extend and ireduce instructions.
2017-03-07 15:07:00 -08:00
Jakob Stoklund Olesen
25677d1bd8 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
5d266acb5f Legalize entry block arguments to match ABI types.
Insert conversion code that reconstructs the original function argument
types from the legalized ABI signature.

Add abi::legalize_abi_value(). This function is used when adapting code
to a legalized function signature.
2017-03-07 13:29:19 -08:00
Jakob Stoklund Olesen
e84a4e41a0 Implement legalize_signature for RISC-V.
Add an abi module with code that is probably useful to all ISAs when
implementing this function.

Add a unit() method to RegClassData which can be used to index the
register units in a class.
2017-03-03 11:09:55 -08:00
Jakob Stoklund Olesen
4ba5cfeed3 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
62334b26b4 Add return_reg encodings for RISC-V. 2017-02-21 16:29:23 -08:00
Jakob Stoklund Olesen
d76280afba Add expansion patterns for large immediates.
Expand foo_imm into iconst + foo.
2016-11-10 15:55:54 -08:00
Jakob Stoklund Olesen
7bbbe97d2f Resolve value aliases when legalizing instructions.
Since we're deconstructing an instruction anyway, go ahead and resolve
any value aliases on its arguments before we construct the replacement
instructions.
2016-11-04 15:54:58 -07:00
Jakob Stoklund Olesen
6f1a60366f Create value aliases when necessary.
If a secondary value in the source pattern becomes a primary value in
the destination pattern, it is not possible to overwrite the definition
of the source value.

Instead, change the original source value to an alias to the new promary
value.
2016-11-04 15:31:23 -07:00
Jakob Stoklund Olesen
2b8732ae13 Advance the insertion cursor after replacinf an instruction.
When expanding iadd_cout, the original instruction is replaced with an
iadd, and an icmp is inserted after the iadd.

Make sure we advance the insertion position after replacing iadd_cout so
the icmp gets inserted *after* iadd.
2016-11-04 11:56:21 -07:00
Jakob Stoklund Olesen
a038279717 TestFile preamble comments apply to all functions.
Include the test file preamble comments when building a filecheck
instance for every function in the file.

This makes it possible to define common regex variables in the preamble
and use these definitions for all the functions.
2016-11-04 10:49:09 -07:00
Jakob Stoklund Olesen
1641365f01 Revisit expanded instructions for legalization.
When an illegal instruction is replaced with other instructions, back up
and revisit the expanded instructions. The new instructions need to have
encodings assigned too.

This also allows for expansions to contain illegal instructions that
need to be legalized themselves.
2016-11-04 09:44:11 -07:00
Jakob Stoklund Olesen
9086c6c8f0 Add narrowing legalization patterns for bitwise ops.
RISC-V 32-bit tests for band.i64, bor.i64, bxor.i64.
2016-11-04 08:02:37 -07:00
Jakob Stoklund Olesen
d85225c537 Parse signature and function declarations.
Also add support for parsing call and call_indirect instructions.
2016-10-18 13:19:24 -07:00
Jakob Stoklund Olesen
f66d84fd95 Integer subtraction with borrow flags.
This is the x86-style of borrow flags. ARM uses subtract-with-carry
which inverts the sense of the carry flag.
2016-09-23 15:47:39 -07:00
Jakob Stoklund Olesen
9cb3451432 Integer add with carry instructions.
Integer addition with carry in/out/both.
2016-09-23 13:42:00 -07:00
Jakob Stoklund Olesen
65f69fb088 Add a 'test legaliser' filetest command.
This test command sends each function through legalize_function() and
then filecheck.
2016-09-21 17:36:06 -07:00
Jakob Stoklund Olesen
64490a3587 Don't have keywords in the lexer and parser.
Instead of recognizing "function" as a keyword, simply match it as a
context-sensitive keyword in the parser outside functions.
2016-09-20 13:00:37 -07:00
Jakob Stoklund Olesen
af29fee5d2 Wrap FunctionName in a newtype struct.
Function names display differently than normal strings since they need
quotes and escaping.

Move the FunctionName type into its own module.
2016-09-19 15:09:25 -07:00
Jakob Stoklund Olesen
b5b1ee23b5 Add a 'test verifier' sub-test.
This test runs the verifier on each function and matches the resulting
verifier error against the "error:" annotation.

Move the existing verifier test into filetests/verifier/ and use the new
syntex.
2016-09-16 16:25:36 -07:00
Jakob Stoklund Olesen
4198b2dde5 Implement a domtree sub-test.
This test verifies the computed dominator tree against annotations.

Move the existing testcases into filetests/ with the new syntax.
2016-09-16 14:50:32 -07:00