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

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

Issue 9874014: New CL for https://chromiumcodereview.appspot.com/9784002/: Support non-speculative type propagatio… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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) 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 class SsaTypePropagator extends HGraphVisitor implements OptimizationPhase { 5 class SsaTypePropagator extends HGraphVisitor implements OptimizationPhase {
6 6
7 final Map<int, HInstruction> workmap; 7 final Map<int, HInstruction> workmap;
8 final List<int> worklist; 8 final List<int> worklist;
9 final Compiler compiler; 9 final Compiler compiler;
10 final bool speculative;
10 final String name = 'type propagator'; 11 final String name = 'type propagator';
11 12
12 SsaTypePropagator(Compiler this.compiler) 13 SsaTypePropagator(Compiler this.compiler, bool this.speculative)
Lasse Reichstein Nielsen 2012/03/29 11:46:55 As mentioned: make this argument optional so you c
13 : workmap = new Map<int, HInstruction>(), 14 : workmap = new Map<int, HInstruction>(),
14 worklist = new List<int>(); 15 worklist = new List<int>();
15 16
17 // Re-compute and update the type of the instruction. Returns
18 // whether or not the type was changed.
19 bool updateType(HInstruction instruction) {
20 if (instruction.type.isConflicting()) return false;
21
22 // Constants have the type they have. It can't be changed.
23 if (instruction.isConstant()) return false;
24 HType oldType = instruction.type;
25 HType newType = instruction.computeType();
26
27 if (speculative) {
Lasse Reichstein Nielsen 2012/03/29 11:46:55 Is this the only place speculative is used? If so
ngeoffray 2012/03/29 12:51:02 Done.
28 HType desiredType = instruction.computeDesiredType();
29 HType combined = newType.combine(desiredType);
30 // If the propagated type [newType] does not conflict with the
31 // speculated type [desiredType], use it.
32 if (combined.isKnown()) newType = combined;
33 }
34
35 instruction.type = oldType.combine(newType);
36 return oldType !== instruction.type;
37 }
38
16 void visitGraph(HGraph graph) { 39 void visitGraph(HGraph graph) {
17 visitDominatorTree(graph); 40 visitDominatorTree(graph);
18 processWorklist(); 41 processWorklist();
19 } 42 }
20 43
21 visitBasicBlock(HBasicBlock block) { 44 visitBasicBlock(HBasicBlock block) {
22 if (block.isLoopHeader()) { 45 if (block.isLoopHeader()) {
23 block.forEachPhi((HPhi phi) { 46 block.forEachPhi((HPhi phi) {
24 phi.setInitialTypeForLoopPhi(); 47 // Set the initial type for the phi.
48 phi.type = phi.inputs[0].type;
25 addToWorkList(phi); 49 addToWorkList(phi);
26 }); 50 });
27 } else { 51 } else {
28 block.forEachPhi((HPhi phi) { 52 block.forEachPhi((HPhi phi) {
29 if (phi.updateType()) addUsersAndInputsToWorklist(phi); 53 if (updateType(phi)) addUsersAndInputsToWorklist(phi);
30 }); 54 });
31 } 55 }
32 56
33 HInstruction instruction = block.first; 57 HInstruction instruction = block.first;
34 while (instruction !== null) { 58 while (instruction !== null) {
35 if (instruction.updateType()) addUsersAndInputsToWorklist(instruction); 59 if (updateType(instruction)) addUsersAndInputsToWorklist(instruction);
36 instruction = instruction.next; 60 instruction = instruction.next;
37 } 61 }
38 } 62 }
39 63
40 void processWorklist() { 64 void processWorklist() {
41 while (!worklist.isEmpty()) { 65 while (!worklist.isEmpty()) {
42 int id = worklist.removeLast(); 66 int id = worklist.removeLast();
43 HInstruction instruction = workmap[id]; 67 HInstruction instruction = workmap[id];
44 assert(instruction !== null); 68 assert(instruction !== null);
45 workmap.remove(id); 69 workmap.remove(id);
46 if (instruction.updateType()) addUsersAndInputsToWorklist(instruction); 70 if (updateType(instruction)) addUsersAndInputsToWorklist(instruction);
47 } 71 }
48 } 72 }
49 73
50 void addUsersAndInputsToWorklist(HInstruction instruction) { 74 void addUsersAndInputsToWorklist(HInstruction instruction) {
51 for (int i = 0, length = instruction.usedBy.length; i < length; i++) { 75 for (int i = 0, length = instruction.usedBy.length; i < length; i++) {
52 addToWorkList(instruction.usedBy[i]); 76 addToWorkList(instruction.usedBy[i]);
53 } 77 }
54 for (int i = 0, length = instruction.inputs.length; i < length; i++) { 78 for (int i = 0, length = instruction.inputs.length; i < length; i++) {
55 addToWorkList(instruction.inputs[i]); 79 addToWorkList(instruction.inputs[i]);
56 } 80 }
57 } 81 }
58 82
59 void addToWorkList(HInstruction instruction) { 83 void addToWorkList(HInstruction instruction) {
60 final int id = instruction.id; 84 final int id = instruction.id;
61 if (!workmap.containsKey(id)) { 85 if (!workmap.containsKey(id)) {
62 worklist.add(id); 86 worklist.add(id);
63 workmap[id] = instruction; 87 workmap[id] = instruction;
64 } 88 }
65 } 89 }
66 } 90 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698