mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
New full inliner.
This commit is contained in:
@@ -130,7 +130,11 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
||||
disambiguate();
|
||||
(FunctionHoister{})(*m_ast);
|
||||
(FunctionGrouper{})(*m_ast);
|
||||
NameDispenser nameDispenser;
|
||||
nameDispenser.m_usedNames = NameCollector(*m_ast).names();
|
||||
ExpressionSplitter{nameDispenser}(*m_ast);
|
||||
FullInliner(*m_ast).run();
|
||||
ExpressionJoiner::run(*m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "mainFunction")
|
||||
{
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
function f(a) -> b, c { let x := mload(a) b := sload(x) c := 3 }
|
||||
let a1 := calldataload(0)
|
||||
let b3, c3 := f(a1)
|
||||
let b4, c4 := f(c3)
|
||||
}
|
||||
// ----
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// let f_a := calldataload(0)
|
||||
// let f_b
|
||||
// let f_c
|
||||
// f_b := sload(mload(f_a))
|
||||
// f_c := 3
|
||||
// let b3 := f_b
|
||||
// let f_a_1 := f_c
|
||||
// let f_b_1
|
||||
// let f_c_1
|
||||
// f_b_1 := sload(mload(f_a_1))
|
||||
// f_c_1 := 3
|
||||
// let b4 := f_b_1
|
||||
// let c4 := f_c_1
|
||||
// }
|
||||
// function f(a) -> b, c
|
||||
// {
|
||||
// b := sload(mload(a))
|
||||
// c := 3
|
||||
// }
|
||||
// }
|
||||
@@ -12,14 +12,12 @@
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// let _1 := mload(0)
|
||||
// let _2 := mload(0)
|
||||
// let f_a := mload(1)
|
||||
// let f_r
|
||||
// {
|
||||
// f_a := mload(f_a)
|
||||
// f_r := add(f_a, calldatasize())
|
||||
// }
|
||||
// if gt(f_r, _1)
|
||||
// f_a := mload(f_a)
|
||||
// f_r := add(f_a, calldatasize())
|
||||
// if gt(f_r, _2)
|
||||
// {
|
||||
// sstore(0, 2)
|
||||
// }
|
||||
|
||||
@@ -9,16 +9,17 @@
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// let _1 := mload(5)
|
||||
// let f_c := mload(4)
|
||||
// let f_b := mload(3)
|
||||
// let _2 := mload(5)
|
||||
// let _4 := mload(4)
|
||||
// let _6 := mload(3)
|
||||
// let f_a := mload(2)
|
||||
// let f_b := _6
|
||||
// let f_c := _4
|
||||
// let f_x
|
||||
// {
|
||||
// f_x := add(f_a, f_b)
|
||||
// f_x := mul(f_x, f_c)
|
||||
// }
|
||||
// let y := add(mload(1), add(f_x, _1))
|
||||
// f_x := add(f_a, f_b)
|
||||
// f_x := mul(f_x, f_c)
|
||||
// let _10 := add(f_x, _2)
|
||||
// let y := add(mload(1), _10)
|
||||
// }
|
||||
// function f(a, b, c) -> x
|
||||
// {
|
||||
|
||||
@@ -7,21 +7,17 @@
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// let g_c := 7
|
||||
// let f_a_1 := 3
|
||||
// let f_x_1
|
||||
// {
|
||||
// f_x_1 := add(f_a_1, f_a_1)
|
||||
// }
|
||||
// let _1 := 7
|
||||
// let f_a := 3
|
||||
// let f_x
|
||||
// f_x := add(f_a, f_a)
|
||||
// let g_b := f_x
|
||||
// let g_c := _1
|
||||
// let g_y
|
||||
// {
|
||||
// let g_f_a := f_x_1
|
||||
// let g_f_x
|
||||
// {
|
||||
// g_f_x := add(g_f_a, g_f_a)
|
||||
// }
|
||||
// g_y := mul(mload(g_c), g_f_x)
|
||||
// }
|
||||
// let g_f_a_1 := g_b
|
||||
// let g_f_x_1
|
||||
// g_f_x_1 := add(g_f_a_1, g_f_a_1)
|
||||
// g_y := mul(mload(g_c), g_f_x_1)
|
||||
// let y_1 := g_y
|
||||
// }
|
||||
// function f(a) -> x
|
||||
@@ -30,11 +26,9 @@
|
||||
// }
|
||||
// function g(b, c) -> y
|
||||
// {
|
||||
// let f_a := b
|
||||
// let f_x
|
||||
// {
|
||||
// f_x := add(f_a, f_a)
|
||||
// }
|
||||
// y := mul(mload(c), f_x)
|
||||
// let f_a_1 := b
|
||||
// let f_x_1
|
||||
// f_x_1 := add(f_a_1, f_a_1)
|
||||
// y := mul(mload(c), f_x_1)
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
// The full inliner currently does not work with
|
||||
// functions returning multiple values.
|
||||
{
|
||||
function f(a) -> x, y {
|
||||
x := mul(a, a)
|
||||
y := add(a, x)
|
||||
}
|
||||
let a, b := f(mload(0))
|
||||
let r, s := f(mload(0))
|
||||
mstore(r, s)
|
||||
}
|
||||
// ----
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// let a_1, b := f(mload(0))
|
||||
// let f_a := mload(0)
|
||||
// let f_x
|
||||
// let f_y
|
||||
// f_x := mul(f_a, f_a)
|
||||
// f_y := add(f_a, f_x)
|
||||
// let r := f_x
|
||||
// mstore(r, f_y)
|
||||
// }
|
||||
// function f(a) -> x, y
|
||||
// {
|
||||
|
||||
@@ -9,11 +9,7 @@
|
||||
// {
|
||||
// {
|
||||
// let f_a := mload(0)
|
||||
// {
|
||||
// sstore(f_a, f_a)
|
||||
// }
|
||||
// {
|
||||
// }
|
||||
// sstore(f_a, f_a)
|
||||
// }
|
||||
// function f(a)
|
||||
// {
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
for { let x := f(0) } f(x) { x := f(x) }
|
||||
{
|
||||
let t := f(x)
|
||||
}
|
||||
function f(a) -> r {
|
||||
sstore(a, 0)
|
||||
r := a
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// for {
|
||||
// let f_a := 0
|
||||
// let f_r
|
||||
// sstore(f_a, 0)
|
||||
// f_r := f_a
|
||||
// let x := f_r
|
||||
// }
|
||||
// f(x)
|
||||
// {
|
||||
// let f_a_1 := x
|
||||
// let f_r_1
|
||||
// sstore(f_a_1, 0)
|
||||
// f_r_1 := f_a_1
|
||||
// x := f_r_1
|
||||
// }
|
||||
// {
|
||||
// let f_a_2 := x
|
||||
// let f_r_2
|
||||
// sstore(f_a_2, 0)
|
||||
// f_r_2 := f_a_2
|
||||
// let t := f_r_2
|
||||
// }
|
||||
// }
|
||||
// function f(a) -> r
|
||||
// {
|
||||
// sstore(a, 0)
|
||||
// r := a
|
||||
// }
|
||||
// }
|
||||
@@ -1,4 +1,6 @@
|
||||
// This tests that `pop(r)` is removed.
|
||||
// An earlier version of the inliner produced
|
||||
// pop(...) statements and explicitly removed them.
|
||||
// This used to test that they are removed.
|
||||
{
|
||||
function f(a) -> x {
|
||||
let r := mul(a, a)
|
||||
@@ -13,12 +15,9 @@
|
||||
// let _1 := 2
|
||||
// let f_a := 7
|
||||
// let f_x
|
||||
// {
|
||||
// let f_r := mul(f_a, f_a)
|
||||
// f_x := add(f_r, f_r)
|
||||
// }
|
||||
// {
|
||||
// }
|
||||
// let f_r := mul(f_a, f_a)
|
||||
// f_x := add(f_r, f_r)
|
||||
// pop(add(f_x, _1))
|
||||
// }
|
||||
// function f(a) -> x
|
||||
// {
|
||||
|
||||
@@ -9,14 +9,12 @@
|
||||
// fullInliner
|
||||
// {
|
||||
// {
|
||||
// let _1 := mload(7)
|
||||
// let _2 := mload(7)
|
||||
// let f_a := sload(mload(2))
|
||||
// let f_x
|
||||
// {
|
||||
// let f_r := mul(f_a, f_a)
|
||||
// f_x := add(f_r, f_r)
|
||||
// }
|
||||
// let y := add(f_x, _1)
|
||||
// let f_r := mul(f_a, f_a)
|
||||
// f_x := add(f_r, f_r)
|
||||
// let y := add(f_x, _2)
|
||||
// }
|
||||
// function f(a) -> x
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user