Skip to content

Commit 209bc67

Browse files
committed
[flang][fir][NFC] Move CharacterType and BoxCharType to TableGen type definition
This patch is a follow up of D96422 and move CharacterType and BoxCharType to TableGen. Reviewed By: schweitz Differential Revision: https://reviews.llvm.org/D96446
1 parent cdcb60a commit 209bc67

File tree

4 files changed

+130
-188
lines changed

4 files changed

+130
-188
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def fir_Type : Type<CPred<"fir::isa_fir_or_std_type($_self)">,
3333
"FIR dialect type">;
3434

3535
// Fortran intrinsic types
36-
def fir_CharacterType : Type<CPred<"$_self.isa<fir::CharacterType>()">,
37-
"FIR character type">;
3836
def fir_ComplexType : Type<CPred<"$_self.isa<fir::ComplexType>()">,
3937
"FIR complex type">;
4038
def fir_IntegerType : Type<CPred<"$_self.isa<fir::IntegerType>()">,
@@ -84,10 +82,6 @@ def fir_PointerType : Type<CPred<"$_self.isa<fir::PointerType>()">,
8482
def AnyReferenceLike : TypeConstraint<Or<[fir_ReferenceType.predicate,
8583
fir_HeapType.predicate, fir_PointerType.predicate]>, "any reference">;
8684

87-
// CHARACTER type descriptor. A pair of a data reference and a LEN value.
88-
def fir_BoxCharType : Type<CPred<"$_self.isa<fir::BoxCharType>()">,
89-
"box character type">;
90-
9185
// PROCEDURE POINTER descriptor. A pair that can capture a host closure.
9286
def fir_BoxProcType : Type<CPred<"$_self.isa<fir::BoxProcType>()">,
9387
"box procedure type">;

flang/include/flang/Optimizer/Dialect/FIRType.h

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ class FIROpsDialect;
4242
using KindTy = unsigned;
4343

4444
namespace detail {
45-
struct BoxCharTypeStorage;
4645
struct BoxProcTypeStorage;
47-
struct CharacterTypeStorage;
4846
struct ComplexTypeStorage;
4947
struct HeapTypeStorage;
5048
struct IntegerTypeStorage;
@@ -98,37 +96,6 @@ mlir::Type dyn_cast_ptrEleTy(mlir::Type t);
9896

9997
// Intrinsic types
10098

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.
105-
class CharacterType
106-
: public mlir::Type::TypeBase<CharacterType, mlir::Type,
107-
detail::CharacterTypeStorage> {
108-
public:
109-
using Base::Base;
110-
using LenType = std::int64_t;
111-
112-
static CharacterType get(mlir::MLIRContext *ctxt, KindTy kind, LenType len);
113-
/// Return unknown length CHARACTER type.
114-
static CharacterType getUnknownLen(mlir::MLIRContext *ctxt, KindTy kind) {
115-
return get(ctxt, kind, unknownLen());
116-
}
117-
/// Return length 1 CHARACTER type.
118-
static CharacterType getSingleton(mlir::MLIRContext *ctxt, KindTy kind) {
119-
return get(ctxt, kind, singleton());
120-
}
121-
KindTy getFKind() const;
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; }
127-
128-
/// Access to a CHARACTER's LEN property. Defaults to 1.
129-
LenType getLen() const;
130-
};
131-
13299
/// Model of a Fortran COMPLEX intrinsic type, including the KIND type
133100
/// parameter. COMPLEX is a floating point type with a real and imaginary
134101
/// member.
@@ -176,17 +143,6 @@ class RealType : public mlir::Type::TypeBase<RealType, mlir::Type,
176143

177144
// FIR support types
178145

179-
/// The type of a pair that describes a CHARACTER variable. Specifically, a
180-
/// CHARACTER consists of a reference to a buffer (the string value) and a LEN
181-
/// type parameter (the runtime length of the buffer).
182-
class BoxCharType : public mlir::Type::TypeBase<BoxCharType, mlir::Type,
183-
detail::BoxCharTypeStorage> {
184-
public:
185-
using Base::Base;
186-
static BoxCharType get(mlir::MLIRContext *ctxt, KindTy kind);
187-
CharacterType getEleTy() const;
188-
};
189-
190146
/// The type of a pair that describes a PROCEDURE reference. Pointers to
191147
/// internal procedures must carry an additional reference to the host's
192148
/// variables that are referenced.

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,64 @@ def ShapeShiftType : FIR_Type<"ShapeShift", "shapeshift"> {
115115
}];
116116
}
117117

118+
def fir_CharacterType : FIR_Type<"Character", "char"> {
119+
let summary = "FIR character type";
120+
121+
let description = [{
122+
Model of the Fortran CHARACTER intrinsic type, including the KIND type
123+
parameter. The model optionally includes a LEN type parameter. A
124+
CharacterType is thus the type of both a single character value and a
125+
character with a LEN parameter.
126+
}];
127+
128+
let parameters = (ins "KindTy":$FKind, "CharacterType::LenType":$len);
129+
130+
let extraClassDeclaration = [{
131+
using KindTy = unsigned;
132+
using LenType = std::int64_t;
133+
134+
// Return unknown length CHARACTER type.
135+
static CharacterType getUnknownLen(mlir::MLIRContext *ctxt, KindTy kind) {
136+
return get(ctxt, kind, unknownLen());
137+
}
138+
139+
// Return length 1 CHARACTER type.
140+
static CharacterType getSingleton(mlir::MLIRContext *ctxt, KindTy kind) {
141+
return get(ctxt, kind, singleton());
142+
}
143+
144+
// CHARACTER is a singleton and has a LEN of 1.
145+
static constexpr LenType singleton() { return 1; }
146+
// CHARACTER has an unknown LEN property.
147+
static constexpr LenType unknownLen() { return -1; }
148+
}];
149+
}
150+
151+
def fir_BoxCharType : FIR_Type<"BoxChar", "boxchar"> {
152+
let summary = "CHARACTER type descriptor.";
153+
154+
let description = [{
155+
The type of a pair that describes a CHARACTER variable. Specifically, a
156+
CHARACTER consists of a reference to a buffer (the string value) and a LEN
157+
type parameter (the runtime length of the buffer).
158+
}];
159+
160+
let parameters = (ins "KindTy":$kind);
161+
162+
let printer = [{
163+
$_printer << "boxchar<" << getImpl()->kind << ">";
164+
}];
165+
166+
let genAccessors = 1;
167+
168+
let extraClassDeclaration = [{
169+
using KindTy = unsigned;
170+
171+
// a !fir.boxchar<k> always wraps a !fir.char<k, ?>
172+
CharacterType getElementType(mlir::MLIRContext *context) const;
173+
174+
CharacterType getEleTy() const;
175+
}];
176+
}
177+
118178
#endif // FIR_DIALECT_FIR_TYPES

0 commit comments

Comments
 (0)