Cleanup StringAddFlags.

Avoid duplication of StringAddFlags in the platform specific code stubs header files.
Fix the inverted flag logic, replacing it with a scheme that is easier to understand.

Depends on: https://codereview.chromium.org/19541003

R=mvstanton@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15775 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2013-07-19 11:52:42 +00:00
parent 784e233ea9
commit 5e85399572
15 changed files with 121 additions and 164 deletions

View File

@ -1897,8 +1897,8 @@ void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) {
__ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE);
__ b(ge, &call_runtime); __ b(ge, &call_runtime);
StringAddStub string_add_stub((StringAddFlags) StringAddStub string_add_stub(
(ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_stub); __ TailCallStub(&string_add_stub);
@ -2256,8 +2256,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE);
__ b(ge, &left_not_string); __ b(ge, &left_not_string);
StringAddStub string_add_left_stub((StringAddFlags) StringAddStub string_add_left_stub(
(ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_left_stub); __ TailCallStub(&string_add_left_stub);
@ -2267,8 +2267,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE);
__ b(ge, &call_runtime); __ b(ge, &call_runtime);
StringAddStub string_add_right_stub((StringAddFlags) StringAddStub string_add_right_stub(
(ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_right_stub); __ TailCallStub(&string_add_right_stub);
@ -5494,7 +5494,11 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument. __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument.
// Make sure that both arguments are strings if not known in advance. // Make sure that both arguments are strings if not known in advance.
if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { // Otherwise, at least one of the arguments is definitely a string,
// and we convert the one that is not known to be a string.
if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) {
ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT);
ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT);
__ JumpIfEitherSmi(r0, r1, &call_runtime); __ JumpIfEitherSmi(r0, r1, &call_runtime);
// Load instance types. // Load instance types.
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
@ -5506,20 +5510,16 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ tst(r4, Operand(kIsNotStringMask)); __ tst(r4, Operand(kIsNotStringMask));
__ tst(r5, Operand(kIsNotStringMask), eq); __ tst(r5, Operand(kIsNotStringMask), eq);
__ b(ne, &call_runtime); __ b(ne, &call_runtime);
} else { } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) {
// Here at least one of the arguments is definitely a string. ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0);
// We convert the one that is not known to be a string. GenerateConvertArgument(
if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_RIGHT;
GenerateConvertArgument( } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) {
masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin); ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0);
builtin_id = Builtins::STRING_ADD_RIGHT; GenerateConvertArgument(
} else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_LEFT;
GenerateConvertArgument(
masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin);
builtin_id = Builtins::STRING_ADD_LEFT;
}
} }
// Both arguments are strings. // Both arguments are strings.
@ -5567,7 +5567,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ b(ne, &longer_than_two); __ b(ne, &longer_than_two);
// Check that both strings are non-external ASCII strings. // Check that both strings are non-external ASCII strings.
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
@ -5615,7 +5615,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// If result is not supposed to be flat, allocate a cons string object. // If result is not supposed to be flat, allocate a cons string object.
// If both strings are ASCII the result is an ASCII cons string. // If both strings are ASCII the result is an ASCII cons string.
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
@ -5698,7 +5698,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// r6: sum of lengths. // r6: sum of lengths.
Label first_prepared, second_prepared; Label first_prepared, second_prepared;
__ bind(&string_add_flat_result); __ bind(&string_add_flat_result);
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset));
__ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset));
__ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset));
@ -5786,7 +5786,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// Just jump to runtime to add the two strings. // Just jump to runtime to add the two strings.
__ bind(&call_runtime); __ bind(&call_runtime);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm); GenerateRegisterArgsPop(masm);
// Build a frame // Build a frame
{ {
@ -5801,7 +5801,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
if (call_builtin.is_linked()) { if (call_builtin.is_linked()) {
__ bind(&call_builtin); __ bind(&call_builtin);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm); GenerateRegisterArgsPop(masm);
// Build a frame // Build a frame
{ {

View File

@ -144,21 +144,6 @@ class StringHelper : public AllStatic {
}; };
// Flag that indicates how to generate code for the stub StringAddStub.
enum StringAddFlags {
NO_STRING_ADD_FLAGS = 1 << 0,
// Omit left string check in stub (left is definitely a string).
NO_STRING_CHECK_LEFT_IN_STUB = 1 << 1,
// Omit right string check in stub (right is definitely a string).
NO_STRING_CHECK_RIGHT_IN_STUB = 1 << 2,
// Stub needs a frame before calling the runtime
ERECT_FRAME = 1 << 3,
// Omit both string checks in stub.
NO_STRING_CHECK_IN_STUB =
NO_STRING_CHECK_LEFT_IN_STUB | NO_STRING_CHECK_RIGHT_IN_STUB
};
class StringAddStub: public PlatformCodeStub { class StringAddStub: public PlatformCodeStub {
public: public:
explicit StringAddStub(StringAddFlags flags) : flags_(flags) {} explicit StringAddStub(StringAddFlags flags) : flags_(flags) {}

View File

@ -3719,7 +3719,7 @@ void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
VisitForStackValue(args->at(0)); VisitForStackValue(args->at(0));
VisitForStackValue(args->at(1)); VisitForStackValue(args->at(1));
StringAddStub stub(NO_STRING_ADD_FLAGS); StringAddStub stub(STRING_ADD_CHECK_BOTH);
__ CallStub(&stub); __ CallStub(&stub);
context()->Plug(r0); context()->Plug(r0);
} }

View File

@ -393,6 +393,22 @@ class RuntimeCallHelper {
DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper); DISALLOW_COPY_AND_ASSIGN(RuntimeCallHelper);
}; };
// TODO(bmeurer): Move to the StringAddStub declaration once we're
// done with the translation to a hydrogen code stub.
enum StringAddFlags {
// Omit both parameter checks.
STRING_ADD_CHECK_NONE = 0,
// Check left parameter.
STRING_ADD_CHECK_LEFT = 1 << 0,
// Check right parameter.
STRING_ADD_CHECK_RIGHT = 1 << 1,
// Check both parameters.
STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT,
// Stub needs a frame before calling the runtime
STRING_ADD_ERECT_FRAME = 1 << 2
};
} } // namespace v8::internal } } // namespace v8::internal
#if V8_TARGET_ARCH_IA32 #if V8_TARGET_ARCH_IA32

View File

@ -6182,7 +6182,7 @@ class HStringAdd: public HBinaryOperation {
HValue* context, HValue* context,
HValue* left, HValue* left,
HValue* right, HValue* right,
StringAddFlags flags = NO_STRING_CHECK_IN_STUB); StringAddFlags flags = STRING_ADD_CHECK_NONE);
StringAddFlags flags() const { return flags_; } StringAddFlags flags() const { return flags_; }

View File

@ -9083,7 +9083,7 @@ void HOptimizedGraphBuilder::GenerateStringAdd(CallRuntime* call) {
HValue* left = Pop(); HValue* left = Pop();
HValue* context = environment()->LookupContext(); HValue* context = environment()->LookupContext();
HInstruction* result = HStringAdd::New( HInstruction* result = HStringAdd::New(
zone(), context, left, right, NO_STRING_ADD_FLAGS); zone(), context, left, right, STRING_ADD_CHECK_BOTH);
return ast_context()->ReturnInstruction(result, call->id()); return ast_context()->ReturnInstruction(result, call->id());
} }

View File

@ -1353,8 +1353,8 @@ void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) {
__ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx);
__ j(above_equal, &call_runtime, Label::kNear); __ j(above_equal, &call_runtime, Label::kNear);
StringAddStub string_add_stub((StringAddFlags) StringAddStub string_add_stub(
(ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_stub); __ TailCallStub(&string_add_stub);
@ -1999,8 +1999,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx);
__ j(above_equal, &left_not_string, Label::kNear); __ j(above_equal, &left_not_string, Label::kNear);
StringAddStub string_add_left_stub((StringAddFlags) StringAddStub string_add_left_stub(
(ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_left_stub); __ TailCallStub(&string_add_left_stub);
@ -2010,8 +2010,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx);
__ j(above_equal, &call_runtime, Label::kNear); __ j(above_equal, &call_runtime, Label::kNear);
StringAddStub string_add_right_stub((StringAddFlags) StringAddStub string_add_right_stub(
(ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_right_stub); __ TailCallStub(&string_add_right_stub);
@ -5376,7 +5376,11 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument.
// Make sure that both arguments are strings if not known in advance. // Make sure that both arguments are strings if not known in advance.
if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { // Otherwise, at least one of the arguments is definitely a string,
// and we convert the one that is not known to be a string.
if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) {
ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT);
ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT);
__ JumpIfSmi(eax, &call_runtime); __ JumpIfSmi(eax, &call_runtime);
__ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx);
__ j(above_equal, &call_runtime); __ j(above_equal, &call_runtime);
@ -5385,20 +5389,16 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ JumpIfSmi(edx, &call_runtime); __ JumpIfSmi(edx, &call_runtime);
__ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx);
__ j(above_equal, &call_runtime); __ j(above_equal, &call_runtime);
} else { } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) {
// Here at least one of the arguments is definitely a string. ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0);
// We convert the one that is not known to be a string. GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi,
if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_RIGHT;
GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) {
&call_builtin); ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0);
builtin_id = Builtins::STRING_ADD_RIGHT; GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi,
} else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_LEFT;
GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi,
&call_builtin);
builtin_id = Builtins::STRING_ADD_LEFT;
}
} }
// Both arguments are strings. // Both arguments are strings.
@ -5684,7 +5684,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ Drop(2); __ Drop(2);
// Just jump to runtime to add the two strings. // Just jump to runtime to add the two strings.
__ bind(&call_runtime); __ bind(&call_runtime);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm, ecx); GenerateRegisterArgsPop(masm, ecx);
// Build a frame // Build a frame
{ {
@ -5699,7 +5699,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
if (call_builtin.is_linked()) { if (call_builtin.is_linked()) {
__ bind(&call_builtin); __ bind(&call_builtin);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm, ecx); GenerateRegisterArgsPop(masm, ecx);
// Build a frame // Build a frame
{ {

View File

@ -144,20 +144,6 @@ class StringHelper : public AllStatic {
}; };
enum StringAddFlags {
NO_STRING_ADD_FLAGS = 1 << 0,
// Omit left string check in stub (left is definitely a string).
NO_STRING_CHECK_LEFT_IN_STUB = 1 << 1,
// Omit right string check in stub (right is definitely a string).
NO_STRING_CHECK_RIGHT_IN_STUB = 1 << 2,
// Stub needs a frame before calling the runtime
ERECT_FRAME = 1 << 3,
// Omit both string checks in stub.
NO_STRING_CHECK_IN_STUB =
NO_STRING_CHECK_LEFT_IN_STUB | NO_STRING_CHECK_RIGHT_IN_STUB
};
class StringAddStub: public PlatformCodeStub { class StringAddStub: public PlatformCodeStub {
public: public:
explicit StringAddStub(StringAddFlags flags) : flags_(flags) {} explicit StringAddStub(StringAddFlags flags) : flags_(flags) {}

View File

@ -3685,7 +3685,7 @@ void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
VisitForStackValue(args->at(0)); VisitForStackValue(args->at(0));
VisitForStackValue(args->at(1)); VisitForStackValue(args->at(1));
StringAddStub stub(NO_STRING_ADD_FLAGS); StringAddStub stub(STRING_ADD_CHECK_BOTH);
__ CallStub(&stub); __ CallStub(&stub);
context()->Plug(eax); context()->Plug(eax);
} }

View File

@ -2140,8 +2140,8 @@ void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) {
__ GetObjectType(right, a2, a2); __ GetObjectType(right, a2, a2);
__ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE)); __ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE));
StringAddStub string_add_stub((StringAddFlags) StringAddStub string_add_stub(
(ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_stub); __ TailCallStub(&string_add_stub);
@ -2558,8 +2558,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ GetObjectType(left, a2, a2); __ GetObjectType(left, a2, a2);
__ Branch(&left_not_string, ge, a2, Operand(FIRST_NONSTRING_TYPE)); __ Branch(&left_not_string, ge, a2, Operand(FIRST_NONSTRING_TYPE));
StringAddStub string_add_left_stub((StringAddFlags) StringAddStub string_add_left_stub(
(ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_left_stub); __ TailCallStub(&string_add_left_stub);
@ -2569,8 +2569,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ GetObjectType(right, a2, a2); __ GetObjectType(right, a2, a2);
__ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE)); __ Branch(&call_runtime, ge, a2, Operand(FIRST_NONSTRING_TYPE));
StringAddStub string_add_right_stub((StringAddFlags) StringAddStub string_add_right_stub(
(ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME));
GenerateRegisterArgsPush(masm); GenerateRegisterArgsPush(masm);
__ TailCallStub(&string_add_right_stub); __ TailCallStub(&string_add_right_stub);
@ -5872,7 +5872,11 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ lw(a1, MemOperand(sp, 0 * kPointerSize)); // Second argument. __ lw(a1, MemOperand(sp, 0 * kPointerSize)); // Second argument.
// Make sure that both arguments are strings if not known in advance. // Make sure that both arguments are strings if not known in advance.
if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { // Otherwise, at least one of the arguments is definitely a string,
// and we convert the one that is not known to be a string.
if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) {
ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT);
ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT);
__ JumpIfEitherSmi(a0, a1, &call_runtime); __ JumpIfEitherSmi(a0, a1, &call_runtime);
// Load instance types. // Load instance types.
__ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset));
@ -5884,20 +5888,16 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ Or(t4, t0, Operand(t1)); __ Or(t4, t0, Operand(t1));
__ And(t4, t4, Operand(kIsNotStringMask)); __ And(t4, t4, Operand(kIsNotStringMask));
__ Branch(&call_runtime, ne, t4, Operand(zero_reg)); __ Branch(&call_runtime, ne, t4, Operand(zero_reg));
} else { } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) {
// Here at least one of the arguments is definitely a string. ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0);
// We convert the one that is not known to be a string. GenerateConvertArgument(
if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { masm, 1 * kPointerSize, a0, a2, a3, t0, t1, &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_RIGHT;
GenerateConvertArgument( } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) {
masm, 1 * kPointerSize, a0, a2, a3, t0, t1, &call_builtin); ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0);
builtin_id = Builtins::STRING_ADD_RIGHT; GenerateConvertArgument(
} else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { masm, 0 * kPointerSize, a1, a2, a3, t0, t1, &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_LEFT;
GenerateConvertArgument(
masm, 0 * kPointerSize, a1, a2, a3, t0, t1, &call_builtin);
builtin_id = Builtins::STRING_ADD_LEFT;
}
} }
// Both arguments are strings. // Both arguments are strings.
@ -5948,7 +5948,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ Branch(&longer_than_two, ne, t2, Operand(2)); __ Branch(&longer_than_two, ne, t2, Operand(2));
// Check that both strings are non-external ASCII strings. // Check that both strings are non-external ASCII strings.
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset));
__ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset));
__ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset));
@ -5992,7 +5992,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// If result is not supposed to be flat, allocate a cons string object. // If result is not supposed to be flat, allocate a cons string object.
// If both strings are ASCII the result is an ASCII cons string. // If both strings are ASCII the result is an ASCII cons string.
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset));
__ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset));
__ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset));
@ -6075,7 +6075,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// t2: sum of lengths. // t2: sum of lengths.
Label first_prepared, second_prepared; Label first_prepared, second_prepared;
__ bind(&string_add_flat_result); __ bind(&string_add_flat_result);
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset)); __ lw(t0, FieldMemOperand(a0, HeapObject::kMapOffset));
__ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset)); __ lw(t1, FieldMemOperand(a1, HeapObject::kMapOffset));
__ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset)); __ lbu(t0, FieldMemOperand(t0, Map::kInstanceTypeOffset));
@ -6161,7 +6161,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// Just jump to runtime to add the two strings. // Just jump to runtime to add the two strings.
__ bind(&call_runtime); __ bind(&call_runtime);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm); GenerateRegisterArgsPop(masm);
// Build a frame. // Build a frame.
{ {
@ -6176,7 +6176,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
if (call_builtin.is_linked()) { if (call_builtin.is_linked()) {
__ bind(&call_builtin); __ bind(&call_builtin);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm); GenerateRegisterArgsPop(masm);
// Build a frame. // Build a frame.
{ {

View File

@ -145,21 +145,6 @@ class StringHelper : public AllStatic {
}; };
// Flag that indicates how to generate code for the stub StringAddStub.
enum StringAddFlags {
NO_STRING_ADD_FLAGS = 1 << 0,
// Omit left string check in stub (left is definitely a string).
NO_STRING_CHECK_LEFT_IN_STUB = 1 << 1,
// Omit right string check in stub (right is definitely a string).
NO_STRING_CHECK_RIGHT_IN_STUB = 1 << 2,
// Stub needs a frame before calling the runtime
ERECT_FRAME = 1 << 3,
// Omit both string checks in stub.
NO_STRING_CHECK_IN_STUB =
NO_STRING_CHECK_LEFT_IN_STUB | NO_STRING_CHECK_RIGHT_IN_STUB
};
class StringAddStub: public PlatformCodeStub { class StringAddStub: public PlatformCodeStub {
public: public:
explicit StringAddStub(StringAddFlags flags) : flags_(flags) {} explicit StringAddStub(StringAddFlags flags) : flags_(flags) {}

View File

@ -3746,7 +3746,7 @@ void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
VisitForStackValue(args->at(0)); VisitForStackValue(args->at(0));
VisitForStackValue(args->at(1)); VisitForStackValue(args->at(1));
StringAddStub stub(NO_STRING_ADD_FLAGS); StringAddStub stub(STRING_ADD_CHECK_BOTH);
__ CallStub(&stub); __ CallStub(&stub);
context()->Plug(v0); context()->Plug(v0);
} }

View File

@ -1014,8 +1014,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ JumpIfSmi(left, &left_not_string, Label::kNear); __ JumpIfSmi(left, &left_not_string, Label::kNear);
__ CmpObjectType(left, FIRST_NONSTRING_TYPE, rcx); __ CmpObjectType(left, FIRST_NONSTRING_TYPE, rcx);
__ j(above_equal, &left_not_string, Label::kNear); __ j(above_equal, &left_not_string, Label::kNear);
StringAddStub string_add_left_stub((StringAddFlags) StringAddStub string_add_left_stub(
(ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME));
BinaryOpStub_GenerateRegisterArgsPushUnderReturn(masm); BinaryOpStub_GenerateRegisterArgsPushUnderReturn(masm);
__ TailCallStub(&string_add_left_stub); __ TailCallStub(&string_add_left_stub);
@ -1025,8 +1025,8 @@ void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) {
__ CmpObjectType(right, FIRST_NONSTRING_TYPE, rcx); __ CmpObjectType(right, FIRST_NONSTRING_TYPE, rcx);
__ j(above_equal, &call_runtime, Label::kNear); __ j(above_equal, &call_runtime, Label::kNear);
StringAddStub string_add_right_stub((StringAddFlags) StringAddStub string_add_right_stub(
(ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME));
BinaryOpStub_GenerateRegisterArgsPushUnderReturn(masm); BinaryOpStub_GenerateRegisterArgsPushUnderReturn(masm);
__ TailCallStub(&string_add_right_stub); __ TailCallStub(&string_add_right_stub);
@ -1101,8 +1101,8 @@ void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) {
__ CmpObjectType(right, FIRST_NONSTRING_TYPE, rcx); __ CmpObjectType(right, FIRST_NONSTRING_TYPE, rcx);
__ j(above_equal, &call_runtime); __ j(above_equal, &call_runtime);
StringAddStub string_add_stub((StringAddFlags) StringAddStub string_add_stub(
(ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME));
BinaryOpStub_GenerateRegisterArgsPushUnderReturn(masm); BinaryOpStub_GenerateRegisterArgsPushUnderReturn(masm);
__ TailCallStub(&string_add_stub); __ TailCallStub(&string_add_stub);
@ -4516,7 +4516,11 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ movq(rdx, Operand(rsp, 1 * kPointerSize)); // Second argument (right). __ movq(rdx, Operand(rsp, 1 * kPointerSize)); // Second argument (right).
// Make sure that both arguments are strings if not known in advance. // Make sure that both arguments are strings if not known in advance.
if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { // Otherwise, at least one of the arguments is definitely a string,
// and we convert the one that is not known to be a string.
if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) {
ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT);
ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT);
__ JumpIfSmi(rax, &call_runtime); __ JumpIfSmi(rax, &call_runtime);
__ CmpObjectType(rax, FIRST_NONSTRING_TYPE, r8); __ CmpObjectType(rax, FIRST_NONSTRING_TYPE, r8);
__ j(above_equal, &call_runtime); __ j(above_equal, &call_runtime);
@ -4525,20 +4529,16 @@ void StringAddStub::Generate(MacroAssembler* masm) {
__ JumpIfSmi(rdx, &call_runtime); __ JumpIfSmi(rdx, &call_runtime);
__ CmpObjectType(rdx, FIRST_NONSTRING_TYPE, r9); __ CmpObjectType(rdx, FIRST_NONSTRING_TYPE, r9);
__ j(above_equal, &call_runtime); __ j(above_equal, &call_runtime);
} else { } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) {
// Here at least one of the arguments is definitely a string. ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0);
// We convert the one that is not known to be a string. GenerateConvertArgument(masm, 2 * kPointerSize, rax, rbx, rcx, rdi,
if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_RIGHT;
GenerateConvertArgument(masm, 2 * kPointerSize, rax, rbx, rcx, rdi, } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) {
&call_builtin); ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0);
builtin_id = Builtins::STRING_ADD_RIGHT; GenerateConvertArgument(masm, 1 * kPointerSize, rdx, rbx, rcx, rdi,
} else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { &call_builtin);
ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); builtin_id = Builtins::STRING_ADD_LEFT;
GenerateConvertArgument(masm, 1 * kPointerSize, rdx, rbx, rcx, rdi,
&call_builtin);
builtin_id = Builtins::STRING_ADD_LEFT;
}
} }
// Both arguments are strings. // Both arguments are strings.
@ -4574,7 +4574,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// If arguments where known to be strings, maps are not loaded to r8 and r9 // If arguments where known to be strings, maps are not loaded to r8 and r9
// by the code above. // by the code above.
if (flags_ != NO_STRING_ADD_FLAGS) { if ((flags_ & STRING_ADD_CHECK_BOTH) != STRING_ADD_CHECK_BOTH) {
__ movq(r8, FieldOperand(rax, HeapObject::kMapOffset)); __ movq(r8, FieldOperand(rax, HeapObject::kMapOffset));
__ movq(r9, FieldOperand(rdx, HeapObject::kMapOffset)); __ movq(r9, FieldOperand(rdx, HeapObject::kMapOffset));
} }
@ -4794,7 +4794,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
// Just jump to runtime to add the two strings. // Just jump to runtime to add the two strings.
__ bind(&call_runtime); __ bind(&call_runtime);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm, rcx); GenerateRegisterArgsPop(masm, rcx);
// Build a frame // Build a frame
{ {
@ -4809,7 +4809,7 @@ void StringAddStub::Generate(MacroAssembler* masm) {
if (call_builtin.is_linked()) { if (call_builtin.is_linked()) {
__ bind(&call_builtin); __ bind(&call_builtin);
if ((flags_ & ERECT_FRAME) != 0) { if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) {
GenerateRegisterArgsPop(masm, rcx); GenerateRegisterArgsPop(masm, rcx);
// Build a frame // Build a frame
{ {

View File

@ -134,21 +134,6 @@ class StringHelper : public AllStatic {
}; };
// Flag that indicates how to generate code for the stub StringAddStub.
enum StringAddFlags {
NO_STRING_ADD_FLAGS = 1 << 0,
// Omit left string check in stub (left is definitely a string).
NO_STRING_CHECK_LEFT_IN_STUB = 1 << 1,
// Omit right string check in stub (right is definitely a string).
NO_STRING_CHECK_RIGHT_IN_STUB = 1 << 2,
// Stub needs a frame before calling the runtime
ERECT_FRAME = 1 << 3,
// Omit both string checks in stub.
NO_STRING_CHECK_IN_STUB =
NO_STRING_CHECK_LEFT_IN_STUB | NO_STRING_CHECK_RIGHT_IN_STUB
};
class StringAddStub: public PlatformCodeStub { class StringAddStub: public PlatformCodeStub {
public: public:
explicit StringAddStub(StringAddFlags flags) : flags_(flags) {} explicit StringAddStub(StringAddFlags flags) : flags_(flags) {}

View File

@ -3645,7 +3645,7 @@ void FullCodeGenerator::EmitStringAdd(CallRuntime* expr) {
VisitForStackValue(args->at(0)); VisitForStackValue(args->at(0));
VisitForStackValue(args->at(1)); VisitForStackValue(args->at(1));
StringAddStub stub(NO_STRING_ADD_FLAGS); StringAddStub stub(STRING_ADD_CHECK_BOTH);
__ CallStub(&stub); __ CallStub(&stub);
context()->Plug(rax); context()->Plug(rax);
} }