Commit 15821ebb authored by Manos Koukoutos's avatar Manos Koukoutos Committed by V8 LUCI CQ

[wasm][refactor] Rename some symbols

- Rename WasmTrapElemSegmentDropped -> WasmTrapElemSegmentOutOfBounds.
- Rename WasmArrayInitFromData -> WasmArrayInitFromSegment, in
  anticipation of array.init_from_elem.
- Rename InitExprInterface::result_ -> computed_value_, to
  distinguish it from the {result} values. Also, rename
  generate_result() -> generate_value().
- Drive-by: Restructure Runtime_WasmArrayInitFromSegment.

Change-Id: Ic372db909847c7a169f3d6732e64e8665f4200fb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3693702Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80991}
parent 4a7b2d47
......@@ -427,7 +427,7 @@ extern enum MessageTemplate {
kWasmTrapFloatUnrepresentable,
kWasmTrapFuncSigMismatch,
kWasmTrapDataSegmentOutOfBounds,
kWasmTrapElemSegmentDropped,
kWasmTrapElementSegmentOutOfBounds,
kWasmTrapTableOutOfBounds,
kWasmTrapRethrowNull,
kWasmTrapNullDereference,
......
......@@ -36,7 +36,7 @@ extern runtime WasmI64AtomicWait(
Context, WasmInstanceObject, Number, BigInt, BigInt): Smi;
extern runtime WasmArrayCopy(
Context, WasmArray, Smi, WasmArray, Smi, Smi): JSAny;
extern runtime WasmArrayInitFromData(
extern runtime WasmArrayInitFromSegment(
Context, WasmInstanceObject, Smi, Smi, Smi, Map): Object;
extern runtime WasmStringNewWtf8(
Context, WasmInstanceObject, Smi, Number, Number): String;
......@@ -363,10 +363,10 @@ builtin WasmAllocateArray_Uninitialized(
return %RawDownCast<WasmArray>(result);
}
builtin WasmArrayInitFromData(
builtin WasmArrayInitFromSegment(
dataSegment: uint32, offset: uint32, length: uint32, rtt: Map): Object {
const instance = LoadInstanceFromFrame();
tail runtime::WasmArrayInitFromData(
tail runtime::WasmArrayInitFromSegment(
LoadContextFromInstance(instance), instance, SmiFromUint32(dataSegment),
SmiFromUint32(offset), SmiFromUint32(length), rtt);
}
......@@ -651,8 +651,9 @@ builtin ThrowWasmTrapDataSegmentOutOfBounds(): JSAny {
tail WasmTrap(SmiConstant(MessageTemplate::kWasmTrapDataSegmentOutOfBounds));
}
builtin ThrowWasmTrapElemSegmentDropped(): JSAny {
tail WasmTrap(SmiConstant(MessageTemplate::kWasmTrapElemSegmentDropped));
builtin ThrowWasmTrapElementSegmentOutOfBounds(): JSAny {
tail WasmTrap(
SmiConstant(MessageTemplate::kWasmTrapElementSegmentOutOfBounds));
}
builtin ThrowWasmTrapTableOutOfBounds(): JSAny {
......
......@@ -1800,7 +1800,7 @@ enum IsolateAddressId {
V(TrapFloatUnrepresentable) \
V(TrapFuncSigMismatch) \
V(TrapDataSegmentOutOfBounds) \
V(TrapElemSegmentDropped) \
V(TrapElementSegmentOutOfBounds) \
V(TrapTableOutOfBounds) \
V(TrapRethrowNull) \
V(TrapNullDereference) \
......
......@@ -637,7 +637,7 @@ namespace internal {
T(WasmTrapMultiReturnLengthMismatch, "multi-return length mismatch") \
T(WasmTrapJSTypeError, "type incompatibility when transforming from/to JS") \
T(WasmTrapDataSegmentOutOfBounds, "data segment out of bounds") \
T(WasmTrapElemSegmentDropped, "element segment has been dropped") \
T(WasmTrapElementSegmentOutOfBounds, "element segment out of bounds") \
T(WasmTrapRethrowNull, "rethrowing null value") \
T(WasmTrapNullDereference, "dereferencing a null pointer") \
T(WasmTrapIllegalCast, "illegal cast") \
......
......@@ -5331,13 +5331,15 @@ Node* WasmGraphBuilder::ArrayInit(const wasm::ArrayType* type, Node* rtt,
return array;
}
Node* WasmGraphBuilder::ArrayInitFromData(const wasm::ArrayType* type,
uint32_t data_segment, Node* offset,
Node* length, Node* rtt,
wasm::WasmCodePosition position) {
return gasm_->CallBuiltin(
Builtin::kWasmArrayInitFromData, Operator::kNoDeopt | Operator::kNoThrow,
gasm_->Uint32Constant(data_segment), offset, length, rtt);
Node* WasmGraphBuilder::ArrayInitFromSegment(const wasm::ArrayType* type,
uint32_t data_segment,
Node* offset, Node* length,
Node* rtt,
wasm::WasmCodePosition position) {
return gasm_->CallBuiltin(Builtin::kWasmArrayInitFromSegment,
Operator::kNoDeopt | Operator::kNoThrow,
gasm_->Uint32Constant(data_segment), offset, length,
rtt);
}
Node* WasmGraphBuilder::RttCanon(uint32_t type_index) {
......
......@@ -501,9 +501,9 @@ class WasmGraphBuilder {
Node* length, wasm::WasmCodePosition position);
Node* ArrayInit(const wasm::ArrayType* type, Node* rtt,
base::Vector<Node*> elements);
Node* ArrayInitFromData(const wasm::ArrayType* type, uint32_t data_segment,
Node* offset, Node* length, Node* rtt,
wasm::WasmCodePosition position);
Node* ArrayInitFromSegment(const wasm::ArrayType* type, uint32_t data_segment,
Node* offset, Node* length, Node* rtt,
wasm::WasmCodePosition position);
Node* I31New(Node* input);
Node* I31GetS(Node* input);
Node* I31GetU(Node* input);
......
......@@ -712,31 +712,36 @@ RUNTIME_FUNCTION(Runtime_WasmArrayCopy) {
return ReadOnlyRoots(isolate).undefined_value();
}
RUNTIME_FUNCTION(Runtime_WasmArrayInitFromData) {
RUNTIME_FUNCTION(Runtime_WasmArrayInitFromSegment) {
ClearThreadInWasmScope flag_scope(isolate);
HandleScope scope(isolate);
DCHECK_EQ(5, args.length());
Handle<WasmInstanceObject> instance = args.at<WasmInstanceObject>(0);
uint32_t data_segment = args.positive_smi_value_at(1);
uint32_t segment_index = args.positive_smi_value_at(1);
uint32_t offset = args.positive_smi_value_at(2);
uint32_t length = args.positive_smi_value_at(3);
Handle<Map> rtt = args.at<Map>(4);
uint32_t element_size = WasmArray::DecodeElementSizeFromMap(*rtt);
uint32_t length_in_bytes = length * element_size;
wasm::ArrayType* type = reinterpret_cast<wasm::ArrayType*>(
rtt->wasm_type_info().foreign_address());
uint32_t element_size = type->element_type().value_kind_size();
// This check also implies no overflow.
if (length > static_cast<uint32_t>(WasmArray::MaxLength(element_size))) {
return ThrowWasmError(isolate, MessageTemplate::kWasmTrapArrayTooLarge);
}
// The check above implies no overflow.
uint32_t length_in_bytes = length * element_size;
DCHECK_EQ(length_in_bytes / element_size, length);
if (!base::IsInBounds<uint32_t>(
offset, length_in_bytes,
instance->data_segment_sizes()[data_segment])) {
instance->data_segment_sizes()[segment_index])) {
return ThrowWasmError(isolate,
MessageTemplate::kWasmTrapDataSegmentOutOfBounds);
}
Address source = instance->data_segment_starts()[data_segment] + offset;
Address source = instance->data_segment_starts()[segment_index] + offset;
return *isolate->factory()->NewWasmArrayFromMemory(length, rtt, source);
}
......
......@@ -608,7 +608,7 @@ namespace internal {
F(WasmTriggerTierUp, 1, 1) \
F(WasmDebugBreak, 0, 1) \
F(WasmArrayCopy, 5, 1) \
F(WasmArrayInitFromData, 5, 1) \
F(WasmArrayInitFromSegment, 5, 1) \
F(WasmAllocateContinuation, 1, 1) \
F(WasmSyncStackLimit, 0, 1) \
F(WasmCreateResumePromise, 2, 1) \
......
......@@ -5581,11 +5581,12 @@ class LiftoffCompiler {
__ PushRegister(kRef, array);
}
void ArrayInitFromData(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment,
const Value& /* offset */, const Value& /* length */,
const Value& /* rtt */, Value* /* result */) {
void ArrayInitFromSegment(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment,
const Value& /* offset */,
const Value& /* length */, const Value& /* rtt */,
Value* /* result */) {
LiftoffRegList pinned;
LiftoffRegister data_segment_reg =
pinned.set(__ GetUnusedRegister(kGpReg, pinned));
......@@ -5593,7 +5594,7 @@ class LiftoffCompiler {
WasmValue(static_cast<int32_t>(data_segment.index)));
LiftoffAssembler::VarState data_segment_var(kI32, data_segment_reg, 0);
CallRuntimeStub(WasmCode::kWasmArrayInitFromData,
CallRuntimeStub(WasmCode::kWasmArrayInitFromSegment,
MakeSig::Returns(kRef).Params(kI32, kI32, kI32, kRtt),
{
data_segment_var,
......
......@@ -983,7 +983,7 @@ struct ControlBase : public PcForErrors<validate> {
const Value& rtt, Value* result) \
F(ArrayInit, const ArrayIndexImmediate<validate>& imm, \
const base::Vector<Value>& elements, const Value& rtt, Value* result) \
F(ArrayInitFromData, const ArrayIndexImmediate<validate>& array_imm, \
F(ArrayInitFromSegment, const ArrayIndexImmediate<validate>& array_imm, \
const IndexImmediate<validate>& data_segment, const Value& offset, \
const Value& length, const Value& rtt, Value* result) \
F(RttCanon, uint32_t type_index, Value* result) \
......@@ -1979,7 +1979,7 @@ class WasmDecoder : public Decoder {
case kExprArrayInitFromDataStatic: {
ArrayIndexImmediate<validate> array_imm(decoder, pc + length);
IndexImmediate<validate> data_imm(
decoder, pc + length + array_imm.length, "data segment index");
decoder, pc + length + array_imm.length, "segment index");
return length + array_imm.length + data_imm.length;
}
case kExprBrOnCast:
......@@ -4410,7 +4410,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
ValueType element_type = array_imm.array_type->element_type();
if (element_type.is_reference()) {
this->DecodeError(
"array.init_from_data can only be used with value-type arrays, "
"array.init_from_data can only be used with numeric-type arrays, "
"found array type #%d instead",
array_imm.index);
return 0;
......@@ -4443,7 +4443,7 @@ class WasmFullDecoder : public WasmDecoder<validate, decoding_mode> {
Value array =
CreateValue(ValueType::Ref(array_imm.index, kNonNullable));
CALL_INTERFACE_IF_OK_AND_REACHABLE(ArrayInitFromData, array_imm,
CALL_INTERFACE_IF_OK_AND_REACHABLE(ArrayInitFromSegment, array_imm,
data_segment, offset, length, rtt,
&array);
Drop(3); // rtt, length, offset
......
......@@ -1193,13 +1193,13 @@ class WasmGraphBuildingInterface {
VectorOf(element_nodes)));
}
void ArrayInitFromData(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment,
const Value& offset, const Value& length,
const Value& rtt, Value* result) {
void ArrayInitFromSegment(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment,
const Value& offset, const Value& length,
const Value& rtt, Value* result) {
SetAndTypeNode(result,
builder_->ArrayInitFromData(
builder_->ArrayInitFromSegment(
array_imm.array_type, data_segment.index, offset.node,
length.node, rtt.node, decoder->position()));
}
......
......@@ -19,35 +19,35 @@ namespace wasm {
void InitExprInterface::I32Const(FullDecoder* decoder, Value* result,
int32_t value) {
if (generate_result()) result->runtime_value = WasmValue(value);
if (generate_value()) result->runtime_value = WasmValue(value);
}
void InitExprInterface::I64Const(FullDecoder* decoder, Value* result,
int64_t value) {
if (generate_result()) result->runtime_value = WasmValue(value);
if (generate_value()) result->runtime_value = WasmValue(value);
}
void InitExprInterface::F32Const(FullDecoder* decoder, Value* result,
float value) {
if (generate_result()) result->runtime_value = WasmValue(value);
if (generate_value()) result->runtime_value = WasmValue(value);
}
void InitExprInterface::F64Const(FullDecoder* decoder, Value* result,
double value) {
if (generate_result()) result->runtime_value = WasmValue(value);
if (generate_value()) result->runtime_value = WasmValue(value);
}
void InitExprInterface::S128Const(FullDecoder* decoder,
Simd128Immediate<validate>& imm,
Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
result->runtime_value = WasmValue(imm.value, kWasmS128);
}
void InitExprInterface::BinOp(FullDecoder* decoder, WasmOpcode opcode,
const Value& lhs, const Value& rhs,
Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
switch (opcode) {
case kExprI32Add:
result->runtime_value =
......@@ -80,7 +80,7 @@ void InitExprInterface::BinOp(FullDecoder* decoder, WasmOpcode opcode,
void InitExprInterface::RefNull(FullDecoder* decoder, ValueType type,
Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
result->runtime_value = WasmValue(isolate_->factory()->null_value(), type);
}
......@@ -90,7 +90,7 @@ void InitExprInterface::RefFunc(FullDecoder* decoder, uint32_t function_index,
outer_module_->functions[function_index].declared = true;
return;
}
if (!generate_result()) return;
if (!generate_value()) return;
ValueType type = ValueType::Ref(module_->functions[function_index].sig_index,
kNonNullable);
Handle<WasmInternalFunction> internal =
......@@ -101,7 +101,7 @@ void InitExprInterface::RefFunc(FullDecoder* decoder, uint32_t function_index,
void InitExprInterface::GlobalGet(FullDecoder* decoder, Value* result,
const GlobalIndexImmediate<validate>& imm) {
if (!generate_result()) return;
if (!generate_value()) return;
const WasmGlobal& global = module_->globals[imm.index];
DCHECK(!global.mutability);
result->runtime_value =
......@@ -120,7 +120,7 @@ void InitExprInterface::GlobalGet(FullDecoder* decoder, Value* result,
void InitExprInterface::StructNewWithRtt(
FullDecoder* decoder, const StructIndexImmediate<validate>& imm,
const Value& rtt, const Value args[], Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
std::vector<WasmValue> field_values(imm.struct_type->field_count());
for (size_t i = 0; i < field_values.size(); i++) {
field_values[i] = args[i].runtime_value;
......@@ -161,7 +161,7 @@ WasmValue DefaultValueForType(ValueType type, Isolate* isolate) {
void InitExprInterface::StructNewDefault(
FullDecoder* decoder, const StructIndexImmediate<validate>& imm,
const Value& rtt, Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
std::vector<WasmValue> field_values(imm.struct_type->field_count());
for (uint32_t i = 0; i < field_values.size(); i++) {
field_values[i] = DefaultValueForType(imm.struct_type->field(i), isolate_);
......@@ -177,7 +177,7 @@ void InitExprInterface::ArrayInit(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& imm,
const base::Vector<Value>& elements,
const Value& rtt, Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
std::vector<WasmValue> element_values;
for (Value elem : elements) element_values.push_back(elem.runtime_value);
result->runtime_value =
......@@ -187,11 +187,11 @@ void InitExprInterface::ArrayInit(FullDecoder* decoder,
ValueType::Ref(HeapType(imm.index), kNonNullable));
}
void InitExprInterface::ArrayInitFromData(
void InitExprInterface::ArrayInitFromSegment(
FullDecoder* decoder, const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment_imm, const Value& offset_value,
const Value& length_value, const Value& rtt, Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
uint32_t length = length_value.runtime_value.to_u32();
uint32_t offset = offset_value.runtime_value.to_u32();
......@@ -222,7 +222,7 @@ void InitExprInterface::ArrayInitFromData(
void InitExprInterface::RttCanon(FullDecoder* decoder, uint32_t type_index,
Value* result) {
if (!generate_result()) return;
if (!generate_value()) return;
result->runtime_value = WasmValue(
handle(instance_->managed_object_maps().get(type_index), isolate_),
ValueType::Rtt(type_index));
......@@ -233,7 +233,9 @@ void InitExprInterface::DoReturn(FullDecoder* decoder,
end_found_ = true;
// End decoding on "end".
decoder->set_end(decoder->pc() + 1);
if (generate_result()) result_ = decoder->stack_value(1)->runtime_value;
if (generate_value()) {
computed_value_ = decoder->stack_value(1)->runtime_value;
}
}
} // namespace wasm
......
......@@ -72,17 +72,17 @@ class InitExprInterface {
WasmValue result() {
DCHECK_NOT_NULL(isolate_);
return result_;
return computed_value_;
}
bool end_found() { return end_found_; }
bool runtime_error() { return error_ != nullptr; }
const char* runtime_error_msg() { return error_; }
private:
bool generate_result() { return isolate_ != nullptr && !runtime_error(); }
bool generate_value() { return isolate_ != nullptr && !runtime_error(); }
bool end_found_ = false;
const char* error_ = nullptr;
WasmValue result_;
WasmValue computed_value_;
const WasmModule* module_;
WasmModule* outer_module_;
Isolate* isolate_;
......
......@@ -118,7 +118,7 @@ struct WasmModule;
V(WasmAllocateArray_Uninitialized) \
V(WasmArrayCopy) \
V(WasmArrayCopyWithChecks) \
V(WasmArrayInitFromData) \
V(WasmArrayInitFromSegment) \
V(WasmAllocateStructWithRtt) \
V(WasmSubtypeCheck) \
V(WasmOnStackReplace) \
......
......@@ -402,11 +402,12 @@ class InitExprInterface {
: WasmInitExpr::ArrayInit(imm.index, args);
}
void ArrayInitFromData(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment_imm,
const Value& offset_value, const Value& length_value,
const Value& rtt, Value* result) {
void ArrayInitFromSegment(FullDecoder* decoder,
const ArrayIndexImmediate<validate>& array_imm,
const IndexImmediate<validate>& data_segment_imm,
const Value& offset_value,
const Value& length_value, const Value& rtt,
Value* result) {
// TODO(7748): Implement.
UNIMPLEMENTED();
}
......
......@@ -905,7 +905,7 @@ let kTrapTableOutOfBounds = 6;
let kTrapFuncSigMismatch = 7;
let kTrapUnalignedAccess = 8;
let kTrapDataSegmentOutOfBounds = 9;
let kTrapElemSegmentDropped = 10;
let kTrapElementSegmentOutOfBounds = 10;
let kTrapRethrowNull = 11;
let kTrapArrayTooLarge = 12;
......@@ -920,7 +920,7 @@ let kTrapMsgs = [
'null function or function signature mismatch', // --
'operation does not support unaligned accesses', // --
'data segment out of bounds', // --
'element segment has been dropped', // --
'element segment out of bounds', // --
'rethrowing null value', // --
'requested new array is too large' // --
];
......
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