Commit Graph

532 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
d078c546e5 Add an EntityMap::get_or_default() method.
This covers a common pattern for secondary entity maps: Get the value in
the map or the default value for out-of-range keys.
2017-04-25 15:53:30 -07:00
Eric Anholt
43ce26e64b Verify that the instruction encoding matches what the ISA would encode.
Fixes #69
2017-04-23 17:21:32 -07:00
Jakob Stoklund Olesen
c5da572ebb Add a liveness verifier.
The liveness verifier will check that the live ranges are consistent
with the function. It runs as part of the register allocation pipeline
when enable_verifier is set.

The initial implementation checks the live ranges, but not the
ISA-specific constraints and affinities.
2017-04-21 16:01:08 -07:00
Jakob Stoklund Olesen
c4b794f7cf Run the verifier in the Context methods when it is enabled.
The test drivers can stop calling comp_ctx.verify because legalize() and
regalloc() do it themselves now.

This also makes it possible for those two passes to return other
CtonError codes in the future, not just verifier errors.
2017-04-21 12:36:35 -07:00
Jakob Stoklund Olesen
28ff7b7925 Move the ctrl_typevar function into dfg.
Soon, InstructionData won't have sufficient information to compute this.

Give TargetIsa::encode() an explicit ctrl_typevar argument. This
function does not require the instruction to be inserted in the DFG
tables.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
8a3f538441 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
81251c3005 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
72cb6459a9 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
1984c96f7c rustfmt 0.8.1 2017-04-05 09:00:11 -07:00
Jakob Stoklund Olesen
479ff156c1 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
cb33f93fcd Use pretty_verifier_error in runone too. 2017-03-29 15:30:44 -07:00
Jakob Stoklund Olesen
4c3e590bb9 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
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
ca6e402b90 Add a ControlFlowGraph argument to legalize_function.
Legalizing some instructions may require modifications to the control
flow graph, and some operations need to use the CFG analysis.

The CFG reference is threaded through all the legalization functions to
reach the generated expansion functions as well as the legalizer::split
module where it will be used first.
2017-03-21 16:00:28 -07:00
Jakob Stoklund Olesen
a9056f699e Rename the 'cfg' module to 'flowgraph'.
The 'cfg' name was easy to confuse with 'configuration'.
2017-03-21 15:33:23 -07:00
Jakob Stoklund Olesen
9549cf603c Add a primitive debug tracing facility.
When the CRETONNE_DBG environment variable is set, send debug messages
to a file named cretonne.dbg.*.

The trace facility is only enabled when debug assertions are on.
2017-03-15 11:32:01 -07:00
Jakob Stoklund Olesen
010861d58e Upgrade to rustfmt 0.8.0.
Lots of changes this time.

Worked around what looks like a rustfmt bug in parse_inst_operands where
a large match was nested inside Ok().
2017-03-14 10:48:05 -07:00
Jakob Stoklund Olesen
5170ef6b5f Convert the Branch and Jump instruction formats to value_list.
The Branch format also stores its fixed argument in the value list. This
requires the value pool to be passed to a few more functions.

Note that this actually makes the Branch and Jump variants of
InstructionData identical. The instruction format hashing does not yet
understand that all value operands are stored in the value list. We'll
fix that in a later patch.

Also convert IndirectCall, noting that Call and IndirectCall remain
separate instruction formats because they have different immediate
fields.
2017-03-09 15:38:12 -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
rep-nop
b23f1fb347 Converts all try! macros to ? syntax.
Fixes #46
2017-02-26 07:50: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
85fa68023c Make the DominatorTree reusable.
Add a compute() method which can recompute a dominator tree for
different functions.

Add a dominator tree data to the cretonne::Context.
2017-02-17 13:09:41 -08:00
Jakob Stoklund Olesen
77a7ad88f4 Make the ControlFlowGraph reusable.
Move the flow graph computation into a compute method which can be
called with multiple functions.

This allows us to reuse the ControlFlowGraph memory and keep an instance
in the Context.
2017-02-17 12:20:33 -08:00
Jakob Stoklund Olesen
859cca081c Upgrade to rustfmt 0.7.1 2017-01-25 15:17:27 -08:00
Jakob Stoklund Olesen
02bf84431b Use PackedOption<Inst> in the dominator tree.
Also rework the algorithm to be more robust against unreachable blocks.

- Add an is_reachable(ebb) method.
- Change idom(ebb) to just return an instruction.
- Make idom() return None for the entry block as well as unreachable
  blocks.
2017-01-19 19:44:16 -08: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
f9734458f8 Promote the src/tools crate to the top-level workspace.
The 'src' and 'tests' top-level directories now contain tools sources
and integration tests for any of the library crates.
2016-10-17 15:04:29 -07:00
Jakob Stoklund Olesen
846db00a21 Move library crates under 'lib/'.
Give these crates each a more standard directory layout with sources in
a 'src' sub-sirectory and Cargo.toml in the top lib/foo directory.

Add license and description fields to each.

The build script for the cretonne crate now lives in
'lib/cretonne/build.rs' separating it from the normal library sources
under 'lib/cretonne/src'.
2016-10-17 14:44:43 -07:00
Jakob Stoklund Olesen
af6355e2ef Move the 'meta' dir to 'lib/cretonne/meta'.
The 'lib/cretonne' directory will be the new root of a stand-alone
cretonne crate containg both Python and Rust sources.

This is in preparation for publishing crates on crates.io.
2016-10-17 14:19:23 -07:00
Jakob Stoklund Olesen
680387a53a Remove test_utils.
These test utilities have been subsumed by ir::Builder.
2016-10-14 15:17:34 -07:00
Jakob Stoklund Olesen
98308177cc Switch domtree tests to using Builder. 2016-10-14 15:16:29 -07:00
Jakob Stoklund Olesen
8fb8a41f8e Give Builder a Cursor.
The Builder keeps track of a position in the layout and inserts new
instructions there.

Add insert_ebb() and ebb() methods to Builder.

Use Builder in the cfg tests.
2016-10-14 15:02:58 -07:00
Jakob Stoklund Olesen
7aef6bd535 Add Cursor::insert_ebb() method.
Insert an EBB at the current position and switch to inserting
instructions there. Call the relevant Layout methods to do so.
2016-10-14 14:01:49 -07:00
Jakob Stoklund Olesen
a41b34c11c Add Layout::insert_ebb_after() method.
Symmetrical with the existing insert_ebb().
2016-10-14 13:54:26 -07:00
Jakob Stoklund Olesen
d1fd91021d Add Layout::split_ebb().
This method splits an EBB in two and moves trailing instructions to a
new EBB.
2016-10-14 12:33:54 -07:00
Jakob Stoklund Olesen
54a4b9b0d7 Add Cursor::insert_inst().
Insert an instruction at thecurrent cursor position.
2016-10-14 10:09:57 -07:00
Jakob Stoklund Olesen
177ac85db5 Add a LAyout Cursor data structure.
A layout cursor can be used instead of an iterator to keep track of a
position in a basic block *and* permitting instructions to be
manipulated.
2016-10-13 14:36:34 -07:00
Jakob Stoklund Olesen
6ce6f25626 Generate a Builder data type. WIP.
The Builder provides a convenient interface for inserting instructions
into an extended basic block.

The bulk of the builder methods are generated automatically from the
meta language instruction descriptions.

Still TODO: Keep track of an insertion position.
2016-10-12 16:47:11 -07:00
Jakob Stoklund Olesen
93f79d7a48 Move second_result outside boxed storage.
In instruction formats that have multiple results AND boxed storage,
place the second_result field outside the boxed storage. The 16-byte
instruction format has room for opcode, type, second_result in the first
8 bytes, and the boxed pointer in the last 8 bytes.

This provides a simpler implementation of the second_result() and
second_result_mut() InstructionData methods.
2016-10-12 16:01:06 -07:00
Jakob Stoklund Olesen
cf8d628254 Add simple Uimm8 and ImmVector immediate types.
Implement the boxed storage of the UnaryImmVector instruction format.
2016-10-12 15:51:22 -07:00
Jakob Stoklund Olesen
e35811e120 Add FuncRef and SigRef entity references.
These refer to external functions and function signatures declared in
the preamble. Since we're already using the type names 'Signature' and
'Function', these entity references don't folow the usual EntityData /
Entity naming convention.
2016-10-12 15:20:46 -07:00
Jakob Stoklund Olesen
75406ad5be Move signatures into new ir::extfunc module.
This new module will gain more data types dealing with external function
calls.
2016-10-12 13:56:26 -07:00
Jakob Stoklund Olesen
e5080fb64e Use 'varargs' consistently for VariableArgs members.
The meta code generators need to be able to infer these too.
2016-10-12 13:56:26 -07:00
Jakob Stoklund Olesen
6b784dd8dc Create a phantom workspace manifest for all crates.
Share a single Cargo.lock and target directory at the repo top-level.
2016-10-10 10:52:48 -07:00
Jakob Stoklund Olesen
4db11d1ae7 Add legalization helper instructions.
The isplit_lohi instruction breaks an integer into two halves. This will
typically be used to get the two halves of an `i64` value on 32-bit
CPUs.

The iconcat_lohi is the reverse operation. It reconstructs the `i64`
from the low and high bits.
2016-09-27 16:22:32 -07:00
Jakob Stoklund Olesen
2a4aaa3da1 Expand OpcodeConstraints to 32 bits.
Make room for 255 different type sets and 2^16 entries in the operand
constraints table.
2016-09-27 16:09:26 -07:00
Jakob Stoklund Olesen
d256c46f60 Add HalfWidth and DoubleWidth type variable functions.
These functions compute types with half or double the number of bits in
each lane.
2016-09-27 15:39:54 -07:00
Jakob Stoklund Olesen
a616a46db7 Represent type sets with ranges.
Allow limits on the smallest and largest integer type in the set, the
highest and lowest number of lanes etc.
2016-09-27 13:31:31 -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