diff options
author | chriseth <chris@ethereum.org> | 2018-12-21 00:22:17 +0800 |
---|---|---|
committer | chriseth <chris@ethereum.org> | 2019-01-08 00:23:38 +0800 |
commit | 5b73c2ae3bce09442572b5401a7bcccc2ffe7590 (patch) | |
tree | d2e5b07ef78f240b3b8d1ae72cfae4054ce6e41e /libyul/optimiser/CommonSubexpressionEliminator.cpp | |
parent | 9f5d34af7de481c5b8ce89057a6df2a3283d14b0 (diff) | |
download | dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.tar dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.tar.gz dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.tar.bz2 dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.tar.lz dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.tar.xz dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.tar.zst dexon-solidity-5b73c2ae3bce09442572b5401a7bcccc2ffe7590.zip |
Take special functions that require literals into account.
Diffstat (limited to 'libyul/optimiser/CommonSubexpressionEliminator.cpp')
-rw-r--r-- | libyul/optimiser/CommonSubexpressionEliminator.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/libyul/optimiser/CommonSubexpressionEliminator.cpp b/libyul/optimiser/CommonSubexpressionEliminator.cpp index 9b851333..8ce003e7 100644 --- a/libyul/optimiser/CommonSubexpressionEliminator.cpp +++ b/libyul/optimiser/CommonSubexpressionEliminator.cpp @@ -25,6 +25,7 @@ #include <libyul/optimiser/SyntacticalEquality.h> #include <libyul/Exceptions.h> #include <libyul/AsmData.h> +#include <libyul/Dialect.h> using namespace std; using namespace dev; @@ -32,12 +33,24 @@ using namespace yul; void CommonSubexpressionEliminator::visit(Expression& _e) { + bool descend = true; + // If this is a function call to a function that requires literal arguments, + // do not try to simplify there. + if (_e.type() == typeid(FunctionCall)) + if (BuiltinFunction const* builtin = m_dialect.builtin(boost::get<FunctionCall>(_e).functionName.name)) + if (builtin->literalArguments) + // We should not modify function arguments that have to be literals + // Note that replacing the function call entirely is fine, + // if the function call is movable. + descend = false; + // We visit the inner expression first to first simplify inner expressions, // which hopefully allows more matches. // Note that the DataFlowAnalyzer itself only has code for visiting Statements, // so this basically invokes the AST walker directly and thus post-visiting // is also fine with regards to data flow analysis. - DataFlowAnalyzer::visit(_e); + if (descend) + DataFlowAnalyzer::visit(_e); if (_e.type() == typeid(Identifier)) { |