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

Mehdi Amini llvmlistbot at llvm.org
Wed Jul 9 03:47:55 PDT 2025


joker-eph wrote:

> are we OK to transition from builder.create(...) to Op::create(builder, ...) for the benefit of better IDE support?

For posterity I'll correct this, @Mogball identified on discourse that is more to it than better IDE support. Not having a template means that we can have user-defined implicit conversion as part of the call.
For example this does not compile today:

```
  auto acOp = builder.create<spirv::AccessChainOp>(loc, addrOp, {zeroOp, offsetOp});
```

It throw an error like:
```
mlir/include/mlir/IR/Builders.h:503:8: note: candidate template ignored: substitution failure [with OpTy = spirv::AccessChainOp]: deduced incomplete pack <mlir::spirv::AddressOfOp &, (no value)> for template parameter 'Args'
  502 |   template <typename OpTy, typename... Args>
      |                                        ~~~~
  503 |   OpTy create(Location location, Args &&...args) {
      |        ^
1 error generated.
```

We must be explicit and make the type perfectly match:

```
  auto acOp = builder.create<spirv::AccessChainOp>(loc, addrOp, llvm::ArrayRef({zeroOp, offsetOp}));
```

Whereas the new form will just work like this:

```
  auto acOp = spirv::AccessChainOp::create(builder, loc, addrOp, {zeroOp, offsetOp});
```


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


More information about the Mlir-commits mailing list