Commit e7609ecb authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Improve typing rules for various builtins.

Sanitize the typing rules for the various supported Math builtins, and
add appropriate typing rules for various Number, String, Object and global
builtins as well.

R=franzih@chromium.org

Review-Url: https://codereview.chromium.org/2222053002
Cr-Commit-Position: refs/heads/master@{#38472}
parent a8a7794e
...@@ -452,6 +452,15 @@ Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, ...@@ -452,6 +452,15 @@ Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
len, adapt, attrs); len, adapt, attrs);
} }
Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base,
const char* name, Builtins::Name call,
int len, bool adapt,
BuiltinFunctionId id) {
Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt);
fun->shared()->set_builtin_function_id(id);
return fun;
}
Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base,
Handle<String> name, Builtins::Name call, Handle<String> name, Builtins::Name call,
bool adapt) { bool adapt) {
...@@ -3055,27 +3064,29 @@ bool Genesis::InstallNatives(GlobalContextType context_type) { ...@@ -3055,27 +3064,29 @@ bool Genesis::InstallNatives(GlobalContextType context_type) {
// Install Global.decodeURI. // Install Global.decodeURI.
SimpleInstallFunction(global_object, "decodeURI", Builtins::kGlobalDecodeURI, SimpleInstallFunction(global_object, "decodeURI", Builtins::kGlobalDecodeURI,
1, false); 1, false, kGlobalDecodeURI);
// Install Global.decodeURIComponent. // Install Global.decodeURIComponent.
SimpleInstallFunction(global_object, "decodeURIComponent", SimpleInstallFunction(global_object, "decodeURIComponent",
Builtins::kGlobalDecodeURIComponent, 1, false); Builtins::kGlobalDecodeURIComponent, 1, false,
kGlobalDecodeURIComponent);
// Install Global.encodeURI. // Install Global.encodeURI.
SimpleInstallFunction(global_object, "encodeURI", Builtins::kGlobalEncodeURI, SimpleInstallFunction(global_object, "encodeURI", Builtins::kGlobalEncodeURI,
1, false); 1, false, kGlobalEncodeURI);
// Install Global.encodeURIComponent. // Install Global.encodeURIComponent.
SimpleInstallFunction(global_object, "encodeURIComponent", SimpleInstallFunction(global_object, "encodeURIComponent",
Builtins::kGlobalEncodeURIComponent, 1, false); Builtins::kGlobalEncodeURIComponent, 1, false,
kGlobalEncodeURIComponent);
// Install Global.escape. // Install Global.escape.
SimpleInstallFunction(global_object, "escape", Builtins::kGlobalEscape, 1, SimpleInstallFunction(global_object, "escape", Builtins::kGlobalEscape, 1,
false); false, kGlobalEscape);
// Install Global.unescape. // Install Global.unescape.
SimpleInstallFunction(global_object, "unescape", Builtins::kGlobalUnescape, 1, SimpleInstallFunction(global_object, "unescape", Builtins::kGlobalUnescape, 1,
false); false, kGlobalUnescape);
// Install Global.eval. // Install Global.eval.
{ {
......
...@@ -1292,21 +1292,27 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) { ...@@ -1292,21 +1292,27 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
// Unary math functions. // Unary math functions.
case kMathAbs: case kMathAbs:
case kMathExp: case kMathExp:
case kMathExpm1:
return Type::Union(Type::PlainNumber(), Type::NaN(), t->zone()); return Type::Union(Type::PlainNumber(), Type::NaN(), t->zone());
case kMathLog:
case kMathSqrt:
case kMathCos:
case kMathSin:
case kMathTan:
case kMathAcos: case kMathAcos:
case kMathAcosh: case kMathAcosh:
case kMathAsin: case kMathAsin:
case kMathAsinh: case kMathAsinh:
case kMathAtan: case kMathAtan:
case kMathAtanh: case kMathAtanh:
case kMathCbrt:
case kMathCos:
case kMathFround: case kMathFround:
case kMathSign: case kMathLog:
case kMathLog1p:
case kMathLog10:
case kMathLog2:
case kMathSin:
case kMathSqrt:
case kMathTan:
return Type::Number(); return Type::Number();
case kMathSign:
return t->cache_.kMinusOneToOne;
// Binary math functions. // Binary math functions.
case kMathAtan2: case kMathAtan2:
case kMathPow: case kMathPow:
...@@ -1317,6 +1323,11 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) { ...@@ -1317,6 +1323,11 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
return Type::Signed32(); return Type::Signed32();
case kMathClz32: case kMathClz32:
return t->cache_.kZeroToThirtyTwo; return t->cache_.kZeroToThirtyTwo;
// Number functions.
case kNumberParseInt:
return t->cache_.kIntegerOrMinusZeroOrNaN;
case kNumberToString:
return Type::String();
// String functions. // String functions.
case kStringCharCodeAt: case kStringCharCodeAt:
return Type::Union(Type::Range(0, kMaxUInt16, t->zone()), Type::NaN(), return Type::Union(Type::Range(0, kMaxUInt16, t->zone()), Type::NaN(),
...@@ -1324,13 +1335,25 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) { ...@@ -1324,13 +1335,25 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
case kStringCharAt: case kStringCharAt:
case kStringConcat: case kStringConcat:
case kStringFromCharCode: case kStringFromCharCode:
case kStringSubstr:
case kStringToLowerCase: case kStringToLowerCase:
case kStringToUpperCase: case kStringToUpperCase:
return Type::String(); return Type::String();
// Array functions. // Array functions.
case kArrayIndexOf: case kArrayIndexOf:
case kArrayLastIndexOf: case kArrayLastIndexOf:
return Type::Number(); return Type::Range(-1, kMaxSafeInteger, t->zone());
// Object functions.
case kObjectHasOwnProperty:
return Type::Boolean();
// Global functions.
case kGlobalDecodeURI:
case kGlobalDecodeURIComponent:
case kGlobalEncodeURI:
case kGlobalEncodeURIComponent:
case kGlobalEscape:
case kGlobalUnescape:
return Type::String();
default: default:
break; break;
} }
......
...@@ -6797,6 +6797,7 @@ class Script: public Struct { ...@@ -6797,6 +6797,7 @@ class Script: public Struct {
V(String.prototype, charCodeAt, StringCharCodeAt) \ V(String.prototype, charCodeAt, StringCharCodeAt) \
V(String.prototype, charAt, StringCharAt) \ V(String.prototype, charAt, StringCharAt) \
V(String.prototype, concat, StringConcat) \ V(String.prototype, concat, StringConcat) \
V(String.prototype, substr, StringSubstr) \
V(String.prototype, toLowerCase, StringToLowerCase) \ V(String.prototype, toLowerCase, StringToLowerCase) \
V(String.prototype, toUpperCase, StringToUpperCase) \ V(String.prototype, toUpperCase, StringToUpperCase) \
V(String, fromCharCode, StringFromCharCode) \ V(String, fromCharCode, StringFromCharCode) \
...@@ -6834,7 +6835,8 @@ class Script: public Struct { ...@@ -6834,7 +6835,8 @@ class Script: public Struct {
V(Math, clz32, MathClz32) \ V(Math, clz32, MathClz32) \
V(Math, fround, MathFround) \ V(Math, fround, MathFround) \
V(Math, trunc, MathTrunc) \ V(Math, trunc, MathTrunc) \
V(Number, parseInt, NumberParseInt) V(Number, parseInt, NumberParseInt) \
V(Number.prototype, toString, NumberToString)
#define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \ #define ATOMIC_FUNCTIONS_WITH_ID_LIST(V) \
V(Atomics, load, AtomicsLoad) \ V(Atomics, load, AtomicsLoad) \
...@@ -6855,6 +6857,12 @@ enum BuiltinFunctionId { ...@@ -6855,6 +6857,12 @@ enum BuiltinFunctionId {
kDataViewBuffer, kDataViewBuffer,
kDataViewByteLength, kDataViewByteLength,
kDataViewByteOffset, kDataViewByteOffset,
kGlobalDecodeURI,
kGlobalDecodeURIComponent,
kGlobalEncodeURI,
kGlobalEncodeURIComponent,
kGlobalEscape,
kGlobalUnescape,
kTypedArrayByteLength, kTypedArrayByteLength,
kTypedArrayByteOffset, kTypedArrayByteOffset,
kTypedArrayLength, kTypedArrayLength,
......
...@@ -49,6 +49,7 @@ class TypeCache final { ...@@ -49,6 +49,7 @@ class TypeCache final {
Type* const kTenOrUndefined = Type* const kTenOrUndefined =
Type::Union(kSingletonTen, Type::Undefined(), zone()); Type::Union(kSingletonTen, Type::Undefined(), zone());
Type* const kMinusOneOrZero = CreateRange(-1.0, 0.0); Type* const kMinusOneOrZero = CreateRange(-1.0, 0.0);
Type* const kMinusOneToOne = CreateRange(-1.0, 1.0);
Type* const kZeroOrOne = CreateRange(0.0, 1.0); Type* const kZeroOrOne = CreateRange(0.0, 1.0);
Type* const kZeroOrOneOrNaN = Type::Union(kZeroOrOne, Type::NaN(), zone()); Type* const kZeroOrOneOrNaN = Type::Union(kZeroOrOne, Type::NaN(), zone());
Type* const kZeroToThirtyOne = CreateRange(0.0, 31.0); Type* const kZeroToThirtyOne = CreateRange(0.0, 31.0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment