Skip to content

Commit 889b81a

Browse files
committed
Implement live variable analysis
Implement the basics of variable life analysis. Define the range from start to end offset where a variable is used and allocates space for used variables. Also defines which variables need to be cleared before use. Also moves consant values to a lower offset on the stack if possibles. Signed-off-by: Adam Laszlo Kulcsar <[email protected]>
1 parent 75dc3e4 commit 889b81a

File tree

8 files changed

+2541
-165
lines changed

8 files changed

+2541
-165
lines changed

src/interpreter/ByteCode.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ class ByteCodeOffset2 : public ByteCode {
671671

672672
ByteCodeStackOffset stackOffset1() const { return m_stackOffset1; }
673673
ByteCodeStackOffset stackOffset2() const { return m_stackOffset2; }
674+
void setStackOffset1(ByteCodeStackOffset o) { m_stackOffset1 = o; }
675+
void setStackOffset2(ByteCodeStackOffset o) { m_stackOffset2 = o; }
674676

675677
protected:
676678
ByteCodeStackOffset m_stackOffset1;
@@ -687,6 +689,7 @@ class ByteCodeOffsetValue : public ByteCode {
687689
}
688690

689691
ByteCodeStackOffset stackOffset() const { return m_stackOffset; }
692+
void setStackOffset(ByteCodeStackOffset o) { m_stackOffset = o; }
690693
uint32_t uint32Value() const { return m_value; }
691694
int32_t int32Value() const { return static_cast<int32_t>(m_value); }
692695

@@ -802,6 +805,7 @@ class BinaryOperation : public ByteCode {
802805
const ByteCodeStackOffset* srcOffset() const { return m_srcOffset; }
803806
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
804807
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
808+
void setSrcOffset(ByteCodeStackOffset o, size_t index) { m_srcOffset[index] = o; }
805809
#if !defined(NDEBUG)
806810
void dump(size_t pos)
807811
{
@@ -1188,11 +1192,15 @@ class Select : public ByteCode {
11881192
}
11891193

11901194
ByteCodeStackOffset condOffset() const { return m_condOffset; }
1195+
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
11911196
uint16_t valueSize() const { return m_valueSize; }
11921197
bool isFloat() const { return m_isFloat != 0; }
11931198
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1199+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
11941200
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1201+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
11951202
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1203+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
11961204

11971205
#if !defined(NDEBUG)
11981206
void dump(size_t pos)
@@ -1225,6 +1233,7 @@ class BrTable : public ByteCode {
12251233
}
12261234

12271235
ByteCodeStackOffset condOffset() const { return m_condOffset; }
1236+
void setCondOffset(ByteCodeStackOffset o) { m_condOffset = o; }
12281237
int32_t defaultOffset() const { return m_defaultOffset; }
12291238
static inline size_t offsetOfDefault() { return offsetof(BrTable, m_defaultOffset); }
12301239

@@ -1263,6 +1272,7 @@ class MemorySize : public ByteCode {
12631272
}
12641273

12651274
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1275+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
12661276

12671277
#if !defined(NDEBUG)
12681278
void dump(size_t pos)
@@ -1295,6 +1305,10 @@ class MemoryInit : public ByteCode {
12951305
{
12961306
return m_srcOffsets;
12971307
}
1308+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1309+
{
1310+
m_srcOffsets[idx] = o;
1311+
}
12981312

12991313
#if !defined(NDEBUG)
13001314
void dump(size_t pos)
@@ -1326,6 +1340,10 @@ class MemoryCopy : public ByteCode {
13261340
{
13271341
return m_srcOffsets;
13281342
}
1343+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1344+
{
1345+
m_srcOffsets[idx] = o;
1346+
}
13291347

13301348
#if !defined(NDEBUG)
13311349
void dump(size_t pos)
@@ -1353,6 +1371,10 @@ class MemoryFill : public ByteCode {
13531371
{
13541372
return m_srcOffsets;
13551373
}
1374+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1375+
{
1376+
m_srcOffsets[idx] = o;
1377+
}
13561378

13571379
#if !defined(NDEBUG)
13581380
void dump(size_t pos)
@@ -1403,7 +1425,9 @@ class MemoryGrow : public ByteCode {
14031425
}
14041426

14051427
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1428+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
14061429
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1430+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14071431

14081432
#if !defined(NDEBUG)
14091433
void dump(size_t pos)
@@ -1432,7 +1456,9 @@ class MemoryLoad : public ByteCode {
14321456

14331457
uint32_t offset() const { return m_offset; }
14341458
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1459+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
14351460
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1461+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14361462

14371463
#if !defined(NDEBUG)
14381464
void dump(size_t pos)
@@ -1461,8 +1487,11 @@ class SIMDMemoryLoad : public ByteCode {
14611487
uint32_t offset() const { return m_offset; }
14621488
ByteCodeStackOffset index() const { return m_index; }
14631489
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1490+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
14641491
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1492+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
14651493
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1494+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
14661495

14671496
#if !defined(NDEBUG)
14681497
void dump(size_t pos)
@@ -1530,7 +1559,9 @@ class MemoryStore : public ByteCode {
15301559

15311560
uint32_t offset() const { return m_offset; }
15321561
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1562+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
15331563
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1564+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
15341565

15351566
#if !defined(NDEBUG)
15361567
void dump(size_t pos)
@@ -1557,8 +1588,11 @@ class SIMDMemoryStore : public ByteCode {
15571588

15581589
uint32_t offset() const { return m_offset; }
15591590
ByteCodeStackOffset index() const { return m_index; }
1591+
void setIndex(ByteCodeStackOffset o) { m_index = o; }
15601592
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
1593+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
15611594
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
1595+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
15621596

15631597
#if !defined(NDEBUG)
15641598
void dump(size_t pos)
@@ -1584,8 +1618,11 @@ class SIMDExtractLane : public ByteCode {
15841618
}
15851619

15861620
ByteCodeStackOffset index() const { return m_index; }
1621+
void setIndex(ByteCodeStackOffset o) { m_index = o; }
15871622
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
1623+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
15881624
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1625+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
15891626

15901627
#if !defined(NDEBUG)
15911628
void dump(size_t pos)
@@ -1611,7 +1648,9 @@ class SIMDReplaceLane : public ByteCode {
16111648

16121649
uint32_t index() const { return m_index; }
16131650
const ByteCodeStackOffset* srcOffsets() const { return m_srcOffsets; }
1651+
void setSrcOffset(ByteCodeStackOffset o, size_t idx) { m_srcOffsets[idx] = o; }
16141652
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1653+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
16151654

16161655
#if !defined(NDEBUG)
16171656
void dump(size_t pos)
@@ -1934,7 +1973,12 @@ class V128BitSelect : public ByteCode {
19341973
{
19351974
return m_srcOffsets;
19361975
}
1976+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
1977+
{
1978+
m_srcOffsets[idx] = o;
1979+
}
19371980
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
1981+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
19381982

19391983
#if !defined(NDEBUG)
19401984
void dump(size_t pos)
@@ -1990,7 +2034,9 @@ class I8X16Shuffle : public ByteCode {
19902034
}
19912035

19922036
const ByteCodeStackOffset* srcOffsets() const { return m_srcOffsets; }
2037+
void setSrcOffset(ByteCodeStackOffset o, size_t idx) { m_srcOffsets[idx] = o; }
19932038
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2039+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
19942040
const uint8_t* value() const { return m_value; }
19952041

19962042
#if !defined(NDEBUG)
@@ -2017,7 +2063,9 @@ class TableGet : public ByteCode {
20172063

20182064
uint32_t tableIndex() const { return m_tableIndex; }
20192065
ByteCodeStackOffset srcOffset() const { return m_srcOffset; }
2066+
void setSrcOffset(ByteCodeStackOffset o) { m_srcOffset = o; }
20202067
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2068+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
20212069

20222070
#if !defined(NDEBUG)
20232071
void dump(size_t pos)
@@ -2046,7 +2094,9 @@ class TableSet : public ByteCode {
20462094
}
20472095

20482096
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
2097+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
20492098
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
2099+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
20502100
uint32_t tableIndex() const { return m_tableIndex; }
20512101

20522102
#if !defined(NDEBUG)
@@ -2078,8 +2128,11 @@ class TableGrow : public ByteCode {
20782128

20792129
uint32_t tableIndex() const { return m_tableIndex; }
20802130
ByteCodeStackOffset src0Offset() const { return m_src0Offset; }
2131+
void setSrc0Offset(ByteCodeStackOffset o) { m_src0Offset = o; }
20812132
ByteCodeStackOffset src1Offset() const { return m_src1Offset; }
2133+
void setSrc1Offset(ByteCodeStackOffset o) { m_src1Offset = o; }
20822134
ByteCodeStackOffset dstOffset() const { return m_dstOffset; }
2135+
void setDstOffset(ByteCodeStackOffset o) { m_dstOffset = o; }
20832136

20842137
#if !defined(NDEBUG)
20852138
void dump(size_t pos)
@@ -2135,6 +2188,10 @@ class TableCopy : public ByteCode {
21352188
{
21362189
return m_srcOffsets;
21372190
}
2191+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2192+
{
2193+
m_srcOffsets[idx] = o;
2194+
}
21382195

21392196
#if !defined(NDEBUG)
21402197
void dump(size_t pos)
@@ -2167,6 +2224,11 @@ class TableFill : public ByteCode {
21672224
{
21682225
return m_srcOffsets;
21692226
}
2227+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2228+
{
2229+
m_srcOffsets[idx] = o;
2230+
}
2231+
21702232
#if !defined(NDEBUG)
21712233
void dump(size_t pos)
21722234
{
@@ -2199,6 +2261,11 @@ class TableInit : public ByteCode {
21992261
{
22002262
return m_srcOffsets;
22012263
}
2264+
void setSrcOffset(ByteCodeStackOffset o, size_t idx)
2265+
{
2266+
m_srcOffsets[idx] = o;
2267+
}
2268+
22022269
#if !defined(NDEBUG)
22032270
void dump(size_t pos)
22042271
{

0 commit comments

Comments
 (0)