[llvm] [SandboxIR] Implement CmpInst, FCmpInst, and ICmpInst (PR #106301)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 27 18:35:30 PDT 2024


================
@@ -2974,6 +2989,187 @@ class PHINode final : public SingleLLVMInstructionImpl<llvm::PHINode> {
   //                         uint32_t ToIdx = 0)
 };
 
+// Wraps a static function that takes a single Predicate parameter
+// LLVMValType should be the type of the wrapped class
+#define WRAP_STATIC_PREDICATE(FunctionName)                                    \
+  static auto FunctionName(Predicate P) { return LLVMValType::FunctionName(P); }
+// Wraps a member function that takes no parameters
+// LLVMValType should be the type of the wrapped class
+#define WRAP_MEMBER(FunctionName)                                              \
+  auto FunctionName() { return cast<LLVMValType>(Val)->FunctionName(); }
+// Wraps both--a common idiom in the CmpInst classes
+#define WRAP_BOTH(FunctionName)                                                \
+  WRAP_STATIC_PREDICATE(FunctionName)                                          \
+  WRAP_MEMBER(FunctionName)
+
+class CmpInst : public Instruction {
+protected:
+  using LLVMValType = llvm::CmpInst;
+  /// Use Context::createCmpInst(). Don't call the
+  /// constructor directly.
+  CmpInst(llvm::CmpInst *CI, Context &Ctx, ClassID Id = ClassID::Cmp,
+          Opcode Opc = Opcode::Cmp)
+      : Instruction(Id, Opc, CI, Ctx) {}
+  friend Context; // for CmpInst()
+  Use getOperandUseInternal(unsigned OpIdx, bool Verify) const final {
+    return getOperandUseDefault(OpIdx, Verify);
+  }
+  SmallVector<llvm::Instruction *, 1> getLLVMInstrs() const final {
+    return {cast<llvm::Instruction>(Val)};
+  }
+  static Value *createCommon(Value *Cond, Value *True, Value *False,
+                             const Twine &Name, IRBuilder<> &Builder,
+                             Context &Ctx);
+
+public:
+  using Predicate = llvm::CmpInst::Predicate;
+  using PredicateField = llvm::CmpInst::PredicateField;
+  using OtherOps = llvm::Instruction::OtherOps;
+
+  unsigned getUseOperandNo(const Use &Use) const final {
+    return getUseOperandNoDefault(Use);
+  }
+  unsigned getNumOfIRInstrs() const final { return 1u; }
+  static CmpInst *create(OtherOps Op, Predicate Pred, Value *S1, Value *S2,
+                         const Twine &Name = "",
+                         InsertPosition InsertBefore = nullptr);
+  static CmpInst *CreateWithCopiedFlags(OtherOps Op, Predicate Pred, Value *S1,
----------------
vporpo wrote:

Let's stick with the coding style and use a small case `c` `createWithCopiedFlags`

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


More information about the llvm-commits mailing list