Commit Graph

32 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
5f2e37e05c 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
Jakob Stoklund Olesen
1b6702ceba 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
c480f2264a Eliminate InstructionFormat.value_operands and .kinds.
Part of the refactoring of instruction formats. This list is now stored
in the instruction itself as value_opnums.
2017-03-10 10:46:45 -08:00
Jakob Stoklund Olesen
405cc14522 Change index domain for typevar_operand.
An instruction format is now seen as having two separate operand lists:
immediates and values. Change InstructionFormat.typevar_operand to be a
pure index into the value list.
2017-03-10 10:41:39 -08:00
Jakob Stoklund Olesen
be7ff71b15 Change InstBuilder low-level format constructor signatures.
The per-instruction format low-level constructors in InstBuilder should
be independent of the relative ordering of value and immediate operands
in order to prepare for the future instruction format merger.

Reorder their arguments such that all the immediate operands are placed
before the value operands.

For instruction formats that use a value list representation, just take
a single ValueList argument. The value lists are created by the
individual instruction constructors. This means that the format
constructor doesn't care how many of the instructions operands are
'fixed' and how many are 'variable' arguments.
2017-03-10 09:34:30 -08:00
Jakob Stoklund Olesen
e217b04347 Clean up lifetimes a bit.
No functional change.
2017-03-10 09:34:30 -08:00
Jakob Stoklund Olesen
f451cf42c8 Simplify the arguments() return type.
Now that variable arguments are always stored in a value list with the
fixed arguments, we no longer need the arcane [&[Value]; 2] return type.

Arguments are always stored contiguously, so just return a &[Value]
slice.

Also remove the each_arg() methods which were just trying to make it
easier to work with the old slice pair.
2017-03-09 22:09:22 -08:00
Jakob Stoklund Olesen
703762a67c Python InstructionFormat refactoring.
Make some changes that will make it easier to get rid of the
'value_operands' and 'members' fields in the Python InstructionFormat
class. This is necessary to be able to combine instruction formats that
all use a value list representation, but with different fixed value
operands. The goal is to eventually identify formats by a new signature:

   (multiple_results, imm_kinds, num_value_operands)

Start by adding new fields:

- imm_members and imm_kinds are lists describing the format operands,
  excluding any values and variable_args operands.
- num_value_operands is the number of fixed value operands, or None in a
  has_value-list format.

Use these new members in preference to the old ones where possible.
2017-03-09 21:54:22 -08:00
Jakob Stoklund Olesen
cd06b176ac Remove some has_value_list workarounds.
Now that all variable_args formats use has_value_list, we can remove
some workarounds that allowed the old boxed_storage form.
2017-03-09 19:12:00 -08:00
Jakob Stoklund Olesen
1135a89af9 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
364b8e5f0a Use value lists for call arguments.
Add a new kind of instruction format that keeps all of its value
arguments in a value list. These value lists are all allocated out of
the dfg.value_lists memory pool.

Instruction formats with the value_list property set store *all* of
their value arguments in a single value list. There is no distinction
between fixed arguments and variable arguments.

Change the Call instruction format to use the value list representation
for its arguments.

This change is only the beginning. The intent is to eliminate the
boxed_storage instruction formats completely. Value lists use less
memory, and when the transition is complete, InstructionData will have a
trivial Drop implementation.
2017-03-09 14:34:07 -08:00
Jakob Stoklund Olesen
58756e5d34 Add is_call and is_return instruction attributes. 2017-03-08 14:48:50 -08:00
Jakob Stoklund Olesen
8c5a69eb47 Fixed for mypy 0.501.
The List and Dict types are no longer implicitly available. They must be
imported from typing.

Type annotations must appear before the doc comment in a function. Also
fix type errors in these functions that weren't detected before.
2017-03-03 09:08:28 -08:00
Angus Holder
2ec7412a81 Removed unnecessary documentation. 2017-02-22 10:22:08 -08:00
Angus Holder
a4e4776087 Removed the Opcode::NotAnOpcode variant, replaced its uses with Option<Opcode>, and used the NonZero optimization to maintain the small 1-byte size of an optional Opcode. 2017-02-22 10:22:08 -08:00
Jakob Stoklund Olesen
a7d24ab1dc Compute the controlling type variable accurately.
Some polymorphic instructions don't return the controlling type
variable, so it has to be computed from the designated operand instead.

- Add a requires_typevar_operand() method to the operand constraints
  which indicates that.
- Add a ctrl_typevar(dfg) method to InstructionData which computes the
  controlling type variable correctly, and returns VOID for monomorphic
  instructions.
- Use ctrl_typevar(dfg) to drive the level-1 encoding table lookups.
2017-02-21 16:26:19 -08:00
Jakob Stoklund Olesen
2e6cf219e9 Use PackedOption<Value> instead of NO_VALUE.
- Remove NO_VALUE and ExpandedValue::None.
- Remove the Default implelmentation for Value.
- InstructionData::second_result() returns an Option<Value>.
- InstructionData::second_result() returns a reference to the packed
  option.
2017-01-19 15:55:18 -08:00
Jakob Stoklund Olesen
3392a2b79a Fix Python formatting to keep flake8 happy.
Python coding style is verified by the lib/cretonne/meta/check.sh script
which is not run as part of test-all.sh.

cc @dinfuehr
2016-12-08 13:30:40 -10:00
Dominik Inführ
c1ecb29851 remove old is_terminating function
for InstructionData. Use generated `is_terminator()` for `Opcode`
instead. `is_terminator`, `can_trap` and `is_branch` functions are now
public.

fix syntax error
2016-12-07 10:16:01 -10:00
Dominik Inführ
93aa2b456e added Opcode flags methods
generate `is_branch`, `is_terminator`, `can_trap` methods for `enum
Opcode`.
2016-12-02 15:50:28 -08:00
Jakob Stoklund Olesen
5c9a12f101 Add TypeVar.rust_expr().
Generate a Rust expression that computes the value of a derived type
variable.
2016-11-10 15:47:57 -08:00
Jakob Stoklund Olesen
45fd134d3e 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
5fa322f797 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
bb28dc6686 Split out operand descriptions.
- cdsl.operands has the Operand and OperandKind classes.
2016-11-08 10:58:23 -08:00
Jakob Stoklund Olesen
f8545574b5 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
152aabbfc0 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
125fe64121 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
3da569de06 Require documentation on cretonne public items. 2016-10-26 19:10:06 -07:00
Jakob Stoklund Olesen
61f5eeee2f 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
6db94bb980 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
58168bcd07 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
e7f30a40b4 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