Author: Henrich Lauko Date: 2025-05-07T19:23:53+02:00 New Revision: 5fd90987e147c64a735f0cb2bcfbef4e4cce5e21
URL: https://github.com/llvm/llvm-project/commit/5fd90987e147c64a735f0cb2bcfbef4e4cce5e21 DIFF: https://github.com/llvm/llvm-project/commit/5fd90987e147c64a735f0cb2bcfbef4e4cce5e21.diff LOG: [CIR] Refactor VoidPtr constraint to CIR_VoidPtrType (#138859) This mirrors incubator changes from https://github.com/llvm/clangir/pull/1601 Added: Modified: clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td clang/include/clang/CIR/Dialect/IR/CIRTypes.td Removed: ################################################################################ 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<code type> : CPred<"$_self.isPtrTo<" # type # ">()">; + +class CIR_PtrTo<code type, string summary> + : CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPred<type>], + "pointer to " # summary>; + +// Pointer to pointer constraint bases +class CIR_IsPtrToPtrToPred<code type> + : CPred<"$_self.isPtrToPtrTo<" # type # ">()">; + +class CIR_PtrToPtrTo<code type, string summary> + : CIR_ConfinedType<CIR_AnyPtrType, [CIR_IsPtrToPtrToPred<type>], + "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 <typename ...Types> + bool isPtrTo() const { + return mlir::isa< Types... >(getPointee()); + } + bool isVoidPtr() const { - return mlir::isa<cir::VoidType>(getPointee()); + return isPtrTo<cir::VoidType>(); + } + + template <typename ...Types> + bool isPtrToPtrTo() const { + if (auto ptrType = mlir::dyn_cast<cir::PointerType>(getPointee())) + return ptrType.isPtrTo<Types...>(); + return false; + } + + bool isPtrTo(mlir::Type type) const { + return getPointee() == type; + } + + bool isPtrToPtrTo(mlir::Type type) const { + if (auto ptrType = mlir::dyn_cast<cir::PointerType>(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 // _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits