Commit 087847d9 authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Properly terminate throwing control edges.

This merges all control edges that are known to unconditionally throw
directly into the graph end node. This applies to the "Throw" as well as
the "Rethrow" operation, and reduces their code size.

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

Change-Id: Idd4918ab084bcc697d5798d512ccc695ca943b00
Reviewed-on: https://chromium-review.googlesource.com/c/1305273Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57119}
parent 59c324a0
...@@ -176,13 +176,20 @@ Node* WasmGraphBuilder::Loop(Node* entry) { ...@@ -176,13 +176,20 @@ Node* WasmGraphBuilder::Loop(Node* entry) {
return graph()->NewNode(mcgraph()->common()->Loop(1), entry); return graph()->NewNode(mcgraph()->common()->Loop(1), entry);
} }
Node* WasmGraphBuilder::Terminate(Node* effect, Node* control) { Node* WasmGraphBuilder::TerminateLoop(Node* effect, Node* control) {
Node* terminate = Node* terminate =
graph()->NewNode(mcgraph()->common()->Terminate(), effect, control); graph()->NewNode(mcgraph()->common()->Terminate(), effect, control);
MergeControlToEnd(mcgraph(), terminate); MergeControlToEnd(mcgraph(), terminate);
return terminate; return terminate;
} }
Node* WasmGraphBuilder::TerminateThrow(Node* effect, Node* control) {
Node* terminate =
graph()->NewNode(mcgraph()->common()->Throw(), effect, control);
MergeControlToEnd(mcgraph(), terminate);
return terminate;
}
bool WasmGraphBuilder::IsPhiWithMerge(Node* phi, Node* merge) { bool WasmGraphBuilder::IsPhiWithMerge(Node* phi, Node* merge) {
return phi && IrOpcode::IsPhiOpcode(phi->opcode()) && return phi && IrOpcode::IsPhiOpcode(phi->opcode()) &&
NodeProperties::GetControlInput(phi) == merge; NodeProperties::GetControlInput(phi) == merge;
......
...@@ -159,7 +159,8 @@ class WasmGraphBuilder { ...@@ -159,7 +159,8 @@ class WasmGraphBuilder {
Node* Start(unsigned params); Node* Start(unsigned params);
Node* Param(unsigned index); Node* Param(unsigned index);
Node* Loop(Node* entry); Node* Loop(Node* entry);
Node* Terminate(Node* effect, Node* control); Node* TerminateLoop(Node* effect, Node* control);
Node* TerminateThrow(Node* effect, Node* control);
Node* Merge(unsigned count, Node** controls); Node* Merge(unsigned count, Node** controls);
Node* Phi(wasm::ValueType type, unsigned count, Node** vals, Node* control); Node* Phi(wasm::ValueType type, unsigned count, Node** vals, Node* control);
Node* CreateOrMergeIntoPhi(MachineRepresentation rep, Node* merge, Node* CreateOrMergeIntoPhi(MachineRepresentation rep, Node* merge,
......
...@@ -415,14 +415,14 @@ class WasmGraphBuildingInterface { ...@@ -415,14 +415,14 @@ class WasmGraphBuildingInterface {
args[i] = value_args[i].node; args[i] = value_args[i].node;
} }
BUILD(Throw, imm.index, imm.exception, vec2vec(args)); BUILD(Throw, imm.index, imm.exception, vec2vec(args));
Unreachable(decoder); builder_->TerminateThrow(ssa_env_->effect, ssa_env_->control);
} }
void Rethrow(FullDecoder* decoder, Control* block) { void Rethrow(FullDecoder* decoder, Control* block) {
DCHECK(block->is_try_catchall() || block->is_try_catch()); DCHECK(block->is_try_catchall() || block->is_try_catch());
TFNode* exception = block->try_info->exception; TFNode* exception = block->try_info->exception;
BUILD(Rethrow, exception); BUILD(Rethrow, exception);
Unreachable(decoder); builder_->TerminateThrow(ssa_env_->effect, ssa_env_->control);
} }
void CatchException(FullDecoder* decoder, void CatchException(FullDecoder* decoder,
...@@ -700,7 +700,7 @@ class WasmGraphBuildingInterface { ...@@ -700,7 +700,7 @@ class WasmGraphBuildingInterface {
env->control = builder_->Loop(env->control); env->control = builder_->Loop(env->control);
env->effect = builder_->EffectPhi(1, &env->effect, env->control); env->effect = builder_->EffectPhi(1, &env->effect, env->control);
builder_->Terminate(env->effect, env->control); builder_->TerminateLoop(env->effect, env->control);
// The '+ 1' here is to be able to set the instance cache as assigned. // The '+ 1' here is to be able to set the instance cache as assigned.
BitVector* assigned = WasmDecoder<validate>::AnalyzeLoopAssignment( BitVector* assigned = WasmDecoder<validate>::AnalyzeLoopAssignment(
decoder, decoder->pc(), decoder->total_locals() + 1, decoder->zone()); decoder, decoder->pc(), decoder->total_locals() + 1, decoder->zone());
......
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