Commit 3067391c authored by Thibaud Michaud's avatar Thibaud Michaud Committed by Commit Bot

[wasm][liftoff][eh] Unpack i32s from exception

R=clemensb@chromium.org

Bug: v8:11453
Change-Id: Ie50e5c85eaed04b4e90dd51261838f7f1a5f65a9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2743884
Commit-Queue: Thibaud Michaud <thibaudm@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73406}
parent 4a5167ef
......@@ -646,9 +646,9 @@ class LiftoffAssembler : public TurboAssembler {
inline void LoadFixedArrayLengthAsInt32(LiftoffRegister dst, Register array,
LiftoffRegList pinned) {
int offset = FixedArray::kLengthOffset - kHeapObjectTag;
LoadTaggedSignedAsInt32(dst, array, offset, pinned);
LoadSmiAsInt32(dst, array, offset, pinned);
}
inline void LoadTaggedSignedAsInt32(LiftoffRegister dst, Register src_addr,
inline void LoadSmiAsInt32(LiftoffRegister dst, Register src_addr,
int32_t offset, LiftoffRegList pinned) {
if (SmiValuesAre32Bits()) {
#if V8_TARGET_LITTLE_ENDIAN
......
......@@ -1070,12 +1070,16 @@ class LiftoffCompiler {
PushControl(block);
}
// Load the exception tag in {kReturnRegister0}.
void GetExceptionTag(LiftoffAssembler::VarState& exception) {
// Load the property in {kReturnRegister0}.
LiftoffRegister GetExceptionProperty(LiftoffAssembler::VarState& exception,
RootIndex root_index) {
DCHECK(root_index == RootIndex::kwasm_exception_tag_symbol ||
root_index == RootIndex::kwasm_exception_values_symbol);
LiftoffRegList pinned;
LiftoffRegister tag_symbol_reg =
pinned.set(__ GetUnusedRegister(kGpReg, pinned));
LoadExceptionTagSymbol(tag_symbol_reg.gp(), pinned);
LoadExceptionSymbol(tag_symbol_reg.gp(), pinned, root_index);
LiftoffRegister context_reg =
pinned.set(__ GetUnusedRegister(kGpReg, pinned));
LOAD_TAGGED_PTR_INSTANCE_FIELD(context_reg.gp(), NativeContext, pinned);
......@@ -1094,6 +1098,7 @@ class LiftoffCompiler {
DEBUG_CODE_COMMENT("Call builtin");
__ CallRuntimeStub(WasmCode::RuntimeStubId::kWasmGetOwnProperty);
DefineSafepoint();
return LiftoffRegister(kReturnRegister0);
}
void CatchException(FullDecoder* decoder,
......@@ -1120,9 +1125,10 @@ class LiftoffCompiler {
DEBUG_CODE_COMMENT("load caught exception tag");
DCHECK_EQ(__ cache_state()->stack_state.back().kind(), kRef);
GetExceptionTag(__ cache_state()->stack_state.back());
LiftoffRegister caught_tag =
GetExceptionProperty(__ cache_state()->stack_state.back(),
RootIndex::kwasm_exception_tag_symbol);
LiftoffRegList pinned;
LiftoffRegister caught_tag(kReturnRegister0);
pinned.set(caught_tag);
DEBUG_CODE_COMMENT("load expected exception tag");
......@@ -1145,10 +1151,8 @@ class LiftoffCompiler {
block->try_info->in_handler = true;
num_exceptions_++;
}
if (env_->module->exceptions[imm.index].sig->parameter_count() > 0) {
// TODO(thibaudm): Unpack exception.
unsupported(decoder, kExceptionHandling, "exception with parameters");
}
GetExceptionValues(decoder, __ cache_state()->stack_state.back(),
imm.exception);
}
void Rethrow(FullDecoder* decoder,
......@@ -3842,6 +3846,22 @@ class LiftoffCompiler {
tmp_reg, pinned, LiftoffAssembler::kSkipWriteBarrier);
}
void Load32BitExceptionValue(LiftoffRegister dst,
LiftoffRegister values_array, uint32_t* index,
LiftoffRegList pinned) {
LiftoffRegister upper = pinned.set(__ GetUnusedRegister(kGpReg, pinned));
__ LoadSmiAsInt32(
upper, values_array.gp(),
wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(*index), pinned);
(*index)++;
__ emit_i32_shli(upper.gp(), upper.gp(), 16);
__ LoadSmiAsInt32(
dst, values_array.gp(),
wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(*index), pinned);
(*index)++;
__ emit_i32_or(dst.gp(), upper.gp(), dst.gp());
}
void StoreExceptionValue(ValueType type, Register values_array,
int* index_in_array, LiftoffRegList pinned) {
// TODO(clemensb): Handle more types.
......@@ -3850,6 +3870,28 @@ class LiftoffCompiler {
Store32BitExceptionValue(values_array, index_in_array, value.gp(), pinned);
}
void GetExceptionValues(FullDecoder* decoder,
LiftoffAssembler::VarState& exception_var,
const WasmException* exception) {
LiftoffRegList pinned;
DEBUG_CODE_COMMENT("get exception values");
LiftoffRegister values_array = GetExceptionProperty(
exception_var, RootIndex::kwasm_exception_values_symbol);
uint32_t index = 0;
const WasmExceptionSig* sig = exception->sig;
LiftoffRegister value = pinned.set(__ GetUnusedRegister(kGpReg, pinned));
for (ValueType param : sig->parameters()) {
if (param != kWasmI32) {
unsupported(decoder, kExceptionHandling,
"unsupported type in exception payload");
return;
}
Load32BitExceptionValue(value, values_array, &index, pinned);
__ PushRegister(kI32, value);
}
DCHECK_EQ(index, WasmExceptionPackage::GetEncodedSize(exception));
}
void EmitLandingPad(FullDecoder* decoder) {
if (current_catch_ == -1) return;
MovableLabel handler;
......@@ -5559,8 +5601,7 @@ class LiftoffCompiler {
WasmExportedFunctionData::kInstanceOffset),
pinned);
LiftoffRegister func_index = target;
__ LoadTaggedSignedAsInt32(
func_index, func_data.gp(),
__ LoadSmiAsInt32(func_index, func_data.gp(),
wasm::ObjectAccess::ToTagged(
WasmExportedFunctionData::kFunctionIndexOffset),
pinned);
......@@ -5590,8 +5631,7 @@ class LiftoffCompiler {
WasmInstanceObject::kJumpTableStartOffset),
kPointerLoadType, pinned);
LiftoffRegister jump_table_offset = temp;
__ LoadTaggedSignedAsInt32(
jump_table_offset, func_data.gp(),
__ LoadSmiAsInt32(jump_table_offset, func_data.gp(),
wasm::ObjectAccess::ToTagged(
WasmExportedFunctionData::kJumpTableOffsetOffset),
pinned);
......@@ -5716,10 +5756,10 @@ class LiftoffCompiler {
pinned);
}
void LoadExceptionTagSymbol(Register dst, LiftoffRegList pinned) {
void LoadExceptionSymbol(Register dst, LiftoffRegList pinned,
RootIndex root_index) {
LOAD_INSTANCE_FIELD(dst, IsolateRoot, kSystemPointerSize, pinned);
uint32_t offset_imm =
IsolateData::root_slot_offset(RootIndex::kwasm_exception_tag_symbol);
uint32_t offset_imm = IsolateData::root_slot_offset(root_index);
__ LoadFullPointer(dst, dst, offset_imm);
}
......
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