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

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

Issue 10106004: Revert "Refactor type propagation." (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
« no previous file with comments | « lib/compiler/implementation/ssa/bailout.dart ('k') | lib/compiler/implementation/ssa/optimize.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/ssa/nodes.dart
diff --git a/lib/compiler/implementation/ssa/nodes.dart b/lib/compiler/implementation/ssa/nodes.dart
index 30134858fcc2127d3aef2a4a40d8191ec159a48e..64b85d6987875bca57fb19d0aa5045f040fec44b 100644
--- a/lib/compiler/implementation/ssa/nodes.dart
+++ b/lib/compiler/implementation/ssa/nodes.dart
@@ -788,8 +788,7 @@ class HType {
bool isNumber() => (this.flag & (FLAG_INTEGER | FLAG_DOUBLE)) != 0;
bool isStringOrArray() =>
(this.flag & (FLAG_STRING | FLAG_READABLE_ARRAY)) != 0;
- /** A type is useful it is not unknown and not conflicting. */
- bool isUseful() => this !== UNKNOWN && this !== CONFLICTING;
+ bool isKnown() => this !== UNKNOWN && this !== CONFLICTING;
static HType getTypeFromFlag(int flag) {
if (flag === CONFLICTING.flag) return CONFLICTING;
@@ -837,6 +836,7 @@ class HInstruction implements Hashable {
HInstruction previous = null;
HInstruction next = null;
int flags = 0;
+ HType type = HType.UNKNOWN;
// Changes flags.
static final int FLAG_CHANGES_SOMETHING = 0;
@@ -848,11 +848,7 @@ class HInstruction implements Hashable {
// Other flags.
static final int FLAG_USE_GVN = FLAG_DEPENDS_ON_SOMETHING + 1;
- HInstruction(this.inputs)
- : id = idCounter++,
- usedBy = <HInstruction>[] {
- if (guaranteedType.isUseful()) propagatedType = guaranteedType;
- }
+ HInstruction(this.inputs) : id = idCounter++, usedBy = <HInstruction>[];
int hashCode() => id;
@@ -874,68 +870,24 @@ class HInstruction implements Hashable {
// Does this node potentially affect control flow.
bool isControlFlow() => false;
- // All isFunctions work on the propagated types.
- bool isArray() => propagatedType.isArray();
- bool isMutableArray() => propagatedType.isMutableArray();
- bool isBoolean() => propagatedType.isBoolean();
- bool isInteger() => propagatedType.isInteger();
- bool isDouble() => propagatedType.isDouble();
- bool isNumber() => propagatedType.isNumber();
- bool isString() => propagatedType.isString();
- bool isTypeUnknown() => propagatedType.isUnknown();
- bool isStringOrArray() => propagatedType.isStringOrArray();
+ bool isArray() => type.isArray();
+ bool isMutableArray() => type.isMutableArray();
+ bool isBoolean() => type.isBoolean();
+ bool isInteger() => type.isInteger();
+ bool isNumber() => type.isNumber();
+ bool isString() => type.isString();
+ bool isTypeUnknown() => type.isUnknown();
+ bool isStringOrArray() => type.isStringOrArray();
- /**
- * This is the type the instruction is guaranteed to have. It does not
- * take any propagation into account.
- */
- HType get guaranteedType() => HType.UNKNOWN;
- bool hasGuaranteedType() => !guaranteedType.isUnknown();
+ // Compute the type of the instruction.
+ HType computeType() => HType.UNKNOWN;
- /**
- * The [propagatedType] is the type the instruction is assumed to have.
- * Without speculative type assumptions it is computed frome the propagated
- * type of the instruction's inputs and does not any guess work.
- *
- * With speculative types [computeTypeFromInputTypes()] and [propagatedType]
- * may differ. In this case the instruction's type must be guarded.
- *
- * Note that the [propagatedType] may only be set to [HType.CONFLICTING] with
- * speculative types (as otherwise the instruction either sets the output
- * type to [HType.UNKNOWN] or a specific type.
- */
- HType propagatedType = HType.UNKNOWN;
+ HType computeDesiredInputType(HInstruction input) => HType.UNKNOWN;
- /**
- * Some instructions have a good idea of their return type, but cannot
- * guarantee the type. The [likelyType] does not need to be more specialized
- * than the [propagatedType].
- *
- * Examples: the [likelyType] of [:x == y:] is a boolean. In most cases this
- * cannot be guaranteed, but when merging types we still want to use this
- * information.
- *
- * Similarily the [HAdd] instruction is likely a number. Note that, even if
- * the [propagatedType] is already set to integer, the [likelyType] still
- * might just return the number type.
- */
- HType get likelyType() => propagatedType;
-
- /**
- * Compute the type of the instruction by propagating the input types through
- * the instruction.
- *
- * By default just copy the guaranteed type.
- */
- HType computeTypeFromInputTypes() => guaranteedType;
-
- /**
- * Compute the desired type for the the given [input]. Aside from using
- * other inputs to compute the desired type one should also use
- * the [propagatedType] which, during the invocation of this method,
- * represents the desired type of [this].
- */
- HType computeDesiredTypeForInput(HInstruction input) => HType.UNKNOWN;
+ // Returns whether the instruction does produce the type it claims.
+ // For most instructions, this returns false. A type guard will be
+ // inserted to make sure the users get the right type in.
+ bool hasExpectedType() => false;
bool isInBasicBlock() => block !== null;
@@ -1049,7 +1001,8 @@ class HBoolify extends HInstruction {
setUseGvn();
}
- HType get guaranteedType() => HType.BOOLEAN;
+ HType computeType() => HType.BOOLEAN;
+ bool hasExpectedType() => true;
accept(HVisitor visitor) => visitor.visitBoolify(this);
int typeCode() => 0;
@@ -1077,16 +1030,21 @@ class HTypeGuard extends HInstruction {
HInstruction get guarded() => inputs.last();
+ HType computeType() => type;
+ bool hasExpectedType() => true;
+
bool isControlFlow() => true;
accept(HVisitor visitor) => visitor.visitTypeGuard(this);
int typeCode() => 1;
bool typeEquals(other) => other is HTypeGuard;
- bool dataEquals(HTypeGuard other) => propagatedType == other.propagatedType;
+ bool dataEquals(HTypeGuard other) => type == other.type;
}
class HBoundsCheck extends HCheck {
- HBoundsCheck(length, index) : super(<HInstruction>[length, index]);
+ HBoundsCheck(length, index) : super(<HInstruction>[length, index]) {
+ type = HType.INTEGER;
+ }
HInstruction get length() => inputs[0];
HInstruction get index() => inputs[1];
@@ -1096,7 +1054,8 @@ class HBoundsCheck extends HCheck {
setUseGvn();
}
- HType get guaranteedType() => HType.INTEGER;
+ HType computeType() => HType.INTEGER;
+ bool hasExpectedType() => true;
accept(HVisitor visitor) => visitor.visitBoundsCheck(this);
int typeCode() => 2;
@@ -1114,7 +1073,8 @@ class HIntegerCheck extends HCheck {
setUseGvn();
}
- HType get guaranteedType() => HType.INTEGER;
+ HType computeType() => HType.INTEGER;
+ bool hasExpectedType() => true;
accept(HVisitor visitor) => visitor.visitIntegerCheck(this);
int typeCode() => 3;
@@ -1219,24 +1179,15 @@ class HInvokeStatic extends HInvoke {
&& element.enclosingElement.name.slowToString() == 'List');
}
- HType get guaranteedType() {
+ HType computeType() {
if (isArrayConstructor()) {
return HType.MUTABLE_ARRAY;
}
return HType.UNKNOWN;
}
- HType computeDesiredTypeForInput(HInstruction input) {
- // TODO(floitsch): we want the target to be a function.
- if (input == target) return HType.UNKNOWN;
- return computeDesiredTypeForNonTargetInput(input);
- }
-
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- return HType.UNKNOWN;
- }
-
bool get builtin() => isArrayConstructor();
+ bool hasExpectedType() => isArrayConstructor();
}
class HInvokeSuper extends HInvokeStatic {
@@ -1257,14 +1208,10 @@ class HInvokeInterceptor extends HInvokeStatic {
toString() => 'invoke interceptor: ${element.name}';
accept(HVisitor visitor) => visitor.visitInvokeInterceptor(this);
- bool isLengthGetterOnStringOrArray() {
- return getter
- && name == const SourceString('length')
- && inputs[1].isStringOrArray();
- }
-
String get builtinJsName() {
- if (isLengthGetterOnStringOrArray()) {
+ if (getter
+ && name == const SourceString('length')
+ && inputs[1].isStringOrArray()) {
return 'length';
} else if (name == const SourceString('add')
&& inputs[1].isMutableArray()) {
@@ -1276,23 +1223,17 @@ class HInvokeInterceptor extends HInvokeStatic {
return null;
}
- HType get guaranteedType() => HType.UNKNOWN;
-
- HType get likelyType() {
- // In general a length getter or method returns an int.
- if (name == const SourceString('length')) return HType.INTEGER;
- return HType.UNKNOWN;
- }
-
- HType computeTypeFromInputTypes() {
- if (isLengthGetterOnStringOrArray()) return HType.INTEGER;
+ HType computeType() {
+ if (getter
+ && name == const SourceString('length')
+ && inputs[1].isStringOrArray()) {
+ return HType.INTEGER;
+ }
return HType.UNKNOWN;
}
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // If the first argument is a string or an array and we invoke methods
- // on it that mutate it, then we want to restrict the incoming type to be
- // a mutable array.
+ HType computeDesiredInputType(HInstruction input) {
+ if (input == inputs[0]) return HType.UNKNOWN;
if (input == inputs[1] && input.isStringOrArray()) {
if (name == const SourceString('add')
|| name == const SourceString('removeLast')) {
@@ -1302,8 +1243,10 @@ class HInvokeInterceptor extends HInvokeStatic {
return HType.UNKNOWN;
}
+ bool hasExpectedType() => builtinJsName != null;
+
void prepareGvn() {
- if (isLengthGetterOnStringOrArray()) {
+ if (builtinJsName == 'length') {
clearAllSideEffects();
} else {
setAllSideEffects();
@@ -1346,13 +1289,12 @@ class HFieldSet extends HInstruction {
class HForeign extends HInstruction {
final DartString code;
- final HType foreignType;
- HForeign(this.code, DartString declaredType, List<HInstruction> inputs)
- : foreignType = computeTypeFromDeclaredType(declaredType),
- super(inputs);
+ final DartString declaredType;
+ HForeign(this.code, this.declaredType, List<HInstruction> inputs)
+ : super(inputs);
accept(HVisitor visitor) => visitor.visitForeign(this);
- static HType computeTypeFromDeclaredType(DartString declaredType) {
+ HType computeType() {
if (declaredType.slowToString() == 'bool') return HType.BOOLEAN;
if (declaredType.slowToString() == 'int') return HType.INTEGER;
if (declaredType.slowToString() == 'num') return HType.NUMBER;
@@ -1360,7 +1302,7 @@ class HForeign extends HInstruction {
return HType.UNKNOWN;
}
- HType get guaranteedType() => foreignType;
+ bool hasExpectedType() => true;
}
class HForeignNew extends HForeign {
@@ -1378,6 +1320,15 @@ class HInvokeBinary extends HInvokeStatic {
HInstruction get left() => inputs[1];
HInstruction get right() => inputs[2];
+ HType computeInputsType() {
+ HType leftType = left.type;
+ HType rightType = right.type;
+ if (leftType.isUnknown() || rightType.isUnknown()) {
+ return HType.UNKNOWN;
+ }
+ return leftType.combine(rightType);
+ }
+
abstract BinaryOperation get operation();
}
@@ -1399,33 +1350,22 @@ class HBinaryArithmetic extends HInvokeBinary {
bool get builtin() => left.isNumber() && right.isNumber();
- HType computeTypeFromInputTypes() {
- if (left.isInteger() && right.isInteger()) return left.propagatedType;
- if (left.isNumber()) {
- if (left.isDouble() || right.isDouble()) return HType.DOUBLE;
- return HType.NUMBER;
- }
- return HType.UNKNOWN;
- }
-
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // If the desired output type should be an integer we want to get two
- // integers as arguments.
- if (propagatedType.isInteger()) return HType.INTEGER;
- // If the outgoing type should be a number we can get that if both inputs
- // are numbers. If we don't know the outgoing type we try to make it a
- // number.
- if (propagatedType.isUnknown() || propagatedType.isNumber()) {
- return HType.NUMBER;
- }
+ HType computeType() {
+ HType inputsType = computeInputsType();
+ if (inputsType.isKnown()) return inputsType;
+ if (left.isNumber()) return HType.NUMBER;
return HType.UNKNOWN;
}
- HType get likelyType() {
- if (left.isTypeUnknown()) return HType.NUMBER;
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ if (isNumber() || left.isNumber() || right.isNumber()) return HType.NUMBER;
+ if (type.isUnknown()) return HType.NUMBER;
return HType.UNKNOWN;
}
+ bool hasExpectedType() => left.isNumber() && right.isNumber();
// TODO(1603): The class should be marked as abstract.
abstract BinaryOperation get operation();
}
@@ -1441,38 +1381,24 @@ class HAdd extends HBinaryArithmetic {
|| (left.isString() && right is HConstant);
}
- HType computeTypeFromInputTypes() {
- if (left.isInteger() && right.isInteger()) return left.propagatedType;
- if (left.isNumber()) {
- if (left.isDouble() || right.isDouble()) return HType.DOUBLE;
- return HType.NUMBER;
- }
- if (left.isString()) return HType.STRING;
+ HType computeType() {
+ HType computedType = computeInputsType();
+ if (computedType.isConflicting() && left.isString()) return HType.STRING;
+ if (computedType.isKnown()) return computedType;
+ if (left.isNumber()) return HType.NUMBER;
return HType.UNKNOWN;
}
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // If the desired output type is an integer we want two integers as input.
- if (propagatedType.isInteger()) {
- return HType.INTEGER;
- }
- // TODO(floitsch): remove string specialization once string+ is removed
- // from dart2js.
- if (propagatedType.isString() || left.isString() || right.isString()) {
- return HType.STRING;
- }
- // If the desired output is a number or any of the inputs is a number
- // ask for a number. Note that we might return the input's (say 'left')
- // type depending on its (the 'left's) type. But that shouldn't matter.
- if (propagatedType.isNumber() || left.isNumber() || right.isNumber()) {
- return HType.NUMBER;
- }
- return HType.UNKNOWN;
- }
+ bool hasExpectedType() => builtin || type.isUnknown() || left.isString();
- HType get likelyType() {
- if (left.isString() || right.isString()) return HType.STRING;
- if (left.isTypeUnknown() || left.isNumber()) return HType.NUMBER;
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ if (isString() || left.isString()) {
+ return (input == left) ? HType.STRING : HType.UNKNOWN;
+ }
+ if (right.isString()) return HType.STRING;
+ if (isNumber() || left.isNumber() || right.isNumber()) return HType.NUMBER;
return HType.UNKNOWN;
}
@@ -1490,17 +1416,12 @@ class HDivide extends HBinaryArithmetic {
bool get builtin() => left.isNumber() && right.isNumber();
- HType computeTypeFromInputTypes() {
+ HType computeType() {
+ HType inputsType = computeInputsType();
if (left.isNumber()) return HType.DOUBLE;
return HType.UNKNOWN;
}
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // A division can never return an integer. So don't ask for integer inputs.
- if (propagatedType.isInteger()) return HType.UNKNOWN;
- return super.computeDesiredTypeForNonTargetInput(input);
- }
-
DivideOperation get operation() => const DivideOperation();
int typeCode() => 6;
bool typeEquals(other) => other is HDivide;
@@ -1561,24 +1482,17 @@ class HBinaryBitOp extends HBinaryArithmetic {
bool get builtin() => left.isInteger() && right.isInteger();
- HType computeTypeFromInputTypes() {
+ HType computeType() {
+ HType inputsType = computeInputsType();
+ if (inputsType.isKnown()) return inputsType;
if (left.isInteger()) return HType.INTEGER;
return HType.UNKNOWN;
}
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // If the outgoing type should be a number we can get that only if both
- // inputs are integers. If we don't know the outgoing type we try to make
- // it an integer.
- if (propagatedType.isUnknown() || propagatedType.isNumber()) {
- return HType.INTEGER;
- }
- return HType.UNKNOWN;
- }
-
- HType get likelyType() {
- if (left.isTypeUnknown()) return HType.INTEGER;
- return HType.UNKNOWN;
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ return HType.INTEGER;
}
// TODO(floitsch): make class abstract instead of adding an abstract method.
@@ -1660,22 +1574,20 @@ class HInvokeUnary extends HInvokeStatic {
bool get builtin() => operand.isNumber();
- HType computeTypeFromInputTypes() {
- HType operandType = operand.propagatedType;
- if (operandType.isNumber()) return operandType;
+ HType computeType() {
+ HType operandType = operand.type;
+ if (!operandType.isUnknown()) return operandType;
return HType.UNKNOWN;
}
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // If the outgoing type should be a number (integer, double or both) we
- // want the outgoing type to be the input too.
- // If we don't know the outgoing type we try to make it a number.
- if (propagatedType.isNumber()) return propagatedType;
- if (propagatedType.isUnknown()) return HType.NUMBER;
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ if (type.isUnknown() || type.isNumber()) return HType.NUMBER;
return HType.UNKNOWN;
}
- HType get likelyType() => HType.NUMBER;
+ bool hasExpectedType() => builtin || type.isUnknown();
abstract UnaryOperation get operation();
}
@@ -1696,19 +1608,16 @@ class HBitNot extends HInvokeUnary {
bool get builtin() => operand.isInteger();
- HType computeTypeFromInputTypes() {
- HType operandType = operand.propagatedType;
- if (operandType.isInteger()) return HType.INTEGER;
+ HType computeType() {
+ HType operandType = operand.type;
+ if (!operandType.isUnknown()) return operandType;
return HType.UNKNOWN;
}
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // Bit operations only work on integers. If there is no desired output
- // type or if it as a number we want to get an integer as input.
- if (propagatedType.isUnknown() || propagatedType.isNumber()) {
- return HType.INTEGER;
- }
- return HType.UNKNOWN;
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ return HType.INTEGER;
}
BitNotOperation get operation() => const BitNotOperation();
@@ -1797,9 +1706,9 @@ class HLoopBranch extends HConditionalBranch {
class HConstant extends HInstruction {
final Constant constant;
- final HType constantType;
- HConstant.internal(this.constant, HType this.constantType)
- : super(<HInstruction>[]);
+ HConstant.internal(this.constant, HType type) : super(<HInstruction>[]) {
+ this.type = type;
+ }
void prepareGvn() {
assert(!hasSideEffects());
@@ -1807,8 +1716,9 @@ class HConstant extends HInstruction {
toString() => 'literal: $constant';
accept(HVisitor visitor) => visitor.visitConstant(this);
+ HType computeType() => type;
- HType get guaranteedType() => constantType;
+ bool hasExpectedType() => true;
bool isConstant() => true;
bool isConstantBoolean() => constant.isBool();
@@ -1827,10 +1737,11 @@ class HNot extends HInstruction {
setUseGvn();
}
- HType get guaranteedType() => HType.BOOLEAN;
-
- // 'Not' only works on booleans. That's what we want as input.
- HType computeDesiredTypeForInput(HInstruction input) => HType.BOOLEAN;
+ HType computeType() => HType.BOOLEAN;
+ bool hasExpectedType() => true;
+ HType computeDesiredInputType(HInstruction input) {
+ return HType.BOOLEAN;
+ }
accept(HVisitor visitor) => visitor.visitNot(this);
int typeCode() => 18;
@@ -1886,48 +1797,35 @@ class HPhi extends HInstruction {
// have the same known type return it. If any two inputs have
// different known types, we'll return a conflict -- otherwise we'll
// simply return an unknown type.
- HType computeInputsType(bool unknownWins) {
+ HType computeInputsType() {
bool seenUnknown = false;
- HType candidateType = inputs[0].propagatedType;
+ HType candidateType = inputs[0].type;
for (int i = 1, length = inputs.length; i < length; i++) {
- HType inputType = inputs[i].propagatedType;
- if (inputType.isUnknown()) {
- seenUnknown = true;
- } else {
- candidateType = candidateType.combine(inputType);
- if (candidateType.isConflicting()) return HType.CONFLICTING;
- }
+ HType inputType = inputs[i].type;
+ if (inputType.isUnknown()) return HType.UNKNOWN;
+ candidateType = candidateType.combine(inputType);
+ if (candidateType.isConflicting()) return HType.CONFLICTING;
}
- if (seenUnknown && unknownWins) return HType.UNKNOWN;
return candidateType;
}
- HType computeTypeFromInputTypes() {
- HType inputsType = computeInputsType(true);
- if (inputsType.isConflicting()) return HType.UNKNOWN;
- return inputsType;
+ HType computeType() {
+ HType inputsType = computeInputsType();
+ if (!inputsType.isUnknown()) return inputsType;
+ return super.computeType();
}
- HType computeDesiredTypeForInput(HInstruction input) {
- // Best case scenario for a phi is, when all inputs have the same type. If
- // there is no desired outgoing type we therefore try to unify the input
- // types (which is basically the [likelyType]).
- if (propagatedType.isUnknown()) return likelyType;
- // When the desired outgoing type is conflicting we don't need to give any
- // requirements on the inputs.
- if (propagatedType.isConflicting()) return HType.UNKNOWN;
- // Otherwise the input type must match the desired outgoing type.
- return propagatedType;
+ HType computeDesiredInputType(HInstruction input) {
+ if (type.isNumber()) return HType.NUMBER;
+ if (type.isStringOrArray()) return HType.STRING_OR_ARRAY;
+ return type;
}
- HType get likelyType() {
- HType agreedType = computeInputsType(false);
- if (agreedType.isConflicting()) return HType.UNKNOWN;
- // Don't be too restrictive. If the agreed type is integer or double just
- // say that the likely type is number. If more is expected the type will be
- // propagated back.
- if (agreedType.isNumber()) return HType.NUMBER;
- return agreedType;
+ bool hasExpectedType() {
+ for (int i = 0; i < inputs.length; i++) {
+ if (type.combine(inputs[i].type).isConflicting()) return false;
+ }
+ return true;
}
bool isLogicalOperator() => logicalOperatorType != IS_NOT_LOGICAL_OPERATOR;
@@ -1945,7 +1843,9 @@ class HPhi extends HInstruction {
class HRelational extends HInvokeBinary {
HRelational(HStatic target, HInstruction left, HInstruction right)
- : super(target, left, right);
+ : super(target, left, right) {
+ type = HType.BOOLEAN;
+ }
void prepareGvn() {
// Relational expressions can take part in global value numbering
@@ -1959,24 +1859,19 @@ class HRelational extends HInvokeBinary {
}
}
- HType computeTypeFromInputTypes() {
- if (left.isNumber()) return HType.BOOLEAN;
- return HType.UNKNOWN;
- }
-
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- // For all relational operations exept HEquals, we expect to get numbers
- // only. With numbers the outgoing type is a boolean. If something else
- // is desired, then numbers are incorrect, though.
- if (propagatedType.isUnknown() || propagatedType.isBoolean()) {
- if (left.isTypeUnknown() || left.isNumber()) return HType.NUMBER;
- }
- return HType.UNKNOWN;
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ // For all relational operations exept HEquals, we expect to only
+ // get numbers.
+ return HType.NUMBER;
}
- HType get likelyType() => HType.BOOLEAN;
-
bool get builtin() => left.isNumber() && right.isNumber();
+ HType computeType() => HType.BOOLEAN;
+ // A HRelational goes through the builtin operator or the top level
+ // element. Therefore, it always has the expected type.
+ bool hasExpectedType() => true;
// TODO(1603): the class should be marked as abstract.
abstract BinaryOperation get operation();
}
@@ -1987,37 +1882,20 @@ class HEquals extends HRelational {
accept(HVisitor visitor) => visitor.visitEquals(this);
bool get builtin() {
- // All useful types have === semantics.
- // Note that this includes all constants except the user-constructed
- // objects.
- return left.isConstantNull() || left.propagatedType.isUseful();
+ if (left.isNumber() && right.isNumber()) return true;
+ if (left is !HConstant) return false;
+ HConstant leftConstant = left;
+ // TODO(floitsch): we can do better if we know that the constant does not
+ // have the equality operator overridden.
+ return !leftConstant.constant.isConstructedObject();
}
- HType computeTypeFromInputTypes() {
- if (builtin) return HType.BOOLEAN;
- return HType.UNKNOWN;
- }
+ HType computeType() => HType.BOOLEAN;
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- if (input == left && right.propagatedType.isUseful()) {
- // All our useful types have === semantics. But we don't want to
- // speculatively test for all possible types. Therefore we try to match
- // the two types. That is, if we see x == 3, then we speculatively test
- // if x is a number and bailout if it isn't.
- if (right.isNumber()) return HType.NUMBER; // No need to be more precise.
- // String equality testing is much more common than array equality
- // testing.
- if (right.isStringOrArray()) return HType.STRING;
- return right.propagatedType;
- }
- // String equality testing is much more common than array equality testing.
- if (input == left && left.isStringOrArray()) {
- return HType.READABLE_ARRAY;
- }
- // String equality testing is much more common than array equality testing.
- if (input == right && right.isStringOrArray()) {
- return HType.STRING;
- }
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ if (left.isNumber() || right.isNumber()) return HType.NUMBER;
return HType.UNKNOWN;
}
@@ -2033,11 +1911,10 @@ class HIdentity extends HRelational {
accept(HVisitor visitor) => visitor.visitIdentity(this);
bool get builtin() => true;
+ HType computeType() => HType.BOOLEAN;
+ bool hasExpectedType() => true;
- HType get guaranteedType() => HType.BOOLEAN;
- HType computeTypeFromInputTypes() => HType.BOOLEAN;
- // Note that the identity operator really does not care for its input types.
- HType computeDesiredTypeForInput(HInstruction input) => HType.UNKNOWN;
+ HType computeDesiredInputType(HInstruction input) => HType.UNKNOWN;
IdentityOperation get operation() => const IdentityOperation();
int typeCode() => 20;
@@ -2137,8 +2014,8 @@ class HLiteralList extends HInstruction {
HLiteralList(inputs) : super(inputs);
toString() => 'literal list';
accept(HVisitor visitor) => visitor.visitLiteralList(this);
-
- HType get guaranteedType() => HType.MUTABLE_ARRAY;
+ HType computeType() => HType.MUTABLE_ARRAY;
+ bool hasExpectedType() => true;
void prepareGvn() {
assert(!hasSideEffects());
@@ -2162,18 +2039,16 @@ class HIndex extends HInvokeStatic {
HInstruction get receiver() => inputs[1];
HInstruction get index() => inputs[2];
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- if (input == receiver && (index.isTypeUnknown() || index.isNumber())) {
- return HType.STRING_OR_ARRAY;
- }
- // The index should be an int when the receiver is a string or array.
- // However it turns out that inserting an integer check in the optimized
- // version is cheaper than having another bailout case. This is true,
- // because the integer check will simply throw if it fails.
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ if (input == receiver) return HType.STRING_OR_ARRAY;
return HType.UNKNOWN;
}
- bool get builtin() => receiver.isStringOrArray() && index.isInteger();
+ bool get builtin() => receiver.isStringOrArray();
+ HType computeType() => HType.UNKNOWN;
+ bool hasExpectedType() => false;
}
class HIndexAssign extends HInvokeStatic {
@@ -2190,21 +2065,18 @@ class HIndexAssign extends HInvokeStatic {
HInstruction get index() => inputs[2];
HInstruction get value() => inputs[3];
- // Note, that we don't have a computeTypeFromInputTypes, since [HIndexAssign]
- // is never used as input.
-
- HType computeDesiredTypeForNonTargetInput(HInstruction input) {
- if (input == receiver && (index.isTypeUnknown() || index.isNumber())) {
- return HType.MUTABLE_ARRAY;
- }
- // The index should be an int when the receiver is a string or array.
- // However it turns out that inserting an integer check in the optimized
- // version is cheaper than having another bailout case. This is true,
- // because the integer check will simply throw if it fails.
+ HType computeDesiredInputType(HInstruction input) {
+ // TODO(floitsch): we want the target to be a function.
+ if (input == target) return HType.UNKNOWN;
+ if (input == receiver) return HType.MUTABLE_ARRAY;
return HType.UNKNOWN;
}
- bool get builtin() => receiver.isMutableArray() && index.isInteger();
+ bool get builtin() => receiver.isMutableArray();
+ HType computeType() => value.type;
+ // This instruction does not yield a new value, so it always
+ // has the expected type (void).
+ bool hasExpectedType() => true;
}
class HIs extends HInstruction {
@@ -2216,7 +2088,8 @@ class HIs extends HInstruction {
HInstruction get expression() => inputs[0];
- HType get guaranteedType() => HType.BOOLEAN;
+ HType computeType() => HType.BOOLEAN;
+ bool hasExpectedType() => true;
accept(HVisitor visitor) => visitor.visitIs(this);
« no previous file with comments | « lib/compiler/implementation/ssa/bailout.dart ('k') | lib/compiler/implementation/ssa/optimize.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698