Skip to content

Commit f9214e8

Browse files
committed
Implement GeneratorBailInInstr - special label that holds relevant information for a bail-in point
1 parent cfbfcbc commit f9214e8

File tree

3 files changed

+96
-3
lines changed

3 files changed

+96
-3
lines changed

lib/Backend/IR.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,14 @@ bool Instr::UnaryCalculator(IntConstType src1Const, IntConstType *pResult, IRTyp
42474247
return true;
42484248
}
42494249

4250+
GeneratorBailInInstr*
4251+
GeneratorBailInInstr::New(IR::Instr* yieldInstr, Func* func)
4252+
{
4253+
GeneratorBailInInstr* labelInstr = JitAnew(func->m_alloc, IR::GeneratorBailInInstr, func->m_alloc, yieldInstr);
4254+
labelInstr->Init(Js::OpCode::GeneratorBailInLabel, InstrKindLabel, func, false /* isOpHelper */);
4255+
return labelInstr;
4256+
}
4257+
42504258
#if ENABLE_DEBUG_CONFIG_OPTIONS
42514259
///----------------------------------------------------------------------------
42524260
///

lib/Backend/IR.h

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class IRBuilderAsmJs;
1515
class FlowGraph;
1616
class GlobOpt;
1717
class BailOutInfo;
18+
class GeneratorBailInInfo;
1819
class SCCLiveness;
1920

2021
struct LazyBailOutRecord;
@@ -53,7 +54,7 @@ struct CapturedValues
5354
refCount++;
5455
}
5556

56-
void CopyTo(JitArenaAllocator *allocator, CapturedValues *other)
57+
void CopyTo(JitArenaAllocator *allocator, CapturedValues *other) const
5758
{
5859
Assert(other != nullptr);
5960
this->constantValues.CopyTo(allocator, other->constantValues);
@@ -117,6 +118,7 @@ class ProfiledLabelInstr;
117118
class MultiBranchInstr;
118119
class PragmaInstr;
119120
class ByteCodeUsesInstr;
121+
class GeneratorBailInInstr;
120122

121123
class Opnd;
122124
class RegOpnd;
@@ -154,8 +156,8 @@ const int32 InvalidInstrLayout = -1;
154156
/// ExitInstr
155157
/// PragmaInstr
156158
/// BailoutInstr
157-
/// ByteCoteUsesInstr
158-
///
159+
/// ByteCodeUsesInstr
160+
/// GeneratorBailInInstr
159161
///---------------------------------------------------------------------------
160162

161163
class Instr
@@ -220,6 +222,9 @@ class Instr
220222
BranchInstr * AsBranchInstr();
221223
bool IsLabelInstr() const;
222224
LabelInstr * AsLabelInstr();
225+
bool IsGeneratorBailInInstr() const;
226+
GeneratorBailInInstr * AsGeneratorBailInInstr();
227+
223228
bool IsJitProfilingInstr() const;
224229
JitProfilingInstr * AsJitProfilingInstr();
225230
bool IsProfiledInstr() const;
@@ -1109,6 +1114,58 @@ class PragmaInstr : public Instr
11091114
PragmaInstr * CopyPragma();
11101115
};
11111116

1117+
class GeneratorBailInInstr : public LabelInstr
1118+
{
1119+
private:
1120+
GeneratorBailInInstr(JitArenaAllocator* allocator, IR::Instr* yieldInstr):
1121+
LabelInstr(allocator), allocator(allocator), yieldInstr(yieldInstr), upwardExposedUses(allocator)
1122+
{
1123+
Assert(yieldInstr != nullptr && yieldInstr->m_opcode == Js::OpCode::Yield);
1124+
this->usedCapturedValues = JitAnew(allocator, CapturedValues);
1125+
}
1126+
1127+
JitArenaAllocator* const allocator;
1128+
IR::Instr* const yieldInstr;
1129+
CapturedValues* usedCapturedValues;
1130+
BVSparse<JitArenaAllocator> upwardExposedUses;
1131+
1132+
public:
1133+
static GeneratorBailInInstr* New(IR::Instr* yieldInstr, Func* func);
1134+
1135+
IR::Instr* GetYieldInstr() const
1136+
{
1137+
return this->yieldInstr;
1138+
}
1139+
1140+
const CapturedValues& GetCapturedValues() const
1141+
{
1142+
return *this->usedCapturedValues;
1143+
}
1144+
1145+
const BVSparse<JitArenaAllocator>& GetUpwardExposedUses() const
1146+
{
1147+
return this->upwardExposedUses;
1148+
}
1149+
1150+
void SetCopyPropSyms(const SListBase<CopyPropSyms>& copyPropSyms)
1151+
{
1152+
this->usedCapturedValues->copyPropSyms.Clear(this->allocator);
1153+
copyPropSyms.CopyTo(this->allocator , this->usedCapturedValues->copyPropSyms);
1154+
}
1155+
1156+
void SetConstantValues(const SListBase<ConstantStackSymValue>& constantValues)
1157+
{
1158+
this->usedCapturedValues->constantValues.Clear(this->allocator);
1159+
constantValues.CopyTo(this->allocator, this->usedCapturedValues->constantValues);
1160+
}
1161+
1162+
void SetUpwardExposedUses(const BVSparse<JitArenaAllocator>& other)
1163+
{
1164+
this->upwardExposedUses.ClearAll();
1165+
this->upwardExposedUses.Or(&other);
1166+
}
1167+
};
1168+
11121169
template <typename InstrType>
11131170
class BailOutInstrTemplate : public InstrType
11141171
{

lib/Backend/IR.inl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,34 @@ Instr::AsLabelInstr()
124124
return reinterpret_cast<LabelInstr *>(this);
125125
}
126126

127+
///----------------------------------------------------------------------------
128+
///
129+
/// Instr::IsGeneratorBailInInstr
130+
///
131+
///----------------------------------------------------------------------------
132+
133+
__forceinline bool
134+
Instr::IsGeneratorBailInInstr() const
135+
{
136+
return this->m_opcode == Js::OpCode::GeneratorBailInLabel;
137+
}
138+
139+
///----------------------------------------------------------------------------
140+
///
141+
/// Instr::AsGeneratorBailInInstr
142+
///
143+
/// Return this as a GeneratorBailInInstr *
144+
///
145+
///----------------------------------------------------------------------------
146+
147+
inline GeneratorBailInInstr*
148+
Instr::AsGeneratorBailInInstr()
149+
{
150+
AssertMsg(this->IsGeneratorBailInInstr(), "Bad call to AsGeneratorBailInInstr()");
151+
152+
return reinterpret_cast<GeneratorBailInInstr*>(this);
153+
}
154+
127155
///----------------------------------------------------------------------------
128156
///
129157
/// Instr::AsMultiBrInstr

0 commit comments

Comments
 (0)