MLIR  20.0.0git
TypeDetail.h
Go to the documentation of this file.
1 //===- TypeDetail.h ---------------------------------------------*- C++ -*-===//
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 #ifndef LIB_MLIR_TOOLS_PDLL_AST_TYPEDETAIL_H_
10 #define LIB_MLIR_TOOLS_PDLL_AST_TYPEDETAIL_H_
11 
13 
14 namespace mlir {
15 namespace pdll {
16 namespace ast {
17 //===----------------------------------------------------------------------===//
18 // Type
19 //===----------------------------------------------------------------------===//
20 
23 
24  /// The type identifier for the derived type class.
26 };
27 
28 namespace detail {
29 
30 /// A utility CRTP base class that defines many of the necessary utilities for
31 /// defining a PDLL AST Type.
32 template <typename ConcreteT, typename KeyT = void>
33 struct TypeStorageBase : public Type::Storage {
34  using KeyTy = KeyT;
37  : Type::Storage(TypeID::get<ConcreteT>()), key(key) {}
38 
39  /// Construct an instance with the given storage allocator.
40  static ConcreteT *construct(StorageUniquer::StorageAllocator &alloc,
41  const KeyTy &key) {
42  return new (alloc.allocate<ConcreteT>()) ConcreteT(key);
43  }
44 
45  /// Utility methods required by the storage allocator.
46  bool operator==(const KeyTy &key) const { return this->key == key; }
47 
48  /// Return the key value of this storage class.
49  const KeyTy &getValue() const { return key; }
50 
51 protected:
53 };
54 /// A specialization of the storage base for singleton types.
55 template <typename ConcreteT>
56 struct TypeStorageBase<ConcreteT, void> : public Type::Storage {
58  TypeStorageBase() : Type::Storage(TypeID::get<ConcreteT>()) {}
59 };
60 
61 //===----------------------------------------------------------------------===//
62 // AttributeType
63 //===----------------------------------------------------------------------===//
64 
65 struct AttributeTypeStorage : public TypeStorageBase<AttributeTypeStorage> {};
66 
67 //===----------------------------------------------------------------------===//
68 // ConstraintType
69 //===----------------------------------------------------------------------===//
70 
71 struct ConstraintTypeStorage : public TypeStorageBase<ConstraintTypeStorage> {};
72 
73 //===----------------------------------------------------------------------===//
74 // OperationType
75 //===----------------------------------------------------------------------===//
76 
78  : public TypeStorageBase<OperationTypeStorage,
79  std::pair<StringRef, const ods::Operation *>> {
80  using Base::Base;
81 
82  static OperationTypeStorage *
84  const std::pair<StringRef, const ods::Operation *> &key) {
86  std::make_pair(alloc.copyInto(key.first), key.second));
87  }
88 };
89 
90 //===----------------------------------------------------------------------===//
91 // RangeType
92 //===----------------------------------------------------------------------===//
93 
94 struct RangeTypeStorage : public TypeStorageBase<RangeTypeStorage, Type> {
95  using Base::Base;
96 };
97 
98 //===----------------------------------------------------------------------===//
99 // RewriteType
100 //===----------------------------------------------------------------------===//
101 
102 struct RewriteTypeStorage : public TypeStorageBase<RewriteTypeStorage> {};
103 
104 //===----------------------------------------------------------------------===//
105 // TupleType
106 //===----------------------------------------------------------------------===//
107 
109  : public TypeStorageBase<TupleTypeStorage,
110  std::pair<ArrayRef<Type>, ArrayRef<StringRef>>> {
111  using Base::Base;
112 
113  static TupleTypeStorage *
115  std::pair<ArrayRef<Type>, ArrayRef<StringRef>> key) {
116  SmallVector<StringRef> names = llvm::to_vector(llvm::map_range(
117  key.second, [&](StringRef name) { return alloc.copyInto(name); }));
118  return new (alloc.allocate<TupleTypeStorage>())
119  TupleTypeStorage(std::make_pair(alloc.copyInto(key.first),
120  alloc.copyInto(llvm::ArrayRef(names))));
121  }
122 };
123 
124 //===----------------------------------------------------------------------===//
125 // TypeType
126 //===----------------------------------------------------------------------===//
127 
128 struct TypeTypeStorage : public TypeStorageBase<TypeTypeStorage> {};
129 
130 //===----------------------------------------------------------------------===//
131 // ValueType
132 //===----------------------------------------------------------------------===//
133 
134 struct ValueTypeStorage : public TypeStorageBase<ValueTypeStorage> {};
135 
136 } // namespace detail
137 } // namespace ast
138 } // namespace pdll
139 } // namespace mlir
140 
141 #endif // LIB_MLIR_TOOLS_PDLL_AST_TYPEDETAIL_H_
This class acts as the base storage that all storage classes must derived from.
This is a utility allocator used to allocate memory for instances of derived types.
ArrayRef< T > copyInto(ArrayRef< T > elements)
Copy the specified array of elements into memory managed by our bump pointer allocator.
T * allocate()
Allocate an instance of the provided type.
This class provides an efficient unique identifier for a specific C++ type.
Definition: TypeID.h:104
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
TypeID typeID
The type identifier for the derived type class.
Definition: TypeDetail.h:25
static OperationTypeStorage * construct(StorageUniquer::StorageAllocator &alloc, const std::pair< StringRef, const ods::Operation * > &key)
Definition: TypeDetail.h:83
static TupleTypeStorage * construct(StorageUniquer::StorageAllocator &alloc, std::pair< ArrayRef< Type >, ArrayRef< StringRef >> key)
Definition: TypeDetail.h:114
A specialization of the storage base for singleton types.
Definition: TypeDetail.h:56
A utility CRTP base class that defines many of the necessary utilities for defining a PDLL AST Type.
Definition: TypeDetail.h:33
static ConcreteT * construct(StorageUniquer::StorageAllocator &alloc, const KeyTy &key)
Construct an instance with the given storage allocator.
Definition: TypeDetail.h:40
bool operator==(const KeyTy &key) const
Utility methods required by the storage allocator.
Definition: TypeDetail.h:46
TypeStorageBase< OperationTypeStorage, std::pair< StringRef, const ods::Operation * > > Base
Definition: TypeDetail.h:35
const KeyTy & getValue() const
Return the key value of this storage class.
Definition: TypeDetail.h:49