Commit Graph

1293 Commits

Author SHA1 Message Date
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
Jakob Stoklund Olesen
0acabc80d0 Define live range splitting instructions.
The copy/spill/fill instructions will be used by the register allocator
for splitting live ranges. The copy instruction is also useful when
rewriting values:

If a primary value is rewritten as a secondary result, a copy
instruction can be used instead:

  a = foo x
=>
  t, vx1 = call ...
  a = copy vx1

Since a primary value must be the first value of an instruction, this
doesn't work:

  a = foo x
=>
  t, a = call ...
2016-10-20 15:34:16 -07:00
Jakob Stoklund Olesen
8422976d78 Add a ReplaceBuilder instruction builder.
The DataFlowGraph::replace(inst) method returns an instruction builder
that will replace an instruction in-place.

This will be used when transforming instructions, replacing an old
instruction with a new (legal) way of computing its primary value. Since
primary result values are essentially instruction pointers, this is the
only way of replacing the definition of a value.

If secondary result values match the old instruction in both number and
types, they can be reused. If not, added a detach_secondary_results()
method for detaching old secondary values.
2016-10-20 13:33:49 -07:00
Jakob Stoklund Olesen
d763bedeaa Rename Builder to InsertBuilder.
This instruction builder inserts an instruction at the cursor position.
We'll add other kinds of builders shortly.
2016-10-20 11:16:58 -07:00
Jakob Stoklund Olesen
5f140eddf7 Switch InstrBuilder to the one-shot builder pattern.
All the InstrBuilder methods now consume the builder, and the non-leaf
methods return the dfg mutable reference they were holding.

This makes it possible to construct instruction builders that are only
safe to use once because they are doing more advanced value rewriting.
2016-10-19 19:33:48 -07:00
Jakob Stoklund Olesen
78312c6c46 Add a Cursor::ins() method which constructs a Builder.
Rewrite Builder uses in test cases to use this method and construct a
new builder for each instruction. This pattern allows us to change the
InstBuilder trait to a one-shot implementation that can only create a
single instruction.

Don't re-export the Builder struct, it is less important than the
InstBuilder trait, and we may get more implementations.
2016-10-19 19:33:19 -07:00
Jakob Stoklund Olesen
4cd33b210e Use more precise lifetimes for Builder.
Distinguish the lifetime of the Cursor and its referenced function
layout.

Use two separate function lifetimes: 'fc and 'fd. The borrow checker
seems to get confused if we don't.
2016-10-19 19:32:57 -07:00
Jakob Stoklund Olesen
eef5de1cf0 Generate an InstBuilder trait.
All of the instruction format an opcode methods are emitted as an
InstBuilder trait instead of adding them to the Bulder struct directly.
The methods only make use of the InstBuilderBase methods to create new
instructions.

This makes it possible to reuse the InstBuilder trait for different ways
of inserting instructions.
2016-10-19 18:21:17 -07:00
Jakob Stoklund Olesen
499fefebd9 Rename lifetimes in layout.rs to 'f
These lifetimes all represent the lifetime of the Function.
2016-10-19 16:23:08 -07:00
Jakob Stoklund Olesen
cdb141d138 Also rebuild if build.rs itself changes.
We already have all the meta/**.py as dependencies.
2016-10-19 12:03:50 -07:00
Jakob Stoklund Olesen
a5913e6489 Add more expansion patterns.
RISC-V does not have a flags register, and thus no add-with-carry
instructions. Neither does MIPS.

Add expansions of these instructions in terms of iadd and icmp.
2016-10-19 11:24:08 -07:00
Jakob Stoklund Olesen
1e18e66ebe Bump filecheck version to 0.0.1, allow publication. 2016-10-18 13:33:39 -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
cdb63a547e Add result values to call instructions too.
The make_inst_results() method now understands direct and indirect
calls, and can allocate result values matching the return types of the
function call.
2016-10-18 13:08:50 -07:00
Jakob Stoklund Olesen
1bcb8e25a2 Add signatures and ext_funcs tables to DataFlowGraph.
These two tables are used to keep track of type signatures of function
calls as well as external function references used in direct function
calls.

Also add an ExtFuncData struct representing an external function that
can be called directly.
2016-10-18 11:28:03 -07:00
Jakob Stoklund Olesen
bdc95990d4 Add call and call_indirect instructions.
Add a new IndirectCall instruction format which has a value callee as
well as the call arguments.

Define call and call_indirect instructions.
2016-10-18 10:04:06 -07:00
Jakob Stoklund Olesen
b8a76822cf Track signatures and function references in the source map. 2016-10-18 09:43:20 -07:00
Jakob Stoklund Olesen
80a6ae203d Generalize def_inst() to def_entity().
Use this source map method for assigning a location to any entity whose
source number is not exposed. This could be

- Instructions.
- Signatures defined implicitly by function decls.

These entities only appear in the location map, not the entity number
maps.
2016-10-18 09:38:05 -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