Commit Graph

65 Commits

Author SHA1 Message Date
Vyacheslav Egorov a942c10bff [vm] Remove IL serializer.
Unfortunately, we never capitalized on having it (e.g. original plan was
to use it for writing tests, among other things) and continuing to
maintain it does not make sense.

TEST=ci

Change-Id: I02b2c35149298a295aa0de75916d48434d4a3ea9
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,pkg-linux-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190220
Auto-Submit: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-10 10:02:58 +00:00
Tess Strickland dadf3f56e8 [vm/compiler] Add flag for checking token positions.
When this flag is enabled, then the validity of real token positions are
checked in three places:

* FlowGraphChecker::VisitInstruction
* CodeSourceMapBuilder::BufferChangeLocation
* DescriptorList::AddDescriptor

The validity check ensures that, if the flow graph has an inlining
ID, that the instruction has an inlining ID and that any real token
position is a valid source offset for the appropriate script (found
via the inlining ID) by attempting to look up line and column.

This flag is disabled by default until existing issues with invalid
inlining IDs and token positions are resolved.

TEST=Enabled the flag manually to check that it caught invalid token
positions.

Bug: https://github.com/dart-lang/sdk/issues/44436

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try
Change-Id: I86439db3661d976ac4ea608d132e3277425615d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175641
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-17 12:19:43 +00:00
Tess Strickland ee8690563d [vm/compiler] Fix early return value from SerializeGraph.
The bodies provided to COMPILER_PASS macro uses are put into
a DoBody method of a generated class that has the following signature:

virtual bool DoBody(CompilerPassState* state);

CompilerState::Run uses this return value to decide whether to repeat a
given pass.

Previously, if no precompiler was provided in the compiler state, the
SerializeGraph compiler pass returned the compiler state. Since the
compiler state itself was not nullptr, it would implicitly convert to
true, meaning that CompilerState::Run would always run SerializeGraph
twice in this case. Since SerializeGraph was marked as an AOT pass,
though, this case never happened as the precompiler is always provided
for AOT passes.

In the meantime, others have used it as a basis for new compiler passes
with early returns that _could_ happen and then were confused by seeing
the pass happen twice in those cases. Fix the return value so it avoids
such confusion in the future.

Change-Id: I3a91e84abe2fbcc8437c64ce1b5b91f3d4808c65
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161784
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-09-07 11:44:13 +00:00
Tess Strickland fa03ee7782 [vm] Create a common base class for TextBuffer/ZoneTextBuffer.
Generally, methods that take a *TextBuffer pointer do not care how the
internal buffer is allocated, and so they could be used for either if
both were subclasses of a base class that contained the printing
methods.  This CL makes that base class, and now TextBuffer and
ZoneTextBuffer now share the exact same set of methods for printing to
the internal buffer.

Since the base class is in platform, this does mean dropping the
overload of AddString for Dart String objects that was part of
ZoneTextBuffer.  Instead, this CL just adds an intermediate call to
ToCString() for the small number of callers that used the overload,
keeping the printing interface the same for both.

In addition, one use of TextBuffer that then re-allocated the buffer
contents into the zone manually has been replaced with a ZoneTextBuffer
instead.

Change-Id: I438a085e7e20d55d93987fd7f36afd636f95955f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157741
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-08-07 18:09:35 +00:00
Aske Simon Christensen 00edd9756b [vm/aot] Delay allocation instructions until right before first use.
Moves AllocateObject and CreateArray instructions down to their
dominant use (use that dominates all other uses) when such a use exists
and the move is not hampered by environment uses (which can happen when
the allocation is inside a try block).

This improves write barrier elimination for inlined constructors, since
it moves the allocation after evaluation of the arguments. Any Dart
calls in an argument would disable elimination after it.

The optimization is particularly effective for Flutter Widget code,
since such code typically contains many nested constructor calls.

Reduces instructions size of Flutter Gallery by about 0.8%.

Change-Id: Ife30850c1a23f0986f85d42c1015f4caa7cf1fa6
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153602
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-07-30 15:57:33 +00:00
Alexander Markov 411272691c [vm/compiler] Add extra call specialization pass during inlining
After constant propagation is performed on the callee function body
during inlining, there are extra opportunities for specializing
calls. Unspecialized calls are not inlined, so it is important to
specialize those calls during inlining to open further opportunities
for inlining.

With this extra pass inliner is able to inline get:length after
specializing inlined List.generate constructor, and eliminate
bounds check from the initialization loop.

This change improves micro-benchmark creating 100,000 lists using

      List<int>.generate(1000, (int x) => x, growable: false);

in AOT mode on x64 from 308ms to 167ms.

This makes it on par with pre-NNBD fixed-size list initialization:

  var result = List<int>(1000);
  for (var i = 0; i < 1000; i++) {
    result[i] = i;
  }

In fact, after all optimizations final flow graph (and generated
code) for List.generate and explicit loop become very similar.

This change has no effect on Flutter gallery size in release mode.

Issue: https://github.com/dart-lang/sdk/issues/42283
Change-Id: I3566386608733226e1c11cb5d6892cd869e564d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151466
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-06-18 15:46:40 +00:00
Vyacheslav Egorov beb7114861 [vm/compiler] Add check to prevent inclusion of compiler headers into AOT runtime
This relands commit b0a71d364c

Cq-Include-Trybots: dart/try:vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-simarm-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: I1d32e5d0d44f4e422d188643b548ed81859f7d74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143807
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-04-17 13:11:08 +00:00
Alexander Aprelev c7861f309f Revert "[vm/compiler] Add check to prevent inclusion of compiler headers into AOT runtime"
This reverts commit b0a71d364c as it broke precomp builds.

Change-Id: Ieb776739b8d3e9ac74794e05fc20a793625e5f09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143865
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-04-16 23:51:09 +00:00
Vyacheslav Egorov b0a71d364c [vm/compiler] Add check to prevent inclusion of compiler headers into AOT runtime
#if defined(DART_PRECOMPILED_RUNTIME)
  #error "AOT runtime should not use compiler sources (including header files)"
  #endif  // defined(DART_PRECOMPILED_RUNTIME)

Remove #if defined(DART_PRECOMPILED_RUNTIME) from most compiler sources.

Change-Id: Id175c83fdbea38d9d5e1371ff433e3888f2afe8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143523
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-04-16 22:59:03 +00:00
Daco Harkes 55659b0372 [vm] Make our AOT pipeline work independent of the FLAG_precompiled_mode
Closes: https://github.com/dart-lang/sdk/issues/36521

Change-Id: I8f56d7bc9f3bfc7f4a6f0dcbee66f99838dde3cb
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-release-simarm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136622
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2020-03-25 11:58:20 +00:00
Alexander Markov 70e5532795 [vm] Optimize phis and branches more extensively
Remove phis which have redefinitions of the same value in the arguments:

  v1 = ...
  v2 = Redefinition(v1)
  v3 = phi(v1, v2)

Also eliminate redundant branches after DCE and merge blocks after
branches are eliminated.

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

Change-Id: I9d4e6c8ed356ab185fee85678e45841d82357403
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/139602
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-03-16 22:19:46 +00:00
Samir Jindel 4c6a2ab47c Re-land "[vm] Aggressive write-barrier elimination."
Three bugs were fixed:

1. BitVector::Equals was not fully fixed by the original CL.
2. We need to add old objects to the deferred marking queue during
   RememberLiveTemporaries().
3. The thread being scanned in RestoreWriteBarrierInvariant may not
   be scheduled, so we cannot use its store buffer block.

In addition, this changed uncovered another bug fixed in:
https://dart-review.googlesource.com/c/sdk/+/138960.

Original CL is in patchset 3.

This reverts commit 30a12a349e.

Change-Id: I36169b09563998ed5b3c3eac70ee0ebe78853e62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138920
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
2020-03-11 13:05:59 +00:00
Martin Kustermann 30a12a349e Revert "Re-land "[vm] Aggressive write-barrier elimination.""
This reverts commit eff1a9ff97.

Reason for revert:
  Causes flaky hits of RELEASE_ASSERT in marker.cc, see b/151131634.

Original change's description:
> Re-land "[vm] Aggressive write-barrier elimination."
> 
> The original revision is in Patchset 3.
> 
> Four bugs were fixed:
> 
> 1. JoinEntryInstr::SuccessorCount() is not the correct way to get the
>    number of successor blocks from the Join block;
>    JoinEntryInstr::last_instruction()->SuccessorCount() must be used
>    instead.
> 
> 2. BitVector::Equals() was non-deterministically returning 'false'
>    for equal vectors.
> 
> 3. All blocks need to be processed at least once during the Analysis
>    phase (not only in the SaveResults phase).
> 
> 4. We were not removing write barriers from StoreIndexed instructions,
>    even though we had support for it.
> 
> This reverts commit 7fd8ad5a2d.
> 
> Fixes https://github.com/dart-lang/sdk/issues/40780
> 
> Change-Id: I9650ec2c547ec49cf88ca0524e14f6c245621f6a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138086
> Commit-Queue: Samir Jindel <sjindel@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TBR=kustermann@google.com,rmacnak@google.com,sjindel@google.com

Change-Id: If9afd84465175fad2431405a97e9293c8bd5e476
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138808
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-03-10 10:15:30 +00:00
Samir Jindel eff1a9ff97 Re-land "[vm] Aggressive write-barrier elimination."
The original revision is in Patchset 3.

Four bugs were fixed:

1. JoinEntryInstr::SuccessorCount() is not the correct way to get the
   number of successor blocks from the Join block;
   JoinEntryInstr::last_instruction()->SuccessorCount() must be used
   instead.

2. BitVector::Equals() was non-deterministically returning 'false'
   for equal vectors.

3. All blocks need to be processed at least once during the Analysis
   phase (not only in the SaveResults phase).

4. We were not removing write barriers from StoreIndexed instructions,
   even though we had support for it.

This reverts commit 7fd8ad5a2d.

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

Change-Id: I9650ec2c547ec49cf88ca0524e14f6c245621f6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138086
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-03-09 14:37:27 +00:00
Ryan Macnak 7fd8ad5a2d Revert "[vm] Re-land aggressive write-barrier elimination."
This reverts commit c7d7552697.

Reason for revert: https://github.com/dart-lang/sdk/issues/40780

Original change's description:
> [vm] Re-land aggressive write-barrier elimination.
> 
> It incorrectly assumed that all stores in Dart code write to Instances.
> There is actually one exception, Contexts, which do not inherit from Instance.
> 
> I've added asserts to ensure this kind of bug cannot resurface.
> 
> The original change is in patchset 4.
> 
> Change-Id: Ic2d8d05e70a4de738eb9fb5980487b4f27111b8c
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136221
> Commit-Queue: Samir Jindel <sjindel@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TBR=kustermann@google.com,rmacnak@google.com,sjindel@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: I1891677b21560c7fc5a54a8eb800ef5850654402
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137290
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-02-26 02:18:25 +00:00
Samir Jindel c7d7552697 [vm] Re-land aggressive write-barrier elimination.
It incorrectly assumed that all stores in Dart code write to Instances.
There is actually one exception, Contexts, which do not inherit from Instance.

I've added asserts to ensure this kind of bug cannot resurface.

The original change is in patchset 4.

Change-Id: Ic2d8d05e70a4de738eb9fb5980487b4f27111b8c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136221
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-02-24 18:26:46 +00:00
Ben Konyi edc8bd7ec6 Revert "Re-land "[vm] Aggressive write-barrier elimination.""
Reason: Causing numerous DartFuzz crashes

This reverts commit 595038d19f.

Change-Id: I94e79cf1a3ddf9210a2929128cfc825bf47c92ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136260
Reviewed-by: Ben Konyi <bkonyi@google.com>
2020-02-18 17:12:21 +00:00
Samir Jindel 595038d19f Re-land "[vm] Aggressive write-barrier elimination."
DoubleToIntegerInstr was incorrectly marked with CanCallDart() = false.
Original CL is in patchset 3.
Fixes https://github.com/dart-lang/sdk/issues/40593

This reverts commit e7403c149a.

Change-Id: Ibb33fcf6480c820a10c968a2e22339afc5286035
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135310
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
2020-02-17 14:47:15 +00:00
Siva Annamalai e7403c149a Revert "[vm] Aggressive write-barrier elimination."
This reverts commit e5a22713b1.

Reason for revert: We are seeing some crashes on the bot see https://ci.chromium.org/p/dart/builders/ci.sandbox/vm-kernel-linux-debug-x64/8684

Original change's description:
> [vm] Aggressive write-barrier elimination.
> 
> Flutter Gallery code size total:
> -0.88% on ARM64
> -0.98% on ARM
> 
> Fixes https://github.com/dart-lang/sdk/issues/39164.
> 
> Change-Id: I8e65b1209ef1150bb73f3474506ebc97d7ab3685
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132003
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Samir Jindel <sjindel@google.com>

TBR=kustermann@google.com,rmacnak@google.com,sjindel@google.com

Change-Id: Ia93b43a423ee982aea550eb9fc24d34509db3dce
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/135421
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2020-02-12 00:53:05 +00:00
Samir Jindel e5a22713b1 [vm] Aggressive write-barrier elimination.
Flutter Gallery code size total:
-0.88% on ARM64
-0.98% on ARM

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

Change-Id: I8e65b1209ef1150bb73f3474506ebc97d7ab3685
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132003
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
2020-02-11 22:48:25 +00:00
Aske Simon Christensen 76c6282de6 [vm/aot] Use a global dispatch table for instance calls in AOT.
This is a Dart-tailored implementation of the "row-displacement
dispatch table" technique for closed-world instance calls:

All interface targets in the program are grouped into selectors such
that all targets that could potentially be called from the same call
site have the same selector (currently just grouped by name).

Each selector is assigned a selector offset such that offset + classid
is unique for all selector/classid combinations where the class
implements the selector.

At every instance call site that has an interface target (i.e. where
the static type of the receiver is not dynamic), the selector offset +
receiver classid is computed and used as index into a global table of
entry points.

If the receiver can be null (as determined by the front-end TFA and the
VM type propagation), a null check is inserted before the call.

An arguments descriptor is provided (only) for selectors that need it
(those which have type parameters or optional/named parameters).

The dispatch table calls don't need the monomorphic entry code, so for
functions that are only called via dispatch table calls (i.e. never
called dynamically), the monomorphic entry code is left out.


Some future improvements to the table dispatch implementation are
mentioned in https://github.com/dart-lang/sdk/issues/40188


The table dispatch flag is disabled by default in this commit. A
separate commit enables the flag.

Change-Id: Ic2911742b4a2c9a8d3bc7df60605454cbe4c0714
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/126648
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-02-03 11:04:15 +00:00
Aske Simon Christensen 1d026781b5 [vm] Fix some issues with round trip serialization.
- Update the flow graph and block order in the call specializer after
  round trip serialization. This ensures that compiler passes using the
  call specializer operate on the deserialized flow graph rather than
  the original one.

- Add 2 instead of 1 to the highest seen SSA temp index after
  deserialization to obtain the current SSA temp index. This makes room
  for values that expand into two SSA slots during some optimizations,
  e.g. unboxed integers on 32-bit platforms.

The changes expose an issue with early round-trip serialization,
described in https://github.com/dart-lang/sdk/issues/40120

Change-Id: I21e22fa1bab595fb5764ab72b599a3c663b4ff47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128405
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Teagan Strickland <sstrickl@google.com>
2020-01-14 17:17:25 +00:00
Alexander Markov f4e61eacfd [vm/compiler] Remove PushArgument instructions from IL up to AllocateRegisters
PushArgument instructions are removed from IL while it is constructed and
optimized. Before allocating registers, PushArgument instructions are
inserted immediately before call instructions. On ARM/ARM64 subsequent
PushArgument instructions are generated using store multiple (STM) / store
pair (STP) instructions which reduces size.

Flutter gallery in release mode after this CL and https://dart-review.googlesource.com/c/sdk/+/129324:
arm: instructions size -1.4%, total size -0.83%
arm64: instructions size -1.43%, total size -0.83%

Closes https://github.com/dart-lang/sdk/issues/39788
Closes https://github.com/dart-lang/sdk/issues/38354

Change-Id: I61493c72306c3ade4d9850e0dfc17e7e943a14c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128481
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-01-09 01:37:27 +00:00
Daco Harkes b8a679ab88 [vm] Fix IntConverter canonicalization
The check of not removing 64-bit->32-bit truncating conversions was in the wrong place.

Fixes: https://github.com/dart-lang/sdk/issues/39885
Fixes: https://github.com/flutter/flutter/issues/47454

Change-Id: Ic32a13cbf7ec622692cdca86b3237dae1c0f1cef
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129284
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-01-02 12:43:36 +00:00
Teagan Strickland 217e265b02 [vm/compiler] During DCE, remove PushArguments of non-live definitions.
In the current compiler pipeline, PushArgument instructions can
end up outliving the calls to which they are an argument in some
circumstances. For example, the PushArgument is left in the graph
if it also appears in the environments of interleaving instructions.

When the dead code eliminator calculates liveness of a definition,
it ignores appearances in PushArgument instructions. Instead, it
looks for uses of the definition either directly or via
PushArgument in the arguments of calls and environments of other
instructions in the graph. An separate pass run before DCE
removes environments from instructions, so a definition used only
in PushArguments that have outlived their calls is considered dead.

The current DCE removes dead definitions but leaves PushArgument
instructions be. For orphaned PushArguments of dead definitions,
this means after DCE they now reference definitions no longer in
the graph.

This change instead checks the definitions referenced by
PushArgument instructions for liveness. If a PushArgument
references a dead definition, then the DCE removes the PushArgument
instruction, as its call must have already been removed (else
the definition would still be live), and environments, and thus
environmental uses, have already been removed from the graph.

Bug: https://github.com/dart-lang/sdk/issues/39767
Change-Id: I74c8e92a0d93f2aae42f8ff6f06ee70899b2f794
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128403
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Teagan Strickland <sstrickl@google.com>
2019-12-13 18:15:04 +00:00
Alexander Markov ad1a26b90b Reland "[vm/compiler] Dead code elimination"
This is a reland of b69596bb1b

Original change's description:
> [vm/compiler] Dead code elimination
> 
> flutter_gallery total size -0.9% (arm), -0.77% (arm64)
> flutter_gallery instructions size -1.27% (arm), -1.11% (arm64)
> 
> Fixes https://github.com/dart-lang/sdk/issues/33414
> 
> Change-Id: I9de07ac866ba8a6bf3575df85b790e26a2753750
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127381
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>

Change-Id: Id53dddfe22af4d48673e30a3f66e63ed878523ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128010
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-12-11 19:23:48 +00:00
Alexander Markov 3a456fb3cc Revert "[vm/compiler] Dead code elimination"
This reverts commit b69596bb1b.

Reason for revert: failures on vm-kernel-precomp-win-release-x64 bot.

Original change's description:
> [vm/compiler] Dead code elimination
> 
> flutter_gallery total size -0.9% (arm), -0.77% (arm64)
> flutter_gallery instructions size -1.27% (arm), -1.11% (arm64)
> 
> Fixes https://github.com/dart-lang/sdk/issues/33414
> 
> Change-Id: I9de07ac866ba8a6bf3575df85b790e26a2753750
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127381
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>

TBR=vegorov@google.com,kustermann@google.com,rmacnak@google.com,alexmarkov@google.com,sjindel@google.com

Change-Id: I0bf0e27cc13b4d0708be19304e278977c7eb6558
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/128003
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2019-12-10 22:59:26 +00:00
Alexander Markov b69596bb1b [vm/compiler] Dead code elimination
flutter_gallery total size -0.9% (arm), -0.77% (arm64)
flutter_gallery instructions size -1.27% (arm), -1.11% (arm64)

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

Change-Id: I9de07ac866ba8a6bf3575df85b790e26a2753750
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127381
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2019-12-10 18:50:35 +00:00
Samir Jindel c7ac27bf50 [vm/ffi] Refactor and fix pipeline for force-optimized code.
Change-Id: I18429fcfe44065c73674c9a00977e222e5abb5de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/114513
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Samir Jindel <sjindel@google.com>
2019-08-27 11:06:53 +00:00
Samir Jindel 43417df9c7 [vm/ffi] Fix crashes on stacktraces and debugging with force-optimized frames.
Issue https://github.com/dart-lang/sdk/issues/37910

Change-Id: I76630fbc6733712c8709b782619a76190c70bfd5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113999
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-08-26 10:18:34 +00:00
Teagan Strickland ab54ea60e5 [vm/compiler] Add the framework for the IL deserializer.
This adds in a version of the IL deserializer that doesn't actually do
any deserialization yet.

However, it adds in a couple of compile passes that passes the FlowGraph
for compiled functions through the serializer and deserializer.  If the
deserialization step succeeds, then the FlowGraph stored in the
CompilerPassState is replaced with the new FlowGraph for the rest of the
compiler.

Also change the default zone handling in the FlowGraphSerializer to use
the zone for the current thread, instead of the zone stored in the
FlowGraph, so that it is appropriately affected by StackZone uses.

Bug: https://github.com/dart-lang/sdk/issues/36882
Change-Id: I8fa1c7af434f724ccec45ddb73263f84730af5b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113184
Commit-Queue: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
2019-08-26 08:58:23 +00:00
Teagan Strickland 812796ff3d [vm/compiler] Make BlockScheduler AllStatic.
The FlowGraph on which to run is available at each method call site, so
we don't need to store it.

This also avoids issues in the future if we ever rebuild the FlowGraph
entirely during compilation, since we won't be using a BlockScheduler
object that caches an older version of the FlowGraph.

Change-Id: I5653e1230131fbada3fe01cfa6c1ac37846fccb0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113024
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Teagan Strickland <sstrickl@google.com>
2019-08-14 10:52:14 +00:00
Teagan Strickland d44076efea [vm/compiler] Add S-expression layer to serializer.
Instead of hand-writing S-expression output in the methods used by the
serializer, just create an appropriate S-expression data structure (with
handling of extra info maps) that handles serialization.

Bug: https://github.com/dart-lang/sdk/issues/36882
Change-Id: I9b56827d7452271de4b32c0c01cc2e4c4bcc0367
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109706
Commit-Queue: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-07-26 09:09:18 +00:00
Teagan Strickland 2b3336b51e [vm/compiler] Initial IL serialization implementation.
Adds the --serialize_flow_graphs_to flag, which takes a
filename to which to serialize all compiled functions.
This flag is only active for the AOT compiler.

Bug: https://dartbug.com/36882
Change-Id: Ib7e328ad93373168806539f0a61ec0a07506a51d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107400
Commit-Queue: Teagan Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-07-17 09:11:15 +00:00
Aart Bik fa6fce61fa [dart/vm] Improved inlining methods and heuristics
Rationale:
Previous method cached graph information (instruction and call site
counts) on a per-function level, not accounting for potential
specializations. The improved method runs an extra constant folding
pass, and only caches per-function information for non-specialized
cases. As a result, we inling much better, see for example, the
added test as illustration.

Since we no longer cache for constants, compile-time may be increased
a bit due to the extra scan. In the long run we should consider
for common constant "situations" as the call site.

https://github.com/dart-lang/sdk/issues/36880

Change-Id: I19f007c7f1860ad0ea88fafb38695dc154189ad5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105460
Commit-Queue: Aart Bik <ajcbik@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-06-12 19:39:10 +00:00
Aart Bik b0727bd661 [dart/vm] enhanced graph checker
Rationale:
Refactored existing verify uses (with some overlap and some
additional checks) into the graph checker. Also added more
verification code and repaired some inconsistencies in IR
found by new checker. However, some checks are disabled with
a TODO, since the IR does not currently meet all the stricter
assumptions. Fixes will follow.

https://github.com/dart-lang/sdk/issues/36893
https://github.com/dart-lang/sdk/issues/36894
https://github.com/dart-lang/sdk/issues/36895
https://github.com/dart-lang/sdk/issues/36899

Change-Id: Ic0395208da38ecb6fc8ca2551efe819e6458a731
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101922
Commit-Queue: Aart Bik <ajcbik@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-05-13 17:47:11 +00:00
Aart Bik 7e0b680851 [dart/vm] minor test refactoring
Rationale:
Combining test and declaration. Also reorder
test for efficiency.

Change-Id: I6422c0c3fdf31fccd7b2a58f885bca2daa1e996c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102080
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
2019-05-10 15:50:40 +00:00
Martin Kustermann a3c19d4ffc [vm/compiler] Move inlining/intrinsics pipeline passes to compiler_pass.h
This makes it easier to maintain since all of them are in one place.

Change-Id: If55a9fb4a703aee36889c3fbdb8dded9f6233cb9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99467
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
2019-04-25 10:55:40 +00:00
Martin Kustermann dbfd00f44d [vm/compiler] Add new optimization pass which inlines typed data accesses
Based on the unified typed data layout, we can now inline accesses to
typed data interface classes if there are no 3rd party implementations
of those interfaces.

Example: If a receiver is of type Uint8List and we call `[]` or `[]=` we
will inline the byte access.

Instead of changing the existing inliner / call specializer we add this
as an extra pass: If the inliner / call specializer infer that the
receiver type is e.g. internal typed data then it will perform the
inlining itself using more optimized LoadIndexed instruction.

=> Only if those existing optimization passes have not been able to inline
   the access will we, later on in the compilation pipeline, run a
   specialized pass which will inline the accesses using LoadUntagged +
   LoadIndexed (which is slightly less efficient than using only LoadIndexed
   for internal typed data).

As a first step this is only done for AOT.

For ease of writing tests matching certain IR graphs this CL also adds a
IR pattern matcher.

Issue https://github.com/dart-lang/sdk/issues/35154

Cq-Include-Trybots: luci.dart.try:vm-canary-linux-debug-try, vm-dartkb-linux-debug-x64-try, vm-dartkb-linux-release-x64-try, vm-kernel-asan-linux-release-x64-try, vm-kernel-checked-linux-release-x64-try, vm-kernel-linux-debug-ia32-try, vm-kernel-linux-debug-simdbc64-try, vm-kernel-linux-debug-x64-try, vm-kernel-linux-product-x64-try, vm-kernel-linux-release-ia32-try, vm-kernel-linux-release-simarm-try, vm-kernel-linux-release-simarm64-try, vm-kernel-linux-release-simdbc64-try, vm-kernel-linux-release-x64-try, vm-kernel-optcounter-threshold-linux-release-ia32-try, vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-android-release-arm-try, vm-kernel-precomp-bare-linux-release-simarm-try, vm-kernel-precomp-bare-linux-release-simarm64-try, vm-kernel-precomp-bare-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-product-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-obfuscate-linux-release-x64-try, vm-kernel-precomp-win-release-simarm64-try, vm-kernel-precomp-win-release-x64-try, vm-kernel-reload-linux-debug-x64-try, vm-kernel-reload-linux-release-x64-try, vm-kernel-reload-rollback-linux-debug-x64-try, vm-kernel-reload-rollback-linux-release-x64-try, vm-kernel-win-debug-ia32-try, vm-kernel-win-debug-x64-try, vm-kernel-win-product-x64-try, vm-kernel-win-release-ia32-try, vm-kernel-win-release-x64-try

Change-Id: I5f2e01a55f46b473f64478b05679f65b9fd7c4c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98662
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2019-04-05 15:51:34 +00:00
Martin Kustermann 31d558c81c [vm/compiler] Add il_test_helper.h with support for running compilation pipelines for testing
The two existing places where IR is built are changed to use this new
helper. It supports running normal JIT/AOT passes as well as a
user-specified set of passes.

In order to allow vm/cc tests to make assertions about AOT pipeline this CL
enables the DART_PRECOMPILER define in run_vm_tests binary (similar to
gen_snapshot, run_vm_tests has now JIT and AOT support)

Change-Id: Ib51a024a81e0291e89d20860b8b9a2762611426c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/98482
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
2019-04-04 05:58:29 +00:00
Vyacheslav Egorov d23909802e [vm/compiler] Eliminate dead CatchBlockEntry Parameter-s
Parameter instructions inside CatchBlockEntry's initial definitions
are similar to Phi instructions: Parameter value at entry to the
catch would be taken from corresponding slot in the environment
attached to the instruction which threw the exception which is
being caught.

Thus similarly to Phi-s Parameter instructions can be redundant (if they
always evaluate to the same value - no matter where control arrives
from) or dead (if their value never reaches real instruction).

We already had an analysis to discover subset of redundant Parameter-s
which always evaluate to a constant value.

This CL introduces analysis to eliminate dead Parameter-s.

This should significantly reduce size of metadata generated for try/catch
and reduce spilling within functions with try/catch.

On Flutter Gallery: reduces Isolate part of snapshot by 15k (0.7%), Instructions
part is reduced by 2.7K (0.06%).

Change-Id: I345813e326152ca2ed2d4d5353bb64730d7545d4
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-android-release-arm-try, vm-kernel-precomp-bare-linux-release-simarm-try, vm-kernel-precomp-bare-linux-release-simarm64-try, vm-kernel-precomp-bare-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97110
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
2019-03-29 14:15:42 +00:00
Aart Bik 5823be65af [vm/compiler] Continued graph checker development (reland)
Rationale:
More assumption verified. Found some true issues.

Relands:
https://dart-review.googlesource.com/c/sdk/+/91702
with some fixes

https://github.com/dart-lang/sdk/issues/35803
https://github.com/dart-lang/sdk/issues/35819
https://github.com/dart-lang/sdk/issues/35848
https://github.com/dart-lang/sdk/issues/35849

Change-Id: I26101f8af3bd3fcdd5868d0882f8f096ab02b512
Reviewed-on: https://dart-review.googlesource.com/c/91945
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
2019-02-04 23:18:42 +00:00
Aart Bik b876d12f03 Revert "[vm/compiler] Continued graph checker development"
This reverts commit b01697ba5a.

Reason for revert: we have two check fails on bleeding edge
                    reverting this until we found the underlying issue

Original change's description:
> [vm/compiler] Continued graph checker development
> 
> Rationale:
> More assumption verified. Found some true issues.
> 
> Bug:
> https://github.com/dart-lang/sdk/issues/35803
> https://github.com/dart-lang/sdk/issues/35819
> 
> Change-Id: I5526f203925fb320aa504b4e142fcf987579300a
> Reviewed-on: https://dart-review.googlesource.com/c/91702
> Commit-Queue: Aart Bik <ajcbik@google.com>
> Reviewed-by: Aart Bik <ajcbik@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>

TBR=kustermann@google.com,alexmarkov@google.com,asiva@google.com,ajcbik@google.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Ifd7ee46c42d82312f762cac7021e6a55deac83fd
Reviewed-on: https://dart-review.googlesource.com/c/91943
Reviewed-by: Aart Bik <ajcbik@google.com>
Commit-Queue: Aart Bik <ajcbik@google.com>
2019-02-04 18:11:52 +00:00
Aart Bik b01697ba5a [vm/compiler] Continued graph checker development
Rationale:
More assumption verified. Found some true issues.

Bug:
https://github.com/dart-lang/sdk/issues/35803
https://github.com/dart-lang/sdk/issues/35819

Change-Id: I5526f203925fb320aa504b4e142fcf987579300a
Reviewed-on: https://dart-review.googlesource.com/c/91702
Commit-Queue: Aart Bik <ajcbik@google.com>
Reviewed-by: Aart Bik <ajcbik@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-02-01 19:14:27 +00:00
Aart Bik e02399da33 [vm/compiler] Introduce graph checker
Rationale:
This is a start with a graph checker that verifies
the consistency of the flow graph after each compiler
pass with the goal of detecting errors as early as
possible. The checks add overhead, so are only run
in debug mode. The objective is that all written
and unwritten assumptions on the flow graph that
are relatively easy to check will be converted
into actual code.
Change-Id: Iad9927d5b0fd87a43dc6a7369174d52761d89c9e
Reviewed-on: https://dart-review.googlesource.com/c/91143
Commit-Queue: Aart Bik <ajcbik@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-01-28 18:16:47 +00:00
Ryan Macnak 169331abb1 [vm] Misc timeline tweaks.
- Move compiler pass events to a new CompilerVerbose stream
 - Remove serialization phase events
 - Add class name to class finalization event (lost along with finalization events in recent cleanups of finalization)
 - Add event for kernel loading

Change-Id: Ie72bced978400ea174c1551c961baa55c691b019
Reviewed-on: https://dart-review.googlesource.com/c/90883
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-01-25 18:37:05 +00:00
Ryan Macnak 06a1e6e9e3 [vm] Enable timeline on Fuchsia even in product mode.
On Fuchsia, the timeline is accessed without involving the service isolate or vm-service.

Change-Id: Ia0d4e1ca252604e8fcef466a31e3d2a8b0912251
Reviewed-on: https://dart-review.googlesource.com/c/90100
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-01-18 00:06:10 +00:00
Ryan Macnak 07f95e7761 Revert "[vm] Enable timeline on Fuchsia even in product mode."
This reverts commit 3f7b371f2c.

Reason for revert: Some modes failing to find new constant?

Original change's description:
> [vm] Enable timeline on Fuchsia even in product mode.
> 
> On Fuchsia, the timeline is accessed without involving the service isolate or vm-service.
> 
> Change-Id: I0d2351dcadcfc47835732235e1b8fafa8212f883
> Reviewed-on: https://dart-review.googlesource.com/c/89880
> Reviewed-by: Zach Anderson <zra@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

TBR=rmacnak@google.com,alexmarkov@google.com,zra@google.com,asiva@google.com

Change-Id: Ic03a78d14821e0361d54587f1f7510bc9ebfef1c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/89942
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-01-17 00:39:39 +00:00
Ryan Macnak 3f7b371f2c [vm] Enable timeline on Fuchsia even in product mode.
On Fuchsia, the timeline is accessed without involving the service isolate or vm-service.

Change-Id: I0d2351dcadcfc47835732235e1b8fafa8212f883
Reviewed-on: https://dart-review.googlesource.com/c/89880
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-01-16 22:55:51 +00:00
Aart Bik aae0f7997d [vm/compiler] Express control dependence as data dependence.
Rationale:
This provides a more robust way of expressing control
dependences between bounds checks and their uses, while
still allowing for CSE and LICM where possible.
This also fixes the original bug that started this
whole redesign: invalid LICM of checkbound.

Note:
Deals with bounds check, null check still TBD.

Reland of:
https://dart-review.googlesource.com/c/sdk/+/85470

Mini design doc:
runtime/docs/compiler/data_dep_for_control_dep.md

https://github.com/dart-lang/sdk/issues/35139
https://github.com/dart-lang/sdk/issues/34684
https://github.com/dart-lang/sdk/issues/30633

Change-Id: I24b994344ed28c9f5fbf0ed033698be75448df1c
Reviewed-on: https://dart-review.googlesource.com/c/85720
Commit-Queue: Aart Bik <ajcbik@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-12-03 18:07:39 +00:00