[Mlir-commits] [mlir] [mlir][tblgen] add concrete create methods (PR #147168)
Maksim Levental
llvmlistbot at llvm.org
Mon Jul 7 18:06:23 PDT 2025
makslevental wrote:
@joker-eph
> But thinking a bit more: can't you automatically generate from TablGen the diff you just showed from the custom builder declaration in ODS (let builders =) and forward to the manual implementation like this diff?
Seems like straightforward isn't it?
This works: https://github.com/llvm/llvm-project/actions/runs/16131176576/job/45518805426?pr=147311
All it took was just adding `genInlineCreateBody(arguments);` [here](https://github.com/llvm/llvm-project/blob/949f3a13eb07f55418bebe6697105179d74988d3/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp#L3118).
In getting that to work I realized we need to also support [`ImplicitLocOpBuilder::create`](https://github.com/llvm/llvm-project/blob/f11925e0f0c49737509216403136204624dc2a29/mlir/include/mlir/IR/ImplicitLocOpBuilder.h#L66). This is straightforward - just also emit
```c++
arith::ConstantIndexOp
arith::ConstantIndexOp::create(ImplicitLocOpBuilder &builder, int64_t value) {
return create(builder, builder.getLoc(), value);
}
```
The only issue arises from now needing `#include "mlir/IR/ImplicitLocOpBuilder.h"` basically everywhere a generated `.cpp.inc` is included (see [this commit](https://github.com/llvm/llvm-project/pull/147311/commits/d0ddc3c6fbaa57667325c9ba9fd19428916292b4)). An alternative solution, which would incur no such lines changed and would also naturally work downstream is merging `mlir/IR/ImplicitLocOpBuilder.h` and `mlir/IR/Builders.h`.
https://github.com/llvm/llvm-project/pull/147168
More information about the Mlir-commits
mailing list