Commit Graph

961 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
3c8bdba15e Don't create value aliases when legalizing ABI boundaries.
When converting from ABI types to original program types, the final
conversion instruction can place its result into the original value, so
it doesn't need to be changed to an alias.
2017-04-13 10:16:58 -07:00
Jakob Stoklund Olesen
7ad882c154 Avoid creating value aliases in legalizer/split.rs.
When we're splitting an EBB argument, we insert a iconcat/vconcat
instruction that computes the original value from the new split
arguments.

The concat instruction can now define the original value directly, it is
not necessary to define a new value and alias the old one.
2017-04-13 09:45:36 -07:00
Jakob Stoklund Olesen
d48f79aa72 Avoid creating aliases when expanding legalizer patterns.
Now that we can detach and reuse all values, there is no longer a need
to create a lot of alias values during pattern expansion. Instead, reuse
the values from the source pattern when emitting instructions in the
destination pattern.

If a destination instruction produces the exact same values as a source
instruction, simply leave the values attached and replace the
instruction it. Otherwise, detach the source values, reuse them in the
expansion, and remove the source instruction afterwards.
2017-04-13 09:30:21 -07:00
Jakob Stoklund Olesen
48b2f421b4 Add a with_results() method to the InsertBuilder.
This makes it possible to reuse one or more result values in the
instruction that is being inserted.

Also add a with_result(v) method for the common case of reusing a single
result value. This could be specialized in the future.
2017-04-13 08:55:18 -07:00
Jakob Stoklund Olesen
3197f240ff Add a make_inst_results_reusing() generic method.
This is a generalization of the existing make_inst_results() which lets
you provide some or all of the result values instead of creating all new
ones.
2017-04-13 08:18:52 -07:00
Jakob Stoklund Olesen
d4f511ecfc Return the removed instruction from Cursor::remove_inst().
This is convenient for asserting that the right instruction was removed.
2017-04-13 08:18:52 -07:00
Jakob Stoklund Olesen
801f4ade66 Add remove_inst() methods to Cursor and Layout.
We didn't have a way of removing instructions again.
2017-04-12 17:06:27 -07:00
Jakob Stoklund Olesen
84c15e0e66 Add some safety checks for detached values.
These methods are used to reattach detached values:

- change_to_alias
- attach_result
- attach_ebb_arg

Add an assertion to all of them to ensure that the provided value is not
already attached somewhere else. Use a new value_is_attached() method
for the test.

Also include a verifier check for uses of detached values.
2017-04-12 15:19:26 -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
b165d9a313 Remove the first_type() methods from InstructionData.
Also remove the type field from all the variants. The type of the first
result value can be recovered from the value table now.
2017-04-12 14:32:13 -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
e653d44f39 Stop linking result values together.
Since results are in a value list, they don't need to form a linked
list any longer.

- Simplify make_inst_results() to create values in the natural order.
- Eliminate the last use of next_secondary_value().
- Delete unused result manipulation methods.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
8a2398be08 Stop calling Value::new_direct.
We only ever create table values now.

Simplify legalizer::legalize_inst_results. Instead of calling
detach_secondary_results, just detach all the results and don't treat
the first result specially.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
d133606fe7 Don't assume all first results are direct values.
We're about to change that.
2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
94e26a845a Make tests less sensitive to specific value numbers. 2017-04-12 14:32:13 -07:00
Jakob Stoklund Olesen
f8b473c428 Add detach_results(), attach_result(), and append_result() methods.
These low-level methods for manipulating instruction result value lists
will replace the existing secondary_result methods.
2017-04-12 11:50:59 -07:00
Jakob Stoklund Olesen
0897d43c88 Don't attach a first result in make_inst().
That is now the job of make_inst_results().
2017-04-12 09:45:21 -07:00
Jakob Stoklund Olesen
78a036fa51 Remove the second_result field from instructions.
Now that result values are stored in value lists in the DFG, these
head-of-list pointers are no longer needed.
2017-04-12 09:14:39 -07:00
Jakob Stoklund Olesen
71338bb31f Simplify the back-end of InstBuilder.
We don't want to distinguish between single-result and multiple-result
instructions any longer.

- Merge the simple_instruction() and complex_instruction() builder
  methods into a single build() that can handle all cases.
- All format constructors now take a ctrl_type argument. Previously,
  some would take a result_type argument.
- Instruction constructors no longer attempt to compute a single result
  type. Just pass a ctrl_type and let the backend decide.

Fix one format constructor call in legalizer/split.rs which now takes a
ctrl_type instead of a result type.
2017-04-12 08:56:20 -07:00
Jakob Stoklund Olesen
322a8db839 Change dfg.inst_results to return a slice.
Now we can access instruction results and arguments as well as EBB
arguments as slices.

Delete the Values iterator which was traversing the linked lists of
values. It is no longer needed.
2017-04-11 16:57:15 -07:00
Jakob Stoklund Olesen
3a36435c3b Maintain a ValueList with the results of each instruction.
This is the first step of a larger refactoring to represent instruction
results as value lists instead of using linked lists. The refactoring
will also eliminate the special treatment of first results such that all
result values can be detached and redefined.

This change put us in a temporary state where results are represented
both as linked lists and ValueList vectors.

- Add a dfg.results table.
- Add the first result in make_inst(). This behavior will change.
- Recompute the result list in make_inst_results().
- Make dfg.first_result(inst) crash if the instruction has no results.
2017-04-11 16:21:41 -07:00
Jakob Stoklund Olesen
7b2becfb21 Add EntityList::first().
This is the same as slice::first(), except it returns the first element
by value.

The implementation can avoid checking the list length since empty lists
already have a special representation.
2017-04-11 16:21:41 -07:00
Jakob Stoklund Olesen
fe0d986110 Make the dfg.insts table private again.
- Add a dfg.is_inst_valid() method for the verifier.
- Use the inst_args_mut() method when rewriting values in the parser.
- Add a new branch_destination_mut() to use when rewriting EBBs.

This also gets rid of one of the large instruction format switches in
the parser.
2017-04-11 15:03:43 -07:00
Jakob Stoklund Olesen
5209778ae2 Stop maintaining a linked list of EBB arguments.
Now that we have a value list of the arguments, we can get rid of:

- The first_arg and last_arg members in EbbData,
- The next member in the ValueData::Arg variant.
2017-04-11 12:30:37 -07:00
Jakob Stoklund Olesen
ca900d6bf8 Return the whole value list from detach_ebb_args().
Rather than returning the head of a linked list of EBB arguments, just
return the whole value list of all the arguments.

Delete the next_ebb_arg() method which was only used for traversing that
list.
2017-04-11 12:14:33 -07:00
Jakob Stoklund Olesen
dd0a61cc91 Keep EBB arguments in a ValueList.
This is the first step of the value list refactoring which will replace
linked lists of values with value lists.

- Keep a ValueList in the EbbData struct containing all the EBB
  arguments.
- Change dfg.ebb_args() to return a slice instead of an iterator.

This leaves us in a temporary hybrid state where we maintain both a
linked list and a ValueList vector of the EBB arguments.
2017-04-11 11:36:50 -07:00
Jakob Stoklund Olesen
4ee519e620 Add RISC-V call instruction encodings.
Calls are jal with a fixed %x1 link register.
2017-04-11 10:40:38 -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
e78e4ea4ec Add a Uoffset32 immediate operand kind.
WebAssembly memory instructions encode a 32-bit unsigned offset that is
used to compute an effective address.
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
7c3bc9d19f Add Offset32 support to the parser. 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
51dea9f784 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
896ac935b9 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
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
5025bb67f4 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
856a67ca3a 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
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
598c81c12e 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
f47c62ba8c 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
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
e641c97670 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
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
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
0530e822d4 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