/src/solidity/libyul/backends/evm/ssa/PhiInverse.cpp
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 | | #include <libyul/backends/evm/ssa/PhiInverse.h> |
20 | | |
21 | | using namespace solidity::yul::ssa; |
22 | | |
23 | | PhiInverse::PhiInverse(SSACFG const& _cfg, SSACFG::BlockId const& _from, SSACFG::BlockId const& _to) |
24 | 0 | { |
25 | 0 | _cfg.forEachUpsilon(_cfg.block(_from), [&](InstId const instId, SSACFG::Inst const& inst) { |
26 | 0 | if ( |
27 | 0 | InstId const phi = _cfg.upsilonPhi(instId); |
28 | 0 | _cfg.inst(phi).block == _to |
29 | 0 | ) |
30 | 0 | m_phiToPreImage[phi] = inst.inputs.at(0); |
31 | 0 | }); |
32 | 0 | } |
33 | | |
34 | | bool PhiInverse::noOp() const |
35 | 0 | { |
36 | 0 | return m_phiToPreImage.empty(); |
37 | 0 | } |
38 | | |
39 | | InstId PhiInverse::operator()(InstId _valueId) const |
40 | 0 | { |
41 | 0 | return solidity::util::valueOrDefault(m_phiToPreImage, _valueId, _valueId); |
42 | 0 | } |
43 | | |
44 | | std::map<InstId, InstId> const& PhiInverse::data() const |
45 | 0 | { |
46 | 0 | return m_phiToPreImage; |
47 | 0 | } |