[flang][fir][NFC] Merge tablegen files.

Differential Revision: https://reviews.llvm.org/D96908
This commit is contained in:
Eric Schweitz 2021-02-17 15:16:04 -08:00
parent 78eabcaa48
commit 930150781d
3 changed files with 166 additions and 128 deletions

View File

@ -0,0 +1,22 @@
//===-- FIRDialect.td - FIR dialect definition -------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// Definition of the FIR dialect
///
//===----------------------------------------------------------------------===//
#ifndef FORTRAN_DIALECT_FIR_DIALECT
#define FORTRAN_DIALECT_FIR_DIALECT
def fir_Dialect : Dialect {
let name = "fir";
let cppNamespace = "::fir";
}
#endif // FORTRAN_DIALECT_FIR_DIALECT

View File

@ -20,11 +20,6 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
def fir_Dialect : Dialect {
let name = "fir";
let cppNamespace = "::fir";
}
include "flang/Optimizer/Dialect/FIRTypes.td"
// Types and predicates
@ -80,15 +75,15 @@ def fir_PointerType : Type<CPred<"$_self.isa<fir::PointerType>()">,
def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
fir_HeapType.predicate, fir_PointerType.predicate]>, "any reference">;
def AnyBoxLike : TypeConstraint<Or<[BoxType.predicate,
def AnyBoxLike : TypeConstraint<Or<[fir_BoxType.predicate,
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
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">;
def AnyShapeLike : TypeConstraint<Or<[ShapeType.predicate,
ShapeShiftType.predicate]>, "any legal shape type">;
def AnyShapeLike : TypeConstraint<Or<[fir_ShapeType.predicate,
fir_ShapeShiftType.predicate]>, "any legal shape type">;
def AnyShapeType : Type<AnyShapeLike.predicate, "any legal shape type">;
def fir_SliceType : Type<CPred<"$_self.isa<fir::SliceType>()">, "slice type">;
@ -1068,7 +1063,7 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
let arguments = (ins AnyReferenceLike:$memref, Variadic<AnyEmboxArg>:$args);
let results = (outs BoxType);
let results = (outs fir_BoxType);
let parser = "return parseEmboxOp(parser, result);";
@ -1277,7 +1272,7 @@ def fir_UnboxOp : fir_SimpleOp<"unbox", [NoSideEffect]> {
```
}];
let arguments = (ins BoxType:$box);
let arguments = (ins fir_BoxType:$box);
let results = (outs
fir_ReferenceType, // pointer to data
@ -1348,7 +1343,7 @@ def fir_BoxAddrOp : fir_SimpleOneResultOp<"box_addr", [NoSideEffect]> {
```
}];
let arguments = (ins BoxType:$val);
let arguments = (ins fir_BoxType:$val);
let results = (outs AnyReferenceLike);
@ -1392,7 +1387,7 @@ def fir_BoxDimsOp : fir_Op<"box_dims", [NoSideEffect]> {
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);
@ -1421,7 +1416,7 @@ def fir_BoxEleSizeOp : fir_SimpleOneResultOp<"box_elesize", [NoSideEffect]> {
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);
}
@ -1444,7 +1439,7 @@ def fir_BoxIsAllocOp : fir_SimpleOp<"box_isalloc", [NoSideEffect]> {
variable is an `ALLOCATABLE`.
}];
let arguments = (ins BoxType:$val);
let arguments = (ins fir_BoxType:$val);
let results = (outs BoolLike);
}
@ -1465,7 +1460,7 @@ def fir_BoxIsArrayOp : fir_SimpleOp<"box_isarray", [NoSideEffect]> {
```
}];
let arguments = (ins BoxType:$val);
let arguments = (ins fir_BoxType:$val);
let results = (outs BoolLike);
}
@ -1483,7 +1478,7 @@ def fir_BoxIsPtrOp : fir_SimpleOp<"box_isptr", [NoSideEffect]> {
```
}];
let arguments = (ins BoxType:$val);
let arguments = (ins fir_BoxType:$val);
let results = (outs BoolLike);
}
@ -1527,7 +1522,7 @@ def fir_BoxRankOp : fir_SimpleOneResultOp<"box_rank", [NoSideEffect]> {
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);
}
@ -1545,7 +1540,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);
}
@ -1606,7 +1601,7 @@ def fir_CoordinateOp : fir_Op<"coordinate_of", [NoSideEffect]> {
if (dyn_cast_or_null<LenParamIndexOp>(co.getDefiningOp())) {
if (getNumOperands() != 2)
return emitOpError("len_param_index must be last argument");
if (!ref().getType().dyn_cast<BoxType>())
if (!ref().getType().dyn_cast<fir::BoxType>())
return emitOpError("len_param_index must be used on box type");
}
if (auto attr = (*this)->getAttr(CoordinateOp::baseType())) {
@ -2120,7 +2115,7 @@ def fir_DispatchOp : fir_Op<"dispatch",
let arguments = (ins
StrAttr:$method,
BoxType:$object,
fir_BoxType:$object,
Variadic<AnyType>:$args
);

View File

@ -13,6 +13,8 @@
#ifndef FIR_DIALECT_FIR_TYPES
#define FIR_DIALECT_FIR_TYPES
include "flang/Optimizer/Dialect/FIRDialect.td"
//===----------------------------------------------------------------------===//
// FIR Types
//===----------------------------------------------------------------------===//
@ -21,6 +23,33 @@ class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
let mnemonic = typeMnemonic;
}
def fir_BoxCharType : FIR_Type<"BoxChar", "boxchar"> {
let summary = "CHARACTER type descriptor.";
let description = [{
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
type parameter (the runtime length of the buffer).
}];
let parameters = (ins "KindTy":$kind);
let printer = [{
$_printer << "boxchar<" << getImpl()->kind << ">";
}];
let genAccessors = 1;
let extraClassDeclaration = [{
using KindTy = unsigned;
// a !fir.boxchar<k> always wraps a !fir.char<k, ?>
CharacterType getElementType(mlir::MLIRContext *context) const;
CharacterType getEleTy() const;
}];
}
def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
let summary = "";
@ -39,11 +68,10 @@ def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
}];
let genAccessors = 1;
let genVerifyInvariantsDecl = 1;
}
def BoxType : FIR_Type<"Box", "box"> {
def fir_BoxType : FIR_Type<"Box", "box"> {
let summary = "The type of a Fortran descriptor";
let description = [{
@ -63,104 +91,9 @@ def BoxType : FIR_Type<"Box", "box"> {
}];
let genAccessors = 1;
let genVerifyInvariantsDecl = 1;
}
def fir_FieldType : FIR_Type<"Field", "field"> {
let summary = "A field (in a RecordType) argument's type";
let description = [{
The type of a field name. Implementations may defer the layout of a Fortran
derived type until runtime. This implies that the runtime must be able to
determine the offset of fields within the entity.
}];
let printer = [{
$_printer << "field";
}];
let parser = [{
return get(context);
}];
}
def fir_ComplexType : FIR_Type<"Complex", "complex"> {
let summary = "Complex type";
let description = [{
Model of a Fortran COMPLEX intrinsic type, including the KIND type
parameter. COMPLEX is a floating point type with a real and imaginary
member.
}];
let parameters = (ins "KindTy":$fKind);
let printer = [{
$_printer << "complex<" << getFKind() << '>';
}];
let genAccessors = 1;
let extraClassDeclaration = [{
using KindTy = unsigned;
mlir::Type getElementType() const;
}];
}
def ShapeType : FIR_Type<"Shape", "shape"> {
let summary = "shape of a multidimensional array object";
let description = [{
Type of a vector of runtime values that define the shape of a
multidimensional array object. The vector is the extents of each array
dimension. The rank of a ShapeType must be at least 1.
}];
let parameters = (ins "unsigned":$rank);
let printer = [{
$_printer << "shape<" << getImpl()->rank << ">";
}];
let parser = [{
int rank;
if ($_parser.parseLess() || $_parser.parseInteger(rank) ||
$_parser.parseGreater())
return Type();
return get(context, rank);
}];
}
def ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
let summary = "shape and origin of a multidimensional array object";
let description = [{
Type of a vector of runtime values that define the shape and the origin of a
multidimensional array object. The vector is of pairs, origin offset and
extent, of each array dimension. The rank of a ShapeShiftType must be at
least 1.
}];
let parameters = (ins "unsigned":$rank);
let printer = [{
$_printer << "shapeshift<" << getImpl()->rank << ">";
}];
let parser = [{
if ($_parser.parseLess())
return Type();
int rank;
if ($_parser.parseInteger(rank))
return Type();
if ($_parser.parseGreater())
return Type();
return get(context, rank);
}];
}
def fir_CharacterType : FIR_Type<"Character", "char"> {
let summary = "FIR character type";
@ -194,19 +127,19 @@ def fir_CharacterType : FIR_Type<"Character", "char"> {
}];
}
def fir_BoxCharType : FIR_Type<"BoxChar", "boxchar"> {
let summary = "CHARACTER type descriptor.";
def fir_ComplexType : FIR_Type<"Complex", "complex"> {
let summary = "Complex type";
let description = [{
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
type parameter (the runtime length of the buffer).
Model of a Fortran COMPLEX intrinsic type, including the KIND type
parameter. COMPLEX is a floating point type with a real and imaginary
member.
}];
let parameters = (ins "KindTy":$kind);
let parameters = (ins "KindTy":$fKind);
let printer = [{
$_printer << "boxchar<" << getImpl()->kind << ">";
$_printer << "complex<" << getFKind() << '>';
}];
let genAccessors = 1;
@ -214,10 +147,98 @@ def fir_BoxCharType : FIR_Type<"BoxChar", "boxchar"> {
let extraClassDeclaration = [{
using KindTy = unsigned;
// a !fir.boxchar<k> always wraps a !fir.char<k, ?>
CharacterType getElementType(mlir::MLIRContext *context) const;
mlir::Type getElementType() const;
}];
}
CharacterType getEleTy() const;
def fir_FieldType : FIR_Type<"Field", "field"> {
let summary = "A field (in a RecordType) argument's type";
let description = [{
The type of a field name. Implementations may defer the layout of a Fortran
derived type until runtime. This implies that the runtime must be able to
determine the offset of fields within the entity.
}];
let printer = [{
$_printer << "field";
}];
let parser = [{
return get(context);
}];
}
def fir_ShapeType : FIR_Type<"Shape", "shape"> {
let summary = "shape of a multidimensional array object";
let description = [{
Type of a vector of runtime values that define the shape of a
multidimensional array object. The vector is the extents of each array
dimension. The rank of a ShapeType must be at least 1.
}];
let parameters = (ins "unsigned":$rank);
let printer = [{
$_printer << "shape<" << getImpl()->rank << ">";
}];
let parser = [{
int rank;
if ($_parser.parseLess() || $_parser.parseInteger(rank) ||
$_parser.parseGreater())
return Type();
return get(context, rank);
}];
}
def fir_ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
let summary = "shape and origin of a multidimensional array object";
let description = [{
Type of a vector of runtime values that define the shape and the origin of a
multidimensional array object. The vector is of pairs, origin offset and
extent, of each array dimension. The rank of a ShapeShiftType must be at
least 1.
}];
let parameters = (ins "unsigned":$rank);
let printer = [{
$_printer << "shapeshift<" << getImpl()->rank << ">";
}];
let parser = [{
int rank;
if ($_parser.parseLess() || $_parser.parseInteger(rank) ||
$_parser.parseGreater())
return Type();
return get(context, rank);
}];
}
def fir_ShiftType : FIR_Type<"Shift", "shift"> {
let summary = "lower bounds of a multidimensional array object";
let description = [{
Type of a vector of runtime values that define the lower bounds of a
multidimensional array object. The vector is the lower bounds of each array
dimension. The rank of a ShiftType must be at least 1.
}];
let parameters = (ins "unsigned":$rank);
let printer = [{
$_printer << "shift<" << getImpl()->rank << ">";
}];
let parser = [{
int rank;
if ($_parser.parseLess() || $_parser.parseInteger(rank) ||
$_parser.parseGreater())
return Type();
return get(context, rank);
}];
}