[flang-commits] [flang] [flang][nfc] replace fir.dispatch_table with more generic fir.type_info (PR #68309)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Thu Oct 5 14:59:48 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">]> {
----------------
clementval wrote:
I'm wondering if we really need an operation for the entry. We can maybe just store this directly in the TypeInfoOp. Anyway this is a comment for future clean up.
https://github.com/llvm/llvm-project/pull/68309
More information about the flang-commits
mailing list