Skip to content

Commit 7d0005f

Browse files
committed
[PDLL] Collapse TypeDetail.h into Types.h
This allows this code to be compiled with `MLIR_USE_FALLBACK_TYPE_IDS=1` which is used to solve TypeID issues across different DSOs. This Types.h is only included in a few tools so the impact of this header being larger should be limited.
1 parent 5017370 commit 7d0005f

File tree

5 files changed

+123
-160
lines changed

5 files changed

+123
-160
lines changed

mlir/include/mlir/Tools/PDLL/AST/Types.h

Lines changed: 121 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ class Operation;
2222
namespace ast {
2323
class Context;
2424

25-
namespace detail {
26-
struct AttributeTypeStorage;
27-
struct ConstraintTypeStorage;
28-
struct OperationTypeStorage;
29-
struct RangeTypeStorage;
30-
struct RewriteTypeStorage;
31-
struct TupleTypeStorage;
32-
struct TypeTypeStorage;
33-
struct ValueTypeStorage;
34-
} // namespace detail
35-
3625
//===----------------------------------------------------------------------===//
3726
// Type
3827
//===----------------------------------------------------------------------===//
@@ -99,6 +88,127 @@ inline raw_ostream &operator<<(raw_ostream &os, Type type) {
9988
return os;
10089
}
10190

91+
//===----------------------------------------------------------------------===//
92+
// Type::Storage
93+
//===----------------------------------------------------------------------===//
94+
95+
struct Type::Storage : public StorageUniquer::BaseStorage {
96+
Storage(TypeID typeID) : typeID(typeID) {}
97+
98+
/// The type identifier for the derived type class.
99+
TypeID typeID;
100+
};
101+
102+
namespace detail {
103+
104+
/// A utility CRTP base class that defines many of the necessary utilities for
105+
/// defining a PDLL AST Type.
106+
template <typename ConcreteT, typename KeyT = void>
107+
struct TypeStorageBase : public Type::Storage {
108+
using KeyTy = KeyT;
109+
using Base = TypeStorageBase<ConcreteT, KeyT>;
110+
TypeStorageBase(KeyTy key)
111+
: Type::Storage(TypeID::get<ConcreteT>()), key(key) {}
112+
113+
/// Construct an instance with the given storage allocator.
114+
static ConcreteT *construct(StorageUniquer::StorageAllocator &alloc,
115+
const KeyTy &key) {
116+
return new (alloc.allocate<ConcreteT>()) ConcreteT(key);
117+
}
118+
119+
/// Utility methods required by the storage allocator.
120+
bool operator==(const KeyTy &key) const { return this->key == key; }
121+
122+
/// Return the key value of this storage class.
123+
const KeyTy &getValue() const { return key; }
124+
125+
protected:
126+
KeyTy key;
127+
};
128+
/// A specialization of the storage base for singleton types.
129+
template <typename ConcreteT>
130+
struct TypeStorageBase<ConcreteT, void> : public Type::Storage {
131+
using Base = TypeStorageBase<ConcreteT, void>;
132+
TypeStorageBase() : Type::Storage(TypeID::get<ConcreteT>()) {}
133+
};
134+
135+
//===----------------------------------------------------------------------===//
136+
// AttributeTypeStorage
137+
//===----------------------------------------------------------------------===//
138+
139+
struct AttributeTypeStorage : public TypeStorageBase<AttributeTypeStorage> {};
140+
141+
//===----------------------------------------------------------------------===//
142+
// ConstraintTypeStorage
143+
//===----------------------------------------------------------------------===//
144+
145+
struct ConstraintTypeStorage : public TypeStorageBase<ConstraintTypeStorage> {};
146+
147+
//===----------------------------------------------------------------------===//
148+
// OperationTypeStorage
149+
//===----------------------------------------------------------------------===//
150+
151+
struct OperationTypeStorage
152+
: public TypeStorageBase<OperationTypeStorage,
153+
std::pair<StringRef, const ods::Operation *>> {
154+
using Base::Base;
155+
156+
static OperationTypeStorage *
157+
construct(StorageUniquer::StorageAllocator &alloc,
158+
const std::pair<StringRef, const ods::Operation *> &key) {
159+
return new (alloc.allocate<OperationTypeStorage>()) OperationTypeStorage(
160+
std::make_pair(alloc.copyInto(key.first), key.second));
161+
}
162+
};
163+
164+
//===----------------------------------------------------------------------===//
165+
// RangeTypeStorage
166+
//===----------------------------------------------------------------------===//
167+
168+
struct RangeTypeStorage : public TypeStorageBase<RangeTypeStorage, Type> {
169+
using Base::Base;
170+
};
171+
172+
//===----------------------------------------------------------------------===//
173+
// RewriteTypeStorage
174+
//===----------------------------------------------------------------------===//
175+
176+
struct RewriteTypeStorage : public TypeStorageBase<RewriteTypeStorage> {};
177+
178+
//===----------------------------------------------------------------------===//
179+
// TupleTypeStorage
180+
//===----------------------------------------------------------------------===//
181+
182+
struct TupleTypeStorage
183+
: public TypeStorageBase<TupleTypeStorage,
184+
std::pair<ArrayRef<Type>, ArrayRef<StringRef>>> {
185+
using Base::Base;
186+
187+
static TupleTypeStorage *
188+
construct(StorageUniquer::StorageAllocator &alloc,
189+
std::pair<ArrayRef<Type>, ArrayRef<StringRef>> key) {
190+
SmallVector<StringRef> names = llvm::to_vector(llvm::map_range(
191+
key.second, [&](StringRef name) { return alloc.copyInto(name); }));
192+
return new (alloc.allocate<TupleTypeStorage>())
193+
TupleTypeStorage(std::make_pair(alloc.copyInto(key.first),
194+
alloc.copyInto(llvm::ArrayRef(names))));
195+
}
196+
};
197+
198+
//===----------------------------------------------------------------------===//
199+
// TypeTypeStorage
200+
//===----------------------------------------------------------------------===//
201+
202+
struct TypeTypeStorage : public TypeStorageBase<TypeTypeStorage> {};
203+
204+
//===----------------------------------------------------------------------===//
205+
// ValueTypeStorage
206+
//===----------------------------------------------------------------------===//
207+
208+
struct ValueTypeStorage : public TypeStorageBase<ValueTypeStorage> {};
209+
210+
} // namespace detail
211+
102212
//===----------------------------------------------------------------------===//
103213
// AttributeType
104214
//===----------------------------------------------------------------------===//

mlir/lib/Tools/PDLL/AST/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "mlir/Tools/PDLL/AST/Context.h"
10-
#include "TypeDetail.h"
10+
#include "mlir/Tools/PDLL/AST/Types.h"
1111

1212
using namespace mlir;
1313
using namespace mlir::pdll::ast;

mlir/lib/Tools/PDLL/AST/TypeDetail.h

Lines changed: 0 additions & 141 deletions
This file was deleted.

mlir/lib/Tools/PDLL/AST/Types.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "mlir/Tools/PDLL/AST/Types.h"
10-
#include "TypeDetail.h"
1110
#include "mlir/Tools/PDLL/AST/Context.h"
1211
#include <optional>
1312

utils/bazel/llvm-project-overlay/mlir/BUILD.bazel

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14085,12 +14085,7 @@ cc_library(
1408514085

1408614086
cc_library(
1408714087
name = "PDLLAST",
14088-
srcs = glob(
14089-
[
14090-
"lib/Tools/PDLL/AST/*.cpp",
14091-
"lib/Tools/PDLL/AST/*.h",
14092-
],
14093-
),
14088+
srcs = glob(["lib/Tools/PDLL/AST/*.cpp"]),
1409414089
hdrs = glob(["include/mlir/Tools/PDLL/AST/*.h"]),
1409514090
includes = ["include"],
1409614091
deps = [

0 commit comments

Comments
 (0)