[Mlir-commits] [mlir] Make the index dialect inlineable. (PR #155290)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Aug 25 13:49:07 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Stephen Neuendorffer (stephenneuendorffer)

<details>
<summary>Changes</summary>

This seems like a simple oversight?

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


2 Files Affected:

- (modified) mlir/lib/Dialect/Index/IR/IndexDialect.cpp (+15) 
- (added) mlir/test/Dialect/Index/inlining.mlir (+18) 


``````````diff
diff --git a/mlir/lib/Dialect/Index/IR/IndexDialect.cpp b/mlir/lib/Dialect/Index/IR/IndexDialect.cpp
index 183d0e33b2523..aaf6e76e4f0b3 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;
@@ -16,9 +17,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 arithmetic dialect ops can be inlined.
+  bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
+    return true;
+  }
+};
+} // namespace
+
 void IndexDialect::initialize() {
   registerAttributes();
   registerOperations();
+  addInterfaces<IndexInlinerInterface>();
   declarePromisedInterface<ConvertToLLVMPatternInterface, IndexDialect>();
 }
 
diff --git a/mlir/test/Dialect/Index/inlining.mlir b/mlir/test/Dialect/Index/inlining.mlir
new file mode 100644
index 0000000000000..eb7a87af301d2
--- /dev/null
+++ b/mlir/test/Dialect/Index/inlining.mlir
@@ -0,0 +1,18 @@
+// RUN: mlir-opt %s -inline -split-input-file | FileCheck %s
+
+// -----
+// Indexes should be inlineable
+func.func @func(%arg0 : index) -> index {
+  %1 = index.constant 2
+  return %1 : index
+}
+
+// CHECK-LABEL: @inline_interface
+func.func @inline_interface(%arg0 : index) -> index {
+  // CHECK: index.constant
+  // CHECK-NOT: call
+  %res = call @func(%arg0) : (index) -> (index)
+  // CHECK: return %[[R]]
+  return %res : index
+}
+

``````````

</details>


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


More information about the Mlir-commits mailing list