@@ -73,145 +73,6 @@ DEFINE_TRIVIAL_LLVM_TYPE(LLVMMetadataType, "llvm.metadata");
7373
7474#undef DEFINE_TRIVIAL_LLVM_TYPE
7575
76- // ===----------------------------------------------------------------------===//
77- // LLVMStructType.
78- // ===----------------------------------------------------------------------===//
79-
80- // / LLVM dialect structure type representing a collection of different-typed
81- // / elements manipulated together. Structured can optionally be packed, meaning
82- // / that their elements immediately follow each other in memory without
83- // / accounting for potential alignment.
84- // /
85- // / Structure types can be identified (named) or literal. Literal structures
86- // / are uniquely represented by the list of types they contain and packedness.
87- // / Literal structure types are immutable after construction.
88- // /
89- // / Identified structures are uniquely represented by their name, a string. They
90- // / have a mutable component, consisting of the list of types they contain,
91- // / the packedness and the opacity bits. Identified structs can be created
92- // / without providing the lists of element types, making them suitable to
93- // / represent recursive, i.e. self-referring, structures. Identified structs
94- // / without body are considered opaque. For such structs, one can set the body.
95- // / Identified structs can be created as intentionally-opaque, implying that the
96- // / caller does not intend to ever set the body (e.g. forward-declarations of
97- // / structs from another module) and wants to disallow further modification of
98- // / the body. For intentionally-opaque structs or non-opaque structs with the
99- // / body, one is not allowed to set another body (however, one can set exactly
100- // / the same body).
101- // /
102- // / Note that the packedness of the struct takes place in uniquing of literal
103- // / structs, but does not in uniquing of identified structs.
104- class LLVMStructType
105- : public Type::TypeBase<LLVMStructType, Type, detail::LLVMStructTypeStorage,
106- DataLayoutTypeInterface::Trait,
107- DestructurableTypeInterface::Trait,
108- TypeTrait::IsMutable> {
109- public:
110- // / Inherit base constructors.
111- using Base::Base;
112-
113- static constexpr StringLiteral name = " llvm.struct" ;
114-
115- // / Checks if the given type can be contained in a structure type.
116- static bool isValidElementType (Type type);
117-
118- // / Gets or creates an identified struct with the given name in the provided
119- // / context. Note that unlike llvm::StructType::create, this function will
120- // / _NOT_ rename a struct in case a struct with the same name already exists
121- // / in the context. Instead, it will just return the existing struct,
122- // / similarly to the rest of MLIR type ::get methods.
123- static LLVMStructType getIdentified (MLIRContext *context, StringRef name);
124- static LLVMStructType
125- getIdentifiedChecked (function_ref<InFlightDiagnostic()> emitError,
126- MLIRContext *context, StringRef name);
127-
128- // / Gets a new identified struct with the given body. The body _cannot_ be
129- // / changed later. If a struct with the given name already exists, renames
130- // / the struct by appending a `.` followed by a number to the name. Renaming
131- // / happens even if the existing struct has the same body.
132- static LLVMStructType getNewIdentified (MLIRContext *context, StringRef name,
133- ArrayRef<Type> elements,
134- bool isPacked = false );
135-
136- // / Gets or creates a literal struct with the given body in the provided
137- // / context.
138- static LLVMStructType getLiteral (MLIRContext *context, ArrayRef<Type> types,
139- bool isPacked = false );
140- static LLVMStructType
141- getLiteralChecked (function_ref<InFlightDiagnostic()> emitError,
142- MLIRContext *context, ArrayRef<Type> types,
143- bool isPacked = false );
144-
145- // / Gets or creates an intentionally-opaque identified struct. Such a struct
146- // / cannot have its body set. To create an opaque struct with a mutable body,
147- // / use `getIdentified`. Note that unlike llvm::StructType::create, this
148- // / function will _NOT_ rename a struct in case a struct with the same name
149- // / already exists in the context. Instead, it will just return the existing
150- // / struct, similarly to the rest of MLIR type ::get methods.
151- static LLVMStructType getOpaque (StringRef name, MLIRContext *context);
152- static LLVMStructType
153- getOpaqueChecked (function_ref<InFlightDiagnostic()> emitError,
154- MLIRContext *context, StringRef name);
155-
156- // / Set the body of an identified struct. Returns failure if the body could
157- // / not be set, e.g. if the struct already has a body or if it was marked as
158- // / intentionally opaque. This might happen in a multi-threaded context when a
159- // / different thread modified the struct after it was created. Most callers
160- // / are likely to assert this always succeeds, but it is possible to implement
161- // / a local renaming scheme based on the result of this call.
162- LogicalResult setBody (ArrayRef<Type> types, bool isPacked);
163-
164- // / Checks if a struct is packed.
165- bool isPacked () const ;
166-
167- // / Checks if a struct is identified.
168- bool isIdentified () const ;
169-
170- // / Checks if a struct is opaque.
171- bool isOpaque ();
172-
173- // / Checks if a struct is initialized.
174- bool isInitialized ();
175-
176- // / Returns the name of an identified struct.
177- StringRef getName ();
178-
179- // / Returns the list of element types contained in a non-opaque struct.
180- ArrayRef<Type> getBody () const ;
181-
182- // / Verifies that the type about to be constructed is well-formed.
183- static LogicalResult
184- verifyInvariants (function_ref<InFlightDiagnostic()> emitError, StringRef,
185- bool );
186- static LogicalResult
187- verifyInvariants (function_ref<InFlightDiagnostic()> emitError,
188- ArrayRef<Type> types, bool );
189- using Base::verifyInvariants;
190-
191- // / Hooks for DataLayoutTypeInterface. Should not be called directly. Obtain a
192- // / DataLayout instance and query it instead.
193- llvm::TypeSize getTypeSizeInBits (const DataLayout &dataLayout,
194- DataLayoutEntryListRef params) const ;
195-
196- uint64_t getABIAlignment (const DataLayout &dataLayout,
197- DataLayoutEntryListRef params) const ;
198-
199- uint64_t getPreferredAlignment (const DataLayout &dataLayout,
200- DataLayoutEntryListRef params) const ;
201-
202- bool areCompatible (DataLayoutEntryListRef oldLayout,
203- DataLayoutEntryListRef newLayout) const ;
204-
205- LogicalResult verifyEntries (DataLayoutEntryListRef entries,
206- Location loc) const ;
207-
208- // / Destructs the struct into its indexed field types.
209- std::optional<DenseMap<Attribute, Type>> getSubelementIndexMap ();
210-
211- // / Returns which type is stored at a given integer index within the struct.
212- Type getTypeAtIndex (Attribute index);
213- };
214-
21576// ===----------------------------------------------------------------------===//
21677// Printing and parsing.
21778// ===----------------------------------------------------------------------===//
0 commit comments