Commit 66dd6bdb authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[CSA][cleanup] Turn {} allocation sites into base::nullopt

Bug: v8:10506
Change-Id: I171a587176f4a1a3c98d407e8b6a3b63bbf1ad6a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2202993
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarDan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67852}
parent 402247f3
......@@ -476,7 +476,7 @@ TF_BUILTIN(CloneFastJSArrayFillingHoles, ArrayBuiltinsAssembler) {
LoadElementsKind(array))),
Word32BinaryNot(IsNoElementsProtectorCellInvalid())));
Return(CloneFastJSArray(context, array, {},
Return(CloneFastJSArray(context, array, base::nullopt,
HoleConversionMode::kConvertToUndefined));
}
......@@ -1664,7 +1664,8 @@ void ArrayBuiltinsAssembler::TailCallArrayConstructorStub(
void ArrayBuiltinsAssembler::CreateArrayDispatchNoArgument(
TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode, TNode<AllocationSite> allocation_site) {
AllocationSiteOverrideMode mode,
base::Optional<TNode<AllocationSite>> allocation_site) {
if (mode == DISABLE_ALLOCATION_SITES) {
Callable callable = CodeFactory::ArrayNoArgumentConstructor(
isolate(), GetInitialFastElementsKind(), mode);
......@@ -1673,7 +1674,8 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchNoArgument(
argc);
} else {
DCHECK_EQ(mode, DONT_OVERRIDE);
TNode<Int32T> elements_kind = LoadElementsKind(allocation_site);
DCHECK(allocation_site);
TNode<Int32T> elements_kind = LoadElementsKind(*allocation_site);
// TODO(ishell): Compute the builtin index dynamically instead of
// iterating over all expected elements kinds.
......@@ -1687,7 +1689,7 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchNoArgument(
Callable callable =
CodeFactory::ArrayNoArgumentConstructor(isolate(), kind, mode);
TailCallArrayConstructorStub(callable, context, target, allocation_site,
TailCallArrayConstructorStub(callable, context, target, *allocation_site,
argc);
BIND(&next);
......@@ -1700,7 +1702,8 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchNoArgument(
void ArrayBuiltinsAssembler::CreateArrayDispatchSingleArgument(
TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode, TNode<AllocationSite> allocation_site) {
AllocationSiteOverrideMode mode,
base::Optional<TNode<AllocationSite>> allocation_site) {
if (mode == DISABLE_ALLOCATION_SITES) {
ElementsKind initial = GetInitialFastElementsKind();
ElementsKind holey_initial = GetHoleyElementsKind(initial);
......@@ -1711,7 +1714,8 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchSingleArgument(
argc);
} else {
DCHECK_EQ(mode, DONT_OVERRIDE);
TNode<Smi> transition_info = LoadTransitionInfo(allocation_site);
DCHECK(allocation_site);
TNode<Smi> transition_info = LoadTransitionInfo(*allocation_site);
// Least significant bit in fast array elements kind means holeyness.
STATIC_ASSERT(PACKED_SMI_ELEMENTS == 0);
......@@ -1734,7 +1738,7 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchSingleArgument(
// Make elements kind holey and update elements kind in the type info.
var_elements_kind = Word32Or(var_elements_kind.value(), Int32Constant(1));
StoreObjectFieldNoWriteBarrier(
allocation_site, AllocationSite::kTransitionInfoOrBoilerplateOffset,
*allocation_site, AllocationSite::kTransitionInfoOrBoilerplateOffset,
SmiOr(transition_info, SmiConstant(fast_elements_kind_holey_mask)));
Goto(&normal_sequence);
}
......@@ -1755,7 +1759,7 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchSingleArgument(
Callable callable =
CodeFactory::ArraySingleArgumentConstructor(isolate(), kind, mode);
TailCallArrayConstructorStub(callable, context, target, allocation_site,
TailCallArrayConstructorStub(callable, context, target, *allocation_site,
argc);
BIND(&next);
......@@ -1768,7 +1772,8 @@ void ArrayBuiltinsAssembler::CreateArrayDispatchSingleArgument(
void ArrayBuiltinsAssembler::GenerateDispatchToArrayStub(
TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode, TNode<AllocationSite> allocation_site) {
AllocationSiteOverrideMode mode,
base::Optional<TNode<AllocationSite>> allocation_site) {
Label check_one_case(this), fallthrough(this);
GotoIfNot(Word32Equal(argc, Int32Constant(0)), &check_one_case);
CreateArrayDispatchNoArgument(context, target, argc, mode, allocation_site);
......@@ -1861,8 +1866,9 @@ void ArrayBuiltinsAssembler::GenerateConstructor(
{
TNode<JSArray> array = AllocateJSArray(
elements_kind, array_map, array_size_smi, array_size_smi,
mode == DONT_TRACK_ALLOCATION_SITE ? TNode<AllocationSite>()
: CAST(allocation_site));
mode == DONT_TRACK_ALLOCATION_SITE
? base::Optional<TNode<AllocationSite>>(base::nullopt)
: CAST(allocation_site));
Return(array);
}
}
......@@ -1881,9 +1887,10 @@ void ArrayBuiltinsAssembler::GenerateArrayNoArgumentConstructor(
Parameter(Descriptor::kFunction), JSFunction::kContextOffset));
bool track_allocation_site =
AllocationSite::ShouldTrack(kind) && mode != DISABLE_ALLOCATION_SITES;
TNode<AllocationSite> allocation_site =
track_allocation_site ? CAST(Parameter(Descriptor::kAllocationSite))
: TNode<AllocationSite>();
base::Optional<TNode<AllocationSite>> allocation_site =
track_allocation_site
? CAST(Parameter(Descriptor::kAllocationSite))
: base::Optional<TNode<AllocationSite>>(base::nullopt);
TNode<Map> array_map = LoadJSArrayElementsMap(kind, native_context);
TNode<JSArray> array = AllocateJSArray(
kind, array_map, IntPtrConstant(JSArray::kPreallocatedArrayElements),
......
......@@ -72,20 +72,20 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
TNode<JSFunction> target, TNode<HeapObject> allocation_site_or_undefined,
TNode<Int32T> argc);
void GenerateDispatchToArrayStub(TNode<Context> context,
TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode,
TNode<AllocationSite> allocation_site = {});
void GenerateDispatchToArrayStub(
TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode,
base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt);
void CreateArrayDispatchNoArgument(
TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode,
TNode<AllocationSite> allocation_site = {});
base::Optional<TNode<AllocationSite>> allocation_site);
void CreateArrayDispatchSingleArgument(
TNode<Context> context, TNode<JSFunction> target, TNode<Int32T> argc,
AllocationSiteOverrideMode mode,
TNode<AllocationSite> allocation_site = {});
base::Optional<TNode<AllocationSite>> allocation_site);
void GenerateConstructor(TNode<Context> context,
TNode<HeapObject> array_function,
......
......@@ -314,7 +314,8 @@ TNode<JSArray> ObjectEntriesValuesBuiltinsAssembler::FastGetOwnValuesOrEntries(
TNode<JSArray> array;
TNode<FixedArrayBase> elements;
std::tie(array, elements) = AllocateUninitializedJSArrayWithElements(
PACKED_ELEMENTS, array_map, SmiConstant(2), {}, IntPtrConstant(2));
PACKED_ELEMENTS, array_map, SmiConstant(2), base::nullopt,
IntPtrConstant(2));
StoreFixedArrayElement(CAST(elements), 0, next_key, SKIP_WRITE_BARRIER);
StoreFixedArrayElement(CAST(elements), 1, value, SKIP_WRITE_BARRIER);
value = TNode<JSArray>::UncheckedCast(array);
......@@ -499,7 +500,7 @@ TF_BUILTIN(ObjectKeys, ObjectBuiltinsAssembler) {
LoadJSArrayElementsMap(PACKED_ELEMENTS, native_context);
TNode<Smi> array_length = SmiTag(Signed(object_enum_length));
std::tie(array, elements) = AllocateUninitializedJSArrayWithElements(
PACKED_ELEMENTS, array_map, array_length, {},
PACKED_ELEMENTS, array_map, array_length, base::nullopt,
Signed(object_enum_length));
CopyFixedArrayElements(PACKED_ELEMENTS, object_enum_keys, elements,
object_enum_length, SKIP_WRITE_BARRIER);
......@@ -595,7 +596,7 @@ TF_BUILTIN(ObjectGetOwnPropertyNames, ObjectBuiltinsAssembler) {
TNode<JSArray> array;
TNode<FixedArrayBase> elements;
std::tie(array, elements) = AllocateUninitializedJSArrayWithElements(
PACKED_ELEMENTS, array_map, array_length, {},
PACKED_ELEMENTS, array_map, array_length, base::nullopt,
Signed(object_enum_length));
CopyFixedArrayElements(PACKED_ELEMENTS, object_enum_keys, elements,
object_enum_length, SKIP_WRITE_BARRIER);
......
......@@ -89,7 +89,7 @@ TNode<JSRegExpResult> RegExpBuiltinsAssembler::AllocateRegExpResult(
const ElementsKind elements_kind = PACKED_ELEMENTS;
TNode<Map> map = CAST(LoadContextElement(LoadNativeContext(context),
Context::REGEXP_RESULT_MAP_INDEX));
TNode<AllocationSite> no_allocation_site = {};
base::Optional<TNode<AllocationSite>> no_allocation_site = base::nullopt;
TNode<IntPtrT> length_intptr = SmiUntag(length);
// Note: The returned `elements` may be in young large object space, but
......@@ -1356,7 +1356,6 @@ TNode<JSArray> RegExpBuiltinsAssembler::RegExpPrototypeSplitBody(
const ElementsKind kind = PACKED_ELEMENTS;
const ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS;
TNode<AllocationSite> allocation_site = {};
const TNode<NativeContext> native_context = LoadNativeContext(context);
TNode<Map> array_map = LoadJSArrayElementsMap(kind, native_context);
......@@ -1396,6 +1395,7 @@ TNode<JSArray> RegExpBuiltinsAssembler::RegExpPrototypeSplitBody(
{
TNode<Smi> length = SmiConstant(1);
TNode<IntPtrT> capacity = IntPtrConstant(1);
base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt;
var_result =
AllocateJSArray(kind, array_map, capacity, length, allocation_site);
......@@ -1570,6 +1570,7 @@ TNode<JSArray> RegExpBuiltinsAssembler::RegExpPrototypeSplitBody(
{
TNode<Smi> length = SmiZero();
TNode<IntPtrT> capacity = IntPtrZero();
base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt;
var_result =
AllocateJSArray(kind, array_map, capacity, length, allocation_site);
Goto(&done);
......
......@@ -3552,12 +3552,13 @@ TNode<BoolT> CodeStubAssembler::IsValidFastJSArrayCapacity(
TNode<JSArray> CodeStubAssembler::AllocateJSArray(
TNode<Map> array_map, TNode<FixedArrayBase> elements, TNode<Smi> length,
TNode<AllocationSite> allocation_site, int array_header_size) {
base::Optional<TNode<AllocationSite>> allocation_site,
int array_header_size) {
Comment("begin allocation of JSArray passing in elements");
CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length));
int base_size = array_header_size;
if (!allocation_site.is_null()) {
if (allocation_site) {
base_size += AllocationMemento::kSize;
}
......@@ -3571,8 +3572,9 @@ TNode<JSArray> CodeStubAssembler::AllocateJSArray(
std::pair<TNode<JSArray>, TNode<FixedArrayBase>>
CodeStubAssembler::AllocateUninitializedJSArrayWithElements(
ElementsKind kind, TNode<Map> array_map, TNode<Smi> length,
TNode<AllocationSite> allocation_site, TNode<IntPtrT> capacity,
AllocationFlags allocation_flags, int array_header_size) {
base::Optional<TNode<AllocationSite>> allocation_site,
TNode<IntPtrT> capacity, AllocationFlags allocation_flags,
int array_header_size) {
Comment("begin allocation of JSArray with elements");
CHECK_EQ(allocation_flags & ~kAllowLargeObjectAllocation, 0);
CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length));
......@@ -3608,7 +3610,7 @@ CodeStubAssembler::AllocateUninitializedJSArrayWithElements(
BIND(&nonempty);
{
int base_size = array_header_size;
if (!allocation_site.is_null()) {
if (allocation_site) {
base_size += AllocationMemento::kSize;
}
......@@ -3680,7 +3682,8 @@ CodeStubAssembler::AllocateUninitializedJSArrayWithElements(
TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArray(
TNode<Map> array_map, TNode<Smi> length,
TNode<AllocationSite> allocation_site, TNode<IntPtrT> size_in_bytes) {
base::Optional<TNode<AllocationSite>> allocation_site,
TNode<IntPtrT> size_in_bytes) {
CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length));
// Allocate space for the JSArray and the elements FixedArray in one go.
......@@ -3691,9 +3694,9 @@ TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArray(
StoreObjectFieldRoot(array, JSArray::kPropertiesOrHashOffset,
RootIndex::kEmptyFixedArray);
if (!allocation_site.is_null()) {
if (allocation_site) {
InitializeAllocationMemento(array, IntPtrConstant(JSArray::kHeaderSize),
allocation_site);
*allocation_site);
}
return CAST(array);
......@@ -3701,7 +3704,7 @@ TNode<JSArray> CodeStubAssembler::AllocateUninitializedJSArray(
TNode<JSArray> CodeStubAssembler::AllocateJSArray(
ElementsKind kind, TNode<Map> array_map, TNode<IntPtrT> capacity,
TNode<Smi> length, TNode<AllocationSite> allocation_site,
TNode<Smi> length, base::Optional<TNode<AllocationSite>> allocation_site,
AllocationFlags allocation_flags) {
CSA_SLOW_ASSERT(this, TaggedIsPositiveSmi(length));
......@@ -3743,14 +3746,15 @@ TNode<JSArray> CodeStubAssembler::ExtractFastJSArray(TNode<Context> context,
LoadElements(array), begin, count, base::nullopt,
ExtractFixedArrayFlag::kAllFixedArrays, nullptr, elements_kind);
TNode<JSArray> result =
AllocateJSArray(array_map, new_elements, ParameterToTagged(count), {});
TNode<JSArray> result = AllocateJSArray(
array_map, new_elements, ParameterToTagged(count), base::nullopt);
return result;
}
TNode<JSArray> CodeStubAssembler::CloneFastJSArray(
TNode<Context> context, TNode<JSArray> array,
TNode<AllocationSite> allocation_site, HoleConversionMode convert_holes) {
base::Optional<TNode<AllocationSite>> allocation_site,
HoleConversionMode convert_holes) {
// TODO(dhai): we should be able to assert IsFastJSArray(array) here, but this
// function is also used to copy boilerplates even when the no-elements
// protector is invalid. This function should be renamed to reflect its uses.
......
......@@ -1968,41 +1968,40 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
std::pair<TNode<JSArray>, TNode<FixedArrayBase>>
AllocateUninitializedJSArrayWithElements(
ElementsKind kind, TNode<Map> array_map, TNode<Smi> length,
TNode<AllocationSite> allocation_site, TNode<IntPtrT> capacity,
AllocationFlags allocation_flags = kNone,
base::Optional<TNode<AllocationSite>> allocation_site,
TNode<IntPtrT> capacity, AllocationFlags allocation_flags = kNone,
int array_header_size = JSArray::kHeaderSize);
// Allocate a JSArray and fill elements with the hole.
TNode<JSArray> AllocateJSArray(ElementsKind kind, TNode<Map> array_map,
TNode<IntPtrT> capacity, TNode<Smi> length,
TNode<AllocationSite> allocation_site,
AllocationFlags allocation_flags = kNone);
TNode<JSArray> AllocateJSArray(ElementsKind kind, TNode<Map> array_map,
TNode<Smi> capacity, TNode<Smi> length,
TNode<AllocationSite> allocation_site,
AllocationFlags allocation_flags = kNone) {
TNode<JSArray> AllocateJSArray(
ElementsKind kind, TNode<Map> array_map, TNode<IntPtrT> capacity,
TNode<Smi> length, base::Optional<TNode<AllocationSite>> allocation_site,
AllocationFlags allocation_flags = kNone);
TNode<JSArray> AllocateJSArray(
ElementsKind kind, TNode<Map> array_map, TNode<Smi> capacity,
TNode<Smi> length, base::Optional<TNode<AllocationSite>> allocation_site,
AllocationFlags allocation_flags = kNone) {
return AllocateJSArray(kind, array_map, SmiUntag(capacity), length,
allocation_site, allocation_flags);
}
TNode<JSArray> AllocateJSArray(ElementsKind kind, TNode<Map> array_map,
TNode<Smi> capacity, TNode<Smi> length,
AllocationFlags allocation_flags = kNone) {
return AllocateJSArray(kind, array_map, SmiUntag(capacity), length, {},
allocation_flags);
return AllocateJSArray(kind, array_map, SmiUntag(capacity), length,
base::nullopt, allocation_flags);
}
TNode<JSArray> AllocateJSArray(ElementsKind kind, TNode<Map> array_map,
TNode<IntPtrT> capacity, TNode<Smi> length,
AllocationFlags allocation_flags = kNone) {
return AllocateJSArray(kind, array_map, capacity, length, {},
return AllocateJSArray(kind, array_map, capacity, length, base::nullopt,
allocation_flags);
}
// Allocate a JSArray and initialize the header fields.
TNode<JSArray> AllocateJSArray(TNode<Map> array_map,
TNode<FixedArrayBase> elements,
TNode<Smi> length,
TNode<AllocationSite> allocation_site = {},
int array_header_size = JSArray::kHeaderSize);
TNode<JSArray> AllocateJSArray(
TNode<Map> array_map, TNode<FixedArrayBase> elements, TNode<Smi> length,
base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt,
int array_header_size = JSArray::kHeaderSize);
enum class HoleConversionMode { kDontConvert, kConvertToUndefined };
// Clone a fast JSArray |array| into a new fast JSArray.
......@@ -2017,7 +2016,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// function generates significantly less code in this case.
TNode<JSArray> CloneFastJSArray(
TNode<Context> context, TNode<JSArray> array,
TNode<AllocationSite> allocation_site = {},
base::Optional<TNode<AllocationSite>> allocation_site = base::nullopt,
HoleConversionMode convert_holes = HoleConversionMode::kDontConvert);
TNode<JSArray> ExtractFastJSArray(TNode<Context> context,
......@@ -3955,7 +3954,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// fields initialized.
TNode<JSArray> AllocateUninitializedJSArray(
TNode<Map> array_map, TNode<Smi> length,
TNode<AllocationSite> allocation_site, TNode<IntPtrT> size_in_bytes);
base::Optional<TNode<AllocationSite>> allocation_site,
TNode<IntPtrT> size_in_bytes);
TNode<BoolT> IsValidSmi(TNode<Smi> smi);
......
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