[llvm] b846638 - [SanbdoxIR] Implement BBIterator::getNodeParent() (#109039)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 17 15:20:13 PDT 2024
Author: vporpo
Date: 2024-09-17T15:20:09-07:00
New Revision: b84663854859903c7b457b084d255a77405bd7a2
URL: https://github.com/llvm/llvm-project/commit/b84663854859903c7b457b084d255a77405bd7a2
DIFF: https://github.com/llvm/llvm-project/commit/b84663854859903c7b457b084d255a77405bd7a2.diff
LOG: [SanbdoxIR] Implement BBIterator::getNodeParent() (#109039)
This patch implements sandboxir::BasicBlock::iterator::getNodeParent()
which returns the parent basic block of an iterator.
Added:
Modified:
llvm/include/llvm/SandboxIR/SandboxIR.h
llvm/lib/SandboxIR/SandboxIR.cpp
llvm/unittests/SandboxIR/SandboxIRTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index b276c06033596d..c01516aa9d31ac 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -1693,6 +1693,8 @@ class BBIterator {
/// \Returns the SBInstruction that corresponds to this iterator, or null if
/// the instruction is not found in the IR-to-SandboxIR tables.
pointer get() const { return getInstr(It); }
+ /// \Returns the parent BB.
+ BasicBlock *getNodeParent() const;
};
/// Contains a list of sandboxir::Instruction's.
diff --git a/llvm/lib/SandboxIR/SandboxIR.cpp b/llvm/lib/SandboxIR/SandboxIR.cpp
index d047a53b4752ee..f8faef5a386a93 100644
--- a/llvm/lib/SandboxIR/SandboxIR.cpp
+++ b/llvm/lib/SandboxIR/SandboxIR.cpp
@@ -306,6 +306,11 @@ BBIterator &BBIterator::operator--() {
return *this;
}
+BasicBlock *BBIterator::getNodeParent() const {
+ llvm::BasicBlock *Parent = const_cast<BBIterator *>(this)->It.getNodeParent();
+ return cast<BasicBlock>(Ctx->getValue(Parent));
+}
+
const char *Instruction::getOpcodeName(Opcode Opc) {
switch (Opc) {
#define OP(OPC) \
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index b998091f6d7a97..8807716a52738f 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -1575,12 +1575,16 @@ define void @foo(i32 %v1) {
for (sandboxir::Instruction &I : BB0) {
EXPECT_EQ(&I, Ctx.getValue(LLVMI));
LLVMI = LLVMI->getNextNode();
+ // Check getNodeParent().
+ EXPECT_EQ(I.getIterator().getNodeParent(), &BB0);
}
LLVMI = &*LLVMBB1->begin();
for (sandboxir::Instruction &I : BB1) {
EXPECT_EQ(&I, Ctx.getValue(LLVMI));
LLVMI = LLVMI->getNextNode();
}
+ // Check NodeParent() for BB::end().
+ EXPECT_EQ(BB0.end().getNodeParent(), &BB0);
// Check BB.getTerminator()
EXPECT_EQ(BB0.getTerminator(), Ctx.getValue(LLVMBB0->getTerminator()));
More information about the llvm-commits
mailing list