Skip to content

Commit

Permalink
Merge pull request #15656 from ethereum/ssacfg_liveness_cjump
Browse files Browse the repository at this point in the history
SSACFG liveness: add conditional jump values to live set
  • Loading branch information
clonker authored Dec 19, 2024
2 parents 2fe4769 + 81f410f commit b6486db
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 77 deletions.
22 changes: 19 additions & 3 deletions libyul/backends/evm/SSACFGLiveness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include <libyul/backends/evm/SSACFGLiveness.h>

#include <libsolutil/Visitor.h>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/reverse.hpp>
Expand Down Expand Up @@ -87,9 +89,23 @@ void SSACFGLiveness::runDagDfs()
if (!m_topologicalSort.backEdge(blockId, _successor))
live += m_liveIns[_successor.value] - m_cfg.block(_successor).phis;
});
if (std::holds_alternative<SSACFG::BasicBlock::FunctionReturn>(block.exit))
live += std::get<SSACFG::BasicBlock::FunctionReturn>(block.exit).returnValues
| ranges::views::filter(literalsFilter(m_cfg));
util::GenericVisitor exitVisitor {
[](SSACFG::BasicBlock::MainExit const&) {},
[&](SSACFG::BasicBlock::FunctionReturn const& _functionReturn) {
live += _functionReturn.returnValues | ranges::views::filter(literalsFilter(m_cfg));
},
[&](SSACFG::BasicBlock::JumpTable const& _jt) {
if (literalsFilter(m_cfg)(_jt.value))
live.emplace(_jt.value);
},
[](SSACFG::BasicBlock::Jump const&) {},
[&](SSACFG::BasicBlock::ConditionalJump const& _conditionalJump) {
if (literalsFilter(m_cfg)(_conditionalJump.condition))
live.emplace(_conditionalJump.condition);
},
[](SSACFG::BasicBlock::Terminated const&) {}
};
std::visit(exitVisitor, block.exit);

// clean out unreachables
live = live | ranges::views::filter([&](auto const& valueId) { return !std::holds_alternative<SSACFG::UnreachableValue>(m_cfg.valueInfo(valueId)); }) | ranges::to<std::set>;
Expand Down
70 changes: 47 additions & 23 deletions test/cmdlineTests/standard_yul_cfg_json_export/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v2"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -188,7 +189,8 @@
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v5"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -260,7 +262,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v11"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -303,7 +306,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v12"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -361,7 +365,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v17"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -492,7 +497,8 @@
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v2"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -635,7 +641,8 @@
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v5"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -707,7 +714,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v11"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -750,7 +758,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v12"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -808,7 +817,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v17"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -903,7 +913,8 @@
"out": [
"v0",
"v18",
"v24"
"v24",
"v28"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -997,7 +1008,8 @@
"v24"
],
"out": [
"v41"
"v41",
"v42"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1153,7 +1165,9 @@
"v41"
],
"out": [
"v46"
"v46",
"v59",
"v60"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1224,10 +1238,12 @@
"instructions": [],
"liveness": {
"in": [
"v46"
"v46",
"v59"
],
"out": [
"v46"
"v46",
"v59"
]
}
},
Expand Down Expand Up @@ -1372,7 +1388,8 @@
"v46"
],
"out": [
"v46"
"v46",
"v67"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1480,7 +1497,8 @@
"out": [
"v46",
"v71",
"v77"
"v77",
"v80"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1570,7 +1588,8 @@
"v77"
],
"out": [
"v46"
"v46",
"v90"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1718,7 +1737,8 @@
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v2"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1861,7 +1881,8 @@
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v5"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1933,7 +1954,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v11"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -1976,7 +1998,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v12"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -2034,7 +2057,8 @@
"v0"
],
"out": [
"v0"
"v0",
"v17"
]
},
"type": "BuiltinCall"
Expand Down
15 changes: 10 additions & 5 deletions test/cmdlineTests/strict_asm_yul_cfg_json_export/output
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Yul Control Flow Graph:
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v2"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -188,7 +189,8 @@ Yul Control Flow Graph:
"liveness": {
"in": [],
"out": [
"v0"
"v0",
"v5"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -260,7 +262,8 @@ Yul Control Flow Graph:
"v0"
],
"out": [
"v0"
"v0",
"v11"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -303,7 +306,8 @@ Yul Control Flow Graph:
"v0"
],
"out": [
"v0"
"v0",
"v12"
]
},
"type": "BuiltinCall"
Expand Down Expand Up @@ -361,7 +365,8 @@ Yul Control Flow Graph:
"v0"
],
"out": [
"v0"
"v0",
"v17"
]
},
"type": "BuiltinCall"
Expand Down
Loading

0 comments on commit b6486db

Please sign in to comment.