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

Unified Diff: src/code-stub-assembler.cc

Issue 2395453002: [stubs] Add String and JSReceiver instance type predicates (Closed)
Patch Set: Created 4 years, 2 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
Index: src/code-stub-assembler.cc
diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc
index 5295189a8e7816bdc7947828b3486554c0596e31..1228c43b6018310eb23698f7e166a8c935b2c568 100644
--- a/src/code-stub-assembler.cc
+++ b/src/code-stub-assembler.cc
@@ -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);
{
@@ -2083,9 +2082,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.
@@ -2178,9 +2176,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)),
@@ -2232,6 +2228,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);
@@ -2537,9 +2544,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.
@@ -2885,15 +2890,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);
{
@@ -3103,9 +3104,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);
Igor Sheludko 2016/10/05 08:02:27 You can now remove this assert from here.
- GotoIf(
- Int32GreaterThan(key_instance_type, Int32Constant(FIRST_NONSTRING_TYPE)),
- if_bailout);
+ GotoUnless(IsStringInstanceType(key_instance_type), if_bailout);
jgruber 2016/10/04 13:35:54 Igor: I'm assuming the original code was bugged (s
Igor Sheludko 2016/10/05 08:02:27 FIRST_NONSTRING_TYPE is actually a SYMBOL_TYPE whi
// |key| is a String. Check if it has a cached array index.
Node* hash = LoadNameHashField(key);
Node* contains_index =
@@ -3752,8 +3751,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);
@@ -3762,8 +3760,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);
« no previous file with comments | « src/code-stub-assembler.h ('k') | src/code-stubs.cc » ('j') | src/code-stubs.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698