PR #2695 - Simplify block-value popping in Ion compilation

This commit is contained in:
Shadow 2025-02-25 13:09:26 +00:00 • committed by roytam1
commit 37dcef684a

View file

@ -158,8 +158,6 @@ class FunctionCompiler
const CompileInfo& info_; const CompileInfo& info_;
MIRGenerator& mirGen_; MIRGenerator& mirGen_;
MInstruction* dummyIns_;
MBasicBlock* curBlock_; MBasicBlock* curBlock_;
CallCompileStateVector callStack_; CallCompileStateVector callStack_;
uint32_t maxStackArgBytes_; uint32_t maxStackArgBytes_;
@ -189,7 +187,6 @@ class FunctionCompiler
graph_(mirGen.graph()), graph_(mirGen.graph()),
info_(mirGen.info()), info_(mirGen.info()),
mirGen_(mirGen), mirGen_(mirGen),
dummyIns_(nullptr),
curBlock_(nullptr), curBlock_(nullptr),
maxStackArgBytes_(0), maxStackArgBytes_(0),
loopDepth_(0), loopDepth_(0),
@ -259,9 +256,6 @@ class FunctionCompiler
return false; return false;
} }
dummyIns_ = MConstant::New(alloc(), Int32Value(0), MIRType::Int32);
curBlock_->add(dummyIns_);
addInterruptCheck(); addInterruptCheck();
return true; return true;
@ -977,45 +971,13 @@ class FunctionCompiler
curBlock_->push(def); curBlock_->push(def);
} }
MDefinition* popDefIfPushed(bool shouldReturn = true) MDefinition* popDefIfPushed()
{ {
if (!hasPushed(curBlock_)) if (!hasPushed(curBlock_))
return nullptr; return nullptr;
MDefinition* def = curBlock_->pop(); MDefinition* def = curBlock_->pop();
MOZ_ASSERT_IF(def->type() == MIRType::Value, !shouldReturn); MOZ_ASSERT(def->type() != MIRType::Value);
return shouldReturn ? def : nullptr; return def;
}
template <typename GetBlock>
bool ensurePushInvariants(const GetBlock& getBlock, size_t numBlocks)
{
// Preserve the invariant that, for every iterated MBasicBlock, either:
// every MBasicBlock has a pushed expression with the same type (to
// prevent creating used phis with type Value) OR no MBasicBlock has any
// pushed expression. This is required by MBasicBlock::addPredecessor.
if (numBlocks < 2)
return true;
MBasicBlock* block = getBlock(0);
bool allPushed = hasPushed(block);
if (allPushed) {
MIRType type = peekPushedDef(block)->type();
for (size_t i = 1; allPushed && i < numBlocks; i++) {
block = getBlock(i);
allPushed = hasPushed(block) && peekPushedDef(block)->type() == type;
}
}
if (!allPushed) {
for (size_t i = 0; i < numBlocks; i++) {
block = getBlock(i);
if (!hasPushed(block))
block->push(dummyIns_);
}
}
return allPushed;
} }
private: private:
@ -1085,9 +1047,6 @@ class FunctionCompiler
if (elseJoinPred) if (elseJoinPred)
blocks[numJoinPreds++] = elseJoinPred; blocks[numJoinPreds++] = elseJoinPred;
auto getBlock = [&](size_t i) -> MBasicBlock* { return blocks[i]; };
bool yieldsValue = ensurePushInvariants(getBlock, numJoinPreds);
if (numJoinPreds == 0) { if (numJoinPreds == 0) {
*def = nullptr; *def = nullptr;
return true; return true;
@ -1102,7 +1061,7 @@ class FunctionCompiler
} }
curBlock_ = join; curBlock_ = join;
*def = popDefIfPushed(yieldsValue); *def = popDefIfPushed();
} }
return true; return true;
@ -1406,18 +1365,10 @@ class FunctionCompiler
} }
ControlFlowPatchVector& patches = blockPatches_[absolute]; ControlFlowPatchVector& patches = blockPatches_[absolute];
auto getBlock = [&](size_t i) -> MBasicBlock* {
if (i < patches.length())
return patches[i].ins->block();
return curBlock_;
};
bool yieldsValue = ensurePushInvariants(getBlock, patches.length() + !!curBlock_);
MBasicBlock* join = nullptr;
MControlInstruction* ins = patches[0].ins; MControlInstruction* ins = patches[0].ins;
MBasicBlock* pred = ins->block(); MBasicBlock* pred = ins->block();
MBasicBlock* join = nullptr;
if (!newBlock(pred, &join)) if (!newBlock(pred, &join))
return false; return false;
@ -1446,7 +1397,7 @@ class FunctionCompiler
curBlock_ = join; curBlock_ = join;
*def = popDefIfPushed(yieldsValue); *def = popDefIfPushed();
patches.clear(); patches.clear();
return true; return true;