Skip to content

Commit

Permalink
Merge pull request #12801 from ethereum/cse-optimization
Browse files Browse the repository at this point in the history
CSE optimization
  • Loading branch information
chriseth authored Mar 16, 2022
2 parents 281b68b + 8b0845f commit abaa5c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions libevmasm/CommonSubexpressionEliminator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void CSECodeGenerator::addDependencies(Id _c)
{
if (m_classPositions.count(_c))
return; // it is already on the stack
if (m_neededBy.count(_c))
if (m_neededBy.find(_c) != m_neededBy.end())
return; // we already computed the dependencies for _c
ExpressionClasses::Expression expr = m_expressionClasses.representative(_c);
assertThrow(expr.item, OptimizerException, "");
Expand Down Expand Up @@ -300,8 +300,8 @@ void CSECodeGenerator::addDependencies(Id _c)

void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
{
for (auto it: m_classPositions)
for (auto p: it.second)
for (auto const& it: m_classPositions)
for (int p: it.second)
if (p > m_stackHeight)
{
assertThrow(false, OptimizerException, "");
Expand Down
9 changes: 5 additions & 4 deletions libevmasm/CommonSubexpressionEliminator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@

#pragma once

#include <vector>
#include <map>
#include <ostream>
#include <set>
#include <tuple>
#include <ostream>
#include <unordered_map>
#include <vector>
#include <libsolutil/CommonIO.h>
#include <libsolutil/Exceptions.h>
#include <libevmasm/ExpressionClasses.h>
Expand Down Expand Up @@ -154,11 +155,11 @@ class CSECodeGenerator
/// Current height of the stack relative to the start.
int m_stackHeight = 0;
/// If (b, a) is in m_requests then b is needed to compute a.
std::multimap<Id, Id> m_neededBy;
std::unordered_multimap<Id, Id> m_neededBy;
/// Current content of the stack.
std::map<int, Id> m_stack;
/// Current positions of equivalence classes, equal to the empty set if already deleted.
std::map<Id, std::set<int>> m_classPositions;
std::unordered_map<Id, std::set<int>> m_classPositions;

/// The actual equivalence class items and how to compute them.
ExpressionClasses& m_expressionClasses;
Expand Down

0 comments on commit abaa5c0

Please sign in to comment.