Commit 29bdb26b authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[CSA][cleanup] TNodify builtins conversion gen

One Node* remains since it is crashing when TNodified since it
has the empty Context. When this happens, it means the Context
might not be needed. In this case it's hard to see if that's the
case since it is propagated all over the place. Created a TODO
so we can solve it later, when TNodification is more complete.

Bug: v8:6949
Change-Id: I7db8c507689e30779f102a8272e1b13ecdc3e5e9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1807274Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63846}
parent 11b819c6
......@@ -18,16 +18,17 @@ class ConversionBuiltinsAssembler : public CodeStubAssembler {
: CodeStubAssembler(state) {}
protected:
void Generate_NonPrimitiveToPrimitive(Node* context, Node* input,
void Generate_NonPrimitiveToPrimitive(TNode<Context> context,
TNode<Object> input,
ToPrimitiveHint hint);
void Generate_OrdinaryToPrimitive(Node* context, Node* input,
void Generate_OrdinaryToPrimitive(TNode<Context> context, TNode<Object> input,
OrdinaryToPrimitiveHint hint);
};
// ES6 section 7.1.1 ToPrimitive ( input [ , PreferredType ] )
void ConversionBuiltinsAssembler::Generate_NonPrimitiveToPrimitive(
Node* context, Node* input, ToPrimitiveHint hint) {
TNode<Context> context, TNode<Object> input, ToPrimitiveHint hint) {
// Lookup the @@toPrimitive property on the {input}.
TNode<Object> exotic_to_prim =
GetProperty(context, input, factory()->to_primitive_symbol());
......@@ -42,14 +43,14 @@ void ConversionBuiltinsAssembler::Generate_NonPrimitiveToPrimitive(
CodeFactory::Call(isolate(), ConvertReceiverMode::kNotNullOrUndefined);
TNode<String> hint_string =
HeapConstant(factory()->ToPrimitiveHintString(hint));
Node* result =
CallJS(callable, context, exotic_to_prim, input, hint_string);
TNode<Object> result =
CAST(CallJS(callable, context, exotic_to_prim, input, hint_string));
// Verify that the {result} is actually a primitive.
Label if_resultisprimitive(this),
if_resultisnotprimitive(this, Label::kDeferred);
GotoIf(TaggedIsSmi(result), &if_resultisprimitive);
TNode<Uint16T> result_instance_type = LoadInstanceType(result);
TNode<Uint16T> result_instance_type = LoadInstanceType(CAST(result));
Branch(IsPrimitiveInstanceType(result_instance_type), &if_resultisprimitive,
&if_resultisnotprimitive);
......@@ -78,22 +79,22 @@ void ConversionBuiltinsAssembler::Generate_NonPrimitiveToPrimitive(
}
TF_BUILTIN(NonPrimitiveToPrimitive_Default, ConversionBuiltinsAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Generate_NonPrimitiveToPrimitive(context, input, ToPrimitiveHint::kDefault);
}
TF_BUILTIN(NonPrimitiveToPrimitive_Number, ConversionBuiltinsAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Generate_NonPrimitiveToPrimitive(context, input, ToPrimitiveHint::kNumber);
}
TF_BUILTIN(NonPrimitiveToPrimitive_String, ConversionBuiltinsAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Generate_NonPrimitiveToPrimitive(context, input, ToPrimitiveHint::kString);
}
......@@ -105,22 +106,22 @@ TF_BUILTIN(StringToNumber, CodeStubAssembler) {
}
TF_BUILTIN(ToName, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
VARIABLE(var_input, MachineRepresentation::kTagged, input);
TVARIABLE(Object, var_input, input);
Label loop(this, &var_input);
Goto(&loop);
BIND(&loop);
{
// Load the current {input} value.
Node* input = var_input.value();
TNode<Object> input = var_input.value();
// Dispatch based on the type of the {input.}
Label if_inputisbigint(this), if_inputisname(this), if_inputisnumber(this),
if_inputisoddball(this), if_inputisreceiver(this, Label::kDeferred);
GotoIf(TaggedIsSmi(input), &if_inputisnumber);
TNode<Uint16T> input_instance_type = LoadInstanceType(input);
TNode<Uint16T> input_instance_type = LoadInstanceType(CAST(input));
STATIC_ASSERT(FIRST_NAME_TYPE == FIRST_TYPE);
GotoIf(IsNameInstanceType(input_instance_type), &if_inputisname);
GotoIf(IsJSReceiverInstanceType(input_instance_type), &if_inputisreceiver);
......@@ -151,7 +152,7 @@ TF_BUILTIN(ToName, CodeStubAssembler) {
{
// Just return the {input}'s string representation.
CSA_ASSERT(this, IsOddballInstanceType(input_instance_type));
Return(LoadObjectField(input, Oddball::kToStringOffset));
Return(LoadObjectField(CAST(input), Oddball::kToStringOffset));
}
BIND(&if_inputisreceiver);
......@@ -159,23 +160,23 @@ TF_BUILTIN(ToName, CodeStubAssembler) {
// Convert the JSReceiver {input} to a primitive first,
// and then run the loop again with the new {input},
// which is then a primitive value.
var_input.Bind(CallBuiltin(Builtins::kNonPrimitiveToPrimitive_String,
context, input));
var_input = CallBuiltin(Builtins::kNonPrimitiveToPrimitive_String,
context, input);
Goto(&loop);
}
}
}
TF_BUILTIN(NonNumberToNumber, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<HeapObject> input = CAST(Parameter(Descriptor::kArgument));
Return(NonNumberToNumber(context, input));
}
TF_BUILTIN(NonNumberToNumeric, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<HeapObject> input = CAST(Parameter(Descriptor::kArgument));
Return(NonNumberToNumeric(context, input));
}
......@@ -191,16 +192,19 @@ TF_BUILTIN(ToNumeric, CodeStubAssembler) {
// ES6 section 7.1.3 ToNumber ( argument )
TF_BUILTIN(ToNumber, CodeStubAssembler) {
// TODO(solanes, v8:6949): Changing this to a TNode<Context> crashes with the
// empty context. Context might not be needed, but it is propagated all over
// the place and hard to pull out.
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Return(ToNumber(context, input));
}
// Like ToNumber, but also converts BigInts.
TF_BUILTIN(ToNumberConvertBigInt, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Return(ToNumber(context, input, BigIntHandling::kConvertToNumber));
}
......@@ -214,8 +218,8 @@ TF_BUILTIN(NumberToString, CodeStubAssembler) {
// 7.1.1.1 OrdinaryToPrimitive ( O, hint )
void ConversionBuiltinsAssembler::Generate_OrdinaryToPrimitive(
Node* context, Node* input, OrdinaryToPrimitiveHint hint) {
VARIABLE(var_result, MachineRepresentation::kTagged);
TNode<Context> context, TNode<Object> input, OrdinaryToPrimitiveHint hint) {
TVARIABLE(Object, var_result);
Label return_result(this, &var_result);
Handle<String> method_names[2];
......@@ -246,12 +250,12 @@ void ConversionBuiltinsAssembler::Generate_OrdinaryToPrimitive(
// Call the {method} on the {input}.
Callable callable = CodeFactory::Call(
isolate(), ConvertReceiverMode::kNotNullOrUndefined);
Node* result = CallJS(callable, context, method, input);
var_result.Bind(result);
TNode<Object> result = CAST(CallJS(callable, context, method, input));
var_result = result;
// Return the {result} if it is a primitive.
GotoIf(TaggedIsSmi(result), &return_result);
TNode<Uint16T> result_instance_type = LoadInstanceType(result);
TNode<Uint16T> result_instance_type = LoadInstanceType(CAST(result));
GotoIf(IsPrimitiveInstanceType(result_instance_type), &return_result);
}
......@@ -267,22 +271,22 @@ void ConversionBuiltinsAssembler::Generate_OrdinaryToPrimitive(
}
TF_BUILTIN(OrdinaryToPrimitive_Number, ConversionBuiltinsAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Generate_OrdinaryToPrimitive(context, input,
OrdinaryToPrimitiveHint::kNumber);
}
TF_BUILTIN(OrdinaryToPrimitive_String, ConversionBuiltinsAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Generate_OrdinaryToPrimitive(context, input,
OrdinaryToPrimitiveHint::kString);
}
// ES6 section 7.1.2 ToBoolean ( argument )
TF_BUILTIN(ToBoolean, CodeStubAssembler) {
Node* value = Parameter(Descriptor::kArgument);
TNode<Object> value = CAST(Parameter(Descriptor::kArgument));
Label return_true(this), return_false(this);
BranchIfToBooleanIsTrue(value, &return_true, &return_false);
......@@ -298,7 +302,7 @@ TF_BUILTIN(ToBoolean, CodeStubAssembler) {
// Requires parameter on stack so that it can be used as a continuation from a
// LAZY deopt.
TF_BUILTIN(ToBooleanLazyDeoptContinuation, CodeStubAssembler) {
Node* value = Parameter(Descriptor::kArgument);
TNode<Object> value = CAST(Parameter(Descriptor::kArgument));
Label return_true(this), return_false(this);
BranchIfToBooleanIsTrue(value, &return_true, &return_false);
......@@ -311,11 +315,10 @@ TF_BUILTIN(ToBooleanLazyDeoptContinuation, CodeStubAssembler) {
}
TF_BUILTIN(ToLength, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
// We might need to loop once for ToNumber conversion.
VARIABLE(var_len, MachineRepresentation::kTagged,
Parameter(Descriptor::kArgument));
TVARIABLE(Object, var_len, CAST(Parameter(Descriptor::kArgument)));
Label loop(this, &var_len);
Goto(&loop);
BIND(&loop);
......@@ -325,7 +328,7 @@ TF_BUILTIN(ToLength, CodeStubAssembler) {
return_zero(this, Label::kDeferred);
// Load the current {len} value.
Node* len = var_len.value();
TNode<Object> len = var_len.value();
// Check if {len} is a positive Smi.
GotoIf(TaggedIsPositiveSmi(len), &return_len);
......@@ -334,14 +337,16 @@ TF_BUILTIN(ToLength, CodeStubAssembler) {
GotoIf(TaggedIsSmi(len), &return_zero);
// Check if {len} is a HeapNumber.
TNode<HeapObject> len_heap_object = CAST(len);
Label if_lenisheapnumber(this),
if_lenisnotheapnumber(this, Label::kDeferred);
Branch(IsHeapNumber(len), &if_lenisheapnumber, &if_lenisnotheapnumber);
Branch(IsHeapNumber(len_heap_object), &if_lenisheapnumber,
&if_lenisnotheapnumber);
BIND(&if_lenisheapnumber);
{
// Load the floating-point value of {len}.
TNode<Float64T> len_value = LoadHeapNumberValue(len);
TNode<Float64T> len_value = LoadHeapNumberValue(len_heap_object);
// Check if {len} is not greater than zero.
GotoIfNot(Float64GreaterThan(len_value, Float64Constant(0.0)),
......@@ -361,7 +366,7 @@ TF_BUILTIN(ToLength, CodeStubAssembler) {
BIND(&if_lenisnotheapnumber);
{
// Need to convert {len} to a Number first.
var_len.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, len));
var_len = CallBuiltin(Builtins::kNonNumberToNumber, context, len);
Goto(&loop);
}
......@@ -377,15 +382,15 @@ TF_BUILTIN(ToLength, CodeStubAssembler) {
}
TF_BUILTIN(ToInteger, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Return(ToInteger(context, input, kNoTruncation));
}
TF_BUILTIN(ToInteger_TruncateMinusZero, CodeStubAssembler) {
Node* context = Parameter(Descriptor::kContext);
Node* input = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> input = CAST(Parameter(Descriptor::kArgument));
Return(ToInteger(context, input, kTruncateMinusZero));
}
......@@ -396,15 +401,14 @@ TF_BUILTIN(ToObject, CodeStubAssembler) {
if_noconstructor(this, Label::kDeferred),
if_wrapjs_primitive_wrapper(this);
Node* context = Parameter(Descriptor::kContext);
Node* object = Parameter(Descriptor::kArgument);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<Object> object = CAST(Parameter(Descriptor::kArgument));
VARIABLE(constructor_function_index_var,
MachineType::PointerRepresentation());
TVARIABLE(IntPtrT, constructor_function_index_var);
GotoIf(TaggedIsSmi(object), &if_smi);
TNode<Map> map = LoadMap(object);
TNode<Map> map = LoadMap(CAST(object));
TNode<Uint16T> instance_type = LoadMapInstanceType(map);
GotoIf(IsJSReceiverInstanceType(instance_type), &if_jsreceiver);
......@@ -413,12 +417,12 @@ TF_BUILTIN(ToObject, CodeStubAssembler) {
GotoIf(WordEqual(constructor_function_index,
IntPtrConstant(Map::kNoConstructorFunctionIndex)),
&if_noconstructor);
constructor_function_index_var.Bind(constructor_function_index);
constructor_function_index_var = constructor_function_index;
Goto(&if_wrapjs_primitive_wrapper);
BIND(&if_smi);
constructor_function_index_var.Bind(
IntPtrConstant(Context::NUMBER_FUNCTION_INDEX));
constructor_function_index_var =
IntPtrConstant(Context::NUMBER_FUNCTION_INDEX);
Goto(&if_wrapjs_primitive_wrapper);
BIND(&if_wrapjs_primitive_wrapper);
......@@ -449,7 +453,7 @@ TF_BUILTIN(ToObject, CodeStubAssembler) {
// ES6 section 12.5.5 typeof operator
TF_BUILTIN(Typeof, CodeStubAssembler) {
Node* object = Parameter(Descriptor::kObject);
TNode<Object> object = CAST(Parameter(Descriptor::kObject));
Return(Typeof(object));
}
......
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