|
| 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 | +// The definitive list of dialects used by flang. |
| 28 | +#define FLANG_DIALECT_LIST \ |
| 29 | + mlir::AffineDialect, FIROpsDialect, mlir::LLVM::LLVMDialect, \ |
| 30 | + mlir::acc::OpenACCDialect, mlir::omp::OpenMPDialect, \ |
| 31 | + mlir::scf::SCFDialect, mlir::StandardOpsDialect, \ |
| 32 | + mlir::vector::VectorDialect |
| 33 | + |
| 34 | +/// Register all the dialects used by flang. |
| 35 | +inline void registerDialects(mlir::DialectRegistry ®istry) { |
| 36 | + registry.insert<FLANG_DIALECT_LIST>(); |
| 37 | +} |
| 38 | + |
| 39 | +/// Forced load of all the dialects used by flang. Lowering is not an MLIR |
| 40 | +/// pass, but a producer of FIR and MLIR. It is therefore a requirement that the |
| 41 | +/// dialects be preloaded to be able to build the IR. |
| 42 | +inline void loadDialects(mlir::MLIRContext &context) { |
| 43 | + context.loadDialect<FLANG_DIALECT_LIST>(); |
| 44 | +} |
| 45 | + |
| 46 | +/// Register the standard passes we use. This comes from registerAllPasses(), |
| 47 | +/// but is a smaller set since we aren't using many of the passes found there. |
| 48 | +inline void registerFIRPasses() { |
| 49 | + mlir::registerCanonicalizerPass(); |
| 50 | + mlir::registerCSEPass(); |
| 51 | + mlir::registerAffineLoopFusionPass(); |
| 52 | + mlir::registerLoopInvariantCodeMotionPass(); |
| 53 | + mlir::registerLoopCoalescingPass(); |
| 54 | + mlir::registerStripDebugInfoPass(); |
| 55 | + mlir::registerPrintOpStatsPass(); |
| 56 | + mlir::registerInlinerPass(); |
| 57 | + mlir::registerSCCPPass(); |
| 58 | + mlir::registerMemRefDataFlowOptPass(); |
| 59 | + mlir::registerSymbolDCEPass(); |
| 60 | + mlir::registerLocationSnapshotPass(); |
| 61 | + mlir::registerAffinePipelineDataTransferPass(); |
| 62 | + |
| 63 | + mlir::registerAffineVectorizePass(); |
| 64 | + mlir::registerAffineLoopUnrollPass(); |
| 65 | + mlir::registerAffineLoopUnrollAndJamPass(); |
| 66 | + mlir::registerSimplifyAffineStructuresPass(); |
| 67 | + mlir::registerAffineLoopInvariantCodeMotionPass(); |
| 68 | + mlir::registerAffineLoopTilingPass(); |
| 69 | + mlir::registerAffineDataCopyGenerationPass(); |
| 70 | + |
| 71 | + mlir::registerConvertAffineToStandardPass(); |
| 72 | +} |
| 73 | + |
| 74 | +} // namespace fir::support |
| 75 | + |
| 76 | +#endif // FORTRAN_OPTIMIZER_SUPPORT_INITFIR_H |
0 commit comments