[llvm] [Support] Remove Executor abstract base class from Parallel.cpp. NFC (PR #189266)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 29 10:21:00 PDT 2026


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/189266

ThreadPoolExecutor is the only implementation. Remove the Executor
base class so that add() and getThreadCount() are direct calls
instead of virtual dispatches.


>From 4852be0b03086da698c43502c190aac2ee1b0781 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sun, 29 Mar 2026 10:18:37 -0700
Subject: [PATCH] [Support] Remove Executor abstract base class from
 Parallel.cpp. NFC

ThreadPoolExecutor is the only implementation. Remove the Executor
base class so that add() and getThreadCount() are direct calls
instead of virtual dispatches.
---
 llvm/lib/Support/Parallel.cpp | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

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();
     });



More information about the llvm-commits mailing list