[csa][cleanup] TNodify StoreElement's array parameter

Create two versions of StoreElement: One for RawPtrT and the other one
for FixedArrayBase. They have some common code, but the FixedArrayBase
one has more cases that it allows. This can be simplified if/when we
have access to "if constexpr".

Bug: v8:6949, v8:11074
Change-Id: Ifa12fb0688f41c77fa7ec26749c5f725169faace
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2521149
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: Dan Elphick <delphick@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71007}
This commit is contained in:
Santiago Aboy Solanes 2020-11-06 11:08:33 +00:00 committed by Commit Bot
parent 26b0eb6746
commit e6f18daf46
2 changed files with 44 additions and 14 deletions

View File

@ -9610,14 +9610,19 @@ MachineRepresentation ElementsKindToMachineRepresentation(ElementsKind kind) {
} // namespace
template <typename TIndex>
void CodeStubAssembler::StoreElement(Node* elements, ElementsKind kind,
TNode<TIndex> index, Node* value) {
template <typename TArray, typename TIndex>
void CodeStubAssembler::StoreElementBigIntOrTypedArray(TNode<TArray> elements,
ElementsKind kind,
TNode<TIndex> index,
Node* value) {
// TODO(v8:9708): Do we want to keep both IntPtrT and UintPtrT variants?
static_assert(std::is_same<TIndex, Smi>::value ||
std::is_same<TIndex, UintPtrT>::value ||
std::is_same<TIndex, IntPtrT>::value,
"Only Smi, UintPtrT or IntPtrT index is allowed");
static_assert(std::is_same<TArray, RawPtrT>::value ||
std::is_same<TArray, FixedArrayBase>::value,
"Only RawPtrT or FixedArrayBase elements are allowed");
if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS) {
TNode<IntPtrT> offset = ElementOffsetFromIndex(index, kind, 0);
TVARIABLE(UintPtrT, var_low);
@ -9643,7 +9648,8 @@ void CodeStubAssembler::StoreElement(Node* elements, ElementsKind kind,
var_high.value());
}
#endif
} else if (IsTypedArrayElementsKind(kind)) {
} else {
DCHECK(IsTypedArrayElementsKind(kind));
if (kind == UINT8_CLAMPED_ELEMENTS) {
CSA_ASSERT(this, Word32Equal(UncheckedCast<Word32T>(value),
Word32And(Int32Constant(0xFF), value)));
@ -9652,7 +9658,16 @@ void CodeStubAssembler::StoreElement(Node* elements, ElementsKind kind,
// TODO(cbruni): Add OOB check once typed.
MachineRepresentation rep = ElementsKindToMachineRepresentation(kind);
StoreNoWriteBarrier(rep, elements, offset, value);
return;
}
}
template <typename TIndex>
void CodeStubAssembler::StoreElement(TNode<FixedArrayBase> elements,
ElementsKind kind, TNode<TIndex> index,
Node* value) {
if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS ||
IsTypedArrayElementsKind(kind)) {
StoreElementBigIntOrTypedArray(elements, kind, index, value);
} else if (IsDoubleElementsKind(kind)) {
TNode<Float64T> value_float64 = UncheckedCast<Float64T>(value);
StoreFixedDoubleArrayElement(CAST(elements), index, value_float64);
@ -9664,14 +9679,15 @@ void CodeStubAssembler::StoreElement(Node* elements, ElementsKind kind,
}
}
template V8_EXPORT_PRIVATE void CodeStubAssembler::StoreElement<Smi>(
Node*, ElementsKind, TNode<Smi>, Node*);
template V8_EXPORT_PRIVATE void CodeStubAssembler::StoreElement<IntPtrT>(
Node*, ElementsKind, TNode<IntPtrT>, Node*);
template <typename TIndex>
void CodeStubAssembler::StoreElement(TNode<RawPtrT> elements, ElementsKind kind,
TNode<TIndex> index, Node* value) {
DCHECK(kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS ||
IsTypedArrayElementsKind(kind));
StoreElementBigIntOrTypedArray(elements, kind, index, value);
}
template V8_EXPORT_PRIVATE void CodeStubAssembler::StoreElement<UintPtrT>(
Node*, ElementsKind, TNode<UintPtrT>, Node*);
TNode<RawPtrT>, ElementsKind, TNode<UintPtrT>, Node*);
TNode<Uint8T> CodeStubAssembler::Int32ToUint8Clamped(
TNode<Int32T> int32_value) {

View File

@ -3169,8 +3169,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// we pass {value} as BigInt object instead of int64_t. We should
// teach TurboFan to handle int64_t on 32-bit platforms eventually.
template <typename TIndex>
void StoreElement(Node* elements, ElementsKind kind, TNode<TIndex> index,
Node* value);
void StoreElement(TNode<RawPtrT> elements, ElementsKind kind,
TNode<TIndex> index, Node* value);
// Implements the BigInt part of
// https://tc39.github.io/proposal-bigint/#sec-numbertorawbytes,
@ -3743,6 +3743,20 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<Object> value, WriteBarrierMode barrier_mode = UPDATE_WRITE_BARRIER,
int additional_offset = 0);
// Store value to an elements array with given elements kind.
// TODO(turbofan): For BIGINT64_ELEMENTS and BIGUINT64_ELEMENTS
// we pass {value} as BigInt object instead of int64_t. We should
// teach TurboFan to handle int64_t on 32-bit platforms eventually.
// TODO(solanes): This method can go away and simplify into only one version
// of StoreElement once we have "if constexpr" available to use.
template <typename TArray, typename TIndex>
void StoreElementBigIntOrTypedArray(TNode<TArray> elements, ElementsKind kind,
TNode<TIndex> index, Node* value);
template <typename TIndex>
void StoreElement(TNode<FixedArrayBase> elements, ElementsKind kind,
TNode<TIndex> index, Node* value);
// Converts {input} to a number if {input} is a plain primitve (i.e. String or
// Oddball) and stores the result in {var_result}. Otherwise, it bails out to
// {if_bailout}.