Coverage Report

Created: 2022-08-24 06:28

/src/solidity/libyul/optimiser/CircularReferencesPruner.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
/**
19
 * Optimization stage that removes functions that call each other but are
20
 * otherwise unreferenced.
21
 *
22
 *  Prerequisites: Disambiguator, FunctionHoister.
23
 */
24
25
#pragma once
26
27
#include <libyul/optimiser/ASTWalker.h>
28
#include <libyul/optimiser/CallGraphGenerator.h>
29
#include <libyul/optimiser/OptimiserStep.h>
30
31
namespace solidity::yul
32
{
33
34
/**
35
 * Optimization stage that removes functions that call each other but are
36
 * neither externally referenced nor referenced from the outermost context.
37
 */
38
class CircularReferencesPruner: public ASTModifier
39
{
40
public:
41
  static constexpr char const* name{"CircularReferencesPruner"};
42
  static void run(OptimiserStepContext& _context, Block& _ast);
43
44
  using ASTModifier::operator();
45
  void operator()(Block& _block) override;
46
private:
47
  CircularReferencesPruner(std::set<YulString> const& _reservedIdentifiers):
48
    m_reservedIdentifiers(_reservedIdentifiers)
49
0
  {}
50
51
  /// Run a breadth-first search starting from the outermost context and
52
  /// externally referenced functions to find all the functions that are
53
  /// called from there either directly or indirectly.
54
  std::set<YulString> functionsCalledFromOutermostContext(CallGraph const& _callGraph);
55
56
  std::set<YulString> const& m_reservedIdentifiers;
57
};
58
59
}