Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1368)

Side by Side Diff: pkg/compiler/lib/src/ssa/codegen.dart

Issue 1087973002: Rewrite for-in loop as indexing loop for JavaScript indexable arrays (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: retry Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/codegen_helpers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of ssa; 5 part of ssa;
6 6
7 class SsaCodeGeneratorTask extends CompilerTask { 7 class SsaCodeGeneratorTask extends CompilerTask {
8 8
9 final JavaScriptBackend backend; 9 final JavaScriptBackend backend;
10 10
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 backend.namer.invocationName(call), 1617 backend.namer.invocationName(call),
1618 visitArguments(node.inputs)), 1618 visitArguments(node.inputs)),
1619 node); 1619 node);
1620 registry.registerDynamicInvocation(call); 1620 registry.registerDynamicInvocation(call);
1621 } 1621 }
1622 1622
1623 visitInvokeStatic(HInvokeStatic node) { 1623 visitInvokeStatic(HInvokeStatic node) {
1624 Element element = node.element; 1624 Element element = node.element;
1625 List<DartType> instantiatedTypes = node.instantiatedTypes; 1625 List<DartType> instantiatedTypes = node.instantiatedTypes;
1626 1626
1627 registry.registerStaticInvocation(element);
1628
1629 if (instantiatedTypes != null && !instantiatedTypes.isEmpty) { 1627 if (instantiatedTypes != null && !instantiatedTypes.isEmpty) {
1630 instantiatedTypes.forEach((type) { 1628 instantiatedTypes.forEach((type) {
1631 registry.registerInstantiatedType(type); 1629 registry.registerInstantiatedType(type);
1632 }); 1630 });
1633 } 1631 }
1634 1632
1635 push(backend.emitter.staticFunctionAccess(node.element)); 1633 List<js.Expression> arguments = visitArguments(node.inputs, start: 0);
1636 push(new js.Call(pop(), visitArguments(node.inputs, start: 0)), node); 1634
1635 if (element == backend.getCheckConcurrentModificationError()) {
1636 // Manually inline the [checkConcurrentModificationError] function. This
1637 // function is only called from a for-loop update. Ideally we would just
1638 // generate the conditionalcontrol flow in the builder but it adds basic
1639 // blocks in the loop update that interfere with other optimizations and
1640 // confuses loop recognition.
1641
1642 assert(arguments.length == 2);
1643 Element throwFunction = backend.getThrowConcurrentModificationError();
1644 registry.registerStaticInvocation(throwFunction);
1645
1646 // Calling using `(0, #)(#)` instead of `#(#)` separates the property load
1647 // of the static function access from the call. For some reason this
1648 // helps V8 see that the call never happens so V8 makes the call a
1649 // deoptimization. This removes the call from the optimized loop, making
1650 // more optimizations available to the loop. This form is 50% faster on
1651 // some small loop, almost as fast as loops with no concurrent
1652 // modification check.
1653 push(js.js('# || (0, #)(#)',[
1654 arguments[0],
1655 backend.emitter.staticFunctionAccess(throwFunction),
1656 arguments[1]]));
1657 } else {
1658 registry.registerStaticInvocation(element);
1659 push(backend.emitter.staticFunctionAccess(element));
1660 push(new js.Call(pop(), arguments), node);
1661 }
1662
1637 } 1663 }
1638 1664
1639 visitInvokeSuper(HInvokeSuper node) { 1665 visitInvokeSuper(HInvokeSuper node) {
1640 Element superMethod = node.element; 1666 Element superMethod = node.element;
1641 registry.registerSuperInvocation(superMethod); 1667 registry.registerSuperInvocation(superMethod);
1642 ClassElement superClass = superMethod.enclosingClass; 1668 ClassElement superClass = superMethod.enclosingClass;
1643 if (superMethod.kind == ElementKind.FIELD) { 1669 if (superMethod.kind == ElementKind.FIELD) {
1644 String fieldName = backend.namer.instanceFieldPropertyName(superMethod); 1670 String fieldName = backend.namer.instanceFieldPropertyName(superMethod);
1645 use(node.inputs[0]); 1671 use(node.inputs[0]);
1646 js.PropertyAccess access = 1672 js.PropertyAccess access =
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
2678 js.PropertyAccess accessHelper(String name) { 2704 js.PropertyAccess accessHelper(String name) {
2679 Element helper = backend.findHelper(name); 2705 Element helper = backend.findHelper(name);
2680 if (helper == null) { 2706 if (helper == null) {
2681 // For mocked-up tests. 2707 // For mocked-up tests.
2682 return js.js('(void 0).$name'); 2708 return js.js('(void 0).$name');
2683 } 2709 }
2684 registry.registerStaticUse(helper); 2710 registry.registerStaticUse(helper);
2685 return backend.emitter.staticFunctionAccess(helper); 2711 return backend.emitter.staticFunctionAccess(helper);
2686 } 2712 }
2687 } 2713 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/ssa/builder.dart ('k') | pkg/compiler/lib/src/ssa/codegen_helpers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698