Update FIR registration to not rely on the global MLIR dialect registry (NFC)
authorMehdi Amini <joker.eph@gmail.com>
Sun, 23 Aug 2020 21:20:49 +0000 (21:20 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Sun, 23 Aug 2020 21:24:54 +0000 (21:24 +0000)
MLIR is removing "soon" the global dialect registry, this patch is
transitionning FIR to not rely on it anymore.

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

index 1c06fe5..9702c54 100644 (file)
@@ -32,19 +32,17 @@ public:
                       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(),
index 0e085fa..63a6122 100644 (file)
@@ -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();