Commit f4020f76 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Use a builtin instead of runtime function

... for creating a FixedArray.
Calling builtins is generally cheaper than calling into the runtime, and
this also saves us a int->Smi conversion.
The builtin still has the "Wasm" prefix, since it's only used in wasm
for now.

R=thibaudm@chromium.org

Bug: v8:11453
Change-Id: I0c5b6b71ae1b07608f51e685014a0e8dc0034111
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2698674Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72839}
parent 287634a5
......@@ -192,6 +192,12 @@ builtin WasmRefFunc(index: uint32): Object {
}
}
builtin WasmAllocateFixedArray(size: intptr): FixedArray {
if (size == 0) return kEmptyFixedArray;
return UnsafeCast<FixedArray>(AllocateFixedArray(
ElementsKind::PACKED_ELEMENTS, size, AllocationFlag::kNone));
}
builtin WasmThrow(tag: Object, values: FixedArray): JSAny {
tail runtime::WasmThrow(LoadContextFromFrame(), tag, values);
}
......
......@@ -2277,11 +2277,20 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
wasm::WasmCodePosition position) {
needs_stack_check_ = true;
uint32_t encoded_size = WasmExceptionPackage::GetEncodedSize(exception);
Node* encoded_size_smi =
BuildChangeUint31ToSmi(mcgraph()->Uint32Constant(encoded_size));
Node* values_array = BuildCallToRuntime(
Runtime::kWasmCreateFixedArrayForThrow, &encoded_size_smi, 1);
SetSourcePosition(values_array, position);
Node* values_array;
{
WasmAllocateFixedArrayDescriptor interface_descriptor;
auto* call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), interface_descriptor,
interface_descriptor.GetStackParameterCount(), CallDescriptor::kNoFlags,
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmAllocateFixedArray, RelocInfo::WASM_STUB_CALL);
values_array = gasm_->Call(call_descriptor, call_target,
gasm_->IntPtrConstant(encoded_size));
SetSourcePosition(values_array, position);
}
uint32_t index = 0;
const wasm::WasmExceptionSig* sig = exception->sig;
......@@ -2339,17 +2348,20 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
Node* exception_tag = LoadExceptionTagFromTable(exception_index);
WasmThrowDescriptor interface_descriptor;
auto call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), interface_descriptor,
interface_descriptor.GetStackParameterCount(), CallDescriptor::kNoFlags,
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmThrow, RelocInfo::WASM_STUB_CALL);
Node* call =
gasm_->Call(call_descriptor, call_target, exception_tag, values_array);
SetSourcePosition(call, position);
return call;
Node* throw_call;
{
WasmThrowDescriptor interface_descriptor;
auto* call_descriptor = Linkage::GetStubCallDescriptor(
mcgraph()->zone(), interface_descriptor,
interface_descriptor.GetStackParameterCount(), CallDescriptor::kNoFlags,
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmThrow, RelocInfo::WASM_STUB_CALL);
throw_call =
gasm_->Call(call_descriptor, call_target, exception_tag, values_array);
SetSourcePosition(throw_call, position);
}
return throw_call;
}
void WasmGraphBuilder::BuildEncodeException32BitValue(Node* values_array,
......
......@@ -148,27 +148,14 @@ RUNTIME_FUNCTION(Runtime_WasmThrowJSTypeError) {
isolate, NewTypeError(MessageTemplate::kWasmTrapJSTypeError));
}
RUNTIME_FUNCTION(Runtime_WasmCreateFixedArrayForThrow) {
ClearThreadInWasmScope clear_wasm_flag;
// TODO(wasm): Replace this by equivalent TurboFan code.
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
DCHECK(isolate->context().is_null());
isolate->set_context(GetNativeContextFromWasmInstanceOnStackTop(isolate));
CONVERT_SMI_ARG_CHECKED(size, 0);
Handle<FixedArray> values = isolate->factory()->NewFixedArray(size);
return *values;
}
RUNTIME_FUNCTION(Runtime_WasmThrow) {
// Do not clear the flag in a scope. The unwinder will set it if the exception
// is caught by a wasm frame, otherwise we keep it cleared.
trap_handler::ClearThreadInWasm();
HandleScope scope(isolate);
DCHECK_EQ(2, args.length());
// The context is still set from WasmCreateFixedArrayForThrow.
DCHECK_EQ(isolate->context(),
GetNativeContextFromWasmInstanceOnStackTop(isolate));
isolate->set_context(GetNativeContextFromWasmInstanceOnStackTop(isolate));
CONVERT_ARG_CHECKED(WasmExceptionTag, tag_raw, 0);
CONVERT_ARG_CHECKED(FixedArray, values_raw, 1);
// TODO(wasm): Manually box because parameters are not visited yet.
......
......@@ -579,7 +579,6 @@ namespace internal {
F(WasmAtomicNotify, 3, 1) \
F(WasmMemoryGrow, 2, 1) \
F(WasmStackGuard, 0, 1) \
F(WasmCreateFixedArrayForThrow, 1, 1) \
F(WasmThrow, 2, 1) \
F(WasmReThrow, 1, 1) \
F(WasmThrowJSTypeError, 0, 1) \
......
......@@ -71,6 +71,7 @@ struct WasmModule;
V(WasmTableSet) \
V(WasmStackGuard) \
V(WasmStackOverflow) \
V(WasmAllocateFixedArray) \
V(WasmThrow) \
V(WasmRethrow) \
V(WasmTraceEnter) \
......
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