Commit 1010724e authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm] Use BrOrRet in Interface for conditional branches

The logic to detect if a 'br' instruction is a branch or a return was
duplicated in function-body-decoder-impl.h and in both interfaces.
Apart from code duplication, this structure also made it hard to
implement planned compiler improvements.
This CL removes this duplication by upgrading BrOrRet (that already
existed in both Liftoff and Turbofan interfaces) to an interface
function and using it for unconditional branches.

Change-Id: Ia04952cce621335268fc40ef9544a99b61dc7da3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2557515
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71400}
parent 46be2f26
......@@ -1934,8 +1934,6 @@ class LiftoffCompiler {
__ jmp(target->label.get());
}
void Br(FullDecoder* decoder, Control* target) { BrImpl(target); }
void BrOrRet(FullDecoder* decoder, uint32_t depth) {
if (depth == decoder->control_depth() - 1) {
ReturnImpl(decoder);
......
......@@ -989,7 +989,7 @@ struct ControlBase : public PcForErrors<validate> {
F(Unreachable) \
F(Select, const Value& cond, const Value& fval, const Value& tval, \
Value* result) \
F(Br, Control* target) \
F(BrOrRet, uint32_t depth) \
F(BrIf, const Value& cond, uint32_t depth) \
F(BrTable, const BranchTableImmediate<validate>& imm, const Value& key) \
F(Else, Control* if_block) \
......@@ -1098,7 +1098,9 @@ class WasmDecoder : public Decoder {
module_(module),
enabled_(enabled),
detected_(detected),
sig_(sig) {}
sig_(sig) {
if (sig_ && sig_->return_count() > 1) detected_->Add(kFeature_mv);
}
Zone* zone() const { return local_types_.get_allocator().zone(); }
......@@ -2630,12 +2632,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
Control* c = control_at(imm.depth);
TypeCheckBranchResult check_result = TypeCheckBranch(c, false);
if (V8_LIKELY(check_result == kReachableBranch)) {
if (imm.depth == control_.size() - 1) {
DoReturn();
} else {
CALL_INTERFACE(Br, c);
c->br_merge()->reached = true;
}
CALL_INTERFACE(BrOrRet, imm.depth);
c->br_merge()->reached = true;
} else if (check_result == kInvalidStack) {
return 0;
}
......@@ -4249,9 +4247,6 @@ class WasmFullDecoder : public WasmDecoder<validate> {
void DoReturn() {
size_t return_count = this->sig_->return_count();
if (return_count > 1) {
this->detected_->Add(kFeature_mv);
}
DCHECK_GE(stack_size(), return_count);
Vector<Value> return_values =
Vector<Value>{stack_end_ - return_count, return_count};
......
......@@ -362,16 +362,16 @@ class WasmGraphBuildingInterface {
if (ret_count > 0) {
GetNodes(values.begin(), decoder->stack_value(ret_count), ret_count);
}
if (FLAG_trace_wasm) {
BUILD(TraceFunctionExit, VectorOf(values), decoder->position());
}
BUILD(Return, VectorOf(values));
} else {
Br(decoder, decoder->control_at(depth));
Control* target = decoder->control_at(depth);
MergeValuesInto(decoder, target, target->br_merge());
}
}
void Br(FullDecoder* decoder, Control* target) {
MergeValuesInto(decoder, target, target->br_merge());
}
void BrIf(FullDecoder* decoder, const Value& cond, uint32_t depth) {
SsaEnv* fenv = ssa_env_;
SsaEnv* tenv = Split(decoder->zone(), fenv);
......
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