[flang-commits] [flang] f6615b2 - Update FIR registration to not rely on the global MLIR dialect registry (NFC)

Mehdi Amini via flang-commits flang-commits at lists.llvm.org
Sun Aug 23 14:25:19 PDT 2020


Author: Mehdi Amini
Date: 2020-08-23T21:24:54Z
New Revision: f6615b2ddb3d046cc7a99ec74ee032ea21a1d27a

URL: https://github.com/llvm/llvm-project/commit/f6615b2ddb3d046cc7a99ec74ee032ea21a1d27a
DIFF: https://github.com/llvm/llvm-project/commit/f6615b2ddb3d046cc7a99ec74ee032ea21a1d27a.diff

LOG: 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.

Added: 
    

Modified: 
    flang/include/flang/Optimizer/Dialect/FIRDialect.h
    flang/tools/tco/tco.cpp

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Optimizer/Dialect/FIRDialect.h b/flang/include/flang/Optimizer/Dialect/FIRDialect.h
index 1c06fe5ab060..9702c54367b8 100644
--- a/flang/include/flang/Optimizer/Dialect/FIRDialect.h
+++ b/flang/include/flang/Optimizer/Dialect/FIRDialect.h
@@ -32,19 +32,17 @@ class FIROpsDialect final : public mlir::Dialect {
                       mlir::DialectAsmPrinter &p) const override;
 };
 
-/// Register the dialect with MLIR
-inline void registerFIR() {
-  // we want to register exactly once
-  [[maybe_unused]] static bool init_once = [] {
-    mlir::registerDialect<mlir::AffineDialect>();
-    mlir::registerDialect<mlir::LLVM::LLVMDialect>();
-    mlir::registerDialect<mlir::omp::OpenMPDialect>();
-    mlir::registerDialect<mlir::scf::SCFDialect>();
-    mlir::registerDialect<mlir::StandardOpsDialect>();
-    mlir::registerDialect<mlir::vector::VectorDialect>();
-    mlir::registerDialect<FIROpsDialect>();
-    return true;
-  }();
+/// Register the dialect with the provided registry.
+inline void registerFIRDialects(mlir::DialectRegistry &registry) {
+  // clang-format off
+  registry.insert<mlir::AffineDialect,
+                  mlir::LLVM::LLVMDialect,
+                  mlir::omp::OpenMPDialect,
+                  mlir::scf::SCFDialect,
+                  mlir::StandardOpsDialect,
+                  mlir::vector::VectorDialect,
+                  FIROpsDialect>();
+  // clang-format on
 }
 
 /// Register the standard passes we use. This comes from registerAllPasses(),

diff  --git a/flang/tools/tco/tco.cpp b/flang/tools/tco/tco.cpp
index 0e085fa5633f..63a6122b6324 100644
--- a/flang/tools/tco/tco.cpp
+++ b/flang/tools/tco/tco.cpp
@@ -60,8 +60,9 @@ static int compileFIR() {
   // load the file into a module
   SourceMgr sourceMgr;
   sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), SMLoc());
-  auto context = std::make_unique<mlir::MLIRContext>();
-  auto owningRef = mlir::parseSourceFile(sourceMgr, context.get());
+  mlir::MLIRContext context;
+  fir::registerFIRDialects(context.getDialectRegistry());
+  auto owningRef = mlir::parseSourceFile(sourceMgr, &context);
 
   if (!owningRef) {
     errs() << "Error can't load file " << inputFilename << '\n';
@@ -76,7 +77,7 @@ static int compileFIR() {
   ToolOutputFile out(outputFilename, ec, sys::fs::OF_None);
 
   // run passes
-  mlir::PassManager pm{context.get()};
+  mlir::PassManager pm{&context};
   mlir::applyPassManagerCLOptions(pm);
   if (emitFir) {
     // parse the input and pretty-print it back out
@@ -103,7 +104,6 @@ static int compileFIR() {
 }
 
 int main(int argc, char **argv) {
-  fir::registerFIR();
   fir::registerFIRPasses();
   [[maybe_unused]] InitLLVM y(argc, argv);
   mlir::registerPassManagerCLOptions();


        


More information about the flang-commits mailing list