forked from OSchip/llvm-project
[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:
parent
58c7bf246e
commit
6bce7d8d67
|
@ -60,6 +60,9 @@ public:
|
||||||
|
|
||||||
/// Set the flag specifying if multi-threading is disabled by the context.
|
/// Set the flag specifying if multi-threading is disabled by the context.
|
||||||
void disableMultithreading(bool disable = true);
|
void disableMultithreading(bool disable = true);
|
||||||
|
void enableMultithreading(bool enable = true) {
|
||||||
|
disableMultithreading(!enable);
|
||||||
|
}
|
||||||
|
|
||||||
/// Return true if we should attach the operation to diagnostics emitted via
|
/// Return true if we should attach the operation to diagnostics emitted via
|
||||||
/// Operation::emit.
|
/// Operation::emit.
|
||||||
|
|
|
@ -40,7 +40,14 @@ static LogicalResult performActions(raw_ostream &os, bool verifyDiagnostics,
|
||||||
bool verifyPasses, SourceMgr &sourceMgr,
|
bool verifyPasses, SourceMgr &sourceMgr,
|
||||||
MLIRContext *context,
|
MLIRContext *context,
|
||||||
const PassPipelineCLParser &passPipeline) {
|
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));
|
OwningModuleRef module(parseSourceFile(sourceMgr, context));
|
||||||
|
context->enableMultithreading(wasThreadingEnabled);
|
||||||
if (!module)
|
if (!module)
|
||||||
return failure();
|
return failure();
|
||||||
|
|
||||||
|
|
|
@ -150,9 +150,9 @@ int main(int argc, char **argv) {
|
||||||
// Parse pass names in main to ensure static initialization completed.
|
// Parse pass names in main to ensure static initialization completed.
|
||||||
cl::ParseCommandLineOptions(argc, argv, "MLIR modular optimizer driver\n");
|
cl::ParseCommandLineOptions(argc, argv, "MLIR modular optimizer driver\n");
|
||||||
|
|
||||||
MLIRContext context;
|
|
||||||
if(showDialects) {
|
if(showDialects) {
|
||||||
llvm::outs() << "Registered Dialects:\n";
|
llvm::outs() << "Registered Dialects:\n";
|
||||||
|
MLIRContext context;
|
||||||
for(Dialect *dialect : context.getRegisteredDialects()) {
|
for(Dialect *dialect : context.getRegisteredDialects()) {
|
||||||
llvm::outs() << dialect->getNamespace() << "\n";
|
llvm::outs() << dialect->getNamespace() << "\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue