Commit Graph

492 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
b5d4046591 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
4613cbcf18 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
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
d9f325f6cd 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
c7e25e6a35 Limit type inference for controlling type variables in write.rs 2017-03-22 14:45:38 -07:00
Jakob Stoklund Olesen
272df6489c 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
697246658d 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
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
Jakob Stoklund Olesen
f15651132b 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
d881ed331b 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
4964502782 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
d15f25844a 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
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
Angus Holder
e21bf444dc Added parsing of argument locations for functions and signatures. 2017-03-09 13:55:11 -08:00
Angus Holder
6fba5c4e0a 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
cbbf5cc88b 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
4525929df2 Added tests, some refactoring, fixed a parsing bug. 2017-03-08 13:01:32 -08:00
Jakob Stoklund Olesen
40fc5da3d8 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
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
37b2e94c72 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
42e7021865 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
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
377550b835 Add return_reg encodings for RISC-V. 2017-02-21 16:29:23 -08:00
Jakob Stoklund Olesen
5e4602efb4 Add expansion patterns for large immediates.
Expand foo_imm into iconst + foo.
2016-11-10 15:55:54 -08:00
Jakob Stoklund Olesen
be3577ad7e 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
453a1b2d17 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
b63d62c9e8 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
cb718b869c 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
a2b7769a51 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
1a9abdd158 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
df06f19979 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
f34da59bab 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
b1bd3140db Integer add with carry instructions.
Integer addition with carry in/out/both.
2016-09-23 13:42:00 -07:00
Jakob Stoklund Olesen
51bcc78cea 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
5aa1db2e4f 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
388154e06b 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
a98d6e5256 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
770285d5c6 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
Jakob Stoklund Olesen
ec6a9df08a Make the source map available as filecheck variables.
This makes it possible to refer to entities defined in the source file,
using the source names prefixed with $.

For example, $v20 refers to the value by that name in the sources, even
if it was renumbered to 'vx0' in the parsed file.
2016-09-16 12:59:05 -07:00
Jakob Stoklund Olesen
5ac30b0075 Implement the 'test print-cfg' sub-test.
Move the CFG tests into the filetests directory.

Remove the tests directory, there are no more shell-driven tests left.
2016-09-15 17:21:56 -07:00
Jakob Stoklund Olesen
086bd601a2 Convert parser tests to filetests.
Create a new directory hierarchy under 'filetests' for all the tests
that are run by 'cton-util test'.

Convert the parser tests under 'tests/parser' to use 'test cat' and
filecheck directives.
2016-09-15 15:50:47 -07:00