-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[CIR] Refactor VoidPtr constraint to CIR_VoidPtrType #138859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-clang Author: Henrich Lauko (xlauko) ChangesThis mirrors incubator changes from llvm/clangir#1601 Full diff: https://github.com/llvm/llvm-project/pull/138859.diff 2 Files Affected:
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
//
|
@llvm/pr-subscribers-clangir Author: Henrich Lauko (xlauko) ChangesThis mirrors incubator changes from llvm/clangir#1601 Full diff: https://github.com/llvm/llvm-project/pull/138859.diff 2 Files Affected:
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
//
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable, but I'd like Andy to take a look at this before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
e9b719b
to
f875b20
Compare
This mirrors incubator changes from llvm/clangir#1601
f93f03a
to
5ce38e9
Compare
This mirrors incubator changes from llvm/clangir#1601