forked from OSchip/llvm-project
Revert "[flang][fir][NFC] Move BoxType to TableGen type definition"
This reverts commit d96bb48f78
.
This commit is contained in:
parent
a260ae7160
commit
661f9e2a92
|
@ -9,7 +9,6 @@
|
||||||
#ifndef OPTIMIZER_DIALECT_FIROPS_H
|
#ifndef OPTIMIZER_DIALECT_FIROPS_H
|
||||||
#define OPTIMIZER_DIALECT_FIROPS_H
|
#define OPTIMIZER_DIALECT_FIROPS_H
|
||||||
|
|
||||||
#include "flang/Optimizer/Dialect/FIRType.h"
|
|
||||||
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
#include "mlir/Dialect/StandardOps/IR/Ops.h"
|
||||||
#include "mlir/Interfaces/LoopLikeInterface.h"
|
#include "mlir/Interfaces/LoopLikeInterface.h"
|
||||||
#include "mlir/Interfaces/SideEffectInterfaces.h"
|
#include "mlir/Interfaces/SideEffectInterfaces.h"
|
||||||
|
|
|
@ -83,6 +83,9 @@ 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">;
|
||||||
|
|
||||||
|
// A descriptor tuple (captures a reference to an entity and other information)
|
||||||
|
def fir_BoxType : Type<CPred<"$_self.isa<fir::BoxType>()">, "box type">;
|
||||||
|
|
||||||
// CHARACTER type descriptor. A pair of a data reference and a LEN value.
|
// CHARACTER type descriptor. A pair of a data reference and a LEN value.
|
||||||
def fir_BoxCharType : Type<CPred<"$_self.isa<fir::BoxCharType>()">,
|
def fir_BoxCharType : Type<CPred<"$_self.isa<fir::BoxCharType>()">,
|
||||||
"box character type">;
|
"box character type">;
|
||||||
|
@ -91,11 +94,11 @@ def fir_BoxCharType : Type<CPred<"$_self.isa<fir::BoxCharType>()">,
|
||||||
def fir_BoxProcType : Type<CPred<"$_self.isa<fir::BoxProcType>()">,
|
def fir_BoxProcType : Type<CPred<"$_self.isa<fir::BoxProcType>()">,
|
||||||
"box procedure type">;
|
"box procedure type">;
|
||||||
|
|
||||||
def AnyBoxLike : TypeConstraint<Or<[BoxType.predicate,
|
def AnyBoxLike : TypeConstraint<Or<[fir_BoxType.predicate,
|
||||||
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
|
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
|
||||||
|
|
||||||
def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
|
def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
|
||||||
fir_HeapType.predicate, fir_PointerType.predicate, BoxType.predicate]>,
|
fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>,
|
||||||
"any reference or box">;
|
"any reference or box">;
|
||||||
|
|
||||||
def AnyShapeLike : TypeConstraint<Or<[ShapeType.predicate,
|
def AnyShapeLike : TypeConstraint<Or<[ShapeType.predicate,
|
||||||
|
@ -1045,7 +1048,7 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
|
||||||
|
|
||||||
let arguments = (ins AnyReferenceLike:$memref, Variadic<AnyEmboxArg>:$args);
|
let arguments = (ins AnyReferenceLike:$memref, Variadic<AnyEmboxArg>:$args);
|
||||||
|
|
||||||
let results = (outs BoxType);
|
let results = (outs fir_BoxType);
|
||||||
|
|
||||||
let parser = "return parseEmboxOp(parser, result);";
|
let parser = "return parseEmboxOp(parser, result);";
|
||||||
|
|
||||||
|
@ -1254,7 +1257,7 @@ def fir_UnboxOp : fir_SimpleOp<"unbox", [NoSideEffect]> {
|
||||||
```
|
```
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$box);
|
let arguments = (ins fir_BoxType:$box);
|
||||||
|
|
||||||
let results = (outs
|
let results = (outs
|
||||||
fir_ReferenceType, // pointer to data
|
fir_ReferenceType, // pointer to data
|
||||||
|
@ -1325,7 +1328,7 @@ def fir_BoxAddrOp : fir_SimpleOneResultOp<"box_addr", [NoSideEffect]> {
|
||||||
```
|
```
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs AnyReferenceLike);
|
let results = (outs AnyReferenceLike);
|
||||||
|
|
||||||
|
@ -1369,7 +1372,7 @@ def fir_BoxDimsOp : fir_Op<"box_dims", [NoSideEffect]> {
|
||||||
the box. The triple will be the lower bound, upper bound, and stride.
|
the box. The triple will be the lower bound, upper bound, and stride.
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val, AnyIntegerLike:$dim);
|
let arguments = (ins fir_BoxType:$val, AnyIntegerLike:$dim);
|
||||||
|
|
||||||
let results = (outs AnyIntegerLike, AnyIntegerLike, AnyIntegerLike);
|
let results = (outs AnyIntegerLike, AnyIntegerLike, AnyIntegerLike);
|
||||||
|
|
||||||
|
@ -1398,7 +1401,7 @@ def fir_BoxEleSizeOp : fir_SimpleOneResultOp<"box_elesize", [NoSideEffect]> {
|
||||||
must box an array of REAL values (with dynamic rank and extent).
|
must box an array of REAL values (with dynamic rank and extent).
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs AnyIntegerLike);
|
let results = (outs AnyIntegerLike);
|
||||||
}
|
}
|
||||||
|
@ -1421,7 +1424,7 @@ def fir_BoxIsAllocOp : fir_SimpleOp<"box_isalloc", [NoSideEffect]> {
|
||||||
variable is an `ALLOCATABLE`.
|
variable is an `ALLOCATABLE`.
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs BoolLike);
|
let results = (outs BoolLike);
|
||||||
}
|
}
|
||||||
|
@ -1442,7 +1445,7 @@ def fir_BoxIsArrayOp : fir_SimpleOp<"box_isarray", [NoSideEffect]> {
|
||||||
```
|
```
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs BoolLike);
|
let results = (outs BoolLike);
|
||||||
}
|
}
|
||||||
|
@ -1460,7 +1463,7 @@ def fir_BoxIsPtrOp : fir_SimpleOp<"box_isptr", [NoSideEffect]> {
|
||||||
```
|
```
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs BoolLike);
|
let results = (outs BoolLike);
|
||||||
}
|
}
|
||||||
|
@ -1504,7 +1507,7 @@ def fir_BoxRankOp : fir_SimpleOneResultOp<"box_rank", [NoSideEffect]> {
|
||||||
descriptor may be either an array or a scalar, so the value is nonnegative.
|
descriptor may be either an array or a scalar, so the value is nonnegative.
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs AnyIntegerType);
|
let results = (outs AnyIntegerType);
|
||||||
}
|
}
|
||||||
|
@ -1522,7 +1525,7 @@ def fir_BoxTypeDescOp : fir_SimpleOneResultOp<"box_tdesc", [NoSideEffect]> {
|
||||||
```
|
```
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let arguments = (ins BoxType:$val);
|
let arguments = (ins fir_BoxType:$val);
|
||||||
|
|
||||||
let results = (outs fir_TypeDescType);
|
let results = (outs fir_TypeDescType);
|
||||||
}
|
}
|
||||||
|
@ -2097,7 +2100,7 @@ def fir_DispatchOp : fir_Op<"dispatch",
|
||||||
|
|
||||||
let arguments = (ins
|
let arguments = (ins
|
||||||
StrAttr:$method,
|
StrAttr:$method,
|
||||||
BoxType:$object,
|
fir_BoxType:$object,
|
||||||
Variadic<AnyType>:$args
|
Variadic<AnyType>:$args
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ class FIROpsDialect;
|
||||||
using KindTy = unsigned;
|
using KindTy = unsigned;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
struct BoxTypeStorage;
|
||||||
struct BoxCharTypeStorage;
|
struct BoxCharTypeStorage;
|
||||||
struct BoxProcTypeStorage;
|
struct BoxProcTypeStorage;
|
||||||
struct CharacterTypeStorage;
|
struct CharacterTypeStorage;
|
||||||
|
@ -177,6 +178,23 @@ public:
|
||||||
|
|
||||||
// FIR support types
|
// FIR support types
|
||||||
|
|
||||||
|
/// The type of a Fortran descriptor. Descriptors are tuples of information that
|
||||||
|
/// describe an entity being passed from a calling context. This information
|
||||||
|
/// might include (but is not limited to) whether the entity is an array, its
|
||||||
|
/// size, or what type it has.
|
||||||
|
class BoxType
|
||||||
|
: public mlir::Type::TypeBase<BoxType, mlir::Type, detail::BoxTypeStorage> {
|
||||||
|
public:
|
||||||
|
using Base::Base;
|
||||||
|
static BoxType get(mlir::Type eleTy, mlir::AffineMapAttr map = {});
|
||||||
|
mlir::Type getEleTy() const;
|
||||||
|
mlir::AffineMapAttr getLayoutMap() const;
|
||||||
|
|
||||||
|
static mlir::LogicalResult
|
||||||
|
verifyConstructionInvariants(mlir::Location, mlir::Type eleTy,
|
||||||
|
mlir::AffineMapAttr map);
|
||||||
|
};
|
||||||
|
|
||||||
/// The type of a pair that describes a CHARACTER variable. Specifically, a
|
/// The type of a pair that describes a CHARACTER variable. Specifically, a
|
||||||
/// CHARACTER consists of a reference to a buffer (the string value) and a LEN
|
/// CHARACTER consists of a reference to a buffer (the string value) and a LEN
|
||||||
/// type parameter (the runtime length of the buffer).
|
/// type parameter (the runtime length of the buffer).
|
||||||
|
|
|
@ -21,29 +21,6 @@ class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
|
||||||
let mnemonic = typeMnemonic;
|
let mnemonic = typeMnemonic;
|
||||||
}
|
}
|
||||||
|
|
||||||
def BoxType : FIR_Type<"Box", "box"> {
|
|
||||||
let summary = "The type of a Fortran descriptor";
|
|
||||||
|
|
||||||
let description = [{
|
|
||||||
Descriptors are tuples of information that describe an entity being passed
|
|
||||||
from a calling context. This information might include (but is not limited
|
|
||||||
to) whether the entity is an array, its size, or what type it has.
|
|
||||||
}];
|
|
||||||
|
|
||||||
let parameters = (ins "mlir::Type":$eleTy, "mlir::AffineMapAttr":$map);
|
|
||||||
|
|
||||||
let extraClassDeclaration = [{
|
|
||||||
mlir::Type getElementType() const { return getEleTy(); }
|
|
||||||
mlir::AffineMapAttr getLayoutMap() const { return getMap(); }
|
|
||||||
static BoxType get(mlir::Type eleTy, mlir::AffineMapAttr map = {}) {
|
|
||||||
return get(eleTy, map);
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
|
|
||||||
let genAccessors = 1;
|
|
||||||
let genVerifyInvariantsDecl = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
def ShapeType : FIR_Type<"Shape", "shape"> {
|
def ShapeType : FIR_Type<"Shape", "shape"> {
|
||||||
let summary = "shape of a multidimensional array object";
|
let summary = "shape of a multidimensional array object";
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,27 @@ TYPE parseTypeSingleton(mlir::DialectAsmParser &parser, mlir::Location) {
|
||||||
return TYPE::get(ty);
|
return TYPE::get(ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `box` `<` type (',' affine-map)? `>`
|
||||||
|
BoxType parseBox(mlir::DialectAsmParser &parser, mlir::Location loc) {
|
||||||
|
mlir::Type ofTy;
|
||||||
|
if (parser.parseLess() || parser.parseType(ofTy)) {
|
||||||
|
parser.emitError(parser.getCurrentLocation(), "expected type parameter");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
mlir::AffineMapAttr map;
|
||||||
|
if (!parser.parseOptionalComma())
|
||||||
|
if (parser.parseAttribute(map)) {
|
||||||
|
parser.emitError(parser.getCurrentLocation(), "expected affine map");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (parser.parseGreater()) {
|
||||||
|
parser.emitError(parser.getCurrentLocation(), "expected '>'");
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return BoxType::get(ofTy, map);
|
||||||
|
}
|
||||||
|
|
||||||
// `boxchar` `<` kind `>`
|
// `boxchar` `<` kind `>`
|
||||||
BoxCharType parseBoxChar(mlir::DialectAsmParser &parser) {
|
BoxCharType parseBoxChar(mlir::DialectAsmParser &parser) {
|
||||||
return parseKindSingleton<BoxCharType>(parser);
|
return parseKindSingleton<BoxCharType>(parser);
|
||||||
|
@ -334,7 +355,7 @@ mlir::Type fir::parseFirType(FIROpsDialect *dialect,
|
||||||
if (typeNameLit == "array")
|
if (typeNameLit == "array")
|
||||||
return parseSequence(parser, loc);
|
return parseSequence(parser, loc);
|
||||||
if (typeNameLit == "box")
|
if (typeNameLit == "box")
|
||||||
return generatedTypeParser(dialect->getContext(), parser, typeNameLit);
|
return parseBox(parser, loc);
|
||||||
if (typeNameLit == "boxchar")
|
if (typeNameLit == "boxchar")
|
||||||
return parseBoxChar(parser);
|
return parseBoxChar(parser);
|
||||||
if (typeNameLit == "boxproc")
|
if (typeNameLit == "boxproc")
|
||||||
|
@ -573,6 +594,41 @@ private:
|
||||||
explicit RealTypeStorage(KindTy kind) : kind{kind} {}
|
explicit RealTypeStorage(KindTy kind) : kind{kind} {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Boxed object (a Fortran descriptor)
|
||||||
|
struct BoxTypeStorage : public mlir::TypeStorage {
|
||||||
|
using KeyTy = std::tuple<mlir::Type, mlir::AffineMapAttr>;
|
||||||
|
|
||||||
|
static unsigned hashKey(const KeyTy &key) {
|
||||||
|
auto hashVal{llvm::hash_combine(std::get<mlir::Type>(key))};
|
||||||
|
return llvm::hash_combine(
|
||||||
|
hashVal, llvm::hash_combine(std::get<mlir::AffineMapAttr>(key)));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const KeyTy &key) const {
|
||||||
|
return std::get<mlir::Type>(key) == getElementType() &&
|
||||||
|
std::get<mlir::AffineMapAttr>(key) == getLayoutMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
static BoxTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
|
||||||
|
const KeyTy &key) {
|
||||||
|
auto *storage = allocator.allocate<BoxTypeStorage>();
|
||||||
|
return new (storage) BoxTypeStorage{std::get<mlir::Type>(key),
|
||||||
|
std::get<mlir::AffineMapAttr>(key)};
|
||||||
|
}
|
||||||
|
|
||||||
|
mlir::Type getElementType() const { return eleTy; }
|
||||||
|
mlir::AffineMapAttr getLayoutMap() const { return map; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
mlir::Type eleTy;
|
||||||
|
mlir::AffineMapAttr map;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BoxTypeStorage() = delete;
|
||||||
|
explicit BoxTypeStorage(mlir::Type eleTy, mlir::AffineMapAttr map)
|
||||||
|
: eleTy{eleTy}, map{map} {}
|
||||||
|
};
|
||||||
|
|
||||||
/// Boxed CHARACTER object type
|
/// Boxed CHARACTER object type
|
||||||
struct BoxCharTypeStorage : public mlir::TypeStorage {
|
struct BoxCharTypeStorage : public mlir::TypeStorage {
|
||||||
using KeyTy = KindTy;
|
using KeyTy = KindTy;
|
||||||
|
@ -957,6 +1013,20 @@ RealType fir::RealType::get(mlir::MLIRContext *ctxt, KindTy kind) {
|
||||||
|
|
||||||
KindTy fir::RealType::getFKind() const { return getImpl()->getFKind(); }
|
KindTy fir::RealType::getFKind() const { return getImpl()->getFKind(); }
|
||||||
|
|
||||||
|
// Box<T>
|
||||||
|
|
||||||
|
BoxType fir::BoxType::get(mlir::Type elementType, mlir::AffineMapAttr map) {
|
||||||
|
return Base::get(elementType.getContext(), elementType, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
mlir::Type fir::BoxType::getEleTy() const {
|
||||||
|
return getImpl()->getElementType();
|
||||||
|
}
|
||||||
|
|
||||||
|
mlir::AffineMapAttr fir::BoxType::getLayoutMap() const {
|
||||||
|
return getImpl()->getLayoutMap();
|
||||||
|
}
|
||||||
|
|
||||||
mlir::LogicalResult
|
mlir::LogicalResult
|
||||||
fir::BoxType::verifyConstructionInvariants(mlir::Location, mlir::Type eleTy,
|
fir::BoxType::verifyConstructionInvariants(mlir::Location, mlir::Type eleTy,
|
||||||
mlir::AffineMapAttr map) {
|
mlir::AffineMapAttr map) {
|
||||||
|
@ -1270,6 +1340,16 @@ 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<BoxType>()) {
|
||||||
|
os << "box<";
|
||||||
|
p.printType(type.getEleTy());
|
||||||
|
if (auto map = type.getLayoutMap()) {
|
||||||
|
os << ", ";
|
||||||
|
p.printAttribute(map);
|
||||||
|
}
|
||||||
|
os << '>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (auto type = ty.dyn_cast<BoxCharType>()) {
|
if (auto type = ty.dyn_cast<BoxCharType>()) {
|
||||||
os << "boxchar<" << type.getEleTy().cast<fir::CharacterType>().getFKind()
|
os << "boxchar<" << type.getEleTy().cast<fir::CharacterType>().getFKind()
|
||||||
<< '>';
|
<< '>';
|
||||||
|
@ -1420,44 +1500,3 @@ bool fir::isa_unknown_size_box(mlir::Type t) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace fir {
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
// BoxType
|
|
||||||
//===----------------------------------------------------------------------===//
|
|
||||||
|
|
||||||
// `box` `<` type (',' affine-map)? `>`
|
|
||||||
mlir::Type BoxType::parse(mlir::MLIRContext *context,
|
|
||||||
mlir::DialectAsmParser &parser) {
|
|
||||||
mlir::Type ofTy;
|
|
||||||
if (parser.parseLess() || parser.parseType(ofTy)) {
|
|
||||||
parser.emitError(parser.getCurrentLocation(), "expected type parameter");
|
|
||||||
return Type();
|
|
||||||
}
|
|
||||||
|
|
||||||
mlir::AffineMapAttr map;
|
|
||||||
if (!parser.parseOptionalComma()) {
|
|
||||||
if (parser.parseAttribute(map)) {
|
|
||||||
parser.emitError(parser.getCurrentLocation(), "expected affine map");
|
|
||||||
return Type();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (parser.parseGreater()) {
|
|
||||||
parser.emitError(parser.getCurrentLocation(), "expected '>'");
|
|
||||||
return Type();
|
|
||||||
}
|
|
||||||
return get(ofTy, map);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BoxType::print(::mlir::DialectAsmPrinter &printer) const {
|
|
||||||
printer << "box<";
|
|
||||||
printer.printType(getEleTy());
|
|
||||||
if (auto map = getLayoutMap()) {
|
|
||||||
printer << ", ";
|
|
||||||
printer.printAttribute(map);
|
|
||||||
}
|
|
||||||
printer << '>';
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace fir
|
|
||||||
|
|
Loading…
Reference in New Issue