Skip to content

Commit f832bee

Browse files
authored
[flang][NFC] Use the tablegen definition for FIR dialect (#84822)
FIROpsDialect has been declared manually with a class inheriting from the MLIR Dialect class. Another declaration is done using tablegen here `flang/include/flang/Optimizer/Dialect/FIRDialect.td`. This patch merge the two declaration so we can use the tablegen generated class for all the FIROpsDialect needs. This is part of a series of patch to bring FIR up to date with the current MLIR infra.
1 parent f4c1e87 commit f832bee

File tree

7 files changed

+40
-47
lines changed

7 files changed

+40
-47
lines changed

flang/include/flang/Optimizer/Dialect/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# This replicates part of the add_mlir_dialect cmake function from MLIR that
22
# cannot be used her because it expects to be run inside MLIR directory which
33
# is not the case for FIR.
4+
set(LLVM_TARGET_DEFINITIONS FIRDialect.td)
5+
mlir_tablegen(FIRDialect.h.inc -gen-dialect-decls -dialect=fir)
6+
mlir_tablegen(FIRDialect.cpp.inc -gen-dialect-defs -dialect=fir)
7+
48
set(LLVM_TARGET_DEFINITIONS FIRAttr.td)
59
mlir_tablegen(FIREnumAttr.h.inc -gen-enum-decls)
610
mlir_tablegen(FIREnumAttr.cpp.inc -gen-enum-defs)

flang/include/flang/Optimizer/Dialect/FIRAttr.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
include "flang/Optimizer/Dialect/FIRDialect.td"
1717
include "mlir/IR/EnumAttr.td"
1818

19-
class fir_Attr<string name> : AttrDef<fir_Dialect, name>;
19+
class fir_Attr<string name> : AttrDef<FIROpsDialect, name>;
2020

2121
def FIRnoAttributes : I32BitEnumAttrCaseNone<"None">;
2222
def FIRallocatable : I32BitEnumAttrCaseBit<"allocatable", 0>;
@@ -91,7 +91,7 @@ def fir_CUDADataAttribute : I32EnumAttr<
9191
}
9292

9393
def fir_CUDADataAttributeAttr :
94-
EnumAttr<fir_Dialect, fir_CUDADataAttribute, "cuda"> {
94+
EnumAttr<FIROpsDialect, fir_CUDADataAttribute, "cuda"> {
9595
let assemblyFormat = [{ ```<` $value `>` }];
9696
}
9797

@@ -109,7 +109,7 @@ def fir_CUDAProcAttribute : I32EnumAttr<
109109
}
110110

111111
def fir_CUDAProcAttributeAttr :
112-
EnumAttr<fir_Dialect, fir_CUDAProcAttribute, "cuda_proc"> {
112+
EnumAttr<FIROpsDialect, fir_CUDAProcAttribute, "cuda_proc"> {
113113
let assemblyFormat = [{ ```<` $value `>` }];
114114
}
115115

flang/include/flang/Optimizer/Dialect/FIRDialect.h

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,43 +15,14 @@
1515

1616
#include "mlir/IR/Dialect.h"
1717

18+
#include "flang/Optimizer/Dialect/FIRDialect.h.inc"
19+
1820
namespace mlir {
1921
class IRMapping;
2022
} // namespace mlir
2123

2224
namespace fir {
2325

24-
/// FIR dialect
25-
class FIROpsDialect final : public mlir::Dialect {
26-
public:
27-
explicit FIROpsDialect(mlir::MLIRContext *ctx);
28-
virtual ~FIROpsDialect();
29-
30-
static llvm::StringRef getDialectNamespace() { return "fir"; }
31-
32-
mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
33-
void printType(mlir::Type ty, mlir::DialectAsmPrinter &p) const override;
34-
35-
mlir::Attribute parseAttribute(mlir::DialectAsmParser &parser,
36-
mlir::Type type) const override;
37-
void printAttribute(mlir::Attribute attr,
38-
mlir::DialectAsmPrinter &p) const override;
39-
40-
/// Return string name of fir.runtime attribute.
41-
static constexpr llvm::StringRef getFirRuntimeAttrName() {
42-
return "fir.runtime";
43-
}
44-
45-
private:
46-
// Register the Attributes of this dialect.
47-
void registerAttributes();
48-
// Register the Types of this dialect.
49-
void registerTypes();
50-
// Register external interfaces on operations of
51-
// this dialect.
52-
void registerOpExternalInterfaces();
53-
};
54-
5526
/// The FIR codegen dialect is a dialect containing a small set of transient
5627
/// operations used exclusively during code generation.
5728
class FIRCodeGenDialect final : public mlir::Dialect {

flang/include/flang/Optimizer/Dialect/FIRDialect.td

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ include "mlir/Interfaces/InferTypeOpInterface.td"
2121
include "mlir/Interfaces/LoopLikeInterface.td"
2222
include "mlir/Interfaces/SideEffectInterfaces.td"
2323

24-
def fir_Dialect : Dialect {
24+
def FIROpsDialect : Dialect {
2525
let name = "fir";
2626
let cppNamespace = "::fir";
2727
let useDefaultTypePrinterParser = 0;
@@ -30,10 +30,33 @@ def fir_Dialect : Dialect {
3030
let dependentDialects = [
3131
// Arith dialect provides FastMathFlagsAttr
3232
// supported by some FIR operations.
33-
"arith::ArithDialect",
33+
"mlir::arith::ArithDialect",
3434
// TBAA Tag types
35-
"LLVM::LLVMDialect"
35+
"mlir::LLVM::LLVMDialect"
3636
];
37+
let extraClassDeclaration = [{
38+
private:
39+
// Register the builtin Attributes.
40+
void registerAttributes();
41+
// Register the builtin Types.
42+
void registerTypes();
43+
// Register external interfaces on operations of
44+
// this dialect.
45+
void registerOpExternalInterfaces();
46+
public:
47+
mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
48+
void printType(mlir::Type ty, mlir::DialectAsmPrinter &p) const override;
49+
50+
mlir::Attribute parseAttribute(mlir::DialectAsmParser &parser,
51+
mlir::Type type) const override;
52+
void printAttribute(mlir::Attribute attr,
53+
mlir::DialectAsmPrinter &p) const override;
54+
55+
// Return string name of fir.runtime attribute.
56+
static constexpr llvm::StringRef getFirRuntimeAttrName() {
57+
return "fir.runtime";
58+
}
59+
}];
3760
}
3861

3962
#endif // FORTRAN_DIALECT_FIR_DIALECT

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ include "mlir/IR/BuiltinAttributes.td"
2727
// Base class for FIR operations.
2828
// All operations automatically get a prefix of "fir.".
2929
class fir_Op<string mnemonic, list<Trait> traits>
30-
: Op<fir_Dialect, mnemonic, traits>;
30+
: Op<FIROpsDialect, mnemonic, traits>;
3131

3232
// Base class for FIR operations that take a single argument
3333
class fir_SimpleOp<string mnemonic, list<Trait> traits>

flang/include/flang/Optimizer/Dialect/FIRTypes.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ include "flang/Optimizer/Dialect/FIRDialect.td"
2222

2323
class FIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
2424
string baseCppClass = "::mlir::Type">
25-
: TypeDef<fir_Dialect, name, traits, baseCppClass> {
25+
: TypeDef<FIROpsDialect, name, traits, baseCppClass> {
2626
let mnemonic = typeMnemonic;
2727
}
2828

flang/lib/Optimizer/Dialect/FIRDialect.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
1919
#include "mlir/Transforms/InliningUtils.h"
2020

21+
#include "flang/Optimizer/Dialect/FIRDialect.cpp.inc"
22+
2123
using namespace fir;
2224

2325
namespace {
@@ -58,9 +60,7 @@ struct FIRInlinerInterface : public mlir::DialectInlinerInterface {
5860
};
5961
} // namespace
6062

61-
fir::FIROpsDialect::FIROpsDialect(mlir::MLIRContext *ctx)
62-
: mlir::Dialect("fir", ctx, mlir::TypeID::get<FIROpsDialect>()) {
63-
getContext()->loadDialect<mlir::LLVM::LLVMDialect>();
63+
void fir::FIROpsDialect::initialize() {
6464
registerTypes();
6565
registerAttributes();
6666
addOperations<
@@ -94,11 +94,6 @@ void fir::addFIRToLLVMIRExtension(mlir::DialectRegistry &registry) {
9494
});
9595
}
9696

97-
// anchor the class vtable to this compilation unit
98-
fir::FIROpsDialect::~FIROpsDialect() {
99-
// do nothing
100-
}
101-
10297
mlir::Type fir::FIROpsDialect::parseType(mlir::DialectAsmParser &parser) const {
10398
return parseFirType(const_cast<FIROpsDialect *>(this), parser);
10499
}

0 commit comments

Comments
 (0)