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

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

Issue 12033056: Implement "one-shot" interceptors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 new SsaDeadPhiEliminator(), 51 new SsaDeadPhiEliminator(),
52 new SsaConstantFolder(constantSystem, backend, work, types), 52 new SsaConstantFolder(constantSystem, backend, work, types),
53 new SsaTypePropagator(compiler, types), 53 new SsaTypePropagator(compiler, types),
54 new SsaReceiverSpecialization(compiler), 54 new SsaReceiverSpecialization(compiler),
55 new SsaGlobalValueNumberer(compiler, types), 55 new SsaGlobalValueNumberer(compiler, types),
56 new SsaCodeMotion(), 56 new SsaCodeMotion(),
57 new SsaValueRangeAnalyzer(constantSystem, types, work), 57 new SsaValueRangeAnalyzer(constantSystem, types, work),
58 // Previous optimizations may have generated new 58 // Previous optimizations may have generated new
59 // opportunities for constant folding. 59 // opportunities for constant folding.
60 new SsaConstantFolder(constantSystem, backend, work, types), 60 new SsaConstantFolder(constantSystem, backend, work, types),
61 new SsaSimplifyInterceptors(constantSystem),
61 new SsaDeadCodeEliminator(types)]; 62 new SsaDeadCodeEliminator(types)];
62 runPhases(graph, phases); 63 runPhases(graph, phases);
63 if (!speculative) { 64 if (!speculative) {
64 runPhase(graph, new SsaConstructionFieldTypes(backend, work, types)); 65 runPhase(graph, new SsaConstructionFieldTypes(backend, work, types));
65 } 66 }
66 }); 67 });
67 } 68 }
68 69
69 bool trySpeculativeOptimizations(CodegenWorkItem work, HGraph graph) { 70 bool trySpeculativeOptimizations(CodegenWorkItem work, HGraph graph) {
70 if (work.element.isField()) { 71 if (work.element.isField()) {
(...skipping 1367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1438 || otherIntercepted.contains(backend.jsDoubleClass)) { 1439 || otherIntercepted.contains(backend.jsDoubleClass)) {
1439 interceptor.interceptedClasses.addAll(user.interceptedClasses); 1440 interceptor.interceptedClasses.addAll(user.interceptedClasses);
1440 } 1441 }
1441 user.interceptedClasses = interceptor.interceptedClasses; 1442 user.interceptedClasses = interceptor.interceptedClasses;
1442 } 1443 }
1443 } 1444 }
1444 } 1445 }
1445 1446
1446 // TODO(ngeoffray): Also implement it for non-intercepted calls. 1447 // TODO(ngeoffray): Also implement it for non-intercepted calls.
1447 } 1448 }
1449
1450 /**
1451 * This phase changes all interceptors that are used only once with
sra1 2013/01/23 21:21:30 /changes/replaces/
ngeoffray 2013/01/24 08:39:15 Done.
1452 * one-shot interceptors. It saves code size and makes the receiver of
1453 * an intercepted call a candidate for being generated at use site.
1454 */
1455 class SsaSimplifyInterceptors extends HBaseVisitor
1456 implements OptimizationPhase {
1457 final String name = "SsaSimplifyInterceptors";
1458 final ConstantSystem constantSystem;
1459 HGraph graph;
1460
1461 SsaSimplifyInterceptors(this.constantSystem);
1462
1463 void visitGraph(HGraph graph) {
1464 this.graph = graph;
1465 visitDominatorTree(graph);
1466 }
1467
1468 void visitInterceptor(HInterceptor node) {
1469 if (node.usedBy.length != 1) return;
1470 // [HBailoutTarget] instructions might have the interceptor as
1471 // input. In such situation we let the dead code analyzer find out
1472 // the interceptor is not needed.
sra1 2013/01/23 21:21:30 Does this lead to unreferenced one-shots?
ngeoffray 2013/01/24 08:39:15 One-shots have side effects, so there's nothing we
1473 if (node.usedBy[0] is !HInvokeDynamic) return;
1474
1475 // Replace the user with a [HOneShotInterceptor].
1476 HInvokeDynamic user = node.usedBy[0];
1477 HConstant nullConstant = graph.addConstantNull(constantSystem);
1478 List<HInstruction> inputs = new List<HInstruction>.from(user.inputs);
1479 inputs[0] = nullConstant;
1480 HOneShotInterceptor interceptor = new HOneShotInterceptor(
1481 user.selector, inputs, node.interceptedClasses);
1482
1483 HBasicBlock block = user.block;
1484 block.addAfter(user, interceptor);
1485 block.rewrite(user, interceptor);
1486 block.remove(user);
1487
1488 // The interceptor will be removed in the dead code elimination
1489 // phase. Note that removing it here would not work because of how
1490 // the [visitBasicBlock] is implemented.
1491 }
1492 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698