Skip to content

Commit c1b4afd

Browse files
committed
[WIP] Implement live variable analysis
Signed-off-by: Adam Laszlo Kulcsar <[email protected]>
1 parent b947a7d commit c1b4afd

File tree

8 files changed

+2465
-112
lines changed

8 files changed

+2465
-112
lines changed

src/interpreter/ByteCode.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ class BinaryOperation : public ByteCode {
767767
const ByteCodeStackOffset* srcOffset() const { return m_srcOffset; }
768768
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
769769
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
770+
void setSrcOffset(ByteCodeStackOffset o, size_t index) { m_srcOffset[index] = o; }
770771
#if !defined(NDEBUG)
771772
void dump(size_t pos)
772773
{
@@ -809,6 +810,14 @@ class UnaryOperation : public ByteCode {
809810
}
810811
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
811812
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
813+
void setDstOffset(ByteCodeStackOffset newOffset)
814+
{
815+
m_dstOffset = newOffset;
816+
}
817+
void setSrcOffset(ByteCodeStackOffset newOffset)
818+
{
819+
m_srcOffset = newOffset;
820+
}
812821
#if !defined(NDEBUG)
813822
void dump(size_t pos)
814823
{
@@ -860,7 +869,9 @@ class Move : public ByteCode {
860869
}
861870

862871
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
872+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
863873
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
874+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
864875

865876
protected:
866877
ByteCodeStackOffset m_srcOffset;
@@ -1015,7 +1026,9 @@ class Load32 : public ByteCode {
10151026
}
10161027

10171028
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1029+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
10181030
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1031+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
10191032

10201033
#if !defined(NDEBUG)
10211034
void dump(size_t pos)
@@ -1067,7 +1080,9 @@ class Store32 : public ByteCode {
10671080
}
10681081

10691082
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1083+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
10701084
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1085+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
10711086

10721087
#if !defined(NDEBUG)
10731088
void dump(size_t pos)
@@ -1144,6 +1159,7 @@ class JumpIfTrue : public ByteCode {
11441159
}
11451160

11461161
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1162+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
11471163
int32_t offset() const { return m_offset; }
11481164
void setOffset(int32_t offset)
11491165
{
@@ -1174,6 +1190,7 @@ class JumpIfFalse : public ByteCode {
11741190
}
11751191

11761192
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1193+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
11771194
int32_t offset() const { return m_offset; }
11781195
void setOffset(int32_t offset)
11791196
{
@@ -1208,11 +1225,15 @@ class Select : public ByteCode {
12081225
}
12091226

12101227
ByteCodeStackOffset condOffset() const { return m_condOffset; }
1228+
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
12111229
uint16_t valueSize() const { return m_valueSize; }
12121230
bool isFloat() const { return m_isFloat != 0; }
12131231
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1232+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
12141233
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1234+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
12151235
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1236+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
12161237

12171238
#if !defined(NDEBUG)
12181239
void dump(size_t pos)
@@ -1245,6 +1266,7 @@ class BrTable : public ByteCode {
12451266
}
12461267

12471268
ByteCodeStackOffset condOffset() const { return m_condOffset; }
1269+
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
12481270
int32_t defaultOffset() const { return m_defaultOffset; }
12491271
static inline size_t offsetOfDefault() { return offsetof(BrTable, m_defaultOffset); }
12501272

@@ -1283,6 +1305,7 @@ class MemorySize : public ByteCode {
12831305
}
12841306

12851307
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1308+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
12861309

12871310
#if !defined(NDEBUG)
12881311
void dump(size_t pos)
@@ -1315,6 +1338,10 @@ class MemoryInit : public ByteCode {
13151338
{
13161339
return m_srcOffsets;
13171340
}
1341+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1342+
{
1343+
m_srcOffsets[idx] = o;
1344+
}
13181345

13191346
#if !defined(NDEBUG)
13201347
void dump(size_t pos)
@@ -1346,6 +1373,10 @@ class MemoryCopy : public ByteCode {
13461373
{
13471374
return m_srcOffsets;
13481375
}
1376+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1377+
{
1378+
m_srcOffsets[idx] = o;
1379+
}
13491380

13501381
#if !defined(NDEBUG)
13511382
void dump(size_t pos)
@@ -1373,6 +1404,10 @@ class MemoryFill : public ByteCode {
13731404
{
13741405
return m_srcOffsets;
13751406
}
1407+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1408+
{
1409+
m_srcOffsets[idx] = o;
1410+
}
13761411

13771412
#if !defined(NDEBUG)
13781413
void dump(size_t pos)
@@ -1423,7 +1458,9 @@ class MemoryGrow : public ByteCode {
14231458
}
14241459

14251460
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1461+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
14261462
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1463+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14271464

14281465
#if !defined(NDEBUG)
14291466
void dump(size_t pos)
@@ -1452,7 +1489,9 @@ class MemoryLoad : public ByteCode {
14521489

14531490
uint32_t offset() const { return m_offset; }
14541491
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1492+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
14551493
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1494+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14561495

14571496
#if !defined(NDEBUG)
14581497
void dump(size_t pos)
@@ -1481,8 +1520,11 @@ class SIMDMemoryLoad : public ByteCode {
14811520
uint32_t offset() const { return m_offset; }
14821521
ByteCodeStackOffset index() const { return m_index; }
14831522
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1523+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
14841524
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1525+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
14851526
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1527+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14861528

14871529
#if !defined(NDEBUG)
14881530
void dump(size_t pos)
@@ -1550,7 +1592,9 @@ class MemoryStore : public ByteCode {
15501592

15511593
uint32_t offset() const { return m_offset; }
15521594
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1595+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
15531596
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1597+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
15541598

15551599
#if !defined(NDEBUG)
15561600
void dump(size_t pos)
@@ -1577,8 +1621,11 @@ class SIMDMemoryStore : public ByteCode {
15771621

15781622
uint32_t offset() const { return m_offset; }
15791623
ByteCodeStackOffset index() const { return m_index; }
1624+
void setIndex(ByteCodeStackOffset o) { m_index = o; }
15801625
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1626+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
15811627
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1628+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
15821629

15831630
#if !defined(NDEBUG)
15841631
void dump(size_t pos)
@@ -1604,8 +1651,11 @@ class SIMDExtractLane : public ByteCode {
16041651
}
16051652

16061653
ByteCodeStackOffset index() const { return m_index; }
1654+
void setIndex(ByteCodeStackOffset o) { m_index = o; }
16071655
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1656+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
16081657
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1658+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
16091659

16101660
#if !defined(NDEBUG)
16111661
void dump(size_t pos)
@@ -1631,7 +1681,9 @@ class SIMDReplaceLane : public ByteCode {
16311681

16321682
uint32_t index() const { return m_index; }
16331683
const ByteCodeStackOffset* srcOffsets() const { return m_srcOffsets; }
1684+
void setSrcOffset(ByteCodeStackOffset o, size_t idx) { m_srcOffsets[idx] = o; }
16341685
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1686+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
16351687

16361688
#if !defined(NDEBUG)
16371689
void dump(size_t pos)
@@ -1954,7 +2006,12 @@ class V128BitSelect : public ByteCode {
19542006
{
19552007
return m_srcOffsets;
19562008
}
2009+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2010+
{
2011+
m_srcOffsets[idx] = o;
2012+
}
19572013
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2014+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
19582015

19592016
#if !defined(NDEBUG)
19602017
void dump(size_t pos)
@@ -2010,7 +2067,9 @@ class I8X16Shuffle : public ByteCode {
20102067
}
20112068

20122069
const ByteCodeStackOffset* srcOffsets() const { return m_srcOffsets; }
2070+
void setSrcOffset(ByteCodeStackOffset o, size_t idx) { m_srcOffsets[idx] = o; }
20132071
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2072+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
20142073
const uint8_t* value() const { return m_value; }
20152074

20162075
#if !defined(NDEBUG)
@@ -2037,7 +2096,9 @@ class TableGet : public ByteCode {
20372096

20382097
uint32_t tableIndex() const { return m_tableIndex; }
20392098
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
2099+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
20402100
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2101+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
20412102

20422103
#if !defined(NDEBUG)
20432104
void dump(size_t pos)
@@ -2066,7 +2127,9 @@ class TableSet : public ByteCode {
20662127
}
20672128

20682129
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
2130+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
20692131
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
2132+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
20702133
uint32_t tableIndex() const { return m_tableIndex; }
20712134

20722135
#if !defined(NDEBUG)
@@ -2098,8 +2161,11 @@ class TableGrow : public ByteCode {
20982161

20992162
uint32_t tableIndex() const { return m_tableIndex; }
21002163
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
2164+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
21012165
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
2166+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
21022167
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2168+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
21032169

21042170
#if !defined(NDEBUG)
21052171
void dump(size_t pos)
@@ -2130,6 +2196,7 @@ class TableSize : public ByteCode {
21302196

21312197
uint32_t tableIndex() const { return m_tableIndex; }
21322198
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2199+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
21332200

21342201
#if !defined(NDEBUG)
21352202
void dump(size_t pos)
@@ -2161,6 +2228,10 @@ class TableCopy : public ByteCode {
21612228
{
21622229
return m_srcOffsets;
21632230
}
2231+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2232+
{
2233+
m_srcOffsets[idx] = o;
2234+
}
21642235

21652236
#if !defined(NDEBUG)
21662237
void dump(size_t pos)
@@ -2193,6 +2264,11 @@ class TableFill : public ByteCode {
21932264
{
21942265
return m_srcOffsets;
21952266
}
2267+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2268+
{
2269+
m_srcOffsets[idx] = o;
2270+
}
2271+
21962272
#if !defined(NDEBUG)
21972273
void dump(size_t pos)
21982274
{
@@ -2225,6 +2301,11 @@ class TableInit : public ByteCode {
22252301
{
22262302
return m_srcOffsets;
22272303
}
2304+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2305+
{
2306+
m_srcOffsets[idx] = o;
2307+
}
2308+
22282309
#if !defined(NDEBUG)
22292310
void dump(size_t pos)
22302311
{
@@ -2276,6 +2357,7 @@ class RefFunc : public ByteCode {
22762357
}
22772358

22782359
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2360+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
22792361
uint32_t funcIndex() const { return m_funcIndex; }
22802362

22812363
#if !defined(NDEBUG)
@@ -2302,6 +2384,7 @@ class GlobalGet32 : public ByteCode {
23022384
}
23032385

23042386
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2387+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
23052388
uint32_t index() const { return m_index; }
23062389

23072390
#if !defined(NDEBUG)
@@ -2382,6 +2465,7 @@ class GlobalSet32 : public ByteCode {
23822465
{
23832466
}
23842467

2468+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
23852469
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
23862470
uint32_t index() const { return m_index; }
23872471

0 commit comments

Comments
 (0)