@@ -31,18 +31,11 @@ using namespace solidity::yul::ssa;
3131
3232namespace
3333{
34- constexpr auto excludingLiteralsFilter (SSACFG const & _cfg )
34+ constexpr auto excludingLiteralsFilter ()
3535{
36- return [&_cfg ](LivenessAnalysis::LivenessData::Value const & _valueId) -> bool
36+ return [](LivenessAnalysis::LivenessData::Value const & _valueId) -> bool
3737 {
38- return !std::holds_alternative<SSACFG::LiteralValue>(_cfg.valueInfo (_valueId));
39- };
40- }
41- constexpr auto unreachableFilter (SSACFG const & _cfg)
42- {
43- return [&_cfg](LivenessAnalysis::LivenessData::Value const & _valueId) -> bool
44- {
45- return std::holds_alternative<SSACFG::UnreachableValue>(_cfg.valueInfo (_valueId));
38+ return !_valueId.isLiteral ();
4639 };
4740}
4841}
@@ -149,18 +142,18 @@ LivenessAnalysis::LivenessData LivenessAnalysis::blockExitValues(SSACFG::BlockId
149142 [](SSACFG::BasicBlock::MainExit const &) {},
150143 [&](SSACFG::BasicBlock::FunctionReturn const & _functionReturn)
151144 {
152- for (auto const & valueId: _functionReturn.returnValues | ranges::views::filter (excludingLiteralsFilter (m_cfg )))
145+ for (auto const & valueId: _functionReturn.returnValues | ranges::views::filter (excludingLiteralsFilter ()))
153146 result.insert (valueId);
154147 },
155148 [&](SSACFG::BasicBlock::JumpTable const & _jt)
156149 {
157- if (excludingLiteralsFilter (m_cfg )(_jt.value ))
150+ if (excludingLiteralsFilter ()(_jt.value ))
158151 result.insert (_jt.value );
159152 },
160153 [](SSACFG::BasicBlock::Jump const &) {},
161154 [&](SSACFG::BasicBlock::ConditionalJump const & _conditionalJump)
162155 {
163- if (excludingLiteralsFilter (m_cfg )(_conditionalJump.condition ))
156+ if (excludingLiteralsFilter ()(_conditionalJump.condition ))
164157 result.insert (_conditionalJump.condition );
165158 },
166159 [](SSACFG::BasicBlock::Terminated const &) {}};
@@ -218,12 +211,11 @@ void LivenessAnalysis::runDagDfs()
218211 {
219212 for (auto const & phi: m_cfg.block (_successor).phis )
220213 {
221- auto const & info = m_cfg.valueInfo (phi);
222- yulAssert (std::holds_alternative<SSACFG::PhiValue>(info), " value info of phi wasn't PhiValue" );
223- auto const argIndex = m_cfg.phiArgumentIndex (blockId, _successor);
224- yulAssert (argIndex < std::get<SSACFG::PhiValue>(info).arguments .size ());
225- auto const arg = std::get<SSACFG::PhiValue>(info).arguments .at (argIndex);
226- if (!std::holds_alternative<SSACFG::LiteralValue>(m_cfg.valueInfo (arg)))
214+ auto const & info = m_cfg.phiInfo (phi);
215+ auto const & argIndex = m_cfg.phiArgumentIndex (blockId, _successor);
216+ yulAssert (argIndex < info.arguments .size ());
217+ auto const & arg = info.arguments .at (argIndex);
218+ if (!arg.isLiteral ())
227219 live.insert (arg);
228220 }
229221 });
@@ -242,11 +234,11 @@ void LivenessAnalysis::runDagDfs()
242234 });
243235
244236 if (std::holds_alternative<SSACFG::BasicBlock::FunctionReturn>(block.exit ))
245- for (auto const & returnValue: std::get<SSACFG::BasicBlock::FunctionReturn>(block.exit ).returnValues | ranges::views::filter (excludingLiteralsFilter (m_cfg )))
237+ for (auto const & returnValue: std::get<SSACFG::BasicBlock::FunctionReturn>(block.exit ).returnValues | ranges::views::filter (excludingLiteralsFilter ()))
246238 live.insert (returnValue);
247239
248240 // clean out unreachables
249- live.eraseIf ([&](auto const & _entry) { return unreachableFilter (m_cfg)( _entry.first ); });
241+ live.eraseIf ([&](auto const & _entry) { return _entry.first . isUnreachable ( ); });
250242
251243 // LiveOut(B) <- live
252244 m_liveOuts[blockId.value ] = live;
@@ -259,9 +251,9 @@ void LivenessAnalysis::runDagDfs()
259251 for (auto const & op: block.operations | ranges::views::reverse)
260252 {
261253 // remove variables defined at p from live
262- live.eraseAll (op.outputs | ranges::views::filter (excludingLiteralsFilter (m_cfg )) | ranges::to<std::vector>);
254+ live.eraseAll (op.outputs | ranges::views::filter (excludingLiteralsFilter ()) | ranges::to<std::vector>);
263255 // add uses at p to live
264- live.insertAll (op.inputs | ranges::views::filter (excludingLiteralsFilter (m_cfg )) | ranges::to<std::vector>);
256+ live.insertAll (op.inputs | ranges::views::filter (excludingLiteralsFilter ()) | ranges::to<std::vector>);
265257 }
266258 }
267259
@@ -272,7 +264,7 @@ void LivenessAnalysis::runDagDfs()
272264 }
273265}
274266
275- void LivenessAnalysis::runLoopTreeDfs (size_t const _loopHeader)
267+ void LivenessAnalysis::runLoopTreeDfs (SSACFG::BlockId::ValueType const _loopHeader)
276268{
277269 // SSA Book, Algorithm 9.3
278270 if (m_loopNestingForest.loopNodes ().contains (_loopHeader))
@@ -286,7 +278,7 @@ void LivenessAnalysis::runLoopTreeDfs(size_t const _loopHeader)
286278 // must be live out of header if live in of children
287279 m_liveOuts[_loopHeader].maxUnion (liveLoop);
288280 // for each blockId \in children(loopHeader)
289- for (size_t blockIdValue = 0 ; blockIdValue < m_cfg.numBlocks (); ++blockIdValue)
281+ for (SSACFG::BlockId::ValueType blockIdValue = 0u ; blockIdValue < m_cfg.numBlocks (); ++blockIdValue)
290282 if (m_loopNestingForest.loopParents ()[blockIdValue] == _loopHeader)
291283 {
292284 // propagate loop liveness information down to the loop header's children
@@ -313,9 +305,9 @@ void LivenessAnalysis::fillOperationsLiveOut()
313305 for (auto const & op: operations | ranges::views::reverse)
314306 {
315307 *rit = live;
316- for (auto const & output: op.outputs | ranges::views::filter (excludingLiteralsFilter (m_cfg )))
308+ for (auto const & output: op.outputs | ranges::views::filter (excludingLiteralsFilter ()))
317309 live.erase (output);
318- for (auto const & input: op.inputs | ranges::views::filter (excludingLiteralsFilter (m_cfg )))
310+ for (auto const & input: op.inputs | ranges::views::filter (excludingLiteralsFilter ()))
319311 live.insert (input);
320312 ++rit;
321313 }
0 commit comments