Skip to content

Commit 9301507

Browse files
committed
[flang][fir][NFC] Merge tablegen files.
Differential Revision: https://reviews.llvm.org/D96908
1 parent 78eabca commit 9301507

File tree

3 files changed

+128
-90
lines changed

3 files changed

+128
-90
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//===-- FIRDialect.td - FIR dialect definition -------------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file
10+
/// Definition of the FIR dialect
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef FORTRAN_DIALECT_FIR_DIALECT
15+
#define FORTRAN_DIALECT_FIR_DIALECT
16+
17+
def fir_Dialect : Dialect {
18+
let name = "fir";
19+
let cppNamespace = "::fir";
20+
}
21+
22+
#endif // FORTRAN_DIALECT_FIR_DIALECT

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

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ include "mlir/Interfaces/ControlFlowInterfaces.td"
2020
include "mlir/Interfaces/LoopLikeInterface.td"
2121
include "mlir/Interfaces/SideEffectInterfaces.td"
2222

23-
def fir_Dialect : Dialect {
24-
let name = "fir";
25-
let cppNamespace = "::fir";
26-
}
27-
2823
include "flang/Optimizer/Dialect/FIRTypes.td"
2924

3025
// Types and predicates
@@ -80,15 +75,15 @@ def fir_PointerType : Type<CPred<"$_self.isa<fir::PointerType>()">,
8075
def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
8176
fir_HeapType.predicate, fir_PointerType.predicate]>, "any reference">;
8277

83-
def AnyBoxLike : TypeConstraint<Or<[BoxType.predicate,
78+
def AnyBoxLike : TypeConstraint<Or<[fir_BoxType.predicate,
8479
fir_BoxCharType.predicate, fir_BoxProcType.predicate]>, "any box">;
8580

8681
def AnyRefOrBox : TypeConstraint<Or<[fir_ReferenceType.predicate,
87-
fir_HeapType.predicate, fir_PointerType.predicate, BoxType.predicate]>,
82+
fir_HeapType.predicate, fir_PointerType.predicate, fir_BoxType.predicate]>,
8883
"any reference or box">;
8984

90-
def AnyShapeLike : TypeConstraint<Or<[ShapeType.predicate,
91-
ShapeShiftType.predicate]>, "any legal shape type">;
85+
def AnyShapeLike : TypeConstraint<Or<[fir_ShapeType.predicate,
86+
fir_ShapeShiftType.predicate]>, "any legal shape type">;
9287
def AnyShapeType : Type<AnyShapeLike.predicate, "any legal shape type">;
9388
def fir_SliceType : Type<CPred<"$_self.isa<fir::SliceType>()">, "slice type">;
9489

@@ -1068,7 +1063,7 @@ def fir_EmboxOp : fir_Op<"embox", [NoSideEffect]> {
10681063

10691064
let arguments = (ins AnyReferenceLike:$memref, Variadic<AnyEmboxArg>:$args);
10701065

1071-
let results = (outs BoxType);
1066+
let results = (outs fir_BoxType);
10721067

10731068
let parser = "return parseEmboxOp(parser, result);";
10741069

@@ -1277,7 +1272,7 @@ def fir_UnboxOp : fir_SimpleOp<"unbox", [NoSideEffect]> {
12771272
```
12781273
}];
12791274

1280-
let arguments = (ins BoxType:$box);
1275+
let arguments = (ins fir_BoxType:$box);
12811276

12821277
let results = (outs
12831278
fir_ReferenceType, // pointer to data
@@ -1348,7 +1343,7 @@ def fir_BoxAddrOp : fir_SimpleOneResultOp<"box_addr", [NoSideEffect]> {
13481343
```
13491344
}];
13501345

1351-
let arguments = (ins BoxType:$val);
1346+
let arguments = (ins fir_BoxType:$val);
13521347

13531348
let results = (outs AnyReferenceLike);
13541349

@@ -1392,7 +1387,7 @@ def fir_BoxDimsOp : fir_Op<"box_dims", [NoSideEffect]> {
13921387
the box. The triple will be the lower bound, upper bound, and stride.
13931388
}];
13941389

1395-
let arguments = (ins BoxType:$val, AnyIntegerLike:$dim);
1390+
let arguments = (ins fir_BoxType:$val, AnyIntegerLike:$dim);
13961391

13971392
let results = (outs AnyIntegerLike, AnyIntegerLike, AnyIntegerLike);
13981393

@@ -1421,7 +1416,7 @@ def fir_BoxEleSizeOp : fir_SimpleOneResultOp<"box_elesize", [NoSideEffect]> {
14211416
must box an array of REAL values (with dynamic rank and extent).
14221417
}];
14231418

1424-
let arguments = (ins BoxType:$val);
1419+
let arguments = (ins fir_BoxType:$val);
14251420

14261421
let results = (outs AnyIntegerLike);
14271422
}
@@ -1444,7 +1439,7 @@ def fir_BoxIsAllocOp : fir_SimpleOp<"box_isalloc", [NoSideEffect]> {
14441439
variable is an `ALLOCATABLE`.
14451440
}];
14461441

1447-
let arguments = (ins BoxType:$val);
1442+
let arguments = (ins fir_BoxType:$val);
14481443

14491444
let results = (outs BoolLike);
14501445
}
@@ -1465,7 +1460,7 @@ def fir_BoxIsArrayOp : fir_SimpleOp<"box_isarray", [NoSideEffect]> {
14651460
```
14661461
}];
14671462

1468-
let arguments = (ins BoxType:$val);
1463+
let arguments = (ins fir_BoxType:$val);
14691464

14701465
let results = (outs BoolLike);
14711466
}
@@ -1483,7 +1478,7 @@ def fir_BoxIsPtrOp : fir_SimpleOp<"box_isptr", [NoSideEffect]> {
14831478
```
14841479
}];
14851480

1486-
let arguments = (ins BoxType:$val);
1481+
let arguments = (ins fir_BoxType:$val);
14871482

14881483
let results = (outs BoolLike);
14891484
}
@@ -1527,7 +1522,7 @@ def fir_BoxRankOp : fir_SimpleOneResultOp<"box_rank", [NoSideEffect]> {
15271522
descriptor may be either an array or a scalar, so the value is nonnegative.
15281523
}];
15291524

1530-
let arguments = (ins BoxType:$val);
1525+
let arguments = (ins fir_BoxType:$val);
15311526

15321527
let results = (outs AnyIntegerType);
15331528
}
@@ -1545,7 +1540,7 @@ def fir_BoxTypeDescOp : fir_SimpleOneResultOp<"box_tdesc", [NoSideEffect]> {
15451540
```
15461541
}];
15471542

1548-
let arguments = (ins BoxType:$val);
1543+
let arguments = (ins fir_BoxType:$val);
15491544

15501545
let results = (outs fir_TypeDescType);
15511546
}
@@ -1606,7 +1601,7 @@ def fir_CoordinateOp : fir_Op<"coordinate_of", [NoSideEffect]> {
16061601
if (dyn_cast_or_null<LenParamIndexOp>(co.getDefiningOp())) {
16071602
if (getNumOperands() != 2)
16081603
return emitOpError("len_param_index must be last argument");
1609-
if (!ref().getType().dyn_cast<BoxType>())
1604+
if (!ref().getType().dyn_cast<fir::BoxType>())
16101605
return emitOpError("len_param_index must be used on box type");
16111606
}
16121607
if (auto attr = (*this)->getAttr(CoordinateOp::baseType())) {
@@ -2120,7 +2115,7 @@ def fir_DispatchOp : fir_Op<"dispatch",
21202115

21212116
let arguments = (ins
21222117
StrAttr:$method,
2123-
BoxType:$object,
2118+
fir_BoxType:$object,
21242119
Variadic<AnyType>:$args
21252120
);
21262121

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

Lines changed: 90 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#ifndef FIR_DIALECT_FIR_TYPES
1414
#define FIR_DIALECT_FIR_TYPES
1515

16+
include "flang/Optimizer/Dialect/FIRDialect.td"
17+
1618
//===----------------------------------------------------------------------===//
1719
// FIR Types
1820
//===----------------------------------------------------------------------===//
@@ -21,6 +23,33 @@ class FIR_Type<string name, string typeMnemonic> : TypeDef<fir_Dialect, name> {
2123
let mnemonic = typeMnemonic;
2224
}
2325

26+
def fir_BoxCharType : FIR_Type<"BoxChar", "boxchar"> {
27+
let summary = "CHARACTER type descriptor.";
28+
29+
let description = [{
30+
The type of a pair that describes a CHARACTER variable. Specifically, a
31+
CHARACTER consists of a reference to a buffer (the string value) and a LEN
32+
type parameter (the runtime length of the buffer).
33+
}];
34+
35+
let parameters = (ins "KindTy":$kind);
36+
37+
let printer = [{
38+
$_printer << "boxchar<" << getImpl()->kind << ">";
39+
}];
40+
41+
let genAccessors = 1;
42+
43+
let extraClassDeclaration = [{
44+
using KindTy = unsigned;
45+
46+
// a !fir.boxchar<k> always wraps a !fir.char<k, ?>
47+
CharacterType getElementType(mlir::MLIRContext *context) const;
48+
49+
CharacterType getEleTy() const;
50+
}];
51+
}
52+
2453
def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
2554
let summary = "";
2655

@@ -39,11 +68,10 @@ def fir_BoxProcType : FIR_Type<"BoxProc", "boxproc"> {
3968
}];
4069

4170
let genAccessors = 1;
42-
4371
let genVerifyInvariantsDecl = 1;
4472
}
4573

46-
def BoxType : FIR_Type<"Box", "box"> {
74+
def fir_BoxType : FIR_Type<"Box", "box"> {
4775
let summary = "The type of a Fortran descriptor";
4876

4977
let description = [{
@@ -63,25 +91,39 @@ def BoxType : FIR_Type<"Box", "box"> {
6391
}];
6492

6593
let genAccessors = 1;
66-
6794
let genVerifyInvariantsDecl = 1;
6895
}
6996

70-
def fir_FieldType : FIR_Type<"Field", "field"> {
71-
let summary = "A field (in a RecordType) argument's type";
97+
def fir_CharacterType : FIR_Type<"Character", "char"> {
98+
let summary = "FIR character type";
7299

73100
let description = [{
74-
The type of a field name. Implementations may defer the layout of a Fortran
75-
derived type until runtime. This implies that the runtime must be able to
76-
determine the offset of fields within the entity.
101+
Model of the Fortran CHARACTER intrinsic type, including the KIND type
102+
parameter. The model optionally includes a LEN type parameter. A
103+
CharacterType is thus the type of both a single character value and a
104+
character with a LEN parameter.
77105
}];
78106

79-
let printer = [{
80-
$_printer << "field";
81-
}];
107+
let parameters = (ins "KindTy":$FKind, "CharacterType::LenType":$len);
82108

83-
let parser = [{
84-
return get(context);
109+
let extraClassDeclaration = [{
110+
using KindTy = unsigned;
111+
using LenType = std::int64_t;
112+
113+
// Return unknown length CHARACTER type.
114+
static CharacterType getUnknownLen(mlir::MLIRContext *ctxt, KindTy kind) {
115+
return get(ctxt, kind, unknownLen());
116+
}
117+
118+
// Return length 1 CHARACTER type.
119+
static CharacterType getSingleton(mlir::MLIRContext *ctxt, KindTy kind) {
120+
return get(ctxt, kind, singleton());
121+
}
122+
123+
// CHARACTER is a singleton and has a LEN of 1.
124+
static constexpr LenType singleton() { return 1; }
125+
// CHARACTER has an unknown LEN property.
126+
static constexpr LenType unknownLen() { return -1; }
85127
}];
86128
}
87129

@@ -109,7 +151,25 @@ def fir_ComplexType : FIR_Type<"Complex", "complex"> {
109151
}];
110152
}
111153

112-
def ShapeType : FIR_Type<"Shape", "shape"> {
154+
def fir_FieldType : FIR_Type<"Field", "field"> {
155+
let summary = "A field (in a RecordType) argument's type";
156+
157+
let description = [{
158+
The type of a field name. Implementations may defer the layout of a Fortran
159+
derived type until runtime. This implies that the runtime must be able to
160+
determine the offset of fields within the entity.
161+
}];
162+
163+
let printer = [{
164+
$_printer << "field";
165+
}];
166+
167+
let parser = [{
168+
return get(context);
169+
}];
170+
}
171+
172+
def fir_ShapeType : FIR_Type<"Shape", "shape"> {
113173
let summary = "shape of a multidimensional array object";
114174

115175
let description = [{
@@ -133,7 +193,7 @@ def ShapeType : FIR_Type<"Shape", "shape"> {
133193
}];
134194
}
135195

136-
def ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
196+
def fir_ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
137197
let summary = "shape and origin of a multidimensional array object";
138198

139199
let description = [{
@@ -150,74 +210,35 @@ def ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
150210
}];
151211

152212
let parser = [{
153-
if ($_parser.parseLess())
154-
return Type();
155213
int rank;
156-
if ($_parser.parseInteger(rank))
157-
return Type();
158-
if ($_parser.parseGreater())
214+
if ($_parser.parseLess() || $_parser.parseInteger(rank) ||
215+
$_parser.parseGreater())
159216
return Type();
160217
return get(context, rank);
161218
}];
162219
}
163220

164-
def fir_CharacterType : FIR_Type<"Character", "char"> {
165-
let summary = "FIR character type";
221+
def fir_ShiftType : FIR_Type<"Shift", "shift"> {
222+
let summary = "lower bounds of a multidimensional array object";
166223

167224
let description = [{
168-
Model of the Fortran CHARACTER intrinsic type, including the KIND type
169-
parameter. The model optionally includes a LEN type parameter. A
170-
CharacterType is thus the type of both a single character value and a
171-
character with a LEN parameter.
225+
Type of a vector of runtime values that define the lower bounds of a
226+
multidimensional array object. The vector is the lower bounds of each array
227+
dimension. The rank of a ShiftType must be at least 1.
172228
}];
173229

174-
let parameters = (ins "KindTy":$FKind, "CharacterType::LenType":$len);
175-
176-
let extraClassDeclaration = [{
177-
using KindTy = unsigned;
178-
using LenType = std::int64_t;
179-
180-
// Return unknown length CHARACTER type.
181-
static CharacterType getUnknownLen(mlir::MLIRContext *ctxt, KindTy kind) {
182-
return get(ctxt, kind, unknownLen());
183-
}
184-
185-
// Return length 1 CHARACTER type.
186-
static CharacterType getSingleton(mlir::MLIRContext *ctxt, KindTy kind) {
187-
return get(ctxt, kind, singleton());
188-
}
189-
190-
// CHARACTER is a singleton and has a LEN of 1.
191-
static constexpr LenType singleton() { return 1; }
192-
// CHARACTER has an unknown LEN property.
193-
static constexpr LenType unknownLen() { return -1; }
194-
}];
195-
}
196-
197-
def fir_BoxCharType : FIR_Type<"BoxChar", "boxchar"> {
198-
let summary = "CHARACTER type descriptor.";
199-
200-
let description = [{
201-
The type of a pair that describes a CHARACTER variable. Specifically, a
202-
CHARACTER consists of a reference to a buffer (the string value) and a LEN
203-
type parameter (the runtime length of the buffer).
204-
}];
205-
206-
let parameters = (ins "KindTy":$kind);
230+
let parameters = (ins "unsigned":$rank);
207231

208232
let printer = [{
209-
$_printer << "boxchar<" << getImpl()->kind << ">";
233+
$_printer << "shift<" << getImpl()->rank << ">";
210234
}];
211235

212-
let genAccessors = 1;
213-
214-
let extraClassDeclaration = [{
215-
using KindTy = unsigned;
216-
217-
// a !fir.boxchar<k> always wraps a !fir.char<k, ?>
218-
CharacterType getElementType(mlir::MLIRContext *context) const;
219-
220-
CharacterType getEleTy() const;
236+
let parser = [{
237+
int rank;
238+
if ($_parser.parseLess() || $_parser.parseInteger(rank) ||
239+
$_parser.parseGreater())
240+
return Type();
241+
return get(context, rank);
221242
}];
222243
}
223244

0 commit comments

Comments
 (0)