Skip to content

Commit 250f43d

Browse files
committed
[mlir] Remove the use of "kinds" from Attributes and Types
This greatly simplifies a large portion of the underlying infrastructure, allows for lookups of singleton classes to be much more efficient and always thread-safe(no locking). As a result of this, the dialect symbol registry has been removed as it is no longer necessary. For users broken by this change, an alert was sent out(https://llvm.discourse.group/t/removing-kinds-from-attributes-and-types) that helps prevent a majority of the breakage surface area. All that should be necessary, if the advice in that alert was followed, is removing the kind passed to the ::get methods. Differential Revision: https://reviews.llvm.org/D86121
1 parent a7d0b7a commit 250f43d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+593
-894
lines changed

flang/include/flang/Optimizer/Dialect/FIRAttr.h

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@ struct RealAttributeStorage;
2525
struct TypeAttributeStorage;
2626
} // namespace detail
2727

28-
enum AttributeKind {
29-
FIR_ATTR = mlir::Attribute::FIRST_FIR_ATTR,
30-
FIR_EXACTTYPE, // instance_of, precise type relation
31-
FIR_SUBCLASS, // subsumed_by, is-a (subclass) relation
32-
FIR_POINT,
33-
FIR_CLOSEDCLOSED_INTERVAL,
34-
FIR_OPENCLOSED_INTERVAL,
35-
FIR_CLOSEDOPEN_INTERVAL,
36-
FIR_REAL_ATTR,
37-
};
38-
3928
class ExactTypeAttr
4029
: public mlir::Attribute::AttrBase<ExactTypeAttr, mlir::Attribute,
4130
detail::TypeAttributeStorage> {
@@ -47,8 +36,6 @@ class ExactTypeAttr
4736
static ExactTypeAttr get(mlir::Type value);
4837

4938
mlir::Type getType() const;
50-
51-
static constexpr unsigned getId() { return AttributeKind::FIR_EXACTTYPE; }
5239
};
5340

5441
class SubclassAttr
@@ -62,8 +49,6 @@ class SubclassAttr
6249
static SubclassAttr get(mlir::Type value);
6350

6451
mlir::Type getType() const;
65-
66-
static constexpr unsigned getId() { return AttributeKind::FIR_SUBCLASS; }
6752
};
6853

6954
// Attributes for building SELECT CASE multiway branches
@@ -80,9 +65,6 @@ class ClosedIntervalAttr
8065

8166
static constexpr llvm::StringRef getAttrName() { return "interval"; }
8267
static ClosedIntervalAttr get(mlir::MLIRContext *ctxt);
83-
static constexpr unsigned getId() {
84-
return AttributeKind::FIR_CLOSEDCLOSED_INTERVAL;
85-
}
8668
};
8769

8870
/// An upper bound is an open interval (including the bound value) as given as
@@ -97,9 +79,6 @@ class UpperBoundAttr
9779

9880
static constexpr llvm::StringRef getAttrName() { return "upper"; }
9981
static UpperBoundAttr get(mlir::MLIRContext *ctxt);
100-
static constexpr unsigned getId() {
101-
return AttributeKind::FIR_OPENCLOSED_INTERVAL;
102-
}
10382
};
10483

10584
/// A lower bound is an open interval (including the bound value) as given as
@@ -114,9 +93,6 @@ class LowerBoundAttr
11493

11594
static constexpr llvm::StringRef getAttrName() { return "lower"; }
11695
static LowerBoundAttr get(mlir::MLIRContext *ctxt);
117-
static constexpr unsigned getId() {
118-
return AttributeKind::FIR_CLOSEDOPEN_INTERVAL;
119-
}
12096
};
12197

12298
/// A pointer interval is a closed interval as given as an ssa-value. The
@@ -131,7 +107,6 @@ class PointIntervalAttr
131107

132108
static constexpr llvm::StringRef getAttrName() { return "point"; }
133109
static PointIntervalAttr get(mlir::MLIRContext *ctxt);
134-
static constexpr unsigned getId() { return AttributeKind::FIR_POINT; }
135110
};
136111

137112
/// A real attribute is used to workaround MLIR's default parsing of a real
@@ -150,8 +125,6 @@ class RealAttr
150125

151126
int getFKind() const;
152127
llvm::APFloat getValue() const;
153-
154-
static constexpr unsigned getId() { return AttributeKind::FIR_REAL_ATTR; }
155128
};
156129

157130
mlir::Attribute parseFirAttribute(FIROpsDialect *dialect,

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

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,6 @@ struct SequenceTypeStorage;
5454
struct TypeDescTypeStorage;
5555
} // namespace detail
5656

57-
/// Integral identifier for all the types comprising the FIR type system
58-
enum TypeKind {
59-
// The enum starts at the range reserved for this dialect.
60-
FIR_TYPE = mlir::Type::FIRST_FIR_TYPE,
61-
FIR_BOX, // (static) descriptor
62-
FIR_BOXCHAR, // CHARACTER pointer and length
63-
FIR_BOXPROC, // procedure with host association
64-
FIR_CHARACTER, // intrinsic type
65-
FIR_COMPLEX, // intrinsic type
66-
FIR_DERIVED, // derived
67-
FIR_DIMS,
68-
FIR_FIELD,
69-
FIR_HEAP,
70-
FIR_INT, // intrinsic type
71-
FIR_LEN,
72-
FIR_LOGICAL, // intrinsic type
73-
FIR_POINTER, // POINTER attr
74-
FIR_REAL, // intrinsic type
75-
FIR_REFERENCE,
76-
FIR_SEQUENCE, // DIMENSION attr
77-
FIR_TYPEDESC,
78-
};
79-
8057
// These isa_ routines follow the precedent of llvm::isa_or_null<>
8158

8259
/// Is `t` any of the FIR dialect types?
@@ -111,21 +88,14 @@ bool isa_aggregate(mlir::Type t);
11188
/// not a memory reference type, then returns a null `Type`.
11289
mlir::Type dyn_cast_ptrEleTy(mlir::Type t);
11390

114-
/// Boilerplate mixin template
115-
template <typename A, unsigned Id>
116-
struct IntrinsicTypeMixin {
117-
static constexpr unsigned getId() { return Id; }
118-
};
119-
12091
// Intrinsic types
12192

12293
/// Model of the Fortran CHARACTER intrinsic type, including the KIND type
12394
/// parameter. The model does not include a LEN type parameter. A CharacterType
12495
/// is thus the type of a single character value.
12596
class CharacterType
12697
: public mlir::Type::TypeBase<CharacterType, mlir::Type,
127-
detail::CharacterTypeStorage>,
128-
public IntrinsicTypeMixin<CharacterType, TypeKind::FIR_CHARACTER> {
98+
detail::CharacterTypeStorage> {
12999
public:
130100
using Base::Base;
131101
static CharacterType get(mlir::MLIRContext *ctxt, KindTy kind);
@@ -136,8 +106,7 @@ class CharacterType
136106
/// parameter. COMPLEX is a floating point type with a real and imaginary
137107
/// member.
138108
class CplxType : public mlir::Type::TypeBase<CplxType, mlir::Type,
139-
detail::CplxTypeStorage>,
140-
public IntrinsicTypeMixin<CplxType, TypeKind::FIR_COMPLEX> {
109+
detail::CplxTypeStorage> {
141110
public:
142111
using Base::Base;
143112
static CplxType get(mlir::MLIRContext *ctxt, KindTy kind);
@@ -151,8 +120,7 @@ class CplxType : public mlir::Type::TypeBase<CplxType, mlir::Type,
151120
/// Model of a Fortran INTEGER intrinsic type, including the KIND type
152121
/// parameter.
153122
class IntType
154-
: public mlir::Type::TypeBase<IntType, mlir::Type, detail::IntTypeStorage>,
155-
public IntrinsicTypeMixin<IntType, TypeKind::FIR_INT> {
123+
: public mlir::Type::TypeBase<IntType, mlir::Type, detail::IntTypeStorage> {
156124
public:
157125
using Base::Base;
158126
static IntType get(mlir::MLIRContext *ctxt, KindTy kind);
@@ -163,8 +131,7 @@ class IntType
163131
/// parameter.
164132
class LogicalType
165133
: public mlir::Type::TypeBase<LogicalType, mlir::Type,
166-
detail::LogicalTypeStorage>,
167-
public IntrinsicTypeMixin<LogicalType, TypeKind::FIR_LOGICAL> {
134+
detail::LogicalTypeStorage> {
168135
public:
169136
using Base::Base;
170137
static LogicalType get(mlir::MLIRContext *ctxt, KindTy kind);
@@ -174,8 +141,7 @@ class LogicalType
174141
/// Model of a Fortran REAL (and DOUBLE PRECISION) intrinsic type, including the
175142
/// KIND type parameter.
176143
class RealType : public mlir::Type::TypeBase<RealType, mlir::Type,
177-
detail::RealTypeStorage>,
178-
public IntrinsicTypeMixin<RealType, TypeKind::FIR_REAL> {
144+
detail::RealTypeStorage> {
179145
public:
180146
using Base::Base;
181147
static RealType get(mlir::MLIRContext *ctxt, KindTy kind);
@@ -400,7 +366,6 @@ class RecordType : public mlir::Type::TypeBase<RecordType, mlir::Type,
400366
static RecordType get(mlir::MLIRContext *ctxt, llvm::StringRef name);
401367
void finalize(llvm::ArrayRef<TypePair> lenPList,
402368
llvm::ArrayRef<TypePair> typeList);
403-
static constexpr unsigned getId() { return TypeKind::FIR_DERIVED; }
404369

405370
detail::RecordTypeStorage const *uniqueKey() const;
406371

flang/lib/Optimizer/Dialect/FIRAttr.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,40 +74,40 @@ struct TypeAttributeStorage : public mlir::AttributeStorage {
7474
} // namespace detail
7575

7676
ExactTypeAttr ExactTypeAttr::get(mlir::Type value) {
77-
return Base::get(value.getContext(), FIR_EXACTTYPE, value);
77+
return Base::get(value.getContext(), value);
7878
}
7979

8080
mlir::Type ExactTypeAttr::getType() const { return getImpl()->getType(); }
8181

8282
SubclassAttr SubclassAttr::get(mlir::Type value) {
83-
return Base::get(value.getContext(), FIR_SUBCLASS, value);
83+
return Base::get(value.getContext(), value);
8484
}
8585

8686
mlir::Type SubclassAttr::getType() const { return getImpl()->getType(); }
8787

8888
using AttributeUniquer = mlir::detail::AttributeUniquer;
8989

9090
ClosedIntervalAttr ClosedIntervalAttr::get(mlir::MLIRContext *ctxt) {
91-
return AttributeUniquer::get<ClosedIntervalAttr>(ctxt, getId());
91+
return AttributeUniquer::get<ClosedIntervalAttr>(ctxt);
9292
}
9393

9494
UpperBoundAttr UpperBoundAttr::get(mlir::MLIRContext *ctxt) {
95-
return AttributeUniquer::get<UpperBoundAttr>(ctxt, getId());
95+
return AttributeUniquer::get<UpperBoundAttr>(ctxt);
9696
}
9797

9898
LowerBoundAttr LowerBoundAttr::get(mlir::MLIRContext *ctxt) {
99-
return AttributeUniquer::get<LowerBoundAttr>(ctxt, getId());
99+
return AttributeUniquer::get<LowerBoundAttr>(ctxt);
100100
}
101101

102102
PointIntervalAttr PointIntervalAttr::get(mlir::MLIRContext *ctxt) {
103-
return AttributeUniquer::get<PointIntervalAttr>(ctxt, getId());
103+
return AttributeUniquer::get<PointIntervalAttr>(ctxt);
104104
}
105105

106106
// RealAttr
107107

108108
RealAttr RealAttr::get(mlir::MLIRContext *ctxt,
109109
const RealAttr::ValueType &key) {
110-
return Base::get(ctxt, getId(), key);
110+
return Base::get(ctxt, key);
111111
}
112112

113113
int RealAttr::getFKind() const { return getImpl()->getFKind(); }

0 commit comments

Comments
 (0)