Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Remove source locations on Yul optimizer function deduplication for testing. #15894

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions libyul/AST.h
Original file line number Diff line number Diff line change
@@ -154,12 +154,24 @@ template <class T> inline langutil::DebugData::ConstPtr debugDataOf(T const& _no
return _node.debugData;
}

/// Extracts the debug data from a Yul node.
template <class T> inline void setDebugData(T& _node, langutil::DebugData::ConstPtr _debugData)
{
_node.debugData = std::move(_debugData);
}

/// Extracts the debug data from a Yul node.
template <class... Args> inline langutil::DebugData::ConstPtr debugDataOf(std::variant<Args...> const& _node)
{
return std::visit([](auto const& _arg) { return debugDataOf(_arg); }, _node);
}

/// Extracts the debug data from a Yul node.
template <class... Args> inline void setDebugData(std::variant<Args...>& _node, langutil::DebugData::ConstPtr _debugData)
{
return std::visit([&](auto& _arg) { setDebugData(_arg, _debugData); }, _node);
}

inline bool hasDefaultCase(Switch const& _switch)
{
return std::any_of(
1 change: 1 addition & 0 deletions libyul/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -178,6 +178,7 @@ add_library(yul
optimiser/Semantics.h
optimiser/SimplificationRules.cpp
optimiser/SimplificationRules.h
optimiser/SourceLocationRemover.h
optimiser/StackCompressor.cpp
optimiser/StackCompressor.h
optimiser/StackLimitEvader.cpp
11 changes: 11 additions & 0 deletions libyul/optimiser/EquivalentFunctionCombiner.cpp
Original file line number Diff line number Diff line change
@@ -20,8 +20,10 @@
*/

#include <libyul/optimiser/EquivalentFunctionCombiner.h>
#include <libyul/optimiser/SourceLocationRemover.h>
#include <libyul/AST.h>
#include <libsolutil/CommonData.h>
#include <range/v3/view/map.hpp>

using namespace solidity;
using namespace solidity::yul;
@@ -31,6 +33,15 @@ void EquivalentFunctionCombiner::run(OptimiserStepContext&, Block& _ast)
EquivalentFunctionCombiner{EquivalentFunctionDetector::run(_ast)}(_ast);
}

void EquivalentFunctionCombiner::operator()(FunctionDefinition& _functionDefinition)
{
for (auto* functionDefinition: m_duplicates | ranges::views::values)
if (&_functionDefinition == functionDefinition)
SourceLocationRemover{}(_functionDefinition);
ASTModifier::operator()(_functionDefinition);
}


void EquivalentFunctionCombiner::operator()(FunctionCall& _funCall)
{
if (!isBuiltinFunctionCall(_funCall))
1 change: 1 addition & 0 deletions libyul/optimiser/EquivalentFunctionCombiner.h
Original file line number Diff line number Diff line change
@@ -44,6 +44,7 @@ class EquivalentFunctionCombiner: public ASTModifier

using ASTModifier::operator();
void operator()(FunctionCall& _funCall) override;
void operator()(FunctionDefinition& _funCall) override;

private:
EquivalentFunctionCombiner(std::map<YulName, FunctionDefinition const*> _duplicates): m_duplicates(std::move(_duplicates)) {}
117 changes: 117 additions & 0 deletions libyul/optimiser/SourceLocationRemover.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
This file is part of solidity.

solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
// SPDX-License-Identifier: GPL-3.0
#pragma once

#include <libyul/optimiser/ASTWalker.h>
#include <liblangutil/DebugData.h>
#include <libyul/AST.h>

namespace solidity::yul
{
class SourceLocationRemover: public ASTModifier
{
public:
void operator()(Literal& _literal) override
{
resetDebugData(_literal);
ASTModifier::operator()(_literal);
}
void operator()(Identifier& _identifier) override
{
resetDebugData(_identifier);
ASTModifier::operator()(_identifier);
}
void operator()(FunctionCall& _funCall) override
{
resetDebugData(_funCall.functionName);
resetDebugData(_funCall);
ASTModifier::operator()(_funCall);
}
void operator()(ExpressionStatement& _statement) override
{
resetDebugData(_statement);
ASTModifier::operator()(_statement);
}
void operator()(Assignment& _assignment) override
{
resetDebugData(_assignment);
ASTModifier::operator()(_assignment);
}
void operator()(VariableDeclaration& _varDecl) override
{
resetDebugData(_varDecl);
ASTModifier::operator()(_varDecl);
}
void operator()(If& _if) override
{
resetDebugData(_if);
ASTModifier::operator()(_if);
}
void operator()(Switch& _switch) override
{
resetDebugData(_switch);
ASTModifier::operator()(_switch);
}
void operator()(FunctionDefinition& _functionDefinition) override
{
resetDebugData(_functionDefinition);
ASTModifier::operator()(_functionDefinition);
}
void operator()(ForLoop& _forLoop) override
{
resetDebugData(_forLoop);
ASTModifier::operator()(_forLoop);
}
void operator()(Break& _break) override
{
resetDebugData(_break);
ASTModifier::operator()(_break);
}
void operator()(Continue& _continue) override
{
resetDebugData(_continue);
ASTModifier::operator()(_continue);
}
void operator()(Leave& _leaveStatement) override
{
resetDebugData(_leaveStatement);
ASTModifier::operator()(_leaveStatement);
}
void operator()(Block& _block) override
{
resetDebugData(_block);
ASTModifier::operator()(_block);
}
void visit(Statement& _st) override
{
resetDebugData(_st);
ASTModifier::visit(_st);
}
void visit(Expression& _e) override
{
resetDebugData(_e);
ASTModifier::visit(_e);
}
template<typename T>
void resetDebugData(T& _node)
{
setDebugData(_node, {});
}

};
}