@@ -109,7 +109,7 @@ SSACFG::ValueId SSAControlFlowGraphBuilder::tryRemoveTrivialPhi(SSACFG::ValueId
109
109
110
110
m_graph.block (phiInfo->block ).phis .erase (_phi);
111
111
112
- std::set <SSACFG::ValueId> phiUses;
112
+ std::vector <SSACFG::ValueId> phiUses;
113
113
for (size_t blockIdValue = 0 ; blockIdValue < m_graph.numBlocks (); ++blockIdValue)
114
114
{
115
115
auto & block = m_graph.block (SSACFG::BlockId{blockIdValue});
@@ -126,18 +126,13 @@ SSACFG::ValueId SSAControlFlowGraphBuilder::tryRemoveTrivialPhi(SSACFG::ValueId
126
126
usedInPhi = true ;
127
127
}
128
128
if (usedInPhi)
129
- phiUses.emplace (blockPhi);
129
+ phiUses.push_back (blockPhi);
130
130
}
131
131
for (auto & op: block.operations )
132
- std ::replace (op.inputs . begin (), op. inputs . end () , _phi, same);
132
+ ranges ::replace (op.inputs , _phi, same);
133
133
std::visit (util::GenericVisitor{
134
134
[_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);
141
136
},
142
137
[_phi, same](SSACFG::BasicBlock::ConditionalJump& _condJump) {
143
138
if (_condJump.condition == _phi)
@@ -188,22 +183,17 @@ void SSAControlFlowGraphBuilder::cleanUnreachable()
188
183
{
189
184
auto & block = m_graph.block (blockId);
190
185
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); });
197
188
for (auto phi: block.phis )
198
189
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));
206
193
});
194
+ if (erasedCount > 0 )
195
+ maybeTrivialPhi.push_back (phi);
196
+ }
207
197
208
198
// After removing a phi argument, we might end up with a trivial phi that can be removed.
209
199
for (auto phi: maybeTrivialPhi)
0 commit comments