Commit 63a298d4 authored by Nicolas B. Pierron's avatar Nicolas B. Pierron
Browse files

Bug 989641 - Move FlattenedMResumePointIter into LRecover. r=jandem

parent cee53989
Loading
Loading
Loading
Loading
+30 −10
Original line number Diff line number Diff line
@@ -119,28 +119,48 @@ TotalOperandCount(MResumePoint *mir)
    return accum;
}

LRecoverInfo::LRecoverInfo(MResumePoint *mir)
  : mir_(mir),
LRecoverInfo::LRecoverInfo(TempAllocator &alloc)
  : instructions_(alloc),
    recoverOffset_(INVALID_RECOVER_OFFSET)
{ }

LRecoverInfo *
LRecoverInfo::New(MIRGenerator *gen, MResumePoint *mir)
{
    LRecoverInfo *recover = new(gen->alloc()) LRecoverInfo(mir);
    if (!recover)
    LRecoverInfo *recoverInfo = new(gen->alloc()) LRecoverInfo(gen->alloc());
    if (!recoverInfo || !recoverInfo->init(mir))
        return nullptr;

    IonSpew(IonSpew_Snapshots, "Generating LIR recover %p from MIR (%p)",
            (void *)recover, (void *)mir);
    IonSpew(IonSpew_Snapshots, "Generating LIR recover info %p from MIR (%p)",
            (void *)recoverInfo, (void *)mir);

    return recover;
    return recoverInfo;
}

LSnapshot::LSnapshot(LRecoverInfo *recover, BailoutKind kind)
  : numSlots_(TotalOperandCount(recover->mir()) * BOX_PIECES),
bool
LRecoverInfo::init(MResumePoint *rp)
{
    MResumePoint *it = rp;

    // Sort operations in the order in which we need to restore the stack. This
    // implies that outer frames, as well as operations needed to recover the
    // current frame, are located before the current frame. The inner-most
    // resume point should be the last element in the list.
    do {
        if (!instructions_.append(it))
            return false;
        it = it->caller();
    } while (it);

    Reverse(instructions_.begin(), instructions_.end());
    MOZ_ASSERT(mir() == rp);
    return true;
}

LSnapshot::LSnapshot(LRecoverInfo *recoverInfo, BailoutKind kind)
  : numSlots_(TotalOperandCount(recoverInfo->mir()) * BOX_PIECES),
    slots_(nullptr),
    recoverInfo_(recover),
    recoverInfo_(recoverInfo),
    snapshotOffset_(INVALID_SNAPSHOT_OFFSET),
    bailoutId_(INVALID_BAILOUT_ID),
    bailoutKind_(kind)
+18 −3
Original line number Diff line number Diff line
@@ -878,18 +878,26 @@ class LCallInstructionHelper : public LInstructionHelper<Defs, Operands, Temps>

class LRecoverInfo : public TempObject
{
    MResumePoint *mir_;
  public:
    typedef Vector<MResumePoint *, 2, IonAllocPolicy> Instructions;

  private:
    // List of instructions needed to recover the stack frames.
    // Outer frames are stored before inner frames.
    Instructions instructions_;

    // Cached offset where this resume point is encoded.
    RecoverOffset recoverOffset_;

    LRecoverInfo(MResumePoint *mir);
    LRecoverInfo(TempAllocator &alloc);
    bool init(MResumePoint *mir);

  public:
    static LRecoverInfo *New(MIRGenerator *gen, MResumePoint *mir);

    // Resume point of the inner most function.
    MResumePoint *mir() const {
        return mir_;
        return instructions_.back();
    }
    RecoverOffset recoverOffset() const {
        return recoverOffset_;
@@ -898,6 +906,13 @@ class LRecoverInfo : public TempObject
        JS_ASSERT(recoverOffset_ == INVALID_RECOVER_OFFSET);
        recoverOffset_ = offset;
    }

    MResumePoint **begin() {
        return instructions_.begin();
    }
    MResumePoint **end() {
        return instructions_.end();
    }
};

// An LSnapshot is the reflection of an MResumePoint in LIR. Unlike MResumePoints,
+0 −38
Original line number Diff line number Diff line
@@ -9427,44 +9427,6 @@ class MResumePoint MOZ_FINAL : public MNode, public InlineForwardListNode<MResum
    }
};

/*
 * Facade for a chain of MResumePoints that cross frame boundaries (due to
 * function inlining). Operands are ordered from oldest frame to newest.
 */
class FlattenedMResumePointIter
{
    Vector<MResumePoint *, 8, SystemAllocPolicy> resumePoints;
    MResumePoint *newest;
    size_t numOperands_;

  public:
    explicit FlattenedMResumePointIter(MResumePoint *newest)
      : newest(newest), numOperands_(0)
    {}

    bool init() {
        MResumePoint *it = newest;
        do {
            if (!resumePoints.append(it))
                return false;
            it = it->caller();
        } while (it);
        Reverse(resumePoints.begin(), resumePoints.end());
        return true;
    }

    MResumePoint **begin() {
        return resumePoints.begin();
    }
    MResumePoint **end() {
        return resumePoints.end();
    }

    size_t numOperands() const {
        return numOperands_;
    }
};

class MIsCallable
  : public MUnaryInstruction,
    public SingleObjectPolicy
+7 −14
Original line number Diff line number Diff line
@@ -250,11 +250,7 @@ CodeGeneratorShared::encode(LRecoverInfo *recover)

    RecoverOffset offset = recovers_.startRecover(frameCount, resumeAfter);

    FlattenedMResumePointIter mirOperandIter(recover->mir());
    if (!mirOperandIter.init())
        return false;

    for (MResumePoint **it = mirOperandIter.begin(), **end = mirOperandIter.end();
    for (MResumePoint **it = recover->begin(), **end = recover->end();
         it != end;
         ++it)
    {
@@ -320,14 +316,15 @@ CodeGeneratorShared::encode(LSnapshot *snapshot)
    if (snapshot->snapshotOffset() != INVALID_SNAPSHOT_OFFSET)
        return true;

    if (!encode(snapshot->recoverInfo()))
    LRecoverInfo *recoverInfo = snapshot->recoverInfo();
    if (!encode(recoverInfo))
        return false;

    RecoverOffset recoverOffset = snapshot->recoverInfo()->recoverOffset();
    RecoverOffset recoverOffset = recoverInfo->recoverOffset();
    MOZ_ASSERT(recoverOffset != INVALID_RECOVER_OFFSET);

    IonSpew(IonSpew_Snapshots, "Encoding LSnapshot %p (LRecoverInfo %p)",
            (void *)snapshot, (void*) snapshot->recoverInfo());
    IonSpew(IonSpew_Snapshots, "Encoding LSnapshot %p (LRecover %p)",
            (void *)snapshot, (void*) recoverInfo);

    SnapshotOffset offset = snapshots_.startSnapshot(recoverOffset, snapshot->bailoutKind());

@@ -351,12 +348,8 @@ CodeGeneratorShared::encode(LSnapshot *snapshot)
    snapshots_.trackSnapshot(pcOpcode, mirOpcode, mirId, lirOpcode, lirId);
#endif

    FlattenedMResumePointIter mirOperandIter(snapshot->recoverInfo()->mir());
    if (!mirOperandIter.init())
        return false;

    uint32_t startIndex = 0;
    for (MResumePoint **it = mirOperandIter.begin(), **end = mirOperandIter.end();
    for (MResumePoint **it = recoverInfo->begin(), **end = recoverInfo->end();
         it != end;
         ++it)
    {
+5 −10
Original line number Diff line number Diff line
@@ -63,6 +63,9 @@ LIRGeneratorShared::getRecoverInfo(MResumePoint *rp)
        return cachedRecoverInfo_;

    LRecoverInfo *recoverInfo = LRecoverInfo::New(gen, rp);
    if (!recoverInfo)
        return nullptr;

    cachedRecoverInfo_ = recoverInfo;
    return recoverInfo;
}
@@ -79,12 +82,8 @@ LIRGeneratorShared::buildSnapshot(LInstruction *ins, MResumePoint *rp, BailoutKi
    if (!snapshot)
        return nullptr;

    FlattenedMResumePointIter iter(rp);
    if (!iter.init())
        return nullptr;

    size_t i = 0;
    for (MResumePoint **it = iter.begin(), **end = iter.end(); it != end; ++it) {
    for (MResumePoint **it = recover->begin(), **end = recover->end(); it != end; ++it) {
        MResumePoint *mir = *it;
        for (size_t j = 0, e = mir->numOperands(); j < e; ++i, ++j) {
            MDefinition *ins = mir->getOperand(j);
@@ -137,12 +136,8 @@ LIRGeneratorShared::buildSnapshot(LInstruction *ins, MResumePoint *rp, BailoutKi
    if (!snapshot)
        return nullptr;

    FlattenedMResumePointIter iter(rp);
    if (!iter.init())
        return nullptr;

    size_t i = 0;
    for (MResumePoint **it = iter.begin(), **end = iter.end(); it != end; ++it) {
    for (MResumePoint **it = recover->begin(), **end = recover->end(); it != end; ++it) {
        MResumePoint *mir = *it;
        for (size_t j = 0, e = mir->numOperands(); j < e; ++i, ++j) {
            MDefinition *def = mir->getOperand(j);