Commit f7307419 authored by jgruber's avatar jgruber Committed by Commit bot

[stubs] Add String and JSReceiver instance type predicates

These improve readability of relevant code passages.

Review-Url: https://codereview.chromium.org/2395453002
Cr-Commit-Position: refs/heads/master@{#39978}
parent 1d40f819
......@@ -1410,10 +1410,8 @@ void Builtins::Generate_ArrayIncludes(CodeStubAssembler* assembler) {
assembler->Bind(&not_heap_num);
Node* search_type = assembler->LoadMapInstanceType(map);
assembler->GotoIf(
assembler->Int32LessThan(
search_type, assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
&string_loop);
assembler->GotoIf(assembler->IsStringInstanceType(search_type),
&string_loop);
assembler->GotoIf(
assembler->Word32Equal(search_type,
assembler->Int32Constant(SIMD128_VALUE_TYPE)),
......@@ -1517,9 +1515,8 @@ void Builtins::Generate_ArrayIncludes(CodeStubAssembler* assembler) {
Node* element_k = assembler->LoadFixedArrayElement(
elements, index_var.value(), 0, CodeStubAssembler::INTPTR_PARAMETERS);
assembler->GotoIf(assembler->WordIsSmi(element_k), &continue_loop);
assembler->GotoUnless(assembler->Int32LessThan(
assembler->LoadInstanceType(element_k),
assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
assembler->GotoUnless(assembler->IsStringInstanceType(
assembler->LoadInstanceType(element_k)),
&continue_loop);
// TODO(bmeurer): Consider inlining the StringEqual logic here.
......@@ -1855,10 +1852,8 @@ void Builtins::Generate_ArrayIndexOf(CodeStubAssembler* assembler) {
assembler->Bind(&not_heap_num);
Node* search_type = assembler->LoadMapInstanceType(map);
assembler->GotoIf(
assembler->Int32LessThan(
search_type, assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
&string_loop);
assembler->GotoIf(assembler->IsStringInstanceType(search_type),
&string_loop);
assembler->GotoIf(
assembler->Word32Equal(search_type,
assembler->Int32Constant(SIMD128_VALUE_TYPE)),
......@@ -1937,9 +1932,8 @@ void Builtins::Generate_ArrayIndexOf(CodeStubAssembler* assembler) {
Node* element_k = assembler->LoadFixedArrayElement(
elements, index_var.value(), 0, CodeStubAssembler::INTPTR_PARAMETERS);
assembler->GotoIf(assembler->WordIsSmi(element_k), &continue_loop);
assembler->GotoUnless(assembler->Int32LessThan(
assembler->LoadInstanceType(element_k),
assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
assembler->GotoUnless(assembler->IsStringInstanceType(
assembler->LoadInstanceType(element_k)),
&continue_loop);
// TODO(bmeurer): Consider inlining the StringEqual logic here.
......
......@@ -168,10 +168,8 @@ void Builtins::Generate_ToString(CodeStubAssembler* assembler) {
Node* input_instance_type = assembler->LoadMapInstanceType(input_map);
Label not_string(assembler);
assembler->GotoIf(
assembler->Int32GreaterThanOrEqual(
input_instance_type, assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
&not_string);
assembler->GotoUnless(assembler->IsStringInstanceType(input_instance_type),
&not_string);
assembler->Return(input);
Label not_heap_number(assembler);
......
......@@ -230,10 +230,8 @@ void IsString(CodeStubAssembler* assembler, compiler::Node* object,
{
Node* instance_type = assembler->LoadInstanceType(object);
assembler->Branch(
assembler->Int32LessThan(
instance_type, assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
if_string, if_notstring);
assembler->Branch(assembler->IsStringInstanceType(instance_type), if_string,
if_notstring);
}
}
......@@ -259,10 +257,8 @@ void ReturnIfPrimitive(CodeStubAssembler* assembler,
CodeStubAssembler::Label* return_string,
CodeStubAssembler::Label* return_boolean,
CodeStubAssembler::Label* return_number) {
assembler->GotoIf(
assembler->Int32LessThan(instance_type,
assembler->Int32Constant(FIRST_NONSTRING_TYPE)),
return_string);
assembler->GotoIf(assembler->IsStringInstanceType(instance_type),
return_string);
assembler->GotoIf(assembler->Word32Equal(
instance_type, assembler->Int32Constant(ODDBALL_TYPE)),
......
......@@ -760,9 +760,8 @@ void CodeStubAssembler::BranchIfToBooleanIsTrue(Node* value, Label* if_true,
// types, the HeapNumber type and everything else.
GotoIf(Word32Equal(value_instance_type, Int32Constant(HEAP_NUMBER_TYPE)),
&if_valueisheapnumber);
Branch(
Int32LessThan(value_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
&if_valueisstring, &if_valueisother);
Branch(IsStringInstanceType(value_instance_type), &if_valueisstring,
&if_valueisother);
Bind(&if_valueisstring);
{
......@@ -2127,9 +2126,8 @@ Node* CodeStubAssembler::ToThisString(Node* context, Node* value,
// Check if the {value} is already String.
Label if_valueisnotstring(this, Label::kDeferred);
Branch(
Int32LessThan(value_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
&if_valueisstring, &if_valueisnotstring);
Branch(IsStringInstanceType(value_instance_type), &if_valueisstring,
&if_valueisnotstring);
Bind(&if_valueisnotstring);
{
// Check if the {value} is null.
......@@ -2222,9 +2220,7 @@ Node* CodeStubAssembler::ToThisValue(Node* context, Node* value,
&done_loop);
break;
case PrimitiveType::kString:
GotoIf(Int32LessThan(value_instance_type,
Int32Constant(FIRST_NONSTRING_TYPE)),
&done_loop);
GotoIf(IsStringInstanceType(value_instance_type), &done_loop);
break;
case PrimitiveType::kSymbol:
GotoIf(Word32Equal(value_instance_type, Int32Constant(SYMBOL_TYPE)),
......@@ -2276,6 +2272,17 @@ Node* CodeStubAssembler::ThrowIfNotInstanceType(Node* context, Node* value,
return var_value_map.value();
}
Node* CodeStubAssembler::IsStringInstanceType(Node* instance_type) {
STATIC_ASSERT(INTERNALIZED_STRING_TYPE == FIRST_TYPE);
return Int32LessThan(instance_type, Int32Constant(FIRST_NONSTRING_TYPE));
}
Node* CodeStubAssembler::IsJSReceiverInstanceType(Node* instance_type) {
STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
return Int32GreaterThanOrEqual(instance_type,
Int32Constant(FIRST_JS_RECEIVER_TYPE));
}
Node* CodeStubAssembler::StringCharCodeAt(Node* string, Node* index) {
// Translate the {index} into a Word.
index = SmiToWord(index);
......@@ -2581,9 +2588,7 @@ Node* CodeStubAssembler::SubString(Node* context, Node* string, Node* from,
var_instance_type.Bind(instance_type);
// Check if {string} is a String.
GotoIf(Int32GreaterThanOrEqual(instance_type,
Int32Constant(FIRST_NONSTRING_TYPE)),
&runtime);
GotoUnless(IsStringInstanceType(instance_type), &runtime);
// Make sure that both from and to are non-negative smis.
......@@ -2929,15 +2934,11 @@ Node* CodeStubAssembler::NonNumberToNumber(Node* context, Node* input) {
Label if_inputisstring(this), if_inputisoddball(this),
if_inputisreceiver(this, Label::kDeferred),
if_inputisother(this, Label::kDeferred);
GotoIf(
Int32LessThan(input_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
&if_inputisstring);
GotoIf(IsStringInstanceType(input_instance_type), &if_inputisstring);
GotoIf(Word32Equal(input_instance_type, Int32Constant(ODDBALL_TYPE)),
&if_inputisoddball);
STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
Branch(Int32GreaterThanOrEqual(input_instance_type,
Int32Constant(FIRST_JS_RECEIVER_TYPE)),
&if_inputisreceiver, &if_inputisother);
Branch(IsJSReceiverInstanceType(input_instance_type), &if_inputisreceiver,
&if_inputisother);
Bind(&if_inputisstring);
{
......@@ -3147,9 +3148,7 @@ void CodeStubAssembler::TryToName(Node* key, Label* if_keyisindex,
if_keyisunique);
// Miss if |key| is not a String.
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
GotoIf(
Int32GreaterThan(key_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
if_bailout);
GotoUnless(IsStringInstanceType(key_instance_type), if_bailout);
// |key| is a String. Check if it has a cached array index.
Node* hash = LoadNameHashField(key);
Node* contains_index =
......@@ -3796,8 +3795,7 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
{
AssertInstanceType(object, JS_VALUE_TYPE);
Node* string = LoadJSValueValue(object);
Assert(Int32LessThan(LoadInstanceType(string),
Int32Constant(FIRST_NONSTRING_TYPE)));
Assert(IsStringInstanceType(LoadInstanceType(string)));
Node* length = LoadStringLength(string);
GotoIf(UintPtrLessThan(intptr_index, SmiUntag(length)), if_found);
Goto(&if_isobjectorsmi);
......@@ -3806,8 +3804,7 @@ void CodeStubAssembler::TryLookupElement(Node* object, Node* map,
{
AssertInstanceType(object, JS_VALUE_TYPE);
Node* string = LoadJSValueValue(object);
Assert(Int32LessThan(LoadInstanceType(string),
Int32Constant(FIRST_NONSTRING_TYPE)));
Assert(IsStringInstanceType(LoadInstanceType(string)));
Node* length = LoadStringLength(string);
GotoIf(UintPtrLessThan(intptr_index, SmiUntag(length)), if_found);
Goto(&if_isdictionary);
......
......@@ -497,6 +497,10 @@ class CodeStubAssembler : public compiler::CodeAssembler {
InstanceType instance_type,
char const* method_name);
// Type checks.
compiler::Node* IsStringInstanceType(compiler::Node* instance_type);
compiler::Node* IsJSReceiverInstanceType(compiler::Node* instance_type);
// String helpers.
// Load a character from a String (might flatten a ConsString).
compiler::Node* StringCharCodeAt(compiler::Node* string,
......
This diff is collapsed.
......@@ -2371,9 +2371,8 @@ void Interpreter::DoForInPrepare(InterpreterAssembler* assembler) {
if (FLAG_debug_code) {
Label already_receiver(assembler), abort(assembler);
Node* instance_type = __ LoadInstanceType(receiver);
Node* first_receiver_type = __ Int32Constant(FIRST_JS_RECEIVER_TYPE);
__ BranchIfInt32GreaterThanOrEqual(instance_type, first_receiver_type,
&already_receiver, &abort);
__ Branch(__ IsJSReceiverInstanceType(instance_type), &already_receiver,
&abort);
__ Bind(&abort);
{
__ Abort(kExpectedJSReceiver);
......
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