MCPcopy Create free account
hub / github.com/argotorg/solidity / performInline

Method performInline

libyul/optimiser/FullInliner.cpp:296–357  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296std::vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionCall& _funCall)
297{
298 std::vector<Statement> newStatements;
299 std::map<YulName, YulName> variableReplacements;
300
301 yulAssert(std::holds_alternative<Identifier>(_funCall.functionName));
302 FunctionDefinition* function = m_driver.function(std::get<Identifier>(_funCall.functionName).name);
303 assertThrow(!!function, OptimizerException, "Attempt to inline invalid function.");
304
305 m_driver.tentativelyUpdateCodeSize(function->name, m_currentFunction);
306
307 // helper function to create a new variable that is supposed to model
308 // an existing variable.
309 auto newVariable = [&](NameWithDebugData const& _existingVariable, Expression* _value) {
310 YulName newName = m_nameDispenser.newName(_existingVariable.name);
311 variableReplacements[_existingVariable.name] = newName;
312 VariableDeclaration varDecl{_funCall.debugData, {{_funCall.debugData, newName}}, {}};
313 if (_value)
314 varDecl.value = std::make_unique<Expression>(std::move(*_value));
315 else
316 varDecl.value = std::make_unique<Expression>(m_dialect.zeroLiteral());
317 newStatements.emplace_back(std::move(varDecl));
318 };
319
320 for (auto&& [parameter, argument]: ranges::views::zip(function->parameters, _funCall.arguments) | ranges::views::reverse)
321 newVariable(parameter, &argument);
322 for (auto const& var: function->returnVariables)
323 newVariable(var, nullptr);
324
325 Statement newBody = BodyCopier(m_nameDispenser, variableReplacements)(function->body);
326 newStatements += std::move(std::get<Block>(newBody).statements);
327
328 std::visit(util::GenericVisitor{
329 util::VisitorFallback<>{},
330 [&](Assignment& _assignment)
331 {
332 for (size_t i = 0; i < _assignment.variableNames.size(); ++i)
333 newStatements.emplace_back(Assignment{
334 _assignment.debugData,
335 {_assignment.variableNames[i]},
336 std::make_unique<Expression>(Identifier{
337 _assignment.debugData,
338 variableReplacements.at(function->returnVariables[i].name)
339 })
340 });
341 },
342 [&](VariableDeclaration& _varDecl)
343 {
344 for (size_t i = 0; i < _varDecl.variables.size(); ++i)
345 newStatements.emplace_back(VariableDeclaration{
346 _varDecl.debugData,
347 {std::move(_varDecl.variables[i])},
348 std::make_unique<Expression>(Identifier{
349 _varDecl.debugData,
350 variableReplacements.at(function->returnVariables[i].name)
351 })
352 });
353 }

Callers

nothing calls this directly

Calls 7

BodyCopierClass · 0.85
newNameMethod · 0.80
zeroLiteralMethod · 0.80
atMethod · 0.80
functionMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected