[flang][fir][NFC] Merge tablegen files.
Differential Revision: https://reviews.llvm.org/D96908
GitOrigin-RevId: 930150781da15f93811568760a60c7319de916b5
diff --git a/include/flang/Optimizer/Dialect/FIRDialect.td b/include/flang/Optimizer/Dialect/FIRDialect.td
new file mode 100644
index 0000000..0510848
--- /dev/null
+++ b/include/flang/Optimizer/Dialect/FIRDialect.td
@@ -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
diff --git a/include/flang/Optimizer/Dialect/FIROps.td b/include/flang/Optimizer/Dialect/FIROps.td
index afc1fa5..bff6e92 100644
--- a/include/flang/Optimizer/Dialect/FIROps.td
+++ b/include/flang/Optimizer/Dialect/FIROps.td
@@ -20,11 +20,6 @@
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 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 @@
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 @@
```
}];
- let arguments = (ins BoxType:$box);
+ let arguments = (ins fir_BoxType:$box);
let results = (outs
fir_ReferenceType, // pointer to data
@@ -1348,7 +1343,7 @@
```
}];
- let arguments = (ins BoxType:$val);
+ let arguments = (ins fir_BoxType:$val);
let results = (outs AnyReferenceLike);
@@ -1392,7 +1387,7 @@
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 @@
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 @@
variable is an `ALLOCATABLE`.
}];
- let arguments = (ins BoxType:$val);
+ let arguments = (ins fir_BoxType:$val);
let results = (outs BoolLike);
}
@@ -1465,7 +1460,7 @@
```
}];
- let arguments = (ins BoxType:$val);
+ let arguments = (ins fir_BoxType:$val);
let results = (outs BoolLike);
}
@@ -1483,7 +1478,7 @@
```
}];
- let arguments = (ins BoxType:$val);
+ let arguments = (ins fir_BoxType:$val);
let results = (outs BoolLike);
}
@@ -1527,7 +1522,7 @@
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 @@
```
}];
- let arguments = (ins BoxType:$val);
+ let arguments = (ins fir_BoxType:$val);
let results = (outs fir_TypeDescType);
}
@@ -1606,7 +1601,7 @@
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 @@
let arguments = (ins
StrAttr:$method,
- BoxType:$object,
+ fir_BoxType:$object,
Variadic<AnyType>:$args
);
diff --git a/include/flang/Optimizer/Dialect/FIRTypes.td b/include/flang/Optimizer/Dialect/FIRTypes.td
index 75bf89f..ab9bbd6 100644
--- a/include/flang/Optimizer/Dialect/FIRTypes.td
+++ b/include/flang/Optimizer/Dialect/FIRTypes.td
@@ -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 @@
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 @@
}];
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 @@
}];
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_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 @@
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);
}];
}