[Mlir-commits] [mlir] Make the index dialect inlineable. (PR #155290)
Stephen Neuendorffer
llvmlistbot at llvm.org
Mon Aug 25 13:48:17 PDT 2025
https://github.com/stephenneuendorffer created https://github.com/llvm/llvm-project/pull/155290
This seems like a simple oversight?
>From 623aea05d8b229626189bb755f4ed0ab57a264f4 Mon Sep 17 00:00:00 2001
From: Stephen Neuendorffer <stephen.neuendorffer at amd.com>
Date: Mon, 25 Aug 2025 20:37:10 +0000
Subject: [PATCH] Make the index dialect inlineable.
This seems like a simple oversight?
---
mlir/lib/Dialect/Index/IR/IndexDialect.cpp | 15 +++++++++++++++
mlir/test/Dialect/Index/inlining.mlir | 18 ++++++++++++++++++
2 files changed, 33 insertions(+)
create mode 100644 mlir/test/Dialect/Index/inlining.mlir
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
+}
+
More information about the Mlir-commits
mailing list