Coverage Report

Created: 2022-08-24 06:28

/src/solidity/libyul/optimiser/UnusedFunctionsCommon.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
#pragma once
19
20
#include <libyul/optimiser/Metrics.h>
21
#include <libyul/optimiser/NameDispenser.h>
22
23
#include <libyul/AST.h>
24
25
namespace solidity::yul::unusedFunctionsCommon
26
{
27
28
/// Returns true if applying UnusedFunctionParameterPruner is not helpful or redundant because the
29
/// inliner will be able to handle it anyway.
30
inline bool tooSimpleToBePruned(FunctionDefinition const& _f)
31
0
{
32
0
  return _f.body.statements.size() <= 1 && CodeSize::codeSize(_f.body) <= 1;
33
0
}
34
35
/// Given a function definition `_original`, this function returns a 'linking' function that calls
36
/// `_originalFunctionName` (with reduced parameters and return values).
37
///
38
/// The parameter `_usedParametersAndReturnVariables` is a pair of boolean-vectors. Its `.first`
39
/// corresponds to function parameters and its `.second` corresponds to function return-variables. A
40
/// false value at index `i` means that the corresponding function parameter / return-variable at
41
/// index `i` is unused.
42
///
43
/// Example:
44
///
45
/// Let `_original` be the function `function f_1() -> y { }`. (In practice, this function usually cannot
46
/// be inlined and has parameters / return-variables that are unused.)
47
/// Let `_usedParametersAndReturnVariables` be `({}, {false})`
48
/// Let `_originalFunctionName` be `f`.
49
/// Let `_linkingFunctionName` be `f_1`.
50
///
51
/// Then the returned linking function would be `function f_1() -> y_1 { f() }`
52
FunctionDefinition createLinkingFunction(
53
  FunctionDefinition const& _original,
54
  std::pair<std::vector<bool>, std::vector<bool>> const& _usedParametersAndReturns,
55
  YulString const& _originalFunctionName,
56
  YulString const& _linkingFunctionName,
57
  NameDispenser& _nameDispenser
58
);
59
60
}