summaryrefslogtreecommitdiff
path: root/mlir/lib/Support
diff options
context:
space:
mode:
authorMehdi Amini <joker.eph@gmail.com>2021-09-15 01:38:38 +0000
committerMehdi Amini <joker.eph@gmail.com>2021-09-15 03:20:48 +0000
commita32300a68f6c94b7b275e3560ed31e9174cec5ad (patch)
treed5d39a278c35679c79a3c55b66ed38072a5ee106 /mlir/lib/Support
parent500d4c45ba7f31907a64dead8ddb292649e6ce75 (diff)
downloadllvm-a32300a68f6c94b7b275e3560ed31e9174cec5ad.tar.gz
Make the --mlir-disable-threading command line option overrides the C++ API usage
This seems in-line with the intent and how we build tools around it. Update the description for the flag accordingly. Also use an injected thread pool in MLIROptMain, now we will create threads up-front and reuse them across split buffers. Differential Revision: https://reviews.llvm.org/D109802
Diffstat (limited to 'mlir/lib/Support')
-rw-r--r--mlir/lib/Support/MlirOptMain.cpp30
1 files changed, 19 insertions, 11 deletions
diff --git a/mlir/lib/Support/MlirOptMain.cpp b/mlir/lib/Support/MlirOptMain.cpp
index 7f4b6e1e99cb..6da9f993eeaf 100644
--- a/mlir/lib/Support/MlirOptMain.cpp
+++ b/mlir/lib/Support/MlirOptMain.cpp
@@ -32,6 +32,7 @@
#include "llvm/Support/Regex.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/StringSaver.h"
+#include "llvm/Support/ThreadPool.h"
#include "llvm/Support/ToolOutputFile.h"
using namespace mlir;
@@ -93,19 +94,22 @@ static LogicalResult performActions(raw_ostream &os, bool verifyDiagnostics,
/// Parses the memory buffer. If successfully, run a series of passes against
/// it and print the result.
-static LogicalResult processBuffer(raw_ostream &os,
- std::unique_ptr<MemoryBuffer> ownedBuffer,
- bool verifyDiagnostics, bool verifyPasses,
- bool allowUnregisteredDialects,
- bool preloadDialectsInContext,
- const PassPipelineCLParser &passPipeline,
- DialectRegistry &registry) {
+static LogicalResult
+processBuffer(raw_ostream &os, std::unique_ptr<MemoryBuffer> ownedBuffer,
+ bool verifyDiagnostics, bool verifyPasses,
+ bool allowUnregisteredDialects, bool preloadDialectsInContext,
+ const PassPipelineCLParser &passPipeline,
+ DialectRegistry &registry, llvm::ThreadPool &threadPool) {
// Tell sourceMgr about this buffer, which is what the parser will pick up.
SourceMgr sourceMgr;
sourceMgr.AddNewSourceBuffer(std::move(ownedBuffer), SMLoc());
+ // Create a context just for the current buffer. Disable threading on creation
+ // since we'll inject the thread-pool separately.
+ MLIRContext context(registry, MLIRContext::Threading::DISABLED);
+ context.setThreadPool(threadPool);
+
// Parse the input file.
- MLIRContext context(registry);
if (preloadDialectsInContext)
context.loadAllAvailableDialects();
context.allowUnregisteredDialects(allowUnregisteredDialects);
@@ -143,20 +147,24 @@ LogicalResult mlir::MlirOptMain(raw_ostream &outputStream,
bool preloadDialectsInContext) {
// The split-input-file mode is a very specific mode that slices the file
// up into small pieces and checks each independently.
+ // We use an explicit threadpool to avoid creating and joining/destroying
+ // threads for each of the split.
+ llvm::ThreadPool threadPool;
if (splitInputFile)
return splitAndProcessBuffer(
std::move(buffer),
[&](std::unique_ptr<MemoryBuffer> chunkBuffer, raw_ostream &os) {
return processBuffer(os, std::move(chunkBuffer), verifyDiagnostics,
verifyPasses, allowUnregisteredDialects,
- preloadDialectsInContext, passPipeline,
- registry);
+ preloadDialectsInContext, passPipeline, registry,
+ threadPool);
},
outputStream);
return processBuffer(outputStream, std::move(buffer), verifyDiagnostics,
verifyPasses, allowUnregisteredDialects,
- preloadDialectsInContext, passPipeline, registry);
+ preloadDialectsInContext, passPipeline, registry,
+ threadPool);
}
LogicalResult mlir::MlirOptMain(int argc, char **argv, llvm::StringRef toolName,