Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 60124d1

Browse files
committed
Bug 865153 - Remove resume point uses in dead blocks when restarting loop processing, r=h4writer.
1 parent 72c7993 commit 60124d1

5 files changed

Lines changed: 57 additions & 2 deletions

File tree

js/src/ion/IonBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,8 +1741,10 @@ IonBuilder::restartLoop(CFGState state)
17411741
// of the appropriate type and incoming edges to preserve.
17421742
graph().removeBlocksAfter(header);
17431743

1744-
// Remove all instructions from the header itself.
1744+
// Remove all instructions from the header itself, and all resume points
1745+
// except the entry resume point.
17451746
header->discardAllInstructions();
1747+
header->discardAllResumePoints(/* discardEntry = */ false);
17461748
header->setStackDepth(header->getPredecessor(0)->stackDepth());
17471749

17481750
popCfgStack();

js/src/ion/MIR.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,6 +1674,7 @@ MResumePoint::MResumePoint(MBasicBlock *block, jsbytecode *pc, MResumePoint *cal
16741674
instruction_(NULL),
16751675
mode_(mode)
16761676
{
1677+
block->addResumePoint(this);
16771678
}
16781679

16791680
void

js/src/ion/MIR.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ class MUse : public TempObject, public InlineListNode<MUse>
101101
JS_ASSERT(producer_ != NULL);
102102
return producer_;
103103
}
104+
bool hasProducer() const {
105+
return producer_ != NULL;
106+
}
104107
MNode *consumer() const {
105108
JS_ASSERT(consumer_ != NULL);
106109
return consumer_;
@@ -7171,7 +7174,7 @@ class MParNewDenseArray : public MBinaryInstruction
71717174
// A resume point contains the information needed to reconstruct the interpreter
71727175
// state from a position in the JIT. See the big comment near resumeAfter() in
71737176
// IonBuilder.cpp.
7174-
class MResumePoint : public MNode
7177+
class MResumePoint : public MNode, public InlineForwardListNode<MResumePoint>
71757178
{
71767179
public:
71777180
enum Mode {
@@ -7207,6 +7210,11 @@ class MResumePoint : public MNode
72077210
operand->addUse(&operands_[index]);
72087211
}
72097212

7213+
void clearOperand(size_t index) {
7214+
JS_ASSERT(index < stackDepth_);
7215+
operands_[index].set(NULL, this, index);
7216+
}
7217+
72107218
MUse *getUseFor(size_t index) {
72117219
return &operands_[index];
72127220
}
@@ -7251,6 +7259,13 @@ class MResumePoint : public MNode
72517259
Mode mode() const {
72527260
return mode_;
72537261
}
7262+
7263+
void discardUses() {
7264+
for (size_t i = 0; i < stackDepth_; i++) {
7265+
if (operands_[i].hasProducer())
7266+
operands_[i].producer()->removeUse(&operands_[i]);
7267+
}
7268+
}
72547269
};
72557270

72567271
/*

js/src/ion/MIRGraph.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ MIRGraph::removeBlocksAfter(MBasicBlock *start)
7878
osrBlock_ = NULL;
7979
block->discardAllInstructions();
8080
block->discardAllPhis();
81+
block->discardAllResumePoints();
8182
block->markAsDead();
8283
removeBlock(block);
8384
}
@@ -292,6 +293,13 @@ MBasicBlock::inherit(MBasicBlock *pred, uint32_t popped)
292293
for (size_t i = 0; i < stackDepth(); i++)
293294
entryResumePoint()->setOperand(i, getSlot(i));
294295
}
296+
} else if (entryResumePoint()) {
297+
/*
298+
* Don't leave the operands uninitialized for the caller, as it may not
299+
* initialize them later on.
300+
*/
301+
for (size_t i = 0; i < stackDepth(); i++)
302+
entryResumePoint()->clearOperand(i);
295303
}
296304

297305
return true;
@@ -638,6 +646,20 @@ MBasicBlock::discardAllPhis()
638646
(*pred)->setSuccessorWithPhis(NULL, 0);
639647
}
640648

649+
void
650+
MBasicBlock::discardAllResumePoints(bool discardEntry)
651+
{
652+
for (MResumePointIterator iter = resumePointsBegin(); iter != resumePointsEnd(); ) {
653+
MResumePoint *rp = *iter;
654+
if (rp == entryResumePoint() && !discardEntry) {
655+
iter++;
656+
} else {
657+
rp->discardUses();
658+
iter = resumePoints_.removeAt(iter);
659+
}
660+
}
661+
}
662+
641663
void
642664
MBasicBlock::insertBefore(MInstruction *at, MInstruction *ins)
643665
{

js/src/ion/MIRGraph.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MDefinitionIterator;
2626
typedef InlineListIterator<MInstruction> MInstructionIterator;
2727
typedef InlineListReverseIterator<MInstruction> MInstructionReverseIterator;
2828
typedef InlineForwardListIterator<MPhi> MPhiIterator;
29+
typedef InlineForwardListIterator<MResumePoint> MResumePointIterator;
2930

3031
class LBlock;
3132

@@ -156,6 +157,11 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
156157
// Adds a phi instruction, but does not set successorWithPhis.
157158
void addPhi(MPhi *phi);
158159

160+
// Adds a resume point to this block.
161+
void addResumePoint(MResumePoint *resume) {
162+
resumePoints_.pushFront(resume);
163+
}
164+
159165
// Adds a predecessor. Every predecessor must have the same exit stack
160166
// depth as the entry state to this block. Adding a predecessor
161167
// automatically creates phi nodes and rewrites uses as needed.
@@ -217,6 +223,7 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
217223
MDefinitionIterator discardDefAt(MDefinitionIterator &iter);
218224
void discardAllInstructions();
219225
void discardAllPhis();
226+
void discardAllResumePoints(bool discardEntry = true);
220227

221228
// Discards a phi instruction and updates predecessor successorWithPhis.
222229
MPhiIterator discardPhiAt(MPhiIterator &at);
@@ -250,6 +257,7 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
250257
}
251258

252259
uint32_t domIndex() const {
260+
JS_ASSERT(!isDead());
253261
return domIndex_;
254262
}
255263
void setDomIndex(uint32_t d) {
@@ -271,6 +279,12 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
271279
bool phisEmpty() const {
272280
return phis_.empty();
273281
}
282+
MResumePointIterator resumePointsBegin() const {
283+
return resumePoints_.begin();
284+
}
285+
MResumePointIterator resumePointsEnd() const {
286+
return resumePoints_.end();
287+
}
274288
MInstructionIterator begin() {
275289
return instructions_.begin();
276290
}
@@ -453,6 +467,7 @@ class MBasicBlock : public TempObject, public InlineListNode<MBasicBlock>
453467
InlineList<MInstruction> instructions_;
454468
Vector<MBasicBlock *, 1, IonAllocPolicy> predecessors_;
455469
InlineForwardList<MPhi> phis_;
470+
InlineForwardList<MResumePoint> resumePoints_;
456471
FixedList<MDefinition *> slots_;
457472
uint32_t stackPosition_;
458473
MControlInstruction *lastIns_;

0 commit comments

Comments
 (0)