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

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

Issue 10827180: Move types out of the HInstructions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Cosmetic change (updated comment). Created 8 years, 4 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 2b9983647a8ae2a3b7b2fec9147fc8d24046d831..22a58b434b27dab37650d9c8c8c87f5c3a5d6cdb 100644
--- a/lib/compiler/implementation/ssa/bailout.dart
+++ b/lib/compiler/implementation/ssa/bailout.dart
@@ -67,13 +67,13 @@ class Environment {
* Visits the graph in dominator order and inserts TypeGuards in places where
* we consider the guard to be of value.
*
- * Might modify the [:propagatedType:] fields of the instructions in an
- * inconsistent way. No further analysis should rely on them.
+ * Might modify the [:types:] of the work item in an inconsistent way.
+ * No further analysis should rely on them.
*/
class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase {
final Compiler compiler;
final String name = 'SsaTypeGuardInserter';
- final WorkItem work;
+ final JavaScriptWorkItem work;
bool calledInLoop = false;
bool isRecursiveMethod = false;
int stateId = 1;
@@ -145,6 +145,7 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase {
if (isNested(userLoopHeader, currentLoopHeader)) return true;
}
+ HTypeMap types = work.types;
// To speed up computations on values loaded from arrays, we
// insert type guards for builtin array indexing operations in
// nested loops. Since this can blow up code size quite
@@ -153,7 +154,7 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase {
// type guard is much smaller than the first one that causes the
// generation of a bailout method.
if (instruction is HIndex &&
- (instruction as HIndex).builtin &&
+ (instruction as HIndex).isBuiltin(types) &&
hasTypeGuards) {
HBasicBlock loopHeader = instruction.block.enclosingLoopHeader;
if (loopHeader != null && loopHeader.parentLoopHeader != null) {
@@ -166,20 +167,9 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase {
return calledInLoop;
}
- bool shouldInsertTypeGuard(HInstruction instruction) {
- HType speculativeType = instruction.propagatedType;
- HType computedType = instruction.computeTypeFromInputTypes();
- // Start by reverting the propagated type. If we add a type guard then the
- // guard will expose the speculative type. If we don't add a type guard
- // then this avoids subsequent instructions to use the the wrong type.
- //
- // Note that just setting the propagatedType of the instruction is not
- // complete since the type could lead to a phi node which in turn could
- // change the computedType. In this case we might miss some guards we
- // would have liked to insert. Most of the time this should however be
- // fine, due to dominator-order visiting.
- instruction.propagatedType = computedType;
-
+ bool shouldInsertTypeGuard(HInstruction instruction,
+ HType speculativeType,
+ HType computedType) {
if (!speculativeType.isUseful()) return false;
// If the types agree we don't need to check.
if (speculativeType == computedType) return false;
@@ -189,8 +179,21 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase {
}
void visitInstruction(HInstruction instruction) {
- HType speculativeType = instruction.propagatedType;
- if (shouldInsertTypeGuard(instruction)) {
+ HTypeMap types = work.types;
+ HType speculativeType = types[instruction];
+ HType computedType = instruction.computeTypeFromInputTypes(types);
+ // Start by reverting the propagated type. If we add a type guard then the
Lasse Reichstein Nielsen 2012/08/08 07:44:53 How do you revert a type? "propagated" isn't menti
floitsch 2012/08/08 19:18:37 Done.
+ // guard will expose the speculative type. If we don't add a type guard
+ // then this avoids subsequent instructions to use the the wrong type.
Lasse Reichstein Nielsen 2012/08/08 07:44:53 "avoids ... to use" -> "avoids ... using" "the the
floitsch 2012/08/08 19:18:37 reworded.
+ //
+ // Note that just setting the speculative type of the instruction is not
+ // complete since the type could lead to a phi node which in turn could
+ // change the speculative type. In this case we might miss some guards we
+ // would have liked to insert. Most of the time this should however be
+ // fine, due to dominator-order visiting.
+ types[instruction] = computedType;
+
+ if (shouldInsertTypeGuard(instruction, speculativeType, computedType)) {
HInstruction insertionPoint;
if (instruction is HPhi) {
insertionPoint = instruction.block.first;
@@ -218,7 +221,7 @@ class SsaTypeGuardInserter extends HGraphVisitor implements OptimizationPhase {
insertionPoint.block.addBefore(insertionPoint, target);
}
HTypeGuard guard = new HTypeGuard(speculativeType, instruction, target);
- guard.propagatedType = speculativeType;
+ types[guard] = speculativeType;
work.guards.add(guard);
instruction.block.rewrite(instruction, guard);
insertionPoint.block.addBefore(insertionPoint, guard);

Powered by Google App Engine
This is Rietveld 408576698