[llvm] [Support] Remove Executor abstract base class from Parallel.cpp. NFC (PR #189266)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 29 10:21:34 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Fangrui Song (MaskRay)
<details>
<summary>Changes</summary>
ThreadPoolExecutor is the only implementation. Remove the Executor
base class so that add() and getThreadCount() are direct calls
instead of virtual dispatches.
---
Full diff: https://github.com/llvm/llvm-project/pull/189266.diff
1 Files Affected:
- (modified) llvm/lib/Support/Parallel.cpp (+8-19)
``````````diff
diff --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp
index 8f1092e4630dd..d232896a27e88 100644
--- a/llvm/lib/Support/Parallel.cpp
+++ b/llvm/lib/Support/Parallel.cpp
@@ -39,19 +39,8 @@ namespace detail {
namespace {
-/// An abstract class that takes closures and runs them asynchronously.
-class Executor {
-public:
- virtual ~Executor() = default;
- virtual void add(std::function<void()> func) = 0;
- virtual size_t getThreadCount() const = 0;
-
- static Executor *getDefaultExecutor();
-};
-
-/// An implementation of an Executor that runs closures on a thread pool
-/// in filo order.
-class ThreadPoolExecutor : public Executor {
+/// Runs closures on a thread pool in filo order.
+class ThreadPoolExecutor {
public:
explicit ThreadPoolExecutor(ThreadPoolStrategy S) {
if (S.UseJobserver)
@@ -99,7 +88,7 @@ class ThreadPoolExecutor : public Executor {
T.join();
}
- ~ThreadPoolExecutor() override { stop(); }
+ ~ThreadPoolExecutor() { stop(); }
struct Creator {
static void *call() { return new ThreadPoolExecutor(strategy); }
@@ -108,7 +97,7 @@ class ThreadPoolExecutor : public Executor {
static void call(void *Ptr) { ((ThreadPoolExecutor *)Ptr)->stop(); }
};
- void add(std::function<void()> F) override {
+ void add(std::function<void()> F) {
{
std::lock_guard<std::mutex> Lock(Mutex);
WorkStack.push_back(std::move(F));
@@ -116,7 +105,7 @@ class ThreadPoolExecutor : public Executor {
Cond.notify_one();
}
- size_t getThreadCount() const override { return ThreadCount; }
+ size_t getThreadCount() const { return ThreadCount; }
private:
void work(ThreadPoolStrategy S, unsigned ThreadID) {
@@ -190,7 +179,7 @@ class ThreadPoolExecutor : public Executor {
JobserverClient *TheJobserver = nullptr;
};
-Executor *Executor::getDefaultExecutor() {
+ThreadPoolExecutor *getDefaultExecutor() {
#ifdef _WIN32
// The ManagedStatic enables the ThreadPoolExecutor to be stopped via
// llvm_shutdown() on Windows. This is important to avoid various race
@@ -214,7 +203,7 @@ Executor *Executor::getDefaultExecutor() {
} // namespace detail
size_t getThreadCount() {
- return detail::Executor::getDefaultExecutor()->getThreadCount();
+ return detail::getDefaultExecutor()->getThreadCount();
}
#endif
@@ -239,7 +228,7 @@ void TaskGroup::spawn(std::function<void()> F) {
#if LLVM_ENABLE_THREADS
if (Parallel) {
L.inc();
- detail::Executor::getDefaultExecutor()->add([&, F = std::move(F)] {
+ detail::getDefaultExecutor()->add([&, F = std::move(F)] {
F();
L.dec();
});
``````````
</details>
https://github.com/llvm/llvm-project/pull/189266
More information about the llvm-commits
mailing list