/src/solidity/libyul/optimiser/ExpressionSimplifier.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 | | * Optimiser component that uses the simplification rules to simplify expressions. |
20 | | */ |
21 | | |
22 | | #pragma once |
23 | | |
24 | | #include <libyul/ASTForward.h> |
25 | | |
26 | | #include <libyul/optimiser/DataFlowAnalyzer.h> |
27 | | |
28 | | namespace solidity::yul |
29 | | { |
30 | | struct Dialect; |
31 | | struct OptimiserStepContext; |
32 | | |
33 | | /** |
34 | | * Applies simplification rules to all expressions. |
35 | | * The component will work best if the code is in SSA form, but |
36 | | * this is not required for correctness. Using CommonSubexpressionEliminator |
37 | | * also helps this component track equivalent sub-expressions. |
38 | | * |
39 | | * It tracks the current values of variables using the DataFlowAnalyzer |
40 | | * and takes them into account for replacements. |
41 | | * |
42 | | * Prerequisite: Disambiguator, ForLoopInitRewriter. |
43 | | */ |
44 | | class ExpressionSimplifier: public DataFlowAnalyzer |
45 | | { |
46 | | public: |
47 | | static constexpr char const* name{"ExpressionSimplifier"}; |
48 | | static void run(OptimiserStepContext&, Block& _ast); |
49 | | |
50 | | using ASTModifier::operator(); |
51 | | void visit(Expression& _expression) override; |
52 | | |
53 | | private: |
54 | | explicit ExpressionSimplifier(Dialect const& _dialect): |
55 | | DataFlowAnalyzer(_dialect, MemoryAndStorage::Ignore) |
56 | 0 | {} |
57 | | bool knownToBeZero(Expression const& _expression) const; |
58 | | }; |
59 | | |
60 | | } |