Chromium Code Reviews| Index: runtime/vm/intermediate_language.cc |
| =================================================================== |
| --- runtime/vm/intermediate_language.cc (revision 10862) |
| +++ runtime/vm/intermediate_language.cc (working copy) |
| @@ -59,6 +59,16 @@ |
| } |
| +const Object& UseVal::BoundConstant() const { |
| + ASSERT(BindsToConstant()); |
| + BindInstr* bind = definition()->AsBind(); |
| + ASSERT(bind != NULL); |
| + ConstantVal* constant = bind->computation()->AsConstant(); |
| + ASSERT(constant != NULL); |
| + return constant->value(); |
| +} |
| + |
| + |
| void UseVal::RemoveFromUseList() { |
| ASSERT(definition_ != NULL); |
| if (next_use_ != NULL) { |
| @@ -736,16 +746,42 @@ |
| } |
| +intptr_t EqualityCompareComp::ResultCid() const { |
| + if ((receiver_class_id() == kSmiCid) || |
| + (receiver_class_id() == kDoubleCid) || |
| + (receiver_class_id() == kNumberCid)) { |
| + // Known/library equalities that are guaranteed to return Boolean. |
| + return kBoolCid; |
| + } |
| + if (HasICData() && ic_data()->AllTargetsHaveSameOwner(kInstanceCid)) { |
| + return kBoolCid; |
| + } |
| + return kDynamicCid; |
| +} |
| + |
| + |
| RawAbstractType* RelationalOpComp::CompileType() const { |
| if ((operands_class_id() == kSmiCid) || |
| (operands_class_id() == kDoubleCid) || |
| (operands_class_id() == kNumberCid)) { |
| + // Known/library relational ops that are guaranteed to return Boolean. |
| return Type::BoolInterface(); |
| } |
| return Type::DynamicType(); |
| } |
| +intptr_t RelationalOpComp::ResultCid() const { |
| + if ((operands_class_id() == kSmiCid) || |
| + (operands_class_id() == kDoubleCid) || |
| + (operands_class_id() == kNumberCid)) { |
| + // Known/library relational ops that are guaranteed to return Boolean. |
| + return kBoolCid; |
| + } |
| + return kDynamicCid; |
| +} |
| + |
| + |
| RawAbstractType* NativeCallComp::CompileType() const { |
| // The result type of the native function is identical to the result type of |
| // the enclosing native Dart function. However, we prefer to check the type |
| @@ -877,30 +913,44 @@ |
| RawAbstractType* BinaryOpComp::CompileType() const { |
| - // TODO(srdjan): Convert to use with class-ids instead of types. |
| + ObjectStore* object_store = Isolate::Current()->object_store(); |
| if (operands_type() == kMintOperands) { |
| - return Isolate::Current()->object_store()->mint_type(); |
| - } else if (op_kind() == Token::kSHL) { |
| + return object_store->mint_type(); |
| + } |
| + if (op_kind() == Token::kSHL) { |
| return Type::IntInterface(); |
| - } else { |
| - ASSERT(operands_type() == kSmiOperands); |
| - return Isolate::Current()->object_store()->smi_type(); |
| } |
| + ASSERT(operands_type() == kSmiOperands); |
| + return object_store->smi_type(); |
| } |
| +intptr_t BinaryOpComp::ResultCid() const { |
| + if (operands_type() == kMintOperands) { |
| + return kMintCid; |
| + } |
| + ASSERT(operands_type() == kSmiOperands); |
| + return (op_kind() == Token::kSHL) ? kDynamicCid : kSmiCid; |
| +} |
| + |
| + |
| RawAbstractType* DoubleBinaryOpComp::CompileType() const { |
| return Type::DoubleInterface(); |
| } |
| +intptr_t DoubleBinaryOpComp::ResultCid() const { |
| + return kDoubleCid; |
| +} |
| + |
| + |
| RawAbstractType* UnarySmiOpComp::CompileType() const { |
| return Type::IntInterface(); |
| } |
| RawAbstractType* NumberNegateComp::CompileType() const { |
| - return Type::NumberInterface(); |
| + return Type::DoubleInterface(); |
|
regis
2012/08/16 21:43:52
Why?
srdjan
2012/08/16 22:11:06
Adding comment:
Implemented only for doubles.
Add
|
| } |
| @@ -1118,24 +1168,23 @@ |
| Definition* StrictCompareComp::TryReplace(BindInstr* instr) { |
| - // TODO(srdjan): Do not use CompileType for class check elimination. |
| - return NULL; |
| UseVal* left_use = left()->AsUse(); |
| UseVal* right_use = right()->AsUse(); |
| if ((right_use == NULL) || (left_use == NULL)) return NULL; |
| + if (!right_use->BindsToConstant()) return NULL; |
| + const Object& right_constant = right_use->BoundConstant(); |
| Definition* left = left_use->definition(); |
| - BindInstr* right = right_use->definition()->AsBind(); |
| - if (right == NULL) return NULL; |
| - ConstantVal* right_constant = right->computation()->AsConstant(); |
| - if (right_constant == NULL) return NULL; |
| // TODO(fschneider): Handle other cases: e === false and e !== true/false. |
| // Handles e === true. |
| if ((kind() == Token::kEQ_STRICT) && |
| - (right_constant->value().raw() == Bool::True()) && |
| - left_use->CompileTypeIsMoreSpecificThan( |
| - Type::Handle(Type::BoolInterface()))) { |
| + (right_constant.raw() == Bool::True()) && |
| + (left_use->ResultCid() == kBoolCid)) { |
| // Remove the constant from the graph. |
| - right->RemoveFromGraph(); |
| + BindInstr* right = right_use->definition()->AsBind(); |
| + if (right != NULL) { |
| + right->set_use_list(NULL); |
| + right->RemoveFromGraph(); |
| + } |
| // Return left subexpression as the replacement for this instruction. |
| return left; |
| } |