[llvm] c1d935e - [InstrProf] Fix BalancedPartitioning when threads are disabled
Ellis Hoag via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 7 12:04:41 PDT 2023
Author: Ellis Hoag
Date: 2023-06-07T12:04:35-07:00
New Revision: c1d935ece34679679bf0f5f52eb20cf3683949ae
URL: https://github.com/llvm/llvm-project/commit/c1d935ece34679679bf0f5f52eb20cf3683949ae
DIFF: https://github.com/llvm/llvm-project/commit/c1d935ece34679679bf0f5f52eb20cf3683949ae.diff
LOG: [InstrProf] Fix BalancedPartitioning when threads are disabled
In https://reviews.llvm.org/D147812 we introduced the class
`BalancedPartitioning` which includes some threading code. The tests in
that diff run forever when built with `-DLLVM_ENABLE_THREADS=OFF` so
some bots were broken.
These tests were skipped in
https://reviews.llvm.org/rGa4845eaf2e9aa18dd900d7cbeff4e5ff52e4b50e
because of this.
This diff disables the threading code if `LLVM_ENABLE_THREADS` is
disabled so we can re-enable the tests.
Reviewed By: luporl
Differential Revision: https://reviews.llvm.org/D152390
Added:
Modified:
llvm/lib/Support/BalancedPartitioning.cpp
llvm/test/tools/llvm-profdata/show-order.proftext
llvm/unittests/Support/BalancedPartitioningTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/BalancedPartitioning.cpp b/llvm/lib/Support/BalancedPartitioning.cpp
index 324feeade089f..e45852ee8db8f 100644
--- a/llvm/lib/Support/BalancedPartitioning.cpp
+++ b/llvm/lib/Support/BalancedPartitioning.cpp
@@ -27,6 +27,7 @@ void BPFunctionNode::dump(raw_ostream &OS) const {
template <typename Func>
void BalancedPartitioning::BPThreadPool::async(Func &&F) {
+#if LLVM_ENABLE_THREADS
// This new thread could spawn more threads, so mark it as active
++NumActiveThreads;
TheThreadPool.async([=]() {
@@ -44,9 +45,13 @@ void BalancedPartitioning::BPThreadPool::async(Func &&F) {
cv.notify_one();
}
});
+#else
+ llvm_unreachable("threads are disabled");
+#endif
}
void BalancedPartitioning::BPThreadPool::wait() {
+#if LLVM_ENABLE_THREADS
// TODO: We could remove the mutex and condition variable and use
// std::atomic::wait() instead, but that isn't available until C++20
{
@@ -56,6 +61,9 @@ void BalancedPartitioning::BPThreadPool::wait() {
}
// Now we can call ThreadPool::wait() since all tasks have been submitted
TheThreadPool.wait();
+#else
+ llvm_unreachable("threads are disabled");
+#endif
}
BalancedPartitioning::BalancedPartitioning(
@@ -73,8 +81,10 @@ void BalancedPartitioning::run(std::vector<BPFunctionNode> &Nodes) const {
"Partitioning %d nodes using depth %d and %d iterations per split\n",
Nodes.size(), Config.SplitDepth, Config.IterationsPerSplit));
std::optional<BPThreadPool> TP;
+#if LLVM_ENABLE_THREADS
if (Config.TaskSplitDepth > 1)
TP.emplace();
+#endif
// Record the input order
for (unsigned I = 0; I < Nodes.size(); I++)
diff --git a/llvm/test/tools/llvm-profdata/show-order.proftext b/llvm/test/tools/llvm-profdata/show-order.proftext
index 1b80677d5d063..8ef26847ad77e 100644
--- a/llvm/test/tools/llvm-profdata/show-order.proftext
+++ b/llvm/test/tools/llvm-profdata/show-order.proftext
@@ -1,6 +1,4 @@
# RUN: llvm-profdata order %s | FileCheck %s
-# PR63168: Balanced Partitioning tests currently hang on ARM.
-# UNSUPPORTED: target=arm{{.*}}
# CHECK: a
# CHECK: b
diff --git a/llvm/unittests/Support/BalancedPartitioningTest.cpp b/llvm/unittests/Support/BalancedPartitioningTest.cpp
index 05f7411b43277..ebe518a8e89ca 100644
--- a/llvm/unittests/Support/BalancedPartitioningTest.cpp
+++ b/llvm/unittests/Support/BalancedPartitioningTest.cpp
@@ -17,13 +17,6 @@ using testing::Not;
using testing::UnorderedElementsAre;
using testing::UnorderedElementsAreArray;
-// PR63168: Balanced Partitioning tests currently hang on ARM.
-#if defined(__arm__)
-#define SKIP_UNSUPPORTED_PLATFORM GTEST_SKIP()
-#else
-#define SKIP_UNSUPPORTED_PLATFORM do { } while(0)
-#endif
-
namespace llvm {
void PrintTo(const BPFunctionNode &Node, std::ostream *OS) {
@@ -47,7 +40,6 @@ class BalancedPartitioningTest : public ::testing::Test {
};
TEST_F(BalancedPartitioningTest, Basic) {
- SKIP_UNSUPPORTED_PLATFORM;
std::vector<BPFunctionNode> Nodes = {
BPFunctionNode(0, {1, 2}), BPFunctionNode(2, {3, 4}),
BPFunctionNode(1, {1, 2}), BPFunctionNode(3, {3, 4}),
@@ -67,7 +59,6 @@ TEST_F(BalancedPartitioningTest, Basic) {
}
TEST_F(BalancedPartitioningTest, Large) {
- SKIP_UNSUPPORTED_PLATFORM;
const int ProblemSize = 1000;
std::vector<BPFunctionNode::UtilityNodeT> AllUNs;
for (int i = 0; i < ProblemSize; i++)
@@ -94,7 +85,6 @@ TEST_F(BalancedPartitioningTest, Large) {
}
TEST_F(BalancedPartitioningTest, MoveGain) {
- SKIP_UNSUPPORTED_PLATFORM;
BalancedPartitioning::SignaturesT Signatures = {
{10, 10, 10.f, 0.f, true}, // 0
{10, 10, 0.f, 10.f, true}, // 1
More information about the llvm-commits
mailing list