Skip to content

Commit f6615b2

Browse files
committed
Update FIR registration to not rely on the global MLIR dialect registry (NFC)
MLIR is removing "soon" the global dialect registry, this patch is transitionning FIR to not rely on it anymore.
1 parent f6decfa commit f6615b2

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@ class FIROpsDialect final : public mlir::Dialect {
3232
mlir::DialectAsmPrinter &p) const override;
3333
};
3434

35-
/// Register the dialect with MLIR
36-
inline void registerFIR() {
37-
// we want to register exactly once
38-
[[maybe_unused]] static bool init_once = [] {
39-
mlir::registerDialect<mlir::AffineDialect>();
40-
mlir::registerDialect<mlir::LLVM::LLVMDialect>();
41-
mlir::registerDialect<mlir::omp::OpenMPDialect>();
42-
mlir::registerDialect<mlir::scf::SCFDialect>();
43-
mlir::registerDialect<mlir::StandardOpsDialect>();
44-
mlir::registerDialect<mlir::vector::VectorDialect>();
45-
mlir::registerDialect<FIROpsDialect>();
46-
return true;
47-
}();
35+
/// Register the dialect with the provided registry.
36+
inline void registerFIRDialects(mlir::DialectRegistry &registry) {
37+
// clang-format off
38+
registry.insert<mlir::AffineDialect,
39+
mlir::LLVM::LLVMDialect,
40+
mlir::omp::OpenMPDialect,
41+
mlir::scf::SCFDialect,
42+
mlir::StandardOpsDialect,
43+
mlir::vector::VectorDialect,
44+
FIROpsDialect>();
45+
// clang-format on
4846
}
4947

5048
/// Register the standard passes we use. This comes from registerAllPasses(),

flang/tools/tco/tco.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ static int compileFIR() {
6060
// load the file into a module
6161
SourceMgr sourceMgr;
6262
sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc());
63-
auto context = std::make_unique<mlir::MLIRContext>();
64-
auto owningRef = mlir::parseSourceFile(sourceMgr, context.get());
63+
mlir::MLIRContext context;
64+
fir::registerFIRDialects(context.getDialectRegistry());
65+
auto owningRef = mlir::parseSourceFile(sourceMgr, &context);
6566

6667
if (!owningRef) {
6768
errs() << "Error can't load file " << inputFilename << '\n';
@@ -76,7 +77,7 @@ static int compileFIR() {
7677
ToolOutputFile out(outputFilename, ec, sys::fs::OF_None);
7778

7879
// run passes
79-
mlir::PassManager pm{context.get()};
80+
mlir::PassManager pm{&context};
8081
mlir::applyPassManagerCLOptions(pm);
8182
if (emitFir) {
8283
// parse the input and pretty-print it back out
@@ -103,7 +104,6 @@ static int compileFIR() {
103104
}
104105

105106
int main(int argc, char **argv) {
106-
fir::registerFIR();
107107
fir::registerFIRPasses();
108108
[[maybe_unused]] InitLLVM y(argc, argv);
109109
mlir::registerPassManagerCLOptions();

0 commit comments

Comments
 (0)