aboutsummaryrefslogtreecommitdiffstats
path: root/libyul/optimiser/Rematerialiser.h
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-06 06:42:55 +0800
committerchriseth <chris@ethereum.org>2019-01-07 21:03:32 +0800
commit2e9c70add0490a5157f393c78e29bb86f67111d7 (patch)
treeaa182a37aa5cc21be1144041ad3d6df803e9c255 /libyul/optimiser/Rematerialiser.h
parentaca9e581454585fab494a87febb7da3278e3aa7b (diff)
downloaddexon-solidity-2e9c70add0490a5157f393c78e29bb86f67111d7.tar.gz
dexon-solidity-2e9c70add0490a5157f393c78e29bb86f67111d7.tar.zst
dexon-solidity-2e9c70add0490a5157f393c78e29bb86f67111d7.zip
Use rematerializer if variable is unreferenced or value is "cheap".
Diffstat (limited to 'libyul/optimiser/Rematerialiser.h')
-rw-r--r--libyul/optimiser/Rematerialiser.h13
1 files changed, 12 insertions, 1 deletions
diff --git a/libyul/optimiser/Rematerialiser.h b/libyul/optimiser/Rematerialiser.h
index b3841519..c34353de 100644
--- a/libyul/optimiser/Rematerialiser.h
+++ b/libyul/optimiser/Rematerialiser.h
@@ -26,16 +26,27 @@ namespace yul
{
/**
- * Optimisation stage that replaces variables by their most recently assigned expressions.
+ * Optimisation stage that replaces variables by their most recently assigned expressions,
+ * but only if the expression is movable and one of the following holds:
+ * - the variable is referenced exactly once
+ * - the value is extremely cheap ("cost" of zero like ``caller()``)
+ * - the variable is referenced at most 5 times and the value is rather cheap
+ * ("cost" of at most 1 like a constant up to 0xff)
*
* Prerequisite: Disambiguator
*/
class Rematerialiser: public DataFlowAnalyzer
{
+public:
+ static void run(Block& _ast);
+
protected:
+ Rematerialiser(Block& _ast);
+
using ASTModifier::visit;
void visit(Expression& _e) override;
+ std::map<YulString, size_t> m_referenceCounts;
};
}