Evaluate keccak(a, const) if value at memory location a is known

Here the value of constant can be at most 32.
This commit is contained in:
hrkrshnn
2021-04-22 18:19:47 +02:00
parent 011f8d3ff7
commit 3bc4f5708a
4 changed files with 103 additions and 4 deletions
+16 -2
View File
@@ -32,6 +32,9 @@ namespace solidity::yul
* Optimisation stage that replaces expressions of type ``sload(x)`` and ``mload(x)`` by the value
* currently stored in storage resp. memory, if known.
*
* Also evaluates simple ``keccak256(a, c)`` when the value at memory location `a` is known and `c`
* is a constant `<= 32`.
*
* Works best if the code is in SSA form.
*
* Prerequisite: Disambiguator, ForLoopInitRewriter.
@@ -47,10 +50,12 @@ private:
LoadResolver(
Dialect const& _dialect,
std::map<YulString, SideEffects> _functionSideEffects,
bool _optimizeMLoad
bool _optimizeMLoad,
std::optional<size_t> _expectedExecutionsPerDeployment
):
DataFlowAnalyzer(_dialect, std::move(_functionSideEffects)),
m_optimizeMLoad(_optimizeMLoad)
m_optimizeMLoad(_optimizeMLoad),
m_expectedExecutionsPerDeployment(std::move(_expectedExecutionsPerDeployment))
{}
protected:
@@ -63,7 +68,16 @@ protected:
std::vector<Expression> const& _arguments
);
/// Evaluates simple ``keccak256(a, c)`` when the value at memory location ``a`` is known and
/// `c` is a constant `<= 32`.
void tryEvaluateKeccak(
Expression& _e,
std::vector<Expression> const& _arguments
);
bool m_optimizeMLoad = false;
/// The --optimize-runs parameter. Value `nullopt` represents creation code.
std::optional<size_t> m_expectedExecutionsPerDeployment;
};
}