[Mlir-commits] [mlir] f49b234 - [mlir][NFC] Cleanup StandardTypes and reorder the type classes

River Riddle llvmlistbot at llvm.org
Fri May 1 19:31:35 PDT 2020


Author: River Riddle
Date: 2020-05-01T19:28:42-07:00
New Revision: f49b2344a346b43ef00983e18cb0525ffcca79f0

URL: https://github.com/llvm/llvm-project/commit/f49b2344a346b43ef00983e18cb0525ffcca79f0
DIFF: https://github.com/llvm/llvm-project/commit/f49b2344a346b43ef00983e18cb0525ffcca79f0.diff

LOG: [mlir][NFC] Cleanup StandardTypes and reorder the type classes

Added: 
    

Modified: 
    mlir/include/mlir/IR/StandardTypes.h
    mlir/lib/IR/StandardTypes.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/StandardTypes.h b/mlir/include/mlir/IR/StandardTypes.h
index 3241a70f2675..752f2a45f07d 100644
--- a/mlir/include/mlir/IR/StandardTypes.h
+++ b/mlir/include/mlir/IR/StandardTypes.h
@@ -65,6 +65,41 @@ enum Kind {
 
 } // 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
 /// width.
 class IndexType : public Type::TypeBase<IndexType, Type> {
@@ -81,6 +116,10 @@ class IndexType : public Type::TypeBase<IndexType, Type> {
   static constexpr unsigned kInternalStorageBitWidth = 64;
 };
 
+//===----------------------------------------------------------------------===//
+// IntegerType
+//===----------------------------------------------------------------------===//
+
 /// Integer types can have arbitrary bitwidth up to a large fixed limit.
 class IntegerType
     : public Type::TypeBase<IntegerType, Type, detail::IntegerTypeStorage> {
@@ -145,6 +184,10 @@ class IntegerType
   static constexpr unsigned kMaxWidth = 4096;
 };
 
+//===----------------------------------------------------------------------===//
+// FloatType
+//===----------------------------------------------------------------------===//
+
 class FloatType : public Type::TypeBase<FloatType, Type> {
 public:
   using Base::Base;
@@ -178,33 +221,26 @@ class FloatType : public Type::TypeBase<FloatType, Type> {
   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.
-///
-/// The element must be a floating point or integer scalar type.
-///
-class ComplexType
-    : public Type::TypeBase<ComplexType, Type, detail::ComplexTypeStorage> {
+//===----------------------------------------------------------------------===//
+// NoneType
+//===----------------------------------------------------------------------===//
+
+/// NoneType is a unit type, i.e. a type with exactly one possible value, where
+/// its value does not have a defined dynamic representation.
+class NoneType : public Type::TypeBase<NoneType, Type> {
 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();
+  /// Get an instance of the NoneType.
+  static NoneType get(MLIRContext *context);
 
-  static bool kindof(unsigned kind) { return kind == StandardTypes::Complex; }
+  static bool kindof(unsigned kind) { return kind == StandardTypes::None; }
 };
 
+//===----------------------------------------------------------------------===//
+// ShapedType
+//===----------------------------------------------------------------------===//
+
 /// This is a common base class between Vector, UnrankedTensor, RankedTensor,
 /// and MemRef types because they share behavior and semantics around shape,
 /// rank, and fixed element type. Any type with these semantics should inherit
@@ -291,6 +327,10 @@ class ShapedType : public Type {
   }
 };
 
+//===----------------------------------------------------------------------===//
+// VectorType
+//===----------------------------------------------------------------------===//
+
 /// Vector types represent multi-dimensional SIMD vectors, and have a fixed
 /// known constant shape with one or more dimension.
 class VectorType
@@ -326,6 +366,10 @@ class VectorType
   static bool kindof(unsigned kind) { return kind == StandardTypes::Vector; }
 };
 
+//===----------------------------------------------------------------------===//
+// TensorType
+//===----------------------------------------------------------------------===//
+
 /// Tensor types represent multi-dimensional arrays, and have two variants:
 /// RankedTensorType and UnrankedTensorType.
 class TensorType : public ShapedType {
@@ -350,6 +394,9 @@ class TensorType : public ShapedType {
   }
 };
 
+//===----------------------------------------------------------------------===//
+// RankedTensorType
+
 /// 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
 /// integer or unknown (represented by -1).
@@ -382,6 +429,9 @@ class RankedTensorType
   }
 };
 
+//===----------------------------------------------------------------------===//
+// UnrankedTensorType
+
 /// Unranked tensor types represent multi-dimensional arrays that have an
 /// unknown shape.
 class UnrankedTensorType
@@ -411,6 +461,10 @@ class UnrankedTensorType
   }
 };
 
+//===----------------------------------------------------------------------===//
+// BaseMemRefType
+//===----------------------------------------------------------------------===//
+
 /// Base MemRef for Ranked and Unranked variants
 class BaseMemRefType : public ShapedType {
 public:
@@ -423,6 +477,9 @@ class BaseMemRefType : public ShapedType {
   }
 };
 
+//===----------------------------------------------------------------------===//
+// MemRefType
+
 /// 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
 /// unknown (represented by -1). MemRef types also have an affine map
@@ -525,6 +582,9 @@ class MemRefType : public Type::TypeBase<MemRefType, BaseMemRefType,
   using Base::getImpl;
 };
 
+//===----------------------------------------------------------------------===//
+// UnrankedMemRefType
+
 /// Unranked MemRef type represent multi-dimensional MemRefs that
 /// have an unknown rank.
 class UnrankedMemRefType
@@ -558,6 +618,10 @@ class UnrankedMemRefType
   }
 };
 
+//===----------------------------------------------------------------------===//
+// TupleType
+//===----------------------------------------------------------------------===//
+
 /// 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
 /// dialect authors to provides operations for manipulating them, e.g.
@@ -601,17 +665,9 @@ class TupleType
   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.
-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; }
-};
+//===----------------------------------------------------------------------===//
+// Type Utilities
+//===----------------------------------------------------------------------===//
 
 /// Returns the strides of the MemRef if the layout map is in strided form.
 /// MemRefs with layout maps in strided form include:

diff  --git a/mlir/lib/IR/StandardTypes.cpp b/mlir/lib/IR/StandardTypes.cpp
index c61e1d9e2ab9..3f4a7ec6ef6e 100644
--- a/mlir/lib/IR/StandardTypes.cpp
+++ b/mlir/lib/IR/StandardTypes.cpp
@@ -89,6 +89,29 @@ bool Type::isIntOrFloat() { return isa<IntegerType>() || isa<FloatType>(); }
 
 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
 //===----------------------------------------------------------------------===//
@@ -612,29 +635,6 @@ LogicalResult mlir::getStridesAndOffset(MemRefType t,
   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
 //===----------------------------------------------------------------------===//


        


More information about the Mlir-commits mailing list