/src/solidity/libyul/optimiser/SSAReverser.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 | | |
23 | | namespace solidity::yul |
24 | | { |
25 | | |
26 | | class AssignmentCounter; |
27 | | |
28 | | /** |
29 | | * Reverses the SSA transformation. |
30 | | * |
31 | | * In particular, the SSA transform will rewrite |
32 | | * |
33 | | * a := E |
34 | | * |
35 | | * to |
36 | | * |
37 | | * let a_1 := E |
38 | | * a := a_1 |
39 | | * |
40 | | * To undo this kind of transformation, the SSAReverser changes this back to |
41 | | * |
42 | | * a := E |
43 | | * let a_1 := a |
44 | | * |
45 | | * In the special case |
46 | | * let a := E |
47 | | * a := a |
48 | | * |
49 | | * the redundant assignment "a := a" is removed. |
50 | | * |
51 | | * |
52 | | * Secondly, the SSA transform will rewrite |
53 | | * |
54 | | * let a := E |
55 | | * to |
56 | | * |
57 | | * let a_1 := E |
58 | | * let a := a_1 |
59 | | * |
60 | | * To undo this kind of transformation, the SSAReverser changes this back to |
61 | | * |
62 | | * let a := E |
63 | | * let a_1 := a |
64 | | * |
65 | | * After that the CSE can replace references of a_1 by references to a, |
66 | | * after which the unused pruner can remove the declaration of a_1. |
67 | | * |
68 | | * Prerequisites: Disambiguator |
69 | | * |
70 | | */ |
71 | | class SSAReverser: public ASTModifier |
72 | | { |
73 | | public: |
74 | | static constexpr char const* name{"SSAReverser"}; |
75 | | static void run(OptimiserStepContext& _context, Block& _ast); |
76 | | |
77 | | using ASTModifier::operator(); |
78 | | void operator()(Block& _block) override; |
79 | | |
80 | | private: |
81 | 211k | explicit SSAReverser(AssignmentCounter const& _assignmentCounter): m_assignmentCounter(_assignmentCounter) {} |
82 | | |
83 | | AssignmentCounter const& m_assignmentCounter; |
84 | | }; |
85 | | |
86 | | } |