-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir] Convert TensorType and BaseMemRefType to interfaces #133053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,21 +143,21 @@ def ShapedTypeInterface : TypeInterface<"ShapedType"> { | |
|
||
/// Return the number of elements present in the given shape. | ||
static int64_t getNumElements(ArrayRef<int64_t> shape); | ||
}]; | ||
|
||
let extraSharedClassDeclaration = [{ | ||
/// Return a clone of this type with the given new shape and element type. | ||
/// The returned type is ranked, even if this type is unranked. | ||
auto clone(::llvm::ArrayRef<int64_t> shape, Type elementType) { | ||
return cloneWith(shape, elementType); | ||
return $_type.cloneWith(shape, elementType); | ||
} | ||
|
||
/// Return a clone of this type with the given new shape. The returned type | ||
/// is ranked, even if this type is unranked. | ||
auto clone(::llvm::ArrayRef<int64_t> shape) { | ||
return cloneWith(shape, getElementType()); | ||
return $_type.cloneWith(shape, $_type.getElementType()); | ||
} | ||
}]; | ||
|
||
let extraSharedClassDeclaration = [{ | ||
/// Return a clone of this type with the given new element type. The | ||
/// returned type is ranked if and only if this type is ranked. In that | ||
/// case, the returned type has the same shape as this type. | ||
|
@@ -227,4 +227,64 @@ def ShapedTypeInterface : TypeInterface<"ShapedType"> { | |
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// TensorTypeInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
def TensorTypeInterface : TypeInterface<"TensorType", [ShapedTypeInterface]> { | ||
let cppNamespace = "::mlir"; | ||
let description = [{ | ||
This interface provides a shared interface type for ranked, unranked and any | ||
user-specified tensor types. | ||
|
||
This interface attaches the ShapedTypeInterface to act as a mixin to | ||
provide many useful utility functions. | ||
}]; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Return true if the specified element type is ok in a tensor. | ||
static bool isValidElementType(::mlir::Type type); | ||
}]; | ||
|
||
let extraClassOf = [{ | ||
return $_type.hasTrait<::mlir::TensorType::Trait>(); | ||
}]; | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
// BaseMemRefTypeInterface | ||
//===----------------------------------------------------------------------===// | ||
|
||
def BaseMemRefTypeInterface : TypeInterface<"BaseMemRefType", [ShapedTypeInterface]> { | ||
let cppNamespace = "::mlir"; | ||
let description = [{ | ||
This interface provides a shared interface type for ranked, unranked and any | ||
user-specified memref types. | ||
|
||
This interface attaches the ShapedTypeInterface to act as a mixin to | ||
provide many useful utility functions. | ||
}]; | ||
|
||
let methods = [ | ||
InterfaceMethod<[{ | ||
Returns the memory space in which data referred to by this memref resides. | ||
}], | ||
"::mlir::Attribute", "getMemorySpace">, | ||
InterfaceMethod<[{ | ||
[deprecated] Returns the memory space in old raw integer representation. | ||
New `Attribute getMemorySpace()` method should be used instead. | ||
}], | ||
"unsigned", "getMemorySpaceAsInt">, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note to reviewers: this seems to still exist, however it has been marked deprecated for a while. |
||
]; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Return true if the specified element type is ok in a memref. | ||
static bool isValidElementType(::mlir::Type type); | ||
}]; | ||
|
||
let extraClassOf = [{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not familiar with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afaik, this is to generate |
||
return $_type.hasTrait<::mlir::BaseMemRefType::Trait>(); | ||
}]; | ||
} | ||
|
||
#endif // MLIR_IR_BUILTINTYPEINTERFACES_TD_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it necessary to split this into
extraClassDeclaration
andextraSharedClassDeclaration
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember anymore (this patch is actually ~year old at this point :) - i never had time to brush it up).
I think this has to be like this because of reliance on
$_type
(see https://mlir.llvm.org/docs/Interfaces/) to implementcloneWith
(so ShapedType::clone() would behind the scenes call the derived type's methods).