mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[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:
@@ -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>();
|
||||
}
|
||||
|
||||
|
||||
15
mlir/test/Dialect/Index/inliner-interface.mlir
Normal file
15
mlir/test/Dialect/Index/inliner-interface.mlir
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user