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

Unified Diff: lib/compiler/implementation/ssa/bailout.dart

Issue 10165004: Only emit typeguards if we think they are valuable. (Closed) Base URL: https://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 side-by-side diff with in-line comments
Download patch
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) {
« no previous file with comments | « no previous file | lib/compiler/implementation/ssa/nodes.dart » ('j') | lib/compiler/implementation/ssa/nodes.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698