Less destructive switch processing.

This commit is contained in:
chriseth 2022-03-09 09:18:32 +01:00
parent 145186f68c
commit 04c8a7f0c6
2 changed files with 34 additions and 3 deletions

View File

@ -136,16 +136,18 @@ void DataFlowAnalyzer::operator()(Switch& _switch)
unordered_map<YulString, YulString> storage = m_storage;
unordered_map<YulString, YulString> memory = m_memory;
(*this)(_case.body);
//TODO throw away knowledge if it is terminating
joinKnowledge(storage, memory);
set<YulString> variables = assignedVariableNames(_case.body);
assignedVariables += variables;
// This is a little too destructive, we could retain the old values.
clearValues(variables);
clearKnowledgeIfInvalidated(_case.body);
//clearKnowledgeIfInvalidated(_case.body);
}
for (auto& _case: _switch.cases)
clearKnowledgeIfInvalidated(_case.body);
// TODO Handle special case where we have a default switch body?
//for (auto& _case: _switch.cases)
// clearKnowledgeIfInvalidated(_case.body);
clearValues(assignedVariables);
}
@ -341,6 +343,7 @@ void DataFlowAnalyzer::clearKnowledgeIfInvalidated(Block const& _block)
void DataFlowAnalyzer::clearKnowledgeIfInvalidated(Expression const& _expr)
{
// TODO with the extended side-effects, this could also be more precise now.
SideEffectsCollector sideEffects(m_dialect, _expr, &m_functionSideEffects);
if (sideEffects.invalidatesStorage())
m_storage.clear();

View File

@ -0,0 +1,28 @@
{
let _1 := memoryguard(0x80)
mstore(64, _1)
let _2 := 0
switch shr(224, calldataload(_2))
case 0x06661abd {
mstore(_1, sload(_2))
return(_1, 32)
}
case 0xc2985578 {
return(mload(64), _2)
}
}
// ----
// step: fullSuite
//
// {
// {
// let _1 := memoryguard(0x80)
// mstore(64, _1)
// switch shr(224, calldataload(0))
// case 0x06661abd {
// mstore(_1, sload(0))
// return(_1, 32)
// }
// case 0xc2985578 { return(mload(64), 0) }
// }
// }