[Mlir-commits] [mlir] 6bce7d8 - [mlir][mlir-opt] Disable multithreading when parsing the input module.

River Riddle llvmlistbot at llvm.org
Mon May 4 17:32:12 PDT 2020


Author: River Riddle
Date: 2020-05-04T17:29:56-07:00
New Revision: 6bce7d8d67c497306dc1c28ae5328e6a4c6efdab

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

LOG: [mlir][mlir-opt] Disable multithreading when parsing the input module.

This removes the unnecessary/costly context synchronization when parsing, as the context is guaranteed to not be used by any other threads.

Added: 
    

Modified: 
    mlir/include/mlir/IR/MLIRContext.h
    mlir/lib/Support/MlirOptMain.cpp
    mlir/tools/mlir-opt/mlir-opt.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/MLIRContext.h b/mlir/include/mlir/IR/MLIRContext.h
index 40b332698c44..da0b0bd826ce 100644
--- a/mlir/include/mlir/IR/MLIRContext.h
+++ b/mlir/include/mlir/IR/MLIRContext.h
@@ -60,6 +60,9 @@ class MLIRContext {
 
   /// Set the flag specifying if multi-threading is disabled by the context.
   void disableMultithreading(bool disable = true);
+  void enableMultithreading(bool enable = true) {
+    disableMultithreading(!enable);
+  }
 
   /// Return true if we should attach the operation to diagnostics emitted via
   /// Operation::emit.

diff  --git a/mlir/lib/Support/MlirOptMain.cpp b/mlir/lib/Support/MlirOptMain.cpp
index 5c21e19c4bd2..25e197083b62 100644
--- a/mlir/lib/Support/MlirOptMain.cpp
+++ b/mlir/lib/Support/MlirOptMain.cpp
@@ -40,7 +40,14 @@ static LogicalResult performActions(raw_ostream &os, bool verifyDiagnostics,
                                     bool verifyPasses, SourceMgr &sourceMgr,
                                     MLIRContext *context,
                                     const PassPipelineCLParser &passPipeline) {
+  // Disable multi-threading when parsing the input file. This removes the
+  // unnecessary/costly context synchronization when parsing.
+  bool wasThreadingEnabled = context->isMultithreadingEnabled();
+  context->disableMultithreading();
+
+  // Parse the input file and reset the context threading state.
   OwningModuleRef module(parseSourceFile(sourceMgr, context));
+  context->enableMultithreading(wasThreadingEnabled);
   if (!module)
     return failure();
 

diff  --git a/mlir/tools/mlir-opt/mlir-opt.cpp b/mlir/tools/mlir-opt/mlir-opt.cpp
index d9c822169932..c5cc533ab119 100644
--- a/mlir/tools/mlir-opt/mlir-opt.cpp
+++ b/mlir/tools/mlir-opt/mlir-opt.cpp
@@ -150,9 +150,9 @@ int main(int argc, char **argv) {
   // Parse pass names in main to ensure static initialization completed.
   cl::ParseCommandLineOptions(argc, argv, "MLIR modular optimizer driver\n");
 
-  MLIRContext context;
   if(showDialects) {
     llvm::outs() << "Registered Dialects:\n";
+    MLIRContext context;
     for(Dialect *dialect : context.getRegisteredDialects()) {
       llvm::outs() << dialect->getNamespace() << "\n";
     }


        


More information about the Mlir-commits mailing list