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

Side by Side Diff: frog/leg/ssa/types.dart

Issue 9784002: Support non-speculative type propagation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | « frog/leg/ssa/optimize.dart ('k') | no next file » | 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) 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)
floitsch 2012/03/27 22:38:33 I prefer not to type 'this.X' parameters, but your
ngeoffray 2012/03/28 07:23:22 I will keep it with the types since that's what wa
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 HType newType = instruction.computeType();
22
23 if (speculative) {
24 HType desiredType = instruction.computeDesiredType();
25 HType combined = newType.combine(desiredType);
26 if (combined.isKnown()) newType = combined;
27 }
28
29 bool changed = (instruction.type != newType);
30 if (instruction.type.isUnknown()) {
31 instruction.type = newType;
32 return changed;
33 } else if (changed) {
34 instruction.type = instruction.type.combine(newType);
35 return changed;
36 }
37 return false;
38 }
39
16 void visitGraph(HGraph graph) { 40 void visitGraph(HGraph graph) {
17 visitDominatorTree(graph); 41 visitDominatorTree(graph);
18 processWorklist(); 42 processWorklist();
19 } 43 }
20 44
21 visitBasicBlock(HBasicBlock block) { 45 visitBasicBlock(HBasicBlock block) {
22 if (block.isLoopHeader()) { 46 if (block.isLoopHeader()) {
23 block.forEachPhi((HPhi phi) { 47 block.forEachPhi((HPhi phi) {
24 phi.setInitialTypeForLoopPhi(); 48 // Set the initial type for the phi.
49 phi.type = phi.inputs[0].type;
25 addToWorkList(phi); 50 addToWorkList(phi);
26 }); 51 });
27 } else { 52 } else {
28 block.forEachPhi((HPhi phi) { 53 block.forEachPhi((HPhi phi) {
29 if (phi.updateType()) addUsersAndInputsToWorklist(phi); 54 if (updateType(phi)) addUsersAndInputsToWorklist(phi);
30 }); 55 });
31 } 56 }
32 57
33 HInstruction instruction = block.first; 58 HInstruction instruction = block.first;
34 while (instruction !== null) { 59 while (instruction !== null) {
35 if (instruction.updateType()) addUsersAndInputsToWorklist(instruction); 60 if (updateType(instruction)) addUsersAndInputsToWorklist(instruction);
36 instruction = instruction.next; 61 instruction = instruction.next;
37 } 62 }
38 } 63 }
39 64
40 void processWorklist() { 65 void processWorklist() {
41 while (!worklist.isEmpty()) { 66 while (!worklist.isEmpty()) {
42 int id = worklist.removeLast(); 67 int id = worklist.removeLast();
43 HInstruction instruction = workmap[id]; 68 HInstruction instruction = workmap[id];
44 assert(instruction !== null); 69 assert(instruction !== null);
45 workmap.remove(id); 70 workmap.remove(id);
46 if (instruction.updateType()) addUsersAndInputsToWorklist(instruction); 71 if (updateType(instruction)) addUsersAndInputsToWorklist(instruction);
47 } 72 }
48 } 73 }
49 74
50 void addUsersAndInputsToWorklist(HInstruction instruction) { 75 void addUsersAndInputsToWorklist(HInstruction instruction) {
51 for (int i = 0, length = instruction.usedBy.length; i < length; i++) { 76 for (int i = 0, length = instruction.usedBy.length; i < length; i++) {
52 addToWorkList(instruction.usedBy[i]); 77 addToWorkList(instruction.usedBy[i]);
53 } 78 }
54 for (int i = 0, length = instruction.inputs.length; i < length; i++) { 79 for (int i = 0, length = instruction.inputs.length; i < length; i++) {
55 addToWorkList(instruction.inputs[i]); 80 addToWorkList(instruction.inputs[i]);
56 } 81 }
57 } 82 }
58 83
59 void addToWorkList(HInstruction instruction) { 84 void addToWorkList(HInstruction instruction) {
60 final int id = instruction.id; 85 final int id = instruction.id;
61 if (!workmap.containsKey(id)) { 86 if (!workmap.containsKey(id)) {
62 worklist.add(id); 87 worklist.add(id);
63 workmap[id] = instruction; 88 workmap[id] = instruction;
64 } 89 }
65 } 90 }
66 } 91 }
OLDNEW
« no previous file with comments | « frog/leg/ssa/optimize.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698