[PATCH] D133759: [Support] Access threadIndex via a wrapper function
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 23:29:59 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe280940bfb33: [Support] Access threadIndex via a wrapper function (authored by mstorsjo).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D133759/new/
https://reviews.llvm.org/D133759
Files:
lld/ELF/Relocations.cpp
lld/ELF/SyntheticSections.h
llvm/include/llvm/Support/Parallel.h
llvm/lib/Support/Parallel.cpp
Index: llvm/lib/Support/Parallel.cpp
===================================================================
--- llvm/lib/Support/Parallel.cpp
+++ llvm/lib/Support/Parallel.cpp
@@ -18,11 +18,19 @@
#include <vector>
llvm::ThreadPoolStrategy llvm::parallel::strategy;
-thread_local unsigned llvm::parallel::threadIndex;
namespace llvm {
namespace parallel {
#if LLVM_ENABLE_THREADS
+
+#ifdef _WIN32
+static thread_local unsigned threadIndex;
+
+unsigned getThreadIndex() { return threadIndex; }
+#else
+thread_local unsigned threadIndex;
+#endif
+
namespace detail {
namespace {
Index: llvm/include/llvm/Support/Parallel.h
===================================================================
--- llvm/include/llvm/Support/Parallel.h
+++ llvm/include/llvm/Support/Parallel.h
@@ -28,8 +28,22 @@
// this file. It defaults to using all hardware threads and should be
// initialized before the first use of parallel routines.
extern ThreadPoolStrategy strategy;
+
+#if LLVM_ENABLE_THREADS
+#ifdef _WIN32
+// Direct access to thread_local variables from a different DLL isn't
+// possible with Windows Native TLS.
+unsigned getThreadIndex();
+#else
+// Don't access this directly, use the getThreadIndex wrapper.
extern thread_local unsigned threadIndex;
+inline unsigned getThreadIndex() { return threadIndex; }
+#endif
+#else
+inline unsigned getThreadIndex() { return 0; }
+#endif
+
namespace detail {
class Latch {
uint32_t Count;
Index: lld/ELF/SyntheticSections.h
===================================================================
--- lld/ELF/SyntheticSections.h
+++ lld/ELF/SyntheticSections.h
@@ -557,7 +557,7 @@
template <>
inline void RelocationBaseSection::addReloc<true>(const DynamicReloc &reloc) {
- relocsVec[llvm::parallel::threadIndex].push_back(reloc);
+ relocsVec[llvm::parallel::getThreadIndex()].push_back(reloc);
}
template <class ELFT>
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ lld/ELF/Relocations.cpp
@@ -887,7 +887,7 @@
if (part.relrDyn && isec.alignment >= 2 && offsetInSec % 2 == 0) {
isec.relocations.push_back({expr, type, offsetInSec, addend, &sym});
if (shard)
- part.relrDyn->relocsVec[parallel::threadIndex].push_back(
+ part.relrDyn->relocsVec[parallel::getThreadIndex()].push_back(
{&isec, offsetInSec});
else
part.relrDyn->relocs.push_back({&isec, offsetInSec});
@@ -1562,7 +1562,7 @@
tg.execute(fn);
}
- // Both the main thread and thread pool index 0 use threadIndex==0. Be
+ // Both the main thread and thread pool index 0 use getThreadIndex()==0. Be
// careful that they don't concurrently run scanSections. When serial is
// true, fn() has finished at this point, so running execute is safe.
tg.execute([] {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133759.459990.patch
Type: text/x-patch
Size: 2829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220914/862accee/attachment.bin>
More information about the llvm-commits
mailing list