Bug 1401675 - Baldr: simplify how function bodies end (r=lth)

--HG--
extra : rebase_source : 419677654d23ba47ba7ce26472cab50826586850
This commit is contained in:
Luke Wagner 2019-02-19 14:28:06 -06:00
parent 4ad201c574
commit df3ea1382b
3 changed files with 25 additions and 15 deletions

View File

@ -8395,6 +8395,12 @@ bool BaseCompiler::emitEnd() {
}
switch (kind) {
case LabelKind::Body:
endBlock(type);
iter_.popEnd();
MOZ_ASSERT(iter_.controlStackEmpty());
doReturn(type, PopStack(false));
return iter_.readFunctionEnd(iter_.end());
case LabelKind::Block:
endBlock(type);
break;
@ -8558,6 +8564,9 @@ bool BaseCompiler::emitDrop() {
}
void BaseCompiler::doReturn(ExprType type, bool popStack) {
if (deadCode_) {
return;
}
switch (type.code()) {
case ExprType::Void: {
returnCleanup(popStack);
@ -10944,12 +10953,8 @@ bool BaseCompiler::emitBody() {
if (!emitEnd()) {
return false;
}
if (iter_.controlStackEmpty()) {
if (!deadCode_) {
doReturn(funcType().ret(), PopStack(false));
}
return iter_.readFunctionEnd(iter_.end());
return true;
}
NEXT();

View File

@ -1784,6 +1784,17 @@ static bool EmitEnd(FunctionCompiler& f) {
MDefinition* def = nullptr;
switch (kind) {
case LabelKind::Body:
MOZ_ASSERT(f.iter().controlStackEmpty());
if (!f.finishBlock(&def)) {
return false;
}
if (f.inDeadCode() || IsVoid(type)) {
f.returnVoid();
} else {
f.returnExpr(def);
}
return f.iter().readFunctionEnd(f.iter().end());
case LabelKind::Block:
if (!f.finishBlock(&def)) {
return false;
@ -3109,14 +3120,8 @@ static bool EmitBodyExprs(FunctionCompiler& f) {
if (!EmitEnd(f)) {
return false;
}
if (f.iter().controlStackEmpty()) {
if (f.inDeadCode() || IsVoid(f.funcType().ret())) {
f.returnVoid();
} else {
f.returnExpr(f.iter().getResult());
}
return f.iter().readFunctionEnd(f.iter().end());
return true;
}
break;

View File

@ -30,7 +30,7 @@ namespace js {
namespace wasm {
// The kind of a control-flow stack item.
enum class LabelKind : uint8_t { Block, Loop, Then, Else };
enum class LabelKind : uint8_t { Body, Block, Loop, Then, Else };
// The type of values on the operand stack during validation. The Any type
// represents the type of a value produced by an unconditional branch.
@ -815,7 +815,7 @@ inline bool OpIter<Policy>::readFunctionStart(ExprType ret) {
MOZ_ASSERT(controlStack_.empty());
MOZ_ASSERT(op_.b0 == uint16_t(Op::Limit));
return pushControl(LabelKind::Block, ret);
return pushControl(LabelKind::Body, ret);
}
template <typename Policy>
@ -840,7 +840,7 @@ inline bool OpIter<Policy>::readReturn(Value* value) {
MOZ_ASSERT(Classify(op_) == OpKind::Return);
ControlStackEntry<ControlItem>& body = controlStack_[0];
MOZ_ASSERT(body.kind() == LabelKind::Block);
MOZ_ASSERT(body.kind() == LabelKind::Body);
if (!popWithType(body.resultType(), value)) {
return false;