[flang-commits] [flang] 61b8a3e - [flang][fir][NFC] Move BoxProcType to TableGen type definition

via flang-commits flang-commits at lists.llvm.org
Tue Feb 16 18:27:40 PST 2021


Author: Valentin Clement
Date: 2021-02-16T21:27:30-05:00
New Revision: 61b8a3e7c5acdbef8d6f36cbaf062e5b1e8875fc

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

LOG: [flang][fir][NFC] Move BoxProcType to TableGen type definition

This patch is a follow up of D96422 and move BoxProcType to TableGen.

Reviewed By: schweitz, mehdi_amini

Differential Revision: https://reviews.llvm.org/D96514

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIROps.td
    flang/include/flang/Optimizer/Dialect/FIRType.h
    flang/include/flang/Optimizer/Dialect/FIRTypes.td
    flang/lib/Optimizer/Dialect/FIRType.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td
index 21433f8f3c3e..c628371c4971 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROps.td
+++ b/flang/include/flang/Optimizer/Dialect/FIROps.td
@@ -82,10 +82,6 @@ def fir_PointerType : Type<CPred<"$_self.isa<fir::PointerType>()">,
 def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
     fir_HeapType.predicate, fir_PointerType.predicate]>, "any reference">;
 
-// PROCEDURE POINTER descriptor. A pair that can capture a host closure.
-def fir_BoxProcType : Type<CPred<"$_self.isa<fir::BoxProcType>()">,
-    "box procedure type">;
-
 def AnyBoxLike : TypeConstraint<Or<[BoxType.predicate,
     fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
 

diff  --git a/flang/include/flang/Optimizer/Dialect/FIRType.h b/flang/include/flang/Optimizer/Dialect/FIRType.h
index c65565a82f61..f23c075026e4 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRType.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRType.h
@@ -42,7 +42,6 @@ class FIROpsDialect;
 using KindTy = unsigned;
 
 namespace detail {
-struct BoxProcTypeStorage;
 struct ComplexTypeStorage;
 struct HeapTypeStorage;
 struct IntegerTypeStorage;
@@ -143,20 +142,6 @@ class RealType : public mlir::Type::TypeBase<RealType, mlir::Type,
 
 // FIR support types
 
-/// The type of a pair that describes a PROCEDURE reference. Pointers to
-/// internal procedures must carry an additional reference to the host's
-/// variables that are referenced.
-class BoxProcType : public mlir::Type::TypeBase<BoxProcType, mlir::Type,
-                                                detail::BoxProcTypeStorage> {
-public:
-  using Base::Base;
-  static BoxProcType get(mlir::Type eleTy);
-  mlir::Type getEleTy() const;
-
-  static mlir::LogicalResult verifyConstructionInvariants(mlir::Location,
-                                                          mlir::Type eleTy);
-};
-
 /// Type of a vector that represents an array slice operation on an array.
 /// Fortran slices are triples of lower bound, upper bound, and stride. The rank
 /// of a SliceType must be at least 1.

diff  --git a/flang/include/flang/Optimizer/Dialect/FIRTypes.td b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
index e1bff3838daa..28b388115639 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/flang/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -21,6 +21,28 @@ class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
   let mnemonic = typeMnemonic;
 }
 
+def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
+  let summary = "";
+
+  let description = [{
+    The type of a pair that describes a PROCEDURE reference. Pointers to
+    internal procedures must carry an additional reference to the host's
+    variables that are referenced.
+  }];
+
+  let parameters = (ins "mlir::Type":$eleTy);
+
+  let printer = [{
+    $_printer << "boxproc<";
+    $_printer.printType(getEleTy());
+    $_printer << '>';
+  }];
+
+  let genAccessors = 1;
+
+  let genVerifyInvariantsDecl = 1;
+}
+
 def BoxType : FIR_Type<"Box", "box"> {
   let summary = "The type of a Fortran descriptor";
 
@@ -41,6 +63,7 @@ def BoxType : FIR_Type<"Box", "box"> {
   }];
 
   let genAccessors = 1;
+
   let genVerifyInvariantsDecl = 1;
 }
 

diff  --git a/flang/lib/Optimizer/Dialect/FIRType.cpp b/flang/lib/Optimizer/Dialect/FIRType.cpp
index 1ddf6477b175..4889fa11056f 100644
--- a/flang/lib/Optimizer/Dialect/FIRType.cpp
+++ b/flang/lib/Optimizer/Dialect/FIRType.cpp
@@ -58,11 +58,6 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
   return TYPE::get(ty);
 }
 
-// `boxproc` `<` return-type `>`
-BoxProcType parseBoxProc(mlir::DialectAsmParser &parser, mlir::Location loc) {
-  return parseTypeSingleton<BoxProcType>(parser, loc);
-}
-
 // `complex` `<` kind `>`
 fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) {
   return parseKindSingleton<fir::ComplexType>(parser);
@@ -310,7 +305,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
   if (typeNameLit == "boxchar")
     return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
   if (typeNameLit == "boxproc")
-    return parseBoxProc(parser, loc);
+    return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
   if (typeNameLit == "char")
     return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
   if (typeNameLit == "complex")
@@ -493,31 +488,6 @@ struct RealTypeStorage : public mlir::TypeStorage {
   explicit RealTypeStorage(KindTy kind) : kind{kind} {}
 };
 
-/// Boxed PROCEDURE POINTER object type
-struct BoxProcTypeStorage : public mlir::TypeStorage {
-  using KeyTy = mlir::Type;
-
-  static unsigned hashKey(const KeyTy &key) { return llvm::hash_combine(key); }
-
-  bool operator==(const KeyTy &key) const { return key == getElementType(); }
-
-  static BoxProcTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
-                                       mlir::Type eleTy) {
-    assert(eleTy && "element type is null");
-    auto *storage = allocator.allocate<BoxProcTypeStorage>();
-    return new (storage) BoxProcTypeStorage{eleTy};
-  }
-
-  mlir::Type getElementType() const { return eleTy; }
-
-protected:
-  mlir::Type eleTy;
-
-private:
-  BoxProcTypeStorage() = delete;
-  explicit BoxProcTypeStorage(mlir::Type eleTy) : eleTy{eleTy} {}
-};
-
 /// Pointer-like object storage
 struct ReferenceTypeStorage : public mlir::TypeStorage {
   using KeyTy = mlir::Type;
@@ -836,27 +806,6 @@ fir::BoxType::verifyConstructionInvariants(mlir::Location, mlir::Type eleTy,
   return mlir::success();
 }
 
-// BoxProc<T>
-
-BoxProcType fir::BoxProcType::get(mlir::Type elementType) {
-  return Base::get(elementType.getContext(), elementType);
-}
-
-mlir::Type fir::BoxProcType::getEleTy() const {
-  return getImpl()->getElementType();
-}
-
-mlir::LogicalResult
-fir::BoxProcType::verifyConstructionInvariants(mlir::Location loc,
-                                               mlir::Type eleTy) {
-  if (eleTy.isa<mlir::FunctionType>())
-    return mlir::success();
-  if (auto refTy = eleTy.dyn_cast<ReferenceType>())
-    if (refTy.isa<mlir::FunctionType>())
-      return mlir::success();
-  return mlir::emitError(loc, "invalid type for boxproc") << eleTy << '\n';
-}
-
 // Reference<T>
 
 ReferenceType fir::ReferenceType::get(mlir::Type elementType) {
@@ -1132,12 +1081,6 @@ void fir::verifyIntegralType(mlir::Type type) {
 void fir::printFirType(FIROpsDialect *, mlir::Type ty,
                        mlir::DialectAsmPrinter &p) {
   auto &os = p.getStream();
-  if (auto type = ty.dyn_cast<BoxProcType>()) {
-    os << "boxproc<";
-    p.printType(type.getEleTy());
-    os << '>';
-    return;
-  }
   if (auto type = ty.dyn_cast<fir::ComplexType>()) {
     // Fortran intrinsic type COMPLEX
     os << "complex<" << type.getFKind() << '>';
@@ -1260,6 +1203,32 @@ bool fir::isa_unknown_size_box(mlir::Type t) {
   return false;
 }
 
+//===----------------------------------------------------------------------===//
+// BoxProcType
+//===----------------------------------------------------------------------===//
+
+// `boxproc` `<` return-type `>`
+mlir::Type BoxProcType::parse(mlir::MLIRContext *context,
+                              mlir::DialectAsmParser &parser) {
+  mlir::Type ty;
+  if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) {
+    parser.emitError(parser.getCurrentLocation(), "type expected");
+    return Type();
+  }
+  return get(context, ty);
+}
+
+mlir::LogicalResult
+BoxProcType::verifyConstructionInvariants(mlir::Location loc,
+                                          mlir::Type eleTy) {
+  if (eleTy.isa<mlir::FunctionType>())
+    return mlir::success();
+  if (auto refTy = eleTy.dyn_cast<ReferenceType>())
+    if (refTy.isa<mlir::FunctionType>())
+      return mlir::success();
+  return mlir::emitError(loc, "invalid type for boxproc") << eleTy << '\n';
+}
+
 //===----------------------------------------------------------------------===//
 // BoxType
 //===----------------------------------------------------------------------===//


        


More information about the flang-commits mailing list