[flang-commits] [flang] [flang][nfc] replace fir.dispatch_table with more generic fir.type_info (PR #68309)
via flang-commits
flang-commits at lists.llvm.org
Fri Oct 6 00:26:21 PDT 2023
================
@@ -2831,32 +2846,46 @@ def fir_DispatchTableOp : fir_Op<"dispatch_table",
let arguments = (ins
SymbolNameAttr:$sym_name,
- OptionalAttr<StrAttr>:$parent
+ TypeAttr:$type,
+ OptionalAttr<TypeAttr>:$parent_type,
+ UnitAttr:$no_init,
+ UnitAttr:$no_destroy,
+ UnitAttr:$no_final
);
- let hasCustomAssemblyFormat = 1;
let hasVerifier = 1;
- let regions = (region AnyRegion:$region);
+ let regions = (region MaxSizedRegion<1>:$dispatch_table);
- let skipDefaultBuilders = 1;
let builders = [
- OpBuilder<(ins "llvm::StringRef":$name, "mlir::Type":$type,
- "llvm::StringRef":$parent,
+ OpBuilder<(ins "fir::RecordType":$type, "fir::RecordType":$parent_type,
CArg<"llvm::ArrayRef<mlir::NamedAttribute>", "{}">:$attrs)>
];
- let extraClassDeclaration = [{
- static constexpr llvm::StringRef getParentAttrNameStr() { return "parent"; }
- static constexpr llvm::StringRef getExtendsKeyword() { return "extends"; }
+ let assemblyFormat = [{
+ $sym_name (`noinit` $no_init^)? (`nodestroy` $no_destroy^)?
+ (`nofinal` $no_final^)? (`extends` $parent_type^)? attr-dict `:` $type
+ (`dispatch_table` $dispatch_table^)?
+ }];
- mlir::Block &getBlock() {
- return getRegion().front();
+ let extraClassDeclaration = [{
+ fir::RecordType getRecordType() {
+ return mlir::cast<fir::RecordType>(getType());
+ }
+ fir::RecordType getIfParentType() {
+ if (auto parentType = getParentType())
+ return mlir::cast<fir::RecordType>(*parentType);
+ return {};
+ }
+ std::optional<llvm::StringRef> getIfParentName() {
+ if (auto parentType = getIfParentType())
+ return parentType.getName();
+ return std::nullopt;
}
}];
}
-def fir_DTEntryOp : fir_Op<"dt_entry", [HasParent<"DispatchTableOp">]> {
+def fir_DTEntryOp : fir_Op<"dt_entry", [HasParent<"TypeInfoOp">]> {
----------------
jeanPerier wrote:
Thanks for the review, that is a good point. I agree we likely can do it with an array attribute of something and it may be more efficient.
The only drawback is that I do not know if this is possible to print attributes on new lines/several lines, and I think it would make the operation a bit harder to read/debug if it is a gigantic line (although binding tables are probably not that long usually, but there will also be the special bindings to describe at some point and the array components lower bounds).
I will try to think about this more when adding more info.
https://github.com/llvm/llvm-project/pull/68309
More information about the flang-commits
mailing list