[Mlir-commits] [mlir] [mlir][tosa] Add error if checks Variable Operators (PR #137291)
Peng Sun
llvmlistbot at llvm.org
Mon Apr 28 06:35:55 PDT 2025
================
@@ -562,6 +562,74 @@ static LogicalResult verifyConvOpErrorIf(T op) {
return success();
}
+// Verify whether same type and shape of the given two types.
+static LogicalResult errorIfTypeOrShapeMismatch(Operation *op, Type type1,
+ StringRef name1, Type type2,
+ StringRef name2) {
+ auto shapeType1 = dyn_cast<ShapedType>(type1);
+ auto shapeType2 = dyn_cast<ShapedType>(type2);
+ if (!shapeType1 || !shapeType2)
+ return failure();
+
+ auto elemType1 = shapeType1.getElementType();
+ auto elemType2 = shapeType2.getElementType();
+ if (elemType1 != elemType2)
+ return op->emitOpError()
+ << "require same element type for " << name1 << " (" << elemType1
+ << ") and " << name2 << " (" << elemType2 << ")";
+
+ if (failed(verifyCompatibleShape(type1, type2)))
+ return op->emitOpError()
+ << "require same shapes for " << name1 << " (" << type1 << ") and "
+ << name2 << " (" << type2 << ")";
+
+ return success();
+}
+
+template <typename T>
+static LogicalResult verifyVariableOpErrorIf(T op, Type type, StringRef name) {
+ // Currently, the variable's definition point is searched via walk(),
+ // starting from the top-level ModuleOp and stopping at the point of use. Once
+ // TOSA control flow and variable extensions reach the complete state, may
+ // leverage MLIR's Symbol Table functionality to look up symbol and enhance
----------------
psunn wrote:
agree, switch to symbol table based lookup would be ideal, manual walk is fine for prototypes but probably not scalable
https://github.com/llvm/llvm-project/pull/137291
More information about the Mlir-commits
mailing list