[llvm] 8b7cc93 - [JITLink] Add comments, rename types for visitExistingEdges utility.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 17 23:04:35 PDT 2021
Author: Lang Hames
Date: 2021-10-17T22:59:44-07:00
New Revision: 8b7cc93e9dc7e4e3b3a5cb014fa8d047c47f4818
URL: https://github.com/llvm/llvm-project/commit/8b7cc93e9dc7e4e3b3a5cb014fa8d047c47f4818
DIFF: https://github.com/llvm/llvm-project/commit/8b7cc93e9dc7e4e3b3a5cb014fa8d047c47f4818.diff
LOG: [JITLink] Add comments, rename types for visitExistingEdges utility.
The "Fixers" name was a hangover from an earlier draft of the patch. "Visitors"
fits the function name(s).
Added:
Modified:
llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
index dc8346556d488..a9e99547f005f 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h
@@ -1709,28 +1709,34 @@ Error markAllSymbolsLive(LinkGraph &G);
Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B,
const Edge &E);
-static inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
-
-template <typename FixerT, typename... FixerTs>
-static void visitEdge(LinkGraph &G, Block *B, Edge &E, FixerT &&Fixer,
- FixerTs &&...Fixers) {
- if (!Fixer.visitEdge(G, B, E))
- visitEdge(G, B, E, std::forward<FixerTs>(Fixers)...);
+/// Base case for edge-visitors where the visitor-list is empty.
+inline void visitEdge(LinkGraph &G, Block *B, Edge &E) {}
+
+/// Applies the first visitor in the list to the given edge. If the visitor's
+/// visitEdge method returns true then we return immediately, otherwise we
+/// apply the next visitor.
+template <typename VisitorT, typename... VisitorTs>
+void visitEdge(LinkGraph &G, Block *B, Edge &E, VisitorT &&V,
+ VisitorTs &&...Vs) {
+ if (!V.visitEdge(G, B, E))
+ visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
}
-/// Visits edges exist in graph by Fixers.
+/// For each edge in the given graph, apply a list of visitors to the edge,
+/// stopping when the first visitor's visitEdge method returns true.
///
-/// Note: that if a fixer fixes the edge successfully,
-/// the rest of the fixers will not visit this edge.
-template <typename... FixerTs>
-void visitExistingEdges(LinkGraph &G, FixerTs &&...Fixers) {
- // We're going to be adding new blocks, but we don't want to iterate over
- // the new ones, so build a worklist.
+/// Only visits edges that were in the graph at call time: if any visitor
+/// adds new edges those will not be visited. Visitors are not allowed to
+/// remove edges (though they can change their kind, target, and addend).
+template <typename... VisitorTs>
+void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs) {
+ // We may add new blocks during this process, but we don't want to iterate
+ // over them, so build a worklist.
std::vector<Block *> Worklist(G.blocks().begin(), G.blocks().end());
for (auto *B : Worklist)
for (auto &E : B->edges())
- visitEdge(G, B, E, std::forward<FixerTs>(Fixers)...);
+ visitEdge(G, B, E, std::forward<VisitorTs>(Vs)...);
}
/// Create a LinkGraph from the given object buffer.
More information about the llvm-commits
mailing list