mlir::TypedValue is a wrapper class for mlir::Values with a known type
getType will return the known type and all assignments will be asserted
Also the tablegen Operation generator was adapted to use mlir::TypedValue
when appropriate
If an op can only take one type for a specific fields, getting this field
will return a TypedValue of the correct type. so there is no need to cast the type.
I also think TypedValue can be a useful to express directly what an API is expecting or providing
and remove the need for to cast the return of .getType() its Values when using that API.
for example:
/// expressed directly in the API that that the parameter should be a Value of IntegerType. /// And the return will still be of IntegerType. TypedValue<IntegerType> maybeCast(TypedValue<IntegerType> ) Value v; auto v2 = maybeCast(v) /// asserts that the Type is IntergerType assert(v2.getType().getWidth() == 8); /// no need to do .cast<IntegerType>() /// Assuming MyOp is defined to operate on TensorType exclusively MyOp.getLHS().getType() // is a TensorType /// Not just for APIs Value getValue() /// express directly that the expected type of v is IntegerType TypedValue<IntegerType> temporary = getValue() /// express that this should only store Values of type IntegerType DenseMap<mlir::Operations*, TypedValue<IntegerType>>
Nit: "checked" -> "asserted", there won't be any check in non-assert build.