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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/ssa/optimize.dart

Issue 14404004: Throw NoSuchMethod or ArgumentError instead of generating a bailout, when we know the next instruct… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 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
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 abstract class OptimizationPhase { 7 abstract class OptimizationPhase {
8 String get name; 8 String get name;
9 void visitGraph(HGraph graph); 9 void visitGraph(HGraph graph);
10 } 10 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 }); 66 });
67 } 67 }
68 68
69 bool trySpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { 69 bool trySpeculativeOptimizations(CodegenWorkItem work, HGraph graph) {
70 if (work.element.isField()) { 70 if (work.element.isField()) {
71 // Lazy initializers may not have bailout methods. 71 // Lazy initializers may not have bailout methods.
72 return false; 72 return false;
73 } 73 }
74 JavaScriptItemCompilationContext context = work.compilationContext; 74 JavaScriptItemCompilationContext context = work.compilationContext;
75 return measure(() { 75 return measure(() {
76 SsaTypeGuardInserter inserter = new SsaTypeGuardInserter(compiler, work);
77
76 // Run the phases that will generate type guards. 78 // Run the phases that will generate type guards.
77 List<OptimizationPhase> phases = <OptimizationPhase>[ 79 List<OptimizationPhase> phases = <OptimizationPhase>[
78 new SsaTypeGuardInserter(compiler, work), 80 inserter,
79 new SsaEnvironmentBuilder(compiler), 81 new SsaEnvironmentBuilder(compiler),
80 // Then run the [SsaCheckInserter] because the type propagator also 82 // Then run the [SsaCheckInserter] because the type propagator also
81 // propagated types non-speculatively. For example, it might have 83 // propagated types non-speculatively. For example, it might have
82 // propagated the type array for a call to the List constructor. 84 // propagated the type array for a call to the List constructor.
83 new SsaCheckInserter(backend, work, context.boundsChecked)]; 85 new SsaCheckInserter(backend, work, context.boundsChecked)];
84 runPhases(graph, phases); 86 runPhases(graph, phases);
87
88 if (work.guards.isEmpty && inserter.hasInsertedChecks) {
89 // If there is no guard, and we have inserted type checks
90 // instead, we can do the optimizations right away and avoid
91 // the bailout method.
92 optimize(work, graph, false);
93 }
85 return !work.guards.isEmpty; 94 return !work.guards.isEmpty;
86 }); 95 });
87 } 96 }
88 97
89 void prepareForSpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { 98 void prepareForSpeculativeOptimizations(CodegenWorkItem work, HGraph graph) {
90 JavaScriptItemCompilationContext context = work.compilationContext; 99 JavaScriptItemCompilationContext context = work.compilationContext;
91 measure(() { 100 measure(() {
92 // In order to generate correct code for the bailout version, we did not 101 // In order to generate correct code for the bailout version, we did not
93 // propagate types from the instruction to the type guard. We do it 102 // propagate types from the instruction to the type guard. We do it
94 // now to be able to optimize further. 103 // now to be able to optimize further.
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 952
944 HBoundsCheck check = new HBoundsCheck(index, length); 953 HBoundsCheck check = new HBoundsCheck(index, length);
945 node.block.addBefore(node, check); 954 node.block.addBefore(node, check);
946 boundsChecked.add(node); 955 boundsChecked.add(node);
947 return check; 956 return check;
948 } 957 }
949 958
950 HIntegerCheck insertIntegerCheck(HInstruction node, HInstruction value) { 959 HIntegerCheck insertIntegerCheck(HInstruction node, HInstruction value) {
951 HIntegerCheck check = new HIntegerCheck(value); 960 HIntegerCheck check = new HIntegerCheck(value);
952 node.block.addBefore(node, check); 961 node.block.addBefore(node, check);
953 Set<HInstruction> dominatedUsers = value.dominatedUsers(node); 962 value.replaceAllUsersDominatedBy(node, check);
954 for (HInstruction user in dominatedUsers) {
955 user.changeUse(value, check);
956 }
957 return check; 963 return check;
958 } 964 }
959 965
960 void visitIndex(HIndex node) { 966 void visitIndex(HIndex node) {
961 if (boundsChecked.contains(node)) return; 967 if (boundsChecked.contains(node)) return;
962 HInstruction index = node.index; 968 HInstruction index = node.index;
963 if (!node.index.isInteger()) { 969 if (!node.index.isInteger()) {
964 index = insertIntegerCheck(node, index); 970 index = insertIntegerCheck(node, index);
965 } 971 }
966 index = insertBoundsCheck(node, node.receiver, index); 972 index = insertBoundsCheck(node, node.receiver, index);
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 HBasicBlock block = user.block; 1703 HBasicBlock block = user.block;
1698 block.addAfter(user, interceptor); 1704 block.addAfter(user, interceptor);
1699 block.rewrite(user, interceptor); 1705 block.rewrite(user, interceptor);
1700 block.remove(user); 1706 block.remove(user);
1701 1707
1702 // The interceptor will be removed in the dead code elimination 1708 // The interceptor will be removed in the dead code elimination
1703 // phase. Note that removing it here would not work because of how 1709 // phase. Note that removing it here would not work because of how
1704 // the [visitBasicBlock] is implemented. 1710 // the [visitBasicBlock] is implemented.
1705 } 1711 }
1706 } 1712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698