[Mlir-commits] [mlir] [mlir][sparse] Add verification for explicit/implicit value (PR #90111)
Wenyi Zhao
llvmlistbot at llvm.org
Fri Apr 26 02:57:54 PDT 2024
================
@@ -907,6 +907,38 @@ LogicalResult SparseTensorEncodingAttr::verifyEncoding(
return emitError()
<< "dimension-rank mismatch between encoding and tensor shape: "
<< getDimRank() << " != " << dimRank;
+ if (getExplicitVal()) {
+ if (auto typedAttr = llvm::dyn_cast<TypedAttr>(getExplicitVal())) {
+ Type attrType = typedAttr.getType();
+ if (attrType != elementType) {
+ return emitError()
+ << "explicit value type mismatch between encoding and "
+ << "tensor element type: " << attrType << " != " << elementType;
+ }
+ } else {
+ return emitError() << "expected typed explicit value";
+ }
+ }
+ if (getImplicitVal()) {
+ auto impVal = getImplicitVal();
+ if (auto typedAttr = llvm::dyn_cast<TypedAttr>(getImplicitVal())) {
+ Type attrType = typedAttr.getType();
+ if (attrType != elementType) {
+ return emitError()
+ << "implicit value type mismatch between encoding and "
+ << "tensor element type: " << attrType << " != " << elementType;
+ }
+ } else {
+ return emitError() << "expected typed implicit value";
+ }
+ // Currently, we only support zero as the implicit value.
+ auto impFVal = llvm::dyn_cast<FloatAttr>(impVal);
+ auto impIntVal = llvm::dyn_cast<IntegerAttr>(impVal);
----------------
wyzero wrote:
What if both `impFVal` and `impFVal` are null? Do we need to emit an error for this as well?
https://github.com/llvm/llvm-project/pull/90111
More information about the Mlir-commits
mailing list