forked from OSchip/llvm-project
[mlir][NFC] Cleanup StandardTypes and reorder the type classes
This commit is contained in:
parent
e39c7ab2b9
commit
f49b2344a3
|
@ -65,6 +65,41 @@ enum Kind {
|
||||||
|
|
||||||
} // namespace StandardTypes
|
} // namespace StandardTypes
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// ComplexType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
/// The 'complex' type represents a complex number with a parameterized element
|
||||||
|
/// type, which is composed of a real and imaginary value of that element type.
|
||||||
|
///
|
||||||
|
/// The element must be a floating point or integer scalar type.
|
||||||
|
///
|
||||||
|
class ComplexType
|
||||||
|
: public Type::TypeBase<ComplexType, Type, detail::ComplexTypeStorage> {
|
||||||
|
public:
|
||||||
|
using Base::Base;
|
||||||
|
|
||||||
|
/// Get or create a ComplexType with the provided element type.
|
||||||
|
static ComplexType get(Type elementType);
|
||||||
|
|
||||||
|
/// Get or create a ComplexType with the provided element type. This emits
|
||||||
|
/// and error at the specified location and returns null if the element type
|
||||||
|
/// isn't supported.
|
||||||
|
static ComplexType getChecked(Type elementType, Location location);
|
||||||
|
|
||||||
|
/// Verify the construction of an integer type.
|
||||||
|
static LogicalResult verifyConstructionInvariants(Location loc,
|
||||||
|
Type elementType);
|
||||||
|
|
||||||
|
Type getElementType();
|
||||||
|
|
||||||
|
static bool kindof(unsigned kind) { return kind == StandardTypes::Complex; }
|
||||||
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// IndexType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Index is a special integer-like type with unknown platform-dependent bit
|
/// Index is a special integer-like type with unknown platform-dependent bit
|
||||||
/// width.
|
/// width.
|
||||||
class IndexType : public Type::TypeBase<IndexType, Type> {
|
class IndexType : public Type::TypeBase<IndexType, Type> {
|
||||||
|
@ -81,6 +116,10 @@ public:
|
||||||
static constexpr unsigned kInternalStorageBitWidth = 64;
|
static constexpr unsigned kInternalStorageBitWidth = 64;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// IntegerType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Integer types can have arbitrary bitwidth up to a large fixed limit.
|
/// Integer types can have arbitrary bitwidth up to a large fixed limit.
|
||||||
class IntegerType
|
class IntegerType
|
||||||
: public Type::TypeBase<IntegerType, Type, detail::IntegerTypeStorage> {
|
: public Type::TypeBase<IntegerType, Type, detail::IntegerTypeStorage> {
|
||||||
|
@ -145,6 +184,10 @@ public:
|
||||||
static constexpr unsigned kMaxWidth = 4096;
|
static constexpr unsigned kMaxWidth = 4096;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// FloatType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
class FloatType : public Type::TypeBase<FloatType, Type> {
|
class FloatType : public Type::TypeBase<FloatType, Type> {
|
||||||
public:
|
public:
|
||||||
using Base::Base;
|
using Base::Base;
|
||||||
|
@ -178,33 +221,26 @@ public:
|
||||||
const llvm::fltSemantics &getFloatSemantics();
|
const llvm::fltSemantics &getFloatSemantics();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The 'complex' type represents a complex number with a parameterized element
|
//===----------------------------------------------------------------------===//
|
||||||
/// type, which is composed of a real and imaginary value of that element type.
|
// NoneType
|
||||||
///
|
//===----------------------------------------------------------------------===//
|
||||||
/// The element must be a floating point or integer scalar type.
|
|
||||||
///
|
/// NoneType is a unit type, i.e. a type with exactly one possible value, where
|
||||||
class ComplexType
|
/// its value does not have a defined dynamic representation.
|
||||||
: public Type::TypeBase<ComplexType, Type, detail::ComplexTypeStorage> {
|
class NoneType : public Type::TypeBase<NoneType, Type> {
|
||||||
public:
|
public:
|
||||||
using Base::Base;
|
using Base::Base;
|
||||||
|
|
||||||
/// Get or create a ComplexType with the provided element type.
|
/// Get an instance of the NoneType.
|
||||||
static ComplexType get(Type elementType);
|
static NoneType get(MLIRContext *context);
|
||||||
|
|
||||||
/// Get or create a ComplexType with the provided element type. This emits
|
static bool kindof(unsigned kind) { return kind == StandardTypes::None; }
|
||||||
/// and error at the specified location and returns null if the element type
|
|
||||||
/// isn't supported.
|
|
||||||
static ComplexType getChecked(Type elementType, Location location);
|
|
||||||
|
|
||||||
/// Verify the construction of an integer type.
|
|
||||||
static LogicalResult verifyConstructionInvariants(Location loc,
|
|
||||||
Type elementType);
|
|
||||||
|
|
||||||
Type getElementType();
|
|
||||||
|
|
||||||
static bool kindof(unsigned kind) { return kind == StandardTypes::Complex; }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// ShapedType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// This is a common base class between Vector, UnrankedTensor, RankedTensor,
|
/// This is a common base class between Vector, UnrankedTensor, RankedTensor,
|
||||||
/// and MemRef types because they share behavior and semantics around shape,
|
/// and MemRef types because they share behavior and semantics around shape,
|
||||||
/// rank, and fixed element type. Any type with these semantics should inherit
|
/// rank, and fixed element type. Any type with these semantics should inherit
|
||||||
|
@ -291,6 +327,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// VectorType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Vector types represent multi-dimensional SIMD vectors, and have a fixed
|
/// Vector types represent multi-dimensional SIMD vectors, and have a fixed
|
||||||
/// known constant shape with one or more dimension.
|
/// known constant shape with one or more dimension.
|
||||||
class VectorType
|
class VectorType
|
||||||
|
@ -326,6 +366,10 @@ public:
|
||||||
static bool kindof(unsigned kind) { return kind == StandardTypes::Vector; }
|
static bool kindof(unsigned kind) { return kind == StandardTypes::Vector; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// TensorType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Tensor types represent multi-dimensional arrays, and have two variants:
|
/// Tensor types represent multi-dimensional arrays, and have two variants:
|
||||||
/// RankedTensorType and UnrankedTensorType.
|
/// RankedTensorType and UnrankedTensorType.
|
||||||
class TensorType : public ShapedType {
|
class TensorType : public ShapedType {
|
||||||
|
@ -350,6 +394,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// RankedTensorType
|
||||||
|
|
||||||
/// Ranked tensor types represent multi-dimensional arrays that have a shape
|
/// Ranked tensor types represent multi-dimensional arrays that have a shape
|
||||||
/// with a fixed number of dimensions. Each shape element can be a non-negative
|
/// with a fixed number of dimensions. Each shape element can be a non-negative
|
||||||
/// integer or unknown (represented by -1).
|
/// integer or unknown (represented by -1).
|
||||||
|
@ -382,6 +429,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// UnrankedTensorType
|
||||||
|
|
||||||
/// Unranked tensor types represent multi-dimensional arrays that have an
|
/// Unranked tensor types represent multi-dimensional arrays that have an
|
||||||
/// unknown shape.
|
/// unknown shape.
|
||||||
class UnrankedTensorType
|
class UnrankedTensorType
|
||||||
|
@ -411,6 +461,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// BaseMemRefType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Base MemRef for Ranked and Unranked variants
|
/// Base MemRef for Ranked and Unranked variants
|
||||||
class BaseMemRefType : public ShapedType {
|
class BaseMemRefType : public ShapedType {
|
||||||
public:
|
public:
|
||||||
|
@ -423,6 +477,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// MemRefType
|
||||||
|
|
||||||
/// MemRef types represent a region of memory that have a shape with a fixed
|
/// MemRef types represent a region of memory that have a shape with a fixed
|
||||||
/// number of dimensions. Each shape element can be a non-negative integer or
|
/// number of dimensions. Each shape element can be a non-negative integer or
|
||||||
/// unknown (represented by -1). MemRef types also have an affine map
|
/// unknown (represented by -1). MemRef types also have an affine map
|
||||||
|
@ -525,6 +582,9 @@ private:
|
||||||
using Base::getImpl;
|
using Base::getImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// UnrankedMemRefType
|
||||||
|
|
||||||
/// Unranked MemRef type represent multi-dimensional MemRefs that
|
/// Unranked MemRef type represent multi-dimensional MemRefs that
|
||||||
/// have an unknown rank.
|
/// have an unknown rank.
|
||||||
class UnrankedMemRefType
|
class UnrankedMemRefType
|
||||||
|
@ -558,6 +618,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
// TupleType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Tuple types represent a collection of other types. Note: This type merely
|
/// Tuple types represent a collection of other types. Note: This type merely
|
||||||
/// provides a common mechanism for representing tuples in MLIR. It is up to
|
/// provides a common mechanism for representing tuples in MLIR. It is up to
|
||||||
/// dialect authors to provides operations for manipulating them, e.g.
|
/// dialect authors to provides operations for manipulating them, e.g.
|
||||||
|
@ -601,17 +665,9 @@ public:
|
||||||
static bool kindof(unsigned kind) { return kind == StandardTypes::Tuple; }
|
static bool kindof(unsigned kind) { return kind == StandardTypes::Tuple; }
|
||||||
};
|
};
|
||||||
|
|
||||||
/// NoneType is a unit type, i.e. a type with exactly one possible value, where
|
//===----------------------------------------------------------------------===//
|
||||||
/// its value does not have a defined dynamic representation.
|
// Type Utilities
|
||||||
class NoneType : public Type::TypeBase<NoneType, Type> {
|
//===----------------------------------------------------------------------===//
|
||||||
public:
|
|
||||||
using Base::Base;
|
|
||||||
|
|
||||||
/// Get an instance of the NoneType.
|
|
||||||
static NoneType get(MLIRContext *context);
|
|
||||||
|
|
||||||
static bool kindof(unsigned kind) { return kind == StandardTypes::None; }
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Returns the strides of the MemRef if the layout map is in strided form.
|
/// Returns the strides of the MemRef if the layout map is in strided form.
|
||||||
/// MemRefs with layout maps in strided form include:
|
/// MemRefs with layout maps in strided form include:
|
||||||
|
|
|
@ -89,6 +89,29 @@ bool Type::isIntOrFloat() { return isa<IntegerType>() || isa<FloatType>(); }
|
||||||
|
|
||||||
bool Type::isIntOrIndexOrFloat() { return isIntOrFloat() || isIndex(); }
|
bool Type::isIntOrIndexOrFloat() { return isIntOrFloat() || isIndex(); }
|
||||||
|
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
/// ComplexType
|
||||||
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
ComplexType ComplexType::get(Type elementType) {
|
||||||
|
return Base::get(elementType.getContext(), StandardTypes::Complex,
|
||||||
|
elementType);
|
||||||
|
}
|
||||||
|
|
||||||
|
ComplexType ComplexType::getChecked(Type elementType, Location location) {
|
||||||
|
return Base::getChecked(location, StandardTypes::Complex, elementType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verify the construction of an integer type.
|
||||||
|
LogicalResult ComplexType::verifyConstructionInvariants(Location loc,
|
||||||
|
Type elementType) {
|
||||||
|
if (!elementType.isIntOrFloat())
|
||||||
|
return emitError(loc, "invalid element type for complex");
|
||||||
|
return success();
|
||||||
|
}
|
||||||
|
|
||||||
|
Type ComplexType::getElementType() { return getImpl()->elementType; }
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Integer Type
|
// Integer Type
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -612,29 +635,6 @@ LogicalResult mlir::getStridesAndOffset(MemRefType t,
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
/// ComplexType
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
ComplexType ComplexType::get(Type elementType) {
|
|
||||||
return Base::get(elementType.getContext(), StandardTypes::Complex,
|
|
||||||
elementType);
|
|
||||||
}
|
|
||||||
|
|
||||||
ComplexType ComplexType::getChecked(Type elementType, Location location) {
|
|
||||||
return Base::getChecked(location, StandardTypes::Complex, elementType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Verify the construction of an integer type.
|
|
||||||
LogicalResult ComplexType::verifyConstructionInvariants(Location loc,
|
|
||||||
Type elementType) {
|
|
||||||
if (!elementType.isa<FloatType>() && !elementType.isSignlessInteger())
|
|
||||||
return emitError(loc, "invalid element type for complex");
|
|
||||||
return success();
|
|
||||||
}
|
|
||||||
|
|
||||||
Type ComplexType::getElementType() { return getImpl()->elementType; }
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
/// TupleType
|
/// TupleType
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
Loading…
Reference in New Issue