[llvm] 4290ef5 - [Support] Reduce allocations in parallelForEach with move

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Fri May 27 02:31:06 PDT 2022


Author: Andrew Ng
Date: 2022-05-27T10:19:55+01:00
New Revision: 4290ef54e18a61103f21f59c1db66fb67999c375

URL: https://github.com/llvm/llvm-project/commit/4290ef54e18a61103f21f59c1db66fb67999c375
DIFF: https://github.com/llvm/llvm-project/commit/4290ef54e18a61103f21f59c1db66fb67999c375.diff

LOG: [Support] Reduce allocations in parallelForEach with move

Differential Revision: https://reviews.llvm.org/D126458

Added: 
    

Modified: 
    llvm/lib/Support/Parallel.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Parallel.cpp b/llvm/lib/Support/Parallel.cpp
index 4977c188f934f..85426847c28c9 100644
--- a/llvm/lib/Support/Parallel.cpp
+++ b/llvm/lib/Support/Parallel.cpp
@@ -89,7 +89,7 @@ class ThreadPoolExecutor : public Executor {
   void add(std::function<void()> F) override {
     {
       std::lock_guard<std::mutex> Lock(Mutex);
-      WorkStack.push(F);
+      WorkStack.push(std::move(F));
     }
     Cond.notify_one();
   }
@@ -102,7 +102,7 @@ class ThreadPoolExecutor : public Executor {
       Cond.wait(Lock, [&] { return Stop || !WorkStack.empty(); });
       if (Stop)
         break;
-      auto Task = WorkStack.top();
+      auto Task = std::move(WorkStack.top());
       WorkStack.pop();
       Lock.unlock();
       Task();
@@ -161,7 +161,7 @@ TaskGroup::~TaskGroup() {
 void TaskGroup::spawn(std::function<void()> F) {
   if (Parallel) {
     L.inc();
-    Executor::getDefaultExecutor()->add([&, F] {
+    Executor::getDefaultExecutor()->add([&, F = std::move(F)] {
       F();
       L.dec();
     });


        


More information about the llvm-commits mailing list