Commit Graph

219 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
5e75b22c01 Assign a type variable to all VALUE operands.
A few operands have a fixed type assigned. Create a singleton type
variable for these exceptions. Most instructions are polymorphic, so
this is a little overhead.

Eliminate the Operand.typ field and replace it with an Operand.typevar
field which is always a TypeVar, but which only exists in VALUE
operands.
2016-11-08 14:58:44 -08:00
Jakob Stoklund Olesen
8846cb8105 Move ISA definitions into cdsl.isa.
The cretonne package is now split into two: cdsl and base.
2016-11-08 13:21:05 -08:00
Jakob Stoklund Olesen
cc86964ab3 Move ast, xform, and legalize modules.
- cdsl.ast defines classes representing abstract syntax trees.
- cdsl.xform defines classes for instruction transformations.
- base.legalize defines legalization patterns.
2016-11-08 12:33:50 -08:00
Jakob Stoklund Olesen
0b9b956695 Split out instruction definitions.
- cdsl.instructions defines the Instruction class.
- base.instructions defines the base instruction set.
2016-11-08 12:33:50 -08:00
Jakob Stoklund Olesen
87eb1a8ea0 Split out instruction formats.
- cdsl.formats provides classes for describing instruction formats.
- base.formats provides concrete instruction format definitions.
2016-11-08 11:48:05 -08:00
Jakob Stoklund Olesen
b5e592ad56 Move Operand itself into cdsl.operands. 2016-11-08 11:30:31 -08:00
Jakob Stoklund Olesen
0666c8818a Get rid of operand_kind()
This method caused lots of import cycles when type checking.

Use isinstance() in the Operand constructor instead to decipher the
OperandSpec union type.
2016-11-08 11:26:26 -08:00
Jakob Stoklund Olesen
2e718c6554 Split out the typevar module.
- cdsl.typevar defines TypeVar and TypeSet classes.
2016-11-08 11:26:25 -08:00
Jakob Stoklund Olesen
eb688dc72d Move formats, entities, and immediates to the base package.
- base.formats defines instruction formats.
- base.entities defines kinds of entity references.
- base.immediates defines kinds of imediate operands.
2016-11-08 11:06:37 -08:00
Jakob Stoklund Olesen
19287c1f32 Split out operand descriptions.
- cdsl.operands has the Operand and OperandKind classes.
2016-11-08 10:58:23 -08:00
Jakob Stoklund Olesen
e6b959436d Split out predicates and settings.
- cdsl.predicates defines classes for describing predicates.
- cdsl.settings defines classes for describing settings.
- base.settings defines shared settings.
2016-11-08 10:37:17 -08:00
Jakob Stoklund Olesen
ac59376c46 Move ValueType into a new cdsl top-level module.
We want to separate the Python classes that make up the DSL used to
define the Cretonne language from the concrete definitions.

- cdsl.types defines the ValueType class hierarchy.
- base.types defines the concrete types.
2016-11-08 10:12:47 -08:00
Jakob Stoklund Olesen
6419ba12bc Resolve import cycles. 2016-11-08 09:06:28 -08:00
Jakob Stoklund Olesen
4389079647 Add more Python type annotations. 2016-11-08 08:52:21 -08:00
Jakob Stoklund Olesen
15c635f537 Check for unsupported value transformations.
Add an assertion for the value placements that we don't support yet.

1. A primary result in the source pattern becomes a secondary result in
   the destination.
2. A secondary result becomes a secondary result, and the destination
   instruction is not exactly matching the source.
2016-11-04 17:39:20 -07: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
4460adbfc2 Write out value aliases when writing instructions.
If an instruction uses any values that are aliases of other values,
print out the alias mappings on lines preceding the instruction. This is
necessary to reconstruct the data flow graph.

We don't make any attempt to only write out each alias mapping once.

The parser does not yet support value aliases.
2016-11-04 15:28:51 -07:00
Jakob Stoklund Olesen
55bc5599cc Fix off-by-one in resolve_values.
When the extended_values table is empty, the value to resolve is
definitely not an alias, but we still need as least one trip in the loop
to determine that.
2016-11-04 15:28:51 -07:00
Jakob Stoklund Olesen
eb2b56c20a Add arguments() and arguments_mut() methods.
Provide a generic way of accessing the value arguments on an
instruction. This is provided as two slice references. One for the fixed
arguments and one for any VariableArgs.

The arguments() methods return an array of two slices which is a bit
awkward. Also provide an each_arg() method which passes each argument
value to a closure.
2016-11-04 14:16:49 -07:00
Jakob Stoklund Olesen
dc2afb24d9 Add a ref_slice module.
Utility functions for converting &T to an &[T] slice with a single
element.
2016-11-04 12:32:09 -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
8d6d59cc7a Gather comments in the preamble of a test file.
Comments preceding the first function are not associated with any
specific entity in the file. Put them in a TestFile::preamble_comments
field.
2016-11-04 10:42:31 -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
1c57f43643 Add Cursor::set_position.
Make it possible to move a cursor to a new position.

In the current implementation of Layout and Cursor, this is a trivial
operation, but if we switch to a B-tree based function layout, this
involves navigating the tree.
2016-11-04 08:44:01 -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
e59b47c41a Return a Result from the TargetIsa::encode() method.
When an instruction can't be encoded, provide a viable legalization
action in the form of a Legalize enum.
2016-11-03 19:15:36 -07:00
Jakob Stoklund Olesen
9c02fe3553 Legalization pattern emission WIP.
Begin emitting legalization patterns in the form of two functions,
'expand' and 'narrow' that are included in legalizer.rs.

The generated code compiles, but it is not fully working yet. We need to
deal with the special cases of instructions producing multiple results.
2016-11-03 19:13:54 -07:00
Jakob Stoklund Olesen
814d1728aa Add a Value::unwrap_direct() method.
When it is known that a value is the first result of an instruction, it
is safe to unwrap the instruction reference.
2016-11-03 19:13:54 -07:00
Jakob Stoklund Olesen
0543bb049c Save a reference from a Var to its src and dst defs.
When a Var is used in an XForm, it can be defined in the src or dst or
both patterns, and it is classified accordingly. When a Var is defined,
it is also useful to be able to find the `Def` that defined it.

Add src_def and dst_def reference members to Var, and initialize them in
the private Var copies that XForm creates for itself.

These two members also replace the defctx bitmask.
2016-11-03 12:37:24 -07:00
Jakob Stoklund Olesen
318e3b9b33 Classify Vars in patterns.
There's 4 classes of variables, depending on whether they have defs in
the source and destination patterns.

Add more XForm verification: In a legalize XForm, all source defs must
be outputs.

Fix a legalize pattern bug caught by this.
2016-11-02 14:34:48 -07:00
Jakob Stoklund Olesen
c7d1f90b71 Canonicalize the objects in an RTL list.
Any Apply objects in the input are converted to Defs with empty def
lists.
2016-11-02 14:28:37 -07:00
Jakob Stoklund Olesen
e1dae95828 Fix inconsistent instruction name.
The 'fpromote' instruction was renamed from 'fcvt_ftof', but the name
argument was not changed.
2016-11-02 10:45:59 -07:00
Jakob Stoklund Olesen
ececaa902d Add type annotations to TypeVar 2016-11-01 14:23:41 -07:00
Jakob Stoklund Olesen
679448af72 Run unittests with Python 3 if it is available.
The check.sh script always runs the Python unittests with 'python', but
if 'python3' is in the path, run it with that too.

Fix a Python 3 compat issue and avoid passing None to max() and min().
Use an explicit intersect() function instead to intersect intervals.
2016-11-01 12:01:40 -07:00
Benjamin Bouvier
419e686581 Fix a few typos in the docs; 2016-10-28 11:31:22 -07:00
Sean Gillespie
4d729bf986 Use items instead of iteritems for Python 3 compatibility 2016-10-28 08:45:37 -07:00
Jakob Stoklund Olesen
80823b5fc4 Require documentation on cretonne public items. 2016-10-26 19:10:06 -07:00
Jakob Stoklund Olesen
e2418c6ec9 Require documentation on reader public items. 2016-10-26 17:43:18 -07:00
Jakob Stoklund Olesen
447baf015e Require documentation on filecheck public items. 2016-10-26 17:34:45 -07:00
Jakob Stoklund Olesen
15f626ccc0 Begin generating code for the legalizer.
This is a work in progress. The 'legalizer.rs' file generated by
gen_legalizer.py is not used for anything yet.

Add PEP 484 type annotations to a bunch of Python code.
2016-10-26 16:06:57 -07:00
Jakob Stoklund Olesen
d7a479de6d Run mypy if it's available.
The Python tools pyliint, flake8, and mypy are only run if they exist in
$PATH.
2016-10-26 15:15:51 -07:00
Jakob Stoklund Olesen
2a8f8f79ff Create FormatField attributes on demand.
The InstructionFormat objects make their non-value operands available as
FormatField attributes for use by predicates etc.

Compute these on demand instead of up front. This makes it possible for
the mypy tool to infer the types of these attributes from the
__getattr__ signature.
2016-10-26 15:15:51 -07:00
Jakob Stoklund Olesen
ed917c394f Add PEP 484 type annotations to a bunch of Python code.
Along with the mypy tool, this helps find bugs in the Python code
handling the instruction definition data structures.
2016-10-26 15:15:51 -07:00
Jakob Stoklund Olesen
31e033af49 File stale path references.
After rearranging the directory layout, some paths in documentation
needed updating.

Fix some typos too.
2016-10-24 13:27:10 -07:00
Jakob Stoklund Olesen
cf1996b036 Introduce value aliases.
A extended value can now be changed to a third form: An alias of another
value. This is like a copy instruction, but implicit in the value table.

Value aliases are used in lieu of use-def chains which would be used to
implement replace-all-uses-with.

Added new DFG methods:

- change_to_alias() changes an existing extended value into an alias.
  Primay values can't be changed, replace their definition with a copy
  instruction instead.
- resolve_aliases() find the original non-alias value.
- resolve_copies() like resolve_aliases(), but also sees through
  copy/spill/fill instructions.
2016-10-21 11:18:12 -07:00
Jakob Stoklund Olesen
e7a17a1b59 Properly infer result type for single-result instructions.
Polymorphic single-result instructions don't always return the
controlling type variable as their first result. They may use a derived
type variable, as for example icmp does.
2016-10-21 11:10:26 -07:00
Jakob Stoklund Olesen
3791e8660d Make Type::as_bool() less pedantic for scalars.
All scalar types are mapped to b1 which is usually what you want for a
scalar. Vector types have their lanes mapped to the wider boolean types.

Add an as_bool_pedantic() methos that produces the scalar sized boolean
types as before.

Also add a friendlier Debug implementation for Type.
2016-10-21 10:43:33 -07:00
Jakob Stoklund Olesen
ce9049af90 Implement From<i64> for Imm64.
This makes it possible to use literal integers as arguments to
InstBuilder methods.
2016-10-21 10:43:33 -07:00
Jakob Stoklund Olesen
1305283ed8 Move the 'ins' method to DataFlowGraph.
This given us better symmetry between the replace and insert builder operations:

    dfg.replace(inst).iadd(x, y)
    dfg.ins(cursor).imul(x, y)
2016-10-21 09:46:17 -07:00