Skip to content

Commit 40d261b

Browse files
author
Meghana Gupta
committed
[MERGE #5255 @meg-gupta] OS#17677370 : Avoid allocating local value table before legality check
Merge pull request #5255 from meg-gupta:fixexcessmem
2 parents a9fcfde + 6964647 commit 40d261b

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

lib/Backend/FlowGraph.cpp

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4610,13 +4610,9 @@ void
46104610
BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
46114611
{
46124612
IR::LabelInstr * lastBranchTarget = nullptr;
4613-
4614-
// For the block we start processing from, we maintain a valueTable, we go over the instrs in the block
4615-
// If we find a Ld_A, we find if the src1 already has a value in the local valueTable, if not we use the value from the pred's valueTable merge
4616-
// For other instrs, we assign null value
4617-
GlobHashTable * localSymToValueMap = GlobHashTable::New(globOpt->alloc, 8);
4618-
BVSparse<JitArenaAllocator> currentPathDefines(globOpt->alloc);
46194613
IR::Instr *currentInlineeEnd = nullptr, *unskippedInlineeEnd = nullptr;
4614+
GlobHashTable * localSymToValueMap = nullptr;
4615+
BVSparse<JitArenaAllocator> * currentPathDefines = nullptr;
46204616

46214617
auto UpdateValueForCopyTypeInstr = [&](IR::Instr *instr) -> Value* {
46224618
Value * dstValue = nullptr;
@@ -4688,6 +4684,50 @@ BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
46884684

46894685
IR::Instr * instr = this->GetLastInstr();
46904686

4687+
// We have to first check the legality and only then allocate expensive data structures on the tempArena, because most block will have instructions we cant skip
4688+
4689+
while (instr)
4690+
{
4691+
if (!instr->IsBranchInstr() && !instr->IsLabelInstr() && !IsLegalOpcodeForPathDepBrFold(instr))
4692+
{
4693+
return;
4694+
}
4695+
if (instr->IsLabelInstr())
4696+
{
4697+
if (instr->AsLabelInstr()->m_isLoopTop)
4698+
{
4699+
// don't cross over to loops
4700+
return;
4701+
}
4702+
}
4703+
if (instr->IsBranchInstr())
4704+
{
4705+
IR::BranchInstr *branch = instr->AsBranchInstr();
4706+
if (branch->IsUnconditional())
4707+
{
4708+
if (!branch->GetTarget())
4709+
{
4710+
return;
4711+
}
4712+
instr = branch->GetTarget();
4713+
}
4714+
else
4715+
{
4716+
// Found only legal instructions until a conditional branch, build expensive data structures and check provability
4717+
break;
4718+
}
4719+
}
4720+
else
4721+
{
4722+
instr = instr->m_next;
4723+
}
4724+
}
4725+
4726+
instr = this->GetLastInstr();
4727+
// Allocate hefty structures, we will not free them because OptBlock does a Reset on the tempAlloc
4728+
localSymToValueMap = GlobHashTable::New(globOpt->tempAlloc, 8);
4729+
currentPathDefines = JitAnew(globOpt->tempAlloc, BVSparse<JitArenaAllocator>, globOpt->tempAlloc);
4730+
46914731
/* We start from the current instruction and go on scanning for legality, as long as it is legal to skip an instruction, skip.
46924732
* When we see an unconditional branch, start scanning from the branchTarget
46934733
* When we see a conditional branch, check if we can prove the branch target, if we can, adjust the flowgraph, and continue in the direction of the proven target
@@ -4703,6 +4743,14 @@ BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
47034743
{
47044744
return;
47054745
}
4746+
if (instr->IsLabelInstr())
4747+
{
4748+
if (instr->AsLabelInstr()->m_isLoopTop)
4749+
{
4750+
// don't cross over to loops
4751+
return;
4752+
}
4753+
}
47064754
if (instr->m_opcode == Js::OpCode::InlineeEnd)
47074755
{
47084756
if (currentInlineeEnd != nullptr)
@@ -4719,7 +4767,7 @@ BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
47194767
}
47204768

47214769
IR::RegOpnd *dst = instr->GetDst()->AsRegOpnd();
4722-
currentPathDefines.Set(dst->GetStackSym()->m_id);
4770+
currentPathDefines->Set(dst->GetStackSym()->m_id);
47234771

47244772
if (IsCopyTypeInstr(instr))
47254773
{
@@ -4736,14 +4784,7 @@ BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
47364784
*localDstValue = nullptr;
47374785
}
47384786
}
4739-
if (instr->IsLabelInstr())
4740-
{
4741-
if (instr->AsLabelInstr()->m_isLoopTop)
4742-
{
4743-
// don't cross over to loops
4744-
return;
4745-
}
4746-
}
4787+
47474788
if (instr->IsBranchInstr())
47484789
{
47494790
IR::BranchInstr* branch = instr->AsBranchInstr();
@@ -4774,7 +4815,7 @@ BasicBlock::CheckLegalityAndFoldPathDepBranches(GlobOpt* globOpt)
47744815
}
47754816
}
47764817

4777-
FOREACH_BITSET_IN_SPARSEBV(id, &currentPathDefines)
4818+
FOREACH_BITSET_IN_SPARSEBV(id, currentPathDefines)
47784819
{
47794820
if (branchTarget->GetBasicBlock()->upwardExposedUses->Test(id))
47804821
{

0 commit comments

Comments
 (0)