mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9314 from ethereum/inlineStartingFromLeaves
Handle "leaf functions" first in full inliner.
This commit is contained in:
commit
552a5f0913
@ -8,6 +8,7 @@ Compiler Features:
|
||||
* SMTChecker: Support structs.
|
||||
* SMTChecker: Support ``type(T).min`` and ``type(T).max``.
|
||||
* Yul Optimizer: Prune unused parameters in functions.
|
||||
* Yul Optimizer: Inline into functions further down in the call graph first.
|
||||
* Yul Optimizer: Try to simplify function names.
|
||||
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <libyul/optimiser/Metrics.h>
|
||||
#include <libyul/optimiser/SSAValueTracker.h>
|
||||
#include <libyul/optimiser/Semantics.h>
|
||||
#include <libyul/optimiser/CallGraphGenerator.h>
|
||||
#include <libyul/Exceptions.h>
|
||||
#include <libyul/AsmData.h>
|
||||
#include <libyul/Dialect.h>
|
||||
@ -41,7 +42,9 @@ using namespace solidity::yul;
|
||||
|
||||
void FullInliner::run(OptimiserStepContext& _context, Block& _ast)
|
||||
{
|
||||
FullInliner{_ast, _context.dispenser, _context.dialect}.run();
|
||||
FullInliner inliner{_ast, _context.dispenser, _context.dialect};
|
||||
inliner.run(Pass::InlineTiny);
|
||||
inliner.run(Pass::InlineRest);
|
||||
}
|
||||
|
||||
FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const& _dialect):
|
||||
@ -72,14 +75,9 @@ FullInliner::FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const&
|
||||
}
|
||||
}
|
||||
|
||||
void FullInliner::run()
|
||||
void FullInliner::run(Pass _pass)
|
||||
{
|
||||
for (auto& statement: m_ast.statements)
|
||||
if (holds_alternative<Block>(statement))
|
||||
handleBlock({}, std::get<Block>(statement));
|
||||
|
||||
// TODO it might be good to determine a visiting order:
|
||||
// first handle functions that are called from many places.
|
||||
m_pass = _pass;
|
||||
|
||||
// Note that the order of inlining can result in very different code.
|
||||
// Since AST IDs and thus function names depend on whether or not a contract
|
||||
@ -87,14 +85,76 @@ void FullInliner::run()
|
||||
// should have as little an impact as possible. This is the case
|
||||
// if we handle inlining in source (and thus, for the IR generator,
|
||||
// function name) order.
|
||||
// We use stable_sort below to keep the inlining order of two functions
|
||||
// with the same depth.
|
||||
map<YulString, size_t> depths = callDepths();
|
||||
vector<FunctionDefinition*> functions;
|
||||
for (auto& statement: m_ast.statements)
|
||||
if (holds_alternative<FunctionDefinition>(statement))
|
||||
functions.emplace_back(&std::get<FunctionDefinition>(statement));
|
||||
std::stable_sort(functions.begin(), functions.end(), [depths](
|
||||
FunctionDefinition const* _a,
|
||||
FunctionDefinition const* _b
|
||||
) {
|
||||
return depths.at(_a->name) < depths.at(_b->name);
|
||||
});
|
||||
for (FunctionDefinition* fun: functions)
|
||||
{
|
||||
if (!holds_alternative<FunctionDefinition>(statement))
|
||||
continue;
|
||||
FunctionDefinition& fun = std::get<FunctionDefinition>(statement);
|
||||
handleBlock(fun.name, fun.body);
|
||||
updateCodeSize(fun);
|
||||
handleBlock(fun->name, fun->body);
|
||||
updateCodeSize(*fun);
|
||||
}
|
||||
|
||||
for (auto& statement: m_ast.statements)
|
||||
if (holds_alternative<Block>(statement))
|
||||
handleBlock({}, std::get<Block>(statement));
|
||||
}
|
||||
|
||||
map<YulString, size_t> FullInliner::callDepths() const
|
||||
{
|
||||
CallGraph cg = CallGraphGenerator::callGraph(m_ast);
|
||||
cg.functionCalls.erase(""_yulstring);
|
||||
|
||||
// Remove calls to builtin functions.
|
||||
for (auto& call: cg.functionCalls)
|
||||
for (auto it = call.second.begin(); it != call.second.end();)
|
||||
if (m_dialect.builtin(*it))
|
||||
it = call.second.erase(it);
|
||||
else
|
||||
++it;
|
||||
|
||||
map<YulString, size_t> depths;
|
||||
size_t currentDepth = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
vector<YulString> removed;
|
||||
for (auto it = cg.functionCalls.begin(); it != cg.functionCalls.end();)
|
||||
{
|
||||
auto const& [fun, callees] = *it;
|
||||
if (callees.empty())
|
||||
{
|
||||
removed.emplace_back(fun);
|
||||
depths[fun] = currentDepth;
|
||||
it = cg.functionCalls.erase(it);
|
||||
}
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
for (auto& call: cg.functionCalls)
|
||||
call.second -= removed;
|
||||
|
||||
currentDepth++;
|
||||
|
||||
if (removed.empty())
|
||||
break;
|
||||
}
|
||||
|
||||
// Only recursive functions left here.
|
||||
for (auto const& fun: cg.functionCalls)
|
||||
depths[fun.first] = currentDepth;
|
||||
|
||||
return depths;
|
||||
}
|
||||
|
||||
bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite)
|
||||
@ -115,6 +175,10 @@ bool FullInliner::shallInline(FunctionCall const& _funCall, YulString _callSite)
|
||||
if (size <= 1)
|
||||
return true;
|
||||
|
||||
// In the first pass, only inline tiny functions.
|
||||
if (m_pass == Pass::InlineTiny)
|
||||
return false;
|
||||
|
||||
// Do not inline into already big functions.
|
||||
if (m_functionSizes.at(_callSite) > 45)
|
||||
return false;
|
||||
|
@ -91,13 +91,20 @@ public:
|
||||
void tentativelyUpdateCodeSize(YulString _function, YulString _callSite);
|
||||
|
||||
private:
|
||||
enum Pass { InlineTiny, InlineRest };
|
||||
|
||||
FullInliner(Block& _ast, NameDispenser& _dispenser, Dialect const& _dialect);
|
||||
void run();
|
||||
void run(Pass _pass);
|
||||
|
||||
/// @returns a map containing the maximum depths of a call chain starting at each
|
||||
/// function. For recursive functions, the value is one larger than for all others.
|
||||
std::map<YulString, size_t> callDepths() const;
|
||||
|
||||
void updateCodeSize(FunctionDefinition const& _fun);
|
||||
void handleBlock(YulString _currentFunctionName, Block& _block);
|
||||
bool recursive(FunctionDefinition const& _fun) const;
|
||||
|
||||
Pass m_pass;
|
||||
/// The AST to be modified. The root block itself will not be modified, because
|
||||
/// we store pointers to functions.
|
||||
Block& m_ast;
|
||||
|
@ -26,49 +26,40 @@ object "C_56" {
|
||||
if eq(0xf8eddcc6, shr(224, calldataload(_1)))
|
||||
{
|
||||
if callvalue() { revert(_1, _1) }
|
||||
if slt(add(calldatasize(), not(3)), 32) { revert(_1, _1) }
|
||||
let _2 := 32
|
||||
if slt(add(calldatasize(), not(3)), _2) { revert(_1, _1) }
|
||||
let offset := calldataload(4)
|
||||
if gt(offset, 0xffffffffffffffff) { revert(_1, _1) }
|
||||
let value0 := abi_decode_t_array$_t_struct$_S_$dyn(add(4, offset), calldatasize())
|
||||
let value := mload(mload(memory_array_index_access$_t_struct$_S_$dyn(value0, _1)))
|
||||
let _2, _3 := storage_array_index_access$_t_struct$_S_storage(_1, _1)
|
||||
sstore(_2, value)
|
||||
let value_1 := mload(mload(memory_array_index_access$_t_struct$_S_$dyn(value0, 0x01)))
|
||||
let _4, _5 := storage_array_index_access$_t_struct$_S_storage(0x02, _1)
|
||||
update_storage_value_t_uint256_to_t_uint256(_4, _5, value_1)
|
||||
let _6, _7 := storage_array_index_access$_t_struct$_S_storage(0x02, _1)
|
||||
let vloc := extract_from_storage_value_dynamict_uint256(sload(_6), _7)
|
||||
let vloc__24_mpos := convert_t_stringliteral_6490_to_t_string()
|
||||
let _3 := 0xffffffffffffffff
|
||||
if gt(offset, _3) { revert(_1, _1) }
|
||||
if iszero(slt(add(offset, 35), calldatasize())) { revert(_1, _1) }
|
||||
let length := calldataload(add(4, offset))
|
||||
if gt(length, _3) { revert(_1, _1) }
|
||||
let _4 := mul(length, _2)
|
||||
let dst := allocateMemory(add(_4, _2))
|
||||
let dst_1 := dst
|
||||
mstore(dst, length)
|
||||
dst := add(dst, _2)
|
||||
let src := add(offset, 36)
|
||||
if gt(add(add(offset, _4), 36), calldatasize()) { revert(_1, _1) }
|
||||
let i := _1
|
||||
for { } lt(i, length) { i := add(i, 1) }
|
||||
{
|
||||
mstore(dst, abi_decode_t_struct$_S(src, calldatasize()))
|
||||
dst := add(dst, _2)
|
||||
src := add(src, _2)
|
||||
}
|
||||
let ret, ret_1 := fun_sumArray_55(dst_1)
|
||||
let memPos := allocateMemory(_1)
|
||||
return(memPos, sub(abi_encode_uint256_t_string(memPos, vloc, vloc__24_mpos), memPos))
|
||||
return(memPos, sub(abi_encode_uint256_t_string(memPos, ret, ret_1), memPos))
|
||||
}
|
||||
}
|
||||
revert(0, 0)
|
||||
}
|
||||
function abi_decode_t_array$_t_struct$_S_$dyn(offset, end) -> array
|
||||
function abi_decode_t_struct$_S(headStart, end) -> value
|
||||
{
|
||||
if iszero(slt(add(offset, 0x1f), end)) { revert(array, array) }
|
||||
let length := calldataload(offset)
|
||||
if gt(length, 0xffffffffffffffff) { revert(array, array) }
|
||||
let _1 := 0x20
|
||||
let _2 := mul(length, _1)
|
||||
array := allocateMemory(add(_2, _1))
|
||||
let dst := array
|
||||
mstore(array, length)
|
||||
dst := add(array, _1)
|
||||
let src := add(offset, _1)
|
||||
if gt(add(add(offset, _2), _1), end) { revert(0, 0) }
|
||||
let i := 0
|
||||
let i_1 := i
|
||||
for { } lt(i_1, length) { i_1 := add(i_1, 1) }
|
||||
{
|
||||
if slt(sub(end, src), _1) { revert(i, i) }
|
||||
let value := allocateMemory(_1)
|
||||
mstore(value, calldataload(src))
|
||||
mstore(dst, value)
|
||||
dst := add(dst, _1)
|
||||
src := add(src, _1)
|
||||
}
|
||||
if slt(sub(end, headStart), 0x20) { revert(value, value) }
|
||||
value := allocateMemory(0x20)
|
||||
mstore(value, calldataload(headStart))
|
||||
}
|
||||
function abi_encode_uint256_t_string(headStart, value0, value1) -> tail
|
||||
{
|
||||
@ -108,10 +99,24 @@ object "C_56" {
|
||||
{
|
||||
value := shr(mul(offset, 8), slot_value)
|
||||
}
|
||||
function memory_array_index_access$_t_struct$_S_$dyn(baseRef, index) -> addr
|
||||
function fun_sumArray_55(vloc__s_19_mpos) -> vloc, vloc__24_mpos
|
||||
{
|
||||
if iszero(lt(index, mload(baseRef))) { invalid() }
|
||||
addr := add(add(baseRef, mul(index, 32)), 32)
|
||||
let _1 := mload(vloc__s_19_mpos)
|
||||
if iszero(lt(vloc, _1)) { invalid() }
|
||||
let _2 := mload(mload(add(add(vloc__s_19_mpos, mul(vloc, 32)), 32)))
|
||||
let _3, _4 := storage_array_index_access$_t_struct$_S_storage(vloc, vloc)
|
||||
sstore(_3, _2)
|
||||
if iszero(lt(0x01, _1)) { invalid() }
|
||||
let _5 := mload(mload(add(vloc__s_19_mpos, 64)))
|
||||
if iszero(lt(vloc, 0x02)) { invalid() }
|
||||
let slot := add(0x02, vloc)
|
||||
let _6 := sload(slot)
|
||||
let shiftBits := mul(vloc, 8)
|
||||
let mask := shl(shiftBits, not(0))
|
||||
sstore(slot, or(and(_6, not(mask)), and(shl(shiftBits, _5), mask)))
|
||||
let _7, _8 := storage_array_index_access$_t_struct$_S_storage(0x02, vloc)
|
||||
vloc := extract_from_storage_value_dynamict_uint256(sload(_7), _8)
|
||||
vloc__24_mpos := convert_t_stringliteral_6490_to_t_string()
|
||||
}
|
||||
function storage_array_index_access$_t_struct$_S_storage(array, index) -> slot, offset
|
||||
{
|
||||
@ -119,13 +124,6 @@ object "C_56" {
|
||||
slot := add(array, index)
|
||||
offset := offset
|
||||
}
|
||||
function update_storage_value_t_uint256_to_t_uint256(slot, offset, value)
|
||||
{
|
||||
let _1 := sload(slot)
|
||||
let shiftBits := mul(offset, 8)
|
||||
let mask := shl(shiftBits, not(0))
|
||||
sstore(slot, or(and(_1, not(mask)), and(shl(shiftBits, value), mask)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,11 +33,14 @@ object "Arraysum_33" {
|
||||
for { }
|
||||
lt(vloc_i, _2)
|
||||
{
|
||||
vloc_i := increment_t_uint256(vloc_i)
|
||||
if gt(vloc_i, not(1)) { revert(_1, _1) }
|
||||
vloc_i := add(vloc_i, 1)
|
||||
}
|
||||
{
|
||||
let _3, _4 := storage_array_index_access$_t_uint256_$dyn_storage(_1, vloc_i)
|
||||
vloc_sum := checked_add_t_uint256(vloc_sum, extract_from_storage_value_dynamict_uint256(sload(_3), _4))
|
||||
mstore(_1, _1)
|
||||
let _3 := sload(add(keccak256(_1, 0x20), vloc_i))
|
||||
if gt(vloc_sum, not(_3)) { revert(_1, _1) }
|
||||
vloc_sum := add(vloc_sum, _3)
|
||||
}
|
||||
let memPos := allocateMemory(_1)
|
||||
return(memPos, sub(abi_encode_uint(memPos, _1), memPos))
|
||||
@ -57,27 +60,6 @@ object "Arraysum_33" {
|
||||
if or(gt(newFreePtr, 0xffffffffffffffff), lt(newFreePtr, memPtr)) { revert(0, 0) }
|
||||
mstore(64, newFreePtr)
|
||||
}
|
||||
function checked_add_t_uint256(x, y) -> sum
|
||||
{
|
||||
if gt(x, not(y)) { revert(sum, sum) }
|
||||
sum := add(x, y)
|
||||
}
|
||||
function extract_from_storage_value_dynamict_uint256(slot_value, offset) -> value
|
||||
{
|
||||
value := shr(mul(offset, 8), slot_value)
|
||||
}
|
||||
function increment_t_uint256(value) -> ret
|
||||
{
|
||||
if gt(value, not(1)) { revert(ret, ret) }
|
||||
ret := add(value, 1)
|
||||
}
|
||||
function storage_array_index_access$_t_uint256_$dyn_storage(array, index) -> slot, offset
|
||||
{
|
||||
if iszero(lt(index, sload(array))) { invalid() }
|
||||
mstore(slot, array)
|
||||
slot := add(keccak256(slot, 0x20), index)
|
||||
offset := offset
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,9 +6,6 @@
|
||||
(import \"ethereum\" \"finish\" (func $eth.finish (param i32 i32)))
|
||||
(memory $memory (export \"memory\") 1)
|
||||
(export \"main\" (func $main))
|
||||
(global $global_ (mut i64) (i64.const 0))
|
||||
(global $global__1 (mut i64) (i64.const 0))
|
||||
(global $global__2 (mut i64) (i64.const 0))
|
||||
|
||||
(func $main
|
||||
(local $_1 i64)
|
||||
@ -18,7 +15,6 @@
|
||||
(local $z1 i64)
|
||||
(local $z2 i64)
|
||||
(local $z3 i64)
|
||||
(local $z4 i64)
|
||||
(local $_3 i64)
|
||||
(block $label_
|
||||
(local.set $_1 (i64.const 0))
|
||||
@ -32,18 +28,14 @@
|
||||
(i64.store (i32.add (local.get $r) (i32.const 16)) (local.get $_2))
|
||||
(i64.store (i32.add (local.get $r) (i32.const 24)) (call $endian_swap (i64.const 128)))
|
||||
(call $eth.getCallValue (i32.const 0))
|
||||
(block
|
||||
(local.set $z1 (call $mload_internal (i32.const 0)))
|
||||
(local.set $z2 (global.get $global_))
|
||||
(local.set $z3 (global.get $global__1))
|
||||
(local.set $z4 (global.get $global__2))
|
||||
|
||||
)
|
||||
(if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $z1) (local.get $z2)) (i64.or (local.get $z3) (local.get $z4))))) (then
|
||||
(call $eth.revert (call $to_internal_i32ptr (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)) (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)))))
|
||||
(local.set $z1 (call $endian_swap (i64.load (i32.const 0))))
|
||||
(local.set $z2 (call $endian_swap (i64.load (i32.add (i32.const 0) (i32.const 8)))))
|
||||
(local.set $z3 (call $endian_swap (i64.load (i32.add (i32.const 0) (i32.const 16)))))
|
||||
(if (i32.eqz (i64.eqz (i64.or (i64.or (local.get $z1) (local.get $z2)) (i64.or (local.get $z3) (call $endian_swap (i64.load (i32.add (i32.const 0) (i32.const 24)))))))) (then
|
||||
(call $revert (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1))))
|
||||
(local.set $_3 (datasize \"C_2_deployed\"))
|
||||
(call $eth.codeCopy (call $to_internal_i32ptr (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)) (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (dataoffset \"C_2_deployed\")) (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_3)))
|
||||
(call $eth.finish (call $to_internal_i32ptr (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1)) (call $u256_to_i32 (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_3)))
|
||||
(call $codecopy (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (dataoffset \"C_2_deployed\") (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_3))
|
||||
(call $return (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_1) (local.get $_3))
|
||||
)
|
||||
)
|
||||
|
||||
@ -54,7 +46,7 @@
|
||||
(param $x4 i64)
|
||||
(result i32)
|
||||
(local $v i32)
|
||||
(block $label__3
|
||||
(block $label__1
|
||||
(if (i64.ne (i64.const 0) (i64.or (i64.or (local.get $x1) (local.get $x2)) (local.get $x3))) (then
|
||||
(unreachable)))
|
||||
(if (i64.ne (i64.const 0) (i64.shr_u (local.get $x4) (i64.const 32))) (then
|
||||
@ -73,7 +65,7 @@
|
||||
(result i32)
|
||||
(local $r i32)
|
||||
(local $p i32)
|
||||
(block $label__4
|
||||
(block $label__2
|
||||
(local.set $p (call $u256_to_i32 (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)))
|
||||
(local.set $r (i32.add (local.get $p) (i32.const 64)))
|
||||
(if (i32.lt_u (local.get $r) (local.get $p)) (then
|
||||
@ -83,11 +75,29 @@
|
||||
(local.get $r)
|
||||
)
|
||||
|
||||
(func $codecopy
|
||||
(param $x1 i64)
|
||||
(param $x2 i64)
|
||||
(param $x3 i64)
|
||||
(param $x4 i64)
|
||||
(param $y1 i64)
|
||||
(param $y2 i64)
|
||||
(param $y3 i64)
|
||||
(param $y4 i64)
|
||||
(param $z1 i64)
|
||||
(param $z2 i64)
|
||||
(param $z3 i64)
|
||||
(param $z4 i64)
|
||||
(block $label__3
|
||||
(call $eth.codeCopy (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)) (call $u256_to_i32 (local.get $z1) (local.get $z2) (local.get $z3) (local.get $z4)))
|
||||
)
|
||||
)
|
||||
|
||||
(func $endian_swap_16
|
||||
(param $x i64)
|
||||
(result i64)
|
||||
(local $y i64)
|
||||
(block $label__5
|
||||
(block $label__4
|
||||
(local.set $y (i64.or (i64.and (i64.shl (local.get $x) (i64.const 8)) (i64.const 65280)) (i64.and (i64.shr_u (local.get $x) (i64.const 8)) (i64.const 255))))
|
||||
|
||||
)
|
||||
@ -99,7 +109,7 @@
|
||||
(result i64)
|
||||
(local $y i64)
|
||||
(local $hi i64)
|
||||
(block $label__6
|
||||
(block $label__5
|
||||
(local.set $hi (i64.shl (call $endian_swap_16 (local.get $x)) (i64.const 16)))
|
||||
(local.set $y (i64.or (local.get $hi) (call $endian_swap_16 (i64.shr_u (local.get $x) (i64.const 16)))))
|
||||
|
||||
@ -112,7 +122,7 @@
|
||||
(result i64)
|
||||
(local $y i64)
|
||||
(local $hi i64)
|
||||
(block $label__7
|
||||
(block $label__6
|
||||
(local.set $hi (i64.shl (call $endian_swap_32 (local.get $x)) (i64.const 32)))
|
||||
(local.set $y (i64.or (local.get $hi) (call $endian_swap_32 (i64.shr_u (local.get $x) (i64.const 32)))))
|
||||
|
||||
@ -120,24 +130,32 @@
|
||||
(local.get $y)
|
||||
)
|
||||
|
||||
(func $mload_internal
|
||||
(param $pos i32)
|
||||
(result i64)
|
||||
(local $z1 i64)
|
||||
(local $z2 i64)
|
||||
(local $z3 i64)
|
||||
(local $z4 i64)
|
||||
(block $label__8
|
||||
(local.set $z1 (call $endian_swap (i64.load (local.get $pos))))
|
||||
(local.set $z2 (call $endian_swap (i64.load (i32.add (local.get $pos) (i32.const 8)))))
|
||||
(local.set $z3 (call $endian_swap (i64.load (i32.add (local.get $pos) (i32.const 16)))))
|
||||
(local.set $z4 (call $endian_swap (i64.load (i32.add (local.get $pos) (i32.const 24)))))
|
||||
|
||||
(func $return
|
||||
(param $x1 i64)
|
||||
(param $x2 i64)
|
||||
(param $x3 i64)
|
||||
(param $x4 i64)
|
||||
(param $y1 i64)
|
||||
(param $y2 i64)
|
||||
(param $y3 i64)
|
||||
(param $y4 i64)
|
||||
(block $label__7
|
||||
(call $eth.finish (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)))
|
||||
)
|
||||
)
|
||||
|
||||
(func $revert
|
||||
(param $x1 i64)
|
||||
(param $x2 i64)
|
||||
(param $x3 i64)
|
||||
(param $x4 i64)
|
||||
(param $y1 i64)
|
||||
(param $y2 i64)
|
||||
(param $y3 i64)
|
||||
(param $y4 i64)
|
||||
(block $label__8
|
||||
(call $eth.revert (call $to_internal_i32ptr (local.get $x1) (local.get $x2) (local.get $x3) (local.get $x4)) (call $u256_to_i32 (local.get $y1) (local.get $y2) (local.get $y3) (local.get $y4)))
|
||||
)
|
||||
(global.set $global_ (local.get $z2))
|
||||
(global.set $global__1 (local.get $z3))
|
||||
(global.set $global__2 (local.get $z4))
|
||||
(local.get $z1)
|
||||
)
|
||||
|
||||
)
|
||||
|
@ -4,12 +4,6 @@
|
||||
Pretty printed source:
|
||||
object "object" {
|
||||
code {
|
||||
{
|
||||
let a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, o3, p3 := fun()
|
||||
let a3_1, b3_1, c3_1, d3_1, e3_1, f3_1, g3_1, h3_1, i3_1, j3_1, k3_1, l3_1, m3_1, o3_1, p3_1 := fun()
|
||||
sstore(a3, a3_1)
|
||||
}
|
||||
function fun() -> a3, b3, c3, d3, e3, f3, g3, h3, i3, j3, k3, l3, m3, o3, p3
|
||||
{
|
||||
let _1 := 1
|
||||
sstore(_1, _1)
|
||||
@ -25,93 +19,29 @@ object "object" {
|
||||
sstore(11, _1)
|
||||
sstore(12, _1)
|
||||
sstore(13, _1)
|
||||
a3 := _1
|
||||
b3 := _1
|
||||
c3 := _1
|
||||
d3 := _1
|
||||
e3 := _1
|
||||
f3 := _1
|
||||
g3 := _1
|
||||
h3 := _1
|
||||
i3 := _1
|
||||
j3 := _1
|
||||
k3 := _1
|
||||
l3 := _1
|
||||
m3 := _1
|
||||
o3 := _1
|
||||
p3 := _1
|
||||
sstore(_1, _1)
|
||||
sstore(2, _1)
|
||||
sstore(3, _1)
|
||||
sstore(4, _1)
|
||||
sstore(5, _1)
|
||||
sstore(6, _1)
|
||||
sstore(7, _1)
|
||||
sstore(8, _1)
|
||||
sstore(9, _1)
|
||||
sstore(10, _1)
|
||||
sstore(11, _1)
|
||||
sstore(12, _1)
|
||||
sstore(13, _1)
|
||||
sstore(_1, _1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary representation:
|
||||
60056030565b505050505050505050505050505060196030565b5050505050505050505050505050808255505060c3565b6000600060006000600060006000600060006000600060006000600060006001808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d55809f50809e50809d50809c50809b50809a50809950809850809750809650809550809450809350809250809150505b909192939495969798999a9b9c9d9e565b
|
||||
6001808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d55808155806002558060035580600455806005558060065580600755806008558060095580600a5580600b5580600c5580600d5580815550
|
||||
|
||||
Text representation:
|
||||
/* "yul_stack_opt/input.sol":3:573 */
|
||||
tag_1
|
||||
tag_2
|
||||
jump // in
|
||||
tag_1:
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
tag_3
|
||||
tag_2
|
||||
jump // in
|
||||
tag_3:
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":740:742 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":736:738 */
|
||||
dup3
|
||||
/* "yul_stack_opt/input.sol":729:743 */
|
||||
sstore
|
||||
pop
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":3:573 */
|
||||
jump(tag_4)
|
||||
tag_2:
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
0x00
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
0x01
|
||||
dup1
|
||||
@ -192,96 +122,84 @@ tag_2:
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":423:430 */
|
||||
swap16
|
||||
pop
|
||||
dup2
|
||||
/* "yul_stack_opt/input.sol":129:141 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":433:440 */
|
||||
swap15
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":151:160 */
|
||||
0x02
|
||||
/* "yul_stack_opt/input.sol":144:164 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":443:450 */
|
||||
swap14
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":174:183 */
|
||||
0x03
|
||||
/* "yul_stack_opt/input.sol":167:187 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":453:460 */
|
||||
swap13
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":197:206 */
|
||||
0x04
|
||||
/* "yul_stack_opt/input.sol":190:210 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":463:470 */
|
||||
swap12
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":220:229 */
|
||||
0x05
|
||||
/* "yul_stack_opt/input.sol":213:233 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":473:480 */
|
||||
swap11
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":243:252 */
|
||||
0x06
|
||||
/* "yul_stack_opt/input.sol":236:256 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":483:490 */
|
||||
swap10
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":266:275 */
|
||||
0x07
|
||||
/* "yul_stack_opt/input.sol":259:279 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":493:500 */
|
||||
swap9
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":289:298 */
|
||||
0x08
|
||||
/* "yul_stack_opt/input.sol":282:302 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":503:510 */
|
||||
swap8
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":312:321 */
|
||||
0x09
|
||||
/* "yul_stack_opt/input.sol":305:325 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":513:520 */
|
||||
swap7
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":335:344 */
|
||||
0x0a
|
||||
/* "yul_stack_opt/input.sol":328:348 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":523:530 */
|
||||
swap6
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":358:368 */
|
||||
0x0b
|
||||
/* "yul_stack_opt/input.sol":351:372 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":533:540 */
|
||||
swap5
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":382:392 */
|
||||
0x0c
|
||||
/* "yul_stack_opt/input.sol":375:396 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":543:550 */
|
||||
swap4
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":406:416 */
|
||||
0x0d
|
||||
/* "yul_stack_opt/input.sol":399:420 */
|
||||
sstore
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":553:560 */
|
||||
swap3
|
||||
dup2
|
||||
/* "yul_stack_opt/input.sol":729:743 */
|
||||
sstore
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":98:99 */
|
||||
dup1
|
||||
/* "yul_stack_opt/input.sol":563:570 */
|
||||
swap2
|
||||
pop
|
||||
pop
|
||||
/* "yul_stack_opt/input.sol":85:573 */
|
||||
tag_5:
|
||||
swap1
|
||||
swap2
|
||||
swap3
|
||||
swap4
|
||||
swap5
|
||||
swap6
|
||||
swap7
|
||||
swap8
|
||||
swap9
|
||||
swap10
|
||||
swap11
|
||||
swap12
|
||||
swap13
|
||||
swap14
|
||||
swap15
|
||||
jump // out
|
||||
tag_4:
|
||||
|
@ -17,9 +17,9 @@ contract C {
|
||||
// optimize-yul: true
|
||||
// ----
|
||||
// creation:
|
||||
// codeDepositCost: 614600
|
||||
// executionCost: 651
|
||||
// totalCost: 615251
|
||||
// codeDepositCost: 597000
|
||||
// executionCost: 632
|
||||
// totalCost: 597632
|
||||
// external:
|
||||
// a(): 1029
|
||||
// b(uint256): 2084
|
||||
|
@ -9,22 +9,25 @@
|
||||
// {
|
||||
// {
|
||||
// let _1 := 7
|
||||
// let a_6 := 3
|
||||
// let x_7 := 0
|
||||
// x_7 := add(a_6, a_6)
|
||||
// let b_8 := x_7
|
||||
// let c_9 := _1
|
||||
// let y_10 := 0
|
||||
// y_10 := mul(mload(c_9), f(b_8))
|
||||
// let y_1 := y_10
|
||||
// let a_8 := 3
|
||||
// let x_9 := 0
|
||||
// x_9 := add(a_8, a_8)
|
||||
// let b_10 := x_9
|
||||
// let c_11 := _1
|
||||
// let y_12 := 0
|
||||
// let a_6_13 := b_10
|
||||
// let x_7_14 := 0
|
||||
// x_7_14 := add(a_6_13, a_6_13)
|
||||
// y_12 := mul(mload(c_11), x_7_14)
|
||||
// let y_1 := y_12
|
||||
// }
|
||||
// function f(a) -> x
|
||||
// { x := add(a, a) }
|
||||
// function g(b, c) -> y
|
||||
// {
|
||||
// let a_13 := b
|
||||
// let x_14 := 0
|
||||
// x_14 := add(a_13, a_13)
|
||||
// y := mul(mload(c), x_14)
|
||||
// let a_6 := b
|
||||
// let x_7 := 0
|
||||
// x_7 := add(a_6, a_6)
|
||||
// y := mul(mload(c), x_7)
|
||||
// }
|
||||
// }
|
||||
|
@ -26,20 +26,14 @@
|
||||
// step: fullInliner
|
||||
//
|
||||
// {
|
||||
// {
|
||||
// let x_8 := 100
|
||||
// mstore(0, x_8)
|
||||
// mstore(7, h())
|
||||
// g(10)
|
||||
// mstore(1, x_8)
|
||||
// }
|
||||
// { f(100) }
|
||||
// function f(x)
|
||||
// {
|
||||
// mstore(0, x)
|
||||
// let t_14 := 0
|
||||
// t_14 := 2
|
||||
// mstore(7, t_14)
|
||||
// let x_1_15 := 10
|
||||
// let t_8 := 0
|
||||
// t_8 := 2
|
||||
// mstore(7, t_8)
|
||||
// let x_1_9 := 10
|
||||
// f(1)
|
||||
// mstore(1, x)
|
||||
// }
|
||||
|
@ -473,22 +473,22 @@
|
||||
// let i := _1
|
||||
// for { } lt(i, length) { i := add(i, 1) }
|
||||
// {
|
||||
// abi_encode_t_array$_C_memory(mload(srcPtr), pos)
|
||||
// let _3 := mload(srcPtr)
|
||||
// let pos_1 := pos
|
||||
// let srcPtr_1 := _3
|
||||
// let i_1 := _1
|
||||
// for { } lt(i_1, 0x3) { i_1 := add(i_1, 1) }
|
||||
// {
|
||||
// mstore(pos_1, and(mload(srcPtr_1), sub(shl(160, 1), 1)))
|
||||
// srcPtr_1 := add(srcPtr_1, 0x20)
|
||||
// pos_1 := add(pos_1, 0x20)
|
||||
// }
|
||||
// srcPtr := add(srcPtr, 0x20)
|
||||
// pos := add(pos, 0x60)
|
||||
// }
|
||||
// let _3 := mload(64)
|
||||
// let _4 := mload(0x20)
|
||||
// if slt(sub(_3, _4), 128) { revert(_1, _1) }
|
||||
// let offset := calldataload(add(_4, 64))
|
||||
// let _5 := 0xffffffffffffffff
|
||||
// if gt(offset, _5) { revert(_1, _1) }
|
||||
// let value2 := abi_decode_t_array$_t_uint256_$dyn(add(_4, offset), _3)
|
||||
// let offset_1 := calldataload(add(_4, 0x60))
|
||||
// if gt(offset_1, _5) { revert(_1, _1) }
|
||||
// let value3 := abi_decode_t_array$_t_array$_t_uint256_memory_$dyn(add(_4, offset_1), _3)
|
||||
// sstore(calldataload(_4), calldataload(add(_4, 0x20)))
|
||||
// sstore(value2, value3)
|
||||
// let a, b, c, d := abi_decode_uint256t_uint256t_array$_t_uint256_$dynt_array$_t_array$_t_uint256_memory_$dyn(mload(0x20), mload(64))
|
||||
// sstore(a, b)
|
||||
// sstore(c, d)
|
||||
// sstore(_1, pos)
|
||||
// }
|
||||
// function abi_decode_t_array$_t_array$_t_uint256_memory_$dyn(offset, end) -> array
|
||||
@ -508,14 +508,13 @@
|
||||
// for { } lt(i, length) { i := add(i, 1) }
|
||||
// {
|
||||
// if iszero(slt(add(src, _1), end)) { revert(0, 0) }
|
||||
// let _4 := 0x2
|
||||
// let dst_1 := allocateMemory(array_allocation_size_t_array$_t_uint256_memory(_4))
|
||||
// let dst_1 := allocateMemory(_3)
|
||||
// let dst_2 := dst_1
|
||||
// let src_1 := src
|
||||
// let _5 := add(src, _3)
|
||||
// if gt(_5, end) { revert(0, 0) }
|
||||
// let _4 := add(src, _3)
|
||||
// if gt(_4, end) { revert(0, 0) }
|
||||
// let i_1 := 0
|
||||
// for { } lt(i_1, _4) { i_1 := add(i_1, 1) }
|
||||
// for { } lt(i_1, 0x2) { i_1 := add(i_1, 1) }
|
||||
// {
|
||||
// mstore(dst_1, calldataload(src_1))
|
||||
// dst_1 := add(dst_1, _2)
|
||||
@ -523,39 +522,38 @@
|
||||
// }
|
||||
// mstore(dst, dst_2)
|
||||
// dst := add(dst, _2)
|
||||
// src := _5
|
||||
// src := _4
|
||||
// }
|
||||
// }
|
||||
// function abi_decode_t_array$_t_uint256_$dyn(offset, end) -> array
|
||||
// function abi_decode_uint256t_uint256t_array$_t_uint256_$dynt_array$_t_array$_t_uint256_memory_$dyn(headStart, dataEnd) -> value0, value1, value2, value3
|
||||
// {
|
||||
// if iszero(slt(add(offset, 0x1f), end)) { revert(array, array) }
|
||||
// let length := calldataload(offset)
|
||||
// array := allocateMemory(array_allocation_size_t_array$_t_address_$dyn_memory(length))
|
||||
// let dst := array
|
||||
// mstore(array, length)
|
||||
// let _1 := 0x20
|
||||
// dst := add(array, _1)
|
||||
// let src := add(offset, _1)
|
||||
// if gt(add(add(offset, mul(length, _1)), _1), end) { revert(0, 0) }
|
||||
// let i := 0
|
||||
// if slt(sub(dataEnd, headStart), 128) { revert(value2, value2) }
|
||||
// value0 := calldataload(headStart)
|
||||
// let _1 := 32
|
||||
// value1 := calldataload(add(headStart, _1))
|
||||
// let offset := calldataload(add(headStart, 64))
|
||||
// let _2 := 0xffffffffffffffff
|
||||
// if gt(offset, _2) { revert(value2, value2) }
|
||||
// let _3 := add(headStart, offset)
|
||||
// if iszero(slt(add(_3, 0x1f), dataEnd)) { revert(value2, value2) }
|
||||
// let length := calldataload(_3)
|
||||
// let dst := allocateMemory(array_allocation_size_t_array$_t_address_$dyn_memory(length))
|
||||
// let dst_1 := dst
|
||||
// mstore(dst, length)
|
||||
// dst := add(dst, _1)
|
||||
// let src := add(_3, _1)
|
||||
// if gt(add(add(_3, mul(length, _1)), _1), dataEnd) { revert(value2, value2) }
|
||||
// let i := value2
|
||||
// for { } lt(i, length) { i := add(i, 1) }
|
||||
// {
|
||||
// mstore(dst, calldataload(src))
|
||||
// dst := add(dst, _1)
|
||||
// src := add(src, _1)
|
||||
// }
|
||||
// }
|
||||
// function abi_encode_t_array$_C_memory(value, pos)
|
||||
// {
|
||||
// let srcPtr := value
|
||||
// let i := 0
|
||||
// for { } lt(i, 0x3) { i := add(i, 1) }
|
||||
// {
|
||||
// mstore(pos, and(mload(srcPtr), sub(shl(160, 1), 1)))
|
||||
// let _1 := 0x20
|
||||
// srcPtr := add(srcPtr, _1)
|
||||
// pos := add(pos, _1)
|
||||
// }
|
||||
// value2 := dst_1
|
||||
// let offset_1 := calldataload(add(headStart, 96))
|
||||
// if gt(offset_1, _2) { revert(value3, value3) }
|
||||
// value3 := abi_decode_t_array$_t_array$_t_uint256_memory_$dyn(add(headStart, offset_1), dataEnd)
|
||||
// }
|
||||
// function allocateMemory(size) -> memPtr
|
||||
// {
|
||||
@ -569,9 +567,4 @@
|
||||
// if gt(length, 0xffffffffffffffff) { revert(size, size) }
|
||||
// size := add(mul(length, 0x20), 0x20)
|
||||
// }
|
||||
// function array_allocation_size_t_array$_t_uint256_memory(length) -> size
|
||||
// {
|
||||
// if gt(length, 0xffffffffffffffff) { revert(size, size) }
|
||||
// size := mul(length, 0x20)
|
||||
// }
|
||||
// }
|
||||
|
@ -10,6 +10,8 @@
|
||||
out1 := sload(out1)
|
||||
out2 := add(out1, 1)
|
||||
extcodecopy(out1, out2, 1, b)
|
||||
// to prevent foo from getting inlined
|
||||
if iszero(out1) { leave }
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@ -27,5 +29,6 @@
|
||||
// out1 := sload(mload(32))
|
||||
// out2 := add(out1, 1)
|
||||
// extcodecopy(out1, out2, 1, b)
|
||||
// if iszero(out1) { leave }
|
||||
// }
|
||||
// }
|
||||
|
@ -7,6 +7,8 @@
|
||||
{
|
||||
a := calldataload(0)
|
||||
mstore(a, x)
|
||||
// to prevent f from getting inlined
|
||||
if iszero(a) { leave }
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -27,7 +29,11 @@
|
||||
// let b := 10
|
||||
// let _1 := 0
|
||||
// let a := calldataload(_1)
|
||||
// let _2 := iszero(a)
|
||||
// for { } iszero(b) { b := add(b, not(0)) }
|
||||
// { mstore(a, _1) }
|
||||
// {
|
||||
// mstore(a, _1)
|
||||
// if _2 { leave }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
@ -12,6 +12,8 @@
|
||||
out1 := sload(out1)
|
||||
out2 := add(out1, 1)
|
||||
extcodecopy(out1, out1, 1, b)
|
||||
// to prevent foo from getting inlined
|
||||
if iszero(out1) { leave }
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@ -30,5 +32,6 @@
|
||||
// out1 := sload(mload(32))
|
||||
// out2 := add(out1, 1)
|
||||
// extcodecopy(out1, out1, 1, b)
|
||||
// if iszero(out1) { leave }
|
||||
// }
|
||||
// }
|
||||
|
@ -6,11 +6,8 @@
|
||||
// The usage of a is redundant
|
||||
a := calldataload(0)
|
||||
mstore(a, x)
|
||||
// to prevent getting fully inlined
|
||||
sstore(1, 1)
|
||||
sstore(2, 2)
|
||||
sstore(3, 3)
|
||||
sstore(3, 3)
|
||||
// to prevent f from getting inlined
|
||||
if iszero(a) { leave }
|
||||
}
|
||||
}
|
||||
// ----
|
||||
@ -27,10 +24,8 @@
|
||||
// }
|
||||
// function f()
|
||||
// {
|
||||
// mstore(calldataload(0), 0)
|
||||
// sstore(1, 1)
|
||||
// sstore(2, 2)
|
||||
// sstore(3, 3)
|
||||
// sstore(3, 3)
|
||||
// let a := calldataload(0)
|
||||
// mstore(a, 0)
|
||||
// if iszero(a) { leave }
|
||||
// }
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user