Commit 95db83b6 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Consistently use "branch" instead of "break"

In most places we already call them "branches", and the spec also only
uses this name. Hence remove the remaining mentions of "break".

R=titzer@chromium.org

Bug: v8:8562
Change-Id: I64ac39324681b8214cd2e68315eb86a69d85cba8
Reviewed-on: https://chromium-review.googlesource.com/c/1371567Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58153}
parent 2b92afd0
......@@ -288,11 +288,11 @@ struct BlockTypeImmediate {
};
template <Decoder::ValidateFlag validate>
struct BreakDepthImmediate {
struct BranchDepthImmediate {
uint32_t depth;
uint32_t length;
inline BreakDepthImmediate(Decoder* decoder, const byte* pc) {
depth = decoder->read_u32v<validate>(pc + 1, &length, "break depth");
inline BranchDepthImmediate(Decoder* decoder, const byte* pc) {
depth = decoder->read_u32v<validate>(pc + 1, &length, "branch depth");
}
};
......@@ -957,10 +957,10 @@ class WasmDecoder : public Decoder {
return true;
}
inline bool Validate(const byte* pc, BreakDepthImmediate<validate>& imm,
inline bool Validate(const byte* pc, BranchDepthImmediate<validate>& imm,
size_t control_depth) {
if (!VALIDATE(imm.depth < control_depth)) {
errorf(pc + 1, "invalid break depth: %u", imm.depth);
errorf(pc + 1, "invalid branch depth: %u", imm.depth);
return false;
}
return true;
......@@ -1139,7 +1139,7 @@ class WasmDecoder : public Decoder {
case kExprRethrow:
case kExprBr:
case kExprBrIf: {
BreakDepthImmediate<validate> imm(decoder, pc);
BranchDepthImmediate<validate> imm(decoder, pc);
return 1 + imm.length;
}
case kExprSetGlobal:
......@@ -1634,7 +1634,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
case kExprRethrow: {
CHECK_PROTOTYPE_OPCODE(eh);
BreakDepthImmediate<validate> imm(this, this->pc_);
BranchDepthImmediate<validate> imm(this, this->pc_);
if (!this->Validate(this->pc_, imm, control_.size())) break;
Control* c = control_at(imm.depth);
if (!VALIDATE(c->is_try_catchall() || c->is_try_catch())) {
......@@ -1824,10 +1824,10 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
}
case kExprBr: {
BreakDepthImmediate<validate> imm(this, this->pc_);
BranchDepthImmediate<validate> imm(this, this->pc_);
if (!this->Validate(this->pc_, imm, control_.size())) break;
Control* c = control_at(imm.depth);
if (!TypeCheckBreak(c)) break;
if (!TypeCheckBranch(c)) break;
if (imm.depth == control_.size() - 1) {
DoReturn();
} else if (control_.back().reachable()) {
......@@ -1839,12 +1839,12 @@ class WasmFullDecoder : public WasmDecoder<validate> {
break;
}
case kExprBrIf: {
BreakDepthImmediate<validate> imm(this, this->pc_);
BranchDepthImmediate<validate> imm(this, this->pc_);
auto cond = Pop(0, kWasmI32);
if (this->failed()) break;
if (!this->Validate(this->pc_, imm, control_.size())) break;
Control* c = control_at(imm.depth);
if (!TypeCheckBreak(c)) break;
if (!TypeCheckBranch(c)) break;
if (control_.back().reachable()) {
CALL_INTERFACE(BrIf, cond, imm.depth);
c->br_merge()->reached = true;
......@@ -1870,7 +1870,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
i, target);
break;
}
// Avoid redundant break target checks.
// Avoid redundant branch target checks.
if (br_targets[target]) continue;
br_targets[target] = true;
// Check that label types match up.
......@@ -1884,7 +1884,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
" (previous was %u, this one %u)",
i, br_arity, arity);
}
if (!TypeCheckBreak(c)) break;
if (!TypeCheckBranch(c)) break;
}
if (this->failed()) break;
......@@ -2698,8 +2698,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
return TypeCheckMergeValues(c, &c->end_merge);
}
bool TypeCheckBreak(Control* c) {
// Breaks must have at least the number of values expected; can have more.
bool TypeCheckBranch(Control* c) {
// Branches must have at least the number of values expected; can have more.
uint32_t expected = c->br_merge()->arity;
if (expected == 0) return true; // Fast path.
DCHECK_GE(stack_.size(), control_.back().stack_depth);
......
......@@ -215,12 +215,12 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
control_depth--;
break;
case kExprBr: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
os << " // depth=" << imm.depth;
break;
}
case kExprBrIf: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
os << " // depth=" << imm.depth;
break;
}
......
......@@ -132,9 +132,9 @@ class WasmGraphBuildingInterface {
}
void StartFunctionBody(FullDecoder* decoder, Control* block) {
SsaEnv* break_env = ssa_env_;
SetEnv(Steal(decoder->zone(), break_env));
block->end_env = break_env;
SsaEnv* branch_env = ssa_env_;
SetEnv(Steal(decoder->zone(), branch_env));
block->end_env = branch_env;
}
void FinishFunction(FullDecoder*) { builder_->PatchInStackCheckIfNeeded(); }
......@@ -144,7 +144,7 @@ class WasmGraphBuildingInterface {
void NextInstruction(FullDecoder*, WasmOpcode) {}
void Block(FullDecoder* decoder, Control* block) {
// The break environment is the outer environment.
// The branch environment is the outer environment.
block->end_env = ssa_env_;
SetEnv(Steal(decoder->zone(), ssa_env_));
}
......@@ -327,11 +327,11 @@ class WasmGraphBuildingInterface {
return;
}
SsaEnv* break_env = ssa_env_;
SsaEnv* branch_env = ssa_env_;
// Build branches to the various blocks based on the table.
TFNode* sw = BUILD(Switch, imm.table_count + 1, key.node);
SsaEnv* copy = Steal(decoder->zone(), break_env);
SsaEnv* copy = Steal(decoder->zone(), branch_env);
SetEnv(copy);
BranchTableIterator<validate> iterator(decoder, imm);
while (iterator.has_next()) {
......@@ -343,7 +343,7 @@ class WasmGraphBuildingInterface {
BrOrRet(decoder, target);
}
DCHECK(decoder->ok());
SetEnv(break_env);
SetEnv(branch_env);
}
void Else(FullDecoder* decoder, Control* if_block) {
......
......@@ -858,14 +858,14 @@ class SideTable : public ZoneObject {
break;
}
case kExprBr: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
TRACE("control @%u: Br[depth=%u]\n", i.pc_offset(), imm.depth);
Control* c = &control_stack[control_stack.size() - imm.depth - 1];
if (!unreachable) c->end_label->Ref(i.pc(), stack_height);
break;
}
case kExprBrIf: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
TRACE("control @%u: BrIf[depth=%u]\n", i.pc_offset(), imm.depth);
Control* c = &control_stack[control_stack.size() - imm.depth - 1];
if (!unreachable) c->end_label->Ref(i.pc(), stack_height);
......@@ -2191,13 +2191,15 @@ class ThreadImpl {
break;
}
case kExprBr: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&decoder, code->at(pc));
BranchDepthImmediate<Decoder::kNoValidate> imm(&decoder,
code->at(pc));
len = DoBreak(code, pc, imm.depth);
TRACE(" br => @%zu\n", pc + len);
break;
}
case kExprBrIf: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&decoder, code->at(pc));
BranchDepthImmediate<Decoder::kNoValidate> imm(&decoder,
code->at(pc));
WasmValue cond = Pop();
bool is_true = cond.to<uint32_t>() != 0;
if (is_true) {
......
......@@ -113,7 +113,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
}
case kExprBr:
case kExprBrIf: {
BreakDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
BranchDepthImmediate<Decoder::kNoValidate> imm(&i, i.pc());
os << WasmOpcodes::OpcodeName(opcode) << ' ' << imm.depth;
break;
}
......
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