[MLIR][Shape] Add support for `OpAsmInterface` in `shape.const_size`

The SSA values created with `shape.const_size` are now named depending on the
value.
A constant size of 3, e.g., is now automatically named `%c3`.

Differential Revision: https://reviews.llvm.org/D81249
This commit is contained in:
Frederik Gossen 2020-06-08 10:24:50 +00:00
parent 80ab9345ed
commit 215914151e
3 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,7 @@ include "mlir/Dialect/Shape/IR/ShapeBase.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
def Shape_WitnessType : DialectType<ShapeDialect,
CPred<"$_self.isa<::mlir::shape::WitnessType>()">, "witness">,
@ -110,7 +111,11 @@ def Shape_ConstShapeOp : Shape_Op<"const_shape", [ConstantLike, NoSideEffect]> {
let hasFolder = 1;
}
def Shape_ConstSizeOp : Shape_Op<"const_size", [ConstantLike, NoSideEffect]> {
def Shape_ConstSizeOp : Shape_Op<"const_size", [
ConstantLike,
NoSideEffect,
DeclareOpInterfaceMethods<OpAsmOpInterface>
]> {
let summary = "Creates a constant of type `shape.size`";
let description = [{
Creates a `shape.size` type representing the constant size given by `value`.

View File

@ -13,6 +13,7 @@
#include "mlir/IR/DialectImplementation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/StandardTypes.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
using namespace mlir;
@ -352,6 +353,14 @@ OpFoldResult CstrEqOp::fold(ArrayRef<Attribute> operands) {
OpFoldResult ConstSizeOp::fold(ArrayRef<Attribute>) { return valueAttr(); }
void ConstSizeOp::getAsmResultNames(
llvm::function_ref<void(Value, StringRef)> setNameFn) {
SmallString<4> buffer;
llvm::raw_svector_ostream os(buffer);
os << "c" << value();
setNameFn(getResult(), os.str());
}
//===----------------------------------------------------------------------===//
// ConstWitnessOp
//===----------------------------------------------------------------------===//

View File

@ -91,3 +91,13 @@ func @test_mul(%lhs: !shape.size, %rhs: !shape.size) -> !shape.size {
%product = shape.mul %lhs, %rhs
return %product: !shape.size
}
func @const_size() {
// CHECK: %c1 = shape.const_size 1
// CHECK: %c2 = shape.const_size 2
// CHECK: %c2_0 = shape.const_size 2
%0 = shape.const_size 1
%1 = shape.const_size 2
%2 = shape.const_size 2
return
}