1 //===-- Optimizer/Support/InitFIR.h -----------------------------*- 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 // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef FORTRAN_OPTIMIZER_SUPPORT_INITFIR_H
14 #define FORTRAN_OPTIMIZER_SUPPORT_INITFIR_H
15
16 #include "flang/Optimizer/Dialect/FIRDialect.h"
17 #include "mlir/Conversion/Passes.h"
18 #include "mlir/Dialect/Affine/Passes.h"
19 #include "mlir/InitAllDialects.h"
20 #include "mlir/Pass/Pass.h"
21 #include "mlir/Pass/PassRegistry.h"
22 #include "mlir/Transforms/LocationSnapshot.h"
23 #include "mlir/Transforms/Passes.h"
24
25 namespace fir::support {
26
27 #define FLANG_NONCODEGEN_DIALECT_LIST \
28 mlir::AffineDialect, FIROpsDialect, mlir::acc::OpenACCDialect, \
29 mlir::omp::OpenMPDialect, mlir::scf::SCFDialect, \
30 mlir::arith::ArithmeticDialect, mlir::cf::ControlFlowDialect, \
31 mlir::func::FuncDialect, mlir::vector::VectorDialect, \
32 mlir::math::MathDialect
33
34 // The definitive list of dialects used by flang.
35 #define FLANG_DIALECT_LIST \
36 FLANG_NONCODEGEN_DIALECT_LIST, FIRCodeGenDialect, mlir::LLVM::LLVMDialect
37
registerNonCodegenDialects(mlir::DialectRegistry & registry)38 inline void registerNonCodegenDialects(mlir::DialectRegistry ®istry) {
39 registry.insert<FLANG_NONCODEGEN_DIALECT_LIST>();
40 }
41
42 /// Register all the dialects used by flang.
registerDialects(mlir::DialectRegistry & registry)43 inline void registerDialects(mlir::DialectRegistry ®istry) {
44 registry.insert<FLANG_DIALECT_LIST>();
45 }
46
loadNonCodegenDialects(mlir::MLIRContext & context)47 inline void loadNonCodegenDialects(mlir::MLIRContext &context) {
48 context.loadDialect<FLANG_NONCODEGEN_DIALECT_LIST>();
49 }
50
51 /// Forced load of all the dialects used by flang. Lowering is not an MLIR
52 /// pass, but a producer of FIR and MLIR. It is therefore a requirement that the
53 /// dialects be preloaded to be able to build the IR.
loadDialects(mlir::MLIRContext & context)54 inline void loadDialects(mlir::MLIRContext &context) {
55 context.loadDialect<FLANG_DIALECT_LIST>();
56 }
57
58 /// Register the standard passes we use. This comes from registerAllPasses(),
59 /// but is a smaller set since we aren't using many of the passes found there.
registerMLIRPassesForFortranTools()60 inline void registerMLIRPassesForFortranTools() {
61 mlir::registerCanonicalizerPass();
62 mlir::registerCSEPass();
63 mlir::registerAffineLoopFusionPass();
64 mlir::registerLoopInvariantCodeMotionPass();
65 mlir::registerLoopCoalescingPass();
66 mlir::registerStripDebugInfoPass();
67 mlir::registerPrintOpStatsPass();
68 mlir::registerInlinerPass();
69 mlir::registerSCCPPass();
70 mlir::registerAffineScalarReplacementPass();
71 mlir::registerSymbolDCEPass();
72 mlir::registerLocationSnapshotPass();
73 mlir::registerAffinePipelineDataTransferPass();
74
75 mlir::registerAffineVectorizePass();
76 mlir::registerAffineLoopUnrollPass();
77 mlir::registerAffineLoopUnrollAndJamPass();
78 mlir::registerSimplifyAffineStructuresPass();
79 mlir::registerAffineLoopInvariantCodeMotionPass();
80 mlir::registerAffineLoopTilingPass();
81 mlir::registerAffineDataCopyGenerationPass();
82
83 mlir::registerConvertAffineToStandardPass();
84 }
85
86 /// Register the interfaces needed to lower to LLVM IR.
87 void registerLLVMTranslation(mlir::MLIRContext &context);
88
89 } // namespace fir::support
90
91 #endif // FORTRAN_OPTIMIZER_SUPPORT_INITFIR_H
92