mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add structural simplifier as optimization step for Yul.
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
#include <libyul/optimiser/ExpressionJoiner.h>
|
||||
#include <libyul/optimiser/SSATransform.h>
|
||||
#include <libyul/optimiser/RedundantAssignEliminator.h>
|
||||
#include <libyul/optimiser/StructuralSimplifier.h>
|
||||
#include <libyul/optimiser/Suite.h>
|
||||
#include <libyul/AsmPrinter.h>
|
||||
#include <libyul/AsmParser.h>
|
||||
@@ -213,6 +214,11 @@ bool YulOptimizerTest::run(ostream& _stream, string const& _linePrefix, bool con
|
||||
SSATransform::run(*m_ast, nameDispenser);
|
||||
RedundantAssignEliminator::run(*m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "structuralSimplifier")
|
||||
{
|
||||
disambiguate();
|
||||
StructuralSimplifier{}(*m_ast);
|
||||
}
|
||||
else if (m_optimizerStep == "fullSuite")
|
||||
OptimiserSuite::run(*m_ast, *m_analysisInfo);
|
||||
else
|
||||
|
||||
@@ -599,10 +599,6 @@
|
||||
// revert(_2, _2)
|
||||
// }
|
||||
// let abi_decode_abi_decode_length_14_1069 := 0x2
|
||||
// if _2
|
||||
// {
|
||||
// revert(_2, _2)
|
||||
// }
|
||||
// let allocateMe_memPtr_315 := mload(abi_encode_pos_590)
|
||||
// let allocateMe_newFreePtr := add(allocateMe_memPtr_315, abi_encode_pos_590)
|
||||
// if or(gt(allocateMe_newFreePtr, _945), lt(allocateMe_newFreePtr, allocateMe_memPtr_315))
|
||||
|
||||
@@ -9,16 +9,23 @@
|
||||
pop(allocate(0x20))
|
||||
let x := allocate(0x40)
|
||||
mstore(array_index_access(x, 3), 2)
|
||||
if 0 {
|
||||
mstore(0x40, 0x20)
|
||||
}
|
||||
if sub(2,1) {
|
||||
for { switch mul(1,2) case 2 { mstore(0x40, 0x20) } } sub(1,1) {} { mstore(0x80, 0x40) }
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// fullSuite
|
||||
// {
|
||||
// {
|
||||
// let _18 := 0x20
|
||||
// let allocate__7 := 0x40
|
||||
// mstore(allocate__7, add(mload(allocate__7), _18))
|
||||
// let allocate_p_12_31 := mload(allocate__7)
|
||||
// mstore(allocate__7, add(allocate_p_12_31, allocate__7))
|
||||
// mstore(add(allocate_p_12_31, 96), 2)
|
||||
// let _1 := 0x20
|
||||
// let allocate__19 := 0x40
|
||||
// mstore(allocate__19, add(mload(allocate__19), _1))
|
||||
// let allocate_p_24_41 := mload(allocate__19)
|
||||
// mstore(allocate__19, add(allocate_p_24_41, allocate__19))
|
||||
// mstore(add(allocate_p_24_41, 96), 2)
|
||||
// mstore(allocate__19, _1)
|
||||
// }
|
||||
// }
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{ let a := mload(0) if a {} }
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// let a := mload(0)
|
||||
// pop(a)
|
||||
// }
|
||||
@@ -0,0 +1,6 @@
|
||||
{ if mload(0) {} }
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// pop(mload(0))
|
||||
// }
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
for { let a := 42 } 0 { a := a } {
|
||||
let b := a
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// let a := 42
|
||||
// }
|
||||
@@ -0,0 +1,5 @@
|
||||
{ if 0 { mstore(0, 0) } }
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// }
|
||||
@@ -0,0 +1,6 @@
|
||||
{ if 1 { mstore(0, 0) } }
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// mstore(0, 0)
|
||||
// }
|
||||
@@ -0,0 +1,6 @@
|
||||
{ if 1 { if 1 { for { mstore(0, 0) } 0 {} { mstore(2, 3) } if 0 { mstore(1, 2) } } } }
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// mstore(0, 0)
|
||||
// }
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
switch mload(0) default { mstore(1, 2) }
|
||||
}
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// pop(mload(0))
|
||||
// {
|
||||
// mstore(1, 2)
|
||||
// }
|
||||
// }
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
switch 1 case 2 { mstore(0, 0) }
|
||||
}
|
||||
// ----
|
||||
// structuralSimplifier
|
||||
// {
|
||||
// if eq(2, 1)
|
||||
// {
|
||||
// mstore(0, 0)
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user