Commit c79af355 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Use {SmallVector} for call arguments and returns.

This switches the {WasmGraphBuilder} to use {SmallVector} for passing
argument and return values. It deprecates {WasmGraphBuilder::Buffer},
which is a dangerous construct as it makes it easy to accidentally use
the single buffer for two vectors at the same time. This also removes
the by now unused {WasmGraphBuilder::Realloc} method.

R=clemensb@chromium.org

Change-Id: I6bd9be437a99c23bb403a046a75c148ac4a14451
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1859619Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64277}
parent b67f096e
This diff is collapsed.
......@@ -19,6 +19,12 @@
#include "src/zone/zone.h"
namespace v8 {
namespace base {
template <typename T, size_t kSize>
class SmallVector;
} // namespace base
namespace internal {
struct AssemblerOptions;
class OptimizedCompilationJob;
......@@ -179,6 +185,7 @@ class WasmGraphBuilder {
wasm::CompilationEnv* env, Zone* zone, MachineGraph* mcgraph,
wasm::FunctionSig* sig, compiler::SourcePositionTable* spt = nullptr);
// TODO(mstarzinger): Remove this deprecated buffer.
Vector<Node*> Buffer(size_t count) {
if (count > cur_bufsize_) {
size_t new_size = count + cur_bufsize_ + 5;
......@@ -276,15 +283,16 @@ class WasmGraphBuilder {
}
Node* Unreachable(wasm::WasmCodePosition position);
Node* CallDirect(uint32_t index, Node** args, Node*** rets,
Node* CallDirect(uint32_t index, Vector<Node*> args, Vector<Node*> rets,
wasm::WasmCodePosition position);
Node* CallIndirect(uint32_t table_index, uint32_t sig_index, Node** args,
Node*** rets, wasm::WasmCodePosition position);
Node* CallIndirect(uint32_t table_index, uint32_t sig_index,
Vector<Node*> args, Vector<Node*> rets,
wasm::WasmCodePosition position);
Node* ReturnCall(uint32_t index, Node** args,
Node* ReturnCall(uint32_t index, Vector<Node*> args,
wasm::WasmCodePosition position);
Node* ReturnCallIndirect(uint32_t table_index, uint32_t sig_index,
Node** args, wasm::WasmCodePosition position);
Vector<Node*> args, wasm::WasmCodePosition position);
Node* Invert(Node* node);
......@@ -497,28 +505,29 @@ class WasmGraphBuilder {
template <typename... Args>
Node* BuildCCall(MachineSignature* sig, Node* function, Args... args);
Node* BuildCallNode(wasm::FunctionSig* sig, Node** args,
Node* BuildCallNode(wasm::FunctionSig* sig, Vector<Node*> args,
wasm::WasmCodePosition position, Node* instance_node,
const Operator* op);
// Helper function for {BuildIndirectCall}.
void LoadIndirectFunctionTable(uint32_t table_index, Node** ift_size,
Node** ift_sig_ids, Node** ift_targets,
Node** ift_instances);
Node* BuildIndirectCall(uint32_t table_index, uint32_t sig_index, Node** args,
Node*** rets, wasm::WasmCodePosition position,
Node* BuildIndirectCall(uint32_t table_index, uint32_t sig_index,
Vector<Node*> args, Vector<Node*> rets,
wasm::WasmCodePosition position,
IsReturnCall continuation);
Node* BuildWasmCall(wasm::FunctionSig* sig, Node** args, Node*** rets,
wasm::WasmCodePosition position, Node* instance_node,
UseRetpoline use_retpoline);
Node* BuildWasmReturnCall(wasm::FunctionSig* sig, Node** args,
Node* BuildWasmCall(wasm::FunctionSig* sig, Vector<Node*> args,
Vector<Node*> rets, wasm::WasmCodePosition position,
Node* instance_node, UseRetpoline use_retpoline);
Node* BuildWasmReturnCall(wasm::FunctionSig* sig, Vector<Node*> args,
wasm::WasmCodePosition position,
Node* instance_node, UseRetpoline use_retpoline);
Node* BuildImportCall(wasm::FunctionSig* sig, Node** args, Node*** rets,
wasm::WasmCodePosition position, int func_index,
IsReturnCall continuation);
Node* BuildImportCall(wasm::FunctionSig* sig, Node** args, Node*** rets,
wasm::WasmCodePosition position, Node* func_index,
IsReturnCall continuation);
Node* BuildImportCall(wasm::FunctionSig* sig, Vector<Node*> args,
Vector<Node*> rets, wasm::WasmCodePosition position,
int func_index, IsReturnCall continuation);
Node* BuildImportCall(wasm::FunctionSig* sig, Vector<Node*> args,
Vector<Node*> rets, wasm::WasmCodePosition position,
Node* func_index, IsReturnCall continuation);
Node* BuildF32CopySign(Node* left, Node* right);
Node* BuildF64CopySign(Node* left, Node* right);
......@@ -606,16 +615,6 @@ class WasmGraphBuilder {
Node* BuildMultiReturnFixedArrayFromIterable(const wasm::FunctionSig* sig,
Node* iterable, Node* context);
Vector<Node*> Realloc(Node* const* buffer, size_t old_count,
size_t new_count) {
DCHECK_GE(new_count, old_count); // Only support growing.
Vector<Node*> buf = Buffer(new_count);
if (buf.begin() != buffer) {
memcpy(buf.begin(), buffer, old_count * sizeof(Node*));
}
return buf;
}
//-----------------------------------------------------------------------
// Operations involving the CEntry, a dependency we want to remove
// to get off the GC heap.
......
......@@ -887,22 +887,22 @@ class WasmGraphBuildingInterface {
void DoCall(FullDecoder* decoder, uint32_t table_index, TFNode* index_node,
FunctionSig* sig, uint32_t sig_index, const Value args[],
Value returns[]) {
int param_count = static_cast<int>(sig->parameter_count());
Vector<TFNode*> arg_nodes = builder_->Buffer(param_count + 1);
TFNode** return_nodes = nullptr;
size_t param_count = sig->parameter_count();
size_t return_count = sig->return_count();
base::SmallVector<TFNode*, 16> arg_nodes(param_count + 1);
base::SmallVector<TFNode*, 1> return_nodes(return_count);
arg_nodes[0] = index_node;
for (int i = 0; i < param_count; ++i) {
for (size_t i = 0; i < param_count; ++i) {
arg_nodes[i + 1] = args[i].node;
}
if (index_node) {
BUILD(CallIndirect, table_index, sig_index, arg_nodes.begin(),
&return_nodes, decoder->position());
BUILD(CallIndirect, table_index, sig_index, VectorOf(arg_nodes),
VectorOf(return_nodes), decoder->position());
} else {
BUILD(CallDirect, sig_index, arg_nodes.begin(), &return_nodes,
BUILD(CallDirect, sig_index, VectorOf(arg_nodes), VectorOf(return_nodes),
decoder->position());
}
int return_count = static_cast<int>(sig->return_count());
for (int i = 0; i < return_count; ++i) {
for (size_t i = 0; i < return_count; ++i) {
returns[i].node = return_nodes[i];
}
// The invoked function could have used grow_memory, so we need to
......@@ -913,17 +913,17 @@ class WasmGraphBuildingInterface {
void DoReturnCall(FullDecoder* decoder, uint32_t table_index,
TFNode* index_node, FunctionSig* sig, uint32_t sig_index,
const Value args[]) {
int arg_count = static_cast<int>(sig->parameter_count());
Vector<TFNode*> arg_nodes = builder_->Buffer(arg_count + 1);
size_t arg_count = sig->parameter_count();
base::SmallVector<TFNode*, 16> arg_nodes(arg_count + 1);
arg_nodes[0] = index_node;
for (int i = 0; i < arg_count; ++i) {
for (size_t i = 0; i < arg_count; ++i) {
arg_nodes[i + 1] = args[i].node;
}
if (index_node) {
BUILD(ReturnCallIndirect, table_index, sig_index, arg_nodes.begin(),
BUILD(ReturnCallIndirect, table_index, sig_index, VectorOf(arg_nodes),
decoder->position());
} else {
BUILD(ReturnCall, sig_index, arg_nodes.begin(), decoder->position());
BUILD(ReturnCall, sig_index, VectorOf(arg_nodes), decoder->position());
}
}
};
......
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