Commit Graph

35 Commits

Author SHA1 Message Date
fschneider@google.com 8ad125f607 Optimize functions containing try-catch.
This is a first step towards fully optimizing try-catch-finally.

At a catch entry, all local variables and parameters are
expected at a fixed stack location. There is a list of
initial definitions at the catch entry block, similar to
the initial definitions at graph entry.

Inside every try-block there is a special prologue code before each
call (instruction that may throw) inside the try-block. This prologue
is similar to a parallel move instruction: It moves all locals+parameters
to the locations expected by the catch-entry block. The stack frame
is extended with the corresponding number of fixed slots right below
the normal spill slots.

Every function containing try-catch has additional compiler-
generated local variables to pass the context, the exception and
the stack trace.

Variable liveness analysis is adapted to treat locals inside try{} blocks
specially: Every call has an implicit LoadLocal of every local variable.
This CL uses a safe approximiation of liveness which can be optimized further.

Current restrictions which are planned for future CLs:
 * No inlining inside try-blocks.
 * No inlining of functions containing try-catch.
 * No try-finally yet.

R=kmillikin@google.com

Review URL: https://codereview.chromium.org//14682020

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22615 260f80e4-7a28-3924-810f-c04153c831b5
2013-05-13 10:33:24 +00:00
vegorov@google.com 2565ca222f Implement a variation of scalar replacement for non-escaping allocations.
AllocationSinking pass discovers non-escaping allocations that have no input uses other than uses in the stores into its own fields.

Every environment use of such allocation is replaced by a state snapshot (MaterializeObject instruction) that describes the state of each initialized field in the object. State snapshots are computed through an additional round of load-forwarding.

Once snapshots are computed allocations are removed from the graph.

MaterializeObject instructions are not compiled into native code but produce deoptimization instructions instead that describe how object should be materialized at deoptimization.

Deoptimization instructions now follow the following format:

[mat obj #1]...[mat obj #N][ret addr][... mat arguments ...][... real frames ...]

- the prefix describes each object to materialize on deopt via kMaterializeObject instruction;
- actual values that are needed for materialization are emited as a part of bottom-most stack frame. This is done to simplify implementation: they need to be discoverable by a GC during materialization phase. At the end of deoptimization they will be removed from the stack;
- normal stack slots can refer to materialized objects via kMaterializedObjectRef instruction.

Additionally this change contains fixes in load-forwarding that are needed to guarantee that all artificial LoadField instructions inserted during AllocationSinking are correctly replaced with actual values.

Limitations of the current implementation:

- can't eliminate allocations that flow into phis but otherwise don't actually escape;
- can't sink allocations out of loops;
- allocation with type arguments are not handled.

R=regis@google.com, srdjan@google.com, zra@google.com

Review URL: https://codereview.chromium.org//14935005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22485 260f80e4-7a28-3924-810f-c04153c831b5
2013-05-07 23:40:42 +00:00
vegorov@google.com 81ecaba321 Re-apply r20377.
Compute local variable liveness before translation to SSA.

Use it to remove dead values from deoptimization environments.

R=fschneider@google.com
BUG=

Review URL: https://codereview.chromium.org//14215006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@21439 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-15 11:53:50 +00:00
vegorov@google.com 4d4a91ac04 Fix bug in ParallelMoveResolver::EmitSwap: implement swaps of FPU spill slots.
Remove representation from location. Presence of representation in location encoding was violating the invariant that unequal locations must be disjoint (where equality for locations is defined in terms of bitwise equality of their encoding). This could lead ParallelMoveResolver to treat XMM1 containing unboxed double as unequal location to XMM1 containing unboxed mint, which is obviously incorrect.

For similar reason eliminate kFloat32x4StackSlot and kUint32x4StackSlot distinction is eliminated and both are replaced with kQuadStackSlot. Register allocator now guarantees that no kQuadStackSlot occupies the same space as any other kDoubleStackSlot. This also shrinks optimized stack when only doubles are used (but might lead to a higher stack utilization when a mixture of doubles and quads is used).

Implement allocation of scratch Cpu and Xmm registers for ParallelMoveResolver. This also allows to remove push(eax)/pop(eax) pairs when resolving memory-memory cycles on ia32.

BUG=dart:9710

Review URL: https://codereview.chromium.org//13801014

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@21148 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-09 12:23:46 +00:00
johnmccutchan@google.com 7e1450cb9b Flow graph SIMD changes
Review URL: https://codereview.chromium.org//13471013

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20945 260f80e4-7a28-3924-810f-c04153c831b5
2013-04-04 23:23:30 +00:00
vegorov@google.com 535ed8eb25 Revert "Compute local variable liveness before translation to SSA."
Attaching environments to branches on strict comparisons breaks pattern matching in the optimizer and regresses performance.

This reverts commit r20377.

TBR=kmillikin@google.com

Review URL: https://codereview.chromium.org//12827027

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20400 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-22 18:32:17 +00:00
vegorov@google.com 66ecd504f9 Compute local variable liveness before translation to SSA.
Use it to remove dead values from deoptimization environments.

R=kmillikin@google.com
BUG=

Review URL: https://codereview.chromium.org//12638040

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20377 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-22 12:33:42 +00:00
fschneider@google.com 86da5111ad Replace scalarlist optimizations and split external array loads into two IL instructions.
This CL removes optimized access for scalarlist, and only the new TypedData classes
are optimized. I changed the runtime libraries core and math to use typedData
instead of scalarlist (Uint16List is used in StringBuffer, Uint32List by Math.random).

Instead of using LoadIndexed for internal and external arrays,
split external loads into a load of the backing store and a load
of the element.

v3 <- LoadIndexed(v1, index)

becomes

v2 <- LoadUntagged(v1, ExternalTypedData::data_offset)
v3 <- LoadIndexed(v2, index);

For this I introduce two new representations in the IL:

 kUntagged (for values that hold a untagged pointer) and
 
 kNoRepresentation (for instructions accept any input
 representation)

Deoptimization does not need to know about kUntagged
since these values can never occur in the environment.

Also with this change:
* fix COMPILE_ASSERT and use it in one place.
* Cleanup IL printer output of deopt ids.
Review URL: https://codereview.chromium.org//12871010

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@20198 260f80e4-7a28-3924-810f-c04153c831b5
2013-03-19 12:06:23 +00:00
kmillikin@google.com 9ee9cfb78d Remove dead phis as soon as they are discovered.
Previously we removed dead phis late, in the register allocator.  This
change removes them as soon as they are discovered to be dead and packs the
phi array to squeeze out NULLs.  This speeds iteration but doesn't save
space because the phi array is zone-allocated.

The PhiIterator is used everywhere to iterate phis except a few places that
need to know the phi index (e.g., SSA construction, phi elimination).

R=vegorov@google.com

Review URL: https://codereview.chromium.org//12340108

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@19206 260f80e4-7a28-3924-810f-c04153c831b5
2013-02-28 08:25:58 +00:00
regis@google.com 912194a756 Fix vm code base so that it can be built for --arch=simarm (no snapshot yet).
Review URL: https://codereview.chromium.org//11956004

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@17246 260f80e4-7a28-3924-810f-c04153c831b5
2013-01-18 00:34:20 +00:00
vegorov@google.com 5402bf689d Heuristically predict interference on the back edge and use it to minimize number of register reshuffling which is especially expensive when cycles of XMM registers arise.
When allocating free register check if hint can potentially interfere on the back edge try ignoring hint and search for a better candidate.

Additionally fix handling of constants in the liveness analysis to accommodate constants used as immediates.

R=fschneider@google.com
BUG=

Review URL: https://codereview.chromium.org//11418135

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@15291 260f80e4-7a28-3924-810f-c04153c831b5
2012-11-23 16:04:34 +00:00
vegorov@google.com 7c8923b829 Try allocating loop phi into a register even if phi has only unconstrained uses but there are cheap eviction candidates: values that come into the loop and have only unconstrained uses in it.
When spilling a value inside the loop that has only unconstrained uses in this loop move spilling point outside of the loop.

This tweaks allow to minimize amount of memory moves on loop back edges.

R=fschneider@google.com
BUG=

Review URL: https://codereview.chromium.org//11361161

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14673 260f80e4-7a28-3924-810f-c04153c831b5
2012-11-08 02:23:41 +00:00
fschneider@google.com 6632f191c4 Support for unboxed 64-bit integer bitwise operations and equality on ia32.
This CL adds AND, OR, XOR and == operations on unboxed 64-bit integers
(aka. mints).

Unboxed mints are stored in xmm registers. Each xmm register location
has an additional bit to keep track of its value representation.

Unboxed mints are materialized on the heap on deoptmization in the same way as
unboxed doubles.

The SSE instructions used are available on all CPUs that support SSE 4.1.
Review URL: https://codereview.chromium.org//10968059

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@13112 260f80e4-7a28-3924-810f-c04153c831b5
2012-10-02 11:25:53 +00:00
vegorov@google.com 978ec58a5e Rematerialize constants instead of spilling them.
This also fixes the crash that occurs when we try to spill constant null at the graph entry.

R=srdjan@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10918006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11634 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-30 17:49:23 +00:00
kmillikin@google.com 8122966c80 Put live register bits in stackmaps.
Add a count of live registers to each stackmap and add bits describing the
registers.  This allows untagged values in general purpose registers at
safepoints.

R=vegorov@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10882055

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11595 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-30 10:20:26 +00:00
vegorov@google.com 264c4f6d1a Add support for XMM registers in SSA code generation pipeline.
Split BinaryDoubleOp into several instructions that manipulate unboxed doubles.

R=fschneider@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10875030

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@11313 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-24 14:45:42 +00:00
zerny@google.com 5cc78d2a33 Refactored FlowGraphBuilder into a separate FlowGraph representation.
R=kmillikin@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10857016

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10807 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-16 12:06:17 +00:00
vegorov@google.com fe291bf0fa Implement basic support for deferred slow path code with calls that save and restore live registers.
Use it to avoid spilling over stack-checks.

R=kmillikin@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10823308

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10639 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-14 12:47:42 +00:00
kmillikin@google.com 172ee045f3 Build and use stack maps in the SSA compiler.
Add a stack bitmap to the location summaries for calls that are GC
safepoints.  The bitmap covers the spill slots.  The register
allocator collects these bitmaps into a list and then marks live
pointer values during register allocation.  When emitting code for a
call, a heap-allocated stackmap is built.

BUG=

Review URL: https://chromiumcodereview.appspot.com//10831261

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10618 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-14 06:59:24 +00:00
vegorov@google.com 1cf5cc74aa Put PushArgument into the environment instead of raw values.
This allows to shorten live ranges and avoid spilling when PushArgument is the last real use of the value.

BUG=

Review URL: https://chromiumcodereview.appspot.com//10825282

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10508 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-10 14:28:02 +00:00
kmillikin@google.com 4a24120c8d Move all register allocator environment initialization into class Environment.
Move the register constraints and initial live ranges of environment values
out of the register allocator and into the environment class.

R=vegorov@google.com,srdjan@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10826184

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10342 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-07 15:53:02 +00:00
vegorov@google.com 4a24eb7ad8 Add hints when resolving phies and register constraints.
R=fschneider@google.com

Review URL: https://chromiumcodereview.appspot.com//10829218

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10333 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-07 11:55:42 +00:00
vegorov@google.com f07819adb2 Ensure that ia32 build passes all tests with --use-ssa on.
Bugs fixed in register allocator:

- incorrect assertions in SplitAt;
- allocation finger should not cache positions that are owned by a sibling after split;
- UpdateFreeUntil should allow evicting live range with vreg 0;
- values expected in fixed locations should not cause an interference at the instruction itself, they can be evicted if need arises;

Bug fixed in deoptimization:

- parallel move resolver uses push/pop to free a scratch register for memory to memory moves, when using it for deoptimization we need to ensure that those push/pops do not interfere with actual moves;

R=srdjan@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10824165

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10287 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-06 12:24:12 +00:00
fschneider@google.com 04fa2e3547 Refactor our IL instruction for static setters.
We do not need a separate IL instruction anymore. Instead I generate
a normal static call and save the result in a temporary local if it
is needed.
Review URL: https://chromiumcodereview.appspot.com//10825176

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10222 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-03 11:14:07 +00:00
vegorov@google.com b601fa02c7 When selecting an optimal position for SplitBetween(from, to) ensure:
- that loop and block structure is taken into account;
- that split sibling has proper interference with values incoming into instruction corresponding to the to position.

R=srdjan@google.com
BUG=4308

Review URL: https://chromiumcodereview.appspot.com//10850023

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10208 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-03 06:29:35 +00:00
vegorov@google.com abfb2bf67a Implement simple spill store elimination.
Values that are spilled somewhere during their life-time are spilled eagerly at their definiton.

Additionally improve liverange printing used for debugging purposes.

R=srdjan@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10828115

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10155 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-02 08:45:49 +00:00
fschneider@google.com 8eee3f1899 Eliminate unnecessary deoptimization environments.
This CL adds a CanOptimize predicate to every instruction. Before register
allocation there is a simple pass over the IR to remove environments from
instruction that never deoptmize. This reduces the number of uses and shortens
live ranges of values resulting in better code.
Review URL: https://chromiumcodereview.appspot.com//10829098

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10115 260f80e4-7a28-3924-810f-c04153c831b5
2012-08-01 12:09:10 +00:00
vegorov@google.com 79199170eb Revert instruction numbering scheme to an instruction start (2*k) - instruction end (2*k + 1) one. Current instruction numbering scheme does not capture interference between temporaries and inputs correctly which in rare cases causes allocation of the same register both to the temp and to the input register.
Allow live range splitting at every position.

Don't reuse phi-resolution parallel move for connecting live ranges or meeting register constraints, this might cause conflicts between moves.

Allow deoptimization with environments containing spilled values.

R=kmillikin@google.com
BUG=

Review URL: https://chromiumcodereview.appspot.com//10831070

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@10050 260f80e4-7a28-3924-810f-c04153c831b5
2012-07-31 11:16:51 +00:00
srdjan@google.com 67de9f1323 Some cleanups.
Review URL: https://chromiumcodereview.appspot.com//10806099

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9874 260f80e4-7a28-3924-810f-c04153c831b5
2012-07-25 00:25:00 +00:00
vegorov@google.com 16e25206d1 New linear scan allocator.
Review URL: https://chromiumcodereview.appspot.com//10800037

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9851 260f80e4-7a28-3924-810f-c04153c831b5
2012-07-24 16:01:54 +00:00
srdjan@google.com c490158706 Cleanups.
Review URL: https://chromiumcodereview.appspot.com//10809047

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9795 260f80e4-7a28-3924-810f-c04153c831b5
2012-07-20 23:42:23 +00:00
vegorov@google.com 1bd5a9b414 Skeleton of a linear scan register allocator.
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//10696151

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9563 260f80e4-7a28-3924-810f-c04153c831b5
2012-07-11 18:52:17 +00:00
vegorov@google.com 30288c500e Fix a bug in liveness analysis code and add more comments.
R=fschneider@google.com
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//10657044

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9106 260f80e4-7a28-3924-810f-c04153c831b5
2012-06-26 12:14:02 +00:00
vegorov@google.com 2f23dc4b60 Simple iterative liveness analysis over SSA.
R=fschneider@google.com
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//10666026

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9069 260f80e4-7a28-3924-810f-c04153c831b5
2012-06-25 17:07:16 +00:00
fschneider@google.com 63d4ad7d5f Add new files and data structures for the new register allocator.
This CL adds new files to hold the new register allocator and
adds a parallel-move instructions that will be used to insert
moves for register constraints, spills and phi-resolution.

No new functionality added yet.
Review URL: https://chromiumcodereview.appspot.com//10635020

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@9027 260f80e4-7a28-3924-810f-c04153c831b5
2012-06-22 10:59:06 +00:00