[Mlir-commits] [mlir] Add inliner interface to the index dialect (PR #170459)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Dec 3 02:48:06 PST 2025
https://github.com/jack-slingsby created https://github.com/llvm/llvm-project/pull/170459
Add the inliner interface to the index dialect allowing the `inline` pass to inline all index operations.
As far as I can see other dialects (e.g. arith) don't have any tests for inlining. However, this change can be verified by running opt with `--pass-pipeline="builtin.module(inline)"` and this small example
```
func.func @main()->index{
%c0 = arith.constant 1 : i32
%0 = call @b(%c0) : (i32) -> index
return %0 : index
}
func.func @b(%arg0: i32) -> index {
%0 = index.castu %arg0 : i32 to index
return %0 : index
}
```
>From cac52d791b06c8dd27fb72ce6cd10204bfc649de Mon Sep 17 00:00:00 2001
From: Jack Slingsby <jack.slingsby at imgtec.com>
Date: Tue, 2 Dec 2025 18:05:35 +0000
Subject: [PATCH] Allow index dialect to be inlined
---
mlir/lib/Dialect/Index/IR/IndexDialect.cpp | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/mlir/lib/Dialect/Index/IR/IndexDialect.cpp b/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
index 183d0e33b2523..58589cc3fc5bf 100644
--- a/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
+++ b/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
@@ -8,6 +8,7 @@
#include "mlir/Dialect/Index/IR/IndexDialect.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
+#include "mlir/Transforms/InliningUtils.h"
using namespace mlir;
using namespace mlir::index;
@@ -15,10 +16,23 @@ using namespace mlir::index;
//===----------------------------------------------------------------------===//
// IndexDialect
//===----------------------------------------------------------------------===//
+namespace {
+/// This class defines the interface for handling inlining for index
+/// dialect operations.
+struct IndexInlinerInterface : public DialectInlinerInterface {
+ using DialectInlinerInterface::DialectInlinerInterface;
+
+ /// All index dialect ops can be inlined.
+ bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
+ return true;
+ }
+};
+}
void IndexDialect::initialize() {
registerAttributes();
registerOperations();
+ addInterfaces<IndexInlinerInterface>();
declarePromisedInterface<ConvertToLLVMPatternInterface, IndexDialect>();
}
More information about the Mlir-commits
mailing list