OLD | NEW |
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 class BailoutInfo { | 5 class BailoutInfo { |
6 int instructionId; | 6 int instructionId; |
7 int bailoutId; | 7 int bailoutId; |
8 BailoutInfo(this.instructionId, this.bailoutId); | 8 BailoutInfo(this.instructionId, this.bailoutId); |
9 } | 9 } |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 * we consider the guard to be of value. | 68 * we consider the guard to be of value. |
69 * | 69 * |
70 * Might modify the [:propagatedType:] fields of the instructions in an | 70 * Might modify the [:propagatedType:] fields of the instructions in an |
71 * inconsistent way. No further analysis should rely on them. | 71 * inconsistent way. No further analysis should rely on them. |
72 */ | 72 */ |
73 class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase { | 73 class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase { |
74 final Compiler compiler; | 74 final Compiler compiler; |
75 final String name = 'SsaTypeGuardInserter'; | 75 final String name = 'SsaTypeGuardInserter'; |
76 final WorkItem work; | 76 final WorkItem work; |
77 bool calledInLoop = false; | 77 bool calledInLoop = false; |
78 bool highTypeLikelyhood = false; | |
79 bool isRecursiveMethod = false; | 78 bool isRecursiveMethod = false; |
80 int stateId = 1; | 79 int stateId = 1; |
81 | 80 |
82 SsaTypeGuardInserter(this.compiler, this.work); | 81 SsaTypeGuardInserter(this.compiler, this.work); |
83 | 82 |
84 void visitGraph(HGraph graph) { | 83 void visitGraph(HGraph graph) { |
85 isRecursiveMethod = graph.isRecursiveMethod; | 84 isRecursiveMethod = graph.isRecursiveMethod; |
86 calledInLoop = graph.calledInLoop; | 85 calledInLoop = graph.calledInLoop; |
87 highTypeLikelyhood = graph.highTypeLikelyhood; | |
88 work.guards = <HTypeGuard>[]; | 86 work.guards = <HTypeGuard>[]; |
89 visitDominatorTree(graph); | 87 visitDominatorTree(graph); |
90 } | 88 } |
91 | 89 |
92 void visitBasicBlock(HBasicBlock block) { | 90 void visitBasicBlock(HBasicBlock block) { |
93 block.forEachPhi(visitInstruction); | 91 block.forEachPhi(visitInstruction); |
94 | 92 |
95 HInstruction instruction = block.first; | 93 HInstruction instruction = block.first; |
96 while (instruction !== null) { | 94 while (instruction !== null) { |
97 // Note that visitInstruction (from the phis and here) might insert an | 95 // Note that visitInstruction (from the phis and here) might insert an |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 // generation of a bailout method. | 154 // generation of a bailout method. |
157 if (instruction is HIndex && instruction.builtin && hasTypeGuards) { | 155 if (instruction is HIndex && instruction.builtin && hasTypeGuards) { |
158 HBasicBlock loopHeader = instruction.block.enclosingLoopHeader; | 156 HBasicBlock loopHeader = instruction.block.enclosingLoopHeader; |
159 if (loopHeader != null && loopHeader.parentLoopHeader != null) { | 157 if (loopHeader != null && loopHeader.parentLoopHeader != null) { |
160 return true; | 158 return true; |
161 } | 159 } |
162 } | 160 } |
163 | 161 |
164 // Insert type guards if the method is likely to be called in a | 162 // Insert type guards if the method is likely to be called in a |
165 // loop. | 163 // loop. |
166 return calledInLoop || highTypeLikelyhood; | 164 return calledInLoop; |
167 } | 165 } |
168 | 166 |
169 bool shouldInsertTypeGuard(HInstruction instruction) { | 167 bool shouldInsertTypeGuard(HInstruction instruction) { |
170 HType speculativeType = instruction.propagatedType; | 168 HType speculativeType = instruction.propagatedType; |
171 HType computedType = instruction.computeTypeFromInputTypes(); | 169 HType computedType = instruction.computeTypeFromInputTypes(); |
172 // Start by reverting the propagated type. If we add a type guard then the | 170 // Start by reverting the propagated type. If we add a type guard then the |
173 // guard will expose the speculative type. If we don't add a type guard | 171 // guard will expose the speculative type. If we don't add a type guard |
174 // then this avoids subsequent instructions to use the the wrong type. | 172 // then this avoids subsequent instructions to use the the wrong type. |
175 // | 173 // |
176 // Note that just setting the propagatedType of the instruction is not | 174 // Note that just setting the propagatedType of the instruction is not |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 hasComplexTypeGuards = true; | 534 hasComplexTypeGuards = true; |
537 } | 535 } |
538 } else { | 536 } else { |
539 hasComplexTypeGuards = true; | 537 hasComplexTypeGuards = true; |
540 blocks.forEach((HBasicBlock block) { | 538 blocks.forEach((HBasicBlock block) { |
541 block.guards.add(guard); | 539 block.guards.add(guard); |
542 }); | 540 }); |
543 } | 541 } |
544 } | 542 } |
545 } | 543 } |
OLD | NEW |