Skip to content

Commit 2b6e9a2

Browse files
committed
[MERGE #5785 @nhat-nguyen] Change usedCapturedValues in BailOutInfo to a pointer for consistency
Merge pull request #5785 from nhat-nguyen:usedCapturedValues As part of `LazyBailOut`, we want to perform a *shallow* copy of a `BailOutInfo` which includes sharing all field pointers. However, `usedCapturedValues` is the only field in `BailOutInfo` that is not a pointer and is initialized together with `CapturedValues`, which makes it more complicated to do so as we have to perform manual copy of each field inside `CapturedValues`. With this change, we are more consistent with what we already have and also make it easier for future `LazyBailOut` work.
2 parents 913f3fa + 6abc058 commit 2b6e9a2

File tree

5 files changed

+42
-27
lines changed

5 files changed

+42
-27
lines changed

lib/Backend/BackwardPass.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,19 +1716,19 @@ BackwardPass::ProcessBailOutArgObj(BailOutInfo * bailOutInfo, BVSparse<JitArenaA
17161716
{
17171717
if (byteCodeUpwardExposedUsed->TestAndClear(symId))
17181718
{
1719-
if (bailOutInfo->usedCapturedValues.argObjSyms == nullptr)
1719+
if (bailOutInfo->usedCapturedValues->argObjSyms == nullptr)
17201720
{
1721-
bailOutInfo->usedCapturedValues.argObjSyms = JitAnew(this->func->m_alloc,
1721+
bailOutInfo->usedCapturedValues->argObjSyms = JitAnew(this->func->m_alloc,
17221722
BVSparse<JitArenaAllocator>, this->func->m_alloc);
17231723
}
1724-
bailOutInfo->usedCapturedValues.argObjSyms->Set(symId);
1724+
bailOutInfo->usedCapturedValues->argObjSyms->Set(symId);
17251725
}
17261726
}
17271727
NEXT_BITSET_IN_SPARSEBV;
17281728
}
1729-
if (bailOutInfo->usedCapturedValues.argObjSyms)
1729+
if (bailOutInfo->usedCapturedValues->argObjSyms)
17301730
{
1731-
byteCodeUpwardExposedUsed->Minus(bailOutInfo->usedCapturedValues.argObjSyms);
1731+
byteCodeUpwardExposedUsed->Minus(bailOutInfo->usedCapturedValues->argObjSyms);
17321732
}
17331733
}
17341734

@@ -1738,7 +1738,7 @@ BackwardPass::ProcessBailOutConstants(BailOutInfo * bailOutInfo, BVSparse<JitAre
17381738
Assert(this->tag != Js::BackwardPhase);
17391739

17401740
// Remove constants that we are already going to restore
1741-
SListBase<ConstantStackSymValue> * usedConstantValues = &bailOutInfo->usedCapturedValues.constantValues;
1741+
SListBase<ConstantStackSymValue> * usedConstantValues = &bailOutInfo->usedCapturedValues->constantValues;
17421742
FOREACH_SLISTBASE_ENTRY(ConstantStackSymValue, value, usedConstantValues)
17431743
{
17441744
byteCodeUpwardExposedUsed->Clear(value.Key()->m_id);
@@ -1770,7 +1770,7 @@ BackwardPass::ProcessBailOutCopyProps(BailOutInfo * bailOutInfo, BVSparse<JitAre
17701770
Assert(!this->func->GetJITFunctionBody()->IsAsmJsMode());
17711771

17721772
// Remove copy prop that we were already going to restore
1773-
SListBase<CopyPropSyms> * usedCopyPropSyms = &bailOutInfo->usedCapturedValues.copyPropSyms;
1773+
SListBase<CopyPropSyms> * usedCopyPropSyms = &bailOutInfo->usedCapturedValues->copyPropSyms;
17741774
FOREACH_SLISTBASE_ENTRY(CopyPropSyms, copyPropSyms, usedCopyPropSyms)
17751775
{
17761776
byteCodeUpwardExposedUsed->Clear(copyPropSyms.Key()->m_id);
@@ -2602,7 +2602,7 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
26022602
tempBv->And(this->func->m_nonTempLocalVars, bailOutInfo->liveVarSyms);
26032603

26042604
// Remove syms that are restored in other ways than byteCodeUpwardExposedUsed.
2605-
FOREACH_SLIST_ENTRY(ConstantStackSymValue, value, &bailOutInfo->usedCapturedValues.constantValues)
2605+
FOREACH_SLIST_ENTRY(ConstantStackSymValue, value, &bailOutInfo->usedCapturedValues->constantValues)
26062606
{
26072607
Assert(value.Key()->HasByteCodeRegSlot() || value.Key()->GetInstrDef()->m_opcode == Js::OpCode::BytecodeArgOutCapture);
26082608
if (value.Key()->HasByteCodeRegSlot())
@@ -2611,7 +2611,7 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
26112611
}
26122612
}
26132613
NEXT_SLIST_ENTRY;
2614-
FOREACH_SLIST_ENTRY(CopyPropSyms, value, &bailOutInfo->usedCapturedValues.copyPropSyms)
2614+
FOREACH_SLIST_ENTRY(CopyPropSyms, value, &bailOutInfo->usedCapturedValues->copyPropSyms)
26152615
{
26162616
Assert(value.Key()->HasByteCodeRegSlot() || value.Key()->GetInstrDef()->m_opcode == Js::OpCode::BytecodeArgOutCapture);
26172617
if (value.Key()->HasByteCodeRegSlot())
@@ -2620,9 +2620,9 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
26202620
}
26212621
}
26222622
NEXT_SLIST_ENTRY;
2623-
if (bailOutInfo->usedCapturedValues.argObjSyms)
2623+
if (bailOutInfo->usedCapturedValues->argObjSyms)
26242624
{
2625-
tempBv->Minus(bailOutInfo->usedCapturedValues.argObjSyms);
2625+
tempBv->Minus(bailOutInfo->usedCapturedValues->argObjSyms);
26262626
}
26272627

26282628
byteCodeUpwardExposedUsed->Or(tempBv);
@@ -8326,7 +8326,7 @@ BackwardPass::ReverseCopyProp(IR::Instr *instr)
83268326
FOREACH_SLISTBASE_ENTRY(
83278327
CopyPropSyms,
83288328
usedCopyPropSym,
8329-
&instrPrev->GetBailOutInfo()->usedCapturedValues.copyPropSyms)
8329+
&instrPrev->GetBailOutInfo()->usedCapturedValues->copyPropSyms)
83308330
{
83318331
if(dstSym == usedCopyPropSym.Value())
83328332
{

lib/Backend/BailOut.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,21 @@ BailOutInfo::Clear(JitArenaAllocator * allocator)
3030

3131
JitAdelete(allocator, this->capturedValues);
3232
}
33-
this->usedCapturedValues.constantValues.Clear(allocator);
34-
this->usedCapturedValues.copyPropSyms.Clear(allocator);
33+
34+
if (this->usedCapturedValues)
35+
{
36+
Assert(this->usedCapturedValues->refCount == 0);
37+
this->usedCapturedValues->constantValues.Clear(allocator);
38+
this->usedCapturedValues->copyPropSyms.Clear(allocator);
39+
40+
if (this->usedCapturedValues->argObjSyms)
41+
{
42+
JitAdelete(allocator, this->usedCapturedValues->argObjSyms);
43+
}
44+
45+
JitAdelete(allocator, this->usedCapturedValues);
46+
}
47+
3548
if (byteCodeUpwardExposedUsed)
3649
{
3750
JitAdelete(allocator, byteCodeUpwardExposedUsed);

lib/Backend/BailOut.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class BailOutInfo
4141
#endif
4242
this->capturedValues = JitAnew(bailOutFunc->m_alloc, CapturedValues);
4343
this->capturedValues->refCount = 1;
44-
this->usedCapturedValues.argObjSyms = nullptr;
44+
45+
this->usedCapturedValues = JitAnew(bailOutFunc->m_alloc, CapturedValues);
46+
this->usedCapturedValues->argObjSyms = nullptr;
4547
}
4648
void Clear(JitArenaAllocator * allocator);
4749

@@ -77,9 +79,9 @@ class BailOutInfo
7779
#endif
7880
uint32 bailOutOffset;
7981
BailOutRecord * bailOutRecord;
80-
CapturedValues* capturedValues; // Values we know about after forward pass
81-
CapturedValues usedCapturedValues; // Values that need to be restored in the bail out
82-
BVSparse<JitArenaAllocator> * byteCodeUpwardExposedUsed; // Non-constant stack syms that needs to be restored in the bail out
82+
CapturedValues * capturedValues; // Values we know about after forward pass
83+
CapturedValues * usedCapturedValues; // Values that need to be restored in the bail out
84+
BVSparse<JitArenaAllocator> * byteCodeUpwardExposedUsed; // Non-constant stack syms that needs to be restored in the bail out
8385
uint polymorphicCacheIndex;
8486
uint startCallCount;
8587
uint totalOutParamCount;

lib/Backend/LinearScan.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
14171417
memset(state.registerSaveSyms, 0, sizeof(state.registerSaveSyms));
14181418

14191419
// Fill in the constants
1420-
FOREACH_SLISTBASE_ENTRY_EDITING(ConstantStackSymValue, value, &bailOutInfo->usedCapturedValues.constantValues, constantValuesIterator)
1420+
FOREACH_SLISTBASE_ENTRY_EDITING(ConstantStackSymValue, value, &bailOutInfo->usedCapturedValues->constantValues, constantValuesIterator)
14211421
{
14221422
AssertMsg(bailOutInfo->bailOutRecord->bailOutKind != IR::BailOutForGeneratorYield, "constant prop syms unexpected for bail-in for generator yield");
14231423
StackSym * stackSym = value.Key();
@@ -1460,7 +1460,7 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
14601460
NEXT_SLISTBASE_ENTRY_EDITING;
14611461

14621462
// Fill in the copy prop syms
1463-
FOREACH_SLISTBASE_ENTRY_EDITING(CopyPropSyms, copyPropSyms, &bailOutInfo->usedCapturedValues.copyPropSyms, copyPropSymsIter)
1463+
FOREACH_SLISTBASE_ENTRY_EDITING(CopyPropSyms, copyPropSyms, &bailOutInfo->usedCapturedValues->copyPropSyms, copyPropSymsIter)
14641464
{
14651465
AssertMsg(bailOutInfo->bailOutRecord->bailOutKind != IR::BailOutForGeneratorYield, "copy prop syms unexpected for bail-in for generator yield");
14661466
StackSym * stackSym = copyPropSyms.Key();
@@ -1513,9 +1513,9 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
15131513
}
15141514
NEXT_BITSET_IN_SPARSEBV;
15151515

1516-
if (bailOutInfo->usedCapturedValues.argObjSyms)
1516+
if (bailOutInfo->usedCapturedValues->argObjSyms)
15171517
{
1518-
FOREACH_BITSET_IN_SPARSEBV(id, bailOutInfo->usedCapturedValues.argObjSyms)
1518+
FOREACH_BITSET_IN_SPARSEBV(id, bailOutInfo->usedCapturedValues->argObjSyms)
15191519
{
15201520
StackSym * stackSym = this->func->m_symTable->FindStackSym(id);
15211521
Assert(stackSym != nullptr);
@@ -1705,7 +1705,7 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
17051705
uint outParamOffsetIndex = outParamStart + argSlot;
17061706
if (!sym->m_isBailOutReferenced && !sym->IsArgSlotSym())
17071707
{
1708-
FOREACH_SLISTBASE_ENTRY_EDITING(ConstantStackSymValue, constantValue, &bailOutInfo->usedCapturedValues.constantValues, iterator)
1708+
FOREACH_SLISTBASE_ENTRY_EDITING(ConstantStackSymValue, constantValue, &bailOutInfo->usedCapturedValues->constantValues, iterator)
17091709
{
17101710
if (constantValue.Key()->m_id == sym->m_id)
17111711
{
@@ -1731,13 +1731,13 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
17311731
continue;
17321732
}
17331733

1734-
FOREACH_SLISTBASE_ENTRY_EDITING(CopyPropSyms, copyPropSym, &bailOutInfo->usedCapturedValues.copyPropSyms, iter)
1734+
FOREACH_SLISTBASE_ENTRY_EDITING(CopyPropSyms, copyPropSym, &bailOutInfo->usedCapturedValues->copyPropSyms, iter)
17351735
{
17361736
if (copyPropSym.Key()->m_id == sym->m_id)
17371737
{
17381738
StackSym * copyStackSym = copyPropSym.Value();
17391739

1740-
BVSparse<JitArenaAllocator>* argObjSyms = bailOutInfo->usedCapturedValues.argObjSyms;
1740+
BVSparse<JitArenaAllocator>* argObjSyms = bailOutInfo->usedCapturedValues->argObjSyms;
17411741
if (argObjSyms && argObjSyms->Test(copyStackSym->m_id))
17421742
{
17431743
outParamOffsets[outParamOffsetIndex] = BailOutRecord::GetArgumentsObjectOffset();
@@ -1845,7 +1845,7 @@ LinearScan::FillBailOutRecord(IR::Instr * instr)
18451845
Assert(LowererMD::IsAssign(instrDef));
18461846
}
18471847

1848-
if (bailOutInfo->usedCapturedValues.argObjSyms && bailOutInfo->usedCapturedValues.argObjSyms->Test(sym->m_id))
1848+
if (bailOutInfo->usedCapturedValues->argObjSyms && bailOutInfo->usedCapturedValues->argObjSyms->Test(sym->m_id))
18491849
{
18501850
//foo.apply(this,arguments) case and we bailout when the apply is overridden. We need to restore the arguments object.
18511851
outParamOffsets[outParamOffsetIndex] = BailOutRecord::GetArgumentsObjectOffset();

lib/Backend/SccLiveness.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ SCCLiveness::ProcessBailOutUses(IR::Instr * instr)
463463
}
464464
NEXT_BITSET_IN_SPARSEBV;
465465

466-
FOREACH_SLISTBASE_ENTRY(CopyPropSyms, copyPropSyms, &bailOutInfo->usedCapturedValues.copyPropSyms)
466+
FOREACH_SLISTBASE_ENTRY(CopyPropSyms, copyPropSyms, &bailOutInfo->usedCapturedValues->copyPropSyms)
467467
{
468468
ProcessStackSymUse(copyPropSyms.Value(), instr);
469469
}

0 commit comments

Comments
 (0)