Bug 1461888 - Remove trueEnd offset from SRC_IF_ELSE and SRC_COND. r=jandem

This commit is contained in:
Tooru Fujisawa 2018-05-21 10:22:04 +09:00
parent 05f073e8e4
commit 3c8f09cb23
4 changed files with 14 additions and 33 deletions

View File

@ -1962,9 +1962,6 @@ class MOZ_STACK_CLASS IfThenElseEmitter
JumpList jumpAroundThen_;
JumpList jumpsAroundElse_;
// The source note index for SRC_IF, SRC_IF_ELSE, or SRC_COND.
unsigned noteIndex_;
// The stack depth before emitting the then block.
// Used for restoring stack depth before emitting the else block.
// Also used for assertion to make sure then and else blocks pushed the
@ -2014,7 +2011,6 @@ class MOZ_STACK_CLASS IfThenElseEmitter
public:
explicit IfThenElseEmitter(BytecodeEmitter* bce)
: bce_(bce),
noteIndex_(-1),
thenDepth_(0),
#ifdef DEBUG
pushed_(0),
@ -2037,7 +2033,7 @@ class MOZ_STACK_CLASS IfThenElseEmitter
// Emit an annotated branch-if-false around the then part.
SrcNoteType type = nextState == If ? SRC_IF : nextState == IfElse ? SRC_IF_ELSE : SRC_COND;
if (!bce_->newSrcNote(type, &noteIndex_))
if (!bce_->newSrcNote(type))
return false;
if (!bce_->emitJump(JSOP_IFEQ, &jumpAroundThen_))
return false;
@ -2093,17 +2089,6 @@ class MOZ_STACK_CLASS IfThenElseEmitter
if (!bce_->emitJumpTargetAndPatch(jumpAroundThen_))
return false;
// Annotate SRC_IF_ELSE or SRC_COND with the offset from branch to
// jump, for IonMonkey's benefit. We can't just "back up" from the pc
// of the else clause, because we don't know whether an extended
// jump was required to leap from the end of the then clause over
// the else clause.
if (!bce_->setSrcNoteOffset(noteIndex_, 0,
jumpsAroundElse_.offset - jumpAroundThen_.offset))
{
return false;
}
// Restore stack depth of the then part.
bce_->stackDepth = thenDepth_;
state_ = Else;

View File

@ -37,8 +37,8 @@ namespace js {
#define FOR_EACH_SRC_NOTE_TYPE(M) \
M(SRC_NULL, "null", 0) /* Terminates a note vector. */ \
M(SRC_IF, "if", 0) /* JSOP_IFEQ bytecode is from an if-then. */ \
M(SRC_IF_ELSE, "if-else", 1) /* JSOP_IFEQ bytecode is from an if-then-else. */ \
M(SRC_COND, "cond", 1) /* JSOP_IFEQ is from conditional ?: operator. */ \
M(SRC_IF_ELSE, "if-else", 0) /* JSOP_IFEQ bytecode is from an if-then-else. */ \
M(SRC_COND, "cond", 0) /* JSOP_IFEQ is from conditional ?: operator. */ \
M(SRC_FOR, "for", 3) /* JSOP_NOP or JSOP_POP in for(;;) loop head. */ \
M(SRC_WHILE, "while", 1) /* JSOP_GOTO to for or while loop condition from before \
loop, else JSOP_NOP at top of do-while loop. */ \

View File

@ -1762,22 +1762,22 @@ ControlFlowGenerator::processIfStart(JSOp op)
// The bytecode for if/ternary gets emitted either like this:
//
// IFEQ X ; src note (IF_ELSE, COND) points to the GOTO
// IFEQ X ; src note (IF_ELSE, COND)
// ...
// GOTO Z
// X: ... ; else/else if
// X: JUMPTARGET ; else/else if
// ...
// Z: ; join
// Z: JUMPTARGET ; join
//
// Or like this:
//
// IFEQ X ; src note (IF) has no offset
// IFEQ X ; src note (IF)
// ...
// Z: ... ; join
// X: JUMPTARGET ; join
//
// We want to parse the bytecode as if we were parsing the AST, so for the
// IF_ELSE/COND cases, we use the source note and follow the GOTO. For the
// IF case, the IFEQ offset is the join point.
// IF_ELSE/COND cases, we use the IFEQ/GOTO bytecode offsets to follow the
// branch. For the IF case, the IFEQ offset is the join point.
switch (SN_TYPE(sn)) {
case SRC_IF:
if (!cfgStack_.append(CFGState::If(falseStart, test)))
@ -1789,9 +1789,9 @@ ControlFlowGenerator::processIfStart(JSOp op)
{
// Infer the join point from the JSOP_GOTO[X] sitting here, then
// assert as we much we can that this is the right GOTO.
jsbytecode* trueEnd = pc + GetSrcNoteOffset(sn, 0);
MOZ_ASSERT(JSOp(*falseStart) == JSOP_JUMPTARGET);
jsbytecode* trueEnd = falseStart - JSOP_GOTO_LENGTH;
MOZ_ASSERT(trueEnd > pc);
MOZ_ASSERT(trueEnd < falseStart);
MOZ_ASSERT(JSOp(*trueEnd) == JSOP_GOTO);
MOZ_ASSERT(!GetSrcNote(gsn, script, trueEnd));

View File

@ -2695,6 +2695,8 @@ SrcNotes(JSContext* cx, HandleScript script, Sprinter* sp)
switch (type) {
case SRC_NULL:
case SRC_IF:
case SRC_IF_ELSE:
case SRC_COND:
case SRC_CONTINUE:
case SRC_BREAK:
case SRC_BREAK2LABEL:
@ -2729,18 +2731,12 @@ SrcNotes(JSContext* cx, HandleScript script, Sprinter* sp)
}
break;
case SRC_IF_ELSE:
if (!sp->jsprintf(" else %u", unsigned(GetSrcNoteOffset(sn, 0))))
return false;
break;
case SRC_FOR_IN:
case SRC_FOR_OF:
if (!sp->jsprintf(" closingjump %u", unsigned(GetSrcNoteOffset(sn, 0))))
return false;
break;
case SRC_COND:
case SRC_WHILE:
case SRC_NEXTCASE:
if (!sp->jsprintf(" offset %u", unsigned(GetSrcNoteOffset(sn, 0))))