Chromium Code Reviews| Index: lib/compiler/implementation/ssa/bailout.dart |
| diff --git a/lib/compiler/implementation/ssa/bailout.dart b/lib/compiler/implementation/ssa/bailout.dart |
| index dcc64081ebc7df3f00dbfc8ae180aba2690a5e86..72ebf53a285cae3459dfed1b2eee890975f85a7c 100644 |
| --- a/lib/compiler/implementation/ssa/bailout.dart |
| +++ b/lib/compiler/implementation/ssa/bailout.dart |
| @@ -111,6 +111,27 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase { |
| } |
| } |
| + bool typeGuardWouldBeValuable(HInstruction instruction, |
| + HType speculativeType) { |
| + bool isMoreNested(HBasicBlock loopHeader1, HBasicBlock loopHeader2) { |
|
kasperl
2012/04/20 12:07:31
isNestedInside? You're checking if loop1 is inside
floitsch
2012/04/20 12:43:47
Done.
|
| + if (loopHeader1 == loopHeader2) return false; |
|
kasperl
2012/04/20 12:07:31
Is this a place where === makes sense?
floitsch
2012/04/20 12:43:47
Done.
|
| + if (loopHeader2 == null) return true; |
| + while (loopHeader1 != null) { |
| + if (loopHeader1 == loopHeader2) return true; |
| + loopHeader1 = loopHeader1.parentLoopHeader; |
| + } |
| + return false; |
| + } |
| + |
| + // If the instruction is not in a loop then the header will be null. |
| + HBasicBlock currentLoopHeader = instruction.block.getEnclosingLoopHeader(); |
| + for (HInstruction user in instruction.usedBy) { |
| + HBasicBlock userLoopHeader = user.block.getEnclosingLoopHeader(); |
| + if (isMoreNested(userLoopHeader, currentLoopHeader)) return true; |
| + } |
| + return false; |
| + } |
| + |
| bool shouldInsertTypeGuard(HInstruction instruction) { |
| HType speculativeType = instruction.propagatedType; |
| HType computedType = instruction.computeTypeFromInputTypes(); |
| @@ -128,8 +149,9 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase { |
| if (!speculativeType.isUseful()) return false; |
| // If the types agree we don't need to check. |
| if (speculativeType == computedType) return false; |
| - // TODO(floitsch): Make the creation of type guards more conditional. |
| - return true; |
| + // If a bailout check is more expensive than doing the actual operation |
| + // don't do it either. |
| + return typeGuardWouldBeValuable(instruction, speculativeType); |
| } |
| void visitInstruction(HInstruction instruction) { |