Provide full optimiser settings to ContractCompiler.

This commit is contained in:
chriseth 2019-02-21 18:13:52 +01:00
parent 4d10f4b4cf
commit 1ff562d28a
3 changed files with 18 additions and 19 deletions

View File

@ -35,18 +35,17 @@ void Compiler::compileContract(
bytes const& _metadata bytes const& _metadata
) )
{ {
ContractCompiler runtimeCompiler( ContractCompiler runtimeCompiler(nullptr, m_runtimeContext, m_optimiserSettings);
nullptr,
m_runtimeContext,
m_optimiserSettings.runOrderLiterals,
m_optimiserSettings.expectedExecutionsPerDeployment
);
runtimeCompiler.compileContract(_contract, _otherCompilers); runtimeCompiler.compileContract(_contract, _otherCompilers);
m_runtimeContext.appendAuxiliaryData(_metadata); m_runtimeContext.appendAuxiliaryData(_metadata);
// This might modify m_runtimeContext because it can access runtime functions at // This might modify m_runtimeContext because it can access runtime functions at
// creation time. // creation time.
ContractCompiler creationCompiler(&runtimeCompiler, m_context, m_optimiserSettings.runOrderLiterals, 1); OptimiserSettings creationSettings{m_optimiserSettings};
// The creation code will be executed at most once, so we modify the optimizer
// settings accordingly.
creationSettings.expectedExecutionsPerDeployment = 1;
ContractCompiler creationCompiler(&runtimeCompiler, m_context, creationSettings);
m_runtimeSub = creationCompiler.compileConstructor(_contract, _otherCompilers); m_runtimeSub = creationCompiler.compileConstructor(_contract, _otherCompilers);
m_context.optimise(m_optimiserSettings); m_context.optimise(m_optimiserSettings);

View File

@ -391,7 +391,7 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
sortedIDs.emplace_back(it.first); sortedIDs.emplace_back(it.first);
} }
std::sort(sortedIDs.begin(), sortedIDs.end()); std::sort(sortedIDs.begin(), sortedIDs.end());
appendInternalSelector(callDataUnpackerEntryPoints, sortedIDs, notFound, m_optimiseRuns); appendInternalSelector(callDataUnpackerEntryPoints, sortedIDs, notFound, m_optimiserSettings.expectedExecutionsPerDeployment);
} }
m_context << notFound; m_context << notFound;
@ -484,7 +484,7 @@ void ContractCompiler::initializeStateVariables(ContractDefinition const& _contr
solAssert(!_contract.isLibrary(), "Tried to initialize state variables of library."); solAssert(!_contract.isLibrary(), "Tried to initialize state variables of library.");
for (VariableDeclaration const* variable: _contract.stateVariables()) for (VariableDeclaration const* variable: _contract.stateVariables())
if (variable->value() && !variable->isConstant()) if (variable->value() && !variable->isConstant())
ExpressionCompiler(m_context, m_optimiseOrderLiterals).appendStateVariableInitialization(*variable); ExpressionCompiler(m_context, m_optimiserSettings.runOrderLiterals).appendStateVariableInitialization(*variable);
} }
bool ContractCompiler::visit(VariableDeclaration const& _variableDeclaration) bool ContractCompiler::visit(VariableDeclaration const& _variableDeclaration)
@ -497,9 +497,9 @@ bool ContractCompiler::visit(VariableDeclaration const& _variableDeclaration)
m_continueTags.clear(); m_continueTags.clear();
if (_variableDeclaration.isConstant()) if (_variableDeclaration.isConstant())
ExpressionCompiler(m_context, m_optimiseOrderLiterals).appendConstStateVariableAccessor(_variableDeclaration); ExpressionCompiler(m_context, m_optimiserSettings.runOrderLiterals).appendConstStateVariableAccessor(_variableDeclaration);
else else
ExpressionCompiler(m_context, m_optimiseOrderLiterals).appendStateVariableAccessor(_variableDeclaration); ExpressionCompiler(m_context, m_optimiserSettings.runOrderLiterals).appendStateVariableAccessor(_variableDeclaration);
return false; return false;
} }
@ -1053,7 +1053,7 @@ void ContractCompiler::appendStackVariableInitialisation(VariableDeclaration con
void ContractCompiler::compileExpression(Expression const& _expression, TypePointer const& _targetType) void ContractCompiler::compileExpression(Expression const& _expression, TypePointer const& _targetType)
{ {
ExpressionCompiler expressionCompiler(m_context, m_optimiseOrderLiterals); ExpressionCompiler expressionCompiler(m_context, m_optimiserSettings.runOrderLiterals);
expressionCompiler.compile(_expression); expressionCompiler.compile(_expression);
if (_targetType) if (_targetType)
CompilerUtils(m_context).convertType(*_expression.annotation().type, *_targetType); CompilerUtils(m_context).convertType(*_expression.annotation().type, *_targetType);

View File

@ -28,8 +28,10 @@
#include <functional> #include <functional>
#include <ostream> #include <ostream>
namespace dev { namespace dev
namespace solidity { {
namespace solidity
{
/** /**
* Code generator at the contract level. Can be used to generate code for exactly one contract * Code generator at the contract level. Can be used to generate code for exactly one contract
@ -38,9 +40,8 @@ namespace solidity {
class ContractCompiler: private ASTConstVisitor class ContractCompiler: private ASTConstVisitor
{ {
public: public:
explicit ContractCompiler(ContractCompiler* _runtimeCompiler, CompilerContext& _context, bool _optimiseOrderLiterals, size_t _optimiseRuns): explicit ContractCompiler(ContractCompiler* _runtimeCompiler, CompilerContext& _context, OptimiserSettings _optimiserSettings):
m_optimiseOrderLiterals(_optimiseOrderLiterals), m_optimiserSettings(std::move(_optimiserSettings)),
m_optimiseRuns(_optimiseRuns),
m_runtimeCompiler(_runtimeCompiler), m_runtimeCompiler(_runtimeCompiler),
m_context(_context) m_context(_context)
{ {
@ -130,8 +131,7 @@ private:
/// Sets the stack height for the visited loop. /// Sets the stack height for the visited loop.
void storeStackHeight(ASTNode const* _node); void storeStackHeight(ASTNode const* _node);
bool const m_optimiseOrderLiterals; OptimiserSettings const m_optimiserSettings;
size_t const m_optimiseRuns = 200;
/// Pointer to the runtime compiler in case this is a creation compiler. /// Pointer to the runtime compiler in case this is a creation compiler.
ContractCompiler* m_runtimeCompiler = nullptr; ContractCompiler* m_runtimeCompiler = nullptr;
CompilerContext& m_context; CompilerContext& m_context;