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