[Mlir-commits] [mlir] [MLIR][LLVM] Support Recursive DITypes (PR #80251)
Tobias Gysi
llvmlistbot at llvm.org
Wed Mar 13 10:39:27 PDT 2024
================
@@ -319,4 +319,58 @@ def LLVM_PointerElementTypeInterface
];
}
+//===----------------------------------------------------------------------===//
+// LLVM dialect attr interfaces.
+//===----------------------------------------------------------------------===//
+
+def LLVM_DIRecursiveTypeAttrInterface
+ : AttrInterface<"DIRecursiveTypeAttrInterface"> {
+ let description = [{
+ This attribute represents a DITypeAttr that is recursive. Only DITypeAttrs
+ that translate to LLVM DITypes that support mutation should implement this
+ interface.
+
+ There are two modes for conforming attributes:
+
+ 1. "rec-decl":
+ - This attr is a recursive declaration identified by a recId.
+
+ 2. "rec-self":
+ - This attr is considered a recursive self reference.
+ - This attr itself is a placeholder type that should be conceptually
+ replaced with the closest parent attr of the same type with the same
+ recId.
+
+ For example, to represent a linked list struct:
+
+ #rec_self = di_composite_type<recId = 0>
+ #ptr = di_derived_type<baseType: #rec_self, ...>
+ #field = di_derived_type<name = "next", baseType: #ptr, ...>
+ #rec = di_composite_type<recId = 0, name = "Node", elements: #field, ...>
+ #var = di_local_variable<type = #rec, ...>
+
+ Note that a rec-self without an outer rec-decl with the same recId is
+ conceptually the same as an "unbound" variable. The context needs to provide
+ meaning to the rec-self.
+ }];
+ let cppNamespace = "::mlir::LLVM";
+ let methods = [
+ InterfaceMethod<[{
+ Get whether this attr describes a recursive self reference.
+ }], "bool", "isRecSelf", (ins)>,
+ InterfaceMethod<[{
+ Get the recursive ID used for matching "rec-decl" with "rec-self".
+ If this attr instance is not recursive, return a null attribute.
+ }], "DistinctAttr", "getRecId", (ins)>,
+ InterfaceMethod<[{
+ Get a copy of this type attr but with the recursive ID set to `recId`.
+ }], "DIRecursiveTypeAttrInterface", "withRecId",
+ (ins "DistinctAttr":$recId)>,
+ StaticInterfaceMethod<[{
+ Build a rec-self instance using the provided recId.
----------------
gysit wrote:
```suggestion
Build a rec-self instance using the provided `recId`.
```
ultra nit:
https://github.com/llvm/llvm-project/pull/80251
More information about the Mlir-commits
mailing list