aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/optimiser
diff options
context:
space:
mode:
Diffstat (limited to 'libyul/optimiser')
-rw-r--r--libyul/optimiser/FunctionGrouper.cpp15
-rw-r--r--libyul/optimiser/FunctionGrouper.h3
2 files changed, 18 insertions, 0 deletions
diff --git a/libyul/optimiser/FunctionGrouper.cpp b/libyul/optimiser/FunctionGrouper.cpp
index 02ce22cd..b9852fcd 100644
--- a/libyul/optimiser/FunctionGrouper.cpp
+++ b/libyul/optimiser/FunctionGrouper.cpp
@@ -33,6 +33,9 @@ using namespace dev::solidity;
void FunctionGrouper::operator()(Block& _block)
{
+ if (alreadyGrouped(_block))
+ return;
+
vector<Statement> reordered;
reordered.emplace_back(Block{_block.location, {}});
@@ -45,3 +48,15 @@ void FunctionGrouper::operator()(Block& _block)
}
_block.statements = std::move(reordered);
}
+
+bool FunctionGrouper::alreadyGrouped(Block const& _block)
+{
+ if (_block.statements.empty())
+ return false;
+ if (_block.statements.front().type() != typeid(Block))
+ return false;
+ for (size_t i = 1; i < _block.statements.size(); ++i)
+ if (_block.statements.at(i).type() != typeid(FunctionDefinition))
+ return false;
+ return true;
+}
diff --git a/libyul/optimiser/FunctionGrouper.h b/libyul/optimiser/FunctionGrouper.h
index 3b3f48a7..4b6abf76 100644
--- a/libyul/optimiser/FunctionGrouper.h
+++ b/libyul/optimiser/FunctionGrouper.h
@@ -38,6 +38,9 @@ class FunctionGrouper
{
public:
void operator()(Block& _block);
+
+private:
+ bool alreadyGrouped(Block const& _block);
};
}