[llvm] [SandboxIR] Implement SelectInst (PR #99996)

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 22 17:57:22 PDT 2024


================
@@ -455,6 +455,50 @@ void Instruction::dump() const {
 }
 #endif // NDEBUG
 
+Value *SelectInst::create(Value *Cond, Value *True, Value *False,
+                          Instruction *InsertBefore, Context &Ctx,
+                          const Twine &Name) {
+  llvm::Instruction *BeforeIR = InsertBefore->getTopmostLLVMInstruction();
+  auto &Builder = Ctx.getLLVMIRBuilder();
+  Builder.SetInsertPoint(BeforeIR);
+  llvm::Value *NewV =
+      Builder.CreateSelect(Cond->Val, True->Val, False->Val, Name);
+  if (auto *NewSI = dyn_cast<llvm::SelectInst>(NewV))
+    return Ctx.createSelectInst(NewSI);
+  assert(isa<llvm::Constant>(NewV) && "Expected constant");
+  return Ctx.getOrCreateConstant(cast<llvm::Constant>(NewV));
----------------
tmsri wrote:

Maybe a createCommon here too like ReturnInst to capture the duplication?

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


More information about the llvm-commits mailing list