[mlir] Add a ThreadPool to MLIRContext and refactor MLIR threading usage
authorRiver Riddle <riddleriver@gmail.com>
Wed, 23 Jun 2021 01:16:55 +0000 (01:16 +0000)
committerRiver Riddle <riddleriver@gmail.com>
Wed, 23 Jun 2021 01:29:24 +0000 (01:29 +0000)
commit6569cf2a44bf95106e7168bdb79c4674742708fa
treec2b6c9ff67b6ca127622ee3197065d83e64be163
parent18465bcf4dbad4a4035f1f306b1a787e0bf92828
[mlir] Add a ThreadPool to MLIRContext and refactor MLIR threading usage

This revision refactors the usage of multithreaded utilities in MLIR to use a common
thread pool within the MLIR context, in addition to a new utility that makes writing
multi-threaded code in MLIR less error prone. Using a unified thread pool brings about
several advantages:

* Better thread usage and more control
We currently use the static llvm threading utilities, which do not allow multiple
levels of asynchronous scheduling (even if there are open threads). This is due to
how the current TaskGroup structure works, which only allows one truly multithreaded
instance at a time. By having our own ThreadPool we gain more control and flexibility
over our job/thread scheduling, and in a followup can enable threading more parts of
the compiler.

* The static nature of TaskGroup causes issues in certain configurations
Due to the static nature of TaskGroup, there have been quite a few problems related to
destruction that have caused several downstream projects to disable threading. See
D104207 for discussion on some related fallout. By having a ThreadPool scoped to
the context, we don't have to worry about destruction and can ensure that any
additional MLIR thread usage ends when the context is destroyed.

Differential Revision: https://reviews.llvm.org/D104516
13 files changed:
llvm/include/llvm/Support/ThreadPool.h
llvm/lib/Support/ThreadPool.cpp
mlir/include/mlir/IR/MLIRContext.h
mlir/include/mlir/IR/Threading.h [new file with mode: 0644]
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/Verifier.cpp
mlir/lib/Pass/Pass.cpp
mlir/lib/Transforms/Inliner.cpp
mlir/test/Dialect/Affine/SuperVectorize/compose_maps.mlir
mlir/test/Dialect/Affine/slicing-utils.mlir
mlir/test/IR/diagnostic-handler-filter.mlir
mlir/test/Pass/pass-timing.mlir
mlir/test/Pass/pipeline-parsing.mlir