[MLIR][Quant] Add DialectInlinerInterface to QuantDialect (#172509)
Signed-off-by: Jonas Rickert <jonas.rickert@amd.com>
This commit is contained in:
1 parent
8a922e8151
commit
75fefa3087
2 files changed
+57
No files matched your search
@@ -14,6 +14,7 @@
|
||||
#include "mlir/IR/BuiltinTypes.h"
|
||||
#include "mlir/IR/PatternMatch.h"
|
||||
#include "mlir/IR/TypeUtilities.h"
|
||||
#include "mlir/Transforms/InliningUtils.h"
|
||||
|
||||
#include "mlir/Dialect/Quant/IR/QuantOpsDialect.cpp.inc"
|
||||
|
||||
@@ -183,6 +184,14 @@ LogicalResult verifyQuantizationOp(Operation *op, QuantizedType quantizedType,
|
||||
return success();
|
||||
}
|
||||
|
||||
struct QuantInlinerInterface : public DialectInlinerInterface {
|
||||
using DialectInlinerInterface::DialectInlinerInterface;
|
||||
/// All quant dialect ops can be inlined.
|
||||
bool isLegalToInline(Operation *, Region *, bool, IRMapping &) const final {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -197,6 +206,7 @@ void QuantDialect::initialize() {
|
||||
#include "mlir/Dialect/Quant/IR/QuantOps.cpp.inc"
|
||||
>();
|
||||
detail::addBytecodeInterface(this);
|
||||
addInterfaces<QuantInlinerInterface>();
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// RUN: mlir-opt %s -inline | FileCheck %s
|
||||
|
||||
!qalias = !quant.uniform<i8:f32, 2.0:10>
|
||||
|
||||
func.func @inner_dcast_inlinable(%arg0: !qalias) -> f32 {
|
||||
%0 = quant.dcast %arg0 : !qalias to f32
|
||||
return %0 : f32
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func.func @test_inline_dcast(
|
||||
// CHECK-NOT: func.call
|
||||
// CHECK-NEXT: quant.dcast
|
||||
func.func @test_inline_dcast(%v: !qalias) -> f32 {
|
||||
%0 = call @inner_dcast_inlinable(%v) : (!qalias) -> f32
|
||||
return %0 : f32
|
||||
}
|
||||
|
||||
|
||||
|
||||
func.func @inner_qcast_inlinable(%v: f32) -> !qalias {
|
||||
%1 = quant.qcast %v : f32 to !qalias
|
||||
return %1 : !qalias
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func.func @test_inline_qcast(
|
||||
// CHECK-NOT: func.call
|
||||
// CHECK-NEXT: quant.qcast
|
||||
func.func @test_inline_qcast(%v: f32) -> !qalias {
|
||||
%0 = call @inner_qcast_inlinable(%v) : (f32) -> !qalias
|
||||
return %0 : !qalias
|
||||
}
|
||||
|
||||
func.func @inner_scast_inlinable(%v: i8) -> !qalias {
|
||||
%1 = quant.scast %v : i8 to !qalias
|
||||
return %1 : !qalias
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func.func @test_inline_scast(
|
||||
// CHECK-NOT: func.call
|
||||
// CHECK-NEXT: quant.scast
|
||||
func.func @test_inline_scast(%v: i8) -> !qalias {
|
||||
%0 = call @inner_scast_inlinable(%v) : (i8) -> !qalias
|
||||
return %0 : !qalias
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user