Skip to content

Commit 0c68155

Browse files
committed
[llvm-jitlink] Fix llvm-jitlink for LLVM_ENABLE_THREADS=Off.
Commit edca1d9 enabled threaded linking by default in llvm-jitlink, but we need to handle the case where LLVM is built with -DLLVM_ENABLE_THREADS=Off. This patch updates the llvm-jitlink tool to switch back to materialization on the main thread (equivalent to llvm-jitlink -num-threads=0 ...) when LLVM is built without thread support.
1 parent bc87a53 commit 0c68155

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

llvm/tools/llvm-jitlink/llvm-jitlink.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -996,9 +996,14 @@ Expected<std::unique_ptr<Session>> Session::Create(Triple TT,
996996
std::unique_ptr<TaskDispatcher> Dispatcher;
997997
if (MaterializationThreads == 0)
998998
Dispatcher = std::make_unique<InPlaceTaskDispatcher>();
999-
else
999+
else {
1000+
#if LLVM_ENABLE_THREADS
10001001
Dispatcher = std::make_unique<DynamicThreadPoolTaskDispatcher>(
10011002
MaterializationThreads);
1003+
#else
1004+
llvm_unreachable("MaterializationThreads should be 0");
1005+
#endif
1006+
}
10021007

10031008
EPC = std::make_unique<SelfExecutorProcessControl>(
10041009
std::make_shared<SymbolStringPool>(), std::move(Dispatcher),
@@ -1628,15 +1633,24 @@ static Error sanitizeArguments(const Triple &TT, const char *ArgV0) {
16281633
}
16291634
}
16301635

1636+
#if LLVM_ENABLE_THREADS
16311637
if (MaterializationThreads == std::numeric_limits<size_t>::max()) {
16321638
if (auto HC = std::thread::hardware_concurrency())
16331639
MaterializationThreads = HC;
16341640
else {
16351641
errs() << "Warning: std::thread::hardware_concurrency() returned 0, "
1636-
"defaulting to -threads=1.\n";
1642+
"defaulting to -num-threads=1.\n";
16371643
MaterializationThreads = 1;
16381644
}
16391645
}
1646+
#else
1647+
if (MaterializationThreads.getNumOccurrences() &&
1648+
MaterializationThreads != 0) {
1649+
errs() << "Warning: -num-threads was set, but LLVM was built with threads "
1650+
"disabled. Resetting to -num-threads=0\n";
1651+
}
1652+
MaterializationThreads = 0;
1653+
#endif
16401654

16411655
if (!!OutOfProcessExecutor.getNumOccurrences() ||
16421656
!!OutOfProcessExecutorConnect.getNumOccurrences()) {

0 commit comments

Comments
 (0)