Skip to content

[LLVM UPDATE] Refactor MLIR operations to use static creation methods#2416

Merged
mehrdad2m merged 35 commits into
update-llvm-Q1-2026from
refactor-op-create-method
Feb 3, 2026
Merged

[LLVM UPDATE] Refactor MLIR operations to use static creation methods#2416
mehrdad2m merged 35 commits into
update-llvm-Q1-2026from
refactor-op-create-method

Conversation

@mehrdad2m

@mehrdad2m mehrdad2m commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Context:
llvm/llvm-project#147168 in LLVM adds concrete static methods for operation creation that are attached to the operation instead of the builder.
Recently the old rewriter.create<Op>() method is deprecated.

This PR updates operations to utilize static creation methods instead of the deprecated version.

Description of the Change:

  • Replaced rewriter/builder.create<Op>() with Op::create(rewriter/builder, ...) for operations.
  • Updated the "how to write a pass" tutorial to use the updated creation method.
  • Changed integer literals in InsertValueOp::create calls to SmallVector<int64_t> because MLIR introduced DenseI64ArrayAttr overloads, creating ambiguity between ArrayRef<int64_t> and DenseI64ArrayAttr when passing integer literals.

Benefits:
Better autocomplete

Possible Drawbacks:

Related GitHub Issues:
[sc-107551]

@mehrdad2m mehrdad2m marked this pull request as draft January 19, 2026 22:16
@mehrdad2m mehrdad2m marked this pull request as ready for review January 20, 2026 19:41
@mehrdad2m mehrdad2m requested a review from a team January 28, 2026 23:06
@mehrdad2m

Copy link
Copy Markdown
Contributor Author

Note that the CI failures would be resolved after #2445 and #2444 are merged

@mehrdad2m mehrdad2m changed the title Refactor MLIR operations to use static creation methods [LLVM UPDATE] Refactor MLIR operations to use static creation methods Jan 28, 2026

@paul0403 paul0403 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I like how this 1700 line PR is the easiest to review lol

@rniczh rniczh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

💯

mehrdad2m and others added 4 commits February 2, 2026 20:37
**Context:**
Summary
MLIR has updated [Value
type](llvm/llvm-project@31536e6#diff-acfa9a5ea4439eae3f3e5a57ccbb8e72944842f6ae7816624c1d75e2908f3e62)
to be generic in the type of the value it holds and now the generated
dialect bindings emit `Value[Type] / OpResult[Type]` annotations.

This would crash Catalyst when importing the generated python files
because JAX's LLVM version is older and doesn’t expose
`__class_getitem__` which causes an error complaining about indexing.

**Description of the Change:**
patched
`mlir/llvm-project/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp` to
postpone evaluation of type hints to avoid the crash while import.
Thanks @rniczh for the idea!

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
@codecov

codecov Bot commented Feb 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.31%. Comparing base (f9d185c) to head (d7e07ff).

Additional details and impacted files
@@                   Coverage Diff                   @@
##           update-llvm-Q1-2026    #2416      +/-   ##
=======================================================
+ Coverage                96.63%   97.31%   +0.67%     
=======================================================
  Files                       36      107      +71     
  Lines                     4071    12978    +8907     
  Branches                     0     1074    +1074     
=======================================================
+ Hits                      3934    12629    +8695     
- Misses                     137      288     +151     
- Partials                     0       61      +61     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mehrdad2m mehrdad2m merged commit ac02a9b into update-llvm-Q1-2026 Feb 3, 2026
34 checks passed
@mehrdad2m mehrdad2m deleted the refactor-op-create-method branch February 3, 2026 15:26
mehrdad2m added a commit that referenced this pull request Feb 4, 2026
**Context:**
Updating LLVM related dependencies for Q1 2025. After the update we will
point the following versions:

```
jax=0.7.1 (no change)
stablehlo=v1.13.7 -> llvm=8f264586d7521b0e305ca7bb78825aa3382ffef7 
enzyme=v0.0.238
```

**Description of the Change:**

- Replaced rewriter/builder.create<Op>() with
Op::create(rewriter/builder, ...) for operations.
(#2416)

- Updated the "how to write a pass" tutorial to use the updated creation
method. (#2416)

- Changed integer literals in `InsertValueOp::create` calls to
`SmallVector<int64_t>` because MLIR introduced `DenseI64ArrayAttr`
overloads, creating ambiguity between `ArrayRef<int64_t>` and
`DenseI64ArrayAttr` when passing integer literals.
(#2416)

- Patched
`mlir/llvm-project/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp` to
avoid the crash when importing the generated python files because JAX's
LLVM version is older and doesn’t expose `__class_getitem__` which
causes an error complaining about indexing. see
#2444

- Remove the xfail for a vmap+grad test that is passing now with the
update and move another two xfails inside the tests since they are now
segfaulting at runtime. see
#2445

- Changed `std::nullopt` to `{}` for `ValueRange` default arguments
because MLIR removed the `ArrayRef(std::nullopt_t)` constructor,
requiring empty initializer lists instead.
(6b4f790)

- Added `exactNone` argument to `Arith_DivSIOp` pattern because the
operation now requires an explicit `fastmath` attribute parameter in
tablegen.
(279cefc)

- Fixed `BufferizableOpInterfaceImpl.cpp`: Added explicit cast from
`TensorType` to `TensorLikeType` and `BaseMemRefType` to
`BufferLikeType` because MLIR's bufferization framework now uses the
`TensorLikeType` and `BufferLikeType` interface to support generic
tensor/buffer types.
(35b5690)

- Fixed `StringSwitch::Cases` usage in to use `std::initializer_list`
syntax because LLVM deprecated the old `Cases` method that took multiple
string arguments in favor of a single `std::initializer_list` parameter.
(48f97d8)

- Fixed `inferCanonicalRankReducedResultType` call from 5 arguments to 3
arguments
(87cf94b)

- Added `StablehloBroadcastLowering` to `CMakeLists.txt` because
StableHLO split broadcast lowering functionality into a separate library
(fad13a8)

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-107552] [sc-107551]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants