Skip to content

add arith::ConstantIntOp constructor #144638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ashjeong
Copy link

@ashjeong ashjeong commented Jun 18, 2025

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

To be merged after #144636

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jun 18, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-arith

Author: Skrai Pardus (ashjeong)

Changes

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 --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();

@ashjeong ashjeong changed the title add constant int op constructor add arith::ConstantIntOp constructor Jun 18, 2025
@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? The base constructors may be intentionally hidden.

Comment on lines +71 to +70
static void build(OpBuilder &builder, OperationState &result, Type type,
const APInt &value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the order between type and value in this constructor with respect to other constructors is highly confusing. Please revise.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I requested in a previous PR to change the order of type/value for the other constructors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 87 to 88
using arith::ConstantOp::build;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't make changes that are irrelevant to the PR description. It says ConstantIntOp, it shouldn't touch ConstantFloatOp or say otherwise.

@ashjeong ashjeong force-pushed the feat/add-constant-int-constructor branch from 0298d1b to a40e28d Compare June 18, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants