[mlir] Add inliner interface to the index dialect (#170459)

Add the inliner interface to the index dialect allowing the `inline`
pass to inline all index operations.
This commit is contained in:
Jack
2025-12-05 14:43:51 +00:00
committed by GitHub
parent 03afb4f528
commit accf0de990
2 changed files with 29 additions and 0 deletions

View File

@@ -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;
}
};
} // namespace
void IndexDialect::initialize() {
registerAttributes();
registerOperations();
addInterfaces<IndexInlinerInterface>();
declarePromisedInterface<ConvertToLLVMPatternInterface, IndexDialect>();
}

View File

@@ -0,0 +1,15 @@
// RUN: mlir-opt %s -inline | FileCheck %s
// CHECK-LABEL: @main
func.func @main(%arg0: i32) -> index {
// CHECK-NOT: call
// CHECK: index.castu
%0 = call @f(%arg0) : (i32) -> index
return %0 : index
}
// CHECK-LABEL: @f
func.func @f(%arg0: i32) -> index {
%0 = index.castu %arg0 : i32 to index
return %0 : index
}