@@ -44,47 +44,54 @@ using namespace solidity::yul;
44
44
45
45
DataFlowAnalyzer::DataFlowAnalyzer (
46
46
Dialect const & _dialect,
47
+ MemoryAndStorage _analyzeStores,
47
48
map<YulString, SideEffects> _functionSideEffects
48
49
):
49
50
m_dialect(_dialect),
50
51
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)
52
54
{
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
+ }
61
66
}
62
67
63
68
void DataFlowAnalyzer::operator ()(ExpressionStatement& _statement)
64
69
{
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)
76
71
{
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
+ }
87
92
}
93
+ clearKnowledgeIfInvalidated (_statement.expression );
94
+ ASTModifier::operator ()(_statement);
88
95
}
89
96
90
97
void DataFlowAnalyzer::operator ()(Assignment& _assignment)
@@ -346,6 +353,8 @@ void DataFlowAnalyzer::assignValue(YulString _variable, Expression const* _value
346
353
347
354
void DataFlowAnalyzer::clearKnowledgeIfInvalidated (Block const & _block)
348
355
{
356
+ if (!m_analyzeStores)
357
+ return ;
349
358
SideEffectsCollector sideEffects (m_dialect, _block, &m_functionSideEffects);
350
359
if (sideEffects.invalidatesStorage ())
351
360
m_state.storage .clear ();
@@ -355,6 +364,8 @@ void DataFlowAnalyzer::clearKnowledgeIfInvalidated(Block const& _block)
355
364
356
365
void DataFlowAnalyzer::clearKnowledgeIfInvalidated (Expression const & _expr)
357
366
{
367
+ if (!m_analyzeStores)
368
+ return ;
358
369
SideEffectsCollector sideEffects (m_dialect, _expr, &m_functionSideEffects);
359
370
if (sideEffects.invalidatesStorage ())
360
371
m_state.storage .clear ();
@@ -367,6 +378,8 @@ void DataFlowAnalyzer::joinKnowledge(
367
378
unordered_map<YulString, YulString> const & _olderMemory
368
379
)
369
380
{
381
+ if (!m_analyzeStores)
382
+ return ;
370
383
joinKnowledgeHelper (m_state.storage , _olderStorage);
371
384
joinKnowledgeHelper (m_state.memory , _olderMemory);
372
385
}
0 commit comments