Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions mlir/include/mlir/IR/BuiltinTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,17 @@ def Builtin_RankedTensor : Builtin_Type<"RankedTensor", "tensor", [
RankedTensorType clone(::mlir::Type elementType) {
return ::llvm::cast<RankedTensorType>(cloneWith(getShape(), elementType));
}

/// Return a clone of this type without the encoding.
RankedTensorType dropEncoding() {
return RankedTensorType::get(getShape(), getElementType());
}

/// Return a clone of this type with the given new encoding and the same
/// shape and element type as this type.
RankedTensorType cloneWithEncoding(::mlir::Attribute encoding) {
return RankedTensorType::get(getShape(), getElementType(), encoding);
}
}];
let skipDefaultBuilders = 1;
let genVerifyDecl = 1;
Expand Down
14 changes: 14 additions & 0 deletions mlir/unittests/IR/ShapedTypeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,20 @@ TEST(ShapedTypeTest, RankedTensorTypeView) {
ASSERT_TRUE(mlir::isa<RankedTensorType>(viewCreated));
view = mlir::cast<TensorWithString>(viewCreated);
EXPECT_EQ(view.getName(), "bob");

// Verify encoding clone methods.
EXPECT_EQ(unitEncodingRankedTensorType,
cast<RankedTensorType>(noEncodingRankedTensorType)
.cloneWithEncoding(unitAttr));
EXPECT_EQ(stringEncodingRankedTensorType,
cast<RankedTensorType>(noEncodingRankedTensorType)
.cloneWithEncoding(stringAttr));
EXPECT_EQ(
noEncodingRankedTensorType,
cast<RankedTensorType>(unitEncodingRankedTensorType).dropEncoding());
EXPECT_EQ(
noEncodingRankedTensorType,
cast<RankedTensorType>(stringEncodingRankedTensorType).dropEncoding());
}

} // namespace