[Mlir-commits] [mlir] add `arith::ConstantIntOp` constructor (PR #144638)
Skrai Pardus
llvmlistbot at llvm.org
Thu Jun 26 18:00:46 PDT 2025
https://github.com/ashjeong updated https://github.com/llvm/llvm-project/pull/144638
>From 429e108f8b67b86a74498f846c6a201d294fa87f Mon Sep 17 00:00:00 2001
From: ashjeong <ashjeong at umich.edu>
Date: Wed, 18 Jun 2025 14:06:18 +0900
Subject: [PATCH 1/2] add `ConstantIntOp` constructor for `APInt` types
---
mlir/include/mlir/Dialect/Arith/IR/Arith.h | 8 ++++++++
mlir/lib/Dialect/Arith/IR/ArithOps.cpp | 6 ++++++
2 files changed, 14 insertions(+)
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();
>From 0e39980fbb13f81e6329a4d82f6c615fc8f8ab66 Mon Sep 17 00:00:00 2001
From: ashjeong <ashjeong at umich.edu>
Date: Fri, 27 Jun 2025 10:00:11 +0900
Subject: [PATCH 2/2] fix
---
mlir/include/mlir/Dialect/Arith/IR/Arith.h | 4 ----
1 file changed, 4 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Arith/IR/Arith.h b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
index 4d88bbe507e2b..a4332a8395576 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/Arith.h
+++ b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
@@ -56,8 +56,6 @@ 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);
@@ -84,8 +82,6 @@ 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);
More information about the Mlir-commits
mailing list