Skip to content

Commit 8b0845f

Browse files
committed
CommonSubexpressionEliminator performance optimization
1 parent 724af73 commit 8b0845f

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

libevmasm/CommonSubexpressionEliminator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void CSECodeGenerator::addDependencies(Id _c)
219219
{
220220
if (m_classPositions.count(_c))
221221
return; // it is already on the stack
222-
if (m_neededBy.count(_c))
222+
if (m_neededBy.find(_c) != m_neededBy.end())
223223
return; // we already computed the dependencies for _c
224224
ExpressionClasses::Expression expr = m_expressionClasses.representative(_c);
225225
assertThrow(expr.item, OptimizerException, "");
@@ -300,8 +300,8 @@ void CSECodeGenerator::addDependencies(Id _c)
300300

301301
void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
302302
{
303-
for (auto it: m_classPositions)
304-
for (auto p: it.second)
303+
for (auto const& it: m_classPositions)
304+
for (int p: it.second)
305305
if (p > m_stackHeight)
306306
{
307307
assertThrow(false, OptimizerException, "");

libevmasm/CommonSubexpressionEliminator.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
#pragma once
2626

27-
#include <vector>
2827
#include <map>
28+
#include <ostream>
2929
#include <set>
3030
#include <tuple>
31-
#include <ostream>
31+
#include <unordered_map>
32+
#include <vector>
3233
#include <libsolutil/CommonIO.h>
3334
#include <libsolutil/Exceptions.h>
3435
#include <libevmasm/ExpressionClasses.h>
@@ -154,11 +155,11 @@ class CSECodeGenerator
154155
/// Current height of the stack relative to the start.
155156
int m_stackHeight = 0;
156157
/// If (b, a) is in m_requests then b is needed to compute a.
157-
std::multimap<Id, Id> m_neededBy;
158+
std::unordered_multimap<Id, Id> m_neededBy;
158159
/// Current content of the stack.
159160
std::map<int, Id> m_stack;
160161
/// Current positions of equivalence classes, equal to the empty set if already deleted.
161-
std::map<Id, std::set<int>> m_classPositions;
162+
std::unordered_map<Id, std::set<int>> m_classPositions;
162163

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

0 commit comments

Comments
 (0)