Skip to content

Commit 5ed852f

Browse files
authored
[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 #144636
1 parent 863e17a commit 5ed852f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

mlir/include/mlir/Dialect/Arith/IR/Arith.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class ConstantIntOp : public arith::ConstantOp {
6565
static void build(OpBuilder &builder, OperationState &result, Type type,
6666
int64_t value);
6767

68+
/// Build a constant int op that produces an integer from an APInt
69+
static void build(OpBuilder &builder, OperationState &result, Type type,
70+
const APInt &value);
71+
6872
inline int64_t value() {
6973
return cast<IntegerAttr>(arith::ConstantOp::getValue()).getInt();
7074
}

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ void arith::ConstantIntOp::build(OpBuilder &builder, OperationState &result,
262262
builder.getIntegerAttr(type, value));
263263
}
264264

265+
void arith::ConstantIntOp::build(OpBuilder &builder, OperationState &result,
266+
Type type, const APInt &value) {
267+
arith::ConstantOp::build(builder, result, type,
268+
builder.getIntegerAttr(type, value));
269+
}
270+
265271
bool arith::ConstantIntOp::classof(Operation *op) {
266272
if (auto constOp = dyn_cast_or_null<arith::ConstantOp>(op))
267273
return constOp.getType().isSignlessInteger();

0 commit comments

Comments
 (0)