[Mlir-commits] [mlir] add `arith::ConstantIntOp` constructor (PR #144638)

Skrai Pardus llvmlistbot at llvm.org
Wed Jun 18 00:23:38 PDT 2025


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

>From a40e28dff1595c9d7739610f04a6864fcb15ddc9 Mon Sep 17 00:00:00 2001
From: ashjeong <ashjeong at umich.edu>
Date: Wed, 18 Jun 2025 14:06:18 +0900
Subject: [PATCH] add `ConstantIntOp` constructor for `APInt` types

---
 mlir/include/mlir/Dialect/Arith/IR/Arith.h | 4 ++++
 mlir/lib/Dialect/Arith/IR/ArithOps.cpp     | 6 ++++++
 2 files changed, 10 insertions(+)

diff --git a/mlir/include/mlir/Dialect/Arith/IR/Arith.h b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
index 77241319851e6..a4332a8395576 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/Arith.h
+++ b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
@@ -65,6 +65,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();
   }
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();



More information about the Mlir-commits mailing list