Skip to content

Commit 6fd678f

Browse files
committed
minor fixes
1 parent 1f01a5a commit 6fd678f

17 files changed

+50
-83
lines changed

libsolutil/DisjointSet.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525
using namespace solidity::util;
2626

27-
ContiguousDisjointSet::ContiguousDisjointSet(size_t const _numNodes):
27+
template<typename ValueType>
28+
ContiguousDisjointSet<ValueType>::ContiguousDisjointSet(size_t const _numNodes):
2829
m_parents(_numNodes),
2930
m_neighbors(_numNodes),
3031
m_sizes(_numNodes, static_cast<value_type>(1)),
@@ -35,9 +36,11 @@ ContiguousDisjointSet::ContiguousDisjointSet(size_t const _numNodes):
3536
std::iota(m_neighbors.begin(), m_neighbors.end(), 0);
3637
}
3738

38-
size_t ContiguousDisjointSet::numSets() const { return m_numSets; }
39+
template<typename ValueType>
40+
size_t ContiguousDisjointSet<ValueType>::numSets() const { return m_numSets; }
3941

40-
ContiguousDisjointSet::value_type ContiguousDisjointSet::find(value_type const _element) const
42+
template<typename ValueType>
43+
ContiguousDisjointSet<ValueType>::value_type ContiguousDisjointSet<ValueType>::find(value_type const _element) const
4144
{
4245
solAssert(_element < m_parents.size());
4346
// path halving
@@ -50,7 +53,8 @@ ContiguousDisjointSet::value_type ContiguousDisjointSet::find(value_type const _
5053
return rootElement;
5154
}
5255

53-
void ContiguousDisjointSet::merge(value_type const _x, value_type const _y, bool const _mergeBySize)
56+
template<typename ValueType>
57+
void ContiguousDisjointSet<ValueType>::merge(value_type const _x, value_type const _y, bool const _mergeBySize)
5458
{
5559
auto xRoot = find(_x);
5660
auto yRoot = find(_y);
@@ -69,17 +73,20 @@ void ContiguousDisjointSet::merge(value_type const _x, value_type const _y, bool
6973
--m_numSets;
7074
}
7175

72-
bool ContiguousDisjointSet::sameSubset(value_type const _x, value_type const _y) const
76+
template<typename ValueType>
77+
bool ContiguousDisjointSet<ValueType>::sameSubset(value_type const _x, value_type const _y) const
7378
{
7479
return find(_x) == find(_y);
7580
}
7681

77-
ContiguousDisjointSet::size_type ContiguousDisjointSet::sizeOfSubset(value_type const _x) const
82+
template<typename ValueType>
83+
ContiguousDisjointSet<ValueType>::size_type ContiguousDisjointSet<ValueType>::sizeOfSubset(value_type const _x) const
7884
{
7985
return m_sizes[find(_x)];
8086
}
8187

82-
std::set<ContiguousDisjointSet::value_type> ContiguousDisjointSet::subset(value_type const _x) const
88+
template<typename ValueType>
89+
std::set<typename ContiguousDisjointSet<ValueType>::value_type> ContiguousDisjointSet<ValueType>::subset(value_type const _x) const
8390
{
8491
solAssert(_x < m_parents.size());
8592
std::set<value_type> result{_x};
@@ -92,7 +99,8 @@ std::set<ContiguousDisjointSet::value_type> ContiguousDisjointSet::subset(value_
9299
return result;
93100
}
94101

95-
std::vector<std::set<ContiguousDisjointSet::value_type>> ContiguousDisjointSet::subsets() const
102+
template<typename ValueType>
103+
std::vector<std::set<typename ContiguousDisjointSet<ValueType>::value_type>> ContiguousDisjointSet<ValueType>::subsets() const
96104
{
97105
std::vector<std::set<value_type>> result;
98106
std::vector<std::uint8_t> visited(m_parents.size(), false);
@@ -107,3 +115,6 @@ std::vector<std::set<ContiguousDisjointSet::value_type>> ContiguousDisjointSet::
107115
}
108116
return result;
109117
}
118+
119+
template class solidity::util::ContiguousDisjointSet<std::uint64_t>;
120+
template class solidity::util::ContiguousDisjointSet<std::uint32_t>;

libsolutil/DisjointSet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ namespace solidity::util
3131
/// [1] https://en.wikipedia.org/wiki/Disjoint-set_data_structure
3232
/// [2] Tarjan, Robert E., and Jan Van Leeuwen. "Worst-case analysis of set union algorithms."
3333
/// Journal of the ACM (JACM) 31.2 (1984): 245-281.
34+
template<typename ValueType>
3435
class ContiguousDisjointSet
3536
{
3637
public:
3738
using size_type = size_t;
38-
using value_type = size_t;
39+
using value_type = ValueType;
3940

4041
/// Constructs a new disjoint set datastructure with `_numNodes` elements and each element in its own individual set
4142
explicit ContiguousDisjointSet(size_t _numNodes);

libyul/backends/evm/SSACFGEVMCodeTransform.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ SSACFGEVMCodeTransform::SSACFGEVMCodeTransform
143143
m_assembly(_assembly),
144144
m_builtinContext(_builtinContext),
145145
m_cfg(_cfg),
146-
m_liveness(_liveness),
147146
m_junkBlockFinder(_cfg, _liveness.topologicalSort()),
148147
m_stackLayout(StackLayoutGenerator::generate(_liveness, m_junkBlockFinder)),
149148
m_assemblyCallbacks{
@@ -193,7 +192,6 @@ void SSACFGEVMCodeTransform::operator()(SSACFG::BlockId const _block)
193192
yulAssert(m_cfg.block(_block).operations.size() == blockLayout.operationIn.size(), "We need as many stack layouts as we have operations");
194193

195194
// for each op with respective live-out, descend into op
196-
size_t operationIndex = 0;
197195
for (auto const& [operation, operationStackIn]: ranges::views::zip( m_cfg.block(_block).operations, blockLayout.operationIn))
198196
{
199197
bool const hasReturnLabel = std::holds_alternative<SSACFG::Call>(operation.kind)
@@ -268,7 +266,6 @@ void SSACFGEVMCodeTransform::operator()(SSACFG::BlockId const _block)
268266
static_cast<int>(m_stack.size()) == m_assembly.stackHeight(),
269267
fmt::format("symbolic stack size = {} =/= {} = assembly stack height", m_stack.size(), m_assembly.stackHeight())
270268
);
271-
++operationIndex;
272269
}
273270

274271
shuffleStack(m_stackLayout[_block].stackOut);

libyul/backends/evm/SSACFGEVMCodeTransform.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class SSACFGEVMCodeTransform
151151
BuiltinContext& m_builtinContext;
152152
// ControlFlow const& m_controlFlow;
153153
SSACFG const& m_cfg;
154-
LivenessAnalysis const& m_liveness;
155154
TerminationPathAnalysis m_junkBlockFinder;
156155
SSACFGStackLayout const m_stackLayout;
157156
std::vector<StackTooDeepError> m_stackErrors;

libyul/backends/evm/ssa/LivenessAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void LivenessAnalysis::runLoopTreeDfs(SSACFG::BlockId::ValueType const _loopHead
285285
// must be live out of header if live in of children
286286
m_liveOuts[_loopHeader].maxUnion(liveLoop);
287287
// for each blockId \in children(loopHeader)
288-
for (size_t blockIdValue = 0; blockIdValue < m_cfg.numBlocks(); ++blockIdValue)
288+
for (SSACFG::BlockId::ValueType blockIdValue = 0u; blockIdValue < m_cfg.numBlocks(); ++blockIdValue)
289289
if (m_loopNestingForest.loopParents()[blockIdValue] == _loopHeader)
290290
{
291291
// propagate loop liveness information down to the loop header's children

libyul/backends/evm/ssa/OperationForwardShuffler.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ class OperationForwardShuffler
4242
Stack& _stack,
4343
std::vector<Slot> const& _args,
4444
LivenessAnalysis::LivenessData const& _liveOut,
45-
bool _generateJunk,
46-
SSACFG const& _cfg
45+
bool _generateJunk
4746
)
4847
{
4948
yulAssert(ranges::none_of(_args, [](auto const& _slot) { return _slot.isJunk(); }));
5049

5150
constexpr std::size_t maxIterations = 1000;
5251
std::size_t i = 0;
53-
for (; i < maxIterations && shuffleStep(_stack, _args, _liveOut, _generateJunk, _cfg); ++i) {}
52+
for (; i < maxIterations && shuffleStep(_stack, _args, _liveOut, _generateJunk); ++i) {}
5453
yulAssert(i < maxIterations, fmt::format("Maximum iterations reached on {}", stackToString(_stack.data())));
5554
}
5655

@@ -122,7 +121,7 @@ class OperationForwardShuffler
122121

123122
struct Ops
124123
{
125-
Ops(Stack const& _stack, std::vector<Slot> const& _args, LivenessAnalysis::LivenessData const& _liveOut, SSACFG const& _cfg):
124+
Ops(Stack const& _stack, std::vector<Slot> const& _args, LivenessAnalysis::LivenessData const& _liveOut):
126125
stackStats(_stack, _args.size()),
127126
targetMinCounts(detail::histogram(_args)),
128127
stack(_stack),
@@ -304,11 +303,10 @@ class OperationForwardShuffler
304303
Stack& _stack,
305304
std::vector<Slot> const& _args,
306305
LivenessAnalysis::LivenessData const& _liveOut,
307-
bool const _generateJunk,
308-
SSACFG const& _cfg
306+
bool const _generateJunk
309307
)
310308
{
311-
Ops const ops(_stack, _args, _liveOut, _cfg);
309+
Ops const ops(_stack, _args, _liveOut);
312310

313311
// Check if we have the required top already
314312
if (ops.argsRegionIsCorrect())

libyul/backends/evm/ssa/SSACFG.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ class SSACFG
264264
m_literals.emplace_back(std::move(_debugData), std::move(_value));
265265
auto const value = m_literals.size() - 1;
266266
yulAssert(value <= std::numeric_limits<ValueId::ValueType>::max());
267-
auto const literalId = ValueId::makeLiteral(value);
267+
auto const literalId = ValueId::makeLiteral(static_cast<ValueId::ValueType>(value));
268268
m_literalMapping.emplace(_value, literalId);
269269
return literalId;
270270
}

libyul/backends/evm/ssa/SSACFGBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
namespace solidity::yul
3838
{
39-
class AsmAnalysisInfo;
39+
struct AsmAnalysisInfo;
4040
namespace ssa
4141
{
4242

libyul/backends/evm/ssa/SSACFGLoopNestingForest.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include <libyul/backends/evm/ssa/SSACFGLoopNestingForest.h>
2020

21+
#include <range/v3/algorithm/reverse.hpp>
22+
2123
using namespace solidity::yul::ssa;
2224

2325
SSACFGLoopNestingForest::SSACFGLoopNestingForest(ForwardSSACFGTopologicalSort const& _sort):
@@ -28,7 +30,7 @@ SSACFGLoopNestingForest::SSACFGLoopNestingForest(ForwardSSACFGTopologicalSort co
2830
{
2931
auto dfsOrder = m_sort.preOrder();
3032
// we go from innermost to outermost
31-
std::reverse(dfsOrder.begin(), dfsOrder.end());
33+
ranges::reverse(dfsOrder);
3234

3335
for (auto const& blockId: dfsOrder)
3436
findLoop(blockId);

libyul/backends/evm/ssa/SSACFGLoopNestingForest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class SSACFGLoopNestingForest
5454
ForwardSSACFGTopologicalSort const& m_sort;
5555
SSACFG const& m_cfg;
5656

57-
util::ContiguousDisjointSet m_vertexPartition;
57+
util::ContiguousDisjointSet<BlockIdValue> m_vertexPartition;
5858
std::vector<BlockIdValue> m_loopParents;
5959
std::set<BlockIdValue> m_loopNodes;
6060
std::set<BlockIdValue> m_loopRootNodes;

0 commit comments

Comments
 (0)