diff --git a/src/codegen/code-stub-assembler.cc b/src/codegen/code-stub-assembler.cc index 0fb5c2aa58..b6b8bba721 100644 --- a/src/codegen/code-stub-assembler.cc +++ b/src/codegen/code-stub-assembler.cc @@ -9610,14 +9610,19 @@ MachineRepresentation ElementsKindToMachineRepresentation(ElementsKind kind) { } // namespace -template -void CodeStubAssembler::StoreElement(Node* elements, ElementsKind kind, - TNode index, Node* value) { +template +void CodeStubAssembler::StoreElementBigIntOrTypedArray(TNode elements, + ElementsKind kind, + TNode index, + Node* value) { // TODO(v8:9708): Do we want to keep both IntPtrT and UintPtrT variants? static_assert(std::is_same::value || std::is_same::value || std::is_same::value, "Only Smi, UintPtrT or IntPtrT index is allowed"); + static_assert(std::is_same::value || + std::is_same::value, + "Only RawPtrT or FixedArrayBase elements are allowed"); if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS) { TNode 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(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 +void CodeStubAssembler::StoreElement(TNode elements, + ElementsKind kind, TNode index, + Node* value) { + if (kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS || + IsTypedArrayElementsKind(kind)) { + StoreElementBigIntOrTypedArray(elements, kind, index, value); } else if (IsDoubleElementsKind(kind)) { TNode value_float64 = UncheckedCast(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( - Node*, ElementsKind, TNode, Node*); - -template V8_EXPORT_PRIVATE void CodeStubAssembler::StoreElement( - Node*, ElementsKind, TNode, Node*); - +template +void CodeStubAssembler::StoreElement(TNode elements, ElementsKind kind, + TNode index, Node* value) { + DCHECK(kind == BIGINT64_ELEMENTS || kind == BIGUINT64_ELEMENTS || + IsTypedArrayElementsKind(kind)); + StoreElementBigIntOrTypedArray(elements, kind, index, value); +} template V8_EXPORT_PRIVATE void CodeStubAssembler::StoreElement( - Node*, ElementsKind, TNode, Node*); + TNode, ElementsKind, TNode, Node*); TNode CodeStubAssembler::Int32ToUint8Clamped( TNode int32_value) { diff --git a/src/codegen/code-stub-assembler.h b/src/codegen/code-stub-assembler.h index f92fbd9dd7..7d2d2f7852 100644 --- a/src/codegen/code-stub-assembler.h +++ b/src/codegen/code-stub-assembler.h @@ -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 - void StoreElement(Node* elements, ElementsKind kind, TNode index, - Node* value); + void StoreElement(TNode elements, ElementsKind kind, + TNode 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 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 + void StoreElementBigIntOrTypedArray(TNode elements, ElementsKind kind, + TNode index, Node* value); + + template + void StoreElement(TNode elements, ElementsKind kind, + TNode 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}.