1 //===-- Optimizer/Dialect/FIRDialect.h -- FIR dialect -----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef OPTIMIZER_DIALECT_FIRDIALECT_H
10 #define OPTIMIZER_DIALECT_FIRDIALECT_H
11
12 #include "mlir/IR/Dialect.h"
13 #include "mlir/InitAllDialects.h"
14 #include "mlir/InitAllPasses.h"
15
16 namespace fir {
17
18 /// FIR dialect
19 class FIROpsDialect final : public mlir::Dialect {
20 public:
21 explicit FIROpsDialect(mlir::MLIRContext *ctx);
22 virtual ~FIROpsDialect();
23
getDialectNamespace()24 static llvm::StringRef getDialectNamespace() { return "fir"; }
25
26 mlir::Type parseType(mlir::DialectAsmParser &parser) const override;
27 void printType(mlir::Type ty, mlir::DialectAsmPrinter &p) const override;
28
29 mlir::Attribute parseAttribute(mlir::DialectAsmParser &parser,
30 mlir::Type type) const override;
31 void printAttribute(mlir::Attribute attr,
32 mlir::DialectAsmPrinter &p) const override;
33 };
34
35 /// Register the dialect with the provided registry.
registerFIRDialects(mlir::DialectRegistry & registry)36 inline void registerFIRDialects(mlir::DialectRegistry ®istry) {
37 // clang-format off
38 registry.insert<mlir::AffineDialect,
39 mlir::LLVM::LLVMDialect,
40 mlir::acc::OpenACCDialect,
41 mlir::omp::OpenMPDialect,
42 mlir::scf::SCFDialect,
43 mlir::StandardOpsDialect,
44 mlir::vector::VectorDialect,
45 FIROpsDialect>();
46 // clang-format on
47 }
48
49 /// Register the standard passes we use. This comes from registerAllPasses(),
50 /// but is a smaller set since we aren't using many of the passes found there.
registerGeneralPasses()51 inline void registerGeneralPasses() {
52 mlir::createCanonicalizerPass();
53 mlir::createCSEPass();
54 mlir::createSuperVectorizePass({});
55 mlir::createLoopUnrollPass();
56 mlir::createLoopUnrollAndJamPass();
57 mlir::createSimplifyAffineStructuresPass();
58 mlir::createLoopFusionPass();
59 mlir::createLoopInvariantCodeMotionPass();
60 mlir::createAffineLoopInvariantCodeMotionPass();
61 mlir::createPipelineDataTransferPass();
62 mlir::createLowerAffinePass();
63 mlir::createLoopTilingPass(0);
64 mlir::createLoopCoalescingPass();
65 mlir::createAffineDataCopyGenerationPass(0, 0);
66 mlir::createMemRefDataFlowOptPass();
67 mlir::createStripDebugInfoPass();
68 mlir::createPrintOpStatsPass();
69 mlir::createInlinerPass();
70 mlir::createSymbolDCEPass();
71 mlir::createLocationSnapshotPass({});
72 }
73
registerFIRPasses()74 inline void registerFIRPasses() { registerGeneralPasses(); }
75
76 } // namespace fir
77
78 #endif // OPTIMIZER_DIALECT_FIRDIALECT_H
79