Skip to content

Commit 29e6332

Browse files
committed
[JITLink] Add Block::edges_at(Edge::OffsetT): iterate over edges at offset.
Block::edges_at is a convenience method for iterating over edges at a given offset within a jitlink::Block. This method will be used in an upcoming patch for compact unwind info support.
1 parent d248412 commit 29e6332

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Diff for: llvm/include/llvm/ExecutionEngine/JITLink/JITLink.h

+12
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,18 @@ class Block : public Addressable {
336336
return make_range(Edges.begin(), Edges.end());
337337
}
338338

339+
/// Returns an iterator over all edges at the given offset within the block.
340+
auto edges_at(Edge::OffsetT O) {
341+
return make_filter_range(edges(),
342+
[O](const Edge &E) { return E.getOffset() == O; });
343+
}
344+
345+
/// Returns an iterator over all edges at the given offset within the block.
346+
auto edges_at(Edge::OffsetT O) const {
347+
return make_filter_range(edges(),
348+
[O](const Edge &E) { return E.getOffset() == O; });
349+
}
350+
339351
/// Return the size of the edges list.
340352
size_t edges_size() const { return Edges.size(); }
341353

Diff for: llvm/unittests/ExecutionEngine/JITLink/LinkGraphTests.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@ TEST(LinkGraphTest, BlockAndSymbolIteration) {
127127
EXPECT_TRUE(llvm::count(G.defined_symbols(), &S4));
128128
}
129129

130+
TEST(LinkGraphTest, EdgeIteration) {
131+
// Check that we can iterate over blocks within Sections and across sections.
132+
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),
133+
Triple("x86_64-apple-darwin"), SubtargetFeatures(),
134+
getGenericEdgeKindName);
135+
auto &Sec1 =
136+
G.createSection("__data.1", orc::MemProt::Read | orc::MemProt::Write);
137+
auto &B =
138+
G.createContentBlock(Sec1, BlockContent, orc::ExecutorAddr(0x1000), 8, 0);
139+
auto &S = G.addExternalSymbol("S1", 0, false);
140+
141+
constexpr size_t NumEdges = 6;
142+
Edge::OffsetT Offsets[NumEdges] = {0, 1, 2, 2, 3, 7};
143+
144+
for (auto O : Offsets)
145+
B.addEdge(Edge::KeepAlive, O, S, 0);
146+
147+
EXPECT_EQ(llvm::range_size(B.edges()), NumEdges);
148+
EXPECT_EQ(llvm::range_size(B.edges_at(0)), 1U);
149+
EXPECT_EQ(llvm::range_size(B.edges_at(2)), 2U);
150+
EXPECT_EQ(llvm::range_size(B.edges_at(4)), 0U);
151+
152+
{
153+
// Check that offsets and iteration order are as expected.
154+
size_t Idx = 0;
155+
for (auto &E : B.edges())
156+
EXPECT_EQ(E.getOffset(), Offsets[Idx++]);
157+
}
158+
}
159+
130160
TEST(LinkGraphTest, ContentAccessAndUpdate) {
131161
// Check that we can make a defined symbol external.
132162
LinkGraph G("foo", std::make_shared<orc::SymbolStringPool>(),

0 commit comments

Comments
 (0)