Commit Graph

2345 Commits

Author SHA1 Message Date
Ryan Macnak 9d93909715 [vm, arm64] Use a branch instead of two predicated moves for loading cids.
Two instructions shorter.

JIT:
MegaFieldHasGetterOnceIndirect (Odroid-C2) 15.97% (0.8 noise)
        MegaOnlyOverriddenOnce (Odroid-C2) 18.96% (0.9 noise)
MegaOnlyOverriddenOnceIndirect (Odroid-C2) 16.94% (1.0 noise)
                  MegaEquality (Odroid-C2) 5.729% (1.2 noise)
        MegaFieldHasGetterOnce (Odroid-C2) 26.56% (1.2 noise)

AOT:
MegaOverriddenEvery2ndIndirect (Odroid-C2) 2.872% (0.4 noise)
             MegaFieldIndirect (Odroid-C2) 3.856% (0.4 noise)
   MegaNeverOverriddenIndirect (Odroid-C2) 5.658% (0.5 noise)
           MegaNeverOverridden (Odroid-C2) 4.278% (0.5 noise)
        MegaOnlyOverriddenOnce (Odroid-C2) 4.966% (0.6 noise)
                     MegaField (Odroid-C2) 6.310% (0.6 noise)
MegaOnlyOverriddenOnceIndirect (Odroid-C2) 6.355% (0.8 noise)

Change-Id: I66c1d3d5b04bfdada0b09bd4bd9e99d19f8eaa56
Reviewed-on: https://dart-review.googlesource.com/16692
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2017-10-26 19:50:36 +00:00
Vyacheslav Egorov 2c97d724df [VM, JIT] Lower CloneContext into AllocateUninitializedContext.
CloneContext is implemented as a runtime call so it is considerably slower
than AllocateContext which leads to performance issues in loops that capture
iteration variables in for loops.

Lowering CloneContext into AllocateUninitializedContext and a sequence of
explicit load&store instructions both improves the performance by avoiding
the runtime call and also makes CloneContext semantics exposed to store-load
forwarding and allocation sinking.

PutIfAbsent benchmark from issue #31113 is improved by 5x, while 
ForInGeneratedLoop benchmark is improved by 8x.

Bug: https://github.com/dart-lang/sdk/issues/31113
Change-Id: I03fdede75f1a85fda92487aa8f9307ce06f23903
Reviewed-on: https://dart-review.googlesource.com/16280
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2017-10-25 11:09:29 +00:00
Samir Jindel 55eb75d56f [kernel] Delay type finalization when parsing function types.
Currently, the Kernel FE doesn't set up parent pointers correctly for
signature function types. This prevents type parameters on generic
function types from being finalized correctly. In addition, finalization
of generic interface types within a generic function type can crash if they
reference not-yet-finalized type parameters of the enclosing function type.

This review solves both issues. Several failing tests pass again, although
more thorough testing is blocked on Github issue #31213 (nested generic function
types crashing in Fasta).

Bug:
Change-Id: Ib5ee6b2566492e3fd6688fe5a6b6976692562ea1
Reviewed-on: https://dart-review.googlesource.com/16360
Reviewed-by: Régis Crelier <regis@google.com>
2017-10-25 10:36:57 +00:00
Samir Jindel 6b64aa8943 [kernel] Always disable reified generic functions in the Kernel FE.
Currently, we have some tests that run with reified generic functions ON and
some with it OFF. However, this causes inconsistencies when running the Kernel
FE from snapshot in the VM, since the VM requires that the flag be consistent
with the snapshot. Our solution is to turn the reified generic functions flag
into a per-isolate flag, which is always disabled in the Kernel FE's isolate.

Bug:
Change-Id: Ia91e9f0ff5fc059edf4bdbd79ef14abb288b4a49
Reviewed-on: https://dart-review.googlesource.com/16020
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-24 15:21:28 +00:00
Kasper Lund 1db8615e29 Avoid just truncating to the nearby int in double.hashCode.
Preserves the property that doubles and ints that are equal
share the same hash code, but gives different doubles a much
higher chance of having different hash codes.

BUG=https://github.com/dart-lang/sdk/issues/2884

Change-Id: Ia97164087db568f26ffbbd6854ed9c19f81e9611
Reviewed-on: https://dart-review.googlesource.com/15140
Commit-Queue: Kasper Lund <kasperl@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-23 06:47:20 +00:00
Régis Crelier af32a05548 [VM] Use field name instead of parameter name in implicit setter type errors (fixes #30993).
Change-Id: Ib595e654d31cb27ed7c5497742e5f588fe8eaf80
Reviewed-on: https://dart-review.googlesource.com/15763
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2017-10-20 22:58:09 +00:00
Alexander Markov 841b1ad814 [VM] Improve performance of allocators on ARM in non-product mode
This CL improves performance of allocation statistic counters on ARM
by removing duplicated loads and increasing distance between dependent
loads. These statistic counters are part of allocator fast path in a
non-product mode.

This change improves performance of gestures/velocity_tracker_bench
Flutter micro-benchmark in 'flutter run --profile' mode:

Before: 3352 µs
After:  3156 µs (-5.8%)
(minimum of 5 runs)
Change-Id: Ic7998318d9ca3e7997379d0054faaf5b0b569bb6
Reviewed-on: https://dart-review.googlesource.com/15640
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2017-10-20 18:01:49 +00:00
Alexander Markov 55ff4a61c0 [VM, Compiler] Handle corner cases when optimizing IS using static types
This CL fixes optimization of 'x is T' using static (strong mode) types
in the following cases: T = Object, dynamic, Null or non-instantiated
generic type.

Issue: https://github.com/dart-lang/sdk/issues/30480
Change-Id: I6149cbdc2e4173f2ce18e7b0e019c1d44b728e19
Reviewed-on: https://dart-review.googlesource.com/14501
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2017-10-19 16:57:05 +00:00
Konstantin Shcheglov c3a76ed636 Move all documentation comments into metadata.
R=ahe@google.com, kmillikin@google.com, paulberry@google.com, sigmund@google.com

Bug:
Change-Id: I05382fe275e7a3a0f18128508d30fe1438adffc4
Reviewed-on: https://dart-review.googlesource.com/14623
Reviewed-by: Peter von der Ahé <ahe@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
2017-10-18 14:48:56 +00:00
Paul Berry dca8a9acf5 Make it possible to distinguish "as" checks that come from generic covariance.
Change-Id: Ie230e6ca3ae28a0f4a6faaf5cb559426de0d8a0e
Reviewed-on: https://dart-review.googlesource.com/14361
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-18 09:16:05 +00:00
Régis Crelier 269298fa8e [VM] Remove support for deprecated tear off syntax in the VM.
Change-Id: I2359bb18783cf21eab94001fe401f66c2ce680b7
Reviewed-on: https://dart-review.googlesource.com/14721
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2017-10-18 01:11:00 +00:00
Vyacheslav Egorov 826b48ee8a [VM] Clean up typing violations in the numerics implementation.
Bug: https://github.com/dart-lang/sdk/issues/31052
Change-Id: I93d7bca2ff627431f1a316bb01a5dada1b5f2354
Reviewed-on: https://dart-review.googlesource.com/14522
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
2017-10-17 21:00:24 +00:00
Siva Chandra 5558fc4370 Add a new VM object type KernelProgramInfo.
This new object points to program wide data like string offsets,
string data etc. It also holds an array of pointers to all Script
objects corresponding scripts in the program's source table.

This new object type is required for two reasons:
1. The Script objects now have a number of fields which point to
program wide data. All Script objects point to the same data in the
VM heap. By introducing an indirection via this new object, we reduce
the number of pointers in Script objects.
2. Lazy loading of VM objects - Kernel nodes of
entities like fields and functions have a field which point to the
source file in which they are defined. This entry is an index into
the program wide source table and helps in associating 
functions/fields with their actual source location. When lazy loading
functions and fields, the pre-loaded script objects in the
program's KernelProgramInfo help in associating the functions and
fields with the correct source script at load time.

Change-Id: Id863284ae7dd98b0832e5dfc115dabad1ed762d8
Reviewed-on: https://dart-review.googlesource.com/13920
Commit-Queue: Siva Chandra <sivachandra@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2017-10-17 16:57:12 +00:00
Martin Kustermann 5bf78540d7 Fix to "Clear flow graph type propagator information when winden-to-int32"
Clear out the *usages* of the widned instructions.

Change-Id: Id879d25e63e36312c051f13c8960dc9e2cc75e62
Reviewed-on: https://dart-review.googlesource.com/14201
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2017-10-17 10:12:20 +00:00
Paul Berry 9a0e962e67 Add a kernel flag to represent generic contravariance.
This flag indicates when a procedure's return type makes contravariant
use of a class type parameter.  The front end will have to insert "as"
checks at any call sites that refer to such a procedure as their
interface target.  Placing the flag on the procedure will allow the
front end to determine whether the check is needed once, at the same
time as it's determining the need for covariant parameter checks,
rather than when compiling individual call sites.

Once this lands I will follow up with CLs that cause the front end to
set the flag appropriately, and to generate the necessary "as" checks.

Change-Id: I989fc702bc233384eb5ea8cd630c8efd384ab248
Reviewed-on: https://dart-review.googlesource.com/14365
Reviewed-by: Samir Jindel <sjindel@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2017-10-17 05:24:21 +00:00
Samir Jindel dd0d299dcb [kernel] Un-revert support for generic function types and removing type erasure.
Change-Id: I8032e4622a0756199528a61fdb59f3d0ec132d1f
Reviewed-on: https://dart-review.googlesource.com/14202
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2017-10-16 23:17:09 +00:00
Samir Jindel dcf48efa23 [kernel] Un-revert support for generic closures in VM's kernel frontend.
Change-Id: I09dbcfdb13600fe694863db628b379bcf1f56684
Reviewed-on: https://dart-review.googlesource.com/14200
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2017-10-16 22:27:03 +00:00
Régis Crelier 390c80234a [VM generic functions] Properly instantiate generic signatures by providing the
number of free function type parameters.
Add test and mark status files.

Change-Id: I081de7674693c5ac2071a33948d25aadfc65f4ae
Reviewed-on: https://dart-review.googlesource.com/13901
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2017-10-16 21:57:05 +00:00
Alexander Markov c9515f8745 [VM, Compiler] recognize more operations using static types
In --experimental-strong-mode:
* Handle more operations and combinations of input types.
* Provide a more accurate initial type for Phi instructions
  using type of a local variable.

Issue: https://github.com/dart-lang/sdk/issues/30480
Change-Id: Id9d991b1104b7c3fa43ed117106898ba448062cc
Reviewed-on: https://dart-review.googlesource.com/13900
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-16 21:23:37 +00:00
Martin Kustermann 8dca2f344c Clear flow graph type propagator information when winden-to-int32
The CL [0] caused a bug since it was not safe to re-use type propagation
information after certain optimizations.  The winden-to-int32 is one
such optimization we found and we'll for now clear out the type
information on use sites explicitly after doing the widening.

(Hopefully there are no other optimizations causing the type propagation
 information to be no longer up-to-date.)

[0] https://github.com/dart-lang/sdk/commit/3cc0cea37e56bc5c590905f2da4bc5d9db9d73e6


Fixes https://github.com/dart-lang/sdk/issues/31114

Change-Id: I4c2ead9571c4007e8dbef3c0591cc836d71de35d
Reviewed-on: https://dart-review.googlesource.com/14060
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-16 18:23:47 +00:00
Régis Crelier ae94cbf3d6 Revert "[kernel] Support generic closures in VM's kernel frontend."
This reverts commit a273ff8314.

Revert "[kernel] Support generic function types in the VM's kernel frontend."

This reverts commit 2cac57da09.

Revert "[kernel] Completely remove type erasure."

This reverts commit 3ffacb3814.

Change-Id: I8fdd40a6a8f34911028353f48249fdd4bf7dba76
Reviewed-on: https://dart-review.googlesource.com/13622
Reviewed-by: Alan Knight <alanknight@google.com>
Commit-Queue: Alan Knight <alanknight@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2017-10-12 20:01:11 +00:00
Régis Crelier a73e6832fc [VM generic functions] Remove empty_type_arguments singleton.
This empty vector was added in https://codereview.chromium.org/2818273002/
to properly instantiate generic signatures.
Later on, the implementation of HasInstantiatedSignature() was improved in
https://codereview.chromium.org/2965743002/ making the empty vector unnecessary.
However, the implementation of InstantiateFrom() will also need improvement
as noted by the added TODO.

Change-Id: I042a57b643390c789620b04122084db19ec445ea
Reviewed-on: https://dart-review.googlesource.com/13400
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2017-10-12 15:21:52 +00:00
Samir Jindel 2cac57da09 [kernel] Support generic function types in the VM's kernel frontend.
Bug:
Change-Id: I3554562b409b35478437601f34e6263615409b38
Reviewed-on: https://dart-review.googlesource.com/12292
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2017-10-12 14:45:21 +00:00
Samir Jindel a273ff8314 [kernel] Support generic closures in VM's kernel frontend.
Change-Id: I0866971dc633c27df55811cba734d7cca0e849d4
Reviewed-on: https://dart-review.googlesource.com/12290
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2017-10-12 13:53:21 +00:00
Ryan Macnak 7ddc885b5c IA32: Visit the object reference used in optimized static calls.
Such a call site starts with a reference to a stub in the VM isolate, so the pointer was not recordered, but after it first runs it will be patched to a code object in the current isolate, which may move during compaction.

Bug: https://github.com/dart-lang/sdk/issues/30978
Change-Id: I3bf8fd1cf8884cbba9956254cad70f46e8b8cc00
Reviewed-on: https://dart-review.googlesource.com/12701
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2017-10-11 23:29:56 +00:00
Alexander Markov b9e61477ed [VM, Compiler] Enable inlining of static calls to recognized methods
Previously, a lot of recognized instance methods were inlined
only if they are called using InstanceCall instruction.
This CL enables inlining of such methods even if they are called
using StaticCall instruction. Such static calls may appear as the
result of devirtualization of instance calls.

Fixes slow-down of Flutter gestures/velocity_tracker benchmark when
devirtualization is enabled without --experimental-strong-mode.
(The slow-down was caused by inline heuristics rejecting to inline
several methods as their speculative bodies contain non-inlined
calls to recognized methods.)

Issue: https://github.com/dart-lang/sdk/issues/30480
Change-Id: Id0ec0669d0e3fe05aa708baec4a468892dbe7f8e
Reviewed-on: https://dart-review.googlesource.com/13200
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2017-10-11 22:32:47 +00:00
Alexander Markov 86fde60e4d [VM] Intrinsify Type.hashCode
This CL optimizes Type.hashCode similarly to String.hashCode, by
introducing intrinsic version of hashCode calculation which uses
hashcode stored in Type instance.

This is important for Flutter's .of pattern, which heavily uses
Maps with Type keys.

Results on Flutter stocks/build_bench.dart microbenchmark:
Before: 4906 µs
After:  4751 µs
(minimum of 5 runs, using tip of Flutter and Flutter engine)

Issue: https://github.com/dart-lang/sdk/issues/31011
Issue: https://github.com/flutter/flutter/issues/11572
Change-Id: Ifbaf721050007db49bbd969dc669d070f4ce839e
Reviewed-on: https://dart-review.googlesource.com/12622
Reviewed-by: Zach Anderson <zra@google.com>
2017-10-10 23:46:09 +00:00
Ryan Macnak 775f2054e1 [vm] Reduce duplication around EmitCallsiteMetadata.
Change-Id: I9c28ddd6104381902321e8b2788d70c4a63ce21a
Reviewed-on: https://dart-review.googlesource.com/12845
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2017-10-10 23:00:30 +00:00
Alexander Markov 14f6276945 [Kernel, VM] Add null checking to devirtualization
Devirtualization optimization now adds metadata to kernel AST instead
of transforming nodes to Direct* ones. The direct call metadata
provides information about checking receiver for null, while
Direct* kernel nodes do not support null checking.

VM's kernel binary loader is extended to extract arbitrary metadata
from kernel binaries and keep it for flow graph builder.
Kernel flow graph builder is extended to take direct call metadata
into account and generate CheckNull/StaticCall instructions
for devirtualized PropertyGet, PropertySet and MethodInvocation nodes.

Issue: https://github.com/dart-lang/sdk/issues/30480
Change-Id: I57f56fbf4a8981d33b1571c0d93105cf8ca71d76
Reviewed-on: https://dart-review.googlesource.com/12260
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-10 00:50:31 +00:00
Siva Chandra bf096c2bb4 Copy library specific kernel binary data to VM heap.
Before this change, each function and field had its own kernel data blob
in the VM heap. With this change, the entire kernel data of a library is
stored as one single blob in the VM heap. Functions and fields store an
offset which points to the kernel data, specific to them, in that single
blob.

The pointer to the kernel data for a library is saved in two places:
1. With the library objects themselves.
2. With all the patch classes of the library.
3. With the patch classes created during hot reload.

Change-Id: Ie03e738c4d20f16056a5ef04341b75506fda9c60
Bug:
Reviewed-on: https://dart-review.googlesource.com/6601
Commit-Queue: Siva Chandra <sivachandra@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2017-10-09 15:03:15 +00:00
Vyacheslav Egorov cc4e76664f [VM] Relax kernel::StreamingConstantEvaluator::IsAllowedToEvaluate()
When precompiling we might trigger optimizing compilation eagerly
so constant evaluation did not have a chance to run.

It is totally fine though because precompiler does not use
background thread.

Bug:
Change-Id: I6e889284d9ef9be8b09c6f4fe7695c82a78bcee4
Reviewed-on: https://dart-review.googlesource.com/12280
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2017-10-08 17:46:14 +00:00
Vyacheslav Egorov 552d09715d [VM] Cleanup SIMD related IL instructions.
This CL unifies 31 diverse Simd instructions into a single flexible SimdOp instruction.

These instructions were not different enough to warrant being implemented 
as separate IL instructions. The separation did not bring any benefit but
instead we payed the price with considerable amounts of duplicated code 
across the pipeline.

Main motivation for this refactoring is to reduce the surface of our IL.

Bug:
Change-Id: Ie8e39fecd2a51cb8edffdfe9c22e76835f912a9b
Reviewed-on: https://dart-review.googlesource.com/10120
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
2017-10-07 13:25:13 +00:00
Vyacheslav Egorov 05a28ab557 [VM] Introduce new way to define instruction backends (Reland).
Rewrite most SIMD instructions on ARM using this new way.

Our current way for defining instruction backends -- a pair of two virtual
methods called MakeLocationSummary and EmitNativeCode, leads to unnecessary
duplicated and verbose code. Code generation happens in three steps:

1. For each instruction in the graph MakeLocationSummary is called to
constructing a location summary object encoding register allocation constraints;
2. When all register constraints are collected a register allocation is performed
and results are filled back into the location summaries;
3. For each instruction in the graph EmitNativeCode is called. It unpacks
location summary attached to the instruction into actual machine registers and
emits native code.

There is usually a lot of duplication between declaring register constraints in
MLS and unpacking them in ENC which this CL is trying to remove.

The new way is centered on the concept of an *emitter function* which encodes
in its signature register constraints for a particular instruction.

We use a combination of templates and macroses to enable writing

    DEFINE_BACKEND(BinaryFloat32x4Op,
                   (QRegister result, QRegister left, QRegister right)) {
      // ...
    }

Instead of

    LocationSummary* BinaryFloat32x4OpInstr::MakeLocationSummary(Zone* zone,
                                                                 bool opt) const {
      const intptr_t kNumInputs = 2;
      const intptr_t kNumTemps = 0;
      LocationSummary* summary = new (zone)
          LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
      summary->set_in(0, Location::RequiresFpuRegister());
      summary->set_in(1, Location::RequiresFpuRegister());
      summary->set_out(0, Location::RequiresFpuRegister());
      return summary;
    }

    void BinaryFloat32x4OpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
      const QRegister left = locs()->in(0).fpu_reg();
      const QRegister right = locs()->in(1).fpu_reg();
      const QRegister result = locs()->out(0).fpu_reg();
      // ...
    }

This change also introduces a new, more handy way to work with S/D components of QRegisters, QRegister_ wrapper type.

Bug: https://github.com/dart-lang/sdk/issues/30949
Change-Id: I7bb0fc9672c89acc3d3d9b5e9859ae5a5471f420
Reviewed-on: https://dart-review.googlesource.com/11820
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2017-10-06 11:48:02 +00:00
William Hesse 6043dbb6d8 Revert "[VM] Introduce new way to define instruction backends."
This reverts commit 04aa2b0186.

Reason for revert: Compilation is failing on some Windows builders.  It may be the version of MSVC running on those machines that makes the difference.  But I think we need to revert until we figure it out.  The error is "runtime\vm\compiler\backend\locations_helpers_test.cc(111): error C2466: cannot allocate an array of constant size 0"

Original change's description:
> [VM] Introduce new way to define instruction backends.
> 
> Rewrite most SIMD instructions on ARM using this new way.
> 
> Our current way for defining instruction backends -- a pair of two virtual
> methods called MakeLocationSummary and EmitNativeCode, leads to unnecessary
> duplicated and verbose code. Code generation happens in three steps:
> 
> 1. For each instruction in the graph MakeLocationSummary is called to
> constructing a location summary object encoding register allocation constraints;
> 2. When all register constraints are collected a register allocation is performed
> and results are filled back into the location summaries;
> 3. For each instruction in the graph EmitNativeCode is called. It unpacks
> location summary attached to the instruction into actual machine registers and
> emits native code.
> 
> There is usually a lot of duplication between declaring register constraints in
> MLS and unpacking them in ENC which this CL is trying to remove.
> 
> The new way is centered on the concept of an *emitter function* which encodes
> in its signature register constraints for a particular instruction.
> 
> We use a combination of templates and macroses to enable writing
> 
>     DEFINE_BACKEND(BinaryFloat32x4Op,
>                    (QRegister result, QRegister left, QRegister right)) {
>       // ...
>     }
> 
> Instead of
> 
>     LocationSummary* BinaryFloat32x4OpInstr::MakeLocationSummary(Zone* zone,
>                                                                  bool opt) const {
>       const intptr_t kNumInputs = 2;
>       const intptr_t kNumTemps = 0;
>       LocationSummary* summary = new (zone)
>           LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
>       summary->set_in(0, Location::RequiresFpuRegister());
>       summary->set_in(1, Location::RequiresFpuRegister());
>       summary->set_out(0, Location::RequiresFpuRegister());
>       return summary;
>     }
> 
>     void BinaryFloat32x4OpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
>       const QRegister left = locs()->in(0).fpu_reg();
>       const QRegister right = locs()->in(1).fpu_reg();
>       const QRegister result = locs()->out(0).fpu_reg();
>       // ...
>     }
> 
> This change also introduces a new, more handy way to work with S/D components of QRegisters, QRegister_ wrapper type.
> 
> Bug: https://github.com/dart-lang/sdk/issues/30949
> Change-Id: I7f2beb106d1458facf4a3d75cae123e1fc25d8b5
> Reviewed-on: https://dart-review.googlesource.com/11507
> Reviewed-by: Zach Anderson <zra@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Commit-Queue: Vyacheslav Egorov <vegorov@google.com>

TBR=vegorov@google.com,alexmarkov@google.com,zra@google.com

Change-Id: Icfaabe58351a61d4eb50c4f9ac3bbd9677339fe7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/30949
Reviewed-on: https://dart-review.googlesource.com/11780
Reviewed-by: William Hesse <whesse@google.com>
2017-10-05 22:55:58 +00:00
Vyacheslav Egorov 04aa2b0186 [VM] Introduce new way to define instruction backends.
Rewrite most SIMD instructions on ARM using this new way.

Our current way for defining instruction backends -- a pair of two virtual
methods called MakeLocationSummary and EmitNativeCode, leads to unnecessary
duplicated and verbose code. Code generation happens in three steps:

1. For each instruction in the graph MakeLocationSummary is called to
constructing a location summary object encoding register allocation constraints;
2. When all register constraints are collected a register allocation is performed
and results are filled back into the location summaries;
3. For each instruction in the graph EmitNativeCode is called. It unpacks
location summary attached to the instruction into actual machine registers and
emits native code.

There is usually a lot of duplication between declaring register constraints in
MLS and unpacking them in ENC which this CL is trying to remove.

The new way is centered on the concept of an *emitter function* which encodes
in its signature register constraints for a particular instruction.

We use a combination of templates and macroses to enable writing

    DEFINE_BACKEND(BinaryFloat32x4Op,
                   (QRegister result, QRegister left, QRegister right)) {
      // ...
    }

Instead of

    LocationSummary* BinaryFloat32x4OpInstr::MakeLocationSummary(Zone* zone,
                                                                 bool opt) const {
      const intptr_t kNumInputs = 2;
      const intptr_t kNumTemps = 0;
      LocationSummary* summary = new (zone)
          LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall);
      summary->set_in(0, Location::RequiresFpuRegister());
      summary->set_in(1, Location::RequiresFpuRegister());
      summary->set_out(0, Location::RequiresFpuRegister());
      return summary;
    }

    void BinaryFloat32x4OpInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
      const QRegister left = locs()->in(0).fpu_reg();
      const QRegister right = locs()->in(1).fpu_reg();
      const QRegister result = locs()->out(0).fpu_reg();
      // ...
    }

This change also introduces a new, more handy way to work with S/D components of QRegisters, QRegister_ wrapper type.

Bug: https://github.com/dart-lang/sdk/issues/30949
Change-Id: I7f2beb106d1458facf4a3d75cae123e1fc25d8b5
Reviewed-on: https://dart-review.googlesource.com/11507
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
2017-10-05 22:31:43 +00:00
Jens Johansen 89644d89d2 [kernel] Add check to constant evaluator; pass script on error more often.
Change-Id: I655121953c7be2e6c3173a3c186339d31a9be7bc
Reviewed-on: https://dart-review.googlesource.com/11500
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-05 13:47:20 +00:00
Samir Jindel 3b347f94bc [kernel] Don't erase captured type parameters.
- We no longer erase type parameters of generic non-closures in the body of closures.
- We implement support for captured type parameters in the VM.

Bug:
Change-Id: I4f2f19301df1b44108ab2073332934d5d083e219
Reviewed-on: https://dart-review.googlesource.com/10942
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Kevin Millikin <kmillikin@google.com>
2017-10-05 12:45:36 +00:00
Jens Johansen 21f7da094b [kernel] When building type arguments interpret malformed type as dynamic
Bug:
Change-Id: I996bb912262414bc37fa25b4a335a993d0dce7f0
Reviewed-on: https://dart-review.googlesource.com/10041
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-05 12:26:20 +00:00
Jens Johansen 5fff3689d6 [kernel] Report error instead of crashing in constant evaluator.
Change-Id: I2c116cdc6add54194d0641631b3603313603c89e
Reviewed-on: https://dart-review.googlesource.com/11442
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-05 12:13:03 +00:00
Jens Johansen 54f44f2a18 [kernel] Assert not optimizing when running constant evaluator.
Previously we could hit an assert when for instance "42 ~/ 0"
was being optimized by the background compiler. The reason was
that we assert that we're on the "mutator thread" when allocating
memory (which is done as we're evaluating the code - and we're
trying to evaluate it again because evaluating it gives an error,
and errors aren't cached).

However, to create a test for this it would be better if we could
make it always crash, i.e. use something like
```
--optimization_counter_threshold=5 --no-background-compilation
```
to force an optimization, but still make it crash dispite the
optimization happening in mutator thread (because of
--no-background-compilation).

This CL propagates if we're optimizing to the kernel builder,
and in the constant builder further more asserts that we're not.

Additionally it introduces a test that shows the crash and fixes it.

Change-Id: Ic5412ec8b8a1dbc2ba323f0a02a51103a32fab5c
Reviewed-on: https://dart-review.googlesource.com/11380
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-05 11:48:10 +00:00
Vyacheslav Egorov 579b06ed4c [VM] Improve code patterns for various SIMD instructions on ia32/x64.
There are three types of changes in this CL:

* If there is a repeated per-component sequence of instruction, it is
replaced with a loop (e.g. see Float32x4ConstructorInstr);
* When accessing components in the spilled SIMD values don't use 
hardcoded constants but instead compute the offset from op_kind() 
(e.g. kFloat32x4WithZ accesses component with index kFloat32x4WithZ - kFloat32x4WithX = 2).
This allows to share code.
* Use setcc and arithmetic to materialize result of the comparison instead of branches;
* Use the fact that true and false are consecutive values in the Thread structure to convert
0/1 to true/false (see Int32x4GetFlagInstr)
* Extract Int32x4 components without spilling the whole SIMD value to the 
stack (see Int32x4GetFlagInstr).

This extracted from a larger refactoring CL: https://dart-review.googlesource.com/c/sdk/+/10120

Bug: https://github.com/dart-lang/sdk/issues/30949
Change-Id: Ic3757789a1ca621b267150133991fed5b85da633
Reviewed-on: https://dart-review.googlesource.com/11080
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2017-10-04 20:03:41 +00:00
Dmitry Stefantsov e7a29d8dfb [kernel] Add annotations for type parameters and variable declarations
Bug: http://dartbug.com/30035
Change-Id: Id122c2d6596bfa3505418ac2f65369a16965bce5
Reviewed-on: https://dart-review.googlesource.com/10300
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2017-10-04 10:29:23 +00:00
Régis Crelier 6cfac06ad2 [gardening] Fix recently added assembly test.
Change-Id: Ibe3b1ec0e8969159fb04dcd5eac67088e05d44e8
Reviewed-on: https://dart-review.googlesource.com/10821
Reviewed-by: Régis Crelier <regis@google.com>
2017-10-04 00:25:38 +00:00
Régis Crelier 11e5848846 [Kernel to flowgraph] Handle TODOs related to generic functions.
Change-Id: Ia6ad450d9f4a9ddc1940d42b844d97414e31d8b0
Reviewed-on: https://dart-review.googlesource.com/10206
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Samir Jindel <sjindel@google.com>
2017-10-03 16:48:39 +00:00
Lasse Reichstein Holst Nielsen 422bc2ebcc Make X64 assembler setcc operation accept more byte registers.
Bug: http://dartbug.com/30952
Change-Id: If33b439e056b777f723e4be20f892aa2ca64c1ee
Reviewed-on: https://dart-review.googlesource.com/10380
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-03 16:05:39 +00:00
Samir Jindel 6aa6f43815 [kernel] Pass type arguments to method calls.
Bug:
Change-Id: Ic9a29d7c0fc361a3ce9bff6a6ba648fc5a54c86c
Reviewed-on: https://dart-review.googlesource.com/10140
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
2017-10-03 15:20:30 +00:00
Samir Jindel 04c741c4cc [kernel] Pass type arguments to static function calls.
Bug:
Change-Id: If15d952feb782e2848faab36f42d03d818eb669c
Reviewed-on: https://dart-review.googlesource.com/10001
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2017-10-03 15:19:03 +00:00
Jens Johansen 2e75b6cce9 [kernel] Fix closure in for loop
In kernel the loop level wasn't set correctly for for loops, resulting
in the loop variable not always being fresh.

Examples:

```
  // Capture the loop variable, ensure we capture the right value.
  for (int i = 0; i < 10; i++) { if (i == 7) f = () => "i = $i"; }

  print(f());
  // There is only one instance of k. The captured variable continues to change.
  int k;
  for (k = 0; k < 10; k++) { if (k == 7) f = () => "k = $k"; }
  print(f());
```

resulted in
i = 10
k = 10

(i.e. it's wrong)

whereas

```
  // Capture the loop variable, ensure we capture the right value.
  for (int i = 0; i < 10; i++) { if (i == 7) { f = () => "i = $i"; } }
  print(f());
  {
    // There is only one instance of k. The captured variable continues to change.
    int k;
    for (k = 0; k < 10; k++) { if (k == 7) { f = () => "k = $k"; } }
    print(f());
  }
```

resultet in

i = 7
k = 10

(i.e. it's correct).

Now both examples produce the correct result.

Change-Id: I1fb4c888c6a0eaa690f62226e093508992b33ed4
Reviewed-on: https://dart-review.googlesource.com/9961
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-10-03 07:56:13 +00:00
Jens Johansen 471d92dfe4 [kernel] Get class type arguments correctly
Previously we got the length of the class' type_parameters().
Now instead we use the class' NumTypeArguments().

Bug:
Change-Id: I3807443765e4926efc17eba54d3bf4f50e8e30c6
Reviewed-on: https://dart-review.googlesource.com/9482
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2017-10-03 07:26:28 +00:00
Alexander Markov 087d61a2b4 [VM, Compiler] Remove duplication in UnboxInstr code generation
In this CL most of the code generation logic of UnboxInstr is unified
among architectures and moved to a platform-independent part.

In addition:
* Asm comment corrected for check null slow path.
* Non-instantiated generic types are eagerly converted to dynamic in
  type propagator.

Issue: https://github.com/dart-lang/sdk/issues/30480
Change-Id: Idcb2c67938e63ac79cf78d125451bd485247daad
Reviewed-on: https://dart-review.googlesource.com/9741
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2017-09-29 19:42:22 +00:00