IRGenerator: Leave IR optimization up to the caller to avoid unnecessarily doing it twice

This commit is contained in:
Kamil Śliwak
2023-06-07 19:44:40 +02:00
parent facc38097d
commit b1a773be2f
6 changed files with 36 additions and 50 deletions
+2 -26
View File
@@ -89,36 +89,13 @@ set<CallableDeclaration const*, ASTNode::CompareByID> collectReachableCallables(
}
tuple<string, Json::Value, string, Json::Value> IRGenerator::run(
string IRGenerator::run(
ContractDefinition const& _contract,
bytes const& _cborMetadata,
map<ContractDefinition const*, string_view const> const& _otherYulSources
)
{
string ir = yul::reindent(generate(_contract, _cborMetadata, _otherYulSources));
yul::YulStack asmStack(
m_evmVersion,
m_eofVersion,
yul::YulStack::Language::StrictAssembly,
m_optimiserSettings,
m_context.debugInfoSelection()
);
if (!asmStack.parseAndAnalyze("", ir))
{
string errorMessage;
for (auto const& error: asmStack.errors())
errorMessage += langutil::SourceReferenceFormatter::formatErrorInformation(
*error,
asmStack.charStream("")
);
solAssert(false, ir + "\n\nInvalid IR generated:\n" + errorMessage + "\n");
}
Json::Value irAst = asmStack.astJson();
asmStack.optimize();
Json::Value irOptAst = asmStack.astJson();
return {std::move(ir), std::move(irAst), asmStack.print(m_context.soliditySourceProvider()), std::move(irOptAst)};
return yul::reindent(generate(_contract, _cborMetadata, _otherYulSources));
}
string IRGenerator::generate(
@@ -1116,7 +1093,6 @@ void IRGenerator::resetContext(ContractDefinition const& _contract, ExecutionCon
m_evmVersion,
_context,
m_context.revertStrings(),
m_optimiserSettings,
m_context.sourceIndices(),
m_context.debugInfoSelection(),
m_context.soliditySourceProvider()