Skip to content

Commit 3c94682

Browse files
authored
Merge pull request #15692 from ethereum/liveness_for_values_used_in_exit
SSACFG liveness: Adds exit liveness info to livein
2 parents 4939330 + 969c9ca commit 3c94682

File tree

9 files changed

+102
-143
lines changed

9 files changed

+102
-143
lines changed

libyul/backends/evm/SSACFGLiveness.cpp

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,10 @@ void SSACFGLiveness::runDagDfs()
8989
if (!m_topologicalSort.backEdge(blockId, _successor))
9090
live += m_liveIns[_successor.value] - m_cfg.block(_successor).phis;
9191
});
92-
util::GenericVisitor exitVisitor {
93-
[](SSACFG::BasicBlock::MainExit const&) {},
94-
[&](SSACFG::BasicBlock::FunctionReturn const& _functionReturn) {
95-
live += _functionReturn.returnValues | ranges::views::filter(literalsFilter(m_cfg));
96-
},
97-
[&](SSACFG::BasicBlock::JumpTable const& _jt) {
98-
if (literalsFilter(m_cfg)(_jt.value))
99-
live.emplace(_jt.value);
100-
},
101-
[](SSACFG::BasicBlock::Jump const&) {},
102-
[&](SSACFG::BasicBlock::ConditionalJump const& _conditionalJump) {
103-
if (literalsFilter(m_cfg)(_conditionalJump.condition))
104-
live.emplace(_conditionalJump.condition);
105-
},
106-
[](SSACFG::BasicBlock::Terminated const&) {}
107-
};
108-
std::visit(exitVisitor, block.exit);
92+
93+
if (std::holds_alternative<SSACFG::BasicBlock::FunctionReturn>(block.exit))
94+
live += std::get<SSACFG::BasicBlock::FunctionReturn>(block.exit).returnValues
95+
| ranges::views::filter(literalsFilter(m_cfg));
10996

11097
// clean out unreachables
11198
live = live | ranges::views::filter([&](auto const& valueId) { return !std::holds_alternative<SSACFG::UnreachableValue>(m_cfg.valueInfo(valueId)); }) | ranges::to<std::set>;
@@ -114,12 +101,33 @@ void SSACFGLiveness::runDagDfs()
114101
m_liveOuts[blockId.value] = live;
115102

116103
// for each program point p in B, backwards, do:
117-
for (auto const& op: block.operations | ranges::views::reverse)
118104
{
119-
// remove variables defined at p from live
120-
live -= op.outputs | ranges::views::filter(literalsFilter(m_cfg)) | ranges::to<std::vector>;
121-
// add uses at p to live
122-
live += op.inputs | ranges::views::filter(literalsFilter(m_cfg)) | ranges::to<std::vector>;
105+
// add value ids to the live set that are used in exit blocks
106+
util::GenericVisitor exitVisitor {
107+
[](SSACFG::BasicBlock::MainExit const&) {},
108+
[&](SSACFG::BasicBlock::FunctionReturn const& _functionReturn) {
109+
live += _functionReturn.returnValues | ranges::views::filter(literalsFilter(m_cfg));
110+
},
111+
[&](SSACFG::BasicBlock::JumpTable const& _jt) {
112+
if (literalsFilter(m_cfg)(_jt.value))
113+
live.emplace(_jt.value);
114+
},
115+
[](SSACFG::BasicBlock::Jump const&) {},
116+
[&](SSACFG::BasicBlock::ConditionalJump const& _conditionalJump) {
117+
if (literalsFilter(m_cfg)(_conditionalJump.condition))
118+
live.emplace(_conditionalJump.condition);
119+
},
120+
[](SSACFG::BasicBlock::Terminated const&) {}
121+
};
122+
std::visit(exitVisitor, block.exit);
123+
124+
for (auto const& op: block.operations | ranges::views::reverse)
125+
{
126+
// remove variables defined at p from live
127+
live -= op.outputs | ranges::views::filter(literalsFilter(m_cfg)) | ranges::to<std::vector>;
128+
// add uses at p to live
129+
live += op.inputs | ranges::views::filter(literalsFilter(m_cfg)) | ranges::to<std::vector>;
130+
}
123131
}
124132

125133
// livein(b) <- live \cup PhiDefs(B)

test/cmdlineTests/standard_yul_cfg_json_export/output.json

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@
4545
"liveness": {
4646
"in": [],
4747
"out": [
48-
"v0",
49-
"v2"
48+
"v0"
5049
]
5150
},
5251
"type": "BuiltinCall"
@@ -189,8 +188,7 @@
189188
"liveness": {
190189
"in": [],
191190
"out": [
192-
"v0",
193-
"v5"
191+
"v0"
194192
]
195193
},
196194
"type": "BuiltinCall"
@@ -262,8 +260,7 @@
262260
"v0"
263261
],
264262
"out": [
265-
"v0",
266-
"v11"
263+
"v0"
267264
]
268265
},
269266
"type": "BuiltinCall"
@@ -306,8 +303,7 @@
306303
"v0"
307304
],
308305
"out": [
309-
"v0",
310-
"v12"
306+
"v0"
311307
]
312308
},
313309
"type": "BuiltinCall"
@@ -365,8 +361,7 @@
365361
"v0"
366362
],
367363
"out": [
368-
"v0",
369-
"v17"
364+
"v0"
370365
]
371366
},
372367
"type": "BuiltinCall"
@@ -497,8 +492,7 @@
497492
"liveness": {
498493
"in": [],
499494
"out": [
500-
"v0",
501-
"v2"
495+
"v0"
502496
]
503497
},
504498
"type": "BuiltinCall"
@@ -641,8 +635,7 @@
641635
"liveness": {
642636
"in": [],
643637
"out": [
644-
"v0",
645-
"v5"
638+
"v0"
646639
]
647640
},
648641
"type": "BuiltinCall"
@@ -714,8 +707,7 @@
714707
"v0"
715708
],
716709
"out": [
717-
"v0",
718-
"v11"
710+
"v0"
719711
]
720712
},
721713
"type": "BuiltinCall"
@@ -758,8 +750,7 @@
758750
"v0"
759751
],
760752
"out": [
761-
"v0",
762-
"v12"
753+
"v0"
763754
]
764755
},
765756
"type": "BuiltinCall"
@@ -817,8 +808,7 @@
817808
"v0"
818809
],
819810
"out": [
820-
"v0",
821-
"v17"
811+
"v0"
822812
]
823813
},
824814
"type": "BuiltinCall"
@@ -913,8 +903,7 @@
913903
"out": [
914904
"v0",
915905
"v18",
916-
"v24",
917-
"v28"
906+
"v24"
918907
]
919908
},
920909
"type": "BuiltinCall"
@@ -1008,8 +997,7 @@
1008997
"v24"
1009998
],
1010999
"out": [
1011-
"v41",
1012-
"v42"
1000+
"v41"
10131001
]
10141002
},
10151003
"type": "BuiltinCall"
@@ -1166,8 +1154,7 @@
11661154
],
11671155
"out": [
11681156
"v46",
1169-
"v59",
1170-
"v60"
1157+
"v59"
11711158
]
11721159
},
11731160
"type": "BuiltinCall"
@@ -1242,8 +1229,7 @@
12421229
"v59"
12431230
],
12441231
"out": [
1245-
"v46",
1246-
"v59"
1232+
"v46"
12471233
]
12481234
}
12491235
},
@@ -1388,8 +1374,7 @@
13881374
"v46"
13891375
],
13901376
"out": [
1391-
"v46",
1392-
"v67"
1377+
"v46"
13931378
]
13941379
},
13951380
"type": "BuiltinCall"
@@ -1497,8 +1482,7 @@
14971482
"out": [
14981483
"v46",
14991484
"v71",
1500-
"v77",
1501-
"v80"
1485+
"v77"
15021486
]
15031487
},
15041488
"type": "BuiltinCall"
@@ -1588,8 +1572,7 @@
15881572
"v77"
15891573
],
15901574
"out": [
1591-
"v46",
1592-
"v90"
1575+
"v46"
15931576
]
15941577
},
15951578
"type": "BuiltinCall"
@@ -1737,8 +1720,7 @@
17371720
"liveness": {
17381721
"in": [],
17391722
"out": [
1740-
"v0",
1741-
"v2"
1723+
"v0"
17421724
]
17431725
},
17441726
"type": "BuiltinCall"
@@ -1881,8 +1863,7 @@
18811863
"liveness": {
18821864
"in": [],
18831865
"out": [
1884-
"v0",
1885-
"v5"
1866+
"v0"
18861867
]
18871868
},
18881869
"type": "BuiltinCall"
@@ -1954,8 +1935,7 @@
19541935
"v0"
19551936
],
19561937
"out": [
1957-
"v0",
1958-
"v11"
1938+
"v0"
19591939
]
19601940
},
19611941
"type": "BuiltinCall"
@@ -1998,8 +1978,7 @@
19981978
"v0"
19991979
],
20001980
"out": [
2001-
"v0",
2002-
"v12"
1981+
"v0"
20031982
]
20041983
},
20051984
"type": "BuiltinCall"
@@ -2057,8 +2036,7 @@
20572036
"v0"
20582037
],
20592038
"out": [
2060-
"v0",
2061-
"v17"
2039+
"v0"
20622040
]
20632041
},
20642042
"type": "BuiltinCall"

test/cmdlineTests/strict_asm_yul_cfg_json_export/output

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ Yul Control Flow Graph:
4545
"liveness": {
4646
"in": [],
4747
"out": [
48-
"v0",
49-
"v2"
48+
"v0"
5049
]
5150
},
5251
"type": "BuiltinCall"
@@ -189,8 +188,7 @@ Yul Control Flow Graph:
189188
"liveness": {
190189
"in": [],
191190
"out": [
192-
"v0",
193-
"v5"
191+
"v0"
194192
]
195193
},
196194
"type": "BuiltinCall"
@@ -262,8 +260,7 @@ Yul Control Flow Graph:
262260
"v0"
263261
],
264262
"out": [
265-
"v0",
266-
"v11"
263+
"v0"
267264
]
268265
},
269266
"type": "BuiltinCall"
@@ -306,8 +303,7 @@ Yul Control Flow Graph:
306303
"v0"
307304
],
308305
"out": [
309-
"v0",
310-
"v12"
306+
"v0"
311307
]
312308
},
313309
"type": "BuiltinCall"
@@ -365,8 +361,7 @@ Yul Control Flow Graph:
365361
"v0"
366362
],
367363
"out": [
368-
"v0",
369-
"v17"
364+
"v0"
370365
]
371366
},
372367
"type": "BuiltinCall"

0 commit comments

Comments
 (0)