diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td index 10e5d15ff9fa8..00f67e2a03a25 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td @@ -141,4 +141,37 @@ def CIR_AnyIntOrFloatType : AnyTypeOf<[CIR_AnyFloatType, CIR_AnyIntType], let cppFunctionName = "isAnyIntegerOrFloatingPointType"; } +//===----------------------------------------------------------------------===// +// Pointer Type predicates +//===----------------------------------------------------------------------===// + +def CIR_AnyPtrType : CIR_TypeBase<"::cir::PointerType", "pointer type">; + +// Pointer to type constraint bases +class CIR_IsPtrToPred : CPred<"$_self.isPtrTo<" # type # ">()">; + +class CIR_PtrTo + : CIR_ConfinedType], + "pointer to " # summary>; + +// Pointer to pointer constraint bases +class CIR_IsPtrToPtrToPred + : CPred<"$_self.isPtrToPtrTo<" # type # ">()">; + +class CIR_PtrToPtrTo + : CIR_ConfinedType], + "pointer to pointer to " # summary>; + +// Void pointer type constraints +def CIR_VoidPtrType + : CIR_PtrTo<"::cir::VoidType", "void type">, + BuildableType<"$_builder.getType<" # cppType # ">(" + "cir::VoidType::get($_builder.getContext()))">; + +def CIR_PtrToVoidPtrType + : CIR_PtrToPtrTo<"::cir::VoidType", "void type">, + BuildableType<"$_builder.getType<" # cppType # ">(" + "$_builder.getType<" # cppType # ">(" + "cir::VoidType::get($_builder.getContext())))">; + #endif // CLANG_CIR_DIALECT_IR_CIRTYPECONSTRAINTS_TD diff --git a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td index 959e2cd822e76..26f1122a4b261 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIRTypes.td +++ b/clang/include/clang/CIR/Dialect/IR/CIRTypes.td @@ -197,8 +197,30 @@ def CIR_PointerType : CIR_Type<"Pointer", "ptr", let skipDefaultBuilders = 1; let extraClassDeclaration = [{ + template + bool isPtrTo() const { + return mlir::isa< Types... >(getPointee()); + } + bool isVoidPtr() const { - return mlir::isa(getPointee()); + return isPtrTo(); + } + + template + bool isPtrToPtrTo() const { + if (auto ptrType = mlir::dyn_cast(getPointee())) + return ptrType.isPtrTo(); + return false; + } + + bool isPtrTo(mlir::Type type) const { + return getPointee() == type; + } + + bool isPtrToPtrTo(mlir::Type type) const { + if (auto ptrType = mlir::dyn_cast(getPointee())) + return ptrType.isPtrTo(type); + return false; } }]; } @@ -368,20 +390,6 @@ def CIR_VoidType : CIR_Type<"Void", "void"> { }]; } -// Constraints - -// Pointer to void -def VoidPtr : Type< - And<[ - CPred<"::mlir::isa<::cir::PointerType>($_self)">, - CPred<"::mlir::isa<::cir::VoidType>(" - "::mlir::cast<::cir::PointerType>($_self).getPointee())">, - ]>, "void*">, - BuildableType< - "cir::PointerType::get($_builder.getContext()," - "cir::VoidType::get($_builder.getContext()))"> { -} - //===----------------------------------------------------------------------===// // RecordType //