[llvm] r329093 - [dsymutil] Apply recursion workaround for threading
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 3 11:01:19 PDT 2018
Author: jdevlieghere
Date: Tue Apr 3 11:01:18 2018
New Revision: 329093
URL: http://llvm.org/viewvc/llvm-project?rev=329093&view=rev
Log:
[dsymutil] Apply recursion workaround for threading
The DwarfLinker can have some very deep recursion that can max out the
(significantly smaller) stack when using threads. We don't want this
limitation when we only have a single thread. We already have this
workaround for the architecture-related threading. This patch applies
the same workaround to the parallel analysis and cloning.
Differential revision: https://reviews.llvm.org/D45172
Modified:
llvm/trunk/tools/dsymutil/DwarfLinker.cpp
llvm/trunk/tools/dsymutil/dsymutil.cpp
llvm/trunk/tools/dsymutil/dsymutil.h
Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=329093&r1=329092&r2=329093&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Tue Apr 3 11:01:18 2018
@@ -4301,8 +4301,6 @@ bool DwarfLinker::link(const DebugMap &M
if (MaxDwarfVersion == 0)
MaxDwarfVersion = 3;
- ThreadPool pool(2);
-
// These variables manage the list of processed object files.
// The mutex and condition variable are to ensure that this is thread safe.
std::mutex ProcessedFilesMutex;
@@ -4310,7 +4308,7 @@ bool DwarfLinker::link(const DebugMap &M
BitVector ProcessedFiles(NumObjects, false);
// Now do analyzeContextInfo in parallel as it is particularly expensive.
- pool.async([&]() {
+ auto AnalyzeLambda = [&]() {
for (unsigned i = 0, e = NumObjects; i != e; ++i) {
auto &LinkContext = ObjectContexts[i];
@@ -4331,13 +4329,13 @@ bool DwarfLinker::link(const DebugMap &M
ProcessedFiles.set(i);
ProcessedFilesConditionVariable.notify_one();
}
- });
+ };
// And then the remaining work in serial again.
// Note, although this loop runs in serial, it can run in parallel with
// the analyzeContextInfo loop so long as we process files with indices >=
// than those processed by analyzeContextInfo.
- pool.async([&]() {
+ auto CloneLambda = [&]() {
for (unsigned i = 0, e = NumObjects; i != e; ++i) {
{
std::unique_lock<std::mutex> LockGuard(ProcessedFilesMutex);
@@ -4397,9 +4395,20 @@ bool DwarfLinker::link(const DebugMap &M
Streamer->emitAppleTypes(AppleTypes);
Streamer->emitAppleObjc(AppleObjc);
}
- });
+ };
- pool.wait();
+ // FIXME: The DwarfLinker can have some very deep recursion that can max
+ // out the (significantly smaller) stack when using threads. We don't
+ // want this limitation when we only have a single thread.
+ if (Options.Threads == 1) {
+ AnalyzeLambda();
+ CloneLambda();
+ } else {
+ ThreadPool pool(2);
+ pool.async(AnalyzeLambda);
+ pool.async(CloneLambda);
+ pool.wait();
+ }
return Options.NoOutput ? true : Streamer->finish(Map);
}
Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=329093&r1=329092&r2=329093&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Tue Apr 3 11:01:18 2018
@@ -324,6 +324,11 @@ static Expected<LinkOptions> getOptions(
inconvertibleErrorCode());
}
+ if (NumThreads == 0)
+ Options.Threads = llvm::thread::hardware_concurrency();
+ if (DumpDebugMap || Verbose)
+ Options.Threads = 1;
+
return Options;
}
@@ -480,12 +485,8 @@ int main(int argc, char **argv) {
return 1;
}
- if (NumThreads == 0)
- NumThreads = llvm::thread::hardware_concurrency();
- if (DumpDebugMap || Verbose)
- NumThreads = 1;
- NumThreads = std::min<unsigned>(NumThreads, DebugMapPtrsOrErr->size());
-
+ NumThreads =
+ std::min<unsigned>(OptionsOrErr->Threads, DebugMapPtrsOrErr->size());
llvm::ThreadPool Threads(NumThreads);
// If there is more than one link to execute, we need to generate
Modified: llvm/trunk/tools/dsymutil/dsymutil.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.h?rev=329093&r1=329092&r2=329093&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.h (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.h Tue Apr 3 11:01:18 2018
@@ -48,6 +48,9 @@ struct LinkOptions {
/// Do not check swiftmodule timestamp
bool NoTimestamp = false;
+ /// Number of threads.
+ unsigned Threads = 1;
+
/// -oso-prepend-path
std::string PrependPath;
More information about the llvm-commits
mailing list