|
|
@ -37,6 +37,7 @@ using namespace dev::eth; |
|
|
|
|
|
|
|
bool ExpressionClasses::Expression::operator<(ExpressionClasses::Expression const& _other) const |
|
|
|
{ |
|
|
|
assertThrow(!!item && !!_other.item, OptimizerException, ""); |
|
|
|
auto type = item->type(); |
|
|
|
auto otherType = _other.item->type(); |
|
|
|
return std::tie(type, item->data(), arguments, sequenceNumber) < |
|
|
@ -78,6 +79,15 @@ ExpressionClasses::Id ExpressionClasses::find( |
|
|
|
return exp.id; |
|
|
|
} |
|
|
|
|
|
|
|
ExpressionClasses::Id ExpressionClasses::newId() |
|
|
|
{ |
|
|
|
// Note that we cannot insert it in m_expressions because this requires item to be set.
|
|
|
|
Expression exp; |
|
|
|
exp.id = m_representatives.size(); |
|
|
|
m_representatives.push_back(exp); |
|
|
|
return exp.id; |
|
|
|
} |
|
|
|
|
|
|
|
bool ExpressionClasses::knownToBeDifferent(ExpressionClasses::Id _a, ExpressionClasses::Id _b) |
|
|
|
{ |
|
|
|
// Try to simplify "_a - _b" and return true iff the value is a non-zero constant.
|
|
|
@ -122,10 +132,16 @@ string ExpressionClasses::fullDAGToString(ExpressionClasses::Id _id) const |
|
|
|
{ |
|
|
|
Expression const& expr = representative(_id); |
|
|
|
stringstream str; |
|
|
|
str << dec << expr.id << ":" << *expr.item << "("; |
|
|
|
for (Id arg: expr.arguments) |
|
|
|
str << fullDAGToString(arg) << ","; |
|
|
|
str << ")"; |
|
|
|
str << dec << expr.id << ":"; |
|
|
|
if (expr.item) |
|
|
|
{ |
|
|
|
str << *expr.item << "("; |
|
|
|
for (Id arg: expr.arguments) |
|
|
|
str << fullDAGToString(arg) << ","; |
|
|
|
str << ")"; |
|
|
|
} |
|
|
|
else |
|
|
|
str << " UNIQUE"; |
|
|
|
return str.str(); |
|
|
|
} |
|
|
|
|
|
|
@ -279,7 +295,7 @@ ExpressionClasses::Id ExpressionClasses::tryToSimplify(Expression const& _expr, |
|
|
|
{ |
|
|
|
static Rules rules; |
|
|
|
|
|
|
|
if (_expr.item->type() != Operation) |
|
|
|
if (!_expr.item || _expr.item->type() != Operation) |
|
|
|
return -1; |
|
|
|
|
|
|
|
for (auto const& rule: rules.rules()) |
|
|
@ -337,7 +353,7 @@ void Pattern::setMatchGroup(unsigned _group, map<unsigned, Expression const*>& _ |
|
|
|
|
|
|
|
bool Pattern::matches(Expression const& _expr, ExpressionClasses const& _classes) const |
|
|
|
{ |
|
|
|
if (!matchesBaseItem(*_expr.item)) |
|
|
|
if (!matchesBaseItem(_expr.item)) |
|
|
|
return false; |
|
|
|
if (m_matchGroup) |
|
|
|
{ |
|
|
@ -387,13 +403,15 @@ string Pattern::toString() const |
|
|
|
return s.str(); |
|
|
|
} |
|
|
|
|
|
|
|
bool Pattern::matchesBaseItem(AssemblyItem const& _item) const |
|
|
|
bool Pattern::matchesBaseItem(AssemblyItem const* _item) const |
|
|
|
{ |
|
|
|
if (m_type == UndefinedItem) |
|
|
|
return true; |
|
|
|
if (m_type != _item.type()) |
|
|
|
if (!_item) |
|
|
|
return false; |
|
|
|
if (m_type != _item->type()) |
|
|
|
return false; |
|
|
|
if (m_requireDataMatch && m_data != _item.data()) |
|
|
|
if (m_requireDataMatch && m_data != _item->data()) |
|
|
|
return false; |
|
|
|
return true; |
|
|
|
} |
|
|
|