[llvm] [SandboxIR] Add more Instruction member functions (PR #98588)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 12 11:01:26 PDT 2024
================
@@ -262,6 +262,113 @@ const char *Instruction::getOpcodeName(Opcode Opc) {
llvm_unreachable("Unknown Opcode");
}
+llvm::Instruction *Instruction::getTopmostLLVMInstruction() const {
+ Instruction *Prev = getPrevNode();
+ if (Prev == nullptr) {
+ // If at top of the BB, return the first BB instruction.
+ return &*cast<llvm::BasicBlock>(getParent()->Val)->begin();
+ }
+ // Else get the Previous sandbox IR instruction's bottom IR instruction and
+ // return its successor.
+ llvm::Instruction *PrevBotI = cast<llvm::Instruction>(Prev->Val);
+ return PrevBotI->getNextNode();
+}
+
+BBIterator Instruction::getIterator() const {
+ auto *I = cast<llvm::Instruction>(Val);
+ return BasicBlock::iterator(I->getParent(), I->getIterator(), &Ctx);
+}
+
+Instruction *Instruction::getNextNode() const {
+ assert(getParent() != nullptr && "Detached!");
+ assert(getIterator() != getParent()->end() && "Already at end!");
+ auto *LLVMI = cast<llvm::Instruction>(Val);
+ assert(LLVMI->getParent() != nullptr && "LLVM IR instr is detached!");
+ auto *NextLLVMI = LLVMI->getNextNode();
----------------
vporpo wrote:
So here is how this works: `NextLLVMI` is an LLVM instruction that belongs to the next SandboxIR instruction, whether it's a single-Instruction or multi-Instruction. If it's a multi-Instruction, then `NextLLVMI` will be the topmost LLVM instruction. In either case `Ctxt.getValue(NextLLVMI)` returns the correct SandboxIR Instruction that maps to `NextLLVMI`. Does this make sense?
https://github.com/llvm/llvm-project/pull/98588
More information about the llvm-commits
mailing list