Commit Graph

1293 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
02051c4764 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
aa06e40456 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
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
7a0092754d 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
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
Angus Holder
892ad25b1b 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
0619d6f827 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
19710af5b7 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
5027e096b5 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
6fdbbf2b1a 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
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
26ee382b57 Fix weird indentation. 2017-03-22 13:17:25 -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
d32c19c81d Add a DataFlowGraph::replace_ebb_arg() method.
This is needed for rewriting EBB arguments with legalized types.
2017-03-22 10:36:42 -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
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
dfdc1ed514 Move ABI boundary legalization into a sub-module.
Keep things organized.
2017-03-20 15:14:51 -07:00
Jakob Stoklund Olesen
34e5675d17 Add OpcodeConstraints::value_argument_constraint().
As discussed in #3.

Once we know the controlling type variable of a polymorphic instruction,
the types of input operands are either bound to known types, or they can
vary freely.
2017-03-20 14:47:09 -07:00
Angus Holder
d383a41851 Verify that all predecessors to an EBB are valid branches, and have the EBB recorded as a successor. 2017-03-20 08:41:11 -07:00
Angus Holder
8b300a9efb Verify that values are defined by an EBB/instruction that dominates the instruction that uses them. 2017-03-20 08:41:11 -07:00
Angus Holder
c50bf2aa68 Verify that values have a valid reference to either an instruction inserted in an EBB, or an EBB inserted in the layout. 2017-03-20 08:41:11 -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
56d12b14ff Add attach_secondary_result and append_secondary_result.
These low-level functions allow us to build up a list of instruction
results incrementally. They are equivalent to the existing
attach_ebb_arg and append_ebb_arg.
2017-03-17 10:07:32 -07:00
Jakob Stoklund Olesen
6dc11d1267 Use a closure to control the convert_from_abi() function.
This will be used for converting function return types soon, so
generalize it a bit.
2017-03-17 10:07:32 -07:00
Jakob Stoklund Olesen
e90e59cedb Add DataFlowGraph::redefine_first_value()
This makes it possible to compute the first result of an instruction in
a different way without overwriting the original instruction with
replace().
2017-03-16 13:10:12 -07:00
Jakob Stoklund Olesen
2119c85224 Don't return a Values iterator from detach_secondary_results().
Instead, just return the first of the detached values, and provide a
next_secondary_result() method for traversing the list.

This is equivalent to how detach_ebb_args() works, and it allows the
data flow graph to be modified while traversing the list of results.
2017-03-15 15:38:47 -07:00
Jakob Stoklund Olesen
db5aead1a5 Rename take_ebb_args to detach_ebb_args()
This better matches the detach_secondary_results cousin.

Also rename the converse put_ebb_arg -> attach_ebb_arg.
2017-03-15 15:21:57 -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
01cb51ece9 Add DataFlowGraph::display_inst().
This method returns an object that can display an instruction in the
standard textual format, but without any encoding annotations.
2017-03-15 13:52:45 -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
d604855b27 Fix logic bug in requires_typevar_operand.
The Python code computing this property had a bug. The property has only
been used for optimizing the ctrl_typevar() method so far.
2017-03-14 13:32:15 -07:00
Jakob Stoklund Olesen
7db4b1b73a Add OpcodeConstraints::fixed_value_arguments()
Now that some instruction formats put all of their value arguments in a
value list, we need to know how many value are fixed and how many are
variable_args.

CC @angusholder who may need this information in the verifier.
2017-03-14 13:24:49 -07:00
Keith Yeung
98e8a96412 Add unit test for value aliasing 2017-03-14 11:56:09 -07:00
Keith Yeung
f18eddc9ed Allow type inference to go through value aliasing 2017-03-14 11:56:09 -07:00
Keith Yeung
d93c37a826 Make value aliases during references rewriting 2017-03-14 11:56:09 -07:00
Keith Yeung
8e38c7907d Create alias HashMap in parser context 2017-03-14 11:56:09 -07:00
Keith Yeung
50e043477e Parse instruction results separately from instructions 2017-03-14 11:56:09 -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
Angus Holder
477fb4d5da Expanded instruction integrity checking in the verifier, now verifying result types and entity references. 2017-03-14 09:12:33 -07:00
Jakob Stoklund Olesen
d3df198747 Add a grow_at() method to EntityList.
This method opens up a hole in the middle of a list where new elements
can be written.
2017-03-13 16:37:48 -07:00
Jakob Stoklund Olesen
1baedc3ca5 Add take_value_list and put_value_list methods.
Any code that needs to manipulate a variable argument list on an
instruction will need to remove the instruction's value list first,
change the list, and then put it back on the instruction. This is
required to avoid fighting the borrow checker over mutable locks on the
DataFlowGraph and its value list pool.

Add a generated InstructionData::take_value_list() method which lifts
out and existing value list and returns it, levaing an empty list in its
place, like Option::take() does it.

Add a generated InstructionData::put_value_list() which puts it back,
verifying that no existing value list is overwritten.
2017-03-13 14:07:14 -07:00
Angus Holder
1e1a1a8797 Added ControlFlowGraph::recompute_ebb for incremental CFG updates. 2017-03-13 09:01:13 -07:00
Angus Holder
11a0daa7fd Define boolean conversion instructions. 2017-03-11 10:25:55 -08:00
Davide Italiano
46525b0153 [B-tree] Initial comment to describe the design choices. 2017-03-10 12:48:32 -08:00
Jakob Stoklund Olesen
667d6f9381 Remove the value_list and boxed_storage format flags.
The value_list flag can be inferred from the presence of VARIABLE_ARGS
in the operand list.

The boxed_storage flag is obsolete. We don't need boxed storage anywhere
no that we have value lists instead.
2017-03-10 12:43:05 -08:00
Jakob Stoklund Olesen
910e4e6174 Coalesce some formats into MultiAry.
Allow some flexibility in the signature matching for instruction
formats. In particular, look for a value list format as a second chance
option.

The Return, ReturnReg, and TernaryOverflow formats all fit the single
MultiAry catch-all format for instructions without immediate operands.
2017-03-10 12:32:44 -08:00