Commit a786179c authored by Santiago Aboy Solanes's avatar Santiago Aboy Solanes Committed by Commit Bot

[csa][cleanup] Simplify StoreFixedArrayElement

We can remove some of the method definitions, as well as the
sloppy-ness from the method.

Bug: v8:6949, v8:11384
Change-Id: I04880daa3fcce097b79009f12bd24128a47c2c80
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2690591Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarMythri Alle <mythria@chromium.org>
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72867}
parent d112b6d6
...@@ -32,7 +32,7 @@ macro StoreElement<ElementsAccessor : type extends ElementsKind, T: type>( ...@@ -32,7 +32,7 @@ macro StoreElement<ElementsAccessor : type extends ElementsKind, T: type>(
StoreElement<array::FastPackedSmiElements, Smi>(implicit context: Context)( StoreElement<array::FastPackedSmiElements, Smi>(implicit context: Context)(
elements: FixedArrayBase, index: Smi, value: Smi) { elements: FixedArrayBase, index: Smi, value: Smi) {
const elems: FixedArray = UnsafeCast<FixedArray>(elements); const elems: FixedArray = UnsafeCast<FixedArray>(elements);
StoreFixedArrayElement(elems, index, value, SKIP_WRITE_BARRIER); StoreFixedArrayElement(elems, index, value);
} }
StoreElement<array::FastPackedObjectElements, JSAny>(implicit context: Context)( StoreElement<array::FastPackedObjectElements, JSAny>(implicit context: Context)(
......
...@@ -1555,37 +1555,43 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -1555,37 +1555,43 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
void StoreMapNoWriteBarrier(TNode<HeapObject> object, TNode<Map> map); void StoreMapNoWriteBarrier(TNode<HeapObject> object, TNode<Map> map);
void StoreObjectFieldRoot(TNode<HeapObject> object, int offset, void StoreObjectFieldRoot(TNode<HeapObject> object, int offset,
RootIndex root); RootIndex root);
// Store an array element to a FixedArray. // Store an array element to a FixedArray.
void StoreFixedArrayElement( void StoreFixedArrayElement(
TNode<FixedArray> object, int index, SloppyTNode<Object> value, TNode<FixedArray> object, int index, TNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER, WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
CheckBounds check_bounds = CheckBounds::kAlways) { CheckBounds check_bounds = CheckBounds::kAlways) {
return StoreFixedArrayElement(object, IntPtrConstant(index), value, return StoreFixedArrayElement(object, IntPtrConstant(index), value,
barrier_mode, 0, check_bounds); barrier_mode, 0, check_bounds);
} }
// This doesn't emit a bounds-check. As part of the security-performance // This doesn't emit a bounds-check. As part of the security-performance
// tradeoff, only use it if it is performance critical. // tradeoff, only use it if it is performance critical.
void UnsafeStoreFixedArrayElement( void UnsafeStoreFixedArrayElement(
TNode<FixedArray> object, int index, TNode<Object> value, TNode<FixedArray> object, int index, TNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER) { WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER) {
return StoreFixedArrayElement(object, index, value, barrier_mode, return StoreFixedArrayElement(object, IntPtrConstant(index), value,
CheckBounds::kDebugOnly); barrier_mode, 0, CheckBounds::kDebugOnly);
} }
void UnsafeStoreFixedArrayElement(TNode<FixedArray> object, int index, void UnsafeStoreFixedArrayElement(TNode<FixedArray> object, int index,
TNode<Smi> value) { TNode<Smi> value) {
return StoreFixedArrayElement(object, index, value, return StoreFixedArrayElement(object, IntPtrConstant(index), value,
UNSAFE_SKIP_WRITE_BARRIER, UNSAFE_SKIP_WRITE_BARRIER, 0,
CheckBounds::kDebugOnly); CheckBounds::kDebugOnly);
} }
void StoreFixedArrayElement(TNode<FixedArray> object, int index, void StoreFixedArrayElement(TNode<FixedArray> object, int index,
TNode<Smi> value, TNode<Smi> value,
CheckBounds check_bounds = CheckBounds::kAlways) { CheckBounds check_bounds = CheckBounds::kAlways) {
return StoreFixedArrayElement(object, IntPtrConstant(index), value, return StoreFixedArrayElement(object, IntPtrConstant(index),
TNode<Object>{value},
UNSAFE_SKIP_WRITE_BARRIER, 0, check_bounds); UNSAFE_SKIP_WRITE_BARRIER, 0, check_bounds);
} }
template <typename TIndex> template <typename TIndex>
void StoreFixedArrayElement( void StoreFixedArrayElement(
TNode<FixedArray> array, TNode<TIndex> index, SloppyTNode<Object> value, TNode<FixedArray> array, TNode<TIndex> index, TNode<Object> value,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER, WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
int additional_offset = 0, int additional_offset = 0,
CheckBounds check_bounds = CheckBounds::kAlways) { CheckBounds check_bounds = CheckBounds::kAlways) {
...@@ -1600,6 +1606,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -1600,6 +1606,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
StoreFixedArrayOrPropertyArrayElement(array, index, value, barrier_mode, StoreFixedArrayOrPropertyArrayElement(array, index, value, barrier_mode,
additional_offset); additional_offset);
} }
// This doesn't emit a bounds-check. As part of the security-performance // This doesn't emit a bounds-check. As part of the security-performance
// tradeoff, only use it if it is performance critical. // tradeoff, only use it if it is performance critical.
void UnsafeStoreFixedArrayElement( void UnsafeStoreFixedArrayElement(
...@@ -1624,24 +1631,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -1624,24 +1631,12 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
UPDATE_WRITE_BARRIER); UPDATE_WRITE_BARRIER);
} }
void StoreFixedArrayElement( template <typename TIndex>
TNode<FixedArray> array, TNode<Smi> index, TNode<Object> value, void StoreFixedArrayElement(TNode<FixedArray> array, TNode<TIndex> index,
WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER) { TNode<Smi> value, int additional_offset = 0) {
StoreFixedArrayElement(array, index, value, barrier_mode, 0); static_assert(std::is_same<TIndex, Smi>::value ||
} std::is_same<TIndex, IntPtrT>::value,
void StoreFixedArrayElement( "Only Smi or IntPtrT indeces is allowed");
TNode<FixedArray> array, TNode<IntPtrT> index, TNode<Smi> value,
WriteBarrierMode barrier_mode = SKIP_WRITE_BARRIER,
int additional_offset = 0) {
DCHECK_EQ(SKIP_WRITE_BARRIER, barrier_mode);
StoreFixedArrayElement(array, index, TNode<Object>{value},
UNSAFE_SKIP_WRITE_BARRIER, additional_offset);
}
void StoreFixedArrayElement(
TNode<FixedArray> array, TNode<Smi> index, TNode<Smi> value,
WriteBarrierMode barrier_mode = SKIP_WRITE_BARRIER,
int additional_offset = 0) {
DCHECK_EQ(SKIP_WRITE_BARRIER, barrier_mode);
StoreFixedArrayElement(array, index, TNode<Object>{value}, StoreFixedArrayElement(array, index, TNode<Object>{value},
UNSAFE_SKIP_WRITE_BARRIER, additional_offset); UNSAFE_SKIP_WRITE_BARRIER, additional_offset);
} }
...@@ -2862,8 +2857,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler ...@@ -2862,8 +2857,7 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
const int kKeyToDetailsOffset = const int kKeyToDetailsOffset =
(ContainerType::kEntryDetailsIndex - ContainerType::kEntryKeyIndex) * (ContainerType::kEntryDetailsIndex - ContainerType::kEntryKeyIndex) *
kTaggedSize; kTaggedSize;
StoreFixedArrayElement(container, key_index, details, SKIP_WRITE_BARRIER, StoreFixedArrayElement(container, key_index, details, kKeyToDetailsOffset);
kKeyToDetailsOffset);
} }
// Stores the value for the entry with the given key_index. // Stores the value for the entry with the given key_index.
......
...@@ -211,7 +211,7 @@ Handle<Code> BuildTeardownFunction(Isolate* isolate, ...@@ -211,7 +211,7 @@ Handle<Code> BuildTeardownFunction(Isolate* isolate,
Node* param = __ UntypedParameter(i + 2); Node* param = __ UntypedParameter(i + 2);
switch (parameters[i].representation()) { switch (parameters[i].representation()) {
case MachineRepresentation::kTagged: case MachineRepresentation::kTagged:
__ StoreFixedArrayElement(result_array, i, param, __ StoreFixedArrayElement(result_array, i, __ Cast(param),
UNSAFE_SKIP_WRITE_BARRIER); UNSAFE_SKIP_WRITE_BARRIER);
break; break;
// Box FP values into HeapNumbers. // Box FP values into HeapNumbers.
......
...@@ -2748,7 +2748,8 @@ TEST(CreatePromiseResolvingFunctions) { ...@@ -2748,7 +2748,8 @@ TEST(CreatePromiseResolvingFunctions) {
m.NewJSPromise(context, m.UndefinedConstant()); m.NewJSPromise(context, m.UndefinedConstant());
PromiseResolvingFunctions funcs = m.CreatePromiseResolvingFunctions( PromiseResolvingFunctions funcs = m.CreatePromiseResolvingFunctions(
context, promise, m.BooleanConstant(false), native_context); context, promise, m.BooleanConstant(false), native_context);
Node *resolve = funcs.resolve, *reject = funcs.reject; TNode<JSFunction> resolve = funcs.resolve;
TNode<JSFunction> reject = funcs.reject;
TNode<IntPtrT> const kSize = m.IntPtrConstant(2); TNode<IntPtrT> const kSize = m.IntPtrConstant(2);
TNode<FixedArray> const arr = TNode<FixedArray> const arr =
m.Cast(m.AllocateFixedArray(PACKED_ELEMENTS, kSize)); m.Cast(m.AllocateFixedArray(PACKED_ELEMENTS, kSize));
......
...@@ -276,7 +276,7 @@ Store<FastSmiElements>( ...@@ -276,7 +276,7 @@ Store<FastSmiElements>(
const object = UnsafeCast<JSObject>(sortState.receiver); const object = UnsafeCast<JSObject>(sortState.receiver);
const elements = UnsafeCast<FixedArray>(object.elements); const elements = UnsafeCast<FixedArray>(object.elements);
const value = UnsafeCast<Smi>(value); const value = UnsafeCast<Smi>(value);
StoreFixedArrayElement(elements, index, value, SKIP_WRITE_BARRIER); StoreFixedArrayElement(elements, index, value);
return kSuccess; return kSuccess;
} }
......
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