Skip to content

Commit 4fc330b

Browse files
committed
Implement live variable analysis
Implement live variable analysis for function parameters, variables and constants. Define the range from start to end offset where a variable is used and allocate space for used variables. Also define which variables need to be cleared before use. Move constant values to a lower offset on the stack if possibles. Signed-off-by: Adam Laszlo Kulcsar <[email protected]>
1 parent 7f492b3 commit 4fc330b

File tree

8 files changed

+2921
-171
lines changed

8 files changed

+2921
-171
lines changed

src/interpreter/ByteCode.h

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ class ByteCodeOffset2 : public ByteCode {
699699

700700
ByteCodeStackOffset stackOffset1() const { return m_stackOffset1; }
701701
ByteCodeStackOffset stackOffset2() const { return m_stackOffset2; }
702+
void setStackOffset1(ByteCodeStackOffset o) { m_stackOffset1 = o; }
703+
void setStackOffset2(ByteCodeStackOffset o) { m_stackOffset2 = o; }
702704

703705
protected:
704706
ByteCodeStackOffset m_stackOffset1;
@@ -732,6 +734,7 @@ class ByteCodeOffsetValue : public ByteCode {
732734
}
733735

734736
ByteCodeStackOffset stackOffset() const { return m_stackOffset; }
737+
void setStackOffset(ByteCodeStackOffset o) { m_stackOffset = o; }
735738
uint32_t uint32Value() const { return m_value; }
736739
int32_t int32Value() const { return static_cast<int32_t>(m_value); }
737740

@@ -911,6 +914,7 @@ class BinaryOperation : public ByteCodeOffset3 {
911914
const ByteCodeStackOffset* srcOffset() const { return stackOffsets(); }
912915
ByteCodeStackOffset dstOffset() const { return stackOffset3(); }
913916
void setDstOffset(ByteCodeStackOffset o) { m_stackOffsets[2] = o; }
917+
void setSrcOffset(ByteCodeStackOffset o, size_t index) { m_stackOffsets[index] = o; }
914918
#if !defined(NDEBUG)
915919
void dump(size_t pos)
916920
{
@@ -984,6 +988,16 @@ class TernaryOperation : public ByteCodeOffset4 {
984988
{
985989
}
986990

991+
void setDstOffset(ByteCodeStackOffset o)
992+
{
993+
m_stackOffsets[3] = o;
994+
}
995+
996+
void setStackOffset(ByteCodeStackOffset o, uint32_t index)
997+
{
998+
m_stackOffsets[index] = o;
999+
}
1000+
9871001
#if !defined(NDEBUG)
9881002
void dump(size_t pos)
9891003
{
@@ -1120,6 +1134,7 @@ class CallIndirect : public ByteCode {
11201134
}
11211135

11221136
ByteCodeStackOffset calleeOffset() const { return m_calleeOffset; }
1137+
void setCalleeOffset(ByteCodeStackOffset o) { m_calleeOffset = o; }
11231138
uint32_t tableIndex() const { return m_tableIndex; }
11241139
FunctionType* functionType() const { return m_functionType; }
11251140
ByteCodeStackOffset* stackOffsets() const
@@ -1334,11 +1349,15 @@ class Select : public ByteCode {
13341349
}
13351350

13361351
ByteCodeStackOffset condOffset() const { return m_condOffset; }
1352+
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
13371353
uint16_t valueSize() const { return m_valueSize; }
13381354
bool isFloat() const { return m_isFloat != 0; }
13391355
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1356+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
13401357
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1358+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
13411359
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1360+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
13421361

13431362
#if !defined(NDEBUG)
13441363
void dump(size_t pos)
@@ -1371,6 +1390,7 @@ class BrTable : public ByteCode {
13711390
}
13721391

13731392
ByteCodeStackOffset condOffset() const { return m_condOffset; }
1393+
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
13741394
int32_t defaultOffset() const { return m_defaultOffset; }
13751395
static inline size_t offsetOfDefault() { return offsetof(BrTable, m_defaultOffset); }
13761396

@@ -1409,6 +1429,7 @@ class MemorySize : public ByteCode {
14091429
}
14101430

14111431
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1432+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14121433

14131434
#if !defined(NDEBUG)
14141435
void dump(size_t pos)
@@ -1441,6 +1462,10 @@ class MemoryInit : public ByteCode {
14411462
{
14421463
return m_srcOffsets;
14431464
}
1465+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1466+
{
1467+
m_srcOffsets[idx] = o;
1468+
}
14441469

14451470
#if !defined(NDEBUG)
14461471
void dump(size_t pos)
@@ -1471,6 +1496,10 @@ class MemoryCopy : public ByteCodeOffset3 {
14711496
{
14721497
return stackOffsets();
14731498
}
1499+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1500+
{
1501+
m_stackOffsets[idx] = o;
1502+
}
14741503

14751504
#if !defined(NDEBUG)
14761505
void dump(size_t pos)
@@ -1495,6 +1524,10 @@ class MemoryFill : public ByteCodeOffset3 {
14951524
{
14961525
return stackOffsets();
14971526
}
1527+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1528+
{
1529+
m_stackOffsets[idx] = o;
1530+
}
14981531

14991532
#if !defined(NDEBUG)
15001533
void dump(size_t pos)
@@ -1541,7 +1574,9 @@ class MemoryGrow : public ByteCodeOffset2 {
15411574
}
15421575

15431576
ByteCodeStackOffset srcOffset() const { return stackOffset1(); }
1577+
void setSrcOffset(ByteCodeStackOffset o) { m_stackOffset1 = o; }
15441578
ByteCodeStackOffset dstOffset() const { return stackOffset2(); }
1579+
void setDstOffset(ByteCodeStackOffset o) { m_stackOffset2 = o; }
15451580

15461581
#if !defined(NDEBUG)
15471582
void dump(size_t pos)
@@ -1564,6 +1599,8 @@ class MemoryLoad : public ByteCodeOffset2Value {
15641599
uint32_t offset() const { return uint32Value(); }
15651600
ByteCodeStackOffset srcOffset() const { return stackOffset1(); }
15661601
ByteCodeStackOffset dstOffset() const { return stackOffset2(); }
1602+
void setSrcOffset(ByteCodeStackOffset o) { m_stackOffset1 = o; }
1603+
void setDstOffset(ByteCodeStackOffset o) { m_stackOffset2 = o; }
15671604

15681605
#if !defined(NDEBUG)
15691606
void dump(size_t pos)
@@ -1588,8 +1625,11 @@ class SIMDMemoryLoad : public ByteCode {
15881625
uint32_t offset() const { return m_offset; }
15891626
ByteCodeStackOffset index() const { return m_index; }
15901627
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1628+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
15911629
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1630+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
15921631
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1632+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
15931633

15941634
#if !defined(NDEBUG)
15951635
void dump(size_t pos)
@@ -1655,6 +1695,8 @@ class MemoryStore : public ByteCodeOffset2Value {
16551695
uint32_t offset() const { return uint32Value(); }
16561696
ByteCodeStackOffset src0Offset() const { return stackOffset1(); }
16571697
ByteCodeStackOffset src1Offset() const { return stackOffset2(); }
1698+
void setSrc0Offset(ByteCodeStackOffset o) { m_stackOffset1 = o; }
1699+
void setSrc1Offset(ByteCodeStackOffset o) { m_stackOffset2 = o; }
16581700

16591701
#if !defined(NDEBUG)
16601702
void dump(size_t pos)
@@ -1677,8 +1719,11 @@ class SIMDMemoryStore : public ByteCode {
16771719

16781720
uint32_t offset() const { return m_offset; }
16791721
ByteCodeStackOffset index() const { return m_index; }
1722+
void setIndex(ByteCodeStackOffset o) { m_index = o; }
16801723
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1724+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
16811725
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1726+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
16821727

16831728
#if !defined(NDEBUG)
16841729
void dump(size_t pos)
@@ -1704,8 +1749,11 @@ class SIMDExtractLane : public ByteCode {
17041749
}
17051750

17061751
ByteCodeStackOffset index() const { return m_index; }
1752+
void setIndex(ByteCodeStackOffset o) { m_index = o; }
17071753
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1754+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
17081755
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1756+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
17091757

17101758
#if !defined(NDEBUG)
17111759
void dump(size_t pos)
@@ -1731,7 +1779,9 @@ class SIMDReplaceLane : public ByteCode {
17311779

17321780
uint32_t index() const { return m_index; }
17331781
const ByteCodeStackOffset* srcOffsets() const { return m_srcOffsets; }
1782+
void setSrcOffset(ByteCodeStackOffset o, size_t idx) { m_srcOffsets[idx] = o; }
17341783
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1784+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
17351785

17361786
#if !defined(NDEBUG)
17371787
void dump(size_t pos)
@@ -2011,6 +2061,14 @@ class V128BitSelect : public ByteCodeOffset4 {
20112061
{
20122062
}
20132063

2064+
2065+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2066+
{
2067+
m_stackOffsets[idx] = o;
2068+
}
2069+
2070+
void setDstOffset(ByteCodeStackOffset o) { m_stackOffsets[3] = o; }
2071+
20142072
#if !defined(NDEBUG)
20152073
void dump(size_t pos)
20162074
{
@@ -2061,7 +2119,9 @@ class I8X16Shuffle : public ByteCode {
20612119
}
20622120

20632121
const ByteCodeStackOffset* srcOffsets() const { return m_srcOffsets; }
2122+
void setSrcOffset(ByteCodeStackOffset o, size_t idx) { m_srcOffsets[idx] = o; }
20642123
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2124+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
20652125
const uint8_t* value() const { return m_value; }
20662126

20672127
#if !defined(NDEBUG)
@@ -2087,6 +2147,9 @@ class TableGet : public ByteCodeOffset2Value {
20872147
ByteCodeStackOffset dstOffset() const { return stackOffset2(); }
20882148
uint32_t tableIndex() const { return uint32Value(); }
20892149

2150+
void setSrcOffset(ByteCodeStackOffset o) { m_stackOffset1 = o; }
2151+
void setDstOffset(ByteCodeStackOffset o) { m_stackOffset2 = o; }
2152+
20902153
#if !defined(NDEBUG)
20912154
void dump(size_t pos)
20922155
{
@@ -2105,9 +2168,12 @@ class TableSet : public ByteCodeOffset2Value {
21052168
{
21062169
}
21072170

2171+
21082172
ByteCodeStackOffset src0Offset() const { return stackOffset1(); }
21092173
ByteCodeStackOffset src1Offset() const { return stackOffset2(); }
21102174
uint32_t tableIndex() const { return uint32Value(); }
2175+
void setSrc0Offset(ByteCodeStackOffset o) { m_stackOffset1 = o; }
2176+
void setSrc1Offset(ByteCodeStackOffset o) { m_stackOffset2 = o; }
21112177

21122178
#if !defined(NDEBUG)
21132179
void dump(size_t pos)
@@ -2133,8 +2199,11 @@ class TableGrow : public ByteCode {
21332199

21342200
uint32_t tableIndex() const { return m_tableIndex; }
21352201
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
2202+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
21362203
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
2204+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
21372205
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2206+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
21382207

21392208
#if !defined(NDEBUG)
21402209
void dump(size_t pos)
@@ -2190,6 +2259,10 @@ class TableCopy : public ByteCode {
21902259
{
21912260
return m_srcOffsets;
21922261
}
2262+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2263+
{
2264+
m_srcOffsets[idx] = o;
2265+
}
21932266

21942267
#if !defined(NDEBUG)
21952268
void dump(size_t pos)
@@ -2222,6 +2295,11 @@ class TableFill : public ByteCode {
22222295
{
22232296
return m_srcOffsets;
22242297
}
2298+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2299+
{
2300+
m_srcOffsets[idx] = o;
2301+
}
2302+
22252303
#if !defined(NDEBUG)
22262304
void dump(size_t pos)
22272305
{
@@ -2254,6 +2332,11 @@ class TableInit : public ByteCode {
22542332
{
22552333
return m_srcOffsets;
22562334
}
2335+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2336+
{
2337+
m_srcOffsets[idx] = o;
2338+
}
2339+
22572340
#if !defined(NDEBUG)
22582341
void dump(size_t pos)
22592342
{

0 commit comments

Comments
 (0)