Skip to content

Commit 744616b

Browse files
authored
Rename ThreadPool::getThreadCount() to getMaxConcurrency() (NFC) (llvm#82296)
This is addressing a long-time TODO to rename this misleading API. The old one is preserved for now but marked deprecated.
1 parent 71e0623 commit 744616b

File tree

9 files changed

+15
-11
lines changed

9 files changed

+15
-11
lines changed

bolt/tools/merge-fdata/merge-fdata.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ void mergeLegacyProfiles(const SmallVectorImpl<std::string> &Filenames) {
317317
ThreadPoolStrategy S = optimal_concurrency(
318318
std::max(Filenames.size() / 4, static_cast<size_t>(1)));
319319
ThreadPool Pool(S);
320-
DenseMap<llvm::thread::id, ProfileTy> ParsedProfiles(Pool.getThreadCount());
320+
DenseMap<llvm::thread::id, ProfileTy> ParsedProfiles(
321+
Pool.getMaxConcurrency());
321322
for (const auto &Filename : Filenames)
322323
Pool.async(ParseProfile, std::cref(Filename), std::ref(ParsedProfiles));
323324
Pool.wait();

clang/tools/clang-scan-deps/ClangScanDeps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
870870
EagerLoadModules);
871871
llvm::ThreadPool Pool(llvm::hardware_concurrency(NumThreads));
872872
std::vector<std::unique_ptr<DependencyScanningTool>> WorkerTools;
873-
for (unsigned I = 0; I < Pool.getThreadCount(); ++I)
873+
for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I)
874874
WorkerTools.push_back(std::make_unique<DependencyScanningTool>(Service));
875875

876876
std::vector<tooling::CompileCommand> Inputs =
@@ -894,13 +894,13 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
894894

895895
if (Verbose) {
896896
llvm::outs() << "Running clang-scan-deps on " << Inputs.size()
897-
<< " files using " << Pool.getThreadCount() << " workers\n";
897+
<< " files using " << Pool.getMaxConcurrency() << " workers\n";
898898
}
899899

900900
llvm::Timer T;
901901
T.startTimer();
902902

903-
for (unsigned I = 0; I < Pool.getThreadCount(); ++I) {
903+
for (unsigned I = 0; I < Pool.getMaxConcurrency(); ++I) {
904904
Pool.async([&, I]() {
905905
llvm::DenseSet<ModuleID> AlreadySeenModules;
906906
while (auto MaybeInputIndex = GetNextInputIndex()) {

llvm/include/llvm/Support/ThreadPool.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,12 @@ class ThreadPool {
104104
/// not to waste the thread.
105105
void wait(ThreadPoolTaskGroup &Group);
106106

107-
// TODO: misleading legacy name warning!
108107
// Returns the maximum number of worker threads in the pool, not the current
109108
// number of threads!
109+
unsigned getMaxConcurrency() const { return MaxThreadCount; }
110+
111+
// TODO: misleading legacy name warning!
112+
LLVM_DEPRECATED("Use getMaxConcurrency instead", "getMaxConcurrency")
110113
unsigned getThreadCount() const { return MaxThreadCount; }
111114

112115
/// Returns true if the current thread is a worker thread of this thread pool.

llvm/lib/Debuginfod/Debuginfod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ Error DebuginfodCollection::findBinaries(StringRef Path) {
414414
sys::fs::recursive_directory_iterator I(Twine(Path), EC), E;
415415
std::mutex IteratorMutex;
416416
ThreadPoolTaskGroup IteratorGroup(Pool);
417-
for (unsigned WorkerIndex = 0; WorkerIndex < Pool.getThreadCount();
417+
for (unsigned WorkerIndex = 0; WorkerIndex < Pool.getMaxConcurrency();
418418
WorkerIndex++) {
419419
IteratorGroup.async([&, this]() -> void {
420420
std::string FilePath;

llvm/lib/LTO/LTO.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ class InProcessThinBackend : public ThinBackendProc {
15371537
}
15381538

15391539
unsigned getThreadCount() override {
1540-
return BackendThreadPool.getThreadCount();
1540+
return BackendThreadPool.getMaxConcurrency();
15411541
}
15421542
};
15431543
} // end anonymous namespace

mlir/include/mlir/IR/Threading.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ LogicalResult failableParallelForEach(MLIRContext *context, IteratorT begin,
6868
// Otherwise, process the elements in parallel.
6969
llvm::ThreadPool &threadPool = context->getThreadPool();
7070
llvm::ThreadPoolTaskGroup tasksGroup(threadPool);
71-
size_t numActions = std::min(numElements, threadPool.getThreadCount());
71+
size_t numActions = std::min(numElements, threadPool.getMaxConcurrency());
7272
for (unsigned i = 0; i < numActions; ++i)
7373
tasksGroup.async(processFn);
7474
// If the current thread is a worker thread from the pool, then waiting for

mlir/lib/ExecutionEngine/AsyncRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ extern "C" void mlirAsyncRuntimeAwaitAllInGroupAndExecute(AsyncGroup *group,
437437
}
438438

439439
extern "C" int64_t mlirAsyncRuntimGetNumWorkerThreads() {
440-
return getDefaultAsyncRuntime()->getThreadPool().getThreadCount();
440+
return getDefaultAsyncRuntime()->getThreadPool().getMaxConcurrency();
441441
}
442442

443443
//===----------------------------------------------------------------------===//

mlir/lib/IR/MLIRContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ unsigned MLIRContext::getNumThreads() {
638638
if (isMultithreadingEnabled()) {
639639
assert(impl->threadPool &&
640640
"multi-threading is enabled but threadpool not set");
641-
return impl->threadPool->getThreadCount();
641+
return impl->threadPool->getMaxConcurrency();
642642
}
643643
// No multithreading or active thread pool. Return 1 thread.
644644
return 1;

mlir/lib/Pass/Pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ void OpToOpPassAdaptor::runOnOperationAsyncImpl(bool verifyPasses) {
748748
// Create the async executors if they haven't been created, or if the main
749749
// pipeline has changed.
750750
if (asyncExecutors.empty() || hasSizeMismatch(asyncExecutors.front(), mgrs))
751-
asyncExecutors.assign(context->getThreadPool().getThreadCount(), mgrs);
751+
asyncExecutors.assign(context->getThreadPool().getMaxConcurrency(), mgrs);
752752

753753
// This struct represents the information for a single operation to be
754754
// scheduled on a pass manager.

0 commit comments

Comments
 (0)