Commit Graph

522 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
378e7cfe6b Switch branch relaxation to a FuncCursor. 2017-08-04 16:00:48 -07:00
Jakob Stoklund Olesen
6f024267c6 Add a FuncCursor type to the cursor library.
A FuncCursor works a like a layout cursor, but it holds a reference to
the entire function and lets you re-borrow the function reference.

Rewrite the dominator tree unit tests with a FuncCursor instead of a
layout cursor to demonstrate the difference. It avoids the constrained
lifetimes of the layout cursor in the tests.
2017-08-04 15:31:08 -07:00
Jakob Stoklund Olesen
8b2f5c418b Use EncCursor for reload.rs.
Same deal as for spilling. Place an EncCursor in the context and use
that to reference into the IR function when necessary.
2017-08-04 15:02:46 -07:00
Jakob Stoklund Olesen
3eb80fde15 Use EncCursor in regalloc/spilling.rs
Use an EncCursor instead of a layout cursor to keep track of the
current position in the function. Since the EncCursor holds a reference
to the whole IR function insteadof just the layout, we can rework how IR
borrowing works.

The Context data structure that's live during the spilling pass now owns
an EncCursor which in turn holds references to the function and ISA.
This means that we no longer need to pass around references to parts of
the ir::Function. We can no longer borrow any part of the IR function
across a context method call, but that turns out to be not necessary.
2017-08-04 14:13:56 -07:00
Jakob Stoklund Olesen
0ab1976231 Cursor library.
Add a new cursor module and define an EncCursor data type in it. An
EncCursor is a cursor that inserts instructions with a valid encoding
for the ISA. This is useful for passes generating code after
legalization.

Implement a builder interface via the new InstInserterBase trait such
that the EncCursor builders support with_result().

Use EncCursor in coalescing.rs instead of the layout cursor as a proof
of concept.
2017-08-04 14:05:14 -07:00
Jakob Stoklund Olesen
ff39458f96 Reorganize the instruction builder traits.
Leave the primary InstBuilderBase trait alone, but add an alternative
InstInserterBase trait that can be implemented instead by builders that
always allocate new instructions with dfg.make_inst().

Any implementation of InstInserterBase can be used as an instruction
builder by wrapping it in an InsertBuilder. The InsertBuilder type adds
additional functionality via the with_results() method which makes it
possible to override the result values on the instruction that is built.

The motivation for this shuffle is that the with_result() functionality
can now be reused by different kinds of instruction builders, as long as
they insert new instructions. So ReplaceBuilder doesn't get
with_results().
2017-08-04 11:56:03 -07:00
Jakob Stoklund Olesen
019e5dd894 Add CursorBase builder methods.
The CursorBase::at_* are convenience methods for building a cursor that
points to a specific instruction.
2017-08-04 09:08:24 -07:00
Jakob Stoklund Olesen
78db5b3715 Move most Cursor methods into a CursorBase trait.
The Cursor navigation methods all just depend on the cursor's position
and layout reference. Make a CursorBase trait that provides access to
this information with methods and implement the navigation methods on
top of that.

This makes it possible to have multiple types implement the cursor
interface.
2017-08-04 09:08:24 -07:00
Jakob Stoklund Olesen
81ff9bac72 Avoid evaluating dbg!() arguments in a closure.
The dbg!() macro should behave like a function call in how it evaluates
its arguments, and captures by Rust closures are not fully compatible
with path-specific borrowing. Specifically:

    let borrow = &mut obj.foo;
    dbg!("{}", obj.bar);

would fail because the closure inside dbg!() would borrow all of obj
instead of just obj.foo.

Fix this by using the format_args!() macro to evaluate the dbg!()
arguments and produce an fmt::Arguments object which can be safely
passed to the thread-local closure for printing.

The arguments are still evaluated inside an if { .. } which
constant-folds away in release builds.
2017-08-04 08:54:00 -07:00
Denis Merigoux
e0fd5252d5 Added partial recompute of dominator tree in case of Ebb splitting (#135)
* Partial recompute for dominator tree in case of ebb splitting
Implemented via striding in RPO numbers
2017-08-03 18:26:41 -07:00
Jakob Stoklund Olesen
d591b38b37 Add a prologue_epilogue() hook to TargetIsa.
This will compute the stack frame layout as appropriate for the
function's calling convention and insert prologue and epilogue code.

The default implementation is not useful, each target ISA will need to
override this function.
2017-08-03 13:48:30 -07:00
Jakob Stoklund Olesen
f82004e3c0 Move the stack layout computation into its own module.
This is trying to keep algorithms out if the ir module which deals with
the intermediate representation.

Also give the layout_stack() function a Result return value so it can
report a soft error when the stack frame is too large instead of
asserting. Since local variables can be arbitrarily large, it is easy
enough to overflow the stack with even a small function.
2017-08-03 13:31:58 -07:00
Jakob Stoklund Olesen
7f3b807597 Add a calling convention to all function signatures.
A CallConv enum on every function signature makes it possible to
generate calls to functions with different calling conventions within
the same ISA / within a single function.

The calling conventions also serve as a way of customizing Cretonne's
behavior when embedded inside a VM. As an example, the SpiderWASM
calling convention is used to compile WebAssembly functions that run
inside the SpiderMonkey virtual machine.

All function signatures must have a calling convention at the end, so
this changes the textual IL syntax.

Before:

    sig1 = signature(i32, f64) -> f64

After

    sig1 = (i32, f64) -> f64 native
    sig2 = (i32) spiderwasm

When printing functions, the signature goes after the return types:

    function %r1() -> i32, f32 spiderwasm {
    ebb1:
        ...
    }

In the parser, this calling convention is optional and defaults to
"native". This is mostly to avoid updating all the existing test cases
under filetests/. When printing a function, the calling convention is
always included, including for "native" functions.
2017-08-03 11:40:24 -07:00
Aleksey Kuznetsov
bf1820587c Apply conditional compilation of isa targets 2017-08-03 06:28:16 -07:00
Aleksey Kuznetsov
bf5edd5c71 Implement conditional compilation configuration in build.rs 2017-08-03 06:28:16 -07:00
Jakob Stoklund Olesen
534d1dd10d Compute the stack frame layout.
Add a StackSlots::layout() method which computes the total stack frame
size and assigns offsets to all spill slots and local variables so they
don't interfere with each other or with incoming or outgoing function
arguments.

Stack slots are given an ad hoc alignment that is the natural alignment
for power-of-two sized spill slots, up to the stack pointer alignment.
It is possible we need explicit stack slot alignment in the future, but
at least for spill slots, this scheme is likely to work for most ISAs.
2017-08-02 13:02:02 -07:00
Dan Gohman
f19ddb49a3 Don't use documentation-style comments inside a function body. (#131) 2017-08-02 11:19:16 -07:00
Dan Gohman
39488630f6 Avoid floating-point types in Ieee32::new and Ieee64::new. (#130)
* Avoid floating-point types in Ieee32::new and Ieee64::new.

This eliminates the need for unsafe code in code that uses Cretonne, a few
instances of unsafe code in Cretonne itself, and eliminates the only instance
of floating point in Cretonne.

* Rename new to with_bits, and new_from_float to with_float.
2017-08-02 11:05:49 -07:00
Jakob Stoklund Olesen
6dc5b3e608 Assign call arguments to stack slots.
When making an outgoing call, some arguments may have to be passed on
the stack. Allocate OutgoingArg stack slots for these arguments and
write them immediately before the outgoing call instruction.

Do the same for incoming function arguments on the stack, but use
IncomingArg stack slots instead. This was previously done in the
spiller, but we move it to the legalizer so it is done at the same time
as outgoing stack arguments.

These stack slot assignments are done in the legalizer before live
range analysis because the outgoing arguments usually are in different
SSSA values with their own short live ranges.
2017-08-01 13:54:47 -07:00
Jakob Stoklund Olesen
d536888725 Verify the location of outgoing call arguments.
Once a signature has been legalized, the arguments to any call using
that signature must be assigned to the proper stack locations. Outgoing
arguments that are passed on the stack must be assigned to matching
OutgoingArg stack slot locations.

Outgoing arguments that are passed in registers don't need to appear in
the correct registers until after register allocation.
2017-08-01 13:54:47 -07:00
Jakob Stoklund Olesen
c50a836a56 Keep track of OutgoingArg stack slots.
Stack slots for outgoing arguments can be reused between function calls.
Add a list of outgoing argument stack slots allocated so far, and
provide a `get_outgoing_arg()` method which will reuse any outgoing
stack slots with matching size and offset.
2017-08-01 13:54:47 -07:00
d1m0
9e3f4e9195 Cleanup for PR #123 (#129)
* Fix bextend semantics; Change smtlib.py to use z3 python bindings for query building instead of raw strings

* Forgot the mypy stubs for z3
2017-07-31 16:02:27 -07:00
Denis Merigoux
b74723cb68 Added Intel x86-64 encodings for 64bit loads and store instructions (#127)
* Added Intel x86-64 encodings for 64bit loads and store instructions

* Using GPR registers instead of ABCD for istore8 with REX prefix
Fixed testing of 64bit intel encoding

* Emit REX and REX-less encodings for optional REX prefix
Value renumbering in binary64.cton
2017-07-31 14:52:39 -07:00
Jakob Stoklund Olesen
be8331d0a0 Add Intel legalization for division and multiplication.
These operations need custom legalization in order to use Intel's div
and idiv instructions.
2017-07-28 16:41:59 -07:00
Jakob Stoklund Olesen
6609d7baf4 Try to depend only on the ir module being in scope.
Generated code should used qualified names assuming that `ir` is in
scope, not everything else.
2017-07-28 16:33:02 -07:00
Jakob Stoklund Olesen
1968ebad58 Evaluate instruction predicates during legalization.
The generated legalization code needs to evaluate any instruction
patterns on the input pattern being matched.

Emit predicate checking code inside the InstructionFormat pattern match
where all the instruction's immediate fields are available to the
predicate code.

Also make sure an `args` array is available for any type predicates to
evaluate correctly.
2017-07-28 15:22:53 -07:00
Jakob Stoklund Olesen
e2bf4f8981 Include bound typevars in the instruction predicate.
We already do this for the encoding tables, but the instruction
predicates computed by Apply.inst_predicate() did not include them.

Make sure we don't duplicate the type check in the Encoding constructor
when passed an Apply AST node.
2017-07-28 14:56:45 -07:00
Jakob Stoklund Olesen
9df0b09301 Add an inst.all_typevars() method.
Get all type variables controlling an instruction, whether it is
polymorphic or not.
2017-07-28 14:45:56 -07:00
Jakob Stoklund Olesen
dd5bbc298e Allow for multiple legalization patterns for the same opcode.
Each input pattern can have a predicate in addition to an opcode being
matched. When an opcode has multiple patterns, execute the first pattern
with a true predicate.

The predicates can be type checks or instruction predicates checking
immediate fields.
2017-07-28 13:54:25 -07:00
Jakob Stoklund Olesen
222ccae4b2 Support constant integers in AST expressions.
Make it possible to write AST nodes: iconst.i32(imm64(0)).
2017-07-28 13:54:25 -07:00
Dimo
a324d60ccc Cleanup, typechecking and documentation nits 2017-07-28 10:47:08 -07:00
Dimo
9767654dd7 Add semantics for several more iadd with carry; Add xform_correct() and doc cleanup 2017-07-28 10:47:08 -07:00
Dimo
c3092d680f Add smtlib.py 2017-07-28 10:47:08 -07:00
Dimo
59e204cec2 Fix broken test_elaborate tests after the moving of is_concrete/cleanup_concrete_rtl 2017-07-28 10:47:08 -07:00
Dimo
e346bd50c8 Add primitive bvult, bvzeroext; Add semantics for bextend, icmp (partial - only for <) iadd_cout 2017-07-28 10:47:08 -07:00
Dimo
3fd43fd006 Add Rtl.free_vars() 2017-07-28 10:47:08 -07:00
Dimo
ec9e9bd1ca cleanup_semantics() should remove repeated prim_from_bv(x) 2017-07-28 10:47:08 -07:00
Dimo
93b57a5209 Nit: Make elaborate return a new Rtl instead of modifying the existing rtl inplace 2017-07-28 10:47:08 -07:00
Dimo
80a42fdeaa Move apply() -> Xform.apply(); is_concrete_rtl() -> Rtl.is_concrete(); cleanup_concrete_rtl() -> Rtl.cleanup_concrete_rtl(). Documnetation nits in semantics.elaborate 2017-07-28 10:47:08 -07:00
Dimo
a92021ebce With multiple semantic transforms mentioning Enumerators, it may be possible for there not to be a substitution from the concrete rtl to some of the transforms. This is not an error - just a case where a given semantic transform doesnt apply. (e.g. icmp being described by different transforms with concrete intcc condition codes) 2017-07-28 10:47:08 -07:00
Dimo
a2b60108fd Fix up a couple of test changed by unifying control tv first 2017-07-28 10:47:08 -07:00
Dimo
7d1a9c7d81 When doing ti on a polymorphic definition first unify the control variable, then the rest. 2017-07-28 10:47:08 -07:00
Dimo
2387745847 bextend/breduce need constraints 2017-07-28 10:47:08 -07:00
Jakob Stoklund Olesen
b04a2c30d2 Return a function pointer from TargetIsa::encode().
Replace the isa::Legalize enumeration with a function pointer. This
allows an ISA to define its own specific legalization actions instead of
relying on the default two.

Generate a LEGALIZE_ACTIONS table for each ISA which contains
legalization function pointers indexed by the legalization codes that
are already in the encoding tables. Include this table in
isa/*/enc_tables.rs.

Give the `Encodings` iterator a reference to the action table and change
its `legalize()` method to return a function pointer instead of an
ISA-specific code.

The Result<> returned from TargetIsa::encode() no longer implements
Debug, so eliminate uses of unwrap and expect on that type.
2017-07-27 17:08:00 -07:00
Jakob Stoklund Olesen
1bbc06e2d6 Assign legalization codes early.
Make sure legalization codes are assigned by TargetIsa::finish() such
that they can be accessed by multiple gen_* drivers.
2017-07-27 17:08:00 -07:00
Denis Merigoux
f6af7be205 Bugfix: encode function wasn't calling legalize function properly 2017-07-27 16:49:09 -07:00
Jakob Stoklund Olesen
ebf5c80959 Add Intel encodings for more conversion instructions.
The following instructions have simple encodings:

- bitcast.f32.i32
- bitcast.i32.f32
- bitcast.f64.i64
- bitcast.i64.f64
- fpromote.f64.f32
- fdemote.f32.f64

Also add helper functions enc_flt() and enc_i32_i64 to
intel.encodings.py for generating the common set of encodings for an
instruction: I32, I64 w/REX, I64 w/o REX.
2017-07-27 11:08:41 -07:00
Jakob Stoklund Olesen
06bab60fcc Add support for type variable wildcards in bound instructions.
Instructions will multiple type variables can now use `any` to indicate
encodings that don't care about the value of a secondary type variable:

    ishl.i32.any instead of ishl.i32.i32

This is only allowed for secondary type variables (which are converted
to instruction predicates). The controlling type variable must still be
fully specified because it is used to key the encoding tables.
2017-07-26 14:55:26 -07:00
Jakob Stoklund Olesen
ac830e0446 Remove the number field from the PredNode union type.
Predicate numbers are available in the maps
isa.settings.predicate_number and isa.instp_number instead.

Like the name field, predicate numbers don't interact well with
unique_pred().
2017-07-26 11:06:43 -07:00
Jakob Stoklund Olesen
84fffa79f6 Remove the name field from the PredNode union type.
The name of a predicate was only ever used for named settings that are
computed as a boolean expression of other settings.

- Record the names of these settings in named_predicates instead.
- Remove the name field from all predicates.

Named predicates does not interact well with the interning of predicates
through isa.unique_pred().
2017-07-26 10:14:26 -07:00