Commit 9284d8d8 authored by Z Nguyen-Huu's avatar Z Nguyen-Huu Committed by Commit Bot

[builtins] Port some String helpers to Torque

StringAdd_ConvertRight and StringAdd_ConvertLeft

Change-Id: I7d4c560dd53e445ad73f374824ec6fddcce6a641
Bug: v8:8996
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1756853
Commit-Queue: Z Nguyen-Huu <duongn@microsoft.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63381}
parent f0dd3d5f
......@@ -1561,6 +1561,8 @@ transitioning builtin ToString(context: Context, o: Object): String {
extern transitioning runtime ToStringRT(Context, Object): String;
extern transitioning builtin NonPrimitiveToPrimitive_String(
Context, Object): Object;
extern transitioning builtin NonPrimitiveToPrimitive_Default(
Context, Object): Object;
extern transitioning runtime NormalizeElements(Context, JSObject);
extern transitioning runtime TransitionElementsKindWithKind(
......
......@@ -1128,8 +1128,6 @@ namespace internal {
\
/* String helpers */ \
TFS(StringAdd_CheckNone, kLeft, kRight) \
TFS(StringAdd_ConvertLeft, kLeft, kRight) \
TFS(StringAdd_ConvertRight, kLeft, kRight) \
TFS(SubString, kString, kFrom, kTo) \
\
/* Miscellaneous */ \
......
......@@ -525,15 +525,15 @@ TF_BUILTIN(Add, AddStubAssembler) {
BIND(&string_add_convert_left);
{
// Convert {left} to a String and concatenate it with the String {right}.
TailCallBuiltin(Builtins::kStringAdd_ConvertLeft, context, var_left.value(),
TailCallBuiltin(Builtins::kStringAddConvertLeft, context, var_left.value(),
var_right.value());
}
BIND(&string_add_convert_right);
{
// Convert {right} to a String and concatenate it with the String {left}.
TailCallBuiltin(Builtins::kStringAdd_ConvertRight, context,
var_left.value(), var_right.value());
TailCallBuiltin(Builtins::kStringAddConvertRight, context, var_left.value(),
var_right.value());
}
BIND(&do_bigint_add);
......
......@@ -294,28 +294,6 @@ TF_BUILTIN(StringAdd_CheckNone, StringBuiltinsAssembler) {
Return(StringAdd(context, left, right));
}
TF_BUILTIN(StringAdd_ConvertLeft, StringBuiltinsAssembler) {
TNode<Object> left = CAST(Parameter(Descriptor::kLeft));
TNode<String> right = CAST(Parameter(Descriptor::kRight));
Node* context = Parameter(Descriptor::kContext);
// TODO(danno): The ToString and JSReceiverToPrimitive below could be
// combined to avoid duplicate smi and instance type checks.
left =
ToStringImpl(CAST(context), CAST(JSReceiverToPrimitive(context, left)));
TailCallBuiltin(Builtins::kStringAdd_CheckNone, context, left, right);
}
TF_BUILTIN(StringAdd_ConvertRight, StringBuiltinsAssembler) {
TNode<String> left = CAST(Parameter(Descriptor::kLeft));
TNode<Object> right = CAST(Parameter(Descriptor::kRight));
Node* context = Parameter(Descriptor::kContext);
// TODO(danno): The ToString and JSReceiverToPrimitive below could be
// combined to avoid duplicate smi and instance type checks.
right =
ToStringImpl(CAST(context), CAST(JSReceiverToPrimitive(context, right)));
TailCallBuiltin(Builtins::kStringAdd_CheckNone, context, left, right);
}
TF_BUILTIN(SubString, StringBuiltinsAssembler) {
TNode<String> string = CAST(Parameter(Descriptor::kString));
TNode<Smi> from = CAST(Parameter(Descriptor::kFrom));
......
......@@ -179,4 +179,22 @@ namespace string {
obj.value = s;
return obj;
}
transitioning builtin StringAddConvertLeft(implicit context: Context)(
left: Object, right: String): String {
let temp: Object = left;
if (Is<JSReceiver>(temp)) {
temp = NonPrimitiveToPrimitive_Default(context, temp);
}
return ToStringImpl(context, temp) + right;
}
transitioning builtin StringAddConvertRight(implicit context: Context)(
left: String, right: Object): String {
let temp: Object = right;
if (Is<JSReceiver>(temp)) {
temp = NonPrimitiveToPrimitive_Default(context, temp);
}
return left + ToStringImpl(context, temp);
}
}
......@@ -267,9 +267,9 @@ Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags) {
case STRING_ADD_CHECK_NONE:
return Builtins::CallableFor(isolate, Builtins::kStringAdd_CheckNone);
case STRING_ADD_CONVERT_LEFT:
return Builtins::CallableFor(isolate, Builtins::kStringAdd_ConvertLeft);
return Builtins::CallableFor(isolate, Builtins::kStringAddConvertLeft);
case STRING_ADD_CONVERT_RIGHT:
return Builtins::CallableFor(isolate, Builtins::kStringAdd_ConvertRight);
return Builtins::CallableFor(isolate, Builtins::kStringAddConvertRight);
}
UNREACHABLE();
}
......
......@@ -8086,31 +8086,6 @@ TNode<String> CodeStubAssembler::ToString_Inline(SloppyTNode<Context> context,
return CAST(var_result.value());
}
Node* CodeStubAssembler::JSReceiverToPrimitive(Node* context, Node* input) {
Label if_isreceiver(this, Label::kDeferred), if_isnotreceiver(this);
VARIABLE(result, MachineRepresentation::kTagged);
Label done(this, &result);
BranchIfJSReceiver(input, &if_isreceiver, &if_isnotreceiver);
BIND(&if_isreceiver);
{
// Convert {input} to a primitive first passing Number hint.
Callable callable = CodeFactory::NonPrimitiveToPrimitive(isolate());
result.Bind(CallStub(callable, context, input));
Goto(&done);
}
BIND(&if_isnotreceiver);
{
result.Bind(input);
Goto(&done);
}
BIND(&done);
return result.value();
}
TNode<JSReceiver> CodeStubAssembler::ToObject(SloppyTNode<Context> context,
SloppyTNode<Object> input) {
return CAST(CallBuiltin(Builtins::kToObject, context, input));
......
......@@ -2568,9 +2568,6 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<String> ToString_Inline(SloppyTNode<Context> context,
SloppyTNode<Object> input);
// Convert any object to a Primitive.
Node* JSReceiverToPrimitive(Node* context, Node* input);
TNode<JSReceiver> ToObject(SloppyTNode<Context> context,
SloppyTNode<Object> input);
......
......@@ -2300,8 +2300,8 @@ void JSHeapBroker::SerializeShareableObjects() {
Builtins::kJSBuiltinsConstructStub,
Builtins::kJSConstructStubGeneric,
Builtins::kStringAdd_CheckNone,
Builtins::kStringAdd_ConvertLeft,
Builtins::kStringAdd_ConvertRight,
Builtins::kStringAddConvertLeft,
Builtins::kStringAddConvertRight,
Builtins::kToNumber,
Builtins::kToObject,
};
......
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