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

[wasm][cleanup] Expose fewer methods for building constants

The API of the {WasmGraphBuilder} should provide methods for all wasm
opcodes. For constants, that is {Int32Constant}, {Int64Constant},
{Float32Constant}, {Float64Constant}, and {Simd128Constant}. The other
helpers ({Uint32Constant} and {IntPtrConstant}) were only used
internally, hence remove them from the API and call the {MachineGraph}
method directly.

R=ahaas@chromium.org

Bug: v8:10933
Change-Id: Ifeec88f30062ede468bf6b7af2d2b214547130bc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2445475Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70333}
parent afd26925
...@@ -297,9 +297,9 @@ Node* WasmGraphBuilder::RefFunc(uint32_t function_index) { ...@@ -297,9 +297,9 @@ Node* WasmGraphBuilder::RefFunc(uint32_t function_index) {
Node* call_target = mcgraph()->RelocatableIntPtrConstant( Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmRefFunc, RelocInfo::WASM_STUB_CALL); wasm::WasmCode::kWasmRefFunc, RelocInfo::WASM_STUB_CALL);
return SetEffectControl( return SetEffectControl(graph()->NewNode(
graph()->NewNode(mcgraph()->common()->Call(call_descriptor), call_target, mcgraph()->common()->Call(call_descriptor), call_target,
Uint32Constant(function_index), effect(), control())); mcgraph()->Uint32Constant(function_index), effect(), control()));
} }
Node* WasmGraphBuilder::RefAsNonNull(Node* arg, Node* WasmGraphBuilder::RefAsNonNull(Node* arg,
...@@ -321,10 +321,6 @@ Node* WasmGraphBuilder::BuildLoadIsolateRoot() { ...@@ -321,10 +321,6 @@ Node* WasmGraphBuilder::BuildLoadIsolateRoot() {
return LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer()); return LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
} }
Node* WasmGraphBuilder::Uint32Constant(uint32_t value) {
return mcgraph()->Uint32Constant(value);
}
Node* WasmGraphBuilder::Int32Constant(int32_t value) { Node* WasmGraphBuilder::Int32Constant(int32_t value) {
return mcgraph()->Int32Constant(value); return mcgraph()->Int32Constant(value);
} }
...@@ -333,10 +329,6 @@ Node* WasmGraphBuilder::Int64Constant(int64_t value) { ...@@ -333,10 +329,6 @@ Node* WasmGraphBuilder::Int64Constant(int64_t value) {
return mcgraph()->Int64Constant(value); return mcgraph()->Int64Constant(value);
} }
Node* WasmGraphBuilder::IntPtrConstant(intptr_t value) {
return mcgraph()->IntPtrConstant(value);
}
void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) { void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) {
DCHECK_NOT_NULL(env_); // Wrappers don't get stack checks. DCHECK_NOT_NULL(env_); // Wrappers don't get stack checks.
if (!FLAG_wasm_stack_checks || !env_->runtime_exception_support) { if (!FLAG_wasm_stack_checks || !env_->runtime_exception_support) {
...@@ -2084,7 +2076,7 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index, ...@@ -2084,7 +2076,7 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
uint32_t encoded_size = WasmExceptionPackage::GetEncodedSize(exception); uint32_t encoded_size = WasmExceptionPackage::GetEncodedSize(exception);
Node* create_parameters[] = { Node* create_parameters[] = {
LoadExceptionTagFromTable(exception_index), LoadExceptionTagFromTable(exception_index),
BuildChangeUint31ToSmi(Uint32Constant(encoded_size))}; BuildChangeUint31ToSmi(mcgraph()->Uint32Constant(encoded_size))};
Node* except_obj = Node* except_obj =
BuildCallToRuntime(Runtime::kWasmThrowCreate, create_parameters, BuildCallToRuntime(Runtime::kWasmThrowCreate, create_parameters,
arraysize(create_parameters)); arraysize(create_parameters));
...@@ -3257,7 +3249,7 @@ Node* WasmGraphBuilder::BuildChangeSmiToIntPtr(Node* value) { ...@@ -3257,7 +3249,7 @@ Node* WasmGraphBuilder::BuildChangeSmiToIntPtr(Node* value) {
Node* WasmGraphBuilder::BuildConvertUint32ToSmiWithSaturation(Node* value, Node* WasmGraphBuilder::BuildConvertUint32ToSmiWithSaturation(Node* value,
uint32_t maxval) { uint32_t maxval) {
DCHECK(Smi::IsValid(maxval)); DCHECK(Smi::IsValid(maxval));
Node* max = Uint32Constant(maxval); Node* max = mcgraph()->Uint32Constant(maxval);
Node* check = graph()->NewNode(mcgraph()->machine()->Uint32LessThanOrEqual(), Node* check = graph()->NewNode(mcgraph()->machine()->Uint32LessThanOrEqual(),
value, max); value, max);
Node* valsmi = BuildChangeUint31ToSmi(value); Node* valsmi = BuildChangeUint31ToSmi(value);
...@@ -3619,7 +3611,7 @@ Node* WasmGraphBuilder::TableGet(uint32_t table_index, Node* index, ...@@ -3619,7 +3611,7 @@ Node* WasmGraphBuilder::TableGet(uint32_t table_index, Node* index,
return SetEffectControl(graph()->NewNode( return SetEffectControl(graph()->NewNode(
mcgraph()->common()->Call(call_descriptor), call_target, mcgraph()->common()->Call(call_descriptor), call_target,
IntPtrConstant(table_index), index, effect(), control())); mcgraph()->IntPtrConstant(table_index), index, effect(), control()));
} }
Node* WasmGraphBuilder::TableSet(uint32_t table_index, Node* index, Node* val, Node* WasmGraphBuilder::TableSet(uint32_t table_index, Node* index, Node* val,
...@@ -3633,7 +3625,7 @@ Node* WasmGraphBuilder::TableSet(uint32_t table_index, Node* index, Node* val, ...@@ -3633,7 +3625,7 @@ Node* WasmGraphBuilder::TableSet(uint32_t table_index, Node* index, Node* val,
return SetEffectControl(graph()->NewNode( return SetEffectControl(graph()->NewNode(
mcgraph()->common()->Call(call_descriptor), call_target, mcgraph()->common()->Call(call_descriptor), call_target,
IntPtrConstant(table_index), index, val, effect(), control())); mcgraph()->IntPtrConstant(table_index), index, val, effect(), control()));
} }
Node* WasmGraphBuilder::CheckBoundsAndAlignment( Node* WasmGraphBuilder::CheckBoundsAndAlignment(
...@@ -3666,8 +3658,9 @@ Node* WasmGraphBuilder::CheckBoundsAndAlignment( ...@@ -3666,8 +3658,9 @@ Node* WasmGraphBuilder::CheckBoundsAndAlignment(
Node* effective_offset = graph()->NewNode(mcgraph()->machine()->IntAdd(), Node* effective_offset = graph()->NewNode(mcgraph()->machine()->IntAdd(),
MemBuffer(capped_offset), index); MemBuffer(capped_offset), index);
Node* cond = graph()->NewNode(mcgraph()->machine()->WordAnd(), Node* cond =
effective_offset, IntPtrConstant(align_mask)); graph()->NewNode(mcgraph()->machine()->WordAnd(), effective_offset,
mcgraph()->IntPtrConstant(align_mask));
TrapIfFalse(wasm::kTrapUnalignedAccess, TrapIfFalse(wasm::kTrapUnalignedAccess,
graph()->NewNode(mcgraph()->machine()->Word32Equal(), cond, graph()->NewNode(mcgraph()->machine()->Word32Equal(), cond,
mcgraph()->Int32Constant(0)), mcgraph()->Int32Constant(0)),
...@@ -6178,9 +6171,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6178,9 +6171,9 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
wasm::ValueType type) { wasm::ValueType type) {
// Make sure ValueType fits in a Smi. // Make sure ValueType fits in a Smi.
STATIC_ASSERT(wasm::ValueType::kLastUsedBit + 1 <= kSmiValueSize); STATIC_ASSERT(wasm::ValueType::kLastUsedBit + 1 <= kSmiValueSize);
Node* inputs[] = { Node* inputs[] = {instance_node_.get(), input,
instance_node_.get(), input, mcgraph()->IntPtrConstant(
IntPtrConstant(IntToSmi(static_cast<int>(type.raw_bit_field())))}; IntToSmi(static_cast<int>(type.raw_bit_field())))};
Node* check = BuildChangeSmiToInt32(SetEffect(BuildCallToRuntimeWithContext( Node* check = BuildChangeSmiToInt32(SetEffect(BuildCallToRuntimeWithContext(
Runtime::kWasmIsValidRefValue, js_context, inputs, 3))); Runtime::kWasmIsValidRefValue, js_context, inputs, 3)));
...@@ -6358,7 +6351,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6358,7 +6351,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* BuildMultiReturnFixedArrayFromIterable(const wasm::FunctionSig* sig, Node* BuildMultiReturnFixedArrayFromIterable(const wasm::FunctionSig* sig,
Node* iterable, Node* context) { Node* iterable, Node* context) {
Node* length = BuildChangeUint31ToSmi( Node* length = BuildChangeUint31ToSmi(
Uint32Constant(static_cast<uint32_t>(sig->return_count()))); mcgraph()->Uint32Constant(static_cast<uint32_t>(sig->return_count())));
return CALL_BUILTIN(IterableToFixedArrayForWasm, iterable, length, context); return CALL_BUILTIN(IterableToFixedArrayForWasm, iterable, length, context);
} }
...@@ -6939,11 +6932,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6939,11 +6932,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
BuildModifyThreadInWasmFlag(true); BuildModifyThreadInWasmFlag(true);
Node* exception_branch = Node* exception_branch = graph()->NewNode(
graph()->NewNode(mcgraph()->common()->Branch(BranchHint::kTrue), mcgraph()->common()->Branch(BranchHint::kTrue),
graph()->NewNode(mcgraph()->machine()->WordEqual(), graph()->NewNode(mcgraph()->machine()->WordEqual(), return_value,
return_value, IntPtrConstant(0)), mcgraph()->IntPtrConstant(0)),
control()); control());
SetControl( SetControl(
graph()->NewNode(mcgraph()->common()->IfFalse(), exception_branch)); graph()->NewNode(mcgraph()->common()->IfFalse(), exception_branch));
WasmThrowDescriptor interface_descriptor; WasmThrowDescriptor interface_descriptor;
......
...@@ -206,10 +206,8 @@ class WasmGraphBuilder { ...@@ -206,10 +206,8 @@ class WasmGraphBuilder {
Node* RefNull(); Node* RefNull();
Node* RefFunc(uint32_t function_index); Node* RefFunc(uint32_t function_index);
Node* RefAsNonNull(Node* arg, wasm::WasmCodePosition position); Node* RefAsNonNull(Node* arg, wasm::WasmCodePosition position);
Node* Uint32Constant(uint32_t value);
Node* Int32Constant(int32_t value); Node* Int32Constant(int32_t value);
Node* Int64Constant(int64_t value); Node* Int64Constant(int64_t value);
Node* IntPtrConstant(intptr_t value);
Node* Float32Constant(float value); Node* Float32Constant(float value);
Node* Float64Constant(double value); Node* Float64Constant(double value);
Node* Simd128Constant(const uint8_t value[16]); Node* Simd128Constant(const uint8_t value[16]);
......
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