[Mlir-commits] [mlir] Add inliner interface to the index dialect (PR #170459)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed Dec 3 02:49:04 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-index

Author: Jack (jack-slingsby)

<details>
<summary>Changes</summary>

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)"` on 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
}
```

---
Full diff: https://github.com/llvm/llvm-project/pull/170459.diff


1 Files Affected:

- (modified) mlir/lib/Dialect/Index/IR/IndexDialect.cpp (+14) 


``````````diff
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>();
 }
 

``````````

</details>


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


More information about the Mlir-commits mailing list