[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.
This commit is contained in:
River Riddle 2020-05-04 11:21:49 -07:00
parent 58c7bf246e
commit 6bce7d8d67
3 changed files with 11 additions and 1 deletions

View File

@ -60,6 +60,9 @@ public:
/// 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.

View File

@ -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();

View File

@ -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";
}