Skip to content

Commit b846638

Browse files
authored
[SanbdoxIR] Implement BBIterator::getNodeParent() (#109039)
This patch implements sandboxir::BasicBlock::iterator::getNodeParent() which returns the parent basic block of an iterator.
1 parent 9c9a627 commit b846638

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

llvm/include/llvm/SandboxIR/SandboxIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,8 @@ class BBIterator {
16931693
/// \Returns the SBInstruction that corresponds to this iterator, or null if
16941694
/// the instruction is not found in the IR-to-SandboxIR tables.
16951695
pointer get() const { return getInstr(It); }
1696+
/// \Returns the parent BB.
1697+
BasicBlock *getNodeParent() const;
16961698
};
16971699

16981700
/// Contains a list of sandboxir::Instruction's.

llvm/lib/SandboxIR/SandboxIR.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ BBIterator &BBIterator::operator--() {
306306
return *this;
307307
}
308308

309+
BasicBlock *BBIterator::getNodeParent() const {
310+
llvm::BasicBlock *Parent = const_cast<BBIterator *>(this)->It.getNodeParent();
311+
return cast<BasicBlock>(Ctx->getValue(Parent));
312+
}
313+
309314
const char *Instruction::getOpcodeName(Opcode Opc) {
310315
switch (Opc) {
311316
#define OP(OPC) \

llvm/unittests/SandboxIR/SandboxIRTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,12 +1575,16 @@ define void @foo(i32 %v1) {
15751575
for (sandboxir::Instruction &I : BB0) {
15761576
EXPECT_EQ(&I, Ctx.getValue(LLVMI));
15771577
LLVMI = LLVMI->getNextNode();
1578+
// Check getNodeParent().
1579+
EXPECT_EQ(I.getIterator().getNodeParent(), &BB0);
15781580
}
15791581
LLVMI = &*LLVMBB1->begin();
15801582
for (sandboxir::Instruction &I : BB1) {
15811583
EXPECT_EQ(&I, Ctx.getValue(LLVMI));
15821584
LLVMI = LLVMI->getNextNode();
15831585
}
1586+
// Check NodeParent() for BB::end().
1587+
EXPECT_EQ(BB0.end().getNodeParent(), &BB0);
15841588

15851589
// Check BB.getTerminator()
15861590
EXPECT_EQ(BB0.getTerminator(), Ctx.getValue(LLVMBB0->getTerminator()));

0 commit comments

Comments
 (0)