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

[csa][cleanup] Partly TNodify SharedArrayBuffer's AssemblerFunction

As a drive-by, rename "sanity check" to "check" in sharedarraybuffer.

Bug: v8:6949, v8:10933
Change-Id: Ifa2eac381ed309a099b018de4033816ebe3d828d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2429410
Commit-Queue: Santiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70307}
parent c7c8472d
...@@ -19,10 +19,10 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { ...@@ -19,10 +19,10 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler {
: CodeStubAssembler(state) {} : CodeStubAssembler(state) {}
protected: protected:
using AssemblerFunction = Node* (CodeAssembler::*)(MachineType type, using AssemblerFunction =
Node* base, Node* offset, Node* (CodeAssembler::*)(MachineType type, TNode<RawPtrT> base,
Node* value, TNode<UintPtrT> offset, Node* value,
Node* value_high); base::Optional<TNode<UintPtrT>> value_high);
TNode<JSArrayBuffer> ValidateIntegerTypedArray( TNode<JSArrayBuffer> ValidateIntegerTypedArray(
TNode<Object> maybe_array, TNode<Context> context, TNode<Object> maybe_array, TNode<Context> context,
TNode<Int32T>* out_elements_kind, TNode<RawPtrT>* out_backing_store, TNode<Int32T>* out_elements_kind, TNode<RawPtrT>* out_backing_store,
...@@ -32,8 +32,8 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler { ...@@ -32,8 +32,8 @@ class SharedArrayBufferBuiltinsAssembler : public CodeStubAssembler {
TNode<Object> index, TNode<Object> index,
TNode<Context> context); TNode<Context> context);
inline void DebugSanityCheckAtomicIndex(TNode<JSTypedArray> array, inline void DebugCheckAtomicIndex(TNode<JSTypedArray> array,
TNode<UintPtrT> index); TNode<UintPtrT> index);
void AtomicBinopBuiltinCommon(TNode<Object> maybe_array, TNode<Object> index, void AtomicBinopBuiltinCommon(TNode<Object> maybe_array, TNode<Object> index,
TNode<Object> value, TNode<Context> context, TNode<Object> value, TNode<Context> context,
...@@ -127,7 +127,7 @@ TNode<UintPtrT> SharedArrayBufferBuiltinsAssembler::ValidateAtomicAccess( ...@@ -127,7 +127,7 @@ TNode<UintPtrT> SharedArrayBufferBuiltinsAssembler::ValidateAtomicAccess(
return index_uintptr; return index_uintptr;
} }
void SharedArrayBufferBuiltinsAssembler::DebugSanityCheckAtomicIndex( void SharedArrayBufferBuiltinsAssembler::DebugCheckAtomicIndex(
TNode<JSTypedArray> array, TNode<UintPtrT> index) { TNode<JSTypedArray> array, TNode<UintPtrT> index) {
// In Debug mode, we re-validate the index as a sanity check because ToInteger // In Debug mode, we re-validate the index as a sanity check because ToInteger
// above calls out to JavaScript. Atomics work on ArrayBuffers, which may be // above calls out to JavaScript. Atomics work on ArrayBuffers, which may be
...@@ -295,7 +295,7 @@ TF_BUILTIN(AtomicsStore, SharedArrayBufferBuiltinsAssembler) { ...@@ -295,7 +295,7 @@ TF_BUILTIN(AtomicsStore, SharedArrayBufferBuiltinsAssembler) {
TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer); TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
// Steps 8-13. // Steps 8-13.
// //
...@@ -336,7 +336,7 @@ TF_BUILTIN(AtomicsStore, SharedArrayBufferBuiltinsAssembler) { ...@@ -336,7 +336,7 @@ TF_BUILTIN(AtomicsStore, SharedArrayBufferBuiltinsAssembler) {
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_low); TVARIABLE(UintPtrT, var_low);
TVARIABLE(UintPtrT, var_high); TVARIABLE(UintPtrT, var_high);
...@@ -405,7 +405,7 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) { ...@@ -405,7 +405,7 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
// buffer to become detached. // buffer to become detached.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer); TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer);
...@@ -424,29 +424,31 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) { ...@@ -424,29 +424,31 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
BIND(&i8); BIND(&i8);
Return(SmiFromInt32(AtomicExchange(MachineType::Int8(), backing_store, Return(SmiFromInt32(AtomicExchange(MachineType::Int8(), backing_store,
index_word, value_word32))); index_word, value_word32, base::nullopt)));
BIND(&u8); BIND(&u8);
Return(SmiFromInt32(AtomicExchange(MachineType::Uint8(), backing_store, Return(SmiFromInt32(AtomicExchange(MachineType::Uint8(), backing_store,
index_word, value_word32))); index_word, value_word32, base::nullopt)));
BIND(&i16); BIND(&i16);
Return(SmiFromInt32(AtomicExchange(MachineType::Int16(), backing_store, Return(SmiFromInt32(AtomicExchange(MachineType::Int16(), backing_store,
WordShl(index_word, 1), value_word32))); WordShl(index_word, UintPtrConstant(1)),
value_word32, base::nullopt)));
BIND(&u16); BIND(&u16);
Return(SmiFromInt32(AtomicExchange(MachineType::Uint16(), backing_store, Return(SmiFromInt32(AtomicExchange(MachineType::Uint16(), backing_store,
WordShl(index_word, 1), value_word32))); WordShl(index_word, UintPtrConstant(1)),
value_word32, base::nullopt)));
BIND(&i32); BIND(&i32);
Return(ChangeInt32ToTagged(AtomicExchange(MachineType::Int32(), backing_store, Return(ChangeInt32ToTagged(AtomicExchange(
WordShl(index_word, 2), MachineType::Int32(), backing_store,
value_word32))); WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&u32); BIND(&u32);
Return(ChangeUint32ToTagged( Return(ChangeUint32ToTagged(AtomicExchange(
AtomicExchange(MachineType::Uint32(), backing_store, MachineType::Uint32(), backing_store,
WordShl(index_word, 2), value_word32))); WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&big); BIND(&big);
// 4. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value). // 4. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value).
...@@ -455,7 +457,7 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) { ...@@ -455,7 +457,7 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_low); TVARIABLE(UintPtrT, var_low);
TVARIABLE(UintPtrT, var_high); TVARIABLE(UintPtrT, var_high);
...@@ -469,14 +471,14 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) { ...@@ -469,14 +471,14 @@ TF_BUILTIN(AtomicsExchange, SharedArrayBufferBuiltinsAssembler) {
// This uses Uint64() intentionally: AtomicExchange is not implemented for // This uses Uint64() intentionally: AtomicExchange is not implemented for
// Int64(), which is fine because the machine instruction only cares // Int64(), which is fine because the machine instruction only cares
// about words. // about words.
Return(BigIntFromSigned64(AtomicExchange(MachineType::Uint64(), backing_store, Return(BigIntFromSigned64(AtomicExchange(
WordShl(index_word, 3), MachineType::Uint64(), backing_store,
var_low.value(), high))); WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
BIND(&u64); BIND(&u64);
Return(BigIntFromUnsigned64( Return(BigIntFromUnsigned64(AtomicExchange(
AtomicExchange(MachineType::Uint64(), backing_store, MachineType::Uint64(), backing_store,
WordShl(index_word, 3), var_low.value(), high))); WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
// This shouldn't happen, we've already validated the type. // This shouldn't happen, we've already validated the type.
BIND(&other); BIND(&other);
...@@ -540,7 +542,7 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) { ...@@ -540,7 +542,7 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) {
// buffer to become detached. // buffer to become detached.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TNode<Word32T> old_value_word32 = TNode<Word32T> old_value_word32 =
TruncateTaggedToWord32(context, old_value_integer); TruncateTaggedToWord32(context, old_value_integer);
...@@ -600,7 +602,7 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) { ...@@ -600,7 +602,7 @@ TF_BUILTIN(AtomicsCompareExchange, SharedArrayBufferBuiltinsAssembler) {
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_old_low); TVARIABLE(UintPtrT, var_old_low);
TVARIABLE(UintPtrT, var_old_high); TVARIABLE(UintPtrT, var_old_high);
...@@ -703,7 +705,7 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon( ...@@ -703,7 +705,7 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
// buffer to become detached. // buffer to become detached.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer); TNode<Word32T> value_word32 = TruncateTaggedToWord32(context, value_integer);
...@@ -721,33 +723,29 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon( ...@@ -721,33 +723,29 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
arraysize(case_labels)); arraysize(case_labels));
BIND(&i8); BIND(&i8);
Return(SmiFromInt32((this->*function)(MachineType::Int8(), backing_store, Return(
index_word, value_word32, nullptr))); SmiFromInt32((this->*function)(MachineType::Int8(), backing_store,
index_word, value_word32, base::nullopt)));
BIND(&u8); BIND(&u8);
Return(SmiFromInt32((this->*function)(MachineType::Uint8(), backing_store, Return(
index_word, value_word32, nullptr))); SmiFromInt32((this->*function)(MachineType::Uint8(), backing_store,
index_word, value_word32, base::nullopt)));
BIND(&i16); BIND(&i16);
Return(SmiFromInt32((this->*function)(MachineType::Int16(), backing_store, Return(SmiFromInt32((this->*function)(MachineType::Int16(), backing_store,
WordShl(index_word, 1), value_word32, WordShl(index_word, UintPtrConstant(1)),
nullptr))); value_word32, base::nullopt)));
BIND(&u16); BIND(&u16);
Return(SmiFromInt32((this->*function)(MachineType::Uint16(), backing_store, Return(SmiFromInt32((this->*function)(MachineType::Uint16(), backing_store,
WordShl(index_word, 1), value_word32, WordShl(index_word, UintPtrConstant(1)),
nullptr))); value_word32, base::nullopt)));
BIND(&i32); BIND(&i32);
Return(ChangeInt32ToTagged( Return(ChangeInt32ToTagged((this->*function)(
(this->*function)(MachineType::Int32(), backing_store, MachineType::Int32(), backing_store,
WordShl(index_word, 2), value_word32, nullptr))); WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&u32); BIND(&u32);
Return(ChangeUint32ToTagged( Return(ChangeUint32ToTagged((this->*function)(
(this->*function)(MachineType::Uint32(), backing_store, MachineType::Uint32(), backing_store,
WordShl(index_word, 2), value_word32, nullptr))); WordShl(index_word, UintPtrConstant(2)), value_word32, base::nullopt)));
BIND(&big); BIND(&big);
// 4. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value). // 4. If typedArray.[[ContentType]] is BigInt, let v be ? ToBigInt(value).
TNode<BigInt> value_bigint = ToBigInt(context, value); TNode<BigInt> value_bigint = ToBigInt(context, value);
...@@ -755,7 +753,7 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon( ...@@ -755,7 +753,7 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
GotoIf(IsDetachedBuffer(array_buffer), &detached); GotoIf(IsDetachedBuffer(array_buffer), &detached);
DebugSanityCheckAtomicIndex(array, index_word); DebugCheckAtomicIndex(array, index_word);
TVARIABLE(UintPtrT, var_low); TVARIABLE(UintPtrT, var_low);
TVARIABLE(UintPtrT, var_high); TVARIABLE(UintPtrT, var_high);
...@@ -769,15 +767,13 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon( ...@@ -769,15 +767,13 @@ void SharedArrayBufferBuiltinsAssembler::AtomicBinopBuiltinCommon(
// This uses Uint64() intentionally: Atomic* ops are not implemented for // This uses Uint64() intentionally: Atomic* ops are not implemented for
// Int64(), which is fine because the machine instructions only care // Int64(), which is fine because the machine instructions only care
// about words. // about words.
Return(BigIntFromSigned64( Return(BigIntFromSigned64((this->*function)(
(this->*function)(MachineType::Uint64(), backing_store, MachineType::Uint64(), backing_store,
WordShl(index_word, 3), var_low.value(), high))); WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
BIND(&u64); BIND(&u64);
Return(BigIntFromUnsigned64( Return(BigIntFromUnsigned64((this->*function)(
(this->*function)(MachineType::Uint64(), backing_store, MachineType::Uint64(), backing_store,
WordShl(index_word, 3), var_low.value(), high))); WordShl(index_word, UintPtrConstant(3)), var_low.value(), high)));
// This shouldn't happen, we've already validated the type. // This shouldn't happen, we've already validated the type.
BIND(&other); BIND(&other);
Unreachable(); Unreachable();
......
...@@ -802,19 +802,21 @@ Node* CodeAssembler::AtomicStore(MachineRepresentation rep, Node* base, ...@@ -802,19 +802,21 @@ Node* CodeAssembler::AtomicStore(MachineRepresentation rep, Node* base,
return raw_assembler()->AtomicStore(rep, base, offset, value, value_high); return raw_assembler()->AtomicStore(rep, base, offset, value, value_high);
} }
#define ATOMIC_FUNCTION(name) \ #define ATOMIC_FUNCTION(name) \
Node* CodeAssembler::Atomic##name(MachineType type, Node* base, \ Node* CodeAssembler::Atomic##name( \
Node* offset, Node* value, \ MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset, \
Node* value_high) { \ Node* value, base::Optional<TNode<UintPtrT>> value_high) { \
return raw_assembler()->Atomic##name(type, base, offset, value, \ Node* value_high_node = nullptr; \
value_high); \ if (value_high) value_high_node = *value_high; \
return raw_assembler()->Atomic##name(type, base, offset, value, \
value_high_node); \
} }
ATOMIC_FUNCTION(Exchange)
ATOMIC_FUNCTION(Add) ATOMIC_FUNCTION(Add)
ATOMIC_FUNCTION(Sub) ATOMIC_FUNCTION(Sub)
ATOMIC_FUNCTION(And) ATOMIC_FUNCTION(And)
ATOMIC_FUNCTION(Or) ATOMIC_FUNCTION(Or)
ATOMIC_FUNCTION(Xor) ATOMIC_FUNCTION(Xor)
ATOMIC_FUNCTION(Exchange)
#undef ATOMIC_FUNCTION #undef ATOMIC_FUNCTION
Node* CodeAssembler::AtomicCompareExchange(MachineType type, Node* base, Node* CodeAssembler::AtomicCompareExchange(MachineType type, Node* base,
......
...@@ -783,31 +783,31 @@ class V8_EXPORT_PRIVATE CodeAssembler { ...@@ -783,31 +783,31 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Node* AtomicStore(MachineRepresentation rep, Node* base, Node* offset, Node* AtomicStore(MachineRepresentation rep, Node* base, Node* offset,
Node* value, Node* value_high = nullptr); Node* value, Node* value_high = nullptr);
Node* AtomicAdd(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicSub(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicAnd(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicOr(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
Node* AtomicXor(MachineType type, TNode<RawPtrT> base, TNode<UintPtrT> offset,
Node* value, base::Optional<TNode<UintPtrT>> value_high);
// Exchange value at raw memory location // Exchange value at raw memory location
Node* AtomicExchange(MachineType type, Node* base, Node* offset, Node* value, Node* AtomicExchange(MachineType type, TNode<RawPtrT> base,
Node* value_high = nullptr); TNode<UintPtrT> offset, Node* value,
base::Optional<TNode<UintPtrT>> value_high);
// Compare and Exchange value at raw memory location // Compare and Exchange value at raw memory location
Node* AtomicCompareExchange(MachineType type, Node* base, Node* offset, Node* AtomicCompareExchange(MachineType type, Node* base, Node* offset,
Node* old_value, Node* new_value, Node* old_value, Node* new_value,
Node* old_value_high = nullptr, Node* old_value_high = nullptr,
Node* new_value_high = nullptr); Node* new_value_high = nullptr);
Node* AtomicAdd(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicSub(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicAnd(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicOr(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
Node* AtomicXor(MachineType type, Node* base, Node* offset, Node* value,
Node* value_high = nullptr);
// Store a value to the root array. // Store a value to the root array.
Node* StoreRoot(RootIndex root_index, Node* value); Node* StoreRoot(RootIndex root_index, Node* value);
......
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