Skip to content

Commit f800a9b

Browse files
committed
[flang][fir][NFC] Move code from FIRDialect.h into a new header.
Differential Revision: https://reviews.llvm.org/D96630
1 parent 61b4702 commit f800a9b

File tree

3 files changed

+82
-49
lines changed

3 files changed

+82
-49
lines changed

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

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef OPTIMIZER_DIALECT_FIRDIALECT_H
14-
#define OPTIMIZER_DIALECT_FIRDIALECT_H
13+
#ifndef FORTRAN_OPTIMIZER_DIALECT_FIRDIALECT_H
14+
#define FORTRAN_OPTIMIZER_DIALECT_FIRDIALECT_H
1515

1616
#include "mlir/IR/Dialect.h"
17-
#include "mlir/InitAllDialects.h"
18-
#include "mlir/InitAllPasses.h"
1917

2018
namespace fir {
2119

@@ -36,47 +34,6 @@ class FIROpsDialect final : public mlir::Dialect {
3634
mlir::DialectAsmPrinter &p) const override;
3735
};
3836

39-
/// Register the dialect with the provided registry.
40-
inline void registerFIRDialects(mlir::DialectRegistry &registry) {
41-
// clang-format off
42-
registry.insert<mlir::AffineDialect,
43-
mlir::LLVM::LLVMDialect,
44-
mlir::acc::OpenACCDialect,
45-
mlir::omp::OpenMPDialect,
46-
mlir::scf::SCFDialect,
47-
mlir::StandardOpsDialect,
48-
mlir::vector::VectorDialect,
49-
FIROpsDialect>();
50-
// clang-format on
51-
}
52-
53-
/// Register the standard passes we use. This comes from registerAllPasses(),
54-
/// but is a smaller set since we aren't using many of the passes found there.
55-
inline void registerGeneralPasses() {
56-
mlir::createCanonicalizerPass();
57-
mlir::createCSEPass();
58-
mlir::createSuperVectorizePass({});
59-
mlir::createLoopUnrollPass();
60-
mlir::createLoopUnrollAndJamPass();
61-
mlir::createSimplifyAffineStructuresPass();
62-
mlir::createLoopFusionPass();
63-
mlir::createLoopInvariantCodeMotionPass();
64-
mlir::createAffineLoopInvariantCodeMotionPass();
65-
mlir::createPipelineDataTransferPass();
66-
mlir::createLowerAffinePass();
67-
mlir::createLoopTilingPass(0);
68-
mlir::createLoopCoalescingPass();
69-
mlir::createAffineDataCopyGenerationPass(0, 0);
70-
mlir::createMemRefDataFlowOptPass();
71-
mlir::createStripDebugInfoPass();
72-
mlir::createPrintOpStatsPass();
73-
mlir::createInlinerPass();
74-
mlir::createSymbolDCEPass();
75-
mlir::createLocationSnapshotPass({});
76-
}
77-
78-
inline void registerFIRPasses() { registerGeneralPasses(); }
79-
8037
} // namespace fir
8138

82-
#endif // OPTIMIZER_DIALECT_FIRDIALECT_H
39+
#endif // FORTRAN_OPTIMIZER_DIALECT_FIRDIALECT_H
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 &registry) {
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

flang/tools/tco/tco.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "flang/Optimizer/Dialect/FIRDialect.h"
14+
#include "flang/Optimizer/Support/InitFIR.h"
1515
#include "flang/Optimizer/Support/KindMapping.h"
1616
#include "mlir/IR/BuiltinOps.h"
1717
#include "mlir/IR/MLIRContext.h"
@@ -62,7 +62,7 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
6262
SourceMgr sourceMgr;
6363
sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc());
6464
mlir::DialectRegistry registry;
65-
fir::registerFIRDialects(registry);
65+
fir::support::registerDialects(registry);
6666
mlir::MLIRContext context(registry);
6767
auto owningRef = mlir::parseSourceFile(sourceMgr, &context);
6868

@@ -106,7 +106,7 @@ compileFIR(const mlir::PassPipelineCLParser &passPipeline) {
106106
}
107107

108108
int main(int argc, char **argv) {
109-
fir::registerFIRPasses();
109+
fir::support::registerFIRPasses();
110110
[[maybe_unused]] InitLLVM y(argc, argv);
111111
mlir::registerPassManagerCLOptions();
112112
mlir::PassPipelineCLParser passPipe("", "Compiler passes to run");

0 commit comments

Comments
 (0)