mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Extract duplicated code for initializing OptimiserSettings from CommandLineOptions into a common function
This commit is contained in:
parent
2f663c5f36
commit
6b46d4fdbe
@ -551,13 +551,7 @@ bool CommandLineInterface::processInput()
|
|||||||
}
|
}
|
||||||
case InputMode::Assembler:
|
case InputMode::Assembler:
|
||||||
{
|
{
|
||||||
return assemble(
|
return assemble(m_options.assembly.inputLanguage, m_options.assembly.targetMachine);
|
||||||
m_options.assembly.inputLanguage,
|
|
||||||
m_options.assembly.targetMachine,
|
|
||||||
m_options.optimizer.enabled,
|
|
||||||
m_options.optimizer.expectedExecutionsPerDeployment,
|
|
||||||
m_options.optimizer.yulSteps
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
case InputMode::Linker:
|
case InputMode::Linker:
|
||||||
return link();
|
return link();
|
||||||
@ -595,16 +589,7 @@ bool CommandLineInterface::compile()
|
|||||||
m_compiler->enableIRGeneration(m_options.compiler.outputs.ir || m_options.compiler.outputs.irOptimized);
|
m_compiler->enableIRGeneration(m_options.compiler.outputs.ir || m_options.compiler.outputs.irOptimized);
|
||||||
m_compiler->enableEwasmGeneration(m_options.compiler.outputs.ewasm);
|
m_compiler->enableEwasmGeneration(m_options.compiler.outputs.ewasm);
|
||||||
|
|
||||||
OptimiserSettings settings = m_options.optimizer.enabled ? OptimiserSettings::standard() : OptimiserSettings::minimal();
|
m_compiler->setOptimiserSettings(m_options.optimiserSettings());
|
||||||
if (m_options.optimizer.expectedExecutionsPerDeployment.has_value())
|
|
||||||
settings.expectedExecutionsPerDeployment = m_options.optimizer.expectedExecutionsPerDeployment.value();
|
|
||||||
if (m_options.optimizer.noOptimizeYul)
|
|
||||||
settings.runYulOptimiser = false;
|
|
||||||
|
|
||||||
if (m_options.optimizer.yulSteps.has_value())
|
|
||||||
settings.yulOptimiserSteps = m_options.optimizer.yulSteps.value();
|
|
||||||
settings.optimizeStackAllocation = settings.runYulOptimiser;
|
|
||||||
m_compiler->setOptimiserSettings(settings);
|
|
||||||
|
|
||||||
if (m_options.input.mode == InputMode::CompilerWithASTImport)
|
if (m_options.input.mode == InputMode::CompilerWithASTImport)
|
||||||
{
|
{
|
||||||
@ -939,27 +924,21 @@ string CommandLineInterface::objectWithLinkRefsHex(evmasm::LinkerObject const& _
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CommandLineInterface::assemble(
|
bool CommandLineInterface::assemble(yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine)
|
||||||
yul::AssemblyStack::Language _language,
|
|
||||||
yul::AssemblyStack::Machine _targetMachine,
|
|
||||||
bool _optimize,
|
|
||||||
optional<unsigned int> _expectedExecutionsPerDeployment,
|
|
||||||
optional<string> _yulOptimiserSteps
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
solAssert(_optimize || !_yulOptimiserSteps.has_value(), "");
|
|
||||||
|
|
||||||
bool successful = true;
|
bool successful = true;
|
||||||
map<string, yul::AssemblyStack> assemblyStacks;
|
map<string, yul::AssemblyStack> assemblyStacks;
|
||||||
for (auto const& src: m_fileReader.sourceCodes())
|
for (auto const& src: m_fileReader.sourceCodes())
|
||||||
{
|
{
|
||||||
OptimiserSettings settings = _optimize ? OptimiserSettings::full() : OptimiserSettings::minimal();
|
// --no-optimize-yul option is not accepted in assembly mode.
|
||||||
if (_expectedExecutionsPerDeployment.has_value())
|
solAssert(!m_options.optimizer.noOptimizeYul, "");
|
||||||
settings.expectedExecutionsPerDeployment = _expectedExecutionsPerDeployment.value();
|
|
||||||
if (_yulOptimiserSteps.has_value())
|
auto& stack = assemblyStacks[src.first] = yul::AssemblyStack(
|
||||||
settings.yulOptimiserSteps = _yulOptimiserSteps.value();
|
m_options.output.evmVersion,
|
||||||
|
_language,
|
||||||
|
m_options.optimiserSettings()
|
||||||
|
);
|
||||||
|
|
||||||
auto& stack = assemblyStacks[src.first] = yul::AssemblyStack(m_options.output.evmVersion, _language, settings);
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!stack.parseAndAnalyze(src.first, src.second))
|
if (!stack.parseAndAnalyze(src.first, src.second))
|
||||||
|
@ -74,13 +74,7 @@ private:
|
|||||||
/// @returns the full object with library placeholder hints in hex.
|
/// @returns the full object with library placeholder hints in hex.
|
||||||
static std::string objectWithLinkRefsHex(evmasm::LinkerObject const& _obj);
|
static std::string objectWithLinkRefsHex(evmasm::LinkerObject const& _obj);
|
||||||
|
|
||||||
bool assemble(
|
bool assemble(yul::AssemblyStack::Language _language, yul::AssemblyStack::Machine _targetMachine);
|
||||||
yul::AssemblyStack::Language _language,
|
|
||||||
yul::AssemblyStack::Machine _targetMachine,
|
|
||||||
bool _optimize,
|
|
||||||
std::optional<unsigned int> _expectedExecutionsPerDeployment = std::nullopt,
|
|
||||||
std::optional<std::string> _yulOptimiserSteps = std::nullopt
|
|
||||||
);
|
|
||||||
|
|
||||||
void outputCompilationResults();
|
void outputCompilationResults();
|
||||||
|
|
||||||
|
@ -302,6 +302,29 @@ bool CommandLineOptions::operator==(CommandLineOptions const& _other) const noex
|
|||||||
modelChecker.settings == _other.modelChecker.settings;
|
modelChecker.settings == _other.modelChecker.settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OptimiserSettings CommandLineOptions::optimiserSettings() const
|
||||||
|
{
|
||||||
|
OptimiserSettings settings;
|
||||||
|
|
||||||
|
if (optimizer.enabled && input.mode == InputMode::Assembler)
|
||||||
|
settings = OptimiserSettings::full();
|
||||||
|
else if (optimizer.enabled)
|
||||||
|
settings = OptimiserSettings::standard();
|
||||||
|
else
|
||||||
|
settings = OptimiserSettings::minimal();
|
||||||
|
|
||||||
|
if (optimizer.noOptimizeYul)
|
||||||
|
settings.runYulOptimiser = false;
|
||||||
|
|
||||||
|
if (optimizer.expectedExecutionsPerDeployment.has_value())
|
||||||
|
settings.expectedExecutionsPerDeployment = optimizer.expectedExecutionsPerDeployment.value();
|
||||||
|
|
||||||
|
if (optimizer.yulSteps.has_value())
|
||||||
|
settings.yulOptimiserSteps = optimizer.yulSteps.value();
|
||||||
|
|
||||||
|
return settings;
|
||||||
|
}
|
||||||
|
|
||||||
bool CommandLineParser::parseInputPathsAndRemappings()
|
bool CommandLineParser::parseInputPathsAndRemappings()
|
||||||
{
|
{
|
||||||
m_options.input.ignoreMissingFiles = (m_args.count(g_strIgnoreMissingFiles) > 0);
|
m_options.input.ignoreMissingFiles = (m_args.count(g_strIgnoreMissingFiles) > 0);
|
||||||
@ -988,19 +1011,9 @@ General Information)").c_str(),
|
|||||||
if (!m_args[g_strOptimizeRuns].defaulted())
|
if (!m_args[g_strOptimizeRuns].defaulted())
|
||||||
m_options.optimizer.expectedExecutionsPerDeployment = m_args.at(g_strOptimizeRuns).as<unsigned>();
|
m_options.optimizer.expectedExecutionsPerDeployment = m_args.at(g_strOptimizeRuns).as<unsigned>();
|
||||||
|
|
||||||
OptimiserSettings optimiserSettings;
|
|
||||||
if (m_options.optimizer.enabled && m_options.input.mode == InputMode::Assembler)
|
|
||||||
optimiserSettings = OptimiserSettings::full();
|
|
||||||
else if (m_options.optimizer.enabled)
|
|
||||||
optimiserSettings = OptimiserSettings::standard();
|
|
||||||
else
|
|
||||||
optimiserSettings = OptimiserSettings::minimal();
|
|
||||||
|
|
||||||
if (m_options.optimizer.noOptimizeYul)
|
|
||||||
optimiserSettings.runYulOptimiser = false;
|
|
||||||
|
|
||||||
if (m_args.count(g_strYulOptimizations))
|
if (m_args.count(g_strYulOptimizations))
|
||||||
{
|
{
|
||||||
|
OptimiserSettings optimiserSettings = m_options.optimiserSettings();
|
||||||
if (!optimiserSettings.runYulOptimiser)
|
if (!optimiserSettings.runYulOptimiser)
|
||||||
{
|
{
|
||||||
serr() << "--" << g_strYulOptimizations << " is invalid if Yul optimizer is disabled" << endl;
|
serr() << "--" << g_strYulOptimizations << " is invalid if Yul optimizer is disabled" << endl;
|
||||||
|
@ -102,6 +102,7 @@ struct CommandLineOptions
|
|||||||
bool operator==(CommandLineOptions const& _other) const noexcept;
|
bool operator==(CommandLineOptions const& _other) const noexcept;
|
||||||
bool operator!=(CommandLineOptions const& _other) const noexcept { return !(*this == _other); }
|
bool operator!=(CommandLineOptions const& _other) const noexcept { return !(*this == _other); }
|
||||||
|
|
||||||
|
OptimiserSettings optimiserSettings() const;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -169,7 +170,6 @@ struct CommandLineOptions
|
|||||||
bool initialize = false;
|
bool initialize = false;
|
||||||
ModelCheckerSettings settings;
|
ModelCheckerSettings settings;
|
||||||
} modelChecker;
|
} modelChecker;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Parses the command-line arguments and produces a filled-out CommandLineOptions structure.
|
/// Parses the command-line arguments and produces a filled-out CommandLineOptions structure.
|
||||||
|
Loading…
Reference in New Issue
Block a user