@@ -364,11 +364,7 @@ def make_paths_absolute(f):
364
364
return os .path .abspath (f )
365
365
366
366
367
- # Runs llvm-nm in parallel for the given list of files.
368
- # The results are populated in nm_cache
369
- # multiprocessing_pool: An existing multiprocessing pool to reuse for the operation, or None
370
- # to have the function allocate its own.
371
- def parallel_llvm_nm (files ):
367
+ def multithreaded_llvm_nm (files ):
372
368
with ToolchainProfiler .profile_block ('parallel_llvm_nm' ):
373
369
pool = get_multiprocessing_pool ()
374
370
object_contents = pool .map (g_llvm_nm_uncached , files )
@@ -380,6 +376,33 @@ def parallel_llvm_nm(files):
380
376
return object_contents
381
377
382
378
379
+ def singlethreaded_llvm_nm (files ):
380
+ with ToolchainProfiler .profile_block ('singlethreaded_llvm_nm' ):
381
+ object_contents = []
382
+ for file in files :
383
+ obj = llvm_nm_uncached (file )
384
+ if obj .returncode != 0 :
385
+ logger .debug ('llvm-nm failed on file ' + file + ': return code ' + str (obj .returncode ) + ', error: ' + obj .output )
386
+ nm_cache [file ] = obj
387
+ object_contents += [obj ]
388
+ return object_contents
389
+
390
+
391
+ # Runs llvm-nm for the given list of files.
392
+ # The results are populated in nm_cache
393
+ def parallel_llvm_nm (files ):
394
+ # Python multiprocessing pool (get_multiprocessing_pool() and pool.map() functions) have a lot of overhead,
395
+ # so run the llvm-nm calls sequentially if it will be faster than waiting for the pool to come up.
396
+ heuristic_multiprocessing_pool_startup_time_msecs = 700
397
+ # Individual llvm-nm completes very fast
398
+ heuristic_single_threaded_llvm_nm_execution_time_msecs = 10
399
+
400
+ if heuristic_multiprocessing_pool_startup_time_msecs + len (files ) * heuristic_single_threaded_llvm_nm_execution_time_msecs / get_num_cores () < len (files ) * heuristic_single_threaded_llvm_nm_execution_time_msecs :
401
+ return multithreaded_llvm_nm (files )
402
+ else :
403
+ return singlethreaded_llvm_nm (files )
404
+
405
+
383
406
def read_link_inputs (files ):
384
407
with ToolchainProfiler .profile_block ('read_link_inputs' ):
385
408
# Before performing the link, we need to look at each input file to determine which symbols
0 commit comments