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

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

Issue 10537025: Prototype re-compiling methods in dart2js (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Use the results from the resolver when trying to detect final fields Created 8 years, 6 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 interface OptimizationPhase { 5 interface OptimizationPhase {
6 String get name(); 6 String get name();
7 void visitGraph(HGraph graph); 7 void visitGraph(HGraph graph);
8 } 8 }
9 9
10 class SsaOptimizerTask extends CompilerTask { 10 class SsaOptimizerTask extends CompilerTask {
11 final JavaScriptBackend backend; 11 final JavaScriptBackend backend;
12 SsaOptimizerTask(JavaScriptBackend backend) 12 SsaOptimizerTask(JavaScriptBackend backend)
13 : this.backend = backend, 13 : this.backend = backend,
14 super(backend.compiler); 14 super(backend.compiler);
15 String get name() => 'SSA optimizer'; 15 String get name() => 'SSA optimizer';
16 Compiler get compiler() => backend.compiler; 16 Compiler get compiler() => backend.compiler;
17 17
18 void runPhases(HGraph graph, List<OptimizationPhase> phases) { 18 void runPhases(HGraph graph, List<OptimizationPhase> phases) {
19 for (OptimizationPhase phase in phases) { 19 for (OptimizationPhase phase in phases) {
20 phase.visitGraph(graph); 20 phase.visitGraph(graph);
21 compiler.tracer.traceGraph(phase.name, graph); 21 compiler.tracer.traceGraph(phase.name, graph);
22 } 22 }
23 } 23 }
24 24
25 void optimize(WorkItem work, HGraph graph) { 25 void optimize(WorkItem work, HGraph graph) {
26 measure(() { 26 measure(() {
27 List<OptimizationPhase> phases = <OptimizationPhase>[ 27 List<OptimizationPhase> phases = <OptimizationPhase>[
28 // Run trivial constant folding first to optimize 28 // Run trivial constant folding first to optimize
29 // some patterns useful for type conversion. 29 // some patterns useful for type conversion.
30 new SsaConstantFolder(backend), 30 new SsaConstantFolder(backend, work),
31 new SsaTypeConversionInserter(compiler), 31 new SsaTypeConversionInserter(compiler),
32 new SsaTypePropagator(compiler), 32 new SsaTypePropagator(compiler),
33 new SsaCheckInserter(backend), 33 new SsaCheckInserter(backend),
34 new SsaConstantFolder(backend), 34 new SsaConstantFolder(backend, work),
35 new SsaRedundantPhiEliminator(), 35 new SsaRedundantPhiEliminator(),
36 new SsaDeadPhiEliminator(), 36 new SsaDeadPhiEliminator(),
37 new SsaGlobalValueNumberer(compiler), 37 new SsaGlobalValueNumberer(compiler),
38 new SsaCodeMotion(), 38 new SsaCodeMotion(),
39 new SsaDeadCodeEliminator()]; 39 new SsaDeadCodeEliminator()];
40 runPhases(graph, phases); 40 runPhases(graph, phases);
41 }); 41 });
42 } 42 }
43 43
44 bool trySpeculativeOptimizations(WorkItem work, HGraph graph) { 44 bool trySpeculativeOptimizations(WorkItem work, HGraph graph) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 } 84 }
85 85
86 /** 86 /**
87 * If both inputs to known operations are available execute the operation at 87 * If both inputs to known operations are available execute the operation at
88 * compile-time. 88 * compile-time.
89 */ 89 */
90 class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase { 90 class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
91 final String name = "SsaConstantFolder"; 91 final String name = "SsaConstantFolder";
92 final JavaScriptBackend backend; 92 final JavaScriptBackend backend;
93 final WorkItem work;
93 HGraph graph; 94 HGraph graph;
94 Compiler get compiler() => backend.compiler; 95 Compiler get compiler() => backend.compiler;
95 96
96 SsaConstantFolder(this.backend); 97 SsaConstantFolder(this.backend, this.work);
97 98
98 void visitGraph(HGraph visitee) { 99 void visitGraph(HGraph visitee) {
99 graph = visitee; 100 graph = visitee;
100 visitDominatorTree(visitee); 101 visitDominatorTree(visitee);
101 } 102 }
102 103
103 visitBasicBlock(HBasicBlock block) { 104 visitBasicBlock(HBasicBlock block) {
104 HInstruction instruction = block.first; 105 HInstruction instruction = block.first;
105 while (instruction !== null) { 106 while (instruction !== null) {
106 HInstruction next = instruction.next; 107 HInstruction next = instruction.next;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 if (receiver.propagatedType.canBeNull()) return node; 574 if (receiver.propagatedType.canBeNull()) return node;
574 Type type = receiver.propagatedType.computeType(compiler); 575 Type type = receiver.propagatedType.computeType(compiler);
575 if (type === null) return node; 576 if (type === null) return node;
576 Element field = compiler.world.locateSingleField(type, node.name); 577 Element field = compiler.world.locateSingleField(type, node.name);
577 if (field === null) return node; 578 if (field === null) return node;
578 Modifiers modifiers = field.modifiers; 579 Modifiers modifiers = field.modifiers;
579 bool isFinalOrConst = false; 580 bool isFinalOrConst = false;
580 if (modifiers != null) { 581 if (modifiers != null) {
581 isFinalOrConst = modifiers.isFinal() || modifiers.isConst(); 582 isFinalOrConst = modifiers.isFinal() || modifiers.isConst();
582 } 583 }
584 if (!compiler.resolverWorld.hasInvokedSetter(field, compiler)) {
585 // If no setter is ever used for this field it is only initialized in the
586 // initializer list.
587 isFinalOrConst = true;
588 }
589 if (!isFinalOrConst &&
590 !compiler.codegenWorld.hasInvokedSetter(field, compiler) &&
591 !compiler.codegenWorld.hasFieldSetter(field, compiler)) {
592 switch (compiler.pass) {
593 case 1:
594 compiler.enqueuer.codegen.registerRecompilationCandidate(
595 work.element);
596 break;
597 case 2:
598 // If field is not final or const but no setters are used then the
599 // field might be considered final anyway as it will be either
600 // un-initialized or initialized in the constructor initializer list.
601 isFinalOrConst = true;
602 break;
603 }
604 }
583 return new HFieldGet(field, node.inputs[0], isFinalOrConst: isFinalOrConst); 605 return new HFieldGet(field, node.inputs[0], isFinalOrConst: isFinalOrConst);
584 } 606 }
585 607
586 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) { 608 HInstruction visitInvokeDynamicSetter(HInvokeDynamicSetter node) {
587 HInstruction receiver = node.inputs[0]; 609 HInstruction receiver = node.inputs[0];
588 if (!receiver.propagatedType.isUseful()) return node; 610 if (!receiver.propagatedType.isUseful()) return node;
589 if (receiver.propagatedType.canBeNull()) return node; 611 if (receiver.propagatedType.canBeNull()) return node;
590 Type type = receiver.propagatedType.computeType(compiler); 612 Type type = receiver.propagatedType.computeType(compiler);
591 if (type === null) return node; 613 if (type === null) return node;
592 Element field = compiler.world.locateSingleField(type, node.name); 614 Element field = compiler.world.locateSingleField(type, node.name);
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 // the if block terminates. So any use of the instruction 1162 // the if block terminates. So any use of the instruction
1141 // after the join block should be changed to the new 1163 // after the join block should be changed to the new
1142 // instruction. 1164 // instruction.
1143 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType); 1165 changeUsesDominatedBy(ifUser.joinBlock, input, convertedType);
1144 } 1166 }
1145 // TODO(ngeoffray): Also change uses for the then block on a HType 1167 // TODO(ngeoffray): Also change uses for the then block on a HType
1146 // that knows it is not of a specific Type. 1168 // that knows it is not of a specific Type.
1147 } 1169 }
1148 } 1170 }
1149 } 1171 }
OLDNEW
« lib/compiler/implementation/enqueue.dart ('K') | « lib/compiler/implementation/enqueue.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698