1//===-- llvm/Support/Threading.cpp- Control multithreading mode --*- C++ -*-==//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file defines helper functions for running LLVM in a multi-threaded
12//===----------------------------------------------------------------------===//
15#include "llvm/Config/config.h"
16#include "llvm/Config/llvm-config.h"
25//===----------------------------------------------------------------------===//
26//=== WARNING: Implementation here must contain only TRULY operating system
27//=== independent code.
28//===----------------------------------------------------------------------===//
30#if LLVM_ENABLE_THREADS == 0 || \
31 (!defined(_WIN32) && !defined(HAVE_PTHREAD_H))
43 // When threads are disabled, ensure clients will loop at least once.
47// Unknown if threading turned off
52static int computeHostNumHardwareThreads();
57 return JS->getNumJobs();
61 if (MaxThreadCount <= 0)
64 return MaxThreadCount;
70// Include the platform-specific parts of this class.
78// Must be included after Threading.inc to provide definition for llvm::thread
79// because FreeBSD's condvar.h (included by user.h) misuses the "thread"
84 // Darwin's default stack size for threads except the main one is only 512KB,
85 // which is not enough for some/many normal LLVM compilations. This implements
86 // the same interface as std::thread but requests the same stack size as the
87 // main thread (8MB) before creation.
88const std::optional<unsigned> llvm::thread::DefaultStackSize = 8 * 1024 * 1024;
90 // On AIX, the default pthread stack size limit is ~192k for 64-bit programs.
91 // This limit is easily reached when doing link-time thinLTO. AIX library
92 // developers have used 4MB, so we'll do the same.
93const std::optional<unsigned> llvm::thread::DefaultStackSize = 4 * 1024 * 1024;
95const std::optional<unsigned> llvm::thread::DefaultStackSize;
101std::optional<ThreadPoolStrategy>
109 return std::nullopt;
// malformed 'Num' value
113 // Do not take the Default into account. This effectively disables
114 // heavyweight_hardware_concurrency() if the user asks for any number of
115 // threads on the cmd-line.
static JobserverClient * getInstance()
Returns the singleton instance of the JobserverClient.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
bool getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
constexpr bool empty() const
empty - Check if the string is empty.
This tells how a thread pool will be used.
unsigned ThreadsRequested
LLVM_ABI unsigned compute_thread_count() const
Retrieves the max available threads for the current strategy.
bool UseJobserver
If true, the thread pool will attempt to coordinate with a GNU Make jobserver, acquiring a job slot b...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is an optimization pass for GlobalISel generic memory operations.
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
LLVM_ABI llvm::BitVector get_thread_affinity_mask()
Returns a mask that represents on which hardware thread, core, CPU, NUMA group, the calling thread ca...
LLVM_ABI uint32_t get_max_thread_name_length()
Get the maximum length of a thread name on this platform.
LLVM_ABI void set_thread_name(const Twine &Name)
Set the name of the current thread.
LLVM_ABI void get_thread_name(SmallVectorImpl< char > &Name)
Get the name of the current thread.
LLVM_ABI int get_physical_cores()
Returns how many physical cores (as opposed to logical cores returned from thread::hardware_concurren...
LLVM_ABI std::optional< ThreadPoolStrategy > get_threadpool_strategy(StringRef Num, ThreadPoolStrategy Default={})
Build a strategy from a number of threads as a string provided in Num.
LLVM_ABI uint64_t get_threadid()
Return the current thread id, as used in various OS system calls.
@ Default
The result values are uniform if and only if all operands are uniform.