14 #ifndef MLIR_INTERFACES_INFERTYPEOPINTERFACE_H_
15 #define MLIR_INTERFACES_INFERTYPEOPINTERFACE_H_
23 #include "llvm/ADT/PointerUnion.h"
24 #include "llvm/ADT/SmallVector.h"
28 class ShapedTypeComponents;
42 if (
auto st = dyn_cast<ShapedType>(t))
46 if (
auto da = dyn_cast<DenseIntElementsAttr>(t))
73 return ShapedType::isDynamic(
getDimSize(index));
88 explicit operator bool()
const {
return !val.isNull(); }
115 : elementType(elementType), attr(nullptr), ranked(false) {}
117 ranked = shapedType.hasRank();
118 elementType = shapedType.getElementType();
120 dims = llvm::to_vector<4>(shapedType.getShape());
128 template <
typename Arg,
typename = std::enable_if_t<
129 std::is_constructible<ShapeStorageT, Arg>::value>>
132 : dims(std::forward<Arg>(arg)), elementType(elementType), attr(attr),
136 : dims(vec.begin(), vec.end()), elementType(elementType), attr(attr),
142 assert(ranked &&
"requires ranked shape");
176 : RangeBaseT(values), operandShape(operandShape),
177 valueToShape(valueToShape) {}
242 SmallVectorImpl<Type> &inferredReturnTypes);
254 template <
typename ConcreteType>
255 class InferTensorType;
260 #include "mlir/Interfaces/InferTypeOpInterface.h.inc"
265 template <
typename ConcreteType>
269 template <
typename ConcreteType>
271 :
public TraitBase<ConcreteType, InferShapedTypeOpAdaptor> {};
280 template <
typename ConcreteType>
Attributes are known-constant values of operations.
This class helps build Operations.
Tensor type inference trait that constructs a tensor from the inferred shape and elemental types.
Helper class for implementing traits.
Operation is the basic unit of execution within MLIR.
Adaptor class to abstract the differences between whether value is from a ShapedType or ShapedTypeCom...
bool isDynamicDim(int index) const
Returns whether the index'th dimension is dynamic.
int64_t getDimSize(int index) const
Returns the size of the index'th dimension.
void dump() const
Dumps textual repesentation to stderr.
Type getElementType() const
Returns the element type.
ShapeAdaptor(Attribute t)
int64_t getRank() const
Returns the rank of the shape.
bool hasStaticShape() const
Returns whether the shape is fully static.
ShapeAdaptor(ShapedTypeComponents &components)
ShapeAdaptor(ShapedTypeComponents *components)
int64_t getNumElements() const
Returns the number of elements in the shape.
void getDims(SmallVectorImpl< int64_t > &res) const
Populates the dimensions from shape referenced.
bool hasRank() const
Returns whether the shape has a rank.
ShapedTypeComponents that represents the components of a ShapedType.
ShapedTypeComponents()
Default construction is an unranked shape.
ShapedTypeComponents(Arg &&arg, Type elementType=nullptr, Attribute attr=nullptr)
ShapedTypeComponents(ShapedType shapedType)
ShapedTypeComponents(Type elementType)
ShapedTypeComponents(ArrayRef< int64_t > vec, Type elementType=nullptr, Attribute attr=nullptr)
ShapedTypeComponents(ShapeAdaptor adaptor)
bool hasRank() const
Return whether the shape has a rank.
Type getElementType() const
Return the element type component.
Attribute getAttribute() const
Return the raw attribute component.
ArrayRef< int64_t > getDims() const
Return the dimensions of the shape.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
Range of values and shapes (corresponding effectively to Shapes dialect's ValueShape type concept).
ValueShapeMapFn getOperandShapeMapping() const
ValueShapeMapFn getValueToShapeMapping() const
Returns the set Value to ShapeAdaptor mapping function.
ValueShapeRange & setValueToShapeMapping(ValueShapeMapFn fn)
Sets the Value to ShapeAdaptor mapping function and returns this.
ValueShapeRange(const ValueShapeRange &)=default
ShapeAdaptor getValueAsShape(int index)
Returns an argument as shape.
type_range getTypes() const
ValueShapeRange(ValueRange values, ValueShapeMapFn operandShape=nullptr, ValueShapeMapFn valueToShape=nullptr)
ValueShapeRange(const std::initializer_list< Value > &values)
ShapeAdaptor getShape(int index) const
Returns the shape of index'th operand.
function_ref< ShapeAdaptor(Value)> ValueShapeMapFn
ValueShapeRange & setOperandShapeMapping(ValueShapeMapFn fn)
ValueRange getValues() const
Returns the Values in the ValueRange.
This class implements iteration on the types of a given range of values.
This class implements iteration on the types of a given range of values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
LogicalResult inferReturnTensorTypes(ArrayRef< ShapedTypeComponents > retComponents, SmallVectorImpl< Type > &inferredReturnTypes)
void reportFatalInferReturnTypesError(OperationState &state)
Report a fatal error indicating that the result types could not be inferred.
LogicalResult verifyInferredResultTypes(Operation *op)
Verifies that the inferred result types match the actual result types for the op.
Include the generated interface declarations.
LogicalResult reifyResultShapes(OpBuilder &b, Operation *op, ReifiedRankedShapedTypeDims &reifiedReturnShapes)
Reify the shape of the result of an operation (typically in terms of the shape of its operands).