mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Reverse lookup optimization for DataFlowAnalyzer
This commit is contained in:
parent
79d975a77d
commit
83f6330ee9
@ -272,6 +272,8 @@ void DataFlowAnalyzer::handleAssignment(set<YulString> const& _variables, Expres
|
||||
for (auto const& name: _variables)
|
||||
{
|
||||
m_state.references[name] = referencedVariables;
|
||||
for (auto&& referencedVariable: referencedVariables)
|
||||
m_state.references_reverse_lookup[referencedVariable].insert(name);
|
||||
if (!_isDeclaration)
|
||||
{
|
||||
// assignment to slot denoted by "name"
|
||||
@ -316,6 +318,8 @@ void DataFlowAnalyzer::popScope()
|
||||
for (auto const& name: m_variableScopes.back().variables)
|
||||
{
|
||||
m_state.value.erase(name);
|
||||
for (auto&& ref: m_state.references[name])
|
||||
m_state.references_reverse_lookup.erase(ref);
|
||||
m_state.references.erase(name);
|
||||
}
|
||||
m_variableScopes.pop_back();
|
||||
@ -353,14 +357,15 @@ void DataFlowAnalyzer::clearValues(set<YulString> _variables)
|
||||
|
||||
// Also clear variables that reference variables to be cleared.
|
||||
for (auto const& variableToClear: _variables)
|
||||
for (auto const& [ref, names]: m_state.references)
|
||||
if (names.count(variableToClear))
|
||||
_variables.emplace(ref);
|
||||
if (m_state.references_reverse_lookup.count(variableToClear))
|
||||
_variables += m_state.references_reverse_lookup[variableToClear];
|
||||
|
||||
// Clear the value and update the reference relation.
|
||||
for (auto const& name: _variables)
|
||||
{
|
||||
m_state.value.erase(name);
|
||||
for (auto&& ref: m_state.references[name])
|
||||
m_state.references_reverse_lookup.erase(ref);
|
||||
m_state.references.erase(name);
|
||||
}
|
||||
}
|
||||
|
@ -181,6 +181,8 @@ private:
|
||||
std::map<YulString, AssignedValue> value;
|
||||
/// m_references[a].contains(b) <=> the current expression assigned to a references b
|
||||
std::unordered_map<YulString, std::set<YulString>> references;
|
||||
/// Reverse lookup for above m_references map
|
||||
std::unordered_map<YulString, std::set<YulString>> references_reverse_lookup;
|
||||
|
||||
Environment environment;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user