Provide commandline option to activate yul optimizer.

This commit is contained in:
chriseth 2019-02-21 18:35:41 +01:00
parent 83d1382e78
commit 5ddbc434d6
9 changed files with 78 additions and 4 deletions

View File

@ -132,6 +132,7 @@ static string const g_strNatspecUser = "userdoc";
static string const g_strOpcodes = "opcodes";
static string const g_strOptimize = "optimize";
static string const g_strOptimizeRuns = "optimize-runs";
static string const g_strOptimizeYul = "optimize-yul";
static string const g_strOutputDir = "output-dir";
static string const g_strOverwrite = "overwrite";
static string const g_strSignatureHashes = "hashes";
@ -615,6 +616,7 @@ Allowed options)",
"Set for how many contract runs to optimize."
"Lower values will optimize more for initial deployment cost, higher values will optimize more for high-frequency usage."
)
(g_strOptimizeYul.c_str(), "Enable Yul optimizer in Solidity, mostly for ABIEncoderV2.")
(g_argPrettyJson.c_str(), "Output JSON in pretty format. Currently it only works with the combined JSON output.")
(
g_argLibraries.c_str(),
@ -847,7 +849,7 @@ bool CommandLineInterface::processInput()
using Machine = yul::AssemblyStack::Machine;
Input inputLanguage = m_args.count(g_argYul) ? Input::Yul : (m_args.count(g_argStrictAssembly) ? Input::StrictAssembly : Input::Assembly);
Machine targetMachine = Machine::EVM;
bool optimize = m_args.count(g_argOptimize);
bool optimize = m_args.count(g_argOptimize) || m_args.count(g_strOptimizeYul);
if (m_args.count(g_argMachine))
{
string machine = m_args[g_argMachine].as<string>();
@ -901,9 +903,11 @@ bool CommandLineInterface::processInput()
m_compiler->setLibraries(m_libraries);
m_compiler->setEVMVersion(m_evmVersion);
// TODO: Perhaps we should not compile unless requested
bool optimize = m_args.count(g_argOptimize) > 0;
unsigned runs = m_args[g_argOptimizeRuns].as<unsigned>();
m_compiler->setOptimiserSettings(optimize, runs);
OptimiserSettings settings = m_args.count(g_argOptimize) ? OptimiserSettings::enabled() : OptimiserSettings::minimal();
settings.expectedExecutionsPerDeployment = m_args[g_argOptimizeRuns].as<unsigned>();
settings.runYulOptimiser = m_args.count(g_strOptimizeYul);
m_compiler->setOptimiserSettings(settings);
bool successful = m_compiler->compile();

View File

@ -0,0 +1 @@
--gas

View File

@ -0,0 +1,3 @@
gas_test_abiv2/input.sol:2:1: Warning: Experimental features are turned on. Do not use experimental features on live deployments.
pragma experimental ABIEncoderV2;
^-------------------------------^

View File

@ -0,0 +1,15 @@
pragma solidity >=0.0;
pragma experimental ABIEncoderV2;
contract C {
uint public a;
uint[] public b;
function f1(uint) public pure returns (uint) { }
function f2(uint[] memory, string[] memory, uint16, address) public returns (uint[] memory, uint16[] memory) {}
function f3(uint16[] memory, string[] memory, uint16, address) public returns (uint[] memory, uint16[] memory) {}
function f4(uint32[] memory, string[12] memory, bytes[2][] memory, address) public returns (uint[] memory, uint16[] memory) {}
function f5(address[] memory, string[] memory, bytes memory, address) public returns (uint[] memory, uint16[] memory) {}
function f6(uint[30] memory, string[] memory, uint16, address) public returns (uint16[200] memory, uint16[] memory) {}
function f7(uint[31] memory, string[20] memory, C, address) public returns (bytes[] memory, uint16[] memory) {}
function f8(uint[32] memory, string[] memory, uint32, address) public returns (uint[] memory, uint16[] memory) {}
}

View File

@ -0,0 +1,16 @@
======= gas_test_abiv2/input.sol:C =======
Gas estimation:
construction:
1154 + 1109000 = 1110154
external:
a(): 535
b(uint256): 1129
f1(uint256): 591
f2(uint256[],string[],uint16,address): infinite
f3(uint16[],string[],uint16,address): infinite
f4(uint32[],string[12],bytes[2][],address): infinite
f5(address[],string[],bytes,address): infinite
f6(uint256[30],string[],uint16,address): infinite
f7(uint256[31],string[20],address,address): infinite
f8(uint256[32],string[],uint32,address): infinite

View File

@ -0,0 +1 @@
--gas --optimize --optimize-yul

View File

@ -0,0 +1,3 @@
gas_test_abiv2_optimize_yul/input.sol:2:1: Warning: Experimental features are turned on. Do not use experimental features on live deployments.
pragma experimental ABIEncoderV2;
^-------------------------------^

View File

@ -0,0 +1,15 @@
pragma solidity >=0.0;
pragma experimental ABIEncoderV2;
contract C {
uint public a;
uint[] public b;
function f1(uint) public pure returns (uint) { }
function f2(uint[] memory, string[] memory, uint16, address) public returns (uint[] memory, uint16[] memory) {}
function f3(uint16[] memory, string[] memory, uint16, address) public returns (uint[] memory, uint16[] memory) {}
function f4(uint32[] memory, string[12] memory, bytes[2][] memory, address) public returns (uint[] memory, uint16[] memory) {}
function f5(address[] memory, string[] memory, bytes memory, address) public returns (uint[] memory, uint16[] memory) {}
function f6(uint[30] memory, string[] memory, uint16, address) public returns (uint16[200] memory, uint16[] memory) {}
function f7(uint[31] memory, string[20] memory, C, address) public returns (bytes[] memory, uint16[] memory) {}
function f8(uint[32] memory, string[] memory, uint32, address) public returns (uint[] memory, uint16[] memory) {}
}

View File

@ -0,0 +1,16 @@
======= gas_test_abiv2_optimize_yul/input.sol:C =======
Gas estimation:
construction:
676 + 641600 = 642276
external:
a(): 434
b(uint256): 892
f1(uint256): 356
f2(uint256[],string[],uint16,address): infinite
f3(uint16[],string[],uint16,address): infinite
f4(uint32[],string[12],bytes[2][],address): infinite
f5(address[],string[],bytes,address): infinite
f6(uint256[30],string[],uint16,address): infinite
f7(uint256[31],string[20],address,address): infinite
f8(uint256[32],string[],uint32,address): infinite