[Mlir-commits] [mlir] 5ed852f - [mlir][arith] Add `arith::ConstantIntOp` constructor (#144638)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jul 1 14:50:42 PDT 2025
Author: Skrai Pardus
Date: 2025-07-01T23:50:39+02:00
New Revision: 5ed852f7f72855710eeff53179e6a6f2271a3c2a
URL: https://github.com/llvm/llvm-project/commit/5ed852f7f72855710eeff53179e6a6f2271a3c2a
DIFF: https://github.com/llvm/llvm-project/commit/5ed852f7f72855710eeff53179e6a6f2271a3c2a.diff
LOG: [mlir][arith] Add `arith::ConstantIntOp` constructor (#144638)
This PR adds a `build()` constructor for `ConstantIntOp` that takes in
an `APInt`.
Creating an `arith` constant value with an `APInt` currently requires a
structure like the following:
```c
b.create<arith::ConstantOp>(IntegerAttr::get(apintValue, 5));
```
In comparison, the`ConstantFloatOp` already has an `APFloat` constructor
which allows for the following:
```c
b.create<arith::ConstantFloatOp>(floatType, apfloatValue);
```
Thus, intuitively, it makes sense that a similar `ConstantIntOp`
constructor is made for `APInts` like so:
```c
b.create<arith::ConstantIntOp>(intType, apintValue);
```
Depends on https://github.com/llvm/llvm-project/pull/144636
Added:
Modified:
mlir/include/mlir/Dialect/Arith/IR/Arith.h
mlir/lib/Dialect/Arith/IR/ArithOps.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Arith/IR/Arith.h b/mlir/include/mlir/Dialect/Arith/IR/Arith.h
index c2de3c9021b0b..7c50c2036ffdc 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, Type type,
int64_t value);
+ /// 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 ec96a35ae82e7..ae2a00cedf6f5 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -262,6 +262,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