1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
//===- TypeDetail.h ---------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LIB_MLIR_TOOLS_PDLL_AST_TYPEDETAIL_H_
#define LIB_MLIR_TOOLS_PDLL_AST_TYPEDETAIL_H_
#include "mlir/Tools/PDLL/AST/Types.h"
namespace mlir {
namespace pdll {
namespace ast {
//===----------------------------------------------------------------------===//
// Type
//===----------------------------------------------------------------------===//
struct Type::Storage : public StorageUniquer::BaseStorage {
Storage(TypeID typeID) : typeID(typeID) {}
/// The type identifier for the derived type class.
TypeID typeID;
};
namespace detail {
/// A utility CRTP base class that defines many of the necessary utilities for
/// defining a PDLL AST Type.
template <typename ConcreteT, typename KeyT = void>
struct TypeStorageBase : public Type::Storage {
using KeyTy = KeyT;
using Base = TypeStorageBase<ConcreteT, KeyT>;
TypeStorageBase(KeyTy key)
: Type::Storage(TypeID::get<ConcreteT>()), key(key) {}
/// Construct an instance with the given storage allocator.
static ConcreteT *construct(StorageUniquer::StorageAllocator &alloc,
const KeyTy &key) {
return new (alloc.allocate<ConcreteT>()) ConcreteT(key);
}
/// Utility methods required by the storage allocator.
bool operator==(const KeyTy &key) const { return this->key == key; }
/// Return the key value of this storage class.
const KeyTy &getValue() const { return key; }
protected:
KeyTy key;
};
/// A specialization of the storage base for singleton types.
template <typename ConcreteT>
struct TypeStorageBase<ConcreteT, void> : public Type::Storage {
using Base = TypeStorageBase<ConcreteT, void>;
TypeStorageBase() : Type::Storage(TypeID::get<ConcreteT>()) {}
};
//===----------------------------------------------------------------------===//
// AttributeType
//===----------------------------------------------------------------------===//
struct AttributeTypeStorage : public TypeStorageBase<AttributeTypeStorage> {};
//===----------------------------------------------------------------------===//
// ConstraintType
//===----------------------------------------------------------------------===//
struct ConstraintTypeStorage : public TypeStorageBase<ConstraintTypeStorage> {};
//===----------------------------------------------------------------------===//
// OperationType
//===----------------------------------------------------------------------===//
struct OperationTypeStorage
: public TypeStorageBase<OperationTypeStorage,
std::pair<StringRef, const ods::Operation *>> {
using Base::Base;
static OperationTypeStorage *
construct(StorageUniquer::StorageAllocator &alloc,
const std::pair<StringRef, const ods::Operation *> &key) {
return new (alloc.allocate<OperationTypeStorage>()) OperationTypeStorage(
std::make_pair(alloc.copyInto(key.first), key.second));
}
};
//===----------------------------------------------------------------------===//
// RangeType
//===----------------------------------------------------------------------===//
struct RangeTypeStorage : public TypeStorageBase<RangeTypeStorage, Type> {
using Base::Base;
};
//===----------------------------------------------------------------------===//
// RewriteType
//===----------------------------------------------------------------------===//
struct RewriteTypeStorage : public TypeStorageBase<RewriteTypeStorage> {};
//===----------------------------------------------------------------------===//
// TupleType
//===----------------------------------------------------------------------===//
struct TupleTypeStorage
: public TypeStorageBase<TupleTypeStorage,
std::pair<ArrayRef<Type>, ArrayRef<StringRef>>> {
using Base::Base;
static TupleTypeStorage *
construct(StorageUniquer::StorageAllocator &alloc,
std::pair<ArrayRef<Type>, ArrayRef<StringRef>> key) {
SmallVector<StringRef> names = llvm::to_vector(llvm::map_range(
key.second, [&](StringRef name) { return alloc.copyInto(name); }));
return new (alloc.allocate<TupleTypeStorage>())
TupleTypeStorage(std::make_pair(alloc.copyInto(key.first),
alloc.copyInto(llvm::ArrayRef(names))));
}
};
//===----------------------------------------------------------------------===//
// TypeType
//===----------------------------------------------------------------------===//
struct TypeTypeStorage : public TypeStorageBase<TypeTypeStorage> {};
//===----------------------------------------------------------------------===//
// ValueType
//===----------------------------------------------------------------------===//
struct ValueTypeStorage : public TypeStorageBase<ValueTypeStorage> {};
} // namespace detail
} // namespace ast
} // namespace pdll
} // namespace mlir
#endif // LIB_MLIR_TOOLS_PDLL_AST_TYPEDETAIL_H_
|