Skip to content

Commit 5fd9098

Browse files
authored
[CIR] Refactor VoidPtr constraint to CIR_VoidPtrType (#138859)
This mirrors incubator changes from llvm/clangir#1601
1 parent 68ee36a commit 5fd9098

File tree

2 files changed

+56
-15
lines changed

2 files changed

+56
-15
lines changed

clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,37 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType],
141141
let cppFunctionName = "isAnyIntegerOrFloatingPointType";
142142
}
143143

144+
//===----------------------------------------------------------------------===//
145+
// Pointer Type predicates
146+
//===----------------------------------------------------------------------===//
147+
148+
def CIR_AnyPtrType : CIR_TypeBase<"::cir::PointerType", "pointer type">;
149+
150+
// Pointer to type constraint bases
151+
class CIR_IsPtrToPred<code type> : CPred<"$_self.isPtrTo<" # type # ">()">;
152+
153+
class CIR_PtrTo<code type, string summary>
154+
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPred<type>],
155+
"pointer to " # summary>;
156+
157+
// Pointer to pointer constraint bases
158+
class CIR_IsPtrToPtrToPred<code type>
159+
: CPred<"$_self.isPtrToPtrTo<" # type # ">()">;
160+
161+
class CIR_PtrToPtrTo<code type, string summary>
162+
: CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPtrToPred<type>],
163+
"pointer to pointer to " # summary>;
164+
165+
// Void pointer type constraints
166+
def CIR_VoidPtrType
167+
: CIR_PtrTo<"::cir::VoidType", "void type">,
168+
BuildableType<"$_builder.getType<" # cppType # ">("
169+
"cir::VoidType::get($_builder.getContext()))">;
170+
171+
def CIR_PtrToVoidPtrType
172+
: CIR_PtrToPtrTo<"::cir::VoidType", "void type">,
173+
BuildableType<"$_builder.getType<" # cppType # ">("
174+
"$_builder.getType<" # cppType # ">("
175+
"cir::VoidType::get($_builder.getContext())))">;
176+
144177
#endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,30 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr",
197197
let skipDefaultBuilders = 1;
198198

199199
let extraClassDeclaration = [{
200+
template <typename ...Types>
201+
bool isPtrTo() const {
202+
return mlir::isa< Types... >(getPointee());
203+
}
204+
200205
bool isVoidPtr() const {
201-
return mlir::isa<cir::VoidType>(getPointee());
206+
return isPtrTo<cir::VoidType>();
207+
}
208+
209+
template <typename ...Types>
210+
bool isPtrToPtrTo() const {
211+
if (auto ptrType = mlir::dyn_cast<cir::PointerType>(getPointee()))
212+
return ptrType.isPtrTo<Types...>();
213+
return false;
214+
}
215+
216+
bool isPtrTo(mlir::Type type) const {
217+
return getPointee() == type;
218+
}
219+
220+
bool isPtrToPtrTo(mlir::Type type) const {
221+
if (auto ptrType = mlir::dyn_cast<cir::PointerType>(getPointee()))
222+
return ptrType.isPtrTo(type);
223+
return false;
202224
}
203225
}];
204226
}
@@ -368,20 +390,6 @@ def CIR_VoidType : CIR_Type<"Void", "void"> {
368390
}];
369391
}
370392

371-
// Constraints
372-
373-
// Pointer to void
374-
def VoidPtr : Type<
375-
And<[
376-
CPred<"::mlir::isa<::cir::PointerType>($_self)">,
377-
CPred<"::mlir::isa<::cir::VoidType>("
378-
"::mlir::cast<::cir::PointerType>($_self).getPointee())">,
379-
]>, "void*">,
380-
BuildableType<
381-
"cir::PointerType::get($_builder.getContext(),"
382-
"cir::VoidType::get($_builder.getContext()))"> {
383-
}
384-
385393
//===----------------------------------------------------------------------===//
386394
// RecordType
387395
//

0 commit comments

Comments
 (0)