Skip to content

Commit 53a7db4

Browse files
kamleshbhaluiKamlesh Kumar
authored andcommitted
[llvm] Refactor BalancedPartitioning for fixing build failure with MSVC
Fix build failure on windows system with msvc toolchain Reviewed By: ellis Differential Revision: https://reviews.llvm.org/D153318
1 parent 5c4071d commit 53a7db4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

llvm/include/llvm/Support/BalancedPartitioning.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@
4040
#define LLVM_SUPPORT_BALANCED_PARTITIONING_H
4141

4242
#include "raw_ostream.h"
43-
#include "llvm/Support/ThreadPool.h"
43+
#include "llvm/ADT/ArrayRef.h"
4444

45+
#include <atomic>
46+
#include <condition_variable>
47+
#include <mutex>
4548
#include <random>
4649
#include <vector>
4750

4851
namespace llvm {
4952

53+
class ThreadPool;
5054
/// A function with a set of utility nodes where it is beneficial to order two
5155
/// functions close together if they have similar utility nodes
5256
class BPFunctionNode {
@@ -111,7 +115,7 @@ class BalancedPartitioning {
111115
/// threads, so we need to track how many active threads that could spawn more
112116
/// threads.
113117
struct BPThreadPool {
114-
ThreadPool TheThreadPool;
118+
ThreadPool &TheThreadPool;
115119
std::mutex mtx;
116120
std::condition_variable cv;
117121
/// The number of threads that could spawn more threads
@@ -124,6 +128,7 @@ class BalancedPartitioning {
124128
/// acceptable for other threads to add more tasks while blocking on this
125129
/// call.
126130
void wait();
131+
BPThreadPool(ThreadPool &TheThreadPool) : TheThreadPool(TheThreadPool) {}
127132
};
128133

129134
/// Run a recursive bisection of a given list of FunctionNodes

llvm/lib/Support/BalancedPartitioning.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "llvm/Support/Debug.h"
1717
#include "llvm/Support/Format.h"
1818
#include "llvm/Support/FormatVariadic.h"
19+
#include "llvm/Support/ThreadPool.h"
1920

2021
using namespace llvm;
2122
#define DEBUG_TYPE "balanced-partitioning"
@@ -82,8 +83,9 @@ void BalancedPartitioning::run(std::vector<BPFunctionNode> &Nodes) const {
8283
Nodes.size(), Config.SplitDepth, Config.IterationsPerSplit));
8384
std::optional<BPThreadPool> TP;
8485
#if LLVM_ENABLE_THREADS
86+
ThreadPool TheThreadPool;
8587
if (Config.TaskSplitDepth > 1)
86-
TP.emplace();
88+
TP.emplace(TheThreadPool);
8789
#endif
8890

8991
// Record the input order

0 commit comments

Comments
 (0)