[turbofan] Improve typing of JSToNumber.

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/786703002

Cr-Commit-Position: refs/heads/master@{#25698}
This commit is contained in:
Benedikt Meurer 2014-12-08 09:28:10 +01:00
parent 75dbd0d352
commit 1a05ece305
2 changed files with 19 additions and 3 deletions

View File

@ -162,11 +162,13 @@ Typer::Typer(Graph* graph, MaybeHandle<Context> context)
Type::Constant(minusinfinity, zone), zone),
nan_or_minuszero, zone);
boolean_or_number = Type::Union(Type::Boolean(), Type::Number(), zone);
undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone);
undefined_or_number = Type::Union(Type::Undefined(), Type::Number(), zone);
negative_signed32 = Type::Union(
Type::SignedSmall(), Type::OtherSigned32(), zone);
non_negative_signed32 = Type::Union(
Type::UnsignedSmall(), Type::OtherUnsigned31(), zone);
undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone);
singleton_false = Type::Constant(f->false_value(), zone);
singleton_true = Type::Constant(f->true_value(), zone);
singleton_zero = Type::Range(zero, zero, zone);
@ -520,10 +522,22 @@ Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) {
Type* Typer::Visitor::ToNumber(Type* type, Typer* t) {
if (type->Is(Type::Number())) return type;
if (type->Is(Type::Null())) return t->singleton_zero;
if (type->Is(Type::Undefined())) return Type::NaN();
if (type->Is(t->undefined_or_null)) {
return Type::Union(Type::NaN(), t->singleton_zero, t->zone());
}
if (type->Is(t->undefined_or_number)) {
return Type::Union(Type::Intersect(type, Type::Number(), t->zone()),
Type::NaN(), t->zone());
}
if (type->Is(t->singleton_false)) return t->singleton_zero;
if (type->Is(t->singleton_true)) return t->singleton_one;
if (type->Is(Type::Boolean())) return t->zero_or_one;
if (type->Is(t->boolean_or_number)) {
return Type::Union(Type::Intersect(type, Type::Number(), t->zone()),
t->zero_or_one, t->zone());
}
return Type::Number();
}
@ -1172,7 +1186,7 @@ Bounds Typer::Visitor::TypeJSToBoolean(Node* node) {
Bounds Typer::Visitor::TypeJSToNumber(Node* node) {
return Bounds(Type::None(zone()), Type::Number(zone()));
return TypeUnaryOp(node, ToNumber);
}

View File

@ -38,9 +38,11 @@ class Typer {
Decorator* decorator_;
Zone* zone_;
Type* boolean_or_number;
Type* undefined_or_null;
Type* undefined_or_number;
Type* negative_signed32;
Type* non_negative_signed32;
Type* undefined_or_null;
Type* singleton_false;
Type* singleton_true;
Type* singleton_zero;