Skip to content

Commit 635fe8f

Browse files
authored
Merge pull request #16159 from ethereum/SSA-CFG-simpl
SSA-CFG: Tiny code simplifications
2 parents dbabcd0 + c78de76 commit 635fe8f

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

libyul/backends/evm/SSAControlFlowGraphBuilder.cpp

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ SSACFG::ValueId SSAControlFlowGraphBuilder::tryRemoveTrivialPhi(SSACFG::ValueId
109109

110110
m_graph.block(phiInfo->block).phis.erase(_phi);
111111

112-
std::set<SSACFG::ValueId> phiUses;
112+
std::vector<SSACFG::ValueId> phiUses;
113113
for (size_t blockIdValue = 0; blockIdValue < m_graph.numBlocks(); ++blockIdValue)
114114
{
115115
auto& block = m_graph.block(SSACFG::BlockId{blockIdValue});
@@ -126,18 +126,13 @@ SSACFG::ValueId SSAControlFlowGraphBuilder::tryRemoveTrivialPhi(SSACFG::ValueId
126126
usedInPhi = true;
127127
}
128128
if (usedInPhi)
129-
phiUses.emplace(blockPhi);
129+
phiUses.push_back(blockPhi);
130130
}
131131
for (auto& op: block.operations)
132-
std::replace(op.inputs.begin(), op.inputs.end(), _phi, same);
132+
ranges::replace(op.inputs, _phi, same);
133133
std::visit(util::GenericVisitor{
134134
[_phi, same](SSACFG::BasicBlock::FunctionReturn& _functionReturn) {
135-
std::replace(
136-
_functionReturn.returnValues.begin(),
137-
_functionReturn.returnValues.end(),
138-
_phi,
139-
same
140-
);
135+
ranges::replace(_functionReturn.returnValues,_phi, same);
141136
},
142137
[_phi, same](SSACFG::BasicBlock::ConditionalJump& _condJump) {
143138
if (_condJump.condition == _phi)
@@ -188,22 +183,17 @@ void SSAControlFlowGraphBuilder::cleanUnreachable()
188183
{
189184
auto& block = m_graph.block(blockId);
190185

191-
std::set<SSACFG::ValueId> maybeTrivialPhi;
192-
for (auto it = block.entries.begin(); it != block.entries.end();)
193-
if (reachabilityCheck.visited.count(*it))
194-
it++;
195-
else
196-
it = block.entries.erase(it);
186+
std::vector<SSACFG::ValueId> maybeTrivialPhi;
187+
std::erase_if(block.entries, [&](auto const& entry) { return !reachabilityCheck.visited.contains(entry); });
197188
for (auto phi: block.phis)
198189
if (auto* phiInfo = std::get_if<SSACFG::PhiValue>(&m_graph.valueInfo(phi)))
199-
std::erase_if(phiInfo->arguments, [&](SSACFG::ValueId _arg) {
200-
if (std::holds_alternative<SSACFG::UnreachableValue>(m_graph.valueInfo(_arg)))
201-
{
202-
maybeTrivialPhi.insert(phi);
203-
return true;
204-
}
205-
return false;
190+
{
191+
auto erasedCount = std::erase_if(phiInfo->arguments, [&](SSACFG::ValueId _arg) {
192+
return std::holds_alternative<SSACFG::UnreachableValue>(m_graph.valueInfo(_arg));
206193
});
194+
if (erasedCount > 0)
195+
maybeTrivialPhi.push_back(phi);
196+
}
207197

208198
// After removing a phi argument, we might end up with a trivial phi that can be removed.
209199
for (auto phi: maybeTrivialPhi)

0 commit comments

Comments
 (0)