CommonSubexpressionEliminator performance optimization

This commit is contained in:
wechman 2022-03-16 12:57:38 +01:00
parent 724af73fb8
commit 8b0845fe97
2 changed files with 8 additions and 7 deletions

View File

@ -219,7 +219,7 @@ void CSECodeGenerator::addDependencies(Id _c)
{ {
if (m_classPositions.count(_c)) if (m_classPositions.count(_c))
return; // it is already on the stack 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 return; // we already computed the dependencies for _c
ExpressionClasses::Expression expr = m_expressionClasses.representative(_c); ExpressionClasses::Expression expr = m_expressionClasses.representative(_c);
assertThrow(expr.item, OptimizerException, ""); assertThrow(expr.item, OptimizerException, "");
@ -300,8 +300,8 @@ void CSECodeGenerator::addDependencies(Id _c)
void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced) void CSECodeGenerator::generateClassElement(Id _c, bool _allowSequenced)
{ {
for (auto it: m_classPositions) for (auto const& it: m_classPositions)
for (auto p: it.second) for (int p: it.second)
if (p > m_stackHeight) if (p > m_stackHeight)
{ {
assertThrow(false, OptimizerException, ""); assertThrow(false, OptimizerException, "");

View File

@ -24,11 +24,12 @@
#pragma once #pragma once
#include <vector>
#include <map> #include <map>
#include <ostream>
#include <set> #include <set>
#include <tuple> #include <tuple>
#include <ostream> #include <unordered_map>
#include <vector>
#include <libsolutil/CommonIO.h> #include <libsolutil/CommonIO.h>
#include <libsolutil/Exceptions.h> #include <libsolutil/Exceptions.h>
#include <libevmasm/ExpressionClasses.h> #include <libevmasm/ExpressionClasses.h>
@ -154,11 +155,11 @@ private:
/// Current height of the stack relative to the start. /// Current height of the stack relative to the start.
int m_stackHeight = 0; int m_stackHeight = 0;
/// If (b, a) is in m_requests then b is needed to compute a. /// 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. /// Current content of the stack.
std::map<int, Id> m_stack; std::map<int, Id> m_stack;
/// Current positions of equivalence classes, equal to the empty set if already deleted. /// 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. /// The actual equivalence class items and how to compute them.
ExpressionClasses& m_expressionClasses; ExpressionClasses& m_expressionClasses;