[llvm] [SandboxIR] Implement the InsertElementInst class (PR #102404)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 9 09:26:01 PDT 2024
================
@@ -753,6 +755,48 @@ class SelectInst : public Instruction {
#endif
};
+class InsertElementInst final : public Instruction {
+ /// Use Context::createInsertElementInst(). Don't call
+ /// the constructor directly.
+ InsertElementInst(llvm::Instruction *I, Context &Ctx)
+ : Instruction(ClassID::InsertElement, Opcode::InsertElement, I, Ctx) {}
+ InsertElementInst(ClassID SubclassID, llvm::Instruction *I, Context &Ctx)
+ : Instruction(SubclassID, Opcode::InsertElement, I, Ctx) {}
+ friend class Context; // For accessing the constructor in
+ // create*()
+ Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
+ return getOperandUseDefault(OpIdx, Verify);
+ }
+ SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
+ return {cast<llvm::Instruction>(Val)};
+ }
+
+public:
+ static Value *create(Value *Vec, Value *NewElt, Value *Idx,
+ Instruction *InsertBefore, Context &Ctx,
+ const Twine &Name = "");
+ static Value *create(Value *Vec, Value *NewElt, Value *Idx,
+ BasicBlock *InsertAtEnd, Context &Ctx,
+ const Twine &Name = "");
+ static bool classof(const Value *From) {
----------------
vporpo wrote:
Could you also add a test for this? Something like:
```
EXPECT_EQ(sandboxir::InsertElementInst::isValidOperands(V1, V2, V3), llvm::InsertElementInst::isValidOperands(Ctx.getValue(V1), Ctx.getValue(V2), Ctx.getValue(V3)));
```
https://github.com/llvm/llvm-project/pull/102404
More information about the llvm-commits
mailing list