Commit 58f1b315 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm][cleanup] Use Vector<Node*> instead of Node** more.

R=clemensh@chromium.org
BUG=v8:9396

Change-Id: Ic1c49aed8110b982ca793ba5ee94d5135619c2fa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1722567Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62954}
parent ba77172b
This diff is collapsed.
...@@ -186,14 +186,14 @@ class WasmGraphBuilder { ...@@ -186,14 +186,14 @@ class WasmGraphBuilder {
wasm::CompilationEnv* env, Zone* zone, MachineGraph* mcgraph, wasm::CompilationEnv* env, Zone* zone, MachineGraph* mcgraph,
wasm::FunctionSig* sig, compiler::SourcePositionTable* spt = nullptr); wasm::FunctionSig* sig, compiler::SourcePositionTable* spt = nullptr);
Node** Buffer(size_t count) { Vector<Node*> Buffer(size_t count) {
if (count > cur_bufsize_) { if (count > cur_bufsize_) {
size_t new_size = count + cur_bufsize_ + 5; size_t new_size = count + cur_bufsize_ + 5;
cur_buffer_ = cur_buffer_ =
reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*))); reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*)));
cur_bufsize_ = new_size; cur_bufsize_ = new_size;
} }
return cur_buffer_; return {cur_buffer_, count};
} }
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
...@@ -230,7 +230,7 @@ class WasmGraphBuilder { ...@@ -230,7 +230,7 @@ class WasmGraphBuilder {
Node* ExceptionTagEqual(Node* caught_tag, Node* expected_tag); Node* ExceptionTagEqual(Node* caught_tag, Node* expected_tag);
Node* LoadExceptionTagFromTable(uint32_t exception_index); Node* LoadExceptionTagFromTable(uint32_t exception_index);
Node* GetExceptionTag(Node* except_obj); Node* GetExceptionTag(Node* except_obj);
Node** GetExceptionValues(Node* except_obj, Vector<Node*> GetExceptionValues(Node* except_obj,
const wasm::WasmException* exception); const wasm::WasmException* exception);
bool IsPhiWithMerge(Node* phi, Node* merge); bool IsPhiWithMerge(Node* phi, Node* merge);
bool ThrowsException(Node* node, Node** if_success, Node** if_exception); bool ThrowsException(Node* node, Node** if_success, Node** if_exception);
...@@ -274,11 +274,11 @@ class WasmGraphBuilder { ...@@ -274,11 +274,11 @@ class WasmGraphBuilder {
Node* Switch(unsigned count, Node* key); Node* Switch(unsigned count, Node* key);
Node* IfValue(int32_t value, Node* sw); Node* IfValue(int32_t value, Node* sw);
Node* IfDefault(Node* sw); Node* IfDefault(Node* sw);
Node* Return(unsigned count, Node** nodes); Node* Return(Vector<Node*> nodes);
template <typename... Nodes> template <typename... Nodes>
Node* Return(Node* fst, Nodes*... more) { Node* Return(Node* fst, Nodes*... more) {
Node* arr[] = {fst, more...}; Node* arr[] = {fst, more...};
return Return(arraysize(arr), arr); return Return(ArrayVector(arr));
} }
Node* ReturnVoid(); Node* ReturnVoid();
Node* Unreachable(wasm::WasmCodePosition position); Node* Unreachable(wasm::WasmCodePosition position);
...@@ -606,9 +606,13 @@ class WasmGraphBuilder { ...@@ -606,9 +606,13 @@ class WasmGraphBuilder {
Node* BuildDecodeException32BitValue(Node* values_array, uint32_t* index); Node* BuildDecodeException32BitValue(Node* values_array, uint32_t* index);
Node* BuildDecodeException64BitValue(Node* values_array, uint32_t* index); Node* BuildDecodeException64BitValue(Node* values_array, uint32_t* index);
Node** Realloc(Node* const* buffer, size_t old_count, size_t new_count) { Vector<Node*> Realloc(Node* const* buffer, size_t old_count,
Node** buf = Buffer(new_count); size_t new_count) {
if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); 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; return buf;
} }
......
...@@ -258,8 +258,8 @@ class WasmGraphBuildingInterface { ...@@ -258,8 +258,8 @@ class WasmGraphBuildingInterface {
void Drop(FullDecoder* decoder, const Value& value) {} void Drop(FullDecoder* decoder, const Value& value) {}
void DoReturn(FullDecoder* decoder, Vector<Value> values) { void DoReturn(FullDecoder* decoder, Vector<Value> values) {
TFNode** nodes = GetNodes(values); Vector<TFNode*> nodes = GetNodes(values);
BUILD(Return, static_cast<uint32_t>(values.size()), nodes); BUILD(Return, nodes);
} }
void GetLocal(FullDecoder* decoder, Value* result, void GetLocal(FullDecoder* decoder, Value* result,
...@@ -319,10 +319,10 @@ class WasmGraphBuildingInterface { ...@@ -319,10 +319,10 @@ class WasmGraphBuildingInterface {
void BrOrRet(FullDecoder* decoder, uint32_t depth) { void BrOrRet(FullDecoder* decoder, uint32_t depth) {
if (depth == decoder->control_depth() - 1) { if (depth == decoder->control_depth() - 1) {
uint32_t ret_count = static_cast<uint32_t>(decoder->sig_->return_count()); uint32_t ret_count = static_cast<uint32_t>(decoder->sig_->return_count());
TFNode** values = Vector<TFNode*> values =
ret_count == 0 ? nullptr ret_count == 0 ? Vector<TFNode*>{}
: GetNodes(decoder->stack_value(ret_count), ret_count); : GetNodes(decoder->stack_value(ret_count), ret_count);
BUILD(Return, ret_count, values); BUILD(Return, values);
} else { } else {
Br(decoder, decoder->control_at(depth)); Br(decoder, decoder->control_at(depth));
} }
...@@ -431,16 +431,16 @@ class WasmGraphBuildingInterface { ...@@ -431,16 +431,16 @@ class WasmGraphBuildingInterface {
void SimdOp(FullDecoder* decoder, WasmOpcode opcode, Vector<Value> args, void SimdOp(FullDecoder* decoder, WasmOpcode opcode, Vector<Value> args,
Value* result) { Value* result) {
TFNode** inputs = GetNodes(args); Vector<TFNode*> inputs = GetNodes(args);
TFNode* node = BUILD(SimdOp, opcode, inputs); TFNode* node = BUILD(SimdOp, opcode, inputs.begin());
if (result) result->node = node; if (result) result->node = node;
} }
void SimdLaneOp(FullDecoder* decoder, WasmOpcode opcode, void SimdLaneOp(FullDecoder* decoder, WasmOpcode opcode,
const SimdLaneImmediate<validate> imm, Vector<Value> inputs, const SimdLaneImmediate<validate> imm, Vector<Value> inputs,
Value* result) { Value* result) {
TFNode** nodes = GetNodes(inputs); Vector<TFNode*> nodes = GetNodes(inputs);
result->node = BUILD(SimdLaneOp, opcode, imm.lane, nodes); result->node = BUILD(SimdLaneOp, opcode, imm.lane, nodes.begin());
} }
void SimdShiftOp(FullDecoder* decoder, WasmOpcode opcode, void SimdShiftOp(FullDecoder* decoder, WasmOpcode opcode,
...@@ -495,7 +495,7 @@ class WasmGraphBuildingInterface { ...@@ -495,7 +495,7 @@ class WasmGraphBuildingInterface {
SetEnv(if_match_env); SetEnv(if_match_env);
// TODO(mstarzinger): Can't use BUILD() here, GetExceptionValues() returns // TODO(mstarzinger): Can't use BUILD() here, GetExceptionValues() returns
// TFNode** rather than TFNode*. Fix to add landing pads. // TFNode** rather than TFNode*. Fix to add landing pads.
TFNode** caught_values = Vector<TFNode*> caught_values =
builder_->GetExceptionValues(exception.node, imm.exception); builder_->GetExceptionValues(exception.node, imm.exception);
for (size_t i = 0, e = values.size(); i < e; ++i) { for (size_t i = 0, e = values.size(); i < e; ++i) {
values[i].node = caught_values[i]; values[i].node = caught_values[i];
...@@ -526,9 +526,9 @@ class WasmGraphBuildingInterface { ...@@ -526,9 +526,9 @@ class WasmGraphBuildingInterface {
void AtomicOp(FullDecoder* decoder, WasmOpcode opcode, Vector<Value> args, void AtomicOp(FullDecoder* decoder, WasmOpcode opcode, Vector<Value> args,
const MemoryAccessImmediate<validate>& imm, Value* result) { const MemoryAccessImmediate<validate>& imm, Value* result) {
TFNode** inputs = GetNodes(args); Vector<TFNode*> inputs = GetNodes(args);
TFNode* node = BUILD(AtomicOp, opcode, inputs, imm.alignment, imm.offset, TFNode* node = BUILD(AtomicOp, opcode, inputs.begin(), imm.alignment,
decoder->position()); imm.offset, decoder->position());
if (result) result->node = node; if (result) result->node = node;
} }
...@@ -598,15 +598,15 @@ class WasmGraphBuildingInterface { ...@@ -598,15 +598,15 @@ class WasmGraphBuildingInterface {
->try_info; ->try_info;
} }
TFNode** GetNodes(Value* values, size_t count) { Vector<TFNode*> GetNodes(Value* values, size_t count) {
TFNode** nodes = builder_->Buffer(count); Vector<TFNode*> nodes = builder_->Buffer(count);
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
nodes[i] = values[i].node; nodes[i] = values[i].node;
} }
return nodes; return nodes;
} }
TFNode** GetNodes(Vector<Value> values) { Vector<TFNode*> GetNodes(Vector<Value> values) {
return GetNodes(values.begin(), values.size()); return GetNodes(values.begin(), values.size());
} }
...@@ -885,17 +885,17 @@ class WasmGraphBuildingInterface { ...@@ -885,17 +885,17 @@ class WasmGraphBuildingInterface {
FunctionSig* sig, uint32_t sig_index, const Value args[], FunctionSig* sig, uint32_t sig_index, const Value args[],
Value returns[]) { Value returns[]) {
int param_count = static_cast<int>(sig->parameter_count()); int param_count = static_cast<int>(sig->parameter_count());
TFNode** arg_nodes = builder_->Buffer(param_count + 1); Vector<TFNode*> arg_nodes = builder_->Buffer(param_count + 1);
TFNode** return_nodes = nullptr; TFNode** return_nodes = nullptr;
arg_nodes[0] = index_node; arg_nodes[0] = index_node;
for (int i = 0; i < param_count; ++i) { for (int i = 0; i < param_count; ++i) {
arg_nodes[i + 1] = args[i].node; arg_nodes[i + 1] = args[i].node;
} }
if (index_node) { if (index_node) {
BUILD(CallIndirect, table_index, sig_index, arg_nodes, &return_nodes, BUILD(CallIndirect, table_index, sig_index, arg_nodes.begin(),
decoder->position()); &return_nodes, decoder->position());
} else { } else {
BUILD(CallDirect, sig_index, arg_nodes, &return_nodes, BUILD(CallDirect, sig_index, arg_nodes.begin(), &return_nodes,
decoder->position()); decoder->position());
} }
int return_count = static_cast<int>(sig->return_count()); int return_count = static_cast<int>(sig->return_count());
...@@ -911,16 +911,16 @@ class WasmGraphBuildingInterface { ...@@ -911,16 +911,16 @@ class WasmGraphBuildingInterface {
TFNode* index_node, FunctionSig* sig, uint32_t sig_index, TFNode* index_node, FunctionSig* sig, uint32_t sig_index,
const Value args[]) { const Value args[]) {
int arg_count = static_cast<int>(sig->parameter_count()); int arg_count = static_cast<int>(sig->parameter_count());
TFNode** arg_nodes = builder_->Buffer(arg_count + 1); Vector<TFNode*> arg_nodes = builder_->Buffer(arg_count + 1);
arg_nodes[0] = index_node; arg_nodes[0] = index_node;
for (int i = 0; i < arg_count; ++i) { for (int i = 0; i < arg_count; ++i) {
arg_nodes[i + 1] = args[i].node; arg_nodes[i + 1] = args[i].node;
} }
if (index_node) { if (index_node) {
BUILD(ReturnCallIndirect, table_index, sig_index, arg_nodes, BUILD(ReturnCallIndirect, table_index, sig_index, arg_nodes.begin(),
decoder->position()); decoder->position());
} else { } else {
BUILD(ReturnCall, sig_index, arg_nodes, decoder->position()); BUILD(ReturnCall, sig_index, arg_nodes.begin(), 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