Coverage Report

Created: 2022-08-24 06:28

/src/solidity/libyul/optimiser/ConditionalSimplifier.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/ASTWalker.h>
21
#include <libyul/optimiser/OptimiserStep.h>
22
#include <libyul/ASTForward.h>
23
#include <libyul/Dialect.h>
24
#include <libsolutil/Common.h>
25
26
namespace solidity::yul
27
{
28
29
/**
30
 * Conditional simplifier.
31
 *
32
 * Inserts assignments to condition variables if the value can be determined
33
 * from the control-flow.
34
 *
35
 * Destroys SSA form.
36
 *
37
 * Currently, this tool is very limited, mostly because we do not yet have support
38
 * for boolean types. Since conditions only check for expressions being nonzero,
39
 * we cannot assign a specific value.
40
 *
41
 * Current features:
42
 *  - switch cases: insert "<condition> := <caseLabel>"
43
 *  - after if statement with terminating control-flow, insert "<condition> := 0"
44
 *
45
 * Future features:
46
 *  - allow replacements by "1"
47
 *
48
 * Works best with SSA form and if dead code removal has run before.
49
 *
50
 * Prerequisite: Disambiguator.
51
 */
52
class ConditionalSimplifier: public ASTModifier
53
{
54
public:
55
  static constexpr char const* name{"ConditionalSimplifier"};
56
  static void run(OptimiserStepContext& _context, Block& _ast);
57
58
  using ASTModifier::operator();
59
  void operator()(Switch& _switch) override;
60
  void operator()(Block& _block) override;
61
62
private:
63
  explicit ConditionalSimplifier(
64
    Dialect const& _dialect,
65
    std::map<YulString, ControlFlowSideEffects> _sideEffects
66
  ):
67
    m_dialect(_dialect), m_functionSideEffects(move(_sideEffects))
68
0
  {}
69
  Dialect const& m_dialect;
70
  std::map<YulString, ControlFlowSideEffects> m_functionSideEffects;
71
};
72
73
}