| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 instruction = instruction.next; | 100 instruction = instruction.next; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Primitive types that are not null are valuable. These include | 104 // Primitive types that are not null are valuable. These include |
| 105 // indexable arrays. | 105 // indexable arrays. |
| 106 bool typeValuable(HType type) { | 106 bool typeValuable(HType type) { |
| 107 return type.isPrimitive() && !type.isNull(); | 107 return type.isPrimitive() && !type.isNull(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 bool get hasTypeGuards() => work.guards.length != 0; |
| 111 |
| 110 bool typeGuardWouldBeValuable(HInstruction instruction, | 112 bool typeGuardWouldBeValuable(HInstruction instruction, |
| 111 HType speculativeType) { | 113 HType speculativeType) { |
| 112 // If the type itself is not valuable, do not generate a guard for it. | 114 // If the type itself is not valuable, do not generate a guard for it. |
| 113 if (!typeValuable(speculativeType)) return false; | 115 if (!typeValuable(speculativeType)) return false; |
| 114 | 116 |
| 115 // Do not insert a type guard if the instruction has a type | 117 // Do not insert a type guard if the instruction has a type |
| 116 // annotation that disagrees with the speculated type. | 118 // annotation that disagrees with the speculated type. |
| 117 Element source = instruction.sourceElement; | 119 Element source = instruction.sourceElement; |
| 118 if (source !== null) { | 120 if (source !== null) { |
| 119 Type sourceType = source.computeType(compiler); | 121 Type sourceType = source.computeType(compiler); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 138 return false; | 140 return false; |
| 139 } | 141 } |
| 140 | 142 |
| 141 // If the instruction is not in a loop then the header will be null. | 143 // If the instruction is not in a loop then the header will be null. |
| 142 HBasicBlock currentLoopHeader = instruction.block.enclosingLoopHeader; | 144 HBasicBlock currentLoopHeader = instruction.block.enclosingLoopHeader; |
| 143 for (HInstruction user in instruction.usedBy) { | 145 for (HInstruction user in instruction.usedBy) { |
| 144 HBasicBlock userLoopHeader = user.block.enclosingLoopHeader; | 146 HBasicBlock userLoopHeader = user.block.enclosingLoopHeader; |
| 145 if (isNested(userLoopHeader, currentLoopHeader)) return true; | 147 if (isNested(userLoopHeader, currentLoopHeader)) return true; |
| 146 } | 148 } |
| 147 | 149 |
| 150 // To speed up computations on values loaded from arrays, we |
| 151 // insert type guards for builtin array indexing operations in |
| 152 // nested loops. Since this can blow up code size quite |
| 153 // significantly, we only do it if type guards have already been |
| 154 // inserted for this method. The code size price for an additional |
| 155 // type guard is much smaller than the first one that causes the |
| 156 // generation of a bailout method. |
| 157 if (instruction is HIndex && instruction.builtin && hasTypeGuards) { |
| 158 HBasicBlock loopHeader = instruction.block.enclosingLoopHeader; |
| 159 if (loopHeader != null && loopHeader.parentLoopHeader != null) { |
| 160 return true; |
| 161 } |
| 162 } |
| 163 |
| 148 // Insert type guards if the method is likely to be called in a | 164 // Insert type guards if the method is likely to be called in a |
| 149 // loop. | 165 // loop. |
| 150 return calledInLoop || highTypeLikelyhood; | 166 return calledInLoop || highTypeLikelyhood; |
| 151 } | 167 } |
| 152 | 168 |
| 153 bool shouldInsertTypeGuard(HInstruction instruction) { | 169 bool shouldInsertTypeGuard(HInstruction instruction) { |
| 154 HType speculativeType = instruction.propagatedType; | 170 HType speculativeType = instruction.propagatedType; |
| 155 HType computedType = instruction.computeTypeFromInputTypes(); | 171 HType computedType = instruction.computeTypeFromInputTypes(); |
| 156 // Start by reverting the propagated type. If we add a type guard then the | 172 // Start by reverting the propagated type. If we add a type guard then the |
| 157 // guard will expose the speculative type. If we don't add a type guard | 173 // guard will expose the speculative type. If we don't add a type guard |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 hasComplexTypeGuards = true; | 536 hasComplexTypeGuards = true; |
| 521 } | 537 } |
| 522 } else { | 538 } else { |
| 523 hasComplexTypeGuards = true; | 539 hasComplexTypeGuards = true; |
| 524 blocks.forEach((HBasicBlock block) { | 540 blocks.forEach((HBasicBlock block) { |
| 525 block.guards.add(guard); | 541 block.guards.add(guard); |
| 526 }); | 542 }); |
| 527 } | 543 } |
| 528 } | 544 } |
| 529 } | 545 } |
| OLD | NEW |