Coverage Report

Created: 2025-06-24 07:59

/src/solidity/libyul/optimiser/EqualStoreEliminator.h
Line
Count
Source
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
 * Optimisation stage that removes mstore and sstore operations if they store the same
20
 * value that is already known to be in that slot.
21
 */
22
23
#pragma once
24
25
#include <libyul/optimiser/DataFlowAnalyzer.h>
26
#include <libyul/optimiser/OptimiserStep.h>
27
28
namespace solidity::yul
29
{
30
31
/**
32
 * Optimisation stage that removes mstore and sstore operations if they store the same
33
 * value that is already known to be in that slot.
34
 *
35
 * Works best if the code is in SSA form - without literal arguments.
36
 *
37
 * Prerequisite: Disambiguator, ForLoopInitRewriter.
38
 */
39
class EqualStoreEliminator: public DataFlowAnalyzer
40
{
41
public:
42
  static constexpr char const* name{"EqualStoreEliminator"};
43
  static void run(OptimiserStepContext const&, Block& _ast);
44
45
private:
46
  EqualStoreEliminator(
47
    Dialect const& _dialect,
48
    std::map<FunctionHandle, SideEffects> _functionSideEffects
49
  ):
50
    DataFlowAnalyzer(_dialect, MemoryAndStorage::Analyze, std::move(_functionSideEffects))
51
77.4k
  {}
52
53
protected:
54
  using ASTModifier::visit;
55
  void visit(Statement& _statement) override;
56
57
  std::set<Statement const*> m_pendingRemovals;
58
};
59
60
}