clang 22.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 RecordTypeStorage
26//===----------------------------------------------------------------------===//
27
28/// Type storage for CIR record types.
29struct RecordTypeStorage : public mlir::TypeStorage {
30 struct KeyTy {
32 mlir::StringAttr name;
34 bool packed;
35 bool padded;
36 RecordType::RecordKind kind;
37
39 bool incomplete, bool packed, bool padded,
40 RecordType::RecordKind kind)
43 };
44
46 mlir::StringAttr name;
48 bool packed;
49 bool padded;
50 RecordType::RecordKind kind;
51
53 bool incomplete, bool packed, bool padded,
54 RecordType::RecordKind kind)
57 assert((name || !incomplete) && "Incomplete records must have a name");
58 }
59
60 KeyTy getAsKey() const {
62 }
63
64 bool operator==(const KeyTy &key) const {
65 if (name)
66 return (name == key.name) && (kind == key.kind);
67 return std::tie(members, name, incomplete, packed, padded, kind) ==
68 std::tie(key.members, key.name, key.incomplete, key.packed,
69 key.padded, key.kind);
70 }
71
72 static llvm::hash_code hashKey(const KeyTy &key) {
73 if (key.name)
74 return llvm::hash_combine(key.name, key.kind);
75 return llvm::hash_combine(key.members, key.incomplete, key.packed,
76 key.padded, key.kind);
77 }
78
79 static RecordTypeStorage *construct(mlir::TypeStorageAllocator &allocator,
80 const KeyTy &key) {
81 return new (allocator.allocate<RecordTypeStorage>())
82 RecordTypeStorage(allocator.copyInto(key.members), key.name,
83 key.incomplete, key.packed, key.padded, key.kind);
84 }
85
86 /// Mutates the members and attributes an identified record.
87 ///
88 /// Once a record is mutated, it is marked as complete, preventing further
89 /// mutations. Anonymous records are always complete and cannot be mutated.
90 /// This method does not fail if a mutation of a complete record does not
91 /// change the record.
92 llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator,
94 bool padded) {
95 // Anonymous records cannot mutate.
96 if (!name)
97 return llvm::failure();
98
99 // Mutation of complete records are allowed if they change nothing.
100 if (!incomplete)
101 return mlir::success((this->members == members) &&
102 (this->packed == packed) &&
103 (this->padded == padded));
104
105 // Mutate incomplete record.
106 this->members = allocator.copyInto(members);
107 this->packed = packed;
108 this->padded = padded;
109
110 incomplete = false;
111 return llvm::success();
112 }
113};
114
115} // namespace detail
116} // namespace cir
117
118#endif // CIR_DIALECT_IR_CIRTYPESDETAILS_H
Definition: ABIArgInfo.h:22
llvm::ArrayRef< mlir::Type > members
KeyTy(llvm::ArrayRef< mlir::Type > members, mlir::StringAttr name, bool incomplete, bool packed, bool padded, RecordType::RecordKind kind)
Type storage for CIR record types.
bool operator==(const KeyTy &key) const
static llvm::hash_code hashKey(const KeyTy &key)
static RecordTypeStorage * construct(mlir::TypeStorageAllocator &allocator, const KeyTy &key)
llvm::ArrayRef< mlir::Type > members
llvm::LogicalResult mutate(mlir::TypeStorageAllocator &allocator, llvm::ArrayRef< mlir::Type > members, bool packed, bool padded)
Mutates the members and attributes an identified record.
RecordTypeStorage(llvm::ArrayRef< mlir::Type > members, mlir::StringAttr name, bool incomplete, bool packed, bool padded, RecordType::RecordKind kind)
RecordType::RecordKind kind