Skip to content

Commit 6abc058

Browse files
committed
Change usedCapturedValues in BailOutInfo to a pointer for consistency
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.
1 parent e2a9c77 commit 6abc058

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
@@ -1763,19 +1763,19 @@ BackwardPass::ProcessBailOutArgObj(BailOutInfo * bailOutInfo, BVSparse<JitArenaA
17631763
{
17641764
if (byteCodeUpwardExposedUsed->TestAndClear(symId))
17651765
{
1766-
if (bailOutInfo->usedCapturedValues.argObjSyms == nullptr)
1766+
if (bailOutInfo->usedCapturedValues->argObjSyms == nullptr)
17671767
{
1768-
bailOutInfo->usedCapturedValues.argObjSyms = JitAnew(this->func->m_alloc,
1768+
bailOutInfo->usedCapturedValues->argObjSyms = JitAnew(this->func->m_alloc,
17691769
BVSparse<JitArenaAllocator>, this->func->m_alloc);
17701770
}
1771-
bailOutInfo->usedCapturedValues.argObjSyms->Set(symId);
1771+
bailOutInfo->usedCapturedValues->argObjSyms->Set(symId);
17721772
}
17731773
}
17741774
NEXT_BITSET_IN_SPARSEBV;
17751775
}
1776-
if (bailOutInfo->usedCapturedValues.argObjSyms)
1776+
if (bailOutInfo->usedCapturedValues->argObjSyms)
17771777
{
1778-
byteCodeUpwardExposedUsed->Minus(bailOutInfo->usedCapturedValues.argObjSyms);
1778+
byteCodeUpwardExposedUsed->Minus(bailOutInfo->usedCapturedValues->argObjSyms);
17791779
}
17801780
}
17811781

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

17871787
// Remove constants that we are already going to restore
1788-
SListBase<ConstantStackSymValue> * usedConstantValues = &bailOutInfo->usedCapturedValues.constantValues;
1788+
SListBase<ConstantStackSymValue> * usedConstantValues = &bailOutInfo->usedCapturedValues->constantValues;
17891789
FOREACH_SLISTBASE_ENTRY(ConstantStackSymValue, value, usedConstantValues)
17901790
{
17911791
byteCodeUpwardExposedUsed->Clear(value.Key()->m_id);
@@ -1817,7 +1817,7 @@ BackwardPass::ProcessBailOutCopyProps(BailOutInfo * bailOutInfo, BVSparse<JitAre
18171817
Assert(!this->func->GetJITFunctionBody()->IsAsmJsMode());
18181818

18191819
// Remove copy prop that we were already going to restore
1820-
SListBase<CopyPropSyms> * usedCopyPropSyms = &bailOutInfo->usedCapturedValues.copyPropSyms;
1820+
SListBase<CopyPropSyms> * usedCopyPropSyms = &bailOutInfo->usedCapturedValues->copyPropSyms;
18211821
FOREACH_SLISTBASE_ENTRY(CopyPropSyms, copyPropSyms, usedCopyPropSyms)
18221822
{
18231823
byteCodeUpwardExposedUsed->Clear(copyPropSyms.Key()->m_id);
@@ -2596,7 +2596,7 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
25962596
tempBv->And(this->func->m_nonTempLocalVars, bailOutInfo->liveVarSyms);
25972597

25982598
// Remove syms that are restored in other ways than byteCodeUpwardExposedUsed.
2599-
FOREACH_SLIST_ENTRY(ConstantStackSymValue, value, &bailOutInfo->usedCapturedValues.constantValues)
2599+
FOREACH_SLIST_ENTRY(ConstantStackSymValue, value, &bailOutInfo->usedCapturedValues->constantValues)
26002600
{
26012601
Assert(value.Key()->HasByteCodeRegSlot() || value.Key()->GetInstrDef()->m_opcode == Js::OpCode::BytecodeArgOutCapture);
26022602
if (value.Key()->HasByteCodeRegSlot())
@@ -2605,7 +2605,7 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
26052605
}
26062606
}
26072607
NEXT_SLIST_ENTRY;
2608-
FOREACH_SLIST_ENTRY(CopyPropSyms, value, &bailOutInfo->usedCapturedValues.copyPropSyms)
2608+
FOREACH_SLIST_ENTRY(CopyPropSyms, value, &bailOutInfo->usedCapturedValues->copyPropSyms)
26092609
{
26102610
Assert(value.Key()->HasByteCodeRegSlot() || value.Key()->GetInstrDef()->m_opcode == Js::OpCode::BytecodeArgOutCapture);
26112611
if (value.Key()->HasByteCodeRegSlot())
@@ -2614,9 +2614,9 @@ BackwardPass::ProcessBailOutInfo(IR::Instr * instr, BailOutInfo * bailOutInfo)
26142614
}
26152615
}
26162616
NEXT_SLIST_ENTRY;
2617-
if (bailOutInfo->usedCapturedValues.argObjSyms)
2617+
if (bailOutInfo->usedCapturedValues->argObjSyms)
26182618
{
2619-
tempBv->Minus(bailOutInfo->usedCapturedValues.argObjSyms);
2619+
tempBv->Minus(bailOutInfo->usedCapturedValues->argObjSyms);
26202620
}
26212621

26222622
byteCodeUpwardExposedUsed->Or(tempBv);
@@ -8226,7 +8226,7 @@ BackwardPass::ReverseCopyProp(IR::Instr *instr)
82268226
FOREACH_SLISTBASE_ENTRY(
82278227
CopyPropSyms,
82288228
usedCopyPropSym,
8229-
&instrPrev->GetBailOutInfo()->usedCapturedValues.copyPropSyms)
8229+
&instrPrev->GetBailOutInfo()->usedCapturedValues->copyPropSyms)
82308230
{
82318231
if(dstSym == usedCopyPropSym.Value())
82328232
{

lib/Backend/BailOut.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,21 @@ BailOutInfo::Clear(JitArenaAllocator * allocator)
2424
this->capturedValues->copyPropSyms.Clear(allocator);
2525
JitAdelete(allocator, this->capturedValues);
2626
}
27-
this->usedCapturedValues.constantValues.Clear(allocator);
28-
this->usedCapturedValues.copyPropSyms.Clear(allocator);
27+
28+
if (this->usedCapturedValues)
29+
{
30+
Assert(this->usedCapturedValues->refCount == 0);
31+
this->usedCapturedValues->constantValues.Clear(allocator);
32+
this->usedCapturedValues->copyPropSyms.Clear(allocator);
33+
34+
if (this->usedCapturedValues->argObjSyms)
35+
{
36+
JitAdelete(allocator, this->usedCapturedValues->argObjSyms);
37+
}
38+
39+
JitAdelete(allocator, this->usedCapturedValues);
40+
}
41+
2942
if (byteCodeUpwardExposedUsed)
3043
{
3144
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)