diff --git a/libyul/optimiser/StackCompressor.cpp b/libyul/optimiser/StackCompressor.cpp index eb0629258..b3402e4d7 100644 --- a/libyul/optimiser/StackCompressor.cpp +++ b/libyul/optimiser/StackCompressor.cpp @@ -61,16 +61,15 @@ public: /// @returns a map from function name to rematerialisation costs to a vector of variables to rematerialise /// and variables that occur in their expression. /// While the map is sorted by cost, the contained vectors are sorted by the order of occurrence. - map>>>> candidates() + map>> candidates() { - map>>>> cand; + map>> cand; for (auto const& [functionName, candidate]: m_candidates) { if (size_t const* cost = util::valueOrNullptr(m_expressionCodeCost, candidate)) { size_t numRef = m_numReferences[candidate]; - set const* ref = references(candidate); - cand[functionName][*cost * numRef].emplace_back(candidate, ref ? move(*ref) : set{}); + cand[functionName][*cost * numRef].emplace_back(candidate); } } return cand; @@ -144,25 +143,16 @@ public: /// Selects at most @a _numVariables among @a _candidates. set chooseVarsToEliminate( - map>>> const& _candidates, + map> const& _candidates, size_t _numVariables ) { set varsToEliminate; for (auto&& [cost, candidates]: _candidates) - for (auto&& [candidate, references]: candidates) + for (auto&& candidate: candidates) { if (varsToEliminate.size() >= _numVariables) return varsToEliminate; - // If a variable we would like to eliminate references another one - // we already selected for elimination, then stop selecting - // candidates. If we would add that variable, then the cost calculation - // for the previous variable would be off. Furthermore, we - // do not skip the variable because it would be better to properly re-compute - // the costs of all other variables instead. - for (YulString const& referencedVar: references) - if (varsToEliminate.count(referencedVar)) - return varsToEliminate; varsToEliminate.insert(candidate); } return varsToEliminate; @@ -177,7 +167,7 @@ void eliminateVariables( { RematCandidateSelector selector{_dialect}; selector(_ast); - map>>>> candidates = selector.candidates(); + map>> candidates = selector.candidates(); set varsToEliminate; for (auto const& [functionName, numVariables]: _numVariables) @@ -209,7 +199,7 @@ void eliminateVariablesOptimizedCodegen( for (auto const& [functionName, candidatesInFunction]: selector.candidates()) for (auto [cost, candidatesWithCost]: candidatesInFunction) for (auto candidate: candidatesWithCost) - candidates[get<0>(candidate)] = cost; + candidates[candidate] = cost; set varsToEliminate;