solidity/libyul/optimiser/SSAReverser.h

86 lines
2.0 KiB
C
Raw Normal View History

2019-01-16 10:44:45 +00:00
/*
This file is part of solidity.
solidity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
solidity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with solidity. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <libyul/optimiser/ASTWalker.h>
2019-09-23 14:32:50 +00:00
#include <libyul/optimiser/OptimiserStep.h>
2019-01-16 10:44:45 +00:00
2019-12-11 16:31:36 +00:00
namespace solidity::yul
2019-01-16 10:44:45 +00:00
{
2019-01-17 15:11:55 +00:00
class AssignmentCounter;
2019-01-16 10:44:45 +00:00
/**
* Reverses the SSA transformation.
*
* In particular, the SSA transform will rewrite
*
* a := E
*
* to
*
* let a_1 := E
* a := a_1
*
* To undo this kind of transformation, the SSAReverser changes this back to
2019-01-16 10:44:45 +00:00
*
* a := E
* let a_1 := a
*
* In the special case
* let a := E
* a := a
*
* the redundant assignment "a := a" is removed.
*
*
* Secondly, the SSA transform will rewrite
*
* let a := E
* to
*
* let a_1 := E
* let a := a_1
*
* To undo this kind of transformation, the SSAReverser changes this back to
*
* let a := E
* let a_1 := a
*
2019-01-16 10:44:45 +00:00
* After that the CSE can replace references of a_1 by references to a,
* after which the unused pruner can remove the declaration of a_1.
*
2019-01-17 15:11:55 +00:00
* Prerequisites: Disambiguator
2019-01-16 10:44:45 +00:00
*
*/
class SSAReverser: public ASTModifier
{
public:
2019-09-23 14:32:50 +00:00
static constexpr char const* name{"SSAReverser"};
static void run(OptimiserStepContext& _context, Block& _ast);
2019-01-16 10:44:45 +00:00
using ASTModifier::operator();
void operator()(Block& _block) override;
2019-01-17 15:11:55 +00:00
private:
2019-09-23 14:32:50 +00:00
explicit SSAReverser(AssignmentCounter const& _assignmentCounter): m_assignmentCounter(_assignmentCounter) {}
2019-01-17 15:11:55 +00:00
AssignmentCounter const& m_assignmentCounter;
2019-01-16 10:44:45 +00:00
};
}