Bug 1382973 part 1 - Don't use BytecodeAnalysis to compute stack depths in Ion. r=nbp

This commit is contained in:
Jan de Mooij 2017-07-22 14:21:25 +02:00
Родитель 1c78f9203b
Коммит e2a6ce0202
5 изменённых файлов: 57 добавлений и 54 удалений

Просмотреть файл

@ -734,7 +734,7 @@ IonBuilder::build()
script()->baselineScript()->resetMaxInliningDepth(); script()->baselineScript()->resetMaxInliningDepth();
MBasicBlock* entry; MBasicBlock* entry;
MOZ_TRY_VAR(entry, newBlock(pc)); MOZ_TRY_VAR(entry, newBlock(info().firstStackSlot(), pc));
MOZ_TRY(setCurrentAndSpecializePhis(entry)); MOZ_TRY(setCurrentAndSpecializePhis(entry));
#ifdef JS_JITSPEW #ifdef JS_JITSPEW
@ -930,7 +930,7 @@ IonBuilder::buildInline(IonBuilder* callerBuilder, MResumePoint* callerResumePoi
// Generate single entrance block. // Generate single entrance block.
MBasicBlock* entry; MBasicBlock* entry;
MOZ_TRY_VAR(entry, newBlock(pc)); MOZ_TRY_VAR(entry, newBlock(info().firstStackSlot(), pc));
MOZ_TRY(setCurrentAndSpecializePhis(entry)); MOZ_TRY(setCurrentAndSpecializePhis(entry));
current->setCallerResumePoint(callerResumePoint); current->setCallerResumePoint(callerResumePoint);
@ -3845,7 +3845,7 @@ IonBuilder::inlineScriptedCall(CallInfo& callInfo, JSFunction* target)
// Create return block. // Create return block.
jsbytecode* postCall = GetNextPc(pc); jsbytecode* postCall = GetNextPc(pc);
MBasicBlock* returnBlock; MBasicBlock* returnBlock;
MOZ_TRY_VAR(returnBlock, newBlock(nullptr, postCall)); MOZ_TRY_VAR(returnBlock, newBlock(current->stackDepth(), postCall));
graph().addBlock(returnBlock); graph().addBlock(returnBlock);
returnBlock->setCallerResumePoint(callerResumePoint_); returnBlock->setCallerResumePoint(callerResumePoint_);
@ -4541,10 +4541,13 @@ IonBuilder::inlineCalls(CallInfo& callInfo, const InliningTargets& targets, Bool
dispatch = MFunctionDispatch::New(alloc(), callInfo.fun()); dispatch = MFunctionDispatch::New(alloc(), callInfo.fun());
} }
MOZ_ASSERT(dispatchBlock->stackDepth() >= callInfo.numFormals());
uint32_t stackDepth = dispatchBlock->stackDepth() - callInfo.numFormals() + 1;
// Generate a return block to host the rval-collecting MPhi. // Generate a return block to host the rval-collecting MPhi.
jsbytecode* postCall = GetNextPc(pc); jsbytecode* postCall = GetNextPc(pc);
MBasicBlock* returnBlock; MBasicBlock* returnBlock;
MOZ_TRY_VAR(returnBlock, newBlock(nullptr, postCall)); MOZ_TRY_VAR(returnBlock, newBlock(stackDepth, postCall));
graph().addBlock(returnBlock); graph().addBlock(returnBlock);
returnBlock->setCallerResumePoint(callerResumePoint_); returnBlock->setCallerResumePoint(callerResumePoint_);
@ -6510,9 +6513,11 @@ IonBuilder::jsop_initelem_getter_setter()
} }
AbortReasonOr<MBasicBlock*> AbortReasonOr<MBasicBlock*>
IonBuilder::newBlock(MBasicBlock* predecessor, jsbytecode* pc) IonBuilder::newBlock(size_t stackDepth, jsbytecode* pc, MBasicBlock* maybePredecessor)
{ {
MBasicBlock* block = MBasicBlock::New(graph(), &analysis(), info(), predecessor, MOZ_ASSERT_IF(maybePredecessor, maybePredecessor->stackDepth() == stackDepth);
MBasicBlock* block = MBasicBlock::New(graph(), stackDepth, info(), maybePredecessor,
bytecodeSite(pc), MBasicBlock::NORMAL); bytecodeSite(pc), MBasicBlock::NORMAL);
if (!block) if (!block)
return abort(AbortReason::Alloc); return abort(AbortReason::Alloc);
@ -6546,9 +6551,12 @@ IonBuilder::newBlockPopN(MBasicBlock* predecessor, jsbytecode* pc, uint32_t popp
} }
AbortReasonOr<MBasicBlock*> AbortReasonOr<MBasicBlock*>
IonBuilder::newBlockAfter(MBasicBlock* at, MBasicBlock* predecessor, jsbytecode* pc) IonBuilder::newBlockAfter(MBasicBlock* at, size_t stackDepth, jsbytecode* pc,
MBasicBlock* maybePredecessor)
{ {
MBasicBlock* block = MBasicBlock::New(graph(), &analysis(), info(), predecessor, MOZ_ASSERT_IF(maybePredecessor, maybePredecessor->stackDepth() == stackDepth);
MBasicBlock* block = MBasicBlock::New(graph(), stackDepth, info(), maybePredecessor,
bytecodeSite(pc), MBasicBlock::NORMAL); bytecodeSite(pc), MBasicBlock::NORMAL);
if (!block) if (!block)
return abort(AbortReason::Alloc); return abort(AbortReason::Alloc);
@ -6569,7 +6577,7 @@ IonBuilder::newOsrPreheader(MBasicBlock* predecessor, jsbytecode* loopEntry,
// the preheader, which has the OSR entry block as a predecessor. The // the preheader, which has the OSR entry block as a predecessor. The
// OSR block is always the second block (with id 1). // OSR block is always the second block (with id 1).
MBasicBlock* osrBlock; MBasicBlock* osrBlock;
MOZ_TRY_VAR(osrBlock, newBlockAfter(*graph().begin(), loopEntry)); MOZ_TRY_VAR(osrBlock, newBlockAfter(*graph().begin(), predecessor->stackDepth(), loopEntry));
MBasicBlock* preheader; MBasicBlock* preheader;
MOZ_TRY_VAR(preheader, newBlock(predecessor, loopEntry)); MOZ_TRY_VAR(preheader, newBlock(predecessor, loopEntry));

Просмотреть файл

@ -76,22 +76,21 @@ class IonBuilder
AbortReasonOr<Ok> analyzeNewLoopTypes(const CFGBlock* loopEntryBlock); AbortReasonOr<Ok> analyzeNewLoopTypes(const CFGBlock* loopEntryBlock);
AbortReasonOr<MBasicBlock*> newBlock(MBasicBlock* predecessor, jsbytecode* pc); AbortReasonOr<MBasicBlock*> newBlock(size_t stackDepth, jsbytecode* pc,
MBasicBlock* maybePredecessor = nullptr);
AbortReasonOr<MBasicBlock*> newBlock(MBasicBlock* predecessor, jsbytecode* pc, AbortReasonOr<MBasicBlock*> newBlock(MBasicBlock* predecessor, jsbytecode* pc,
MResumePoint* priorResumePoint); MResumePoint* priorResumePoint);
AbortReasonOr<MBasicBlock*> newBlockPopN(MBasicBlock* predecessor, jsbytecode* pc, AbortReasonOr<MBasicBlock*> newBlockPopN(MBasicBlock* predecessor, jsbytecode* pc,
uint32_t popped); uint32_t popped);
AbortReasonOr<MBasicBlock*> newBlockAfter(MBasicBlock* at, MBasicBlock* predecessor, AbortReasonOr<MBasicBlock*> newBlockAfter(MBasicBlock* at, size_t stackDepth,
jsbytecode* pc); jsbytecode* pc, MBasicBlock* maybePredecessor = nullptr);
AbortReasonOr<MBasicBlock*> newOsrPreheader(MBasicBlock* header, jsbytecode* loopEntry, AbortReasonOr<MBasicBlock*> newOsrPreheader(MBasicBlock* header, jsbytecode* loopEntry,
jsbytecode* beforeLoopEntry); jsbytecode* beforeLoopEntry);
AbortReasonOr<MBasicBlock*> newPendingLoopHeader(MBasicBlock* predecessor, jsbytecode* pc, AbortReasonOr<MBasicBlock*> newPendingLoopHeader(MBasicBlock* predecessor, jsbytecode* pc,
bool osr, bool canOsr, unsigned stackPhiCount); bool osr, bool canOsr, unsigned stackPhiCount);
AbortReasonOr<MBasicBlock*> newBlock(jsbytecode* pc) {
return newBlock(nullptr, pc); AbortReasonOr<MBasicBlock*> newBlock(MBasicBlock* predecessor, jsbytecode* pc) {
} return newBlock(predecessor->stackDepth(), pc, predecessor);
AbortReasonOr<MBasicBlock*> newBlockAfter(MBasicBlock* at, jsbytecode* pc) {
return newBlockAfter(at, nullptr, pc);
} }
AbortReasonOr<Ok> visitBlock(const CFGBlock* hblock, MBasicBlock* mblock); AbortReasonOr<Ok> visitBlock(const CFGBlock* hblock, MBasicBlock* mblock);

Просмотреть файл

@ -212,17 +212,17 @@ LoopUnroller::go(LoopIterationBound* bound)
const CompileInfo& info = oldPreheader->info(); const CompileInfo& info = oldPreheader->info();
if (header->trackedPc()) { if (header->trackedPc()) {
unrolledHeader = unrolledHeader =
MBasicBlock::New(graph, nullptr, info, MBasicBlock::New(graph, oldPreheader->stackDepth(), info,
oldPreheader, header->trackedSite(), MBasicBlock::LOOP_HEADER); oldPreheader, header->trackedSite(), MBasicBlock::LOOP_HEADER);
if (!unrolledHeader) if (!unrolledHeader)
return false; return false;
unrolledBackedge = unrolledBackedge =
MBasicBlock::New(graph, nullptr, info, MBasicBlock::New(graph, unrolledHeader->stackDepth(), info,
unrolledHeader, backedge->trackedSite(), MBasicBlock::NORMAL); unrolledHeader, backedge->trackedSite(), MBasicBlock::NORMAL);
if (!unrolledBackedge) if (!unrolledBackedge)
return false; return false;
newPreheader = newPreheader =
MBasicBlock::New(graph, nullptr, info, MBasicBlock::New(graph, unrolledHeader->stackDepth(), info,
unrolledHeader, oldPreheader->trackedSite(), MBasicBlock::NORMAL); unrolledHeader, oldPreheader->trackedSite(), MBasicBlock::NORMAL);
if (!newPreheader) if (!newPreheader)
return false; return false;

Просмотреть файл

@ -286,8 +286,8 @@ MIRGraph::unmarkBlocks()
} }
MBasicBlock* MBasicBlock*
MBasicBlock::New(MIRGraph& graph, BytecodeAnalysis* analysis, const CompileInfo& info, MBasicBlock::New(MIRGraph& graph, size_t stackDepth, const CompileInfo& info,
MBasicBlock* pred, BytecodeSite* site, Kind kind) MBasicBlock* maybePred, BytecodeSite* site, Kind kind)
{ {
MOZ_ASSERT(site->pc() != nullptr); MOZ_ASSERT(site->pc() != nullptr);
@ -295,7 +295,7 @@ MBasicBlock::New(MIRGraph& graph, BytecodeAnalysis* analysis, const CompileInfo&
if (!block->init()) if (!block->init())
return nullptr; return nullptr;
if (!block->inherit(graph.alloc(), analysis, pred, 0)) if (!block->inherit(graph.alloc(), stackDepth, maybePred, 0))
return nullptr; return nullptr;
return block; return block;
@ -309,7 +309,7 @@ MBasicBlock::NewPopN(MIRGraph& graph, const CompileInfo& info,
if (!block->init()) if (!block->init())
return nullptr; return nullptr;
if (!block->inherit(graph.alloc(), nullptr, pred, popped)) if (!block->inherit(graph.alloc(), pred->stackDepth(), pred, popped))
return nullptr; return nullptr;
return block; return block;
@ -348,7 +348,7 @@ MBasicBlock::NewPendingLoopHeader(MIRGraph& graph, const CompileInfo& info,
if (!block->init()) if (!block->init())
return nullptr; return nullptr;
if (!block->inherit(graph.alloc(), nullptr, pred, 0, stackPhiCount)) if (!block->inherit(graph.alloc(), pred->stackDepth(), pred, 0, stackPhiCount))
return nullptr; return nullptr;
return block; return block;
@ -546,35 +546,31 @@ MBasicBlock::copySlots(MBasicBlock* from)
} }
bool bool
MBasicBlock::inherit(TempAllocator& alloc, BytecodeAnalysis* analysis, MBasicBlock* pred, MBasicBlock::inherit(TempAllocator& alloc, size_t stackDepth, MBasicBlock* maybePred,
uint32_t popped, unsigned stackPhiCount) uint32_t popped, unsigned stackPhiCount)
{ {
if (pred) { MOZ_ASSERT_IF(maybePred, maybePred->stackDepth() == stackDepth);
stackPosition_ = pred->stackPosition_;
MOZ_ASSERT(stackPosition_ >= popped); MOZ_ASSERT(stackDepth >= popped);
stackPosition_ -= popped; stackDepth -= popped;
if (kind_ != PENDING_LOOP_HEADER) stackPosition_ = stackDepth;
copySlots(pred);
} else { if (maybePred && kind_ != PENDING_LOOP_HEADER)
uint32_t stackDepth = analysis->info(pc()).stackDepth; copySlots(maybePred);
stackPosition_ = info().firstStackSlot() + stackDepth;
MOZ_ASSERT(stackPosition_ >= popped);
stackPosition_ -= popped;
}
MOZ_ASSERT(info_.nslots() >= stackPosition_); MOZ_ASSERT(info_.nslots() >= stackPosition_);
MOZ_ASSERT(!entryResumePoint_); MOZ_ASSERT(!entryResumePoint_);
// Propagate the caller resume point from the inherited block. // Propagate the caller resume point from the inherited block.
callerResumePoint_ = pred ? pred->callerResumePoint() : nullptr; callerResumePoint_ = maybePred ? maybePred->callerResumePoint() : nullptr;
// Create a resume point using our initial stack state. // Create a resume point using our initial stack state.
entryResumePoint_ = new(alloc) MResumePoint(this, pc(), MResumePoint::ResumeAt); entryResumePoint_ = new(alloc) MResumePoint(this, pc(), MResumePoint::ResumeAt);
if (!entryResumePoint_->init(alloc)) if (!entryResumePoint_->init(alloc))
return false; return false;
if (pred) { if (maybePred) {
if (!predecessors_.append(pred)) if (!predecessors_.append(maybePred))
return false; return false;
if (kind_ == PENDING_LOOP_HEADER) { if (kind_ == PENDING_LOOP_HEADER) {
@ -583,35 +579,35 @@ MBasicBlock::inherit(TempAllocator& alloc, BytecodeAnalysis* analysis, MBasicBlo
MPhi* phi = MPhi::New(alloc.fallible()); MPhi* phi = MPhi::New(alloc.fallible());
if (!phi) if (!phi)
return false; return false;
phi->addInlineInput(pred->getSlot(i)); phi->addInlineInput(maybePred->getSlot(i));
addPhi(phi); addPhi(phi);
setSlot(i, phi); setSlot(i, phi);
entryResumePoint()->initOperand(i, phi); entryResumePoint()->initOperand(i, phi);
} }
MOZ_ASSERT(stackPhiCount <= stackDepth()); MOZ_ASSERT(stackPhiCount <= stackDepth);
MOZ_ASSERT(info().firstStackSlot() <= stackDepth() - stackPhiCount); MOZ_ASSERT(info().firstStackSlot() <= stackDepth - stackPhiCount);
// Avoid creating new phis for stack values that aren't part of the // Avoid creating new phis for stack values that aren't part of the
// loop. Note that for loop headers that can OSR, all values on the // loop. Note that for loop headers that can OSR, all values on the
// stack are part of the loop. // stack are part of the loop.
for (; i < stackDepth() - stackPhiCount; i++) { for (; i < stackDepth - stackPhiCount; i++) {
MDefinition* val = pred->getSlot(i); MDefinition* val = maybePred->getSlot(i);
setSlot(i, val); setSlot(i, val);
entryResumePoint()->initOperand(i, val); entryResumePoint()->initOperand(i, val);
} }
for (; i < stackDepth(); i++) { for (; i < stackDepth; i++) {
MPhi* phi = MPhi::New(alloc.fallible()); MPhi* phi = MPhi::New(alloc.fallible());
if (!phi) if (!phi)
return false; return false;
phi->addInlineInput(pred->getSlot(i)); phi->addInlineInput(maybePred->getSlot(i));
addPhi(phi); addPhi(phi);
setSlot(i, phi); setSlot(i, phi);
entryResumePoint()->initOperand(i, phi); entryResumePoint()->initOperand(i, phi);
} }
} else { } else {
for (size_t i = 0; i < stackDepth(); i++) for (size_t i = 0; i < stackDepth; i++)
entryResumePoint()->initOperand(i, getSlot(i)); entryResumePoint()->initOperand(i, getSlot(i));
} }
} else { } else {
@ -619,7 +615,7 @@ MBasicBlock::inherit(TempAllocator& alloc, BytecodeAnalysis* analysis, MBasicBlo
* Don't leave the operands uninitialized for the caller, as it may not * Don't leave the operands uninitialized for the caller, as it may not
* initialize them later on. * initialize them later on.
*/ */
for (size_t i = 0; i < stackDepth(); i++) for (size_t i = 0; i < stackDepth; i++)
entryResumePoint()->clearOperand(i); entryResumePoint()->clearOperand(i);
} }

Просмотреть файл

@ -49,7 +49,7 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
MBasicBlock(MIRGraph& graph, const CompileInfo& info, BytecodeSite* site, Kind kind); MBasicBlock(MIRGraph& graph, const CompileInfo& info, BytecodeSite* site, Kind kind);
MOZ_MUST_USE bool init(); MOZ_MUST_USE bool init();
void copySlots(MBasicBlock* from); void copySlots(MBasicBlock* from);
MOZ_MUST_USE bool inherit(TempAllocator& alloc, BytecodeAnalysis* analysis, MBasicBlock* pred, MOZ_MUST_USE bool inherit(TempAllocator& alloc, size_t stackDepth, MBasicBlock* maybePred,
uint32_t popped, unsigned stackPhiCount = 0); uint32_t popped, unsigned stackPhiCount = 0);
MOZ_MUST_USE bool inheritResumePoint(MBasicBlock* pred); MOZ_MUST_USE bool inheritResumePoint(MBasicBlock* pred);
void assertUsesAreNotWithin(MUseIterator use, MUseIterator end); void assertUsesAreNotWithin(MUseIterator use, MUseIterator end);
@ -109,8 +109,8 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
// Creates a new basic block for a MIR generator. If |pred| is not nullptr, // Creates a new basic block for a MIR generator. If |pred| is not nullptr,
// its slots and stack depth are initialized from |pred|. // its slots and stack depth are initialized from |pred|.
static MBasicBlock* New(MIRGraph& graph, BytecodeAnalysis* analysis, const CompileInfo& info, static MBasicBlock* New(MIRGraph& graph, size_t stackDepth, const CompileInfo& info,
MBasicBlock* pred, BytecodeSite* site, Kind kind); MBasicBlock* maybePred, BytecodeSite* site, Kind kind);
static MBasicBlock* New(MIRGraph& graph, const CompileInfo& info, MBasicBlock* pred, Kind kind); static MBasicBlock* New(MIRGraph& graph, const CompileInfo& info, MBasicBlock* pred, Kind kind);
static MBasicBlock* NewPopN(MIRGraph& graph, const CompileInfo& info, static MBasicBlock* NewPopN(MIRGraph& graph, const CompileInfo& info,
MBasicBlock* pred, BytecodeSite* site, Kind kind, uint32_t popn); MBasicBlock* pred, BytecodeSite* site, Kind kind, uint32_t popn);