Merge pull request #12801 from ethereum/cse-optimization

CSE optimization
This commit is contained in:
chriseth 2022-03-16 13:54:28 +01:00 committed by GitHub
commit abaa5c0eb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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))
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, "");
@ -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, "");

View File

@ -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>
@ -154,11 +155,11 @@ private:
/// 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;