@@ -31,6 +31,18 @@ class CIR_ConfinedType<Type type, list<Pred> preds, string summary = "">
3131 : Type<And<[type.predicate, CIR_CastedSelfsToType<type.cppType, preds>]>,
3232 summary, type.cppType>;
3333
34+ // Generates a type summary.
35+ // - For a single type: returns its summary.
36+ // - For multiple types: returns `any of <comma-separated summaries>`.
37+ class CIR_TypeSummaries<list<Type> types> {
38+ assert !not(!empty(types)), "expects non-empty list of types";
39+
40+ list<string> summaries = !foreach(type, types, type.summary);
41+ string joined = !interleave(summaries, ", ");
42+
43+ string value = !if(!eq(!size(types), 1), joined, "any of " # joined);
44+ }
45+
3446//===----------------------------------------------------------------------===//
3547// IntType predicates
3648//===----------------------------------------------------------------------===//
@@ -151,6 +163,12 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
151163
152164def CIR_AnyComplexType : CIR_TypeBase<"::cir::ComplexType", "complex type">;
153165
166+ //===----------------------------------------------------------------------===//
167+ // Record Type predicates
168+ //===----------------------------------------------------------------------===//
169+
170+ def CIR_AnyRecordType : CIR_TypeBase<"::cir::RecordType", "record type">;
171+
154172//===----------------------------------------------------------------------===//
155173// Pointer Type predicates
156174//===----------------------------------------------------------------------===//
@@ -176,9 +194,14 @@ class CIR_PtrToPtrTo<code type, string summary>
176194class CIR_PointeePred<Pred pred> : SubstLeaves<"$_self",
177195 "::mlir::cast<::cir::PointerType>($_self).getPointee()", pred>;
178196
179- class CIR_PtrToType<Type type>
180- : CIR_ConfinedType<CIR_AnyPtrType, [CIR_PointeePred<type.predicate>],
181- "pointer to " # type.summary>;
197+ class CIR_PtrToAnyOf<list<Type> types, string summary = "">
198+ : CIR_ConfinedType<CIR_AnyPtrType,
199+ [Or<!foreach(type, types, CIR_PointeePred<type.predicate>)>],
200+ !if(!empty(summary),
201+ "pointer to " # CIR_TypeSummaries<types>.value,
202+ summary)>;
203+
204+ class CIR_PtrToType<Type type> : CIR_PtrToAnyOf<[type]>;
182205
183206// Void pointer type constraints
184207def CIR_VoidPtrType
@@ -197,4 +220,6 @@ def CIR_PtrToIntOrFloatType : CIR_PtrToType<CIR_AnyIntOrFloatType>;
197220
198221def CIR_PtrToComplexType : CIR_PtrToType<CIR_AnyComplexType>;
199222
223+ def CIR_PtrToRecordType : CIR_PtrToType<CIR_AnyRecordType>;
224+
200225#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD
0 commit comments