@@ -1709,28 +1709,34 @@ Error markAllSymbolsLive(LinkGraph &G);
1709
1709
Error makeTargetOutOfRangeError (const LinkGraph &G, const Block &B,
1710
1710
const Edge &E);
1711
1711
1712
- static inline void visitEdge (LinkGraph &G, Block *B, Edge &E) {}
1713
-
1714
- template <typename FixerT, typename ... FixerTs>
1715
- static void visitEdge (LinkGraph &G, Block *B, Edge &E, FixerT &&Fixer,
1716
- FixerTs &&...Fixers) {
1717
- if (!Fixer.visitEdge (G, B, E))
1718
- visitEdge (G, B, E, std::forward<FixerTs>(Fixers)...);
1712
+ // / Base case for edge-visitors where the visitor-list is empty.
1713
+ inline void visitEdge (LinkGraph &G, Block *B, Edge &E) {}
1714
+
1715
+ // / Applies the first visitor in the list to the given edge. If the visitor's
1716
+ // / visitEdge method returns true then we return immediately, otherwise we
1717
+ // / apply the next visitor.
1718
+ template <typename VisitorT, typename ... VisitorTs>
1719
+ void visitEdge (LinkGraph &G, Block *B, Edge &E, VisitorT &&V,
1720
+ VisitorTs &&...Vs) {
1721
+ if (!V.visitEdge (G, B, E))
1722
+ visitEdge (G, B, E, std::forward<VisitorTs>(Vs)...);
1719
1723
}
1720
1724
1721
- // / Visits edges exist in graph by Fixers.
1725
+ // / For each edge in the given graph, apply a list of visitors to the edge,
1726
+ // / stopping when the first visitor's visitEdge method returns true.
1722
1727
// /
1723
- // / Note: that if a fixer fixes the edge successfully,
1724
- // / the rest of the fixers will not visit this edge.
1725
- template <typename ... FixerTs>
1726
- void visitExistingEdges (LinkGraph &G, FixerTs &&...Fixers) {
1727
- // We're going to be adding new blocks, but we don't want to iterate over
1728
- // the new ones, so build a worklist.
1728
+ // / Only visits edges that were in the graph at call time: if any visitor
1729
+ // / adds new edges those will not be visited. Visitors are not allowed to
1730
+ // / remove edges (though they can change their kind, target, and addend).
1731
+ template <typename ... VisitorTs>
1732
+ void visitExistingEdges (LinkGraph &G, VisitorTs &&...Vs) {
1733
+ // We may add new blocks during this process, but we don't want to iterate
1734
+ // over them, so build a worklist.
1729
1735
std::vector<Block *> Worklist (G.blocks ().begin (), G.blocks ().end ());
1730
1736
1731
1737
for (auto *B : Worklist)
1732
1738
for (auto &E : B->edges ())
1733
- visitEdge (G, B, E, std::forward<FixerTs>(Fixers )...);
1739
+ visitEdge (G, B, E, std::forward<VisitorTs>(Vs )...);
1734
1740
}
1735
1741
1736
1742
// / Create a LinkGraph from the given object buffer.
0 commit comments