@@ -44,47 +44,54 @@ using namespace solidity::yul;
4444
4545DataFlowAnalyzer::DataFlowAnalyzer (
4646 Dialect const & _dialect,
47+ MemoryAndStorage _analyzeStores,
4748 map<YulString, SideEffects> _functionSideEffects
4849):
4950 m_dialect(_dialect),
5051 m_functionSideEffects(std::move(_functionSideEffects)),
51- m_knowledgeBase(_dialect, [this ](YulString _var) { return variableValue (_var); })
52+ m_knowledgeBase(_dialect, [this ](YulString _var) { return variableValue (_var); }),
53+ m_analyzeStores (_analyzeStores == MemoryAndStorage::Analyze)
5254{
53- if (auto const * builtin = _dialect.memoryStoreFunction (YulString{}))
54- m_storeFunctionName[static_cast <unsigned >(StoreLoadLocation::Memory)] = builtin->name ;
55- if (auto const * builtin = _dialect.memoryLoadFunction (YulString{}))
56- m_loadFunctionName[static_cast <unsigned >(StoreLoadLocation::Memory)] = builtin->name ;
57- if (auto const * builtin = _dialect.storageStoreFunction (YulString{}))
58- m_storeFunctionName[static_cast <unsigned >(StoreLoadLocation::Storage)] = builtin->name ;
59- if (auto const * builtin = _dialect.storageLoadFunction (YulString{}))
60- m_loadFunctionName[static_cast <unsigned >(StoreLoadLocation::Storage)] = builtin->name ;
55+ if (m_analyzeStores)
56+ {
57+ if (auto const * builtin = _dialect.memoryStoreFunction (YulString{}))
58+ m_storeFunctionName[static_cast <unsigned >(StoreLoadLocation::Memory)] = builtin->name ;
59+ if (auto const * builtin = _dialect.memoryLoadFunction (YulString{}))
60+ m_loadFunctionName[static_cast <unsigned >(StoreLoadLocation::Memory)] = builtin->name ;
61+ if (auto const * builtin = _dialect.storageStoreFunction (YulString{}))
62+ m_storeFunctionName[static_cast <unsigned >(StoreLoadLocation::Storage)] = builtin->name ;
63+ if (auto const * builtin = _dialect.storageLoadFunction (YulString{}))
64+ m_loadFunctionName[static_cast <unsigned >(StoreLoadLocation::Storage)] = builtin->name ;
65+ }
6166}
6267
6368void DataFlowAnalyzer::operator ()(ExpressionStatement& _statement)
6469{
65- if (auto vars = isSimpleStore (StoreLoadLocation::Storage, _statement))
66- {
67- ASTModifier::operator ()(_statement);
68- cxx20::erase_if (m_state.storage , mapTuple ([&](auto && key, auto && value) {
69- return
70- !m_knowledgeBase.knownToBeDifferent (vars->first , key) &&
71- !m_knowledgeBase.knownToBeEqual (vars->second , value);
72- }));
73- m_state.storage [vars->first ] = vars->second ;
74- }
75- else if (auto vars = isSimpleStore (StoreLoadLocation::Memory, _statement))
70+ if (m_analyzeStores)
7671 {
77- ASTModifier::operator ()(_statement);
78- cxx20::erase_if (m_state.memory , mapTuple ([&](auto && key, auto && /* value */ ) {
79- return !m_knowledgeBase.knownToBeDifferentByAtLeast32 (vars->first , key);
80- }));
81- m_state.memory [vars->first ] = vars->second ;
82- }
83- else
84- {
85- clearKnowledgeIfInvalidated (_statement.expression );
86- ASTModifier::operator ()(_statement);
72+ if (auto vars = isSimpleStore (StoreLoadLocation::Storage, _statement))
73+ {
74+ ASTModifier::operator ()(_statement);
75+ cxx20::erase_if (m_state.storage , mapTuple ([&](auto && key, auto && value) {
76+ return
77+ !m_knowledgeBase.knownToBeDifferent (vars->first , key) &&
78+ !m_knowledgeBase.knownToBeEqual (vars->second , value);
79+ }));
80+ m_state.storage [vars->first ] = vars->second ;
81+ return ;
82+ }
83+ else if (auto vars = isSimpleStore (StoreLoadLocation::Memory, _statement))
84+ {
85+ ASTModifier::operator ()(_statement);
86+ cxx20::erase_if (m_state.memory , mapTuple ([&](auto && key, auto && /* value */ ) {
87+ return !m_knowledgeBase.knownToBeDifferentByAtLeast32 (vars->first , key);
88+ }));
89+ m_state.memory [vars->first ] = vars->second ;
90+ return ;
91+ }
8792 }
93+ clearKnowledgeIfInvalidated (_statement.expression );
94+ ASTModifier::operator ()(_statement);
8895}
8996
9097void DataFlowAnalyzer::operator ()(Assignment& _assignment)
@@ -346,6 +353,8 @@ void DataFlowAnalyzer::assignValue(YulString _variable, Expression const* _value
346353
347354void DataFlowAnalyzer::clearKnowledgeIfInvalidated (Block const & _block)
348355{
356+ if (!m_analyzeStores)
357+ return ;
349358 SideEffectsCollector sideEffects (m_dialect, _block, &m_functionSideEffects);
350359 if (sideEffects.invalidatesStorage ())
351360 m_state.storage .clear ();
@@ -355,6 +364,8 @@ void DataFlowAnalyzer::clearKnowledgeIfInvalidated(Block const& _block)
355364
356365void DataFlowAnalyzer::clearKnowledgeIfInvalidated (Expression const & _expr)
357366{
367+ if (!m_analyzeStores)
368+ return ;
358369 SideEffectsCollector sideEffects (m_dialect, _expr, &m_functionSideEffects);
359370 if (sideEffects.invalidatesStorage ())
360371 m_state.storage .clear ();
@@ -367,6 +378,8 @@ void DataFlowAnalyzer::joinKnowledge(
367378 unordered_map<YulString, YulString> const & _olderMemory
368379)
369380{
381+ if (!m_analyzeStores)
382+ return ;
370383 joinKnowledgeHelper (m_state.storage , _olderStorage);
371384 joinKnowledgeHelper (m_state.memory , _olderMemory);
372385}
0 commit comments