mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Remove fixStackTooDeep and adjust combineStack comments.
This commit is contained in:
parent
3bb7414703
commit
556bd9adfc
@ -302,7 +302,6 @@ void StackLayoutGenerator::processEntryPoint(CFG::BasicBlock const& _entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
stitchConditionalJumps(_entry);
|
stitchConditionalJumps(_entry);
|
||||||
fixStackTooDeep(_entry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<Stack> StackLayoutGenerator::getExitLayoutOrStageDependencies(
|
optional<Stack> StackLayoutGenerator::getExitLayoutOrStageDependencies(
|
||||||
@ -446,8 +445,9 @@ void StackLayoutGenerator::stitchConditionalJumps(CFG::BasicBlock const& _block)
|
|||||||
|
|
||||||
Stack StackLayoutGenerator::combineStack(Stack const& _stack1, Stack const& _stack2)
|
Stack StackLayoutGenerator::combineStack(Stack const& _stack1, Stack const& _stack2)
|
||||||
{
|
{
|
||||||
// TODO: there is probably a better way than brute-forcing. This has n! complexity or worse, so
|
// TODO: it would be nicer to replace this by a constructive algorithm.
|
||||||
// we can't keep it like this.
|
// Currently it uses a reduced version of the Heap Algorithm to partly brute-force, which seems
|
||||||
|
// to work decently well.
|
||||||
|
|
||||||
Stack commonPrefix;
|
Stack commonPrefix;
|
||||||
for (auto&& [slot1, slot2]: ranges::zip_view(_stack1, _stack2))
|
for (auto&& [slot1, slot2]: ranges::zip_view(_stack1, _stack2))
|
||||||
@ -478,13 +478,6 @@ Stack StackLayoutGenerator::combineStack(Stack const& _stack1, Stack const& _sta
|
|||||||
|
|
||||||
std::map<size_t, Stack> sortedCandidates;
|
std::map<size_t, Stack> sortedCandidates;
|
||||||
|
|
||||||
// TODO: surprisingly this works for rather comparably large candidate size, but we should probably
|
|
||||||
// set up some limit, since this will quickly explode otherwise.
|
|
||||||
// Ideally we would then have a better fallback mechanism - although returning any naive union of both stacks
|
|
||||||
// like ``candidate`` itself may just be fine.
|
|
||||||
// if (candidate.size() > 8)
|
|
||||||
// return candidate;
|
|
||||||
|
|
||||||
auto evaluate = [&](Stack const& _candidate) -> size_t {
|
auto evaluate = [&](Stack const& _candidate) -> size_t {
|
||||||
size_t numOps = 0;
|
size_t numOps = 0;
|
||||||
Stack testStack = _candidate;
|
Stack testStack = _candidate;
|
||||||
@ -518,6 +511,9 @@ Stack StackLayoutGenerator::combineStack(Stack const& _stack1, Stack const& _sta
|
|||||||
std::swap(candidate[c[i]], candidate[i]);
|
std::swap(candidate[c[i]], candidate[i]);
|
||||||
sortedCandidates.insert(std::make_pair(evaluate(candidate), candidate));
|
sortedCandidates.insert(std::make_pair(evaluate(candidate), candidate));
|
||||||
++c[i];
|
++c[i];
|
||||||
|
// Note that for a proper implementation of the Heap algorithm this would need to revert back to ``i = 1.``
|
||||||
|
// However, the incorrect implementation produces decent result and the proper version would have n!
|
||||||
|
// complexity and is thereby not feasible.
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -530,11 +526,6 @@ Stack StackLayoutGenerator::combineStack(Stack const& _stack1, Stack const& _sta
|
|||||||
return commonPrefix + sortedCandidates.begin()->second;
|
return commonPrefix + sortedCandidates.begin()->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StackLayoutGenerator::fixStackTooDeep(CFG::BasicBlock const&)
|
|
||||||
{
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
Stack StackLayoutGenerator::compressStack(Stack _stack)
|
Stack StackLayoutGenerator::compressStack(Stack _stack)
|
||||||
{
|
{
|
||||||
optional<size_t> firstDupOffset;
|
optional<size_t> firstDupOffset;
|
||||||
|
@ -85,10 +85,6 @@ private:
|
|||||||
/// stack shuffling when starting from the returned layout.
|
/// stack shuffling when starting from the returned layout.
|
||||||
static Stack combineStack(Stack const& _stack1, Stack const& _stack2);
|
static Stack combineStack(Stack const& _stack1, Stack const& _stack2);
|
||||||
|
|
||||||
/// Tries to detect stack layout transitions that are bound to cause stack too deep errors and
|
|
||||||
/// attempts to reorganize the layout to avoid those cases.
|
|
||||||
void fixStackTooDeep(CFG::BasicBlock const& _entry);
|
|
||||||
|
|
||||||
/// @returns a copy of @a _stack stripped of all duplicates and slots that can be freely generated.
|
/// @returns a copy of @a _stack stripped of all duplicates and slots that can be freely generated.
|
||||||
/// Attempts to create a layout that requires a minimal amount of operations to reconstruct the original
|
/// Attempts to create a layout that requires a minimal amount of operations to reconstruct the original
|
||||||
/// stack @a _stack.
|
/// stack @a _stack.
|
||||||
|
Loading…
Reference in New Issue
Block a user