[llvm] [SandboxIR] Implement UnreachableInst (PR #101856)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 4 19:20:41 PDT 2024


================
@@ -747,6 +747,38 @@ void StoreInst::dump() const {
 }
 #endif // NDEBUG
 
+UnreachableInst *UnreachableInst::create(Instruction *InsertBefore,
+                                         Context &Ctx) {
+  auto &Builder = Ctx.getLLVMIRBuilder();
+  Builder.SetInsertPoint(cast<llvm::Instruction>(InsertBefore->Val));
----------------
vporpo wrote:

> and this change is only for the create functions with the InsertBefore param?

Yes. For some context: If `InsertBefore` is a sandboxir Instruction that contains more than one LLVM Instruction, then we should always get its topmost LLVM Instruction and insert before it.

> if it's okay with you, I can create a NFC pr for those changes.

Sure, go for it.

> So from now on, should I always do
> ```
>  auto &Builder = Ctx.getLLVMIRBuilder();
>  llvm::Instruction *LLVMBefore = InsertBefore->getTopmostLLVMInstruction();
>  Builder.SetInsertPoint(LLVMBefore);
>```
> for future implementations?

Yes, this pattern should exist already in a couple of places.

https://github.com/llvm/llvm-project/pull/101856


More information about the llvm-commits mailing list