Commit bb0d4eda authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[csa] TNodify builtins-arguments-gen and remove ParameterMode

Bug: v8:9708, v8:9396
Change-Id: Id957a937a6801292dd31972dd16b188951aa05c4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1803350Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63780}
parent 45b05f31
......@@ -17,38 +17,34 @@
namespace v8 {
namespace internal {
using Node = compiler::Node;
std::tuple<Node*, Node*, Node*>
ArgumentsBuiltinsAssembler::AllocateArgumentsObject(Node* map,
Node* arguments_count,
Node* parameter_map_count,
ParameterMode mode,
int base_size) {
ArgumentsBuiltinsAssembler::ArgumentsAllocationResult
ArgumentsBuiltinsAssembler::AllocateArgumentsObject(
TNode<Map> map, TNode<BInt> arguments_count,
TNode<BInt> parameter_map_count, int base_size) {
// Allocate the parameter object (either a Rest parameter object, a strict
// argument object or a sloppy arguments object) and the elements/mapped
// arguments together.
int elements_offset = base_size;
Node* element_count = arguments_count;
TNode<BInt> element_count = arguments_count;
if (parameter_map_count != nullptr) {
base_size += FixedArray::kHeaderSize;
element_count = IntPtrOrSmiAdd(element_count, parameter_map_count, mode);
element_count = IntPtrOrSmiAdd(element_count, parameter_map_count);
}
bool empty = IsIntPtrOrSmiConstantZero(arguments_count, mode);
bool empty = IsIntPtrOrSmiConstantZero(arguments_count);
DCHECK_IMPLIES(empty, parameter_map_count == nullptr);
TNode<IntPtrT> size =
empty ? IntPtrConstant(base_size)
: ElementOffsetFromIndex(element_count, PACKED_ELEMENTS, mode,
: ElementOffsetFromIndex(element_count, PACKED_ELEMENTS,
base_size + FixedArray::kHeaderSize);
TNode<HeapObject> result = Allocate(size);
Comment("Initialize arguments object");
StoreMapNoWriteBarrier(result, map);
TNode<FixedArray> empty_fixed_array = EmptyFixedArrayConstant();
StoreObjectField(result, JSArray::kPropertiesOrHashOffset, empty_fixed_array);
TNode<Smi> smi_arguments_count = ParameterToTagged(arguments_count, mode);
TNode<Smi> smi_arguments_count = BIntToSmi(arguments_count);
StoreObjectFieldNoWriteBarrier(result, JSArray::kLengthOffset,
smi_arguments_count);
Node* arguments = nullptr;
TNode<HeapObject> arguments;
if (!empty) {
arguments = InnerAllocate(result, elements_offset);
StoreObjectFieldNoWriteBarrier(arguments, FixedArray::kLengthOffset,
......@@ -56,18 +52,17 @@ ArgumentsBuiltinsAssembler::AllocateArgumentsObject(Node* map,
TNode<Map> fixed_array_map = FixedArrayMapConstant();
StoreMapNoWriteBarrier(arguments, fixed_array_map);
}
Node* parameter_map = nullptr;
if (parameter_map_count != nullptr) {
TNode<HeapObject> parameter_map;
if (!parameter_map_count.is_null()) {
TNode<IntPtrT> parameter_map_offset = ElementOffsetFromIndex(
arguments_count, PACKED_ELEMENTS, mode, FixedArray::kHeaderSize);
parameter_map = InnerAllocate(CAST(arguments), parameter_map_offset);
arguments_count, PACKED_ELEMENTS, FixedArray::kHeaderSize);
parameter_map = InnerAllocate(arguments, parameter_map_offset);
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset,
parameter_map);
TNode<Map> sloppy_elements_map = SloppyArgumentsElementsMapConstant();
StoreMapNoWriteBarrier(parameter_map, sloppy_elements_map);
parameter_map_count = ParameterToTagged(parameter_map_count, mode);
StoreObjectFieldNoWriteBarrier(parameter_map, FixedArray::kLengthOffset,
parameter_map_count);
BIntToSmi(parameter_map_count));
} else {
if (empty) {
StoreObjectFieldNoWriteBarrier(result, JSArray::kElementsOffset,
......@@ -77,23 +72,19 @@ ArgumentsBuiltinsAssembler::AllocateArgumentsObject(Node* map,
arguments);
}
}
return std::tuple<Node*, Node*, Node*>(result, arguments, parameter_map);
return {CAST(result), UncheckedCast<FixedArray>(arguments),
UncheckedCast<FixedArray>(parameter_map)};
}
Node* ArgumentsBuiltinsAssembler::ConstructParametersObjectFromArgs(
TNode<JSObject> ArgumentsBuiltinsAssembler::ConstructParametersObjectFromArgs(
TNode<Map> map, TNode<RawPtrT> frame_ptr, TNode<BInt> arg_count,
TNode<BInt> first_arg, TNode<BInt> rest_count, ParameterMode param_mode,
int base_size) {
DCHECK_EQ(param_mode, OptimalParameterMode());
TNode<BInt> first_arg, TNode<BInt> rest_count, int base_size) {
// Allocate the parameter object (either a Rest parameter object, a strict
// argument object or a sloppy arguments object) and the elements together and
// fill in the contents with the arguments above |formal_parameter_count|.
Node* result;
Node* elements;
Node* unused;
std::tie(result, elements, unused) =
AllocateArgumentsObject(map, rest_count, nullptr, param_mode, base_size);
DCHECK_NULL(unused);
ArgumentsAllocationResult alloc_result =
AllocateArgumentsObject(map, rest_count, {}, base_size);
DCHECK(alloc_result.parameter_map.is_null());
CodeStubArguments arguments(this, arg_count, frame_ptr);
TVARIABLE(IntPtrT, offset,
IntPtrConstant(FixedArrayBase::kHeaderSize - kHeapObjectTag));
......@@ -101,23 +92,22 @@ Node* ArgumentsBuiltinsAssembler::ConstructParametersObjectFromArgs(
arguments.ForEach(
list,
[&](TNode<Object> arg) {
StoreNoWriteBarrier(MachineRepresentation::kTagged, elements,
offset.value(), arg);
StoreNoWriteBarrier(MachineRepresentation::kTagged,
alloc_result.elements, offset.value(), arg);
Increment(&offset, kTaggedSize);
},
first_arg);
return result;
return alloc_result.arguments_object;
}
Node* ArgumentsBuiltinsAssembler::EmitFastNewRestParameter(Node* context,
Node* function) {
TNode<JSObject> ArgumentsBuiltinsAssembler::EmitFastNewRestParameter(
TNode<Context> context, TNode<JSFunction> function) {
ParameterMode mode = OptimalParameterMode();
Node* zero = IntPtrOrSmiConstant(0, mode);
TNode<BInt> zero = BIntConstant(0);
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(
CAST(context), UncheckedCast<JSFunction>(function));
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(context, function);
VARIABLE(result, MachineRepresentation::kTagged);
TVARIABLE(JSObject, result);
Label no_rest_parameters(this), runtime(this, Label::kDeferred),
done(this, &result);
......@@ -126,33 +116,29 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewRestParameter(Node* context,
TNode<NativeContext> const native_context = LoadNativeContext(context);
TNode<Map> const array_map =
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
GotoIf(IntPtrOrSmiLessThanOrEqual(rest_count, zero, mode),
&no_rest_parameters);
GotoIf(IntPtrOrSmiLessThanOrEqual(rest_count, zero), &no_rest_parameters);
GotoIfFixedArraySizeDoesntFitInNewSpace(
rest_count, &runtime, JSArray::kSize + FixedArray::kHeaderSize, mode);
// Allocate the Rest JSArray and the elements together and fill in the
// contents with the arguments above |formal_parameter_count|.
result.Bind(ConstructParametersObjectFromArgs(
result = ConstructParametersObjectFromArgs(
array_map, info.frame, info.argument_count, info.formal_parameter_count,
rest_count, mode, JSArray::kSize));
rest_count, JSArray::kSize);
Goto(&done);
BIND(&no_rest_parameters);
{
Node* arguments;
Node* elements;
Node* unused;
std::tie(arguments, elements, unused) =
AllocateArgumentsObject(array_map, zero, nullptr, mode, JSArray::kSize);
result.Bind(arguments);
ArgumentsAllocationResult alloc_result =
AllocateArgumentsObject(array_map, zero, {}, JSArray::kSize);
result = alloc_result.arguments_object;
Goto(&done);
}
BIND(&runtime);
{
result.Bind(CallRuntime(Runtime::kNewRestParameter, context, function));
result = CAST(CallRuntime(Runtime::kNewRestParameter, context, function));
Goto(&done);
}
......@@ -160,16 +146,15 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewRestParameter(Node* context,
return result.value();
}
Node* ArgumentsBuiltinsAssembler::EmitFastNewStrictArguments(Node* context,
Node* function) {
VARIABLE(result, MachineRepresentation::kTagged);
TNode<JSObject> ArgumentsBuiltinsAssembler::EmitFastNewStrictArguments(
TNode<Context> context, TNode<JSFunction> function) {
TVARIABLE(JSObject, result);
Label done(this, &result), empty(this), runtime(this, Label::kDeferred);
ParameterMode mode = OptimalParameterMode();
TNode<BInt> zero = BIntConstant(0);
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(
CAST(context), UncheckedCast<JSFunction>(function));
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(context, function);
GotoIfFixedArraySizeDoesntFitInNewSpace(
info.argument_count, &runtime,
......@@ -180,25 +165,22 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewStrictArguments(Node* context,
LoadContextElement(native_context, Context::STRICT_ARGUMENTS_MAP_INDEX));
GotoIf(BIntEqual(info.argument_count, zero), &empty);
result.Bind(ConstructParametersObjectFromArgs(
map, info.frame, info.argument_count, zero, info.argument_count, mode,
JSStrictArgumentsObject::kSize));
result = ConstructParametersObjectFromArgs(
map, info.frame, info.argument_count, zero, info.argument_count,
JSStrictArgumentsObject::kSize);
Goto(&done);
BIND(&empty);
{
Node* arguments;
Node* elements;
Node* unused;
std::tie(arguments, elements, unused) = AllocateArgumentsObject(
map, zero, nullptr, mode, JSStrictArgumentsObject::kSize);
result.Bind(arguments);
ArgumentsAllocationResult alloc_result =
AllocateArgumentsObject(map, zero, {}, JSStrictArgumentsObject::kSize);
result = alloc_result.arguments_object;
Goto(&done);
}
BIND(&runtime);
{
result.Bind(CallRuntime(Runtime::kNewStrictArguments, context, function));
result = CAST(CallRuntime(Runtime::kNewStrictArguments, context, function));
Goto(&done);
}
......@@ -206,9 +188,9 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewStrictArguments(Node* context,
return result.value();
}
Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
Node* function) {
VARIABLE(result, MachineRepresentation::kTagged);
TNode<JSObject> ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(
TNode<Context> context, TNode<JSFunction> function) {
TVARIABLE(JSObject, result);
ParameterMode mode = OptimalParameterMode();
TNode<BInt> zero = BIntConstant(0);
......@@ -216,8 +198,7 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
Label done(this, &result), empty(this), no_parameters(this),
runtime(this, Label::kDeferred);
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(
CAST(context), UncheckedCast<JSFunction>(function));
TorqueStructArgumentsInfo info = GetArgumentsFrameAndCount(context, function);
GotoIf(BIntEqual(info.argument_count, zero), &empty);
......@@ -240,18 +221,18 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
JSSloppyArgumentsObject::kSize + FixedArray::kHeaderSize * 2, mode);
TNode<NativeContext> const native_context = LoadNativeContext(context);
TNode<Object> const map = LoadContextElement(
native_context, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX);
Node* argument_object;
Node* elements;
Node* map_array;
std::tie(argument_object, elements, map_array) =
TNode<Map> const map = CAST(LoadContextElement(
native_context, Context::FAST_ALIASED_ARGUMENTS_MAP_INDEX));
ArgumentsAllocationResult alloc_result =
AllocateArgumentsObject(map, info.argument_count, parameter_map_size,
mode, JSSloppyArgumentsObject::kSize);
StoreObjectFieldNoWriteBarrier(
argument_object, JSSloppyArgumentsObject::kCalleeOffset, function);
StoreFixedArrayElement(CAST(map_array), 0, context, SKIP_WRITE_BARRIER);
StoreFixedArrayElement(CAST(map_array), 1, elements, SKIP_WRITE_BARRIER);
JSSloppyArgumentsObject::kSize);
StoreObjectFieldNoWriteBarrier(alloc_result.arguments_object,
JSSloppyArgumentsObject::kCalleeOffset,
function);
StoreFixedArrayElement(alloc_result.parameter_map, 0, context,
SKIP_WRITE_BARRIER);
StoreFixedArrayElement(alloc_result.parameter_map, 1, alloc_result.elements,
SKIP_WRITE_BARRIER);
Comment("Fill in non-mapped parameters");
TNode<IntPtrT> argument_offset =
......@@ -270,8 +251,8 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
Increment(&current_argument, kSystemPointerSize);
TNode<Object> arg = LoadBufferObject(
ReinterpretCast<RawPtrT>(current_argument.value()), 0);
StoreNoWriteBarrier(MachineRepresentation::kTagged, elements, offset,
arg);
StoreNoWriteBarrier(MachineRepresentation::kTagged,
alloc_result.elements, offset, arg);
return;
},
-kTaggedSize);
......@@ -294,15 +275,15 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
VariableList var_list2({&context_index}, zone());
const int kParameterMapHeaderSize = FixedArray::OffsetOfElementAt(2);
TNode<IntPtrT> adjusted_map_array = IntPtrAdd(
BitcastTaggedToWord(map_array),
BitcastTaggedToWord(alloc_result.parameter_map),
IntPtrConstant(kParameterMapHeaderSize - FixedArray::kHeaderSize));
TNode<IntPtrT> zero_offset = ElementOffsetFromIndex(
zero, PACKED_ELEMENTS, mode, FixedArray::kHeaderSize - kHeapObjectTag);
BuildFastLoop<IntPtrT>(
var_list2, mapped_offset, zero_offset,
[&](TNode<IntPtrT> offset) {
StoreNoWriteBarrier(MachineRepresentation::kTagged, elements, offset,
the_hole);
StoreNoWriteBarrier(MachineRepresentation::kTagged,
alloc_result.elements, offset, the_hole);
StoreNoWriteBarrier(MachineRepresentation::kTagged,
adjusted_map_array, offset,
BIntToSmi(context_index.value()));
......@@ -310,7 +291,7 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
},
-kTaggedSize);
result.Bind(argument_object);
result = alloc_result.arguments_object;
Goto(&done);
}
......@@ -323,9 +304,9 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
TNode<NativeContext> const native_context = LoadNativeContext(context);
TNode<Map> map = CAST(LoadContextElement(
native_context, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
result.Bind(ConstructParametersObjectFromArgs(
map, info.frame, info.argument_count, zero, info.argument_count, mode,
JSSloppyArgumentsObject::kSize));
result = ConstructParametersObjectFromArgs(
map, info.frame, info.argument_count, zero, info.argument_count,
JSSloppyArgumentsObject::kSize);
StoreObjectFieldNoWriteBarrier(
result.value(), JSSloppyArgumentsObject::kCalleeOffset, function);
Goto(&done);
......@@ -335,14 +316,11 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
{
Comment("Empty JSSloppyArgumentsObject");
TNode<NativeContext> const native_context = LoadNativeContext(context);
TNode<Object> const map =
LoadContextElement(native_context, Context::SLOPPY_ARGUMENTS_MAP_INDEX);
Node* arguments;
Node* elements;
Node* unused;
std::tie(arguments, elements, unused) = AllocateArgumentsObject(
map, zero, nullptr, mode, JSSloppyArgumentsObject::kSize);
result.Bind(arguments);
TNode<Map> const map = CAST(LoadContextElement(
native_context, Context::SLOPPY_ARGUMENTS_MAP_INDEX));
ArgumentsAllocationResult alloc_result =
AllocateArgumentsObject(map, zero, {}, JSSloppyArgumentsObject::kSize);
result = alloc_result.arguments_object;
StoreObjectFieldNoWriteBarrier(
result.value(), JSSloppyArgumentsObject::kCalleeOffset, function);
Goto(&done);
......@@ -350,7 +328,7 @@ Node* ArgumentsBuiltinsAssembler::EmitFastNewSloppyArguments(Node* context,
BIND(&runtime);
{
result.Bind(CallRuntime(Runtime::kNewSloppyArguments, context, function));
result = CAST(CallRuntime(Runtime::kNewSloppyArguments, context, function));
Goto(&done);
}
......
......@@ -10,7 +10,7 @@
namespace v8 {
namespace internal {
using Node = compiler::Node;
// TODO(v8:9396): these declarations pollute the v8::internal scope.
using CodeAssemblerState = compiler::CodeAssemblerState;
using CodeAssemblerLabel = compiler::CodeAssemblerLabel;
......@@ -19,19 +19,25 @@ class ArgumentsBuiltinsAssembler : public CodeStubAssembler {
explicit ArgumentsBuiltinsAssembler(CodeAssemblerState* state)
: CodeStubAssembler(state) {}
Node* EmitFastNewStrictArguments(Node* context, Node* function);
Node* EmitFastNewSloppyArguments(Node* context, Node* function);
Node* EmitFastNewRestParameter(Node* context, Node* function);
TNode<JSObject> EmitFastNewStrictArguments(TNode<Context> context,
TNode<JSFunction> function);
TNode<JSObject> EmitFastNewSloppyArguments(TNode<Context> context,
TNode<JSFunction> function);
TNode<JSObject> EmitFastNewRestParameter(TNode<Context> context,
TNode<JSFunction> function);
private:
struct ArgumentsAllocationResult {
TNode<JSObject> arguments_object;
TNode<FixedArray> elements;
TNode<FixedArray> parameter_map;
};
// Allocates an an arguments (either rest, strict or sloppy) together with the
// FixedArray elements for the arguments and a parameter map (for sloppy
// arguments only). A tuple is returned with pointers to the arguments object,
// the elements and parameter map in the form:
// <argument object, arguments FixedArray, parameter map or nullptr>
std::tuple<Node*, Node*, Node*> AllocateArgumentsObject(
Node* map, Node* arguments, Node* mapped_arguments,
ParameterMode param_mode, int base_size);
// arguments only, or empty TNode<> otherwise).
ArgumentsAllocationResult AllocateArgumentsObject(
TNode<Map> map, TNode<BInt> arguments, TNode<BInt> mapped_arguments,
int base_size);
// For Rest parameters and Strict arguments, the copying of parameters from
// the stack into the arguments object is straight-forward and shares much of
......@@ -40,10 +46,9 @@ class ArgumentsBuiltinsAssembler : public CodeStubAssembler {
// and then copies |rest_count| arguments from the stack frame pointed to by
// |frame_ptr| starting from |first_arg|. |arg_count| == |first_arg| +
// |rest_count|.
Node* ConstructParametersObjectFromArgs(
TNode<JSObject> ConstructParametersObjectFromArgs(
TNode<Map> map, TNode<RawPtrT> frame_ptr, TNode<BInt> arg_count,
TNode<BInt> first_arg, TNode<BInt> rest_count, ParameterMode param_mode,
int base_size);
TNode<BInt> first_arg, TNode<BInt> rest_count, int base_size);
};
} // namespace internal
......
......@@ -424,19 +424,29 @@ Node* CodeStubAssembler::IntPtrOrSmiConstant(int value, ParameterMode mode) {
}
}
bool CodeStubAssembler::IsIntPtrOrSmiConstantZero(TNode<Smi> test) {
Smi smi_test;
if (ToSmiConstant(test, &smi_test) && smi_test.value() == 0) {
return true;
}
return false;
}
bool CodeStubAssembler::IsIntPtrOrSmiConstantZero(TNode<IntPtrT> test) {
int32_t constant_test;
if (ToInt32Constant(test, &constant_test) && constant_test == 0) {
return true;
}
return false;
}
bool CodeStubAssembler::IsIntPtrOrSmiConstantZero(Node* test,
ParameterMode mode) {
int32_t constant_test;
Smi smi_test;
if (mode == INTPTR_PARAMETERS) {
if (ToInt32Constant(test, &constant_test) && constant_test == 0) {
return true;
}
return IsIntPtrOrSmiConstantZero(UncheckedCast<IntPtrT>(test));
} else {
DCHECK_EQ(mode, SMI_PARAMETERS);
if (ToSmiConstant(test, &smi_test) && smi_test.value() == 0) {
return true;
}
return IsIntPtrOrSmiConstantZero(UncheckedCast<Smi>(test));
}
return false;
}
......
......@@ -548,7 +548,11 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// TODO(v8:9708): remove once all uses are ported.
Node* IntPtrOrSmiConstant(int value, ParameterMode mode);
bool IsIntPtrOrSmiConstantZero(TNode<Smi> test);
bool IsIntPtrOrSmiConstantZero(TNode<IntPtrT> test);
// TODO(v8:9708): remove once all uses are ported.
bool IsIntPtrOrSmiConstantZero(Node* test, ParameterMode mode);
bool TryGetIntPtrOrSmiConstantValue(Node* maybe_constant, int* value,
ParameterMode mode);
......
......@@ -2851,9 +2851,9 @@ IGNITION_HANDLER(CreateMappedArguments, InterpreterAssembler) {
// Creates a new unmapped arguments object.
IGNITION_HANDLER(CreateUnmappedArguments, InterpreterAssembler) {
TNode<Context> context = GetContext();
TNode<Object> closure = LoadRegister(Register::function_closure());
TNode<JSFunction> closure = CAST(LoadRegister(Register::function_closure()));
ArgumentsBuiltinsAssembler builtins_assembler(state());
Node* result =
TNode<JSObject> result =
builtins_assembler.EmitFastNewStrictArguments(context, closure);
SetAccumulator(result);
Dispatch();
......@@ -2863,10 +2863,11 @@ IGNITION_HANDLER(CreateUnmappedArguments, InterpreterAssembler) {
//
// Creates a new rest parameter array.
IGNITION_HANDLER(CreateRestParameter, InterpreterAssembler) {
TNode<Object> closure = LoadRegister(Register::function_closure());
TNode<JSFunction> closure = CAST(LoadRegister(Register::function_closure()));
TNode<Context> context = GetContext();
ArgumentsBuiltinsAssembler builtins_assembler(state());
Node* result = builtins_assembler.EmitFastNewRestParameter(context, closure);
TNode<JSObject> result =
builtins_assembler.EmitFastNewRestParameter(context, closure);
SetAccumulator(result);
Dispatch();
}
......
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