Skip to content

Commit 7fdc651

Browse files
committed
[CIR][MLIR] Add some named_tuple type introspection functions
1 parent 27bc429 commit 7fdc651

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

mlir/include/mlir/Dialect/NamedTuple/IR/NamedTupleTypes.td

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,25 @@ def NamedTuple_NamedTupleType : NamedTuple_Type<"NamedTuple", "named_tuple", [
5151
}]>
5252
];
5353

54-
// \todo
55-
// let extraClassDeclaration = [{
56-
// /// Return the number of held types.
57-
// size_t size() const;
54+
let extraClassDeclaration = [{
55+
/// Return the number of held types.
56+
size_t size() const {
57+
return getMemberTypes().size();
58+
}
5859

59-
// /// Iterate over the held elements.
60-
// using iterator = ArrayRef<Type>::iterator;
61-
// iterator begin() const { return getTypes().begin(); }
62-
// iterator end() const { return getTypes().end(); }
60+
// TODO: needs a more complex iterator since the storage is not an
61+
// ArrayRef<Type>.
62+
/// Iterate over the held elements.
63+
// using iterator = ArrayRef<Type>::iterator;
64+
// iterator begin() const { return getTypes().begin(); }
65+
// iterator end() const { return getTypes().end(); }
6366

64-
// /// Return the element type at index 'index'.
65-
// Type getType(size_t index) const {
66-
// assert(index < size() && "invalid index for tuple type");
67-
// return getTypes()[index];
68-
// }
69-
// }];
67+
/// Return the element type at index 'index'.
68+
Type getType(size_t index) const {
69+
assert(index < size() && "invalid index for named_tuple type");
70+
return mlir::cast<mlir::TypeAttr>(getMemberTypes()[index]).getValue();
71+
}
72+
}];
7073
}
7174

7275
#endif // NAMED_TUPLE_TYPES

0 commit comments

Comments
 (0)