[Mlir-commits] [mlir] [mlir][tblgen] add concrete create methods (PR #147168)

Maksim Levental llvmlistbot at llvm.org
Mon Jul 7 09:13:46 PDT 2025


makslevental wrote:

> > preserving compatibility with existing builders (important since they can be handwritten today).
> 
> I forgot the extra builder leading argument here. That means that @kuhar's idea is somehow on par with this I think.

If you look at before and after

```
arith::ConstantIntOp::create(builder, loc, ...
builder.create<arith::ConstantIntOp>(loc, ...
```

It's actually the exact same number of chars 😄 (it actually looks like a savings but it's not - it's just that `<>` are "wider" than `::` - I actually double checked using `strlen` lol).

> How do you write a manual builder now? Ideally we wouldn't add complexity in the body of the builder for users.

I don't think there's really any issue here - we won't have to change any [existing impls](https://github.com/llvm/llvm-project/blob/eb694b28461fdbd5e347fca59829e8a9ad021773/mlir/lib/Dialect/Arith/IR/ArithOps.cpp#L285-L289). Handling these "custom" builders just means adding

```diff
// Arith.h
static void build(OpBuilder &builder, OperationState &result, int64_t value);
+ static arith::ConstantIndexOp create(OpBuilder &builder, Location location, int64_t value);

// ArithOps.cpp
void arith::ConstantIndexOp::build(OpBuilder &builder, OperationState &result, int64_t value) {
  ...
}

+ arith::ConstantIndexOp::create(OpBuilder &builder, Location location, int64_t value) {
+   mlir::OperationState state(location, getOperationName());
+   build(builder, state, value);
+   auto result = llvm::dyn_cast<ConstantIndexOp>(builder.create(state));
+   assert(result && "builder didn't return the right type");
+   return result;
+ }
```

A little tedious but I don't think there are that many (and they're easily found like I pointed out).



https://github.com/llvm/llvm-project/pull/147168


More information about the Mlir-commits mailing list