Skip to content

[flang][NFC] Use the tablegen definition for FIR dialect #84822

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions flang/include/flang/Optimizer/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# This replicates part of the add_mlir_dialect cmake function from MLIR that
# cannot be used her because it expects to be run inside MLIR directory which
# is not the case for FIR.
set(LLVM_TARGET_DEFINITIONS FIRDialect.td)
mlir_tablegen(FIRDialect.h.inc -gen-dialect-decls -dialect=fir)
mlir_tablegen(FIRDialect.cpp.inc -gen-dialect-defs -dialect=fir)

set(LLVM_TARGET_DEFINITIONS FIRAttr.td)
mlir_tablegen(FIREnumAttr.h.inc -gen-enum-decls)
mlir_tablegen(FIREnumAttr.cpp.inc -gen-enum-defs)
Expand Down
6 changes: 3 additions & 3 deletions flang/include/flang/Optimizer/Dialect/FIRAttr.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
include "flang/Optimizer/Dialect/FIRDialect.td"
include "mlir/IR/EnumAttr.td"

class fir_Attr<string name> : AttrDef<fir_Dialect, name>;
class fir_Attr<string name> : AttrDef<FIROpsDialect, name>;

def FIRnoAttributes : I32BitEnumAttrCaseNone<"None">;
def FIRallocatable : I32BitEnumAttrCaseBit<"allocatable", 0>;
Expand Down Expand Up @@ -91,7 +91,7 @@ def fir_CUDADataAttribute : I32EnumAttr<
}

def fir_CUDADataAttributeAttr :
EnumAttr<fir_Dialect, fir_CUDADataAttribute, "cuda"> {
EnumAttr<FIROpsDialect, fir_CUDADataAttribute, "cuda"> {
let assemblyFormat = [{ ```<` $value `>` }];
}

Expand All @@ -109,7 +109,7 @@ def fir_CUDAProcAttribute : I32EnumAttr<
}

def fir_CUDAProcAttributeAttr :
EnumAttr<fir_Dialect, fir_CUDAProcAttribute, "cuda_proc"> {
EnumAttr<FIROpsDialect, fir_CUDAProcAttribute, "cuda_proc"> {
let assemblyFormat = [{ ```<` $value `>` }];
}

Expand Down
33 changes: 2 additions & 31 deletions flang/include/flang/Optimizer/Dialect/FIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,14 @@

#include "mlir/IR/Dialect.h"

#include "flang/Optimizer/Dialect/FIRDialect.h.inc"

namespace mlir {
class IRMapping;
} // namespace mlir

namespace fir {

/// FIR dialect
class FIROpsDialect final : public mlir::Dialect {
public:
explicit FIROpsDialect(mlir::MLIRContext *ctx);
virtual ~FIROpsDialect();

static llvm::StringRef getDialectNamespace() { return "fir"; }

mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
void printType(mlir::Type ty, mlir::DialectAsmPrinter &p) const override;

mlir::Attribute parseAttribute(mlir::DialectAsmParser &parser,
mlir::Type type) const override;
void printAttribute(mlir::Attribute attr,
mlir::DialectAsmPrinter &p) const override;

/// Return string name of fir.runtime attribute.
static constexpr llvm::StringRef getFirRuntimeAttrName() {
return "fir.runtime";
}

private:
// Register the Attributes of this dialect.
void registerAttributes();
// Register the Types of this dialect.
void registerTypes();
// Register external interfaces on operations of
// this dialect.
void registerOpExternalInterfaces();
};

/// The FIR codegen dialect is a dialect containing a small set of transient
/// operations used exclusively during code generation.
class FIRCodeGenDialect final : public mlir::Dialect {
Expand Down
29 changes: 26 additions & 3 deletions flang/include/flang/Optimizer/Dialect/FIRDialect.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"

def fir_Dialect : Dialect {
def FIROpsDialect : Dialect {
let name = "fir";
let cppNamespace = "::fir";
let useDefaultTypePrinterParser = 0;
Expand All @@ -30,10 +30,33 @@ def fir_Dialect : Dialect {
let dependentDialects = [
// Arith dialect provides FastMathFlagsAttr
// supported by some FIR operations.
"arith::ArithDialect",
"mlir::arith::ArithDialect",
// TBAA Tag types
"LLVM::LLVMDialect"
"mlir::LLVM::LLVMDialect"
];
let extraClassDeclaration = [{
private:
// Register the builtin Attributes.
void registerAttributes();
// Register the builtin Types.
void registerTypes();
// Register external interfaces on operations of
// this dialect.
void registerOpExternalInterfaces();
public:
mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
void printType(mlir::Type ty, mlir::DialectAsmPrinter &p) const override;

mlir::Attribute parseAttribute(mlir::DialectAsmParser &parser,
mlir::Type type) const override;
void printAttribute(mlir::Attribute attr,
mlir::DialectAsmPrinter &p) const override;

// Return string name of fir.runtime attribute.
static constexpr llvm::StringRef getFirRuntimeAttrName() {
return "fir.runtime";
}
}];
}

#endif // FORTRAN_DIALECT_FIR_DIALECT
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Dialect/FIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ include "mlir/IR/BuiltinAttributes.td"
// Base class for FIR operations.
// All operations automatically get a prefix of "fir.".
class fir_Op<string mnemonic, list<Trait> traits>
: Op<fir_Dialect, mnemonic, traits>;
: Op<FIROpsDialect, mnemonic, traits>;

// Base class for FIR operations that take a single argument
class fir_SimpleOp<string mnemonic, list<Trait> traits>
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Dialect/FIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ include "flang/Optimizer/Dialect/FIRDialect.td"

class FIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
string baseCppClass = "::mlir::Type">
: TypeDef<fir_Dialect, name, traits, baseCppClass> {
: TypeDef<FIROpsDialect, name, traits, baseCppClass> {
let mnemonic = typeMnemonic;
}

Expand Down
11 changes: 3 additions & 8 deletions flang/lib/Optimizer/Dialect/FIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "mlir/Target/LLVMIR/ModuleTranslation.h"
#include "mlir/Transforms/InliningUtils.h"

#include "flang/Optimizer/Dialect/FIRDialect.cpp.inc"

using namespace fir;

namespace {
Expand Down Expand Up @@ -58,9 +60,7 @@ struct FIRInlinerInterface : public mlir::DialectInlinerInterface {
};
} // namespace

fir::FIROpsDialect::FIROpsDialect(mlir::MLIRContext *ctx)
: mlir::Dialect("fir", ctx, mlir::TypeID::get<FIROpsDialect>()) {
getContext()->loadDialect<mlir::LLVM::LLVMDialect>();
void fir::FIROpsDialect::initialize() {
registerTypes();
registerAttributes();
addOperations<
Expand Down Expand Up @@ -94,11 +94,6 @@ void fir::addFIRToLLVMIRExtension(mlir::DialectRegistry &registry) {
});
}

// anchor the class vtable to this compilation unit
fir::FIROpsDialect::~FIROpsDialect() {
// do nothing
}

mlir::Type fir::FIROpsDialect::parseType(mlir::DialectAsmParser &parser) const {
return parseFirType(const_cast<FIROpsDialect *>(this), parser);
}
Expand Down