mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Less destructive switch processing.
This commit is contained in:
parent
145186f68c
commit
04c8a7f0c6
@ -136,16 +136,18 @@ void DataFlowAnalyzer::operator()(Switch& _switch)
|
|||||||
unordered_map<YulString, YulString> storage = m_storage;
|
unordered_map<YulString, YulString> storage = m_storage;
|
||||||
unordered_map<YulString, YulString> memory = m_memory;
|
unordered_map<YulString, YulString> memory = m_memory;
|
||||||
(*this)(_case.body);
|
(*this)(_case.body);
|
||||||
|
//TODO throw away knowledge if it is terminating
|
||||||
joinKnowledge(storage, memory);
|
joinKnowledge(storage, memory);
|
||||||
|
|
||||||
set<YulString> variables = assignedVariableNames(_case.body);
|
set<YulString> variables = assignedVariableNames(_case.body);
|
||||||
assignedVariables += variables;
|
assignedVariables += variables;
|
||||||
// This is a little too destructive, we could retain the old values.
|
// This is a little too destructive, we could retain the old values.
|
||||||
clearValues(variables);
|
clearValues(variables);
|
||||||
clearKnowledgeIfInvalidated(_case.body);
|
//clearKnowledgeIfInvalidated(_case.body);
|
||||||
}
|
}
|
||||||
for (auto& _case: _switch.cases)
|
// TODO Handle special case where we have a default switch body?
|
||||||
clearKnowledgeIfInvalidated(_case.body);
|
//for (auto& _case: _switch.cases)
|
||||||
|
// clearKnowledgeIfInvalidated(_case.body);
|
||||||
clearValues(assignedVariables);
|
clearValues(assignedVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,6 +343,7 @@ void DataFlowAnalyzer::clearKnowledgeIfInvalidated(Block const& _block)
|
|||||||
|
|
||||||
void DataFlowAnalyzer::clearKnowledgeIfInvalidated(Expression const& _expr)
|
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);
|
SideEffectsCollector sideEffects(m_dialect, _expr, &m_functionSideEffects);
|
||||||
if (sideEffects.invalidatesStorage())
|
if (sideEffects.invalidatesStorage())
|
||||||
m_storage.clear();
|
m_storage.clear();
|
||||||
|
28
test/libyul/yulOptimizerTests/fullSuite/loadrestest.yul
Normal file
28
test/libyul/yulOptimizerTests/fullSuite/loadrestest.yul
Normal 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) }
|
||||||
|
// }
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user