Commit Graph

4835 Commits

Author SHA1 Message Date
Asger Feldthaus 7127119f6d dart2js cps: Do GVN for all primitives except fast constants.
Previously, trivial primitives such as "x+1" would not be hoisted.
Only fast constants are considered trivial now.

This is mainly to enable other optimizations.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1573473003 .
2016-01-08 15:38:13 -08:00
Asger Feldthaus afd7a91da4 dart2js cps: Name labels uniquely within each method, not globally.
Apart from a slight code size benefit, this should also make the diff
more stable.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1575593002 .
2016-01-08 14:15:37 -08:00
Kevin Millikin 5aedac787a dart2js: Eliminate the JsIrBuilderVisitor.
Since there is only one subclass of IrBuilderVisitor, make IrBuilderVisitor
non-abstract and move all the subclass methods to it.

BUG=
R=asgerf@google.com

Review URL: https://codereview.chromium.org/1567403004 .
2016-01-08 13:07:16 -08:00
Asger Feldthaus 8eb030b419 dart2js cps: Fix for tear-off of noSuchMethod or toString on null.
Some optimizations would assume that null.toString and null.noSuchMethod
would throw because these selectors were not whitelisted as non-throwing.

BUG=

Review URL: https://codereview.chromium.org/1570813003 .
2016-01-08 12:49:59 -08:00
Stephen Adams aa85691ddd Specializations of instance methods have non-null receiver.
A null check is inserted before the inlined code.
This occasionally removes a few null checks at inlining sites within the inlinee.

R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1568103003 .
2016-01-08 11:59:19 -08:00
Stephen Adams 1c1a0196f3 Copy all fields of NullCheck
Failing to copy the condition and selector lead to an inlined check that should have been

   if (typeof v0 !== "number") return v0.$add;

becoming

   v0.toString;

R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1564423002 .
2016-01-08 11:14:10 -08:00
Asger Feldthaus 11c7ad4d6f dart2js cps: Compute intercepted classes in optimize_interceptors.
There was previously an optimization in type propagation that replaced
getInterceptor(x) with x, but this depends on the set of intercepted
classes (since null may or may not need interception).

That optimization is now handled at the use-site of the interceptor,
since each use knows if it needs null to be intercepted.

BUG=
R=kmillikin@google.com, sra@google.com

Review URL: https://codereview.chromium.org/1571433002 .
2016-01-08 10:06:09 -08:00
Asger Feldthaus c59ef7d792 dart2js cps: Copy calling convention for InvokeMethodDirectly.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1562253003 .
2016-01-07 12:06:31 -08:00
Stephen Adams 0ed95c7737 Use propagated type of receiver to determine return type, not type-inference type.
The type-inference result is missing for some calls and might be less precise since type propagation happens after some simplification.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1566653004 .
2016-01-07 10:59:08 -08:00
Stephen Adams ac0d8dbd81 Fix null receiver guard on uncached path.
We has two copies of the inlining preparation code, so I put it in a local function.

This fixes some of the errant .toString guards but not all.

BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1561953005 .
2016-01-07 10:22:40 -08:00
Johnni Winther c6f0d75d81 Specialize message for parts as entry point
BUG=
R=sigurdm@google.com

Review URL: https://codereview.chromium.org/1564803002.
2016-01-07 09:50:49 +01:00
Asger Feldthaus 33b1d52057 Improve null-check elimination and change backward traversal strategy.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1569593002 .
2016-01-06 17:25:39 -08:00
Asger Feldthaus d2a6980c1c dart2js cps: Generate increment and compound operators.
Expressions like `i = i + E` now become `i += E` or `++i` if E=1.

The same applies for field and index access.

BUG=
R=sigmund@google.com, sra@google.com

Review URL: https://codereview.chromium.org/1562893002 .
2016-01-06 16:56:33 -08:00
Asger Feldthaus eadb59e4c1 dart2js cps: Eliminate unary string concatenation.
BUG=
R=kmillikin@google.com

Review URL: https://codereview.chromium.org/1563983002 .
2016-01-06 16:18:00 -08:00
Kevin Millikin 97b88e4ee7 dart2js: Do not inline when try is seen.
Do not inline in functions containing try, do not inline functions
containing try.  V8 does not optimize functions containing try, so
inlining in such functions or inlining such functions will make
potentially optimizable code become unoptimizable.

This repairs a large performance regression on the Angular 2 change
detection benchmarks.

R=sra@google.com
BUG=

Review URL: https://codereview.chromium.org/1554083002 .
2016-01-06 23:24:19 +01:00
Stephen Adams 55e8ae0e10 Copier should copy InvokeMethod calling convention
R=asgerf@google.com

Review URL: https://codereview.chromium.org/1564713002 .
2016-01-06 13:07:11 -08:00
Sigmund Cherem e2623f1aea cpsir: add support for deferred code
R=asgerf@google.com

Review URL: https://codereview.chromium.org/1558353002 .
2016-01-06 10:24:52 -08:00
Asger Feldthaus 8d7c326979 dart2js cps: Disable RHS propagation in operands to builtin operators.
Previously we would get code like `x == (y = null)`, which confuses
the JS engine.  It is better to have `y = null` and `x == null` separate.

BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1563693002 .
2016-01-06 07:44:05 -08:00
Johnni Winther 306537be79 Add test of unittests.
BUG=
R=sigurdm@google.com

Review URL: https://codereview.chromium.org/1562023002.
2016-01-06 13:19:41 +01:00
Johnni Winther 812527f5b3 Make NamedMixinApplicationElementX and EnumClassElementX implement DeclarationSite.
BUG=
R=ahe@google.com

Review URL: https://codereview.chromium.org/1504763003.
2016-01-06 11:54:20 +01:00
Asger Feldthaus e9f211962a dart2js cps: Fix some analyzer hints in the CPS backend.
BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1560433003 .
2016-01-05 13:41:39 -08:00
Stephen Adams 731b9894b2 dart2js: minify 'static:' tag
(For now, only in frequency based renamer)

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1540973005 .
2015-12-28 16:12:06 -08:00
Stephen Adams 712574058a Better NullCheck for null-or-number
R=het@google.com

Review URL: https://codereview.chromium.org/1550463002 .
2015-12-28 12:06:15 -08:00
Kevin Millikin 044b283a3c dart2js: Initial implementation of inlining.
Perform a depth-first postorder traversal of the call graph of known
functions.  Make an inlining decision based on the vector of argument
types at the call site, and cache inlining decisions.  For positive
inlining decisions, cache the optimized function body specialized to
the receiver and argument types at the call site.

Future work:
  * Real inlining heuristics.
  * Propagate result types of inlined calls.
  * Specialized for constant arguments when it makes sense.
  * Performance improvements.

R=asgerf@google.com, sra@google.com

Committed: https://github.com/dart-lang/sdk/commit/d63053fea8731d2fb380022c1c3d296489d1c017

Review URL: https://codereview.chromium.org/1537663002 .
2015-12-23 10:12:19 +01:00
Stephen Adams db2d6b798f dart2js: format 'static' sections better.
Unminified: each property goes on a new line.
minified: ignore the isOneLiner directive until a function is seen.

This makes unminified static functions easier to read, and makes minified swarm 0.3% smaller (but almost no different after gzip).

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1548793002 .
2015-12-22 14:45:23 -08:00
Stephen Adams 2847fbbf8a Add 'Math' to list of safe global JavaScript names.
TBR=asgerf@google.com

Review URL: https://codereview.chromium.org/1549603002 .
2015-12-22 14:24:05 -08:00
Kevin Millikin 75eb350abc Revert "dart2js: Initial implementation of inlining."
This reverts commit d63053fea8.

Reverted due to test failures for compiler expected output.  Those tests
need to be rebaselined to reflect the effects of inlining.

TBR=whesse@google.com
BUG=

Review URL: https://codereview.chromium.org/1542003003 .
2015-12-22 13:48:36 +01:00
Kevin Millikin d63053fea8 dart2js: Initial implementation of inlining.
Perform a depth-first postorder traversal of the call graph of known
functions.  Make an inlining decision based on the vector of argument
types at the call site, and cache inlining decisions.  For positive
inlining decisions, cache the optimized function body specialized to
the receiver and argument types at the call site.

Future work:
  * Real inlining heuristics.
  * Propagate result types of inlined calls.
  * Specialized for constant arguments when it makes sense.
  * Performance improvements.

R=asgerf@google.com, sra@google.com

Review URL: https://codereview.chromium.org/1537663002 .
2015-12-22 12:50:23 +01:00
Stephen Adams d2c403704c js_runtime tweaks for better code
1. Help type inference infer constant maps have a .length that is a non-null subtype of int. On some programs this means dynamic.length can be inferred as non-null int.

2. Make arity dispatch interceptor free by comparing constants-first (via a switch statement).

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1539033002 .
2015-12-21 13:30:24 -08:00
Asger Feldthaus 6857dc81e7 dart2js cps: Backward redundant null check removal.
Removes null checks that are follwed by an instruction which performs
the same check.

BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1538593003 .
2015-12-18 16:57:24 +01:00
Asger Feldthaus db00be6476 dart2js cps: Clone small constants to use site.
BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1526333002 .
2015-12-18 16:31:09 +01:00
Florian Loitsch 6ecea2f559 Add dart_messages package.
R=johnniwinther@google.com, sigmund@google.com

Review URL: https://codereview.chromium.org/1514333002 .
2015-12-17 18:15:17 +01:00
Sigmund Cherem 913ca66834 Tweaks to improve performance of type-inference.
- short-circuit cases where join yields dynamic
- improve performance of some queries like `hasOnlySubclasses` and how `contains` is implemented in `flatten`. We could also add caching for `length`, but not sure if we want to just have a static map or precompute the data in the class-hierarchy nodes.

On my experiments this reduces inference times more than 50% on a large customer app, while small apps have almost no change.

R=johnniwinther@google.com, sra@google.com

Review URL: https://codereview.chromium.org/1528953002 .
2015-12-16 17:03:46 -08:00
Stephen Adams 042fcc9de0 Indexer one-shot fast path adjustment
If the index/key is not a number it is unlikely that the receiver is an Array-like JavaScript object.

This suggests that we should have a version of the one-shot with no fast-path to use at call sites where we can prove the (receiver, argument) combination does not benefit from the fast path.

BUG=
R=sigmund@google.com

Review URL: https://codereview.chromium.org/1531453004 .
2015-12-16 15:07:21 -08:00
Johnni Winther 5d53b30151 Handle malformed elements in onElementResolved.
R=sigurdm@google.com

Review URL: https://codereview.chromium.org/1525423002.
2015-12-16 15:04:25 +01:00
Asger Feldthaus 488ffd8aac dart2js cps: Use oneshot interceptors and 'instanceof' expressions.
BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1525163002 .
2015-12-16 14:13:51 +01:00
Stephen Adams c5e9ab890f Constant-fold fields of constant objects.
SSA catch-up item.

R=asgerf@google.com

Review URL: https://codereview.chromium.org/1528673002 .
2015-12-15 10:44:02 -08:00
Stephen Adams 620257ffc0 cps_ir: Add JS checks, use argument nullability
- Add JS checks for wrong number or captured placeholders.

- Add list of nullability bits to allow generation of non-null placeholder expressions in place.

R=asgerf@google.com

Review URL: https://codereview.chromium.org/1526623004 .
2015-12-15 10:38:39 -08:00
Asger Feldthaus c6e2af11db dart2js cps: Replace GetLazyStatic with GetStatic.
Also fixes a bug in GVN that made it unable to GVN GetLazyStatic.

BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1521553003 .
2015-12-15 11:45:59 +01:00
Johnni Winther c5235fde7f Add token invariant to DiagnosticReporter
Closes #3675

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1520293002.
2015-12-15 11:35:55 +01:00
Johnni Winther 212ba4afbe Support optional package name arguments to --show-package-warnings
In response to dartbug.com/18661 and dartbug.com/21651.

Dart2js doesn't know pubspec.yaml or the directory structure but pub does. Next step is to pass arguments from pub.

BUG=
R=sigmund@google.com

Review URL: https://codereview.chromium.org/1513263002.
2015-12-15 10:52:19 +01:00
Johnni Winther 6bb8cd8943 Introduce benign errors.
Closes #25204

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1525593002.
2015-12-15 10:17:00 +01:00
Stephen Adams dcf576a428 js_ast: Better escaping of strings in preparation for utf8 file encoding
- Choose between single and double quotes to reduce number of escapes.
- With "uft8: true", leave most characters for the file encoding.
- LINE SEPARATOR and PAGE SEPARATOR must always be \uXXXX encoded.
- Unpaired surrogates must be encoded as \uXXXX.
- Use \xXX rather than \u00XX where possible.

R=sigmund@google.com

Review URL: https://codereview.chromium.org/1520033002 .
2015-12-14 11:33:12 -08:00
Asger Feldthaus 22bf979646 dart2js cps: Retain refinement nodes and update refinements after GVN.
Refinement nodes are retained throughout the optimization pipeline.

GVN can improve refinements, so a new pass after GVN updated references
to use the best refinement in scope.  For example:

    x.f.g();
    x.f.h();

  ==>

    v0 = x.f;
    v0.g();
    v0.h();

The receiver of h() is known to be non-null after GVN because the two
uses of x.f were proven to be the same value.

BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1519513002 .
2015-12-14 15:01:32 +01:00
Asger Feldthaus f53ce36c3d dart2js cps: Add instruction for bounds checks.
The new instruction is expanded into low-level operations
in a new pass Finalize. The Finalize pass is mandatory.

The BoundsCheck returns the indexable object being checked
so it can be used to restrict code motion.

BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1512303002 .
2015-12-14 14:41:49 +01:00
Asger Feldthaus a28639d634 dart2js cps: Better GVN for fixed lengths and unmodified fields.
BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1518003002 .
2015-12-14 12:46:14 +01:00
Stephen Adams 04e3f8520c Don't constant fold large strings.
This fixes a 10k regression in swarm.  Marked with appropriate TODOs.

R=asgerf@google.com

Review URL: https://codereview.chromium.org/1519773002 .
2015-12-11 11:33:00 -08:00
Asger Feldthaus c5539316fb dart2js cps: Add instruction for null checks.
Currently we only instantiate the instruction for the null
checks inserted for numeric operators.

The corresponding instruction also exists in the tree IR,
partly because there is no way to say "x.toString" with the
current instruction set.

BUG=
R=sra@google.com

Review URL: https://codereview.chromium.org/1507313006 .
2015-12-11 14:17:59 +01:00
Florian Loitsch af4983c6b2 dart2js: add support for configuration-specific imports.
R=johnniwinther@google.com, rnystrom@google.com

Committed: https://github.com/dart-lang/sdk/commit/64edfaf21af3153f32e1229dd97c9b3d40cbfb2b
Reverted: https://github.com/dart-lang/sdk/commit/f38b810d334900317ee6c919b45ebd0c673fdb02

Review URL: https://codereview.chromium.org/1388523002 .
2015-12-11 06:17:15 +01:00
Florian Loitsch f38b810d33 Revert "dart2js: add support for configuration-specific imports."
This reverts commit 64edfaf21a.

Review URL: https://codereview.chromium.org/1517013003 .
2015-12-11 00:49:38 +01:00