Commit 6fafd68a authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[csa] TNodify builtins-array-gen.cc

Convert all but 4 Node*s to TNode and all Variables to TVariable.

In the process this also deletes several unused functions.

Bug: v8:6949, v8:9396
Change-Id: I83db40eefacf8a4a1b155249c5bb8217e6c7da83
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1803347
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarSantiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63770}
parent 1603f672
......@@ -25,10 +25,9 @@ using IteratorRecord = TorqueStructIteratorRecord;
ArrayBuiltinsAssembler::ArrayBuiltinsAssembler(
compiler::CodeAssemblerState* state)
: CodeStubAssembler(state),
k_(this, MachineRepresentation::kTagged),
a_(this, MachineRepresentation::kTagged),
to_(this, MachineRepresentation::kTagged, SmiConstant(0)),
fully_spec_compliant_(this, {&k_, &a_, &to_}) {}
k_(this),
a_(this),
fully_spec_compliant_(this, {&k_, &a_}) {}
void ArrayBuiltinsAssembler::TypedArrayMapResultGenerator() {
// 6. Let A be ? TypedArraySpeciesCreate(O, len).
......@@ -44,14 +43,16 @@ void ArrayBuiltinsAssembler::TypedArrayMapResultGenerator() {
LoadJSTypedArrayLength(a)));
fast_typed_array_target_ =
Word32Equal(LoadElementsKind(original_array), LoadElementsKind(a));
a_.Bind(a);
a_ = a;
}
// See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map.
Node* ArrayBuiltinsAssembler::TypedArrayMapProcessor(Node* k_value, Node* k) {
TNode<Object> ArrayBuiltinsAssembler::TypedArrayMapProcessor(
TNode<Object> k_value, TNode<Object> k) {
// 8. c. Let mapped_value be ? Call(callbackfn, T, « kValue, k, O »).
Node* mapped_value = CallJS(CodeFactory::Call(isolate()), context(),
callbackfn(), this_arg(), k_value, k, o());
TNode<Object> mapped_value =
CAST(CallJS(CodeFactory::Call(isolate()), context(), callbackfn(),
this_arg(), k_value, k, o()));
Label fast(this), slow(this), done(this), detached(this, Label::kDeferred);
// 8. d. Perform ? Set(A, Pk, mapped_value, true).
......@@ -65,7 +66,7 @@ Node* ArrayBuiltinsAssembler::TypedArrayMapProcessor(Node* k_value, Node* k) {
// 5. If arrayTypeName is "BigUint64Array" or "BigInt64Array", let
// numValue be ? ToBigInt(v).
// 6. Otherwise, let numValue be ? ToNumber(value).
Node* num_value;
TNode<Object> num_value;
if (source_elements_kind_ == BIGINT64_ELEMENTS ||
source_elements_kind_ == BIGUINT64_ELEMENTS) {
num_value = ToBigInt(context(), mapped_value);
......@@ -78,7 +79,7 @@ Node* ArrayBuiltinsAssembler::TypedArrayMapProcessor(Node* k_value, Node* k) {
Goto(&done);
BIND(&slow);
SetPropertyStrict(context(), CAST(a()), CAST(k), CAST(mapped_value));
SetPropertyStrict(context(), a(), k, mapped_value);
Goto(&done);
BIND(&detached);
......@@ -90,32 +91,7 @@ Node* ArrayBuiltinsAssembler::TypedArrayMapProcessor(Node* k_value, Node* k) {
return a();
}
void ArrayBuiltinsAssembler::NullPostLoopAction() {}
void ArrayBuiltinsAssembler::FillFixedArrayWithSmiZero(TNode<FixedArray> array,
TNode<Smi> smi_length) {
CSA_ASSERT(this, Word32BinaryNot(IsFixedDoubleArray(array)));
TNode<IntPtrT> length = SmiToIntPtr(smi_length);
TNode<IntPtrT> byte_length = TimesTaggedSize(length);
CSA_ASSERT(this, UintPtrLessThan(length, byte_length));
static const int32_t fa_base_data_offset =
FixedArray::kHeaderSize - kHeapObjectTag;
TNode<IntPtrT> backing_store = IntPtrAdd(BitcastTaggedToWord(array),
IntPtrConstant(fa_base_data_offset));
// Call out to memset to perform initialization.
TNode<ExternalReference> memset =
ExternalConstant(ExternalReference::libc_memset_function());
STATIC_ASSERT(kSizetSize == kIntptrSize);
CallCFunction(memset, MachineType::Pointer(),
std::make_pair(MachineType::Pointer(), backing_store),
std::make_pair(MachineType::IntPtr(), IntPtrConstant(0)),
std::make_pair(MachineType::UintPtr(), byte_length));
}
void ArrayBuiltinsAssembler::ReturnFromBuiltin(Node* value) {
void ArrayBuiltinsAssembler::ReturnFromBuiltin(TNode<Object> value) {
if (argc_ == nullptr) {
Return(value);
} else {
......@@ -126,8 +102,8 @@ void ArrayBuiltinsAssembler::ReturnFromBuiltin(Node* value) {
}
void ArrayBuiltinsAssembler::InitIteratingArrayBuiltinBody(
TNode<Context> context, TNode<Object> receiver, Node* callbackfn,
Node* this_arg, TNode<IntPtrT> argc) {
TNode<Context> context, TNode<Object> receiver, TNode<Object> callbackfn,
TNode<Object> this_arg, TNode<IntPtrT> argc) {
context_ = context;
receiver_ = receiver;
callbackfn_ = callbackfn;
......@@ -137,8 +113,7 @@ void ArrayBuiltinsAssembler::InitIteratingArrayBuiltinBody(
void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
const char* name, const BuiltinResultGenerator& generator,
const CallResultProcessor& processor, const PostLoopAction& action,
ForEachDirection direction) {
const CallResultProcessor& processor, ForEachDirection direction) {
name_ = name;
// ValidateTypedArray: tc39.github.io/ecma262/#sec-validatetypedarray
......@@ -160,7 +135,7 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
Label throw_not_callable(this, Label::kDeferred);
Label distinguish_types(this);
GotoIf(TaggedIsSmi(callbackfn_), &throw_not_callable);
Branch(IsCallableMap(LoadMap(callbackfn_)), &distinguish_types,
Branch(IsCallableMap(LoadMap(CAST(callbackfn_))), &distinguish_types,
&throw_not_callable);
BIND(&throw_not_typed_array);
......@@ -192,9 +167,9 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
generator(this);
if (direction == ForEachDirection::kForward) {
k_.Bind(SmiConstant(0));
k_ = SmiConstant(0);
} else {
k_.Bind(NumberDec(len()));
k_ = NumberDec(len());
}
CSA_ASSERT(this, IsSafeInteger(k()));
TNode<Int32T> elements_kind = LoadMapElementsKind(typed_array_map);
......@@ -214,15 +189,15 @@ void ArrayBuiltinsAssembler::GenerateIteratingTypedArrayBuiltinBody(
Goto(&done);
// No exception, return success
BIND(&done);
action(this);
ReturnFromBuiltin(a_.value());
}
}
void ArrayBuiltinsAssembler::VisitAllTypedArrayElements(
Node* array_buffer, const CallResultProcessor& processor, Label* detached,
ForEachDirection direction, TNode<JSTypedArray> typed_array) {
VariableList list({&a_, &k_, &to_}, zone());
TNode<JSArrayBuffer> array_buffer, const CallResultProcessor& processor,
Label* detached, ForEachDirection direction,
TNode<JSTypedArray> typed_array) {
VariableList list({&a_, &k_}, zone());
TNode<Smi> start = SmiConstant(0);
TNode<Smi> end = CAST(len_);
......@@ -236,62 +211,16 @@ void ArrayBuiltinsAssembler::VisitAllTypedArrayElements(
BuildFastLoop<Smi>(
list, start, end,
[&](TNode<Smi> index) {
GotoIf(IsDetachedBuffer(CAST(array_buffer)), detached);
GotoIf(IsDetachedBuffer(array_buffer), detached);
TNode<RawPtrT> data_ptr = LoadJSTypedArrayBackingStore(typed_array);
TNode<Object> value = LoadFixedTypedArrayElementAsTagged(
data_ptr, index, source_elements_kind_, SMI_PARAMETERS);
k_.Bind(index);
a_.Bind(processor(this, value, index));
k_ = index;
a_ = processor(this, value, index);
},
incr, advance_mode);
}
// Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
void ArrayBuiltinsAssembler::GenerateArraySpeciesCreate(TNode<Number> len) {
Label runtime(this, Label::kDeferred), done(this);
TNode<Map> const original_map = LoadMap(o());
GotoIfNot(InstanceTypeEqual(LoadMapInstanceType(original_map), JS_ARRAY_TYPE),
&runtime);
GotoIfNot(IsPrototypeInitialArrayPrototype(context(), original_map),
&runtime);
TNode<PropertyCell> species_protector = ArraySpeciesProtectorConstant();
TNode<Object> value =
LoadObjectField(species_protector, PropertyCell::kValueOffset);
TNode<Smi> const protector_invalid = SmiConstant(Isolate::kProtectorInvalid);
GotoIf(TaggedEqual(value, protector_invalid), &runtime);
GotoIfNot(TaggedIsPositiveSmi(len), &runtime);
GotoIfNot(IsValidFastJSArrayCapacity(len, CodeStubAssembler::SMI_PARAMETERS),
&runtime);
// We need to be conservative and start with holey because the builtins
// that create output arrays aren't guaranteed to be called for every
// element in the input array (maybe the callback deletes an element).
const ElementsKind elements_kind =
GetHoleyElementsKind(GetInitialFastElementsKind());
TNode<NativeContext> native_context = LoadNativeContext(context());
TNode<Map> array_map = LoadJSArrayElementsMap(elements_kind, native_context);
a_.Bind(AllocateJSArray(PACKED_SMI_ELEMENTS, array_map, len, CAST(len), {},
CodeStubAssembler::SMI_PARAMETERS,
kAllowLargeObjectAllocation));
Goto(&done);
BIND(&runtime);
{
// 5. Let A be ? ArraySpeciesCreate(O, len).
TNode<JSReceiver> constructor =
CAST(CallRuntime(Runtime::kArraySpeciesConstructor, context(), o()));
a_.Bind(Construct(context(), constructor, len));
Goto(&fully_spec_compliant_);
}
BIND(&done);
}
TF_BUILTIN(ArrayPrototypePop, CodeStubAssembler) {
TNode<Int32T> argc =
UncheckedCast<Int32T>(Parameter(Descriptor::kJSActualArgumentsCount));
......@@ -844,8 +773,7 @@ TF_BUILTIN(TypedArrayPrototypeMap, ArrayBuiltinsAssembler) {
GenerateIteratingTypedArrayBuiltinBody(
"%TypedArray%.prototype.map",
&ArrayBuiltinsAssembler::TypedArrayMapResultGenerator,
&ArrayBuiltinsAssembler::TypedArrayMapProcessor,
&ArrayBuiltinsAssembler::NullPostLoopAction);
&ArrayBuiltinsAssembler::TypedArrayMapProcessor);
}
TF_BUILTIN(ArrayIsArray, CodeStubAssembler) {
......@@ -882,15 +810,18 @@ class ArrayIncludesIndexofAssembler : public CodeStubAssembler {
void Generate(SearchVariant variant, TNode<IntPtrT> argc,
TNode<Context> context);
void GenerateSmiOrObject(SearchVariant variant, Node* context, Node* elements,
TNode<Object> search_element, Node* array_length,
Node* from_index);
void GeneratePackedDoubles(SearchVariant variant, Node* elements,
Node* search_element, Node* array_length,
Node* from_index);
void GenerateHoleyDoubles(SearchVariant variant, Node* elements,
Node* search_element, Node* array_length,
Node* from_index);
void GenerateSmiOrObject(SearchVariant variant, TNode<Context> context,
TNode<FixedArray> elements,
TNode<Object> search_element,
TNode<Smi> array_length, TNode<Smi> from_index);
void GeneratePackedDoubles(SearchVariant variant,
TNode<FixedDoubleArray> elements,
TNode<Object> search_element,
TNode<Smi> array_length, TNode<Smi> from_index);
void GenerateHoleyDoubles(SearchVariant variant,
TNode<FixedDoubleArray> elements,
TNode<Object> search_element,
TNode<Smi> array_length, TNode<Smi> from_index);
};
void ArrayIncludesIndexofAssembler::Generate(SearchVariant variant,
......@@ -914,7 +845,7 @@ void ArrayIncludesIndexofAssembler::Generate(SearchVariant variant,
BranchIfFastJSArrayForRead(receiver, context, &init_index, &call_runtime);
BIND(&init_index);
VARIABLE(index_var, MachineType::PointerRepresentation(), intptr_zero);
TVARIABLE(IntPtrT, index_var, intptr_zero);
TNode<JSArray> array = CAST(receiver);
// JSArray length is always a positive Smi for fast arrays.
......@@ -944,14 +875,14 @@ void ArrayIncludesIndexofAssembler::Generate(SearchVariant variant,
BIND(&is_smi);
{
TNode<IntPtrT> intptr_start_from = SmiUntag(CAST(start_from));
index_var.Bind(intptr_start_from);
index_var = intptr_start_from;
GotoIf(IntPtrGreaterThanOrEqual(index_var.value(), intptr_zero), &done);
// The fromIndex is negative: add it to the array's length.
index_var.Bind(IntPtrAdd(array_length_untagged, index_var.value()));
index_var = IntPtrAdd(array_length_untagged, index_var.value());
// Clamp negative results at zero.
GotoIf(IntPtrGreaterThanOrEqual(index_var.value(), intptr_zero), &done);
index_var.Bind(intptr_zero);
index_var = intptr_zero;
Goto(&done);
}
BIND(&done);
......@@ -1039,8 +970,9 @@ void ArrayIncludesIndexofAssembler::Generate(SearchVariant variant,
}
void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
SearchVariant variant, Node* context, Node* elements,
TNode<Object> search_element, Node* array_length, Node* from_index) {
SearchVariant variant, TNode<Context> context, TNode<FixedArray> elements,
TNode<Object> search_element, TNode<Smi> array_length,
TNode<Smi> from_index) {
TVARIABLE(IntPtrT, index_var, SmiUntag(from_index));
TVARIABLE(Float64T, search_num);
TNode<IntPtrT> array_length_untagged = SmiUntag(array_length);
......@@ -1074,7 +1006,7 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
GotoIfNot(UintPtrLessThan(index_var.value(), array_length_untagged),
&return_not_found);
TNode<Object> element_k =
UnsafeLoadFixedArrayElement(CAST(elements), index_var.value());
UnsafeLoadFixedArrayElement(elements, index_var.value());
GotoIf(TaggedEqual(element_k, search_element), &return_found);
Increment(&index_var);
......@@ -1087,7 +1019,7 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
GotoIfNot(UintPtrLessThan(index_var.value(), array_length_untagged),
&return_not_found);
TNode<Object> element_k =
UnsafeLoadFixedArrayElement(CAST(elements), index_var.value());
UnsafeLoadFixedArrayElement(elements, index_var.value());
GotoIf(IsUndefined(element_k), &return_found);
GotoIf(IsTheHole(element_k), &return_found);
......@@ -1107,7 +1039,7 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
GotoIfNot(UintPtrLessThan(index_var.value(), array_length_untagged),
&return_not_found);
TNode<Object> element_k =
UnsafeLoadFixedArrayElement(CAST(elements), index_var.value());
UnsafeLoadFixedArrayElement(elements, index_var.value());
GotoIfNot(TaggedIsSmi(element_k), &not_smi);
Branch(Float64Equal(search_num.value(), SmiToFloat64(CAST(element_k))),
&return_found, &continue_loop);
......@@ -1130,7 +1062,7 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
GotoIfNot(UintPtrLessThan(index_var.value(), array_length_untagged),
&return_not_found);
TNode<Object> element_k =
UnsafeLoadFixedArrayElement(CAST(elements), index_var.value());
UnsafeLoadFixedArrayElement(elements, index_var.value());
GotoIf(TaggedIsSmi(element_k), &continue_loop);
GotoIfNot(IsHeapNumber(CAST(element_k)), &continue_loop);
BranchIfFloat64IsNaN(LoadHeapNumberValue(CAST(element_k)), &return_found,
......@@ -1154,7 +1086,7 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
GotoIfNot(UintPtrLessThan(index_var.value(), array_length_untagged),
&return_not_found);
TNode<Object> element_k =
UnsafeLoadFixedArrayElement(CAST(elements), index_var.value());
UnsafeLoadFixedArrayElement(elements, index_var.value());
GotoIf(TaggedIsSmi(element_k), &continue_loop);
GotoIf(TaggedEqual(search_element_string, element_k), &return_found);
TNode<Uint16T> element_k_type = LoadInstanceType(CAST(element_k));
......@@ -1183,7 +1115,7 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
&return_not_found);
TNode<Object> element_k =
UnsafeLoadFixedArrayElement(CAST(elements), index_var.value());
UnsafeLoadFixedArrayElement(elements, index_var.value());
Label continue_loop(this);
GotoIf(TaggedIsSmi(element_k), &continue_loop);
GotoIfNot(IsBigInt(CAST(element_k)), &continue_loop);
......@@ -1210,11 +1142,10 @@ void ArrayIncludesIndexofAssembler::GenerateSmiOrObject(
}
}
void ArrayIncludesIndexofAssembler::GeneratePackedDoubles(SearchVariant variant,
Node* elements,
Node* search_element,
Node* array_length,
Node* from_index) {
void ArrayIncludesIndexofAssembler::GeneratePackedDoubles(
SearchVariant variant, TNode<FixedDoubleArray> elements,
TNode<Object> search_element, TNode<Smi> array_length,
TNode<Smi> from_index) {
TVARIABLE(IntPtrT, index_var, SmiUntag(from_index));
TNode<IntPtrT> array_length_untagged = SmiUntag(array_length);
......@@ -1225,13 +1156,13 @@ void ArrayIncludesIndexofAssembler::GeneratePackedDoubles(SearchVariant variant,
search_num = Float64Constant(0);
GotoIfNot(TaggedIsSmi(search_element), &search_notnan);
search_num = SmiToFloat64(search_element);
search_num = SmiToFloat64(CAST(search_element));
Goto(&not_nan_loop);
BIND(&search_notnan);
GotoIfNot(IsHeapNumber(search_element), &return_not_found);
GotoIfNot(IsHeapNumber(CAST(search_element)), &return_not_found);
search_num = LoadHeapNumberValue(search_element);
search_num = LoadHeapNumberValue(CAST(search_element));
Label* nan_handling = variant == kIncludes ? &nan_loop : &return_not_found;
BranchIfFloat64IsNaN(search_num.value(), nan_handling, &not_nan_loop);
......@@ -1279,11 +1210,10 @@ void ArrayIncludesIndexofAssembler::GeneratePackedDoubles(SearchVariant variant,
}
}
void ArrayIncludesIndexofAssembler::GenerateHoleyDoubles(SearchVariant variant,
Node* elements,
Node* search_element,
Node* array_length,
Node* from_index) {
void ArrayIncludesIndexofAssembler::GenerateHoleyDoubles(
SearchVariant variant, TNode<FixedDoubleArray> elements,
TNode<Object> search_element, TNode<Smi> array_length,
TNode<Smi> from_index) {
TVARIABLE(IntPtrT, index_var, SmiUntag(from_index));
TNode<IntPtrT> array_length_untagged = SmiUntag(array_length);
......@@ -1294,16 +1224,16 @@ void ArrayIncludesIndexofAssembler::GenerateHoleyDoubles(SearchVariant variant,
search_num = Float64Constant(0);
GotoIfNot(TaggedIsSmi(search_element), &search_notnan);
search_num = SmiToFloat64(search_element);
search_num = SmiToFloat64(CAST(search_element));
Goto(&not_nan_loop);
BIND(&search_notnan);
if (variant == kIncludes) {
GotoIf(IsUndefined(search_element), &hole_loop);
}
GotoIfNot(IsHeapNumber(search_element), &return_not_found);
GotoIfNot(IsHeapNumber(CAST(search_element)), &return_not_found);
search_num = LoadHeapNumberValue(search_element);
search_num = LoadHeapNumberValue(CAST(search_element));
Label* nan_handling = variant == kIncludes ? &nan_loop : &return_not_found;
BranchIfFloat64IsNaN(search_num.value(), nan_handling, &not_nan_loop);
......@@ -1384,30 +1314,30 @@ TF_BUILTIN(ArrayIncludes, ArrayIncludesIndexofAssembler) {
TF_BUILTIN(ArrayIncludesSmiOrObject, ArrayIncludesIndexofAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
Node* elements = Parameter(Descriptor::kElements);
TNode<FixedArray> elements = CAST(Parameter(Descriptor::kElements));
TNode<Object> search_element = CAST(Parameter(Descriptor::kSearchElement));
Node* array_length = Parameter(Descriptor::kLength);
Node* from_index = Parameter(Descriptor::kFromIndex);
TNode<Smi> array_length = CAST(Parameter(Descriptor::kLength));
TNode<Smi> from_index = CAST(Parameter(Descriptor::kFromIndex));
GenerateSmiOrObject(kIncludes, context, elements, search_element,
array_length, from_index);
}
TF_BUILTIN(ArrayIncludesPackedDoubles, ArrayIncludesIndexofAssembler) {
Node* elements = Parameter(Descriptor::kElements);
Node* search_element = Parameter(Descriptor::kSearchElement);
Node* array_length = Parameter(Descriptor::kLength);
Node* from_index = Parameter(Descriptor::kFromIndex);
TNode<FixedDoubleArray> elements = CAST(Parameter(Descriptor::kElements));
TNode<Object> search_element = CAST(Parameter(Descriptor::kSearchElement));
TNode<Smi> array_length = CAST(Parameter(Descriptor::kLength));
TNode<Smi> from_index = CAST(Parameter(Descriptor::kFromIndex));
GeneratePackedDoubles(kIncludes, elements, search_element, array_length,
from_index);
}
TF_BUILTIN(ArrayIncludesHoleyDoubles, ArrayIncludesIndexofAssembler) {
Node* elements = Parameter(Descriptor::kElements);
Node* search_element = Parameter(Descriptor::kSearchElement);
Node* array_length = Parameter(Descriptor::kLength);
Node* from_index = Parameter(Descriptor::kFromIndex);
TNode<FixedDoubleArray> elements = CAST(Parameter(Descriptor::kElements));
TNode<Object> search_element = CAST(Parameter(Descriptor::kSearchElement));
TNode<Smi> array_length = CAST(Parameter(Descriptor::kLength));
TNode<Smi> from_index = CAST(Parameter(Descriptor::kFromIndex));
GenerateHoleyDoubles(kIncludes, elements, search_element, array_length,
from_index);
......@@ -1423,30 +1353,30 @@ TF_BUILTIN(ArrayIndexOf, ArrayIncludesIndexofAssembler) {
TF_BUILTIN(ArrayIndexOfSmiOrObject, ArrayIncludesIndexofAssembler) {
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
Node* elements = Parameter(Descriptor::kElements);
TNode<FixedArray> elements = CAST(Parameter(Descriptor::kElements));
TNode<Object> search_element = CAST(Parameter(Descriptor::kSearchElement));
Node* array_length = Parameter(Descriptor::kLength);
Node* from_index = Parameter(Descriptor::kFromIndex);
TNode<Smi> array_length = CAST(Parameter(Descriptor::kLength));
TNode<Smi> from_index = CAST(Parameter(Descriptor::kFromIndex));
GenerateSmiOrObject(kIndexOf, context, elements, search_element, array_length,
from_index);
}
TF_BUILTIN(ArrayIndexOfPackedDoubles, ArrayIncludesIndexofAssembler) {
Node* elements = Parameter(Descriptor::kElements);
Node* search_element = Parameter(Descriptor::kSearchElement);
Node* array_length = Parameter(Descriptor::kLength);
Node* from_index = Parameter(Descriptor::kFromIndex);
TNode<FixedDoubleArray> elements = CAST(Parameter(Descriptor::kElements));
TNode<Object> search_element = CAST(Parameter(Descriptor::kSearchElement));
TNode<Smi> array_length = CAST(Parameter(Descriptor::kLength));
TNode<Smi> from_index = CAST(Parameter(Descriptor::kFromIndex));
GeneratePackedDoubles(kIndexOf, elements, search_element, array_length,
from_index);
}
TF_BUILTIN(ArrayIndexOfHoleyDoubles, ArrayIncludesIndexofAssembler) {
Node* elements = Parameter(Descriptor::kElements);
Node* search_element = Parameter(Descriptor::kSearchElement);
Node* array_length = Parameter(Descriptor::kLength);
Node* from_index = Parameter(Descriptor::kFromIndex);
TNode<FixedDoubleArray> elements = CAST(Parameter(Descriptor::kElements));
TNode<Object> search_element = CAST(Parameter(Descriptor::kSearchElement));
TNode<Smi> array_length = CAST(Parameter(Descriptor::kLength));
TNode<Smi> from_index = CAST(Parameter(Descriptor::kFromIndex));
GenerateHoleyDoubles(kIndexOf, elements, search_element, array_length,
from_index);
......@@ -1481,10 +1411,10 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
const char* method_name = "Array Iterator.prototype.next";
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
Node* iterator = Parameter(Descriptor::kReceiver);
TNode<Object> maybe_iterator = CAST(Parameter(Descriptor::kReceiver));
VARIABLE(var_done, MachineRepresentation::kTagged, TrueConstant());
VARIABLE(var_value, MachineRepresentation::kTagged, UndefinedConstant());
TVARIABLE(Oddball, var_done, TrueConstant());
TVARIABLE(Object, var_value, UndefinedConstant());
Label allocate_entry_if_needed(this);
Label allocate_iterator_result(this);
......@@ -1494,9 +1424,11 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
// If O does not have all of the internal slots of an Array Iterator Instance
// (22.1.5.3), throw a TypeError exception
ThrowIfNotInstanceType(context, iterator, JS_ARRAY_ITERATOR_TYPE,
ThrowIfNotInstanceType(context, maybe_iterator, JS_ARRAY_ITERATOR_TYPE,
method_name);
TNode<JSArrayIterator> iterator = CAST(maybe_iterator);
// Let a be O.[[IteratedObject]].
TNode<JSReceiver> array =
CAST(LoadObjectField(iterator, JSArrayIterator::kIteratedObjectOffset));
......@@ -1528,8 +1460,8 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
iterator, JSArrayIterator::kNextIndexOffset,
ChangeUint32ToTagged(Unsigned(Int32Add(index32, Int32Constant(1)))));
var_done.Bind(FalseConstant());
var_value.Bind(index);
var_done = FalseConstant();
var_value = index;
GotoIf(Word32Equal(LoadAndUntagToWord32ObjectField(
iterator, JSArrayIterator::kKindOffset),
......@@ -1540,9 +1472,9 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
TNode<Int32T> elements_kind = LoadMapElementsKind(array_map);
TNode<FixedArrayBase> elements = LoadElements(CAST(array));
GotoIfForceSlowPath(&if_generic);
var_value.Bind(LoadFixedArrayBaseElementAsTagged(
var_value = LoadFixedArrayBaseElementAsTagged(
elements, Signed(ChangeUint32ToWord(index32)), elements_kind,
&if_generic, &if_hole));
&if_generic, &if_hole);
Goto(&allocate_entry_if_needed);
BIND(&if_hole);
......@@ -1550,7 +1482,7 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
GotoIf(IsNoElementsProtectorCellInvalid(), &if_generic);
GotoIfNot(IsPrototypeInitialArrayPrototype(context, array_map),
&if_generic);
var_value.Bind(UndefinedConstant());
var_value = UndefinedConstant();
Goto(&allocate_entry_if_needed);
}
}
......@@ -1569,8 +1501,8 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
StoreObjectField(iterator, JSArrayIterator::kNextIndexOffset,
NumberInc(index));
var_done.Bind(FalseConstant());
var_value.Bind(index);
var_done = FalseConstant();
var_value = index;
Branch(Word32Equal(LoadAndUntagToWord32ObjectField(
iterator, JSArrayIterator::kKindOffset),
......@@ -1606,7 +1538,7 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
BIND(&if_generic);
{
var_value.Bind(GetProperty(context, array, index));
var_value = GetProperty(context, array, index);
Goto(&allocate_entry_if_needed);
}
......@@ -1629,8 +1561,8 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
StoreObjectFieldNoWriteBarrier(iterator, JSArrayIterator::kNextIndexOffset,
SmiInc(CAST(index)));
var_done.Bind(FalseConstant());
var_value.Bind(index);
var_done = FalseConstant();
var_value = index;
GotoIf(Word32Equal(LoadAndUntagToWord32ObjectField(
iterator, JSArrayIterator::kKindOffset),
......@@ -1639,8 +1571,8 @@ TF_BUILTIN(ArrayIteratorPrototypeNext, CodeStubAssembler) {
TNode<Int32T> elements_kind = LoadMapElementsKind(array_map);
TNode<RawPtrT> data_ptr = LoadJSTypedArrayBackingStore(CAST(array));
var_value.Bind(LoadFixedTypedArrayElementAsTagged(data_ptr, CAST(index),
elements_kind));
var_value = LoadFixedTypedArrayElementAsTagged(data_ptr, CAST(index),
elements_kind);
Goto(&allocate_entry_if_needed);
}
......@@ -1670,29 +1602,28 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
: CodeStubAssembler(state) {}
// https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
Node* FlattenIntoArray(Node* context, Node* target, Node* source,
Node* source_length, Node* start, Node* depth,
Node* mapper_function = nullptr,
Node* this_arg = nullptr) {
CSA_ASSERT(this, IsJSReceiver(target));
CSA_ASSERT(this, IsJSReceiver(source));
TNode<Number> FlattenIntoArray(
TNode<Context> context, TNode<JSReceiver> target,
TNode<JSReceiver> source, TNode<Number> source_length,
TNode<Number> start, TNode<Number> depth,
base::Optional<TNode<HeapObject>> mapper_function = base::nullopt,
base::Optional<TNode<Object>> this_arg = base::nullopt) {
CSA_ASSERT(this, IsNumberPositive(source_length));
CSA_ASSERT(this, IsNumberPositive(start));
CSA_ASSERT(this, IsNumber(depth));
// 1. Let targetIndex be start.
VARIABLE(var_target_index, MachineRepresentation::kTagged, start);
TVARIABLE(Number, var_target_index, start);
// 2. Let sourceIndex be 0.
VARIABLE(var_source_index, MachineRepresentation::kTagged, SmiConstant(0));
TVARIABLE(Number, var_source_index, SmiConstant(0));
// 3. Repeat...
Label loop(this, {&var_target_index, &var_source_index}), done_loop(this);
Goto(&loop);
BIND(&loop);
{
Node* const source_index = var_source_index.value();
Node* const target_index = var_target_index.value();
TNode<Number> source_index = var_source_index.value();
TNode<Number> target_index = var_target_index.value();
// ...while sourceIndex < sourceLen
GotoIfNumberGreaterThanOrEqual(source_index, source_length, &done_loop);
......@@ -1713,16 +1644,16 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
GetProperty(context, source, source_index);
// ii. If mapperFunction is present, then
if (mapper_function != nullptr) {
CSA_ASSERT(this, Word32Or(IsUndefined(mapper_function),
IsCallable(mapper_function)));
DCHECK_NOT_NULL(this_arg);
if (mapper_function) {
CSA_ASSERT(this, Word32Or(IsUndefined(mapper_function.value()),
IsCallable(mapper_function.value())));
DCHECK(this_arg.has_value());
// 1. Set element to ? Call(mapperFunction, thisArg , « element,
// sourceIndex, source »).
element_maybe_smi = CAST(
CallJS(CodeFactory::Call(isolate()), context, mapper_function,
this_arg, element_maybe_smi, source_index, source));
element_maybe_smi = CAST(CallJS(
CodeFactory::Call(isolate()), context, mapper_function.value(),
this_arg.value(), element_maybe_smi, source_index, source));
}
// iii. Let shouldFlatten be false.
......@@ -1749,7 +1680,7 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
// 2. Set targetIndex to ? FlattenIntoArray(target, element,
// elementLen, targetIndex,
// depth - 1).
var_target_index.Bind(
var_target_index = CAST(
CallBuiltin(Builtins::kFlattenIntoArray, context, target, element,
element_length, target_index, NumberDec(depth)));
Goto(&next);
......@@ -1766,7 +1697,7 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
// 2. Set targetIndex to ? FlattenIntoArray(target, element,
// elementLen, targetIndex,
// depth - 1).
var_target_index.Bind(
var_target_index = CAST(
CallBuiltin(Builtins::kFlattenIntoArray, context, target, element,
element_length, target_index, NumberDec(depth)));
Goto(&next);
......@@ -1786,7 +1717,7 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
target_index, element);
// 3. Increase targetIndex by 1.
var_target_index.Bind(NumberInc(target_index));
var_target_index = NumberInc(target_index);
Goto(&next);
BIND(&throw_error);
......@@ -1797,7 +1728,7 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
BIND(&next);
// d. Increase sourceIndex by 1.
var_source_index.Bind(NumberInc(source_index));
var_source_index = NumberInc(source_index);
Goto(&loop);
}
......@@ -1808,16 +1739,16 @@ class ArrayFlattenAssembler : public CodeStubAssembler {
// https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
TF_BUILTIN(FlattenIntoArray, ArrayFlattenAssembler) {
Node* const context = Parameter(Descriptor::kContext);
Node* const target = Parameter(Descriptor::kTarget);
Node* const source = Parameter(Descriptor::kSource);
Node* const source_length = Parameter(Descriptor::kSourceLength);
Node* const start = Parameter(Descriptor::kStart);
Node* const depth = Parameter(Descriptor::kDepth);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<JSReceiver> target = CAST(Parameter(Descriptor::kTarget));
TNode<JSReceiver> source = CAST(Parameter(Descriptor::kSource));
TNode<Number> source_length = CAST(Parameter(Descriptor::kSourceLength));
TNode<Number> start = CAST(Parameter(Descriptor::kStart));
TNode<Number> depth = CAST(Parameter(Descriptor::kDepth));
// FlattenIntoArray might get called recursively, check stack for overflow
// manually as it has stub linkage.
PerformStackCheck(CAST(context));
PerformStackCheck(context);
Return(
FlattenIntoArray(context, target, source, source_length, start, depth));
......@@ -1825,14 +1756,15 @@ TF_BUILTIN(FlattenIntoArray, ArrayFlattenAssembler) {
// https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
TF_BUILTIN(FlatMapIntoArray, ArrayFlattenAssembler) {
Node* const context = Parameter(Descriptor::kContext);
Node* const target = Parameter(Descriptor::kTarget);
Node* const source = Parameter(Descriptor::kSource);
Node* const source_length = Parameter(Descriptor::kSourceLength);
Node* const start = Parameter(Descriptor::kStart);
Node* const depth = Parameter(Descriptor::kDepth);
Node* const mapper_function = Parameter(Descriptor::kMapperFunction);
Node* const this_arg = Parameter(Descriptor::kThisArg);
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
TNode<JSReceiver> target = CAST(Parameter(Descriptor::kTarget));
TNode<JSReceiver> source = CAST(Parameter(Descriptor::kSource));
TNode<Number> source_length = CAST(Parameter(Descriptor::kSourceLength));
TNode<Number> start = CAST(Parameter(Descriptor::kStart));
TNode<Number> depth = CAST(Parameter(Descriptor::kDepth));
TNode<HeapObject> mapper_function =
CAST(Parameter(Descriptor::kMapperFunction));
TNode<Object> this_arg = CAST(Parameter(Descriptor::kThisArg));
Return(FlattenIntoArray(context, target, source, source_length, start, depth,
mapper_function, this_arg));
......@@ -2124,8 +2056,9 @@ TF_BUILTIN(ArrayConstructorImpl, ArrayBuiltinsAssembler) {
}
void ArrayBuiltinsAssembler::GenerateConstructor(
Node* context, Node* array_function, Node* array_map, Node* array_size,
Node* allocation_site, ElementsKind elements_kind,
TNode<Context> context, TNode<HeapObject> array_function,
TNode<Map> array_map, TNode<Object> array_size,
TNode<HeapObject> allocation_site, ElementsKind elements_kind,
AllocationSiteMode mode) {
Label ok(this);
Label smi_size(this);
......@@ -2135,10 +2068,12 @@ void ArrayBuiltinsAssembler::GenerateConstructor(
Branch(TaggedIsSmi(array_size), &smi_size, &call_runtime);
BIND(&smi_size);
{
TNode<Smi> array_size_smi = CAST(array_size);
if (IsFastPackedElementsKind(elements_kind)) {
Label abort(this, Label::kDeferred);
Branch(SmiEqual(CAST(array_size), SmiConstant(0)), &small_smi_size, &abort);
Branch(SmiEqual(array_size_smi, SmiConstant(0)), &small_smi_size, &abort);
BIND(&abort);
TNode<Smi> reason =
......@@ -2148,22 +2083,23 @@ void ArrayBuiltinsAssembler::GenerateConstructor(
int element_size =
IsDoubleElementsKind(elements_kind) ? kDoubleSize : kTaggedSize;
int max_fast_elements =
(kMaxRegularHeapObjectSize - FixedArray::kHeaderSize - JSArray::kSize -
AllocationMemento::kSize) /
(kMaxRegularHeapObjectSize - FixedArray::kHeaderSize -
JSArray::kSize - AllocationMemento::kSize) /
element_size;
Branch(SmiAboveOrEqual(CAST(array_size), SmiConstant(max_fast_elements)),
Branch(SmiAboveOrEqual(array_size_smi, SmiConstant(max_fast_elements)),
&call_runtime, &small_smi_size);
}
BIND(&small_smi_size);
{
TNode<JSArray> array = AllocateJSArray(
elements_kind, CAST(array_map), array_size, CAST(array_size),
elements_kind, array_map, array_size_smi, array_size_smi,
mode == DONT_TRACK_ALLOCATION_SITE ? TNode<AllocationSite>()
: CAST(allocation_site),
CodeStubAssembler::SMI_PARAMETERS);
Return(array);
}
}
BIND(&call_runtime);
{
......@@ -2193,7 +2129,7 @@ void ArrayBuiltinsAssembler::GenerateArraySingleArgumentConstructor(
ElementsKind kind, AllocationSiteOverrideMode mode) {
using Descriptor = ArraySingleArgumentConstructorDescriptor;
TNode<Context> context = CAST(Parameter(Descriptor::kContext));
Node* function = Parameter(Descriptor::kFunction);
TNode<HeapObject> function = CAST(Parameter(Descriptor::kFunction));
TNode<NativeContext> native_context =
CAST(LoadObjectField(function, JSFunction::kContextOffset));
TNode<Map> array_map = LoadJSArrayElementsMap(kind, native_context);
......@@ -2205,8 +2141,11 @@ void ArrayBuiltinsAssembler::GenerateArraySingleArgumentConstructor(
: DONT_TRACK_ALLOCATION_SITE;
}
Node* array_size = Parameter(Descriptor::kArraySizeSmiParameter);
Node* allocation_site = Parameter(Descriptor::kAllocationSite);
TNode<Object> array_size =
CAST(Parameter(Descriptor::kArraySizeSmiParameter));
// allocation_site can be Undefined or an AllocationSite
TNode<HeapObject> allocation_site =
CAST(Parameter(Descriptor::kAllocationSite));
GenerateConstructor(context, function, array_map, array_size, allocation_site,
kind, allocation_site_mode);
......
......@@ -17,51 +17,13 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
using BuiltinResultGenerator =
std::function<void(ArrayBuiltinsAssembler* masm)>;
using CallResultProcessor = std::function<Node*(ArrayBuiltinsAssembler* masm,
Node* k_value, Node* k)>;
using PostLoopAction = std::function<void(ArrayBuiltinsAssembler* masm)>;
void FindResultGenerator();
Node* FindProcessor(Node* k_value, Node* k);
void FindIndexResultGenerator();
Node* FindIndexProcessor(Node* k_value, Node* k);
void ForEachResultGenerator();
Node* ForEachProcessor(Node* k_value, Node* k);
void SomeResultGenerator();
Node* SomeProcessor(Node* k_value, Node* k);
void EveryResultGenerator();
Node* EveryProcessor(Node* k_value, Node* k);
void ReduceResultGenerator();
Node* ReduceProcessor(Node* k_value, Node* k);
void ReducePostLoopAction();
using CallResultProcessor = std::function<TNode<Object>(
ArrayBuiltinsAssembler* masm, TNode<Object> k_value, TNode<Object> k)>;
void TypedArrayMapResultGenerator();
Node* SpecCompliantMapProcessor(Node* k_value, Node* k);
Node* FastMapProcessor(Node* k_value, Node* k);
// See tc39.github.io/ecma262/#sec-%typedarray%.prototype.map.
Node* TypedArrayMapProcessor(Node* k_value, Node* k);
void NullPostLoopAction();
// Uses memset to effectively initialize the given FixedArray with Smi zeroes.
void FillFixedArrayWithSmiZero(TNode<FixedArray> array,
TNode<Smi> smi_length);
TNode<Object> TypedArrayMapProcessor(TNode<Object> k_value, TNode<Object> k);
TNode<String> CallJSArrayArrayJoinConcatToSequentialString(
TNode<FixedArray> fixed_array, TNode<IntPtrT> length, TNode<String> sep,
......@@ -86,20 +48,22 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
TNode<IntPtrT> argc() { return argc_; }
TNode<JSReceiver> o() { return o_; }
TNode<Number> len() { return len_; }
Node* callbackfn() { return callbackfn_; }
Node* this_arg() { return this_arg_; }
TNode<Number> k() { return CAST(k_.value()); }
Node* a() { return a_.value(); }
TNode<Object> callbackfn() { return callbackfn_; }
TNode<Object> this_arg() { return this_arg_; }
TNode<Number> k() { return k_.value(); }
TNode<Object> a() { return a_.value(); }
void ReturnFromBuiltin(Node* value);
void ReturnFromBuiltin(TNode<Object> value);
void InitIteratingArrayBuiltinBody(TNode<Context> context,
TNode<Object> receiver, Node* callbackfn,
Node* this_arg, TNode<IntPtrT> argc);
TNode<Object> receiver,
TNode<Object> callbackfn,
TNode<Object> this_arg,
TNode<IntPtrT> argc);
void GenerateIteratingTypedArrayBuiltinBody(
const char* name, const BuiltinResultGenerator& generator,
const CallResultProcessor& processor, const PostLoopAction& action,
const CallResultProcessor& processor,
ForEachDirection direction = ForEachDirection::kForward);
void TailCallArrayConstructorStub(
......@@ -122,8 +86,10 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
AllocationSiteOverrideMode mode,
TNode<AllocationSite> allocation_site = {});
void GenerateConstructor(Node* context, Node* array_function, Node* array_map,
Node* array_size, Node* allocation_site,
void GenerateConstructor(TNode<Context> context,
TNode<HeapObject> array_function,
TNode<Map> array_map, TNode<Object> array_size,
TNode<HeapObject> allocation_site,
ElementsKind elements_kind, AllocationSiteMode mode);
void GenerateArrayNoArgumentConstructor(ElementsKind kind,
AllocationSiteOverrideMode mode);
......@@ -135,33 +101,22 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
TNode<HeapObject> maybe_allocation_site);
private:
static ElementsKind ElementsKindForInstanceType(InstanceType type);
void VisitAllTypedArrayElements(Node* array_buffer,
void VisitAllTypedArrayElements(TNode<JSArrayBuffer> array_buffer,
const CallResultProcessor& processor,
Label* detached, ForEachDirection direction,
TNode<JSTypedArray> typed_array);
// Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
// This version is specialized to create a zero length array
// of the elements kind of the input array.
void GenerateArraySpeciesCreate();
// Perform ArraySpeciesCreate (ES6 #sec-arrayspeciescreate).
void GenerateArraySpeciesCreate(TNode<Number> len);
Node* callbackfn_ = nullptr;
TNode<Object> callbackfn_;
TNode<JSReceiver> o_;
Node* this_arg_ = nullptr;
TNode<Object> this_arg_;
TNode<Number> len_;
TNode<Context> context_;
TNode<Object> receiver_;
TNode<IntPtrT> argc_;
Node* fast_typed_array_target_ = nullptr;
TNode<BoolT> fast_typed_array_target_;
const char* name_ = nullptr;
Variable k_;
Variable a_;
Variable to_;
TVariable<Number> k_;
TVariable<Object> a_;
Label fully_spec_compliant_;
ElementsKind source_elements_kind_ = ElementsKind::NO_ELEMENTS;
};
......
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