Skip to content

Commit 61b8a3e

Browse files
committed
[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
1 parent 209bc67 commit 61b8a3e

File tree

4 files changed

+50
-77
lines changed

4 files changed

+50
-77
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@ def fir_PointerType : Type<CPred<"$_self.isa<fir::PointerType>()">,
8282
def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
8383
fir_HeapType.predicate, fir_PointerType.predicate]>, "any reference">;
8484

85-
// PROCEDURE POINTER descriptor. A pair that can capture a host closure.
86-
def fir_BoxProcType : Type<CPred<"$_self.isa<fir::BoxProcType>()">,
87-
"box procedure type">;
88-
8985
def AnyBoxLike : TypeConstraint<Or<[BoxType.predicate,
9086
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
9187

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class FIROpsDialect;
4242
using KindTy = unsigned;
4343

4444
namespace detail {
45-
struct BoxProcTypeStorage;
4645
struct ComplexTypeStorage;
4746
struct HeapTypeStorage;
4847
struct IntegerTypeStorage;
@@ -143,20 +142,6 @@ class RealType : public mlir::Type::TypeBase<RealType, mlir::Type,
143142

144143
// FIR support types
145144

146-
/// The type of a pair that describes a PROCEDURE reference. Pointers to
147-
/// internal procedures must carry an additional reference to the host's
148-
/// variables that are referenced.
149-
class BoxProcType : public mlir::Type::TypeBase<BoxProcType, mlir::Type,
150-
detail::BoxProcTypeStorage> {
151-
public:
152-
using Base::Base;
153-
static BoxProcType get(mlir::Type eleTy);
154-
mlir::Type getEleTy() const;
155-
156-
static mlir::LogicalResult verifyConstructionInvariants(mlir::Location,
157-
mlir::Type eleTy);
158-
};
159-
160145
/// Type of a vector that represents an array slice operation on an array.
161146
/// Fortran slices are triples of lower bound, upper bound, and stride. The rank
162147
/// of a SliceType must be at least 1.

flang/include/flang/Optimizer/Dialect/FIRTypes.td

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
2121
let mnemonic = typeMnemonic;
2222
}
2323

24+
def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
25+
let summary = "";
26+
27+
let description = [{
28+
The type of a pair that describes a PROCEDURE reference. Pointers to
29+
internal procedures must carry an additional reference to the host's
30+
variables that are referenced.
31+
}];
32+
33+
let parameters = (ins "mlir::Type":$eleTy);
34+
35+
let printer = [{
36+
$_printer << "boxproc<";
37+
$_printer.printType(getEleTy());
38+
$_printer << '>';
39+
}];
40+
41+
let genAccessors = 1;
42+
43+
let genVerifyInvariantsDecl = 1;
44+
}
45+
2446
def BoxType : FIR_Type<"Box", "box"> {
2547
let summary = "The type of a Fortran descriptor";
2648

@@ -41,6 +63,7 @@ def BoxType : FIR_Type<"Box", "box"> {
4163
}];
4264

4365
let genAccessors = 1;
66+
4467
let genVerifyInvariantsDecl = 1;
4568
}
4669

flang/lib/Optimizer/Dialect/FIRType.cpp

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
5858
return TYPE::get(ty);
5959
}
6060

61-
// `boxproc` `<` return-type `>`
62-
BoxProcType parseBoxProc(mlir::DialectAsmParser &parser, mlir::Location loc) {
63-
return parseTypeSingleton<BoxProcType>(parser, loc);
64-
}
65-
6661
// `complex` `<` kind `>`
6762
fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) {
6863
return parseKindSingleton<fir::ComplexType>(parser);
@@ -310,7 +305,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
310305
if (typeNameLit == "boxchar")
311306
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
312307
if (typeNameLit == "boxproc")
313-
return parseBoxProc(parser, loc);
308+
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
314309
if (typeNameLit == "char")
315310
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
316311
if (typeNameLit == "complex")
@@ -493,31 +488,6 @@ struct RealTypeStorage : public mlir::TypeStorage {
493488
explicit RealTypeStorage(KindTy kind) : kind{kind} {}
494489
};
495490

496-
/// Boxed PROCEDURE POINTER object type
497-
struct BoxProcTypeStorage : public mlir::TypeStorage {
498-
using KeyTy = mlir::Type;
499-
500-
static unsigned hashKey(const KeyTy &key) { return llvm::hash_combine(key); }
501-
502-
bool operator==(const KeyTy &key) const { return key == getElementType(); }
503-
504-
static BoxProcTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
505-
mlir::Type eleTy) {
506-
assert(eleTy && "element type is null");
507-
auto *storage = allocator.allocate<BoxProcTypeStorage>();
508-
return new (storage) BoxProcTypeStorage{eleTy};
509-
}
510-
511-
mlir::Type getElementType() const { return eleTy; }
512-
513-
protected:
514-
mlir::Type eleTy;
515-
516-
private:
517-
BoxProcTypeStorage() = delete;
518-
explicit BoxProcTypeStorage(mlir::Type eleTy) : eleTy{eleTy} {}
519-
};
520-
521491
/// Pointer-like object storage
522492
struct ReferenceTypeStorage : public mlir::TypeStorage {
523493
using KeyTy = mlir::Type;
@@ -836,27 +806,6 @@ fir::BoxType::verifyConstructionInvariants(mlir::Location, mlir::Type eleTy,
836806
return mlir::success();
837807
}
838808

839-
// BoxProc<T>
840-
841-
BoxProcType fir::BoxProcType::get(mlir::Type elementType) {
842-
return Base::get(elementType.getContext(), elementType);
843-
}
844-
845-
mlir::Type fir::BoxProcType::getEleTy() const {
846-
return getImpl()->getElementType();
847-
}
848-
849-
mlir::LogicalResult
850-
fir::BoxProcType::verifyConstructionInvariants(mlir::Location loc,
851-
mlir::Type eleTy) {
852-
if (eleTy.isa<mlir::FunctionType>())
853-
return mlir::success();
854-
if (auto refTy = eleTy.dyn_cast<ReferenceType>())
855-
if (refTy.isa<mlir::FunctionType>())
856-
return mlir::success();
857-
return mlir::emitError(loc, "invalid type for boxproc") << eleTy << '\n';
858-
}
859-
860809
// Reference<T>
861810

862811
ReferenceType fir::ReferenceType::get(mlir::Type elementType) {
@@ -1132,12 +1081,6 @@ void fir::verifyIntegralType(mlir::Type type) {
11321081
void fir::printFirType(FIROpsDialect *, mlir::Type ty,
11331082
mlir::DialectAsmPrinter &p) {
11341083
auto &os = p.getStream();
1135-
if (auto type = ty.dyn_cast<BoxProcType>()) {
1136-
os << "boxproc<";
1137-
p.printType(type.getEleTy());
1138-
os << '>';
1139-
return;
1140-
}
11411084
if (auto type = ty.dyn_cast<fir::ComplexType>()) {
11421085
// Fortran intrinsic type COMPLEX
11431086
os << "complex<" << type.getFKind() << '>';
@@ -1260,6 +1203,32 @@ bool fir::isa_unknown_size_box(mlir::Type t) {
12601203
return false;
12611204
}
12621205

1206+
//===----------------------------------------------------------------------===//
1207+
// BoxProcType
1208+
//===----------------------------------------------------------------------===//
1209+
1210+
// `boxproc` `<` return-type `>`
1211+
mlir::Type BoxProcType::parse(mlir::MLIRContext *context,
1212+
mlir::DialectAsmParser &parser) {
1213+
mlir::Type ty;
1214+
if (parser.parseLess() || parser.parseType(ty) || parser.parseGreater()) {
1215+
parser.emitError(parser.getCurrentLocation(), "type expected");
1216+
return Type();
1217+
}
1218+
return get(context, ty);
1219+
}
1220+
1221+
mlir::LogicalResult
1222+
BoxProcType::verifyConstructionInvariants(mlir::Location loc,
1223+
mlir::Type eleTy) {
1224+
if (eleTy.isa<mlir::FunctionType>())
1225+
return mlir::success();
1226+
if (auto refTy = eleTy.dyn_cast<ReferenceType>())
1227+
if (refTy.isa<mlir::FunctionType>())
1228+
return mlir::success();
1229+
return mlir::emitError(loc, "invalid type for boxproc") << eleTy << '\n';
1230+
}
1231+
12631232
//===----------------------------------------------------------------------===//
12641233
// BoxType
12651234
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)