/src/solidity/libyul/optimiser/StructuralSimplifier.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 | | #pragma once |
19 | | |
20 | | #include <libyul/optimiser/ASTWalker.h> |
21 | | #include <libyul/optimiser/OptimiserStep.h> |
22 | | #include <libsolutil/Common.h> |
23 | | |
24 | | namespace solidity::yul |
25 | | { |
26 | | |
27 | | /** |
28 | | * Structural simplifier. Performs the following simplification steps: |
29 | | * - replace if with true condition with its body |
30 | | * - remove if with false condition |
31 | | * - replace switch with const expr with matching case body |
32 | | * - replace for with false condition by its initialization part |
33 | | * |
34 | | * The LiteralRematerialiser should be run before this. |
35 | | * |
36 | | * Prerequisite: Disambiguator. |
37 | | * |
38 | | * Important: Can only be used on EVM code. |
39 | | */ |
40 | | class StructuralSimplifier: public ASTModifier |
41 | | { |
42 | | public: |
43 | | static constexpr char const* name{"StructuralSimplifier"}; |
44 | | static void run(OptimiserStepContext&, Block& _ast); |
45 | | |
46 | | using ASTModifier::operator(); |
47 | | void operator()(Block& _block) override; |
48 | | private: |
49 | 656k | StructuralSimplifier() = default; |
50 | | |
51 | | void simplify(std::vector<Statement>& _statements); |
52 | | }; |
53 | | |
54 | | } |