Huge commit from which this can be extracted in stages.

This commit is contained in:
Daniel Kirchner 2021-05-04 14:15:58 +02:00
parent af61f25e51
commit 576dce091d
206 changed files with 3163 additions and 1247 deletions

View File

@ -52,6 +52,21 @@ template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U&& _
std::move(_b.begin(), _b.end(), std::back_inserter(_a)); std::move(_b.begin(), _b.end(), std::back_inserter(_a));
return _a; return _a;
} }
/// Concatenate the contents of a container onto a list
template <class T, class U> std::list<T>& operator+=(std::list<T>& _a, U& _b)
{
for (auto const& i: _b)
_a.push_back(T(i));
return _a;
}
/// Concatenate the contents of a container onto a list, move variant.
template <class T, class U> std::list<T>& operator+=(std::list<T>& _a, U&& _b)
{
std::move(_b.begin(), _b.end(), std::back_inserter(_a));
return _a;
}
/// Concatenate the contents of a container onto a multiset /// Concatenate the contents of a container onto a multiset
template <class U, class... T> std::multiset<T...>& operator+=(std::multiset<T...>& _a, U& _b) template <class U, class... T> std::multiset<T...>& operator+=(std::multiset<T...>& _a, U& _b)
{ {
@ -295,6 +310,50 @@ decltype(auto) mapTuple(Callable&& _callable)
return detail::MapTuple<Callable>{std::forward<Callable>(_callable)}; return detail::MapTuple<Callable>{std::forward<Callable>(_callable)};
} }
namespace detail
{
template<typename Container, typename Value>
auto findOffset(Container&& _container, Value&& _value, int)
-> decltype(_container.find(_value) == _container.end(), std::optional<size_t>())
{
auto it = _container.find(std::forward<Value>(_value));
auto end = _container.end();
if (it == end)
return std::nullopt;
return std::distance(it, end);
}
template<typename Range, typename Value>
auto findOffset(Range&& _range, Value&& _value, void*)
-> decltype(std::find(std::begin(_range), std::end(_range), std::forward<Value>(_value)) == std::end(_range), std::optional<size_t>())
{
auto begin = std::begin(_range);
auto end = std::end(_range);
auto it = std::find(begin, end, std::forward<Value>(_value));
if (it == end)
return std::nullopt;
return std::distance(begin, it);
}
}
template<typename Range>
auto findOffset(Range&& _range, std::remove_reference_t<decltype(*std::cbegin(_range))> const& _value)
-> decltype(detail::findOffset(std::forward<Range>(_range), _value, 0))
{
return detail::findOffset(std::forward<Range>(_range), _value, 0);
}
template<typename Range, typename Pred>
std::optional<size_t> findOffsetPred(Range&& _range, Pred _pred)
{
auto begin = std::begin(_range);
auto end = std::end(_range);
auto it = std::find_if(begin, end, _pred);
if (it == end)
return std::nullopt;
return std::distance(begin, it);
}
// String conversion functions, mainly to/from hex/nibble/byte representations. // String conversion functions, mainly to/from hex/nibble/byte representations.

228
libsolutil/Permutations.h Normal file
View File

@ -0,0 +1,228 @@
/*
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 <libsolutil/Visitor.h>
#include <liblangutil/Exceptions.h>
#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/iota.hpp>
namespace solidity::util
{
// TODO: This is currently only used for permuteDup as special case handling, which is not the best way to do things.
// Not worth spending time reviewing this.
template<typename GetTargetPosition, typename Swap, typename Pop>
void permute(unsigned _n, GetTargetPosition _getTargetPosition, Swap _swap, Pop _pop)
{
static_assert(
std::is_same_v<std::invoke_result_t<GetTargetPosition, unsigned>, int>,
"_getTargetPosition needs to have the signature int(unsigned)"
);
static_assert(
std::is_same_v<std::invoke_result_t<Swap, unsigned>, void>,
"_swap needs to have the signature void(unsigned)"
);
static_assert(
std::is_same_v<std::invoke_result_t<Pop>, void>,
"_pop needs to have the signature void()"
);
if (_n == 0) return;
int targetPositionTop = _getTargetPosition(_n - 1);
if (targetPositionTop < 0)
{
// The last element should not be kept.
// Pop it and recurse.
_pop();
permute(_n - 1, _getTargetPosition, _swap, _pop);
return;
}
// TODO: exception?
// assertThrow(static_cast<unsigned>(targetPositionTop) < _n, langutil::InternalCompilerError, "Invalid permutation.");
if (static_cast<unsigned>(targetPositionTop) == _n - 1)
{
// The last element is in position.
// Search for the deepest element that is not in position.
// If there is none, we are done. Otherwise swap it up and recurse.
for (int i = 0; i < static_cast<int>(_n - 1); ++i)
if (_getTargetPosition(static_cast<unsigned>(i)) != i)
{
_swap(_n - static_cast<unsigned>(i) - 1);
permute(_n, _getTargetPosition, _swap, _pop);
return;
}
}
else
{
// The last element is not in position.
// Move it to its position and recurse.
_swap(_n - static_cast<unsigned>(targetPositionTop) - 1);
permute(_n, _getTargetPosition, _swap, _pop);
}
}
// TODO: This is now only used in StackLayoutGenerator.cpp in ``createIdealLayout`` and that usage is actually abuse,
// since it provides "invalid" target positions (it works, but it's not soundly specified).
// Hence ``createIdealLayout`` should rather be rewritten properly and it does not make much sense to review
// this in detail.
template<typename GetTargetPositions, typename Swap, typename Dup, typename Push, typename Pop>
void permuteDup(unsigned _n, GetTargetPositions _getTargetPositions, Swap _swap, Dup _dup, Push _push, Pop _pop, bool _debug = false)
{
static_assert(
std::is_same_v<std::invoke_result_t<GetTargetPositions, unsigned>, std::set<unsigned>>,
"_getTargetPosition needs to have the signature std::vector<int>(unsigned)"
);
static_assert(
std::is_same_v<std::invoke_result_t<Swap, unsigned>, void>,
"_swap needs to have the signature void(unsigned)"
);
static_assert(
std::is_same_v<std::invoke_result_t<Dup, unsigned>, void>,
"_dup needs to have the signature void(unsigned)"
);
static_assert(
std::is_same_v<std::invoke_result_t<Push>, void>,
"_push needs to have the signature void()"
);
static_assert(
std::is_same_v<std::invoke_result_t<Pop>, void>,
"_pop needs to have the signature void()"
);
if (_n == 0) return;
if (_debug)
{
for (auto offset: ranges::views::iota(0u, _n))
{
auto targetPositions = _getTargetPositions(offset);
std::cout << "{ ";
for (auto pos: targetPositions)
std::cout << pos << " ";
std::cout << "} ";
}
std::cout << std::endl;
}
std::set<unsigned> targetPositionsTop = _getTargetPositions(_n - 1);
if (targetPositionsTop.empty())
{
// The last element should not be kept.
// Pop it and recurse.
_pop();
permuteDup(_n - 1, _getTargetPositions, _swap, _dup, _push, _pop, _debug);
return;
}
if (targetPositionsTop.count(_n - 1))
{
if (_debug)
std::cout << "Top position should stay" << std::endl;
// The last element should remain at the top (but potentially also be dupped).
/*if (targetPositionsTop.size() > 1)
{
std::cout << "TOP targets: { ";
for (auto i: targetPositionsTop)
std::cout << i << " ";
std::cout << "}" << std::endl;
// The last element should remain at the top and be dupped. Dup it and recurse.
_dup(1);
permuteDup(_n + 1, _getTargetPositions, _swap, _dup, _push, _pop);
return;
}
else*/
{
if (_debug)
std::cout << "Look for deeper element to be dupped." << std::endl;
// The last element should *only* exist at the current top.
// Look for the deepest element that should still be dupped.
for (auto offset: ranges::views::iota(0u, _n))
{
auto targetPositions = _getTargetPositions(offset);
if (targetPositions.size() > 1)
{
if (_debug)
std::cout << "DUP element " << offset << " (DUP" << (_n - offset) << ")" << std::endl;
// Dup it, adjust the target positions and recurse.
// The next recursion will move the duplicate in place.
_dup(_n - offset);
permuteDup(_n + 1, _getTargetPositions, _swap, _dup, _push, _pop, _debug);
return;
}
}
// There is no more dupping requested, so we can switch to the non-dupping version.
permute(_n, [&](unsigned _i) -> int {
auto const& targetPositions = _getTargetPositions(_i);
if (targetPositions.empty())
return -1;
else
{
assertThrow(targetPositions.size() == 1, langutil::InternalCompilerError, "");
return static_cast<int>(*targetPositions.begin());
}
}, _swap, _pop);
return;
}
}
else
{
// The last element should end up at *some* position that isn't its current one.
auto topTargetPos = *targetPositionsTop.begin();
if (_debug)
std::cout << "Top target pos: " << topTargetPos << std::endl;
if (topTargetPos < _n - 1)
{
// If the element is supposed to exist anywhere deeper than the current top, swap it there and recurse.
_swap(_n - static_cast<unsigned>(topTargetPos) - 1);
permuteDup(_n, _getTargetPositions, _swap, _dup, _push, _pop, _debug);
return;
}
else
{
// If there is an element that is supposed to be dupped to the current top position. Find it, dup it and recurse.
for (auto offset: ranges::views::iota(0u, _n))
{
auto targetPositions = _getTargetPositions(offset);
if (targetPositions.size() > 1 && targetPositions.count(static_cast<unsigned>(_n)))
{
_dup(static_cast<unsigned>(targetPositions.size() - offset));
permuteDup(_n + 1, _getTargetPositions, _swap, _dup, _push, _pop, _debug);
return;
}
}
// If there is any other element that is supposed to be dupped. Find it, dup it and recurse.
for (auto offset: ranges::views::iota(0u, _n))
{
auto targetPositions = _getTargetPositions(offset);
if (targetPositions.size() > 1)
{
_dup(static_cast<unsigned>(targetPositions.size() - offset));
permuteDup(_n + 1, _getTargetPositions, _swap, _dup, _push, _pop, _debug);
return;
}
}
// There must be a new element requested. Request it to be pushed and recurse.
_push();
permuteDup(_n + 1, _getTargetPositions, _swap, _dup, _push, _pop, _debug);
return;
assertThrow(false, langutil::InternalCompilerError, "Invalid permutation.");
}
}
}
}

View File

@ -49,6 +49,32 @@ erase_if(std::unordered_map<Key, T, Hash, KeyEqual, Alloc>& _c, Pred _pred)
return old_size - _c.size(); return old_size - _c.size();
} }
// Taken from https://en.cppreference.com/w/cpp/container/set/erase_if
template<class Key, class Compare, class Alloc, class Pred>
typename std::set<Key,Compare,Alloc>::size_type
erase_if(std::set<Key,Compare,Alloc>& c, Pred pred)
{
auto old_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last;)
if (pred(*i))
i = c.erase(i);
else
++i;
return static_cast<typename std::set<Key,Compare,Alloc>::size_type>(old_size - c.size());
}
// Taken from https://en.cppreference.com/w/cpp/container/deque/erase2
template<class T, class Alloc, class Pred>
typename std::deque<T,Alloc>::size_type
erase_if(std::deque<T,Alloc>& c, Pred pred)
{
auto it = std::remove_if(c.begin(), c.end(), pred);
auto r = std::distance(it, c.end());
c.erase(it, c.end());
return static_cast<typename std::deque<T,Alloc>::size_type>(r);
}
// Taken from https://en.cppreference.com/w/cpp/container/vector/erase2 // Taken from https://en.cppreference.com/w/cpp/container/vector/erase2
template<class T, class Alloc, class Pred> template<class T, class Alloc, class Pred>
constexpr typename std::vector<T, Alloc>::size_type constexpr typename std::vector<T, Alloc>::size_type

View File

@ -83,18 +83,16 @@ struct Continue { std::shared_ptr<DebugData const> debugData; };
/// Leave statement (valid within function) /// Leave statement (valid within function)
struct Leave { std::shared_ptr<DebugData const> debugData; }; struct Leave { std::shared_ptr<DebugData const> debugData; };
struct LocationExtractor
{
template <class T> langutil::SourceLocation operator()(T const& _node) const
{
return _node.debugData ? _node.debugData->location : langutil::SourceLocation{};
}
};
/// Extracts the source location from a Yul node. /// Extracts the source location from a Yul node.
template <class T> inline langutil::SourceLocation locationOf(T const& _node) template <class T> inline langutil::SourceLocation locationOf(T const& _node)
{ {
return std::visit(LocationExtractor(), _node); return _node.debugData ? _node.debugData->location : langutil::SourceLocation{};
}
/// Extracts the source location from a Yul node.
template <class... Args> inline langutil::SourceLocation locationOf(std::variant<Args...> const& _node)
{
return std::visit([](auto const& _arg) { return locationOf(_arg); }, _node);
} }
struct DebugDataExtractor struct DebugDataExtractor

View File

@ -113,9 +113,9 @@ public:
private: private:
bool analyzeParsed(); bool analyzeParsed();
bool analyzeParsed(yul::Object& _object); bool analyzeParsed(yul::Object& _object);
public:
void compileEVM(yul::AbstractAssembly& _assembly, bool _optimize) const; void compileEVM(yul::AbstractAssembly& _assembly, bool _optimize) const;
private:
void optimize(yul::Object& _object, bool _isCreation); void optimize(yul::Object& _object, bool _isCreation);
Language m_language = Language::Assembly; Language m_language = Language::Assembly;

View File

@ -68,6 +68,11 @@ add_library(yul
backends/evm/EVMMetrics.h backends/evm/EVMMetrics.h
backends/evm/NoOutputAssembly.h backends/evm/NoOutputAssembly.h
backends/evm/NoOutputAssembly.cpp backends/evm/NoOutputAssembly.cpp
backends/evm/OptimizedEVMCodeTransform.cpp
backends/evm/OptimizedEVMCodeTransform.h
backends/evm/StackHelpers.h
backends/evm/StackLayoutGenerator.cpp
backends/evm/StackLayoutGenerator.h
backends/evm/VariableReferenceCounter.h backends/evm/VariableReferenceCounter.h
backends/evm/VariableReferenceCounter.cpp backends/evm/VariableReferenceCounter.cpp
backends/wasm/EVMToEwasmTranslator.cpp backends/wasm/EVMToEwasmTranslator.cpp

View File

@ -55,7 +55,7 @@ void visitArguments(
for (auto const& arg: _call.arguments | ranges::views::reverse) for (auto const& arg: _call.arguments | ranges::views::reverse)
_visitExpression(arg); _visitExpression(arg);
_assembly.setSourceLocation(_call.debugData->location); _assembly.setSourceLocation(locationOf(_call));
} }

View File

@ -23,6 +23,7 @@
#include <libyul/backends/evm/EVMCodeTransform.h> #include <libyul/backends/evm/EVMCodeTransform.h>
#include <libyul/backends/evm/EVMDialect.h> #include <libyul/backends/evm/EVMDialect.h>
#include <libyul/backends/evm/OptimizedEVMCodeTransform.h>
#include <libyul/Object.h> #include <libyul/Object.h>
#include <libyul/Exceptions.h> #include <libyul/Exceptions.h>
@ -58,6 +59,10 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
yulAssert(_object.analysisInfo, "No analysis info."); yulAssert(_object.analysisInfo, "No analysis info.");
yulAssert(_object.code, "No code."); yulAssert(_object.code, "No code.");
if (_optimize && m_dialect.evmVersion() > langutil::EVMVersion::homestead())
OptimizedEVMCodeTransform::run(m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context);
else
{
// We do not catch and re-throw the stack too deep exception here because it is a YulException, // We do not catch and re-throw the stack too deep exception here because it is a YulException,
// which should be native to this part of the code. // which should be native to this part of the code.
CodeTransform transform{m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context, _optimize}; CodeTransform transform{m_assembly, *_object.analysisInfo, *_object.code, m_dialect, context, _optimize};
@ -65,3 +70,4 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
if (!transform.stackErrors().empty()) if (!transform.stackErrors().empty())
BOOST_THROW_EXCEPTION(transform.stackErrors().front()); BOOST_THROW_EXCEPTION(transform.stackErrors().front());
} }
}

View File

@ -0,0 +1,458 @@
/*
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
#include <libyul/backends/evm/OptimizedEVMCodeTransform.h>
#include <libyul/backends/evm/ControlFlowGraphBuilder.h>
#include <libyul/backends/evm/StackHelpers.h>
#include <libyul/backends/evm/StackLayoutGenerator.h>
#include <libyul/Utilities.h>
#include <libsolutil/Permutations.h>
#include <libsolutil/Visitor.h>
#include <libsolutil/cxx20.h>
#include <range/v3/action/push_back.hpp>
#include <range/v3/view/drop.hpp>
#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/map.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/take_last.hpp>
using namespace solidity;
using namespace solidity::yul;
using namespace std;
OptimizedEVMCodeTransform::OptimizedEVMCodeTransform(
AbstractAssembly& _assembly,
BuiltinContext& _builtinContext,
bool _useNamedLabelsForFunctions,
CFG const& _dfg,
StackLayout const& _stackLayout
):
m_assembly(_assembly),
m_builtinContext(_builtinContext),
m_useNamedLabelsForFunctions(_useNamedLabelsForFunctions),
m_dfg(_dfg),
m_stackLayout(_stackLayout)
{
}
void OptimizedEVMCodeTransform::assertLayoutCompatibility(Stack const& _currentStack, Stack const& _desiredStack)
{
for (auto&& [currentSlot, desiredSlot]: ranges::zip_view(_currentStack, _desiredStack))
yulAssert(holds_alternative<JunkSlot>(desiredSlot) || currentSlot == desiredSlot, "");
}
AbstractAssembly::LabelID OptimizedEVMCodeTransform::getFunctionLabel(Scope::Function const& _function)
{
CFG::FunctionInfo const& functionInfo = m_dfg.functionInfo.at(&_function);
if (!m_functionLabels.count(&functionInfo))
{
m_functionLabels[&functionInfo] = m_useNamedLabelsForFunctions ?
m_assembly.namedLabel(
functionInfo.function.name.str(),
functionInfo.function.arguments.size(),
functionInfo.function.returns.size(),
{}
) : m_assembly.newLabelId();
}
return m_functionLabels[&functionInfo];
}
void OptimizedEVMCodeTransform::validateSlot(StackSlot const& _slot, Expression const& _expression)
{
std::visit(util::GenericVisitor{
[&](yul::Literal const& _literal) {
auto* literalSlot = get_if<LiteralSlot>(&_slot);
yulAssert(literalSlot && valueOfLiteral(_literal) == literalSlot->value, "");
},
[&](yul::Identifier const& _identifier) {
auto* variableSlot = get_if<VariableSlot>(&_slot);
yulAssert(variableSlot && variableSlot->variable.get().name == _identifier.name, "");
},
[&](yul::FunctionCall const& _call) {
auto* temporarySlot = get_if<TemporarySlot>(&_slot);
yulAssert(temporarySlot && &temporarySlot->call.get() == &_call, "");
}
}, _expression);
}
void OptimizedEVMCodeTransform::operator()(CFG::FunctionInfo const& _functionInfo)
{
yulAssert(!m_currentFunctionInfo, "");
m_currentFunctionInfo = &_functionInfo;
Stack const& entryLayout = m_stackLayout.blockInfos.at(_functionInfo.entry).entryLayout;
m_stack.clear();
m_stack.emplace_back(FunctionReturnLabelSlot{});
for (auto const& param: _functionInfo.parameters | ranges::views::reverse)
m_stack.emplace_back(param);
m_assembly.setStackHeight(static_cast<int>(m_stack.size()));
m_assembly.setSourceLocation(locationOf(_functionInfo));
if (!m_functionLabels.count(&_functionInfo))
m_functionLabels[&_functionInfo] = m_assembly.newLabelId();
m_assembly.appendLabel(getFunctionLabel(_functionInfo.function));
createStackLayout(entryLayout);
(*this)(*_functionInfo.entry);
m_currentFunctionInfo = nullptr;
m_stack.clear();
m_assembly.setStackHeight(0);
}
void OptimizedEVMCodeTransform::operator()(CFG::FunctionCall const& _call)
{
yulAssert(m_stack.size() >= _call.function.get().arguments.size() + 1, "");
auto returnLabel = m_returnLabels.at(&_call.functionCall.get());
// Assert that we got a correct arguments on stack for the call.
for (auto&& [arg, slot]: ranges::zip_view(
_call.functionCall.get().arguments | ranges::views::reverse,
m_stack | ranges::views::take_last(_call.functionCall.get().arguments.size())
))
validateSlot(slot, arg);
// Assert that we got the correct return label on stack.
auto* returnLabelSlot = get_if<FunctionCallReturnLabelSlot>(&m_stack.at(m_stack.size() - _call.functionCall.get().arguments.size() - 1));
yulAssert(returnLabelSlot && &returnLabelSlot->call.get() == &_call.functionCall.get(), "");
m_assembly.setSourceLocation(locationOf(_call));
m_assembly.appendJumpTo(
getFunctionLabel(_call.function),
static_cast<int>(_call.function.get().returns.size() - _call.function.get().arguments.size()) - 1,
AbstractAssembly::JumpType::IntoFunction
);
m_assembly.appendLabel(returnLabel);
// Remove arguments and return label from m_stack.
for (size_t i = 0; i < _call.function.get().arguments.size() + 1; ++i)
m_stack.pop_back();
// Push return values to m_stack.
ranges::actions::push_back(
m_stack,
ranges::views::iota(0u, _call.function.get().returns.size()) |
ranges::views::transform([&](size_t _i) -> StackSlot { return TemporarySlot{_call.functionCall, _i}; })
);
yulAssert(m_assembly.stackHeight() == static_cast<int>(m_stack.size()), "");
}
void OptimizedEVMCodeTransform::operator()(CFG::BuiltinCall const& _call)
{
yulAssert(m_stack.size() >= _call.arguments, "");
// Assert that we got a correct stack for the call.
for (auto&& [arg, slot]: ranges::zip_view(
_call.functionCall.get().arguments | ranges::views::enumerate |
ranges::views::filter(util::mapTuple([&](size_t idx, auto&) -> bool { return !_call.builtin.get().literalArgument(idx); })) |
ranges::views::reverse | ranges::views::values,
m_stack | ranges::views::take_last(_call.arguments)
))
validateSlot(slot, arg);
m_assembly.setSourceLocation(locationOf(_call));
static_cast<BuiltinFunctionForEVM const&>(_call.builtin.get()).generateCode(_call.functionCall, m_assembly, m_builtinContext, [](auto&&){});
// Remove arguments from m_stack.
for (size_t i = 0; i < _call.arguments; ++i)
m_stack.pop_back();
// Push return values to m_stack.
ranges::actions::push_back(
m_stack,
ranges::views::iota(0u, _call.builtin.get().returns.size()) |
ranges::views::transform([&](size_t _i) -> StackSlot { return TemporarySlot{_call.functionCall, _i};})
);
yulAssert(m_assembly.stackHeight() == static_cast<int>(m_stack.size()), "");
}
void OptimizedEVMCodeTransform::operator()(CFG::Assignment const& _assignment)
{
for (auto& currentSlot: m_stack)
if (VariableSlot const* varSlot = get_if<VariableSlot>(&currentSlot))
if (util::findOffset(_assignment.variables, *varSlot))
currentSlot = JunkSlot{};
for (auto&& [currentSlot, varSlot]: ranges::zip_view(m_stack | ranges::views::take_last(_assignment.variables.size()), _assignment.variables))
currentSlot = varSlot;
}
void OptimizedEVMCodeTransform::operator()(CFG::BasicBlock const& _block)
{
if (!m_generated.insert(&_block).second)
return;
auto&& [entryLayout, exitLayout] = m_stackLayout.blockInfos.at(&_block);
if (auto label = util::valueOrNullptr(m_blockLabels, &_block))
m_assembly.appendLabel(*label);
assertLayoutCompatibility(m_stack, entryLayout);
m_stack = entryLayout;
yulAssert(static_cast<int>(m_stack.size()) == m_assembly.stackHeight(), "");
for (auto const& operation: _block.operations)
{
createStackLayout(m_stackLayout.operationEntryLayout.at(&operation));
std::visit(*this, operation.operation);
}
createStackLayout(exitLayout);
std::visit(util::GenericVisitor{
[&](CFG::BasicBlock::MainExit const&)
{
m_assembly.appendInstruction(evmasm::Instruction::STOP);
m_assembly.setStackHeight(0);
m_stack.clear();
},
[&](CFG::BasicBlock::Jump const& _jump)
{
Stack const& entryLayout = m_stackLayout.blockInfos.at(_jump.target).entryLayout;
createStackLayout(entryLayout);
if (!m_blockLabels.count(_jump.target) && _jump.target->entries.size() == 1)
{
yulAssert(!_jump.backwards, "");
(*this)(*_jump.target);
}
else
{
if (!m_blockLabels.count(_jump.target))
m_blockLabels[_jump.target] = m_assembly.newLabelId();
m_assembly.appendJumpTo(m_blockLabels[_jump.target]);
if (!m_generated.count(_jump.target))
(*this)(*_jump.target);
}
},
[&](CFG::BasicBlock::ConditionalJump const& _conditionalJump)
{
if (!m_blockLabels.count(_conditionalJump.nonZero))
m_blockLabels[_conditionalJump.nonZero] = m_assembly.newLabelId();
m_assembly.appendJumpToIf(m_blockLabels[_conditionalJump.nonZero]);
m_stack.pop_back();
assertLayoutCompatibility(m_stack, m_stackLayout.blockInfos.at(_conditionalJump.nonZero).entryLayout);
assertLayoutCompatibility(m_stack, m_stackLayout.blockInfos.at(_conditionalJump.zero).entryLayout);
{
ScopedSaveAndRestore stackRestore(m_stack, Stack{m_stack});
if (!m_blockLabels.count(_conditionalJump.zero))
m_blockLabels[_conditionalJump.zero] = m_assembly.newLabelId();
if (m_generated.count(_conditionalJump.zero))
m_assembly.appendJumpTo(m_blockLabels[_conditionalJump.zero]);
else
(*this)(*_conditionalJump.zero);
}
if (!m_generated.count(_conditionalJump.nonZero))
{
m_assembly.setStackHeight(static_cast<int>(m_stack.size()));
(*this)(*_conditionalJump.nonZero);
}
},
[&](CFG::BasicBlock::FunctionReturn const& _functionReturn)
{
yulAssert(m_currentFunctionInfo, "");
yulAssert(m_currentFunctionInfo == _functionReturn.info, "");
Stack exitStack = m_currentFunctionInfo->returnVariables | ranges::views::transform([](auto const& _varSlot){
return StackSlot{_varSlot};
}) | ranges::to<Stack>;
exitStack.emplace_back(FunctionReturnLabelSlot{});
createStackLayout(exitStack);
m_assembly.setSourceLocation(locationOf(*m_currentFunctionInfo));
m_assembly.appendJump(0, AbstractAssembly::JumpType::OutOfFunction); // TODO: stack height diff.
m_assembly.setStackHeight(0);
m_stack.clear();
},
[&](CFG::BasicBlock::Terminated const&)
{
m_assembly.setStackHeight(0);
m_stack.clear();
}
}, _block.exit);
}
// TODO: It may or may not be nicer to merge this with createStackLayout (e.g. by adding an option to it that
// disables actually emitting assembly output).
Stack OptimizedEVMCodeTransform::tryCreateStackLayout(Stack const& _currentStack, Stack _targetStack)
{
Stack unreachable;
Stack commonPrefix;
for (auto&& [slot1, slot2]: ranges::zip_view(_currentStack, _targetStack))
{
if (!(slot1 == slot2))
break;
commonPrefix.emplace_back(slot1);
}
Stack temporaryStack = _currentStack | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>;
::createStackLayout(temporaryStack, _targetStack | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>, [&](unsigned _i) {
if (_i > 16)
{
if (!util::findOffset(unreachable, temporaryStack.at(temporaryStack.size() - _i - 1)))
unreachable.emplace_back(temporaryStack.at(temporaryStack.size() - _i - 1));
}
}, [&](unsigned _i) {
if (_i > 16)
{
if (!util::findOffset(unreachable, temporaryStack.at(temporaryStack.size() - _i - 1)))
unreachable.emplace_back(temporaryStack.at(temporaryStack.size() - _i - 1));
}
}, [&](StackSlot const& _slot) {
Stack currentFullStack = commonPrefix;
for (auto slot: temporaryStack)
currentFullStack.emplace_back(slot);
if (auto depth = util::findOffset(currentFullStack | ranges::views::reverse, _slot))
{
if (*depth + 1 > 16)
{
if (!util::findOffset(unreachable, _slot))
unreachable.emplace_back(_slot);
}
return;
}
}, [&]() {});
return unreachable;
}
void OptimizedEVMCodeTransform::createStackLayout(Stack _targetStack)
{
Stack commonPrefix;
for (auto&& [currentSlot, targetSlot]: ranges::zip_view(m_stack, _targetStack))
{
if (!(currentSlot == targetSlot) || holds_alternative<JunkSlot>(targetSlot))
break;
commonPrefix.emplace_back(targetSlot);
}
Stack temporaryStack = m_stack | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>;
if (!tryCreateStackLayout(m_stack, _targetStack).empty())
{
yulAssert(false, "Stack too deep."); // Make this a hard failure now to focus on avoiding it earlier.
// TODO: check if we can do better.
// Maybe switching to a general "fix everything deep first" algorithm.
// Or we just let these cases, that weren't fixed in the StackLayoutGenerator go through and report the
// need for stack limit evasion for these cases instead.
std::map<unsigned, StackSlot> slotsByDepth;
for (auto slot: _targetStack | ranges::views::take_last(_targetStack.size() - commonPrefix.size()))
if (auto offset = util::findOffset(m_stack | ranges::views::reverse | ranges::to<Stack>, slot))
slotsByDepth.insert(std::make_pair(*offset, slot));
for (auto slot: slotsByDepth | ranges::views::reverse | ranges::views::values)
if (!util::findOffset(temporaryStack, slot))
{
auto offset = util::findOffset(m_stack | ranges::views::reverse | ranges::to<Stack>, slot);
m_stack.emplace_back(slot);
m_assembly.appendInstruction(evmasm::dupInstruction(static_cast<unsigned>(*offset + 1)));
}
temporaryStack = m_stack | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>;
}
::createStackLayout(temporaryStack, _targetStack | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>, [&](unsigned _i) {
m_assembly.appendInstruction(evmasm::swapInstruction(_i));
}, [&](unsigned _i) {
m_assembly.appendInstruction(evmasm::dupInstruction(_i));
}, [&](StackSlot const& _slot) {
Stack currentFullStack = commonPrefix;
for (auto slot: temporaryStack)
currentFullStack.emplace_back(slot);
if (auto depth = util::findOffset(currentFullStack | ranges::views::reverse, _slot))
{
m_assembly.appendInstruction(evmasm::dupInstruction(static_cast<unsigned>(*depth + 1)));
return;
}
std::visit(util::GenericVisitor{
[&](LiteralSlot const& _literal)
{
m_assembly.setSourceLocation(locationOf(_literal));
m_assembly.appendConstant(_literal.value);
},
[&](FunctionReturnLabelSlot const&)
{
yulAssert(false, "Cannot produce function return label.");
},
[&](FunctionCallReturnLabelSlot const& _returnLabel)
{
if (!m_returnLabels.count(&_returnLabel.call.get()))
m_returnLabels[&_returnLabel.call.get()] = m_assembly.newLabelId();
m_assembly.appendLabelReference(m_returnLabels.at(&_returnLabel.call.get()));
},
[&](VariableSlot const& _variable)
{
if (m_currentFunctionInfo)
if (util::contains(m_currentFunctionInfo->returnVariables, _variable))
{
// TODO: maybe track uninitialized return variables.
m_assembly.appendConstant(0);
return;
}
yulAssert(false, "Variable not found on stack.");
},
[&](TemporarySlot const&)
{
yulAssert(false, "Function call result requested, but not found on stack.");
},
[&](JunkSlot const&)
{
// Note: this will always be popped, so we can push anything.
// TODO: discuss if PC is in fact a good choice here.
// Advantages:
// - costs only 2 gas
// - deterministic value (in case it is in fact used due to some bug)
// - hard to exploit in case of a bug
// - distinctive, since it is not generated elsewhere
// Disadvantages:
// - static analysis might get confused until it realizes that these are always popped
// Alternatives:
// - any other opcode with cost 2
// - unless the stack is empty: DUP1
// - the constant 0
// Note: it might even make sense to introduce a specific assembly item for this, s.t.
// the peephole optimizer can deal with this (e.g. POP PUSHJUNK can be removed).
m_assembly.appendInstruction(evmasm::Instruction::PC);
}
}, _slot);
}, [&]() { m_assembly.appendInstruction(evmasm::Instruction::POP); });
m_stack = commonPrefix;
for (auto slot: temporaryStack)
m_stack.emplace_back(slot);
}
void OptimizedEVMCodeTransform::run(
AbstractAssembly& _assembly,
AsmAnalysisInfo& _analysisInfo,
Block const& _block,
EVMDialect const& _dialect,
BuiltinContext& _builtinContext,
ExternalIdentifierAccess const&,
bool _useNamedLabelsForFunctions
)
{
std::unique_ptr<CFG> dfg = ControlFlowGraphBuilder::build(_analysisInfo, _dialect, _block);
StackLayout stackLayout = StackLayoutGenerator::run(*dfg);
OptimizedEVMCodeTransform optimizedCodeTransform(_assembly, _builtinContext, _useNamedLabelsForFunctions, *dfg, stackLayout);
optimizedCodeTransform(*dfg->entry);
for (Scope::Function const* function: dfg->functions)
optimizedCodeTransform(dfg->functionInfo.at(function));
}

View File

@ -0,0 +1,110 @@
/*
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
/**
* Code generator for translating Yul / inline assembly to EVM.
*/
#pragma once
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/backends/evm/ControlFlowGraph.h>
#include <libyul/AST.h>
#include <libyul/Scope.h>
#include <optional>
#include <stack>
namespace solidity::langutil
{
class ErrorReporter;
}
namespace solidity::yul
{
struct AsmAnalysisInfo;
struct StackLayout;
class OptimizedEVMCodeTransform
{
public:
static void run(
AbstractAssembly& _assembly,
AsmAnalysisInfo& _analysisInfo,
Block const& _block,
EVMDialect const& _dialect,
BuiltinContext& _builtinContext,
ExternalIdentifierAccess const& _identifierAccess = ExternalIdentifierAccess(),
bool _useNamedLabelsForFunctions = false
);
private:
OptimizedEVMCodeTransform(
AbstractAssembly& _assembly,
BuiltinContext& _builtinContext,
bool _useNamedLabelsForFunctions,
CFG const& _dfg,
StackLayout const& _stackLayout
);
AbstractAssembly::LabelID getFunctionLabel(Scope::Function const& _function);
/// Shuffles m_stack to the desired @a _targetStack while emitting the shuffling code to m_assembly.
void createStackLayout(Stack _targetStack);
/// Generate code for the given block @a _block.
/// Expects the current stack layout m_stack to be a stack layout that is compatible with the
/// entry layout expected by the block.
void operator()(CFG::BasicBlock const& _block);
/// Generate code for the given function.
/// Resets m_stack.
void operator()(CFG::FunctionInfo const& _functionInfo);
public:
/// Generate code for the function call @a _call.
void operator()(CFG::FunctionCall const& _call);
/// Generate code for the builtin call @a _call.
void operator()(CFG::BuiltinCall const& _call);
/// Generate code for the assignment @a _assignment.
void operator()(CFG::Assignment const& _assignment);
/// @returns the stack slots that would become unreachable when createStackLayout was called with
/// @a _targetStack as argument while m_stack was @a _stack.
static Stack tryCreateStackLayout(Stack const& _stack, Stack _targetStack);
private:
/// Assert that @a _slot contains the value of @a _expression.
static void validateSlot(StackSlot const& _slot, Expression const& _expression);
/// Assert that it is valid to transition from @a _currentStack to @a _desiredStack.
/// That is @a _currentStack matches each slot in @a _desiredStack that is not a JunkSlot exactly.
static void assertLayoutCompatibility(Stack const& _currentStack, Stack const& _desiredStack);
AbstractAssembly& m_assembly;
BuiltinContext& m_builtinContext;
bool m_useNamedLabelsForFunctions = true;
CFG const& m_dfg;
StackLayout const& m_stackLayout;
Stack m_stack;
std::map<yul::FunctionCall const*, AbstractAssembly::LabelID> m_returnLabels;
std::map<CFG::BasicBlock const*, AbstractAssembly::LabelID> m_blockLabels;
std::map<CFG::FunctionInfo const*, AbstractAssembly::LabelID> m_functionLabels;
/// Set of blocks already generated. If any of the contained blocks is ever jumped to, m_blockLabels should
/// contain a jump label for it.
std::set<CFG::BasicBlock const*> m_generated;
CFG::FunctionInfo const* m_currentFunctionInfo = nullptr;
};
}

View File

@ -0,0 +1,188 @@
/*
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/backends/evm/ControlFlowGraph.h>
#include <libyul/Exceptions.h>
#include <libsolutil/Visitor.h>
#include <range/v3/view/enumerate.hpp>
#include <range/v3/view/reverse.hpp>
namespace solidity::yul
{
inline std::string stackSlotToString(StackSlot const& _slot)
{
return std::visit(util::GenericVisitor{
[](FunctionCallReturnLabelSlot const& _ret) -> std::string { return "RET[" + _ret.call.get().functionName.name.str() + "]"; },
[](FunctionReturnLabelSlot const&) -> std::string { return "RET"; },
[](VariableSlot const& _var) { return _var.variable.get().name.str(); },
[](LiteralSlot const& _lit) { return util::toCompactHexWithPrefix(_lit.value); },
[](TemporarySlot const& _tmp) -> std::string { return "TMP[" + _tmp.call.get().functionName.name.str() + ", " + std::to_string(_tmp.index) + "]"; },
[](JunkSlot const&) -> std::string { return "JUNK"; }
}, _slot);
}
inline std::string stackToString(Stack const& _stack)
{
std::string result("[ ");
for (auto const& slot: _stack)
result += stackSlotToString(slot) + ' ';
result += ']';
return result;
}
template<typename Range, typename Value>
std::set<unsigned> findAllOffsets(Range&& _range, Value&& _value)
{
std::set<unsigned> result;
auto begin = std::begin(_range);
auto end = std::end(_range);
auto it = begin;
while (it != end)
{
it = std::find(it, end, std::forward<Value>(_value));
if (it == end)
return result;
result.emplace(static_cast<unsigned>(std::distance(begin, it)));
++it;
}
return result;
}
template<typename Swap, typename Dup, typename Pop, typename PushSlot>
void createStackLayout(Stack& _currentStack, Stack const& _targetStack, Swap _swap, Dup _dup, PushSlot _push, Pop _pop)
{
if (_currentStack == _targetStack)
return;
if (_currentStack.empty())
{
while (_currentStack.size() < _targetStack.size())
{
StackSlot newSlot = _targetStack.at(_currentStack.size());
_push(newSlot);
_currentStack.emplace_back(newSlot);
}
yulAssert(_currentStack == _targetStack, "");
return;
}
auto topTargets = findAllOffsets(_targetStack, _currentStack.back());
if (topTargets.size() < findAllOffsets(_currentStack, _currentStack.back()).size())
{
_pop();
_currentStack.pop_back();
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
else if (_targetStack.size() >= _currentStack.size() && _targetStack.at(_currentStack.size() - 1) == _currentStack.back())
{
// Current top is in place.
// Dup deepest one to be dupped (TODO: choose optimal).
for (auto&& [offset, slot]: _currentStack | ranges::views::enumerate)
{
if (findAllOffsets(_currentStack, slot).size() < findAllOffsets(_targetStack, slot).size())
{
auto leastDeepOccurrence = util::findOffset(_currentStack | ranges::views::reverse, slot);
yulAssert(leastDeepOccurrence, "");
_dup(static_cast<unsigned>(*leastDeepOccurrence + 1));
_currentStack.emplace_back(_currentStack.at(offset));
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
}
// Nothing to dup. Find anything to be pushed and push it.
for (auto const& slot: _targetStack)
{
if (!util::findOffset(_currentStack, slot))
{
_push(slot);
_currentStack.emplace_back(slot);
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
}
// Nothing to push or dup.
// Swap the deepest one that's not in place up.
for (auto&& [offset, slot]: _currentStack | ranges::views::enumerate)
{
if (!(slot == _targetStack.at(offset)) && !(slot == _currentStack.back()))
{
_swap(static_cast<unsigned>(_currentStack.size() - offset - 1));
std::swap(_currentStack.back(), _currentStack.at(offset));
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
}
// Nothing to push or dup and nothing out of place => done.
yulAssert(_currentStack == _targetStack, "");
return;
}
else
{
for (unsigned deepestTopTarget: topTargets)
{
if (deepestTopTarget >= _currentStack.size())
break;
if (!(_currentStack.at(deepestTopTarget) == _targetStack.at(deepestTopTarget)))
{
// Move top into place.
_swap(static_cast<unsigned>(_currentStack.size() - deepestTopTarget - 1));
std::swap(_currentStack.back(), _currentStack.at(deepestTopTarget));
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
}
// There needs to be something to dup or push. Try dupping. (TODO: suboptimal)
for (auto&& [offset, slot]: _currentStack | ranges::views::enumerate)
{
if (findAllOffsets(_currentStack, slot).size() < findAllOffsets(_targetStack, slot).size())
{
auto leastDeepOccurrence = util::findOffset(_currentStack | ranges::views::reverse, slot);
yulAssert(leastDeepOccurrence, "");
_dup(static_cast<unsigned>(*leastDeepOccurrence + 1));
// _dup(static_cast<unsigned>(_currentStack.size() - offset));
_currentStack.emplace_back(_currentStack.at(offset));
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
}
// Nothing to dup. Find anything to be pushed and push it.
for (auto const& slot: _targetStack)
{
if (!util::findOffset(_currentStack, slot))
{
_push(slot);
_currentStack.emplace_back(slot);
createStackLayout(_currentStack, _targetStack, _swap, _dup, _push, _pop);
return;
}
}
yulAssert(false, "");
}
yulAssert(_currentStack == _targetStack, "");
}
}

View File

@ -0,0 +1,567 @@
/*
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
/**
* Stack layout generator for Yul to EVM code generation.
*/
#include <libyul/backends/evm/StackLayoutGenerator.h>
#include <libyul/backends/evm/OptimizedEVMCodeTransform.h>
#include <libyul/backends/evm/StackHelpers.h>
#include <libsolutil/Algorithms.h>
#include <libsolutil/cxx20.h>
#include <libsolutil/Permutations.h>
#include <libsolutil/Visitor.h>
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/all.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/drop.hpp>
#include <range/v3/view/drop_last.hpp>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/map.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/take.hpp>
#include <range/v3/view/take_last.hpp>
#include <range/v3/view/transform.hpp>
using namespace solidity;
using namespace solidity::yul;
using namespace std;
StackLayoutGenerator::StackLayoutGenerator(StackLayout& _layout): m_layout(_layout)
{
}
namespace
{
struct PreviousSlot { size_t slot; };
// TODO: Rewrite this as custom algorithm matching createStackLayout exactly and make it work
// for all cases, including duplicates and removals of slots that can be generated on the fly, etc.
// After that the util::permute* functions can be removed.
Stack createIdealLayout(Stack const& _post, vector<variant<PreviousSlot, set<unsigned>>> layout)
{
util::permuteDup(static_cast<unsigned>(layout.size()), [&](unsigned _i) -> set<unsigned> {
// For call return values the target position is known.
if (set<unsigned>* pos = get_if<set<unsigned>>(&layout.at(_i)))
return *pos;
// Previous arguments can stay where they are.
return {_i};
}, [&](unsigned _i) {
std::swap(layout.back(), layout.at(layout.size() - _i - 1));
}, [&](unsigned _i) {
auto positions = get_if<set<unsigned>>(&layout.at(layout.size() - _i));
yulAssert(positions, "");
if (positions->count(static_cast<unsigned>(layout.size())))
{
positions->erase(static_cast<unsigned>(layout.size()));
layout.emplace_back(set<unsigned>{static_cast<unsigned>(layout.size())});
}
else
{
optional<unsigned> duppingOffset;
for (unsigned pos: *positions)
{
if (pos != layout.size() - _i)
{
duppingOffset = pos;
break;
}
}
yulAssert(duppingOffset, "");
positions->erase(*duppingOffset);
layout.emplace_back(set<unsigned>{*duppingOffset});
}
}, [&]() {
yulAssert(false, "");
}, [&]() {
layout.pop_back();
});
// Now we can construct the ideal layout before the operation.
// "layout" has the declared variables in the desired position and
// for any PreviousSlot{x}, x yields the ideal place of the slot before the declaration.
vector<optional<StackSlot>> idealLayout(_post.size(), nullopt);
for (auto const& [slot, idealPosition]: ranges::zip_view(_post, layout))
if (PreviousSlot* previousSlot = std::get_if<PreviousSlot>(&idealPosition))
idealLayout.at(previousSlot->slot) = slot;
while (!idealLayout.empty() && !idealLayout.back())
idealLayout.pop_back();
return idealLayout | ranges::views::transform([](optional<StackSlot> s) {
yulAssert(s, "");
return *s;
}) | ranges::to<Stack>;
}
}
Stack StackLayoutGenerator::propagateStackThroughOperation(Stack _exitStack, CFG::Operation const& _operation)
{
Stack& stack = _exitStack;
vector<set<unsigned>> targetPositions(_operation.output.size(), set<unsigned>{});
size_t numToKeep = 0;
for (size_t idx: ranges::views::iota(0u, targetPositions.size()))
for (unsigned offset: findAllOffsets(stack, _operation.output.at(idx)))
{
targetPositions[idx].emplace(offset);
++numToKeep;
}
auto layout = ranges::views::iota(0u, stack.size() - numToKeep) |
ranges::views::transform([](size_t _index) { return PreviousSlot{_index}; }) |
ranges::to<vector<variant<PreviousSlot, set<unsigned>>>>;
// The call produces values with known target positions.
layout += targetPositions;
stack = createIdealLayout(stack, layout);
if (auto const* assignment = get_if<CFG::Assignment>(&_operation.operation))
for (auto& stackSlot: stack)
if (auto const* varSlot = get_if<VariableSlot>(&stackSlot))
if (util::findOffset(assignment->variables, *varSlot))
stackSlot = JunkSlot{};
for (StackSlot const& input: _operation.input)
stack.emplace_back(input);
m_layout.operationEntryLayout[&_operation] = stack;
// TODO: We will potentially accumulate a lot of return labels here.
// Removing them naively has huge implications on both code size and runtime gas cost (both positive and negative):
// cxx20::erase_if(*m_stack, [](StackSlot const& _slot) { return holds_alternative<FunctionCallReturnLabelSlot>(_slot); });
// Consider removing them properly while accounting for the induced backwards stack shuffling.
// Remove anything from the stack top that can be freely generated or dupped from deeper on the stack.
while (!stack.empty() && (
canBeFreelyGenerated(stack.back()) ||
util::findOffset(stack | ranges::views::drop_last(1), stack.back())
))
stack.pop_back();
// TODO: suboptimal. Should account for induced stack shuffling.
// TODO: consider if we want this kind of compression at all, resp. whether stack.size() > 12 is a good condition.
if (stack.size() > 12)
stack = stack | ranges::views::enumerate | ranges::views::filter(util::mapTuple([&](size_t _index, StackSlot const& _slot) {
// Filter out slots that can be freely generated or are already present on the stack.
return !canBeFreelyGenerated(_slot) && !util::findOffset(stack | ranges::views::take(_index), _slot);
})) | ranges::views::values | ranges::to<Stack>;
return stack;
}
Stack StackLayoutGenerator::propagateStackThroughBlock(Stack _exitStack, CFG::BasicBlock const& _block)
{
Stack stack = std::move(_exitStack);
for (auto& operation: _block.operations | ranges::views::reverse)
stack = propagateStackThroughOperation(stack, operation);
return stack;
}
void StackLayoutGenerator::processEntryPoint(CFG::BasicBlock const& _entry)
{
std::list<CFG::BasicBlock const*> toVisit{&_entry};
std::set<CFG::BasicBlock const*> visited;
while (!toVisit.empty())
{
// TODO: calculate backwardsJumps only once.
std::list<std::pair<CFG::BasicBlock const*, CFG::BasicBlock const*>> backwardsJumps;
while (!toVisit.empty())
{
CFG::BasicBlock const *block = *toVisit.begin();
toVisit.pop_front();
if (visited.count(block))
continue;
if (std::optional<Stack> exitLayout = std::visit(util::GenericVisitor{
[&](CFG::BasicBlock::MainExit const&) -> std::optional<Stack>
{
visited.emplace(block);
return Stack{};
},
[&](CFG::BasicBlock::Jump const& _jump) -> std::optional<Stack>
{
if (_jump.backwards)
{
visited.emplace(block);
backwardsJumps.emplace_back(block, _jump.target);
if (auto* info = util::valueOrNullptr(m_layout.blockInfos, _jump.target))
return info->entryLayout;
return Stack{};
}
if (visited.count(_jump.target))
{
visited.emplace(block);
return m_layout.blockInfos.at(_jump.target).entryLayout;
}
toVisit.emplace_front(_jump.target);
return nullopt;
},
[&](CFG::BasicBlock::ConditionalJump const& _conditionalJump) -> std::optional<Stack>
{
bool zeroVisited = visited.count(_conditionalJump.zero);
bool nonZeroVisited = visited.count(_conditionalJump.nonZero);
if (zeroVisited && nonZeroVisited)
{
Stack stack = combineStack(
m_layout.blockInfos.at(_conditionalJump.zero).entryLayout,
m_layout.blockInfos.at(_conditionalJump.nonZero).entryLayout
);
stack.emplace_back(_conditionalJump.condition);
visited.emplace(block);
return stack;
}
if (!zeroVisited)
toVisit.emplace_front(_conditionalJump.zero);
if (!nonZeroVisited)
toVisit.emplace_front(_conditionalJump.nonZero);
return nullopt;
},
[&](CFG::BasicBlock::FunctionReturn const& _functionReturn) -> std::optional<Stack>
{
visited.emplace(block);
yulAssert(_functionReturn.info, "");
Stack stack = _functionReturn.info->returnVariables | ranges::views::transform([](auto const& _varSlot){
return StackSlot{_varSlot};
}) | ranges::to<Stack>;
stack.emplace_back(FunctionReturnLabelSlot{});
return stack;
},
[&](CFG::BasicBlock::Terminated const&) -> std::optional<Stack>
{
visited.emplace(block);
return Stack{};
},
}, block->exit))
{
// We can skip the visit, if we have seen this precise exit layout already last time.
// Note: if the entire graph is revisited in the backwards jump check below, doing
// this seems to break things; not sure why.
// Note: since I don't quite understand why doing this can break things, I comment
// it out for now, since not aborting in those cases should always be safe.
// if (auto* previousInfo = util::valueOrNullptr(m_layout.blockInfos, block))
// if (previousInfo->exitLayout == *exitLayout)
// continue;
auto& info = m_layout.blockInfos[block];
info.exitLayout = *exitLayout;
info.entryLayout = propagateStackThroughBlock(info.exitLayout, *block);
for (auto entry: block->entries)
toVisit.emplace_back(entry);
}
else
continue;
}
for (auto [block, target]: backwardsJumps)
if (ranges::any_of(
m_layout.blockInfos[target].entryLayout,
[exitLayout = m_layout.blockInfos[block].exitLayout](StackSlot const& _slot) {
return !util::findOffset(exitLayout, _slot);
}
))
{
// This block jumps backwards, but does not provide all slots required by the jump target on exit.
// Therefore we need to visit the subgraph between ``target`` and ``block`` again.
// In particular we can visit backwards starting from ``block`` and mark all entries to-be-visited-
// again until we hit ``target``.
toVisit.emplace_front(block);
util::BreadthFirstSearch<CFG::BasicBlock const*>{{block}}.run(
[&visited, target = target](CFG::BasicBlock const* _block, auto _addChild) {
visited.erase(_block);
if (_block == target)
return;
for (auto const* entry: _block->entries)
_addChild(entry);
}
);
// TODO: while the above is enough, the layout of ``target`` might change in the process.
// While the shuffled layout for ``target`` will be compatible, it can be worthwhile propagating
// it further up once more.
// This would mean not stopping at _block == target above or even doing visited.clear() here, revisiting the entire graph.
// This is a tradeoff between the runtime of this process and the optimality of the result.
// Also note that while visiting the entire graph again *can* be helpful, it can also be detrimental.
// Also note that for some reason using visited.clear() is incompatible with skipping the revisit
// of already seen exit layouts above, I'm not sure yet why.
}
}
stitchConditionalJumps(_entry);
fixStackTooDeep(_entry);
}
Stack StackLayoutGenerator::combineStack(Stack const& _stack1, Stack const& _stack2)
{
if (_stack1.empty())
return _stack2;
if (_stack2.empty())
return _stack1;
// TODO: there is probably a better way than brute-forcing. This has n! complexity or worse, so
// we can't keep it like this.
Stack commonPrefix;
for (auto&& [slot1, slot2]: ranges::zip_view(_stack1, _stack2))
{
if (!(slot1 == slot2))
break;
commonPrefix.emplace_back(slot1);
}
Stack stack1Tail = _stack1 | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>;
Stack stack2Tail = _stack2 | ranges::views::drop(commonPrefix.size()) | ranges::to<Stack>;
Stack candidate;
for (auto slot: stack1Tail)
if (!util::findOffset(candidate, slot))
candidate.emplace_back(slot);
for (auto slot: stack2Tail)
if (!util::findOffset(candidate, slot))
candidate.emplace_back(slot);
cxx20::erase_if(candidate, [](StackSlot const& slot) {
return holds_alternative<LiteralSlot>(slot) || holds_alternative<FunctionCallReturnLabelSlot>(slot);
});
std::map<size_t, Stack> sortedCandidates;
// TODO: surprisingly this works for rather comparably large candidate size, but we should probably
// set up some limit, since this will quickly explode otherwise.
// Ideally we would then have a better fallback mechanism - although returning any naive union of both stacks
// like ``candidate`` itself may just be fine.
// if (candidate.size() > 8)
// return candidate;
auto evaluate = [&](Stack const& _candidate) -> size_t {
size_t numOps = 0;
Stack testStack = _candidate;
auto swap = [&](unsigned _swapDepth) { ++numOps; if (_swapDepth > 16) numOps += 1000; };
auto dup = [&](unsigned _dupDepth) { ++numOps; if (_dupDepth > 16) numOps += 1000; };
auto push = [&](StackSlot const& _slot) {
if (!canBeFreelyGenerated(_slot))
{
auto offsetInPrefix = util::findOffset(commonPrefix, _slot);
yulAssert(offsetInPrefix, "");
// Effectively this is a dup.
++numOps;
// TODO: Verify that this is correct. The idea is to penalize dupping stuff up that's too deep in
// the prefix at this point.
if (commonPrefix.size() + testStack.size() - *offsetInPrefix > 16)
numOps += 1000;
}
};
createStackLayout(testStack, stack1Tail, swap, dup, push, [&](){} );
testStack = _candidate;
createStackLayout(testStack, stack2Tail, swap, dup, push, [&](){});
return numOps;
};
// See https://en.wikipedia.org/wiki/Heap's_algorithm
size_t n = candidate.size();
sortedCandidates.insert(std::make_pair(evaluate(candidate), candidate));
std::vector<size_t> c(n, 0);
size_t i = 1;
while (i < n)
{
if (c[i] < i)
{
if (i & 1)
std::swap(candidate.front(), candidate[i]);
else
std::swap(candidate[c[i]], candidate[i]);
sortedCandidates.insert(std::make_pair(evaluate(candidate), candidate));
++c[i];
++i;
}
else
{
c[i] = 0;
++i;
}
}
return commonPrefix + sortedCandidates.begin()->second;
}
void StackLayoutGenerator::stitchConditionalJumps(CFG::BasicBlock const& _block)
{
util::BreadthFirstSearch<CFG::BasicBlock const*> breadthFirstSearch{{&_block}};
breadthFirstSearch.run([&](CFG::BasicBlock const* _block, auto _addChild) {
auto& info = m_layout.blockInfos.at(_block);
std::visit(util::GenericVisitor{
[&](CFG::BasicBlock::MainExit const&) {},
[&](CFG::BasicBlock::Jump const& _jump)
{
if (!_jump.backwards)
_addChild(_jump.target);
},
[&](CFG::BasicBlock::ConditionalJump const& _conditionalJump)
{
auto& zeroTargetInfo = m_layout.blockInfos.at(_conditionalJump.zero);
auto& nonZeroTargetInfo = m_layout.blockInfos.at(_conditionalJump.nonZero);
Stack exitLayout = info.exitLayout;
// The last block must have produced the condition at the stack top.
yulAssert(!exitLayout.empty(), "");
yulAssert(exitLayout.back() == _conditionalJump.condition, "");
// The condition is consumed by the jump.
exitLayout.pop_back();
auto fixJumpTargetEntry = [&](Stack const& _originalEntryLayout) -> Stack {
Stack newEntryLayout = exitLayout;
// Whatever the block being jumped to does not actually require, can be marked as junk.
for (auto& slot: newEntryLayout)
if (!util::findOffset(_originalEntryLayout, slot))
slot = JunkSlot{};
// Make sure everything the block being jumped to requires is actually present or can be generated.
for (auto const& slot: _originalEntryLayout)
yulAssert(canBeFreelyGenerated(slot) || util::findOffset(newEntryLayout, slot), "");
return newEntryLayout;
};
zeroTargetInfo.entryLayout = fixJumpTargetEntry(zeroTargetInfo.entryLayout);
nonZeroTargetInfo.entryLayout = fixJumpTargetEntry(nonZeroTargetInfo.entryLayout);
_addChild(_conditionalJump.zero);
_addChild(_conditionalJump.nonZero);
},
[&](CFG::BasicBlock::FunctionReturn const&) {},
[&](CFG::BasicBlock::Terminated const&) { },
}, _block->exit);
});
}
void StackLayoutGenerator::fixStackTooDeep(CFG::BasicBlock const& _block)
{
// This is just an initial proof of concept. Doing this in a clever way and in all cases will take some doing.
// It might be enough to keep it at fixing inner-block issues and leave inter-block issues to the stack limit
// evader.
// TODO: make sure this really always terminates.
util::BreadthFirstSearch<CFG::BasicBlock const*> breadthFirstSearch{{&_block}};
breadthFirstSearch.run([&](CFG::BasicBlock const* _block, auto _addChild) {
Stack stack;
stack = m_layout.blockInfos.at(_block).entryLayout;
size_t cursor = 1;
while (cursor < _block->operations.size())
{
Stack& operationEntry = cursor < _block->operations.size() ?
m_layout.operationEntryLayout.at(&_block->operations.at(cursor)) :
m_layout.blockInfos.at(_block).exitLayout;
auto unreachable = OptimizedEVMCodeTransform::tryCreateStackLayout(stack, operationEntry);
if (unreachable.empty())
{
stack = operationEntry;
if (cursor < _block->operations.size())
{
CFG::Operation const& operation = _block->operations.at(cursor);
for (size_t i = 0; i < operation.input.size(); i++)
stack.pop_back();
stack += operation.output;
}
++cursor;
}
else
{
CFG::Operation const& previousOperation = _block->operations.at(cursor - 1);
if (auto const* assignment = get_if<CFG::Assignment>(&previousOperation.operation))
{
for (auto& slot: unreachable)
if (VariableSlot const* varSlot = get_if<VariableSlot>(&slot))
if (util::findOffset(assignment->variables, *varSlot))
{
// TODO: proper warning
std::cout << "Unreachable slot after assignment." << std::endl;
std::cout << "CANNOT FIX YET" << std::endl;
return;
}
}
Stack& previousEntry = m_layout.operationEntryLayout.at(&previousOperation);
Stack newStack = ranges::concat_view(
previousEntry | ranges::views::take(previousEntry.size() - previousOperation.input.size()),
unreachable,
previousEntry | ranges::views::take_last(previousOperation.input.size())
) | ranges::to<Stack>;
previousEntry = newStack;
--cursor;
if (cursor > 0)
{
CFG::Operation const& ancestorOperation = _block->operations.at(cursor - 1);
Stack& ancestorEntry = m_layout.operationEntryLayout.at(&ancestorOperation);
stack = ancestorEntry | ranges::views::take(ancestorEntry.size() - ancestorOperation.input.size()) | ranges::to<Stack>;
stack += ancestorOperation.output;
}
else
// Stop at block entry, hope for the best and continue downwards again.
++cursor;
}
}
stack = m_layout.blockInfos.at(_block).exitLayout;
std::visit(util::GenericVisitor{
[&](CFG::BasicBlock::MainExit const&) {},
[&](CFG::BasicBlock::Jump const& _jump)
{
auto unreachable = OptimizedEVMCodeTransform::tryCreateStackLayout(stack, m_layout.blockInfos.at(_jump.target).entryLayout);
if (!unreachable.empty())
// TODO: proper warning
std::cout << "UNREACHABLE SLOTS AT JUMP: " << stackToString(unreachable) << std::endl
<< "CANNOT FIX YET" << std::endl;
if (!_jump.backwards)
_addChild(_jump.target);
},
[&](CFG::BasicBlock::ConditionalJump const& _conditionalJump)
{
auto unreachable = OptimizedEVMCodeTransform::tryCreateStackLayout(stack, m_layout.blockInfos.at(_conditionalJump.zero).entryLayout);
if (!unreachable.empty())
// TODO: proper warning
std::cout
<< "UNREACHABLE SLOTS AT CONDITIONAL JUMP: " << stackToString(unreachable) << std::endl
<< "CANNOT FIX YET" << std::endl;
unreachable = OptimizedEVMCodeTransform::tryCreateStackLayout(stack, m_layout.blockInfos.at(_conditionalJump.nonZero).entryLayout);
if (!unreachable.empty())
// TODO: proper warning
std::cout
<< "UNREACHABLE SLOTS AT CONDITIONAL JUMP: " << stackToString(unreachable) << std::endl
<< "CANNOT FIX YET" << std::endl;
_addChild(_conditionalJump.zero);
_addChild(_conditionalJump.nonZero);
},
[&](CFG::BasicBlock::FunctionReturn const&) {},
[&](CFG::BasicBlock::Terminated const&) { },
}, _block->exit);
});
}
StackLayout StackLayoutGenerator::run(CFG const& _dfg)
{
StackLayout stackLayout;
StackLayoutGenerator stackLayoutGenerator{stackLayout};
stackLayoutGenerator.processEntryPoint(*_dfg.entry);
for (auto& functionInfo: _dfg.functionInfo | ranges::views::values)
stackLayoutGenerator.processEntryPoint(*functionInfo.entry);
return stackLayout;
}

View File

@ -0,0 +1,84 @@
/*
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
/**
* Stack layout generator for Yul to EVM code generation.
*/
#pragma once
#include <libyul/backends/evm/ControlFlowGraph.h>
#include <map>
namespace solidity::yul
{
struct StackLayout
{
struct BlockInfo
{
/// Complete stack layout that is required for entering a block.
Stack entryLayout;
/// The resulting stack layout after executing the block.
Stack exitLayout;
};
std::map<CFG::BasicBlock const*, BlockInfo> blockInfos;
/// For each operation the complete stack layout that:
/// - has the slots required for the operation at the stack top.
/// - will have the operation result in a layout that makes it easy to achieve the next desired layout.
std::map<CFG::Operation const*, Stack> operationEntryLayout;
};
class StackLayoutGenerator
{
public:
static StackLayout run(CFG const& _dfg);
private:
StackLayoutGenerator(StackLayout& _context);
/// @returns the optimal entry stack layout, s.t. @a _operation can be applied to it and
/// the result can be transformed to @a _exitStack with minimal stack shuffling.
Stack propagateStackThroughOperation(Stack _exitStack, CFG::Operation const& _operation);
/// @returns the desired stack layout at the entry of @a _block, assuming the layout after
/// executing the block should be @a _exitStack.
Stack propagateStackThroughBlock(Stack _exitStack, CFG::BasicBlock const& _block);
/// Main algorithm walking the graph from entry to exit and propagating back the stack layouts to the entries.
/// Iteratively reruns itself along backwards jumps until the layout is stabilized.
void processEntryPoint(CFG::BasicBlock const& _entry);
/// After the main algorithms, layouts at conditional jumps are merely compatible, i.e. the exit layout of the
/// jumping block is a superset of the entry layout of the target block. This function modifies the entry layouts
/// of conditional jump targets, s.t. the entry layout of target blocks match the exit layout of the jumping block
/// exactly, except that slots not required after the jump are marked as `JunkSlot`s.
void stitchConditionalJumps(CFG::BasicBlock const& _block);
/// Calculates the ideal stack layout, s.t. both @a _stack1 and @a _stack2 can be achieved with minimal
/// stack shuffling when starting from the returned layout.
static Stack combineStack(Stack const& _stack1, Stack const& _stack2);
/// Tries to detect stack layout transitions that are bound to cause stack too deep errors and
/// attempts to reorganize the layout to avoid those cases.
void fixStackTooDeep(CFG::BasicBlock const& _entry);
StackLayout& m_layout;
};
}

View File

@ -27,6 +27,7 @@
#include <libyul/optimiser/SSAValueTracker.h> #include <libyul/optimiser/SSAValueTracker.h>
#include <libyul/optimiser/Semantics.h> #include <libyul/optimiser/Semantics.h>
#include <libyul/optimiser/CallGraphGenerator.h> #include <libyul/optimiser/CallGraphGenerator.h>
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/Exceptions.h> #include <libyul/Exceptions.h>
#include <libyul/AST.h> #include <libyul/AST.h>
#include <libyul/Dialect.h> #include <libyul/Dialect.h>
@ -178,8 +179,17 @@ bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite)
return false; return false;
// Do not inline into already big functions. // Do not inline into already big functions.
if (
auto evmDialect = dynamic_cast<EVMDialect const*>(&m_dialect);
!evmDialect || !evmDialect->providesObjectAccess() || evmDialect->evmVersion() <= langutil::EVMVersion::homestead()
)
{
if (m_functionSizes.at(_callSite) > 45) if (m_functionSizes.at(_callSite) > 45)
return false; return false;
}
else
if (m_functionSizes.at(_callSite) > 350)
return false;
if (m_singleUse.count(calledFunction->name)) if (m_singleUse.count(calledFunction->name))
return true; return true;

View File

@ -19,96 +19,81 @@ object "C_59" {
object "C_59_deployed" { object "C_59_deployed" {
code { code {
{ {
mstore(64, 128) let _1 := 64
mstore(_1, 128)
if iszero(lt(calldatasize(), 4)) if iszero(lt(calldatasize(), 4))
{ {
let _1 := 0 let _2 := 0
if eq(0xf8eddcc6, shr(224, calldataload(_1))) if eq(0xf8eddcc6, shr(224, calldataload(_2)))
{ {
if callvalue() { revert(_1, _1) } if callvalue() { revert(_2, _2) }
let _2 := 32 let _3 := 32
if slt(add(calldatasize(), not(3)), _2) { revert(_1, _1) } if slt(add(calldatasize(), not(3)), _3) { revert(_2, _2) }
let offset := calldataload(4) let offset := calldataload(4)
let _3 := 0xffffffffffffffff let _4 := 0xffffffffffffffff
if gt(offset, _3) { revert(_1, _1) } if gt(offset, _4) { revert(_2, _2) }
if iszero(slt(add(offset, 35), calldatasize())) { revert(_1, _1) } if iszero(slt(add(offset, 35), calldatasize())) { revert(_2, _2) }
let _4 := calldataload(add(4, offset)) let _5 := calldataload(add(4, offset))
if gt(_4, _3) { panic_error_0x41() } if gt(_5, _4) { panic_error_0x41() }
let _5 := shl(5, _4) let _6 := shl(5, _5)
let dst := allocate_memory(add(_5, _2)) let memPtr := mload(_1)
let _7 := not(31)
let newFreePtr := add(memPtr, and(add(_6, 63), _7))
if or(gt(newFreePtr, _4), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(_1, newFreePtr)
let dst := memPtr
mstore(memPtr, _5)
dst := add(memPtr, _3)
let dst_1 := dst let dst_1 := dst
mstore(dst, _4)
dst := add(dst, _2)
let src := add(offset, 36) let src := add(offset, 36)
if gt(add(add(offset, _5), 36), calldatasize()) { revert(_1, _1) } if gt(add(add(offset, _6), 36), calldatasize()) { revert(_2, _2) }
let i := _1 let i := _2
for { } lt(i, _4) { i := add(i, 1) } for { } lt(i, _5) { i := add(i, 1) }
{ {
if slt(sub(calldatasize(), src), _2) { revert(_1, _1) } if slt(sub(calldatasize(), src), _3) { revert(_2, _2) }
let value := allocate_memory_1228() let memPtr_1 := mload(_1)
mstore(value, calldataload(src)) let newFreePtr_1 := add(memPtr_1, _3)
mstore(dst, value) if or(gt(newFreePtr_1, _4), lt(newFreePtr_1, memPtr_1)) { panic_error_0x41() }
dst := add(dst, _2) mstore(_1, newFreePtr_1)
src := add(src, _2) mstore(memPtr_1, calldataload(src))
mstore(dst, memPtr_1)
dst := add(dst, _3)
src := add(src, _3)
} }
let ret, ret_1 := fun_sumArray(dst_1) if iszero(mload(memPtr)) { panic_error_0x32() }
let memPos := mload(64) sstore(_2, mload(mload(dst_1)))
return(memPos, sub(abi_encode_uint256_string(memPos, ret, ret_1), memPos)) if iszero(lt(1, mload(memPtr))) { panic_error_0x32() }
let _8 := mload(mload(add(memPtr, _1)))
sstore(0x02, _8)
let memPtr_2 := mload(_1)
let newFreePtr_2 := add(memPtr_2, 160)
if or(gt(newFreePtr_2, _4), lt(newFreePtr_2, memPtr_2)) { panic_error_0x41() }
mstore(_1, newFreePtr_2)
mstore(memPtr_2, 100)
mstore(add(memPtr_2, _3), "longstringlongstringlongstringlo")
mstore(add(memPtr_2, _1), "ngstringlongstringlongstringlong")
let _9 := 96
mstore(add(memPtr_2, _9), "stringlongstringlongstringlongst")
mstore(add(memPtr_2, 128), "ring")
let memPos := mload(_1)
mstore(memPos, _8)
mstore(add(memPos, _3), _1)
let length := mload(memPtr_2)
mstore(add(memPos, _1), length)
let i_1 := _2
for { } lt(i_1, length) { i_1 := add(i_1, _3) }
{
mstore(add(add(memPos, i_1), _9), mload(add(add(memPtr_2, i_1), _3)))
}
if gt(i_1, length)
{
mstore(add(add(memPos, length), _9), _2)
}
return(memPos, add(sub(add(memPos, and(add(length, 31), _7)), memPos), _9))
} }
} }
revert(0, 0) revert(0, 0)
} }
function abi_encode_uint256_string(headStart, value0, value1) -> tail
{
mstore(headStart, value0)
let _1 := 32
mstore(add(headStart, _1), 64)
let length := mload(value1)
mstore(add(headStart, 64), length)
let i := 0
for { } lt(i, length) { i := add(i, _1) }
{
mstore(add(add(headStart, i), 96), mload(add(add(value1, i), _1)))
}
if gt(i, length)
{
mstore(add(add(headStart, length), 96), 0)
}
tail := add(add(headStart, and(add(length, 31), not(31))), 96)
}
function allocate_memory_1228() -> memPtr
{
memPtr := mload(64)
let newFreePtr := add(memPtr, 32)
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
}
function allocate_memory(size) -> memPtr
{
memPtr := mload(64)
let newFreePtr := add(memPtr, and(add(size, 31), not(31)))
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
}
function fun_sumArray(var_s_mpos) -> var, var_mpos
{
if iszero(mload(var_s_mpos)) { panic_error_0x32() }
sstore(0x00, mload(mload(add(var_s_mpos, 32))))
if iszero(lt(1, mload(var_s_mpos))) { panic_error_0x32() }
let _1 := mload(mload(add(var_s_mpos, 64)))
sstore(0x02, _1)
var := _1
let memPtr := mload(64)
let newFreePtr := add(memPtr, 160)
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { panic_error_0x41() }
mstore(64, newFreePtr)
mstore(memPtr, 100)
mstore(add(memPtr, 32), "longstringlongstringlongstringlo")
mstore(add(memPtr, 64), "ngstringlongstringlongstringlong")
mstore(add(memPtr, 96), "stringlongstringlongstringlongst")
mstore(add(memPtr, 128), "ring")
var_mpos := memPtr
}
function panic_error_0x32() function panic_error_0x32()
{ {
mstore(0, shl(224, 0x4e487b71)) mstore(0, shl(224, 0x4e487b71))

View File

@ -23,7 +23,7 @@ object "MyContract" {
Binary representation: Binary representation:
33600055600b806012600039806000f350fe60005460005260206000f3 33600055600b8060106000396000f3fe60005460005260206000f3
Text representation: Text representation:
/* "object_compiler/input.yul":128:136 */ /* "object_compiler/input.yul":128:136 */
@ -32,21 +32,19 @@ Text representation:
0x00 0x00
/* "object_compiler/input.yul":118:137 */ /* "object_compiler/input.yul":118:137 */
sstore sstore
dataSize(sub_0)
/* "object_compiler/input.yul":240:259 */ /* "object_compiler/input.yul":240:259 */
dataSize(sub_0)
dup1 dup1
/* "object_compiler/input.yul":217:238 */
dataOffset(sub_0) dataOffset(sub_0)
/* "object_compiler/input.yul":125:126 */ /* "object_compiler/input.yul":125:126 */
0x00 0x00
/* "object_compiler/input.yul":205:260 */ /* "object_compiler/input.yul":205:260 */
codecopy codecopy
/* "object_compiler/input.yul":275:294 */
dup1
/* "object_compiler/input.yul":125:126 */ /* "object_compiler/input.yul":125:126 */
0x00 0x00
/* "object_compiler/input.yul":265:295 */ /* "object_compiler/input.yul":265:295 */
return return
pop
stop stop
sub_0: assembly { sub_0: assembly {

View File

@ -43,16 +43,12 @@ object "Arraysum_34" {
var_sum := add(var_sum, _3) var_sum := add(var_sum, _3)
} }
let memPos := mload(64) let memPos := mload(64)
return(memPos, sub(abi_encode_uint256(memPos, var_sum), memPos)) mstore(memPos, var_sum)
return(memPos, 32)
} }
} }
revert(0, 0) revert(0, 0)
} }
function abi_encode_uint256(headStart, value0) -> tail
{
tail := add(headStart, 32)
mstore(headStart, value0)
}
function panic_error_0x11() function panic_error_0x11()
{ {
mstore(0, shl(224, 0x4e487b71)) mstore(0, shl(224, 0x4e487b71))

View File

@ -1,18 +1,14 @@
{"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":17:18 */ {"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":38:39 */
0x00 0x00
dup1
dup1
/* \"A\":11:19 */ /* \"A\":11:19 */
mload mload
/* \"A\":38:39 */
0x00
/* \"A\":34:35 */
0x00
/* \"A\":31:32 */
dup3
/* \"A\":27:36 */ /* \"A\":27:36 */
add add
/* \"A\":20:40 */ /* \"A\":20:40 */
sstore sstore
pop stop
","bytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}},"ir":"object \"object\" { ","bytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}},"ir":"object \"object\" {
code { code {
let x := mload(0) let x := mload(0)

View File

@ -1,10 +1,11 @@
{"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":17:18 */ {"contracts":{"A":{"object":{"evm":{"assembly":" /* \"A\":17:18 */
0x00 0x00
0x00 dup1
/* \"A\":11:19 */ /* \"A\":11:19 */
mload mload
/* \"A\":20:40 */ /* \"A\":20:40 */
sstore sstore
stop
","bytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}},"ir":"object \"object\" { ","bytecode":{"functionDebugData":{},"generatedSources":[],"linkReferences":{},"object":"<BYTECODE REMOVED>","opcodes":"<OPCODES REMOVED>","sourceMap":"<SOURCEMAP REMOVED>"}},"ir":"object \"object\" {
code { code {
let x := mload(0) let x := mload(0)

View File

@ -24,7 +24,7 @@ object "C_6" {
Binary representation: Binary representation:
60806040523415600f5760006000fd5b6010601d60003960106000f3fe608060405260043610155060006000fd 6080604052346016575b600f601c600039600f6000f35b600080fdfe6080604052600436101550600080fd
Text representation: Text representation:
/* "strict_asm_optimizer_steps/input.yul":45:48 */ /* "strict_asm_optimizer_steps/input.yul":45:48 */
@ -34,32 +34,28 @@ Text representation:
/* "strict_asm_optimizer_steps/input.yul":34:49 */ /* "strict_asm_optimizer_steps/input.yul":34:49 */
mstore mstore
/* "strict_asm_optimizer_steps/input.yul":61:72 */ /* "strict_asm_optimizer_steps/input.yul":61:72 */
callvalue jumpi(tag_1, callvalue)
/* "strict_asm_optimizer_steps/input.yul":58:60 */ tag_2:
iszero /* "strict_asm_optimizer_steps/input.yul":138:162 */
tag_1
jumpi
/* "strict_asm_optimizer_steps/input.yul":85:86 */
0x00
/* "strict_asm_optimizer_steps/input.yul":82:83 */
0x00
/* "strict_asm_optimizer_steps/input.yul":75:87 */
revert
/* "strict_asm_optimizer_steps/input.yul":58:60 */
tag_1:
/* "strict_asm_optimizer_steps/input.yul":98:163 */
dataSize(sub_0) dataSize(sub_0)
/* "strict_asm_optimizer_steps/input.yul":110:136 */
dataOffset(sub_0) dataOffset(sub_0)
/* "strict_asm_optimizer_steps/input.yul":107:108 */ /* "strict_asm_optimizer_steps/input.yul":107:108 */
0x00 0x00
/* "strict_asm_optimizer_steps/input.yul":98:163 */ /* "strict_asm_optimizer_steps/input.yul":98:163 */
codecopy codecopy
/* "strict_asm_optimizer_steps/input.yul":172:207 */ /* "strict_asm_optimizer_steps/input.yul":182:206 */
dataSize(sub_0) dataSize(sub_0)
/* "strict_asm_optimizer_steps/input.yul":179:180 */ /* "strict_asm_optimizer_steps/input.yul":179:180 */
0x00 0x00
/* "strict_asm_optimizer_steps/input.yul":172:207 */ /* "strict_asm_optimizer_steps/input.yul":172:207 */
return return
tag_1:
/* "strict_asm_optimizer_steps/input.yul":85:86 */
0x00
dup1
/* "strict_asm_optimizer_steps/input.yul":75:87 */
revert
stop stop
sub_0: assembly { sub_0: assembly {
@ -81,8 +77,7 @@ sub_0: assembly {
pop pop
/* "strict_asm_optimizer_steps/input.yul":570:571 */ /* "strict_asm_optimizer_steps/input.yul":570:571 */
0x00 0x00
/* "strict_asm_optimizer_steps/input.yul":567:568 */ dup1
0x00
/* "strict_asm_optimizer_steps/input.yul":560:572 */ /* "strict_asm_optimizer_steps/input.yul":560:572 */
revert revert
} }

View File

@ -1,9 +1,9 @@
======= viair_subobjects/input.sol:C ======= ======= viair_subobjects/input.sol:C =======
Binary: Binary:
60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd 6080604052346015575b600980601b6080396080f35b600080fdfe6080604052600080fd
Binary of the runtime part: Binary of the runtime part:
608060405260006000fd 6080604052600080fd
Optimized IR: Optimized IR:
/******************************************************* /*******************************************************
* WARNING * * WARNING *
@ -35,9 +35,9 @@ object "C_3" {
======= viair_subobjects/input.sol:D ======= ======= viair_subobjects/input.sol:D =======
Binary: Binary:
608060405234156100105760006000fd5b60ba80610020608039806080f350fe6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd 608060405234610017575b60ba8061001d6080396080f35b600080fdfe60806040526004361015610013575b600080fd5b6000803560e01c6326121ff01461002b575b5061000e565b34610092575b8060031936011261008f575b60248060800167ffffffffffffffff6080821091111761007a575b80610096608039608082f01561006e575b604051f35b604051903d90823e3d90fd5b50602490634e487b7160e01b81526041600452fd5b80fd5b80fdfe6080604052346015575b600980601b6080396080f35b600080fdfe6080604052600080fd
Binary of the runtime part: Binary of the runtime part:
6080604052600436101515608b576000803560e01c6326121ff0141560895734156027578081fd5b80600319360112156036578081fd5b6028806080016080811067ffffffffffffffff82111715606457634e487b7160e01b83526041600452602483fd5b508061009260803980608083f015156082576040513d83823e3d81fd505b5080604051f35b505b60006000fdfe60806040523415600f5760006000fd5b600a80601e608039806080f350fe608060405260006000fd 60806040526004361015610013575b600080fd5b6000803560e01c6326121ff01461002b575b5061000e565b34610092575b8060031936011261008f575b60248060800167ffffffffffffffff6080821091111761007a575b80610096608039608082f01561006e575b604051f35b604051903d90823e3d90fd5b50602490634e487b7160e01b81526041600452fd5b80fd5b80fdfe6080604052346015575b600980601b6080396080f35b600080fdfe6080604052600080fd
Optimized IR: Optimized IR:
/******************************************************* /*******************************************************
* WARNING * * WARNING *

View File

@ -39,167 +39,140 @@ object "object" {
Binary representation: Binary representation:
6001808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d55808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d5580815550 6001808055806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d55808055806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d55805500
Text representation: Text representation:
/* "yul_stack_opt/input.yul":98:99 */ /* "yul_stack_opt/input.yul":98:99 */
0x01 0x01
dup1 dup1
dup2 dup1
/* "yul_stack_opt/input.yul":129:141 */ /* "yul_stack_opt/input.yul":129:141 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":151:160 */ /* "yul_stack_opt/input.yul":151:160 */
0x02 0x02
/* "yul_stack_opt/input.yul":144:164 */ /* "yul_stack_opt/input.yul":144:164 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":174:183 */ /* "yul_stack_opt/input.yul":174:183 */
0x03 0x03
/* "yul_stack_opt/input.yul":167:187 */ /* "yul_stack_opt/input.yul":167:187 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":197:206 */ /* "yul_stack_opt/input.yul":197:206 */
0x04 0x04
/* "yul_stack_opt/input.yul":190:210 */ /* "yul_stack_opt/input.yul":190:210 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":220:229 */ /* "yul_stack_opt/input.yul":220:229 */
0x05 0x05
/* "yul_stack_opt/input.yul":213:233 */ /* "yul_stack_opt/input.yul":213:233 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":243:252 */ /* "yul_stack_opt/input.yul":243:252 */
0x06 0x06
/* "yul_stack_opt/input.yul":236:256 */ /* "yul_stack_opt/input.yul":236:256 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":266:275 */ /* "yul_stack_opt/input.yul":266:275 */
0x07 0x07
/* "yul_stack_opt/input.yul":259:279 */ /* "yul_stack_opt/input.yul":259:279 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":289:298 */ /* "yul_stack_opt/input.yul":289:298 */
0x08 0x08
/* "yul_stack_opt/input.yul":282:302 */ /* "yul_stack_opt/input.yul":282:302 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":312:321 */ /* "yul_stack_opt/input.yul":312:321 */
0x09 0x09
/* "yul_stack_opt/input.yul":305:325 */ /* "yul_stack_opt/input.yul":305:325 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":335:344 */ /* "yul_stack_opt/input.yul":335:344 */
0x0a 0x0a
/* "yul_stack_opt/input.yul":328:348 */ /* "yul_stack_opt/input.yul":328:348 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":358:368 */ /* "yul_stack_opt/input.yul":358:368 */
0x0b 0x0b
/* "yul_stack_opt/input.yul":351:372 */ /* "yul_stack_opt/input.yul":351:372 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":382:392 */ /* "yul_stack_opt/input.yul":382:392 */
0x0c 0x0c
/* "yul_stack_opt/input.yul":375:396 */ /* "yul_stack_opt/input.yul":375:396 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":406:416 */ /* "yul_stack_opt/input.yul":406:416 */
0x0d 0x0d
/* "yul_stack_opt/input.yul":399:420 */ /* "yul_stack_opt/input.yul":399:420 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
dup2 dup1
/* "yul_stack_opt/input.yul":129:141 */ /* "yul_stack_opt/input.yul":129:141 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":151:160 */ /* "yul_stack_opt/input.yul":151:160 */
0x02 0x02
/* "yul_stack_opt/input.yul":144:164 */ /* "yul_stack_opt/input.yul":144:164 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":174:183 */ /* "yul_stack_opt/input.yul":174:183 */
0x03 0x03
/* "yul_stack_opt/input.yul":167:187 */ /* "yul_stack_opt/input.yul":167:187 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":197:206 */ /* "yul_stack_opt/input.yul":197:206 */
0x04 0x04
/* "yul_stack_opt/input.yul":190:210 */ /* "yul_stack_opt/input.yul":190:210 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":220:229 */ /* "yul_stack_opt/input.yul":220:229 */
0x05 0x05
/* "yul_stack_opt/input.yul":213:233 */ /* "yul_stack_opt/input.yul":213:233 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":243:252 */ /* "yul_stack_opt/input.yul":243:252 */
0x06 0x06
/* "yul_stack_opt/input.yul":236:256 */ /* "yul_stack_opt/input.yul":236:256 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":266:275 */ /* "yul_stack_opt/input.yul":266:275 */
0x07 0x07
/* "yul_stack_opt/input.yul":259:279 */ /* "yul_stack_opt/input.yul":259:279 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":289:298 */ /* "yul_stack_opt/input.yul":289:298 */
0x08 0x08
/* "yul_stack_opt/input.yul":282:302 */ /* "yul_stack_opt/input.yul":282:302 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":312:321 */ /* "yul_stack_opt/input.yul":312:321 */
0x09 0x09
/* "yul_stack_opt/input.yul":305:325 */ /* "yul_stack_opt/input.yul":305:325 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":335:344 */ /* "yul_stack_opt/input.yul":335:344 */
0x0a 0x0a
/* "yul_stack_opt/input.yul":328:348 */ /* "yul_stack_opt/input.yul":328:348 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":358:368 */ /* "yul_stack_opt/input.yul":358:368 */
0x0b 0x0b
/* "yul_stack_opt/input.yul":351:372 */ /* "yul_stack_opt/input.yul":351:372 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":382:392 */ /* "yul_stack_opt/input.yul":382:392 */
0x0c 0x0c
/* "yul_stack_opt/input.yul":375:396 */ /* "yul_stack_opt/input.yul":375:396 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
/* "yul_stack_opt/input.yul":406:416 */ /* "yul_stack_opt/input.yul":406:416 */
0x0d 0x0d
/* "yul_stack_opt/input.yul":399:420 */ /* "yul_stack_opt/input.yul":399:420 */
sstore sstore
/* "yul_stack_opt/input.yul":98:99 */
dup1 dup1
dup2
/* "yul_stack_opt/input.yul":729:743 */ /* "yul_stack_opt/input.yul":729:743 */
sstore sstore
pop stop

View File

@ -14,7 +14,7 @@ object "object" {
Binary representation: Binary representation:
612000515061616002600055 61200051506161600260005500
Text representation: Text representation:
/* "yul_verbatim_msize/input.yul":125:131 */ /* "yul_verbatim_msize/input.yul":125:131 */
@ -30,3 +30,4 @@ Text representation:
0x00 0x00
/* "yul_verbatim_msize/input.yul":162:174 */ /* "yul_verbatim_msize/input.yul":162:174 */
sstore sstore
stop

View File

@ -24,6 +24,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0x20, 0x8, 0x40, 0x3, 0x9, 0xa, 0xb // f() -> 0x20, 0x8, 0x40, 0x3, 0x9, 0xa, 0xb
// gas irOptimized: 203921 // gas irOptimized: 204081
// gas legacy: 206126 // gas legacy: 206126
// gas legacyOptimized: 203105 // gas legacyOptimized: 203105

View File

@ -60,10 +60,10 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test_bytes() -> // test_bytes() ->
// gas irOptimized: 465417 // gas irOptimized: 390740
// gas legacy: 423563 // gas legacy: 423563
// gas legacyOptimized: 331391 // gas legacyOptimized: 331391
// test_uint256() -> // test_uint256() ->
// gas irOptimized: 661059 // gas irOptimized: 546333
// gas legacy: 591392 // gas legacy: 591392
// gas legacyOptimized: 456137 // gas legacyOptimized: 456137

View File

@ -26,6 +26,6 @@ contract C {
// ---- // ----
// library: L // library: L
// f() -> 8, 7, 1, 2, 7, 12 // f() -> 8, 7, 1, 2, 7, 12
// gas irOptimized: 168199 // gas irOptimized: 166704
// gas legacy: 169475 // gas legacy: 169475
// gas legacyOptimized: 167397 // gas legacyOptimized: 167397

View File

@ -61,10 +61,10 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test_bytes() -> // test_bytes() ->
// gas irOptimized: 465417 // gas irOptimized: 390740
// gas legacy: 423563 // gas legacy: 423563
// gas legacyOptimized: 331391 // gas legacyOptimized: 331391
// test_uint256() -> // test_uint256() ->
// gas irOptimized: 661059 // gas irOptimized: 546333
// gas legacy: 591392 // gas legacy: 591392
// gas legacyOptimized: 456137 // gas legacyOptimized: 456137

View File

@ -53,6 +53,6 @@ contract C {
// f2() -> 0x20, 0xa0, 0x1, 0x60, 0x2, 0x3, "abc" // f2() -> 0x20, 0xa0, 0x1, 0x60, 0x2, 0x3, "abc"
// f3() -> 0x20, 0xa0, 0x1, 0x60, 0x2, 0x3, "abc" // f3() -> 0x20, 0xa0, 0x1, 0x60, 0x2, 0x3, "abc"
// f4() -> 0x20, 0x160, 0x1, 0x80, 0xc0, 0x2, 0x3, "abc", 0x7, 0x40, 0x2, 0x2, 0x3 // f4() -> 0x20, 0x160, 0x1, 0x80, 0xc0, 0x2, 0x3, "abc", 0x7, 0x40, 0x2, 0x2, 0x3
// gas irOptimized: 113683 // gas irOptimized: 113098
// gas legacy: 114728 // gas legacy: 114728
// gas legacyOptimized: 112606 // gas legacyOptimized: 112606

View File

@ -32,6 +32,6 @@ contract C is B {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 77 // test() -> 77
// gas irOptimized: 132435 // gas irOptimized: 127054
// gas legacy: 155249 // gas legacy: 155249
// gas legacyOptimized: 111743 // gas legacyOptimized: 111743

View File

@ -40,5 +40,5 @@ contract C is B {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 5, 10 // test() -> 5, 10
// gas irOptimized: 91524 // gas irOptimized: 89080
// gas legacy: 99137 // gas legacy: 99137

View File

@ -21,6 +21,6 @@ contract C {
// f(uint256[][1]): 32, 32, 0 -> true // f(uint256[][1]): 32, 32, 0 -> true
// f(uint256[][1]): 32, 32, 1, 42 -> true // f(uint256[][1]): 32, 32, 1, 42 -> true
// f(uint256[][1]): 32, 32, 8, 421, 422, 423, 424, 425, 426, 427, 428 -> true // f(uint256[][1]): 32, 32, 8, 421, 422, 423, 424, 425, 426, 427, 428 -> true
// gas irOptimized: 224675 // gas irOptimized: 133946
// gas legacy: 141900 // gas legacy: 141900
// gas legacyOptimized: 121788 // gas legacyOptimized: 121788

View File

@ -19,10 +19,10 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// h(uint256[2][]): 0x20, 3, 123, 124, 223, 224, 323, 324 -> 32, 256, 0x20, 3, 123, 124, 223, 224, 323, 324 // h(uint256[2][]): 0x20, 3, 123, 124, 223, 224, 323, 324 -> 32, 256, 0x20, 3, 123, 124, 223, 224, 323, 324
// gas irOptimized: 181410 // gas irOptimized: 181484
// gas legacy: 184929 // gas legacy: 184929
// gas legacyOptimized: 181504 // gas legacyOptimized: 181504
// i(uint256[2][2]): 123, 124, 223, 224 -> 32, 128, 123, 124, 223, 224 // i(uint256[2][2]): 123, 124, 223, 224 -> 32, 128, 123, 124, 223, 224
// gas irOptimized: 112981 // gas irOptimized: 112920
// gas legacy: 115468 // gas legacy: 115468
// gas legacyOptimized: 112988 // gas legacyOptimized: 112988

View File

@ -11,6 +11,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg" // f(bytes): 0x20, 0x80, 0x21, 0x40, 0x7, "abcdefg" -> 0x21, 0x40, 0x7, "abcdefg"
// gas irOptimized: 136231 // gas irOptimized: 136127
// gas legacy: 137190 // gas legacy: 137190
// gas legacyOptimized: 136082 // gas legacyOptimized: 136082

View File

@ -14,7 +14,7 @@ contract Test {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06 // set(uint24[3][]): 0x20, 0x06, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12 -> 0x06
// gas irOptimized: 191293 // gas irOptimized: 189863
// gas legacy: 211485 // gas legacy: 211485
// gas legacyOptimized: 206394 // gas legacyOptimized: 206394
// data(uint256,uint256): 0x02, 0x02 -> 0x09 // data(uint256,uint256): 0x02, 0x02 -> 0x09

View File

@ -47,7 +47,7 @@ contract c {
// gas legacyOptimized: 58606 // gas legacyOptimized: 58606
// storageEmpty -> 0 // storageEmpty -> 0
// test_long() -> 67 // test_long() -> 67
// gas irOptimized: 91520 // gas irOptimized: 90990
// gas legacy: 103590 // gas legacy: 103590
// gas legacyOptimized: 101044 // gas legacyOptimized: 101044
// storageEmpty -> 0 // storageEmpty -> 0

View File

@ -19,6 +19,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0 // test() -> 0
// gas irOptimized: 171767 // gas irOptimized: 161154
// gas legacy: 189715 // gas legacy: 189715
// gas legacyOptimized: 184472 // gas legacyOptimized: 184472

View File

@ -15,7 +15,7 @@ contract c {
// ---- // ----
// getLength() -> 0 // getLength() -> 0
// set(): 1, 2 -> true // set(): 1, 2 -> true
// gas irOptimized: 110570 // gas irOptimized: 110451
// gas legacy: 110726 // gas legacy: 110726
// gas legacyOptimized: 110567 // gas legacyOptimized: 110567
// getLength() -> 68 // getLength() -> 68

View File

@ -22,7 +22,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// store(uint256[9],uint8[3][]): 21, 22, 23, 24, 25, 26, 27, 28, 29, 0x140, 4, 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33 -> 32 // store(uint256[9],uint8[3][]): 21, 22, 23, 24, 25, 26, 27, 28, 29, 0x140, 4, 1, 2, 3, 11, 12, 13, 21, 22, 23, 31, 32, 33 -> 32
// gas irOptimized: 651816 // gas irOptimized: 651532
// gas legacy: 694515 // gas legacy: 694515
// gas legacyOptimized: 694013 // gas legacyOptimized: 694013
// retrieve() -> 9, 28, 9, 28, 4, 3, 32 // retrieve() -> 9, 28, 9, 28, 4, 3, 32

View File

@ -23,6 +23,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> true // f() -> true
// gas irOptimized: 92958 // gas irOptimized: 91272
// gas legacy: 93035 // gas legacy: 93035
// gas legacyOptimized: 92257 // gas legacyOptimized: 92257

View File

@ -48,6 +48,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> true // f() -> true
// gas irOptimized: 154441 // gas irOptimized: 146336
// gas legacy: 155961 // gas legacy: 155961
// gas legacyOptimized: 153588 // gas legacyOptimized: 153588

View File

@ -15,6 +15,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0 // f() -> 0
// gas irOptimized: 135505 // gas irOptimized: 134523
// gas legacy: 135313 // gas legacy: 135313
// gas legacyOptimized: 134548 // gas legacyOptimized: 134548

View File

@ -42,11 +42,11 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0 // f() -> 0
// gas irOptimized: 92966 // gas irOptimized: 91293
// gas legacy: 93006 // gas legacy: 93006
// gas legacyOptimized: 92261 // gas legacyOptimized: 92261
// g() -> 0 // g() -> 0
// h() -> 0 // h() -> 0
// gas irOptimized: 93012 // gas irOptimized: 91380
// gas legacy: 93028 // gas legacy: 93028
// gas legacyOptimized: 92303 // gas legacyOptimized: 92303

View File

@ -21,6 +21,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x05000000000000000000000000000000000000000000000000 // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x05000000000000000000000000000000000000000000000000
// gas irOptimized: 214644 // gas irOptimized: 210357
// gas legacy: 221883 // gas legacy: 221883
// gas legacyOptimized: 220734 // gas legacyOptimized: 220734

View File

@ -37,12 +37,12 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x02000202 // test() -> 0x02000202
// gas irOptimized: 4690992 // gas irOptimized: 4682282
// gas legacy: 4578341 // gas legacy: 4578341
// gas legacyOptimized: 4548354 // gas legacyOptimized: 4548354
// storageEmpty -> 1 // storageEmpty -> 1
// clear() -> 0, 0 // clear() -> 0, 0
// gas irOptimized: 4516821 // gas irOptimized: 4506598
// gas legacy: 4410769 // gas legacy: 4410769
// gas legacyOptimized: 4382531 // gas legacyOptimized: 4382531
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -15,6 +15,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test(uint256[2][]): 32, 3, 7, 8, 9, 10, 11, 12 -> 10 // test(uint256[2][]): 32, 3, 7, 8, 9, 10, 11, 12 -> 10
// gas irOptimized: 691977 // gas irOptimized: 690179
// gas legacy: 686268 // gas legacy: 686268
// gas legacyOptimized: 685688 // gas legacyOptimized: 685688

View File

@ -19,6 +19,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 5, 4 // test() -> 5, 4
// gas irOptimized: 226467 // gas irOptimized: 225242
// gas legacy: 233801 // gas legacy: 233801
// gas legacyOptimized: 232816 // gas legacyOptimized: 232816

View File

@ -24,6 +24,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 3, 4 // test() -> 3, 4
// gas irOptimized: 191858 // gas irOptimized: 190637
// gas legacy: 195353 // gas legacy: 195353
// gas legacyOptimized: 192441 // gas legacyOptimized: 192441

View File

@ -17,7 +17,7 @@ contract c {
// ---- // ----
// setData1(uint256,uint256,uint256): 10, 5, 4 -> // setData1(uint256,uint256,uint256): 10, 5, 4 ->
// copyStorageStorage() -> // copyStorageStorage() ->
// gas irOptimized: 111563 // gas irOptimized: 111429
// gas legacy: 109278 // gas legacy: 109278
// gas legacyOptimized: 109268 // gas legacyOptimized: 109268
// getData2(uint256): 5 -> 10, 4 // getData2(uint256): 5 -> 10, 4

View File

@ -20,6 +20,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 5, 4 // test() -> 5, 4
// gas irOptimized: 272786 // gas irOptimized: 272096
// gas legacy: 270834 // gas legacy: 270834
// gas legacyOptimized: 269960 // gas legacyOptimized: 269960

View File

@ -14,6 +14,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 9, 4 // test() -> 9, 4
// gas irOptimized: 123375 // gas irOptimized: 123221
// gas legacy: 123579 // gas legacy: 123579
// gas legacyOptimized: 123208 // gas legacyOptimized: 123208

View File

@ -18,6 +18,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 8, 0 // test() -> 8, 0
// gas irOptimized: 236656 // gas irOptimized: 236388
// gas legacy: 234695 // gas legacy: 234695
// gas legacyOptimized: 234103 // gas legacyOptimized: 234103

View File

@ -19,7 +19,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 4, 5 // test() -> 4, 5
// gas irOptimized: 240552 // gas irOptimized: 239059
// gas legacy: 238736 // gas legacy: 238736
// gas legacyOptimized: 237159 // gas legacyOptimized: 237159
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -17,6 +17,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0x20, 2, 0x40, 0xa0, 2, 0, 1, 2, 2, 3 // f() -> 0x20, 2, 0x40, 0xa0, 2, 0, 1, 2, 2, 3
// gas irOptimized: 161991 // gas irOptimized: 160944
// gas legacy: 162278 // gas legacy: 162278
// gas legacyOptimized: 159955 // gas legacyOptimized: 159955

View File

@ -20,6 +20,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000 // test() -> 0xffffffff, 0x0000000000000000000000000a00090008000700060005000400030002000100, 0x0000000000000000000000000000000000000000000000000000000000000000
// gas irOptimized: 140618 // gas irOptimized: 126407
// gas legacy: 186406 // gas legacy: 186406
// gas legacyOptimized: 166126 // gas legacyOptimized: 166126

View File

@ -22,6 +22,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x04000000000000000000000000000000000000000000000000, 0x0, 0x0 // test() -> 0x04000000000000000000000000000000000000000000000000, 0x0, 0x0
// gas irOptimized: 95528 // gas irOptimized: 92325
// gas legacy: 97451 // gas legacy: 97451
// gas legacyOptimized: 94200 // gas legacyOptimized: 94200

View File

@ -22,6 +22,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x0 // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x0
// gas irOptimized: 296092 // gas irOptimized: 293911
// gas legacy: 303653 // gas legacy: 303653
// gas legacyOptimized: 301999 // gas legacyOptimized: 301999

View File

@ -22,6 +22,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00 // test() -> 0x01000000000000000000000000000000000000000000000000, 0x02000000000000000000000000000000000000000000000000, 0x03000000000000000000000000000000000000000000000000, 0x04000000000000000000000000000000000000000000000000, 0x00
// gas irOptimized: 274785 // gas irOptimized: 273418
// gas legacy: 276381 // gas legacy: 276381
// gas legacyOptimized: 275453 // gas legacyOptimized: 275453

View File

@ -38,10 +38,10 @@ contract c {
// compileViaYul: true // compileViaYul: true
// ---- // ----
// test1(uint256[][]): 0x20, 2, 0x40, 0x40, 2, 23, 42 -> 2, 65 // test1(uint256[][]): 0x20, 2, 0x40, 0x40, 2, 23, 42 -> 2, 65
// gas irOptimized: 182348 // gas irOptimized: 180097
// test2(uint256[][2]): 0x20, 0x40, 0x40, 2, 23, 42 -> 2, 65 // test2(uint256[][2]): 0x20, 0x40, 0x40, 2, 23, 42 -> 2, 65
// gas irOptimized: 158638 // gas irOptimized: 157464
// test3(uint256[2][]): 0x20, 2, 23, 42, 23, 42 -> 2, 65 // test3(uint256[2][]): 0x20, 2, 23, 42, 23, 42 -> 2, 65
// gas irOptimized: 135778 // gas irOptimized: 134984
// test4(uint256[2][2]): 23, 42, 23, 42 -> 65 // test4(uint256[2][2]): 23, 42, 23, 42 -> 65
// gas irOptimized: 111695 // gas irOptimized: 111483

View File

@ -40,12 +40,12 @@ contract Test {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 24 // test() -> 24
// gas irOptimized: 227891 // gas irOptimized: 226186
// gas legacy: 227133 // gas legacy: 227133
// gas legacyOptimized: 226547 // gas legacyOptimized: 226547
// test1() -> 3 // test1() -> 3
// test2() -> 6 // test2() -> 6
// test3() -> 24 // test3() -> 24
// gas irOptimized: 134338 // gas irOptimized: 133423
// gas legacy: 134295 // gas legacy: 134295
// gas legacyOptimized: 133383 // gas legacyOptimized: 133383

View File

@ -17,4 +17,4 @@ contract C {
// compileViaYul: true // compileViaYul: true
// ---- // ----
// f((uint128,uint64,uint128)[]): 0x20, 3, 0, 0, 12, 0, 11, 0, 10, 0, 0 -> 10, 11, 12 // f((uint128,uint64,uint128)[]): 0x20, 3, 0, 0, 12, 0, 11, 0, 10, 0, 0 -> 10, 11, 12
// gas irOptimized: 121461 // gas irOptimized: 120509

View File

@ -19,4 +19,4 @@ contract C {
// compileViaYul: true // compileViaYul: true
// ---- // ----
// f() -> 10, 11, 12 // f() -> 10, 11, 12
// gas irOptimized: 120457 // gas irOptimized: 119248

View File

@ -23,4 +23,4 @@ contract C {
// compileViaYul: true // compileViaYul: true
// ---- // ----
// f((uint256[])[]): 0x20, 3, 0x60, 0x60, 0x60, 0x20, 3, 1, 2, 3 -> 3, 1 // f((uint256[])[]): 0x20, 3, 0x60, 0x60, 0x60, 0x20, 3, 1, 2, 3 -> 3, 1
// gas irOptimized: 332878 // gas irOptimized: 321914

View File

@ -26,4 +26,4 @@ contract C {
// compileViaYul: true // compileViaYul: true
// ---- // ----
// f() -> 3, 3, 3, 1 // f() -> 3, 3, 3, 1
// gas irOptimized: 185077 // gas irOptimized: 183750

View File

@ -15,6 +15,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 1, 2, 3 // f() -> 1, 2, 3
// gas irOptimized: 133671 // gas irOptimized: 132265
// gas legacy: 134619 // gas legacy: 134619
// gas legacyOptimized: 131940 // gas legacyOptimized: 131940

View File

@ -12,7 +12,7 @@ contract Test {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// set(uint24[]): 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 -> 18 // set(uint24[]): 0x20, 18, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 -> 18
// gas irOptimized: 101659 // gas irOptimized: 99934
// gas legacy: 103815 // gas legacy: 103815
// gas legacyOptimized: 101614 // gas legacyOptimized: 101614
// data(uint256): 7 -> 8 // data(uint256): 7 -> 8

View File

@ -7,11 +7,11 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// set(uint256): 1, 2 -> true // set(uint256): 1, 2 -> true
// gas irOptimized: 110824 // gas irOptimized: 110621
// gas legacy: 111091 // gas legacy: 111091
// gas legacyOptimized: 110736 // gas legacyOptimized: 110736
// set(uint256): 2, 2, 3, 4, 5 -> true // set(uint256): 2, 2, 3, 4, 5 -> true
// gas irOptimized: 177811 // gas irOptimized: 177590
// gas legacy: 178021 // gas legacy: 178021
// gas legacyOptimized: 177666 // gas legacyOptimized: 177666
// storageEmpty -> 0 // storageEmpty -> 0

View File

@ -19,25 +19,25 @@ contract c {
// ---- // ----
// f(uint256): 0 -> 0x20, 0x00 // f(uint256): 0 -> 0x20, 0x00
// f(uint256): 31 -> 0x20, 0x1f, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00 // f(uint256): 31 -> 0x20, 0x1f, 0x0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e00
// gas irOptimized: 135396 // gas irOptimized: 114862
// gas legacy: 124364 // gas legacy: 124364
// gas legacyOptimized: 119898 // gas legacyOptimized: 119898
// f(uint256): 32 -> 0x20, 0x20, 1780731860627700044960722568376592200742329637303199754547598369979440671 // f(uint256): 32 -> 0x20, 0x20, 1780731860627700044960722568376592200742329637303199754547598369979440671
// gas irOptimized: 142291 // gas irOptimized: 121021
// gas legacy: 135431 // gas legacy: 135431
// gas legacyOptimized: 130829 // gas legacyOptimized: 130829
// f(uint256): 33 -> 0x20, 33, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x2000000000000000000000000000000000000000000000000000000000000000 // f(uint256): 33 -> 0x20, 33, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x2000000000000000000000000000000000000000000000000000000000000000
// gas irOptimized: 149603 // gas irOptimized: 127832
// gas legacy: 142238 // gas legacy: 142238
// gas legacyOptimized: 137518 // gas legacyOptimized: 137518
// f(uint256): 63 -> 0x20, 0x3f, 1780731860627700044960722568376592200742329637303199754547598369979440671, 14532552714582660066924456880521368950258152170031413196862950297402215316992 // f(uint256): 63 -> 0x20, 0x3f, 1780731860627700044960722568376592200742329637303199754547598369979440671, 14532552714582660066924456880521368950258152170031413196862950297402215316992
// gas irOptimized: 174873 // gas irOptimized: 133392
// gas legacy: 160728 // gas legacy: 160728
// gas legacyOptimized: 152168 // gas legacyOptimized: 152168
// f(uint256): 12 -> 0x20, 0x0c, 0x0102030405060708090a0b0000000000000000000000000000000000000000 // f(uint256): 12 -> 0x20, 0x0c, 0x0102030405060708090a0b0000000000000000000000000000000000000000
// gas legacy: 59345 // gas legacy: 59345
// gas legacyOptimized: 57279 // gas legacyOptimized: 57279
// f(uint256): 129 -> 0x20, 0x81, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f, 29063324697304692433803953038474361308315562010425523193971352996434451193439, 0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f, -57896044618658097711785492504343953926634992332820282019728792003956564819968 // f(uint256): 129 -> 0x20, 0x81, 1780731860627700044960722568376592200742329637303199754547598369979440671, 0x202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f, 29063324697304692433803953038474361308315562010425523193971352996434451193439, 0x606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f, -57896044618658097711785492504343953926634992332820282019728792003956564819968
// gas irOptimized: 452115 // gas irOptimized: 367467
// gas legacy: 423017 // gas legacy: 423017
// gas legacyOptimized: 406021 // gas legacyOptimized: 406021

View File

@ -11,6 +11,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f(uint256[]): 0x20, 0x03, 0x1, 0x2, 0x3 -> 0x1 // f(uint256[]): 0x20, 0x03, 0x1, 0x2, 0x3 -> 0x1
// gas irOptimized: 111384 // gas irOptimized: 111103
// gas legacy: 111565 // gas legacy: 111565
// gas legacyOptimized: 111347 // gas legacyOptimized: 111347

View File

@ -37,11 +37,11 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0x40, 0x80, 6, 0x6162636465660000000000000000000000000000000000000000000000000000, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000 // f() -> 0x40, 0x80, 6, 0x6162636465660000000000000000000000000000000000000000000000000000, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000
// gas irOptimized: 180274 // gas irOptimized: 180098
// gas legacy: 180694 // gas legacy: 180694
// gas legacyOptimized: 180088 // gas legacyOptimized: 180088
// g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000 // g() -> 0x40, 0xc0, 0x49, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738393031323334353637383930313233343536373839303120, 0x3132333435363738390000000000000000000000000000000000000000000000, 0x11, 0x3132333435363738393233343536373839000000000000000000000000000000
// gas irOptimized: 107618 // gas irOptimized: 107525
// gas legacy: 107895 // gas legacy: 107895
// gas legacyOptimized: 107254 // gas legacyOptimized: 107254
// h() -> 0x40, 0x60, 0x00, 0x00 // h() -> 0x40, 0x60, 0x00, 0x00

View File

@ -48,6 +48,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0xff // f() -> 0xff
// gas irOptimized: 122009 // gas irOptimized: 120116
// gas legacy: 126745 // gas legacy: 126745
// gas legacyOptimized: 123476 // gas legacyOptimized: 123476

View File

@ -18,6 +18,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 7 // test() -> 7
// gas irOptimized: 127846 // gas irOptimized: 126713
// gas legacy: 205196 // gas legacy: 205196
// gas legacyOptimized: 204987 // gas legacyOptimized: 204987

View File

@ -9,7 +9,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// set(): 1, 2, 3, 4, 5 -> true // set(): 1, 2, 3, 4, 5 -> true
// gas irOptimized: 177557 // gas irOptimized: 177429
// gas legacy: 177656 // gas legacy: 177656
// gas legacyOptimized: 177496 // gas legacyOptimized: 177496
// storageEmpty -> 0 // storageEmpty -> 0

View File

@ -20,6 +20,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 3 // f() -> 3
// gas irOptimized: 134208 // gas irOptimized: 128887
// gas legacy: 130307 // gas legacy: 130307
// gas legacyOptimized: 129363 // gas legacyOptimized: 129363

View File

@ -19,6 +19,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 1, 2, 3, 4, 5, 6, 7 // f() -> 1, 2, 3, 4, 5, 6, 7
// gas irOptimized: 209108 // gas irOptimized: 205948
// gas legacy: 212325 // gas legacy: 212325
// gas legacyOptimized: 211486 // gas legacyOptimized: 211486

View File

@ -13,6 +13,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0x20, 0x02, 0x40, 0x80, 3, 0x6162630000000000000000000000000000000000000000000000000000000000, 0x99, 44048183304486788312148433451363384677562265908331949128489393215789685032262, 32241931068525137014058842823026578386641954854143559838526554899205067598957, 49951309422467613961193228765530489307475214998374779756599339590522149884499, 0x54555658595a6162636465666768696a6b6c6d6e6f707172737475767778797a, 0x4142434445464748494a4b4c4d4e4f5051525354555658595a00000000000000 // f() -> 0x20, 0x02, 0x40, 0x80, 3, 0x6162630000000000000000000000000000000000000000000000000000000000, 0x99, 44048183304486788312148433451363384677562265908331949128489393215789685032262, 32241931068525137014058842823026578386641954854143559838526554899205067598957, 49951309422467613961193228765530489307475214998374779756599339590522149884499, 0x54555658595a6162636465666768696a6b6c6d6e6f707172737475767778797a, 0x4142434445464748494a4b4c4d4e4f5051525354555658595a00000000000000
// gas irOptimized: 203063 // gas irOptimized: 203008
// gas legacy: 204459 // gas legacy: 204459
// gas legacyOptimized: 203437 // gas legacyOptimized: 203437

View File

@ -20,6 +20,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 1, 2, 3, 4, 5, 6, 7 // f() -> 1, 2, 3, 4, 5, 6, 7
// gas irOptimized: 209108 // gas irOptimized: 205948
// gas legacy: 212330 // gas legacy: 212330
// gas legacyOptimized: 211491 // gas legacyOptimized: 211491

View File

@ -26,6 +26,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 11, 0x0c, 1, 0x15, 22, 4 // f() -> 11, 0x0c, 1, 0x15, 22, 4
// gas irOptimized: 293695 // gas irOptimized: 291768
// gas legacy: 293516 // gas legacy: 293516
// gas legacyOptimized: 290263 // gas legacyOptimized: 290263

View File

@ -15,6 +15,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 2, 3, 4 // f() -> 2, 3, 4
// gas irOptimized: 115383 // gas irOptimized: 118794
// gas legacy: 126449 // gas legacy: 126449
// gas legacyOptimized: 120902 // gas legacyOptimized: 120902

View File

@ -20,6 +20,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> "A", 8, 4, "B" // f() -> "A", 8, 4, "B"
// gas irOptimized: 150997 // gas irOptimized: 128810
// gas legacy: 121398 // gas legacy: 121398
// gas legacyOptimized: 115494 // gas legacyOptimized: 115494

View File

@ -18,6 +18,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test1() -> true // test1() -> true
// gas irOptimized: 244579 // gas irOptimized: 212092
// gas legacy: 255577 // gas legacy: 255577
// gas legacyOptimized: 248611 // gas legacyOptimized: 248611

View File

@ -16,4 +16,4 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 0, 0, 0 // f() -> 0, 0, 0
// gas irOptimized: 91179 // gas irOptimized: 90107

View File

@ -16,7 +16,7 @@ contract c {
// ---- // ----
// storageEmpty -> 1 // storageEmpty -> 1
// fill() -> // fill() ->
// gas irOptimized: 520998 // gas irOptimized: 520360
// gas legacy: 521773 // gas legacy: 521773
// gas legacyOptimized: 517048 // gas legacyOptimized: 517048
// storageEmpty -> 0 // storageEmpty -> 0

View File

@ -44,7 +44,7 @@ contract c {
// ---- // ----
// getLengths() -> 0, 0 // getLengths() -> 0, 0
// setLengths(uint256,uint256): 48, 49 -> // setLengths(uint256,uint256): 48, 49 ->
// gas irOptimized: 108326 // gas irOptimized: 103558
// gas legacy: 108571 // gas legacy: 108571
// gas legacyOptimized: 100417 // gas legacyOptimized: 100417
// getLengths() -> 48, 49 // getLengths() -> 48, 49

View File

@ -18,7 +18,7 @@ contract c {
// ---- // ----
// storageEmpty -> 1 // storageEmpty -> 1
// fill() -> 8 // fill() -> 8
// gas irOptimized: 124480 // gas irOptimized: 116558
// gas legacy: 121756 // gas legacy: 121756
// gas legacyOptimized: 120687 // gas legacyOptimized: 120687
// storageEmpty -> 0 // storageEmpty -> 0

View File

@ -13,7 +13,7 @@ contract c {
// ---- // ----
// storageEmpty -> 1 // storageEmpty -> 1
// fill() -> // fill() ->
// gas irOptimized: 465878 // gas irOptimized: 465538
// gas legacy: 471460 // gas legacy: 471460
// gas legacyOptimized: 467520 // gas legacyOptimized: 467520
// storageEmpty -> 0 // storageEmpty -> 0

View File

@ -21,6 +21,6 @@ contract B {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f() -> 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003, 1004 // f() -> 2, 3, 4, 5, 6, 1000, 1001, 1002, 1003, 1004
// gas irOptimized: 133483 // gas irOptimized: 116423
// gas legacy: 235167 // gas legacy: 235167
// gas legacyOptimized: 133299 // gas legacyOptimized: 133299

View File

@ -45,6 +45,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 5, 6, 7 // test() -> 5, 6, 7
// gas irOptimized: 337455 // gas irOptimized: 314380
// gas legacy: 463662 // gas legacy: 463662
// gas legacyOptimized: 296513 // gas legacyOptimized: 296513

View File

@ -25,7 +25,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 1, 2, 3 // test() -> 1, 2, 3
// gas irOptimized: 2280897 // gas irOptimized: 2270841
// gas legacy: 2273722 // gas legacy: 2273722
// gas legacyOptimized: 2262396 // gas legacyOptimized: 2262396
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -20,7 +20,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 38, 28, 18 // test() -> 38, 28, 18
// gas irOptimized: 195867 // gas irOptimized: 187932
// gas legacy: 189780 // gas legacy: 189780
// gas legacyOptimized: 178870 // gas legacyOptimized: 178870
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -20,7 +20,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 20, 10 // test() -> 20, 10
// gas irOptimized: 163721 // gas irOptimized: 159134
// gas legacy: 159459 // gas legacy: 159459
// gas legacyOptimized: 153281 // gas legacyOptimized: 153281
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -12,6 +12,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000 // test() -> 0x20, 29, 0x0303030303030303030303030303030303030303030303030303030303000000
// gas irOptimized: 112526 // gas irOptimized: 111672
// gas legacy: 127309 // gas legacy: 127309
// gas legacyOptimized: 124136 // gas legacyOptimized: 124136

View File

@ -18,7 +18,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> true // test() -> true
// gas irOptimized: 219418 // gas irOptimized: 184772
// gas legacy: 229864 // gas legacy: 229864
// gas legacyOptimized: 210964 // gas legacyOptimized: 210964
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -17,7 +17,7 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> // test() ->
// gas irOptimized: 150914 // gas irOptimized: 146901
// gas legacy: 165363 // gas legacy: 165363
// gas legacyOptimized: 159446 // gas legacyOptimized: 159446
// storageEmpty -> 1 // storageEmpty -> 1

View File

@ -12,6 +12,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0x20, 33, 0x303030303030303030303030303030303030303030303030303030303030303, 0x0300000000000000000000000000000000000000000000000000000000000000 // test() -> 0x20, 33, 0x303030303030303030303030303030303030303030303030303030303030303, 0x0300000000000000000000000000000000000000000000000000000000000000
// gas irOptimized: 110514 // gas irOptimized: 109293
// gas legacy: 126187 // gas legacy: 126187
// gas legacyOptimized: 123261 // gas legacyOptimized: 123261

View File

@ -18,6 +18,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 5, 4, 3, 3 // test() -> 5, 4, 3, 3
// gas irOptimized: 111269 // gas irOptimized: 110866
// gas legacy: 111838 // gas legacy: 111838
// gas legacyOptimized: 111128 // gas legacyOptimized: 111128

View File

@ -14,6 +14,6 @@ contract C {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// f(uint120[]): 0x20, 3, 1, 2, 3 -> 1 // f(uint120[]): 0x20, 3, 1, 2, 3 -> 1
// gas irOptimized: 113684 // gas irOptimized: 112175
// gas legacy: 113686 // gas legacy: 113686
// gas legacyOptimized: 113499 // gas legacyOptimized: 113499

View File

@ -16,6 +16,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 1, 2, 3, 4 // test() -> 1, 2, 3, 4
// gas irOptimized: 93083 // gas irOptimized: 91505
// gas legacy: 92798 // gas legacy: 92798
// gas legacyOptimized: 92062 // gas legacyOptimized: 92062

View File

@ -22,6 +22,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 2, 3, 4, 5 // test() -> 2, 3, 4, 5
// gas irOptimized: 138070 // gas irOptimized: 136581
// gas legacy: 147484 // gas legacy: 147484
// gas legacyOptimized: 146456 // gas legacyOptimized: 146456

View File

@ -18,6 +18,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test((uint16,uint16,uint16[3],uint16[])): 0x20, 2, 3, 0, 0, 4, 0xC0, 4, 0, 0, 5, 0, 0 -> 2, 3, 4, 5 // test((uint16,uint16,uint16[3],uint16[])): 0x20, 2, 3, 0, 0, 4, 0xC0, 4, 0, 0, 5, 0, 0 -> 2, 3, 4, 5
// gas irOptimized: 139798 // gas irOptimized: 138718
// gas legacy: 144322 // gas legacy: 144322
// gas legacyOptimized: 139171 // gas legacyOptimized: 139171

View File

@ -17,6 +17,6 @@ contract c {
// compileViaYul: also // compileViaYul: also
// ---- // ----
// test() -> 0 // test() -> 0
// gas irOptimized: 195787 // gas irOptimized: 178770
// gas legacy: 218028 // gas legacy: 218028
// gas legacyOptimized: 205124 // gas legacyOptimized: 205124

Some files were not shown because too many files have changed in this diff Show More