[Mlir-commits] [mlir] add constant int op constructor (PR #144638)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jun 17 22:22:02 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-arith

Author: Skrai Pardus (ashjeong)

<details>
<summary>Changes</summary>

Added a `build()` constructor for `ConstantIntOp` that takes in an `APInt`.

---
Full diff: https://github.com/llvm/llvm-project/pull/144638.diff


2 Files Affected:

- (modified) mlir/include/mlir/Dialect/Arith/IR/Arith.h (+8) 
- (modified) mlir/lib/Dialect/Arith/IR/ArithOps.cpp (+6) 


``````````diff
diff --git a/mlir/include/mlir/Dialect/Arith/IR/Arith.h b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
index 77241319851e6..4d88bbe507e2b 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/Arith.h
+++ b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
@@ -56,6 +56,8 @@ class ConstantIntOp : public arith::ConstantOp {
   using arith::ConstantOp::ConstantOp;
   static ::mlir::TypeID resolveTypeID() { return TypeID::get<ConstantOp>(); }
 
+  using arith::ConstantOp::build;
+
   /// Build a constant int op that produces an integer of the specified width.
   static void build(OpBuilder &builder, OperationState &result, int64_t value,
                     unsigned width);
@@ -65,6 +67,10 @@ class ConstantIntOp : public arith::ConstantOp {
   static void build(OpBuilder &builder, OperationState &result, int64_t value,
                     Type type);
 
+  /// Build a constant int op that produces an integer from an APInt
+  static void build(OpBuilder &builder, OperationState &result, Type type,
+                    const APInt &value);
+
   inline int64_t value() {
     return cast<IntegerAttr>(arith::ConstantOp::getValue()).getInt();
   }
@@ -78,6 +84,8 @@ class ConstantFloatOp : public arith::ConstantOp {
   using arith::ConstantOp::ConstantOp;
   static ::mlir::TypeID resolveTypeID() { return TypeID::get<ConstantOp>(); }
 
+  using arith::ConstantOp::build;
+
   /// Build a constant float op that produces a float of the specified type.
   static void build(OpBuilder &builder, OperationState &result,
                     const APFloat &value, FloatType type);
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 9e53e195274aa..e36018654719d 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -264,6 +264,12 @@ void arith::ConstantIntOp::build(OpBuilder &builder, OperationState &result,
                            builder.getIntegerAttr(type, value));
 }
 
+void arith::ConstantIntOp::build(OpBuilder &builder, OperationState &result,
+                                 Type type, const APInt &value) {
+  arith::ConstantOp::build(builder, result, type,
+                           builder.getIntegerAttr(type, value));
+}
+
 bool arith::ConstantIntOp::classof(Operation *op) {
   if (auto constOp = dyn_cast_or_null<arith::ConstantOp>(op))
     return constOp.getType().isSignlessInteger();

``````````

</details>


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


More information about the Mlir-commits mailing list