clang 23.0.0git
CIRTypesDetails.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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// This file contains implementation details, such as storage structures, of
10// CIR dialect types.
11//
12//===----------------------------------------------------------------------===//
13#ifndef CIR_DIALECT_IR_CIRTYPESDETAILS_H
14#define CIR_DIALECT_IR_CIRTYPESDETAILS_H
15
16#include "mlir/IR/BuiltinAttributes.h"
17#include "mlir/Support/LogicalResult.h"
19#include "llvm/ADT/Hashing.h"
20
21namespace cir {
22namespace detail {
23
24//===----------------------------------------------------------------------===//
25// CIR StructTypeStorage
26//===----------------------------------------------------------------------===//
27
28/// Type storage for CIR struct/class types.
29struct StructTypeStorage : public mlir::TypeStorage {
43
45 mlir::StringAttr name;
47 bool packed;
48 bool padded;
50
52 bool incomplete, bool packed, bool padded, bool is_class)
55 assert((name || !incomplete) && "Incomplete records must have a name");
56 }
57
58 KeyTy getAsKey() const {
60 }
61
62 bool operator==(const KeyTy &key) const {
63 if (name)
64 return (name == key.name) && (is_class == key.is_class);
65 return std::tie(members, name, incomplete, packed, padded, is_class) ==
66 std::tie(key.members, key.name, key.incomplete, key.packed,
67 key.padded, key.is_class);
68 }
69
70 static llvm::hash_code hashKey(const KeyTy &key) {
71 if (key.name)
72 return llvm::hash_combine(key.name, key.is_class);
73 return llvm::hash_combine(key.members, key.incomplete, key.packed,
74 key.padded, key.is_class);
75 }
76
77 static StructTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
78 const KeyTy &key) {
79 return new (allocator.allocate<StructTypeStorage>())
80 StructTypeStorage(allocator.copyInto(key.members), key.name,
81 key.incomplete, key.packed, key.padded, key.is_class);
82 }
83
84 /// Mutates the members and attributes of an identified struct/class.
85 llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator,
87 bool padded) {
88 if (!name)
89 return llvm::failure();
90
91 if (!incomplete)
92 return mlir::success((this->members == members) &&
93 (this->packed == packed) &&
94 (this->padded == padded));
95
96 this->members = allocator.copyInto(members);
97 this->packed = packed;
98 this->padded = padded;
99 incomplete = false;
100 return llvm::success();
101 }
102};
103
104//===----------------------------------------------------------------------===//
105// CIR UnionTypeStorage
106//===----------------------------------------------------------------------===//
107
108/// Type storage for CIR union types.
109struct UnionTypeStorage : public mlir::TypeStorage {
110 struct KeyTy {
112 mlir::StringAttr name;
114 bool packed;
115 mlir::Type padding;
116
121 };
122
124 mlir::StringAttr name;
126 bool packed;
127 mlir::Type padding;
128
130 bool incomplete, bool packed, mlir::Type padding)
133 assert((name || !incomplete) && "Incomplete records must have a name");
134 }
135
136 KeyTy getAsKey() const {
138 }
139
140 bool operator==(const KeyTy &key) const {
141 if (name)
142 return name == key.name;
143 return std::tie(members, name, incomplete, packed, padding) ==
144 std::tie(key.members, key.name, key.incomplete, key.packed,
145 key.padding);
146 }
147
148 static llvm::hash_code hashKey(const KeyTy &key) {
149 if (key.name)
150 return llvm::hash_combine(key.name);
151 return llvm::hash_combine(key.members, key.incomplete, key.packed,
152 key.padding);
153 }
154
155 static UnionTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
156 const KeyTy &key) {
157 return new (allocator.allocate<UnionTypeStorage>())
158 UnionTypeStorage(allocator.copyInto(key.members), key.name,
159 key.incomplete, key.packed, key.padding);
160 }
161
162 /// Mutates the members and attributes of an identified union.
163 llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator,
165 mlir::Type padding) {
166 if (!name)
167 return llvm::failure();
168
169 if (!incomplete)
170 return mlir::success((this->members == members) &&
171 (this->packed == packed) &&
172 (this->padding == padding));
173
174 this->members = allocator.copyInto(members);
175 this->packed = packed;
176 this->padding = padding;
177 incomplete = false;
178 return llvm::success();
179 }
180};
181
182} // namespace detail
183} // namespace cir
184
185#endif // CIR_DIALECT_IR_CIRTYPESDETAILS_H
KeyTy(llvm::ArrayRef< mlir::Type > members, mlir::StringAttr name, bool incomplete, bool packed, bool padded, bool is_class)
llvm::ArrayRef< mlir::Type > members
static llvm::hash_code hashKey(const KeyTy &key)
StructTypeStorage(llvm::ArrayRef< mlir::Type > members, mlir::StringAttr name, bool incomplete, bool packed, bool padded, bool is_class)
llvm::ArrayRef< mlir::Type > members
static StructTypeStorage * construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key)
bool operator==(const KeyTy &key) const
llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator, llvm::ArrayRef< mlir::Type > members, bool packed, bool padded)
Mutates the members and attributes of an identified struct/class.
KeyTy(llvm::ArrayRef< mlir::Type > members, mlir::StringAttr name, bool incomplete, bool packed, mlir::Type padding)
llvm::ArrayRef< mlir::Type > members
llvm::ArrayRef< mlir::Type > members
bool operator==(const KeyTy &key) const
static llvm::hash_code hashKey(const KeyTy &key)
static UnionTypeStorage * construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key)
UnionTypeStorage(llvm::ArrayRef< mlir::Type > members, mlir::StringAttr name, bool incomplete, bool packed, mlir::Type padding)
llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator, llvm::ArrayRef< mlir::Type > members, bool packed, mlir::Type padding)
Mutates the members and attributes of an identified union.