forked from OSchip/llvm-project
[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
This commit is contained in:
parent
209bc67b78
commit
61b8a3e7c5
|
@ -82,10 +82,6 @@ def fir_PointerType : Type<CPred<"$_self.isa<fir::PointerType>()">,
|
||||||
def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
|
def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
|
||||||
fir_HeapType.predicate, fir_PointerType.predicate]>, "any reference">;
|
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,
|
def AnyBoxLike : TypeConstraint<Or<[BoxType.predicate,
|
||||||
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
|
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@ class FIROpsDialect;
|
||||||
using KindTy = unsigned;
|
using KindTy = unsigned;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
struct BoxProcTypeStorage;
|
|
||||||
struct ComplexTypeStorage;
|
struct ComplexTypeStorage;
|
||||||
struct HeapTypeStorage;
|
struct HeapTypeStorage;
|
||||||
struct IntegerTypeStorage;
|
struct IntegerTypeStorage;
|
||||||
|
@ -143,20 +142,6 @@ public:
|
||||||
|
|
||||||
// FIR support types
|
// 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.
|
/// 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
|
/// Fortran slices are triples of lower bound, upper bound, and stride. The rank
|
||||||
/// of a SliceType must be at least 1.
|
/// of a SliceType must be at least 1.
|
||||||
|
|
|
@ -21,6 +21,28 @@ class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
|
||||||
let mnemonic = typeMnemonic;
|
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"> {
|
def BoxType : FIR_Type<"Box", "box"> {
|
||||||
let summary = "The type of a Fortran descriptor";
|
let summary = "The type of a Fortran descriptor";
|
||||||
|
|
||||||
|
@ -41,6 +63,7 @@ def BoxType : FIR_Type<"Box", "box"> {
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let genAccessors = 1;
|
let genAccessors = 1;
|
||||||
|
|
||||||
let genVerifyInvariantsDecl = 1;
|
let genVerifyInvariantsDecl = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,6 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
|
||||||
return TYPE::get(ty);
|
return TYPE::get(ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `boxproc` `<` return-type `>`
|
|
||||||
BoxProcType parseBoxProc(mlir::DialectAsmParser &parser, mlir::Location loc) {
|
|
||||||
return parseTypeSingleton<BoxProcType>(parser, loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
// `complex` `<` kind `>`
|
// `complex` `<` kind `>`
|
||||||
fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) {
|
fir::ComplexType parseComplex(mlir::DialectAsmParser &parser) {
|
||||||
return parseKindSingleton<fir::ComplexType>(parser);
|
return parseKindSingleton<fir::ComplexType>(parser);
|
||||||
|
@ -310,7 +305,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
|
||||||
if (typeNameLit == "boxchar")
|
if (typeNameLit == "boxchar")
|
||||||
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
|
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
|
||||||
if (typeNameLit == "boxproc")
|
if (typeNameLit == "boxproc")
|
||||||
return parseBoxProc(parser, loc);
|
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
|
||||||
if (typeNameLit == "char")
|
if (typeNameLit == "char")
|
||||||
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
|
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
|
||||||
if (typeNameLit == "complex")
|
if (typeNameLit == "complex")
|
||||||
|
@ -493,31 +488,6 @@ private:
|
||||||
explicit RealTypeStorage(KindTy kind) : kind{kind} {}
|
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
|
/// Pointer-like object storage
|
||||||
struct ReferenceTypeStorage : public mlir::TypeStorage {
|
struct ReferenceTypeStorage : public mlir::TypeStorage {
|
||||||
using KeyTy = mlir::Type;
|
using KeyTy = mlir::Type;
|
||||||
|
@ -836,27 +806,6 @@ fir::BoxType::verifyConstructionInvariants(mlir::Location, mlir::Type eleTy,
|
||||||
return mlir::success();
|
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>
|
// Reference<T>
|
||||||
|
|
||||||
ReferenceType fir::ReferenceType::get(mlir::Type elementType) {
|
ReferenceType fir::ReferenceType::get(mlir::Type elementType) {
|
||||||
|
@ -1132,12 +1081,6 @@ void fir::verifyIntegralType(mlir::Type type) {
|
||||||
void fir::printFirType(FIROpsDialect *, mlir::Type ty,
|
void fir::printFirType(FIROpsDialect *, mlir::Type ty,
|
||||||
mlir::DialectAsmPrinter &p) {
|
mlir::DialectAsmPrinter &p) {
|
||||||
auto &os = p.getStream();
|
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>()) {
|
if (auto type = ty.dyn_cast<fir::ComplexType>()) {
|
||||||
// Fortran intrinsic type COMPLEX
|
// Fortran intrinsic type COMPLEX
|
||||||
os << "complex<" << type.getFKind() << '>';
|
os << "complex<" << type.getFKind() << '>';
|
||||||
|
@ -1260,6 +1203,32 @@ bool fir::isa_unknown_size_box(mlir::Type t) {
|
||||||
return false;
|
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
|
// BoxType
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
Loading…
Reference in New Issue