18#define DEBUG_TYPE "jobserver"
29struct JobserverConfig {
45 if (
Input.consume_front(Prefix)) {
55static std::optional<FdPair> getFileDescriptorPair(
StringRef Input) {
57 if (
Input.consumeInteger(10, FDs.Read))
59 if (!
Input.consume_front(
","))
61 if (
Input.consumeInteger(10, FDs.Write))
63 if (!
Input.empty() || !FDs.isValid())
74 JobserverConfig Config;
75 if (MakeFlags.
empty())
84 if (!Args.empty() && !Args[0].starts_with(
"-") && Args[0].contains(
'n'))
91 if (getPrefixedValue(Arg,
"--jobserver-auth=",
Value)) {
93 if (
auto FDPair = getFileDescriptorPair(
Value)) {
94 Config.TheMode = JobserverConfig::PosixPipe;
95 Config.PipeFDs = *FDPair;
99 if (getPrefixedValue(
Value,
"fifo:", FifoPath)) {
100 Config.TheMode = JobserverConfig::PosixFifo;
101 Config.Path = FifoPath.
str();
104 Config.TheMode = JobserverConfig::Win32Semaphore;
105 Config.Path =
Value.str();
108 }
else if (getPrefixedValue(Arg,
"--jobserver-fds=",
Value)) {
110 if (
auto FDPair = getFileDescriptorPair(
Value)) {
111 Config.TheMode = JobserverConfig::PosixPipe;
112 Config.PipeFDs = *FDPair;
115 "Invalid file descriptor pair in MAKEFLAGS");
122 if (Config.TheMode == JobserverConfig::PosixFifo ||
123 Config.TheMode == JobserverConfig::PosixPipe)
126 "FIFO/Pipe-based jobserver is not supported on Windows");
128 if (Config.TheMode == JobserverConfig::Win32Semaphore)
131 "Semaphore-based jobserver is not supported on this platform");
136std::once_flag GJobserverOnceFlag;
143 bool IsInitialized =
false;
144 std::atomic<bool> HasImplicitSlot{
true};
145 unsigned NumJobs = 0;
155 bool isValid()
const {
return IsInitialized; }
158#if defined(LLVM_ON_UNIX)
161 std::string FifoPath;
163 void *Semaphore =
nullptr;
169#if defined(LLVM_ON_UNIX)
186 return static_cast<uint8_t>(Value);
196 std::call_once(GJobserverOnceFlag, []() {
199 <<
"JobserverClient::getInstance() called for the first time.\n");
200 const char *MakeFlagsEnv = getenv(
"MAKEFLAGS");
202 errs() <<
"Warning: failed to create jobserver client due to MAKEFLAGS "
203 "environment variable not found\n";
207 LLVM_DEBUG(
dbgs() <<
"Found MAKEFLAGS = \"" << MakeFlagsEnv <<
"\"\n");
209 auto ConfigOrErr = parseNativeMakeFlags(MakeFlagsEnv);
210 if (
Error Err = ConfigOrErr.takeError()) {
211 errs() <<
"Warning: failed to create jobserver client due to invalid "
212 "MAKEFLAGS environment variable: "
213 <<
toString(std::move(Err)) <<
"\n";
217 JobserverConfig Config = *ConfigOrErr;
218 if (Config.TheMode == JobserverConfig::None) {
219 errs() <<
"Warning: failed to create jobserver client due to jobserver "
220 "mode missing in MAKEFLAGS environment variable\n";
224 if (Config.TheMode == JobserverConfig::PosixPipe) {
225#if defined(LLVM_ON_UNIX)
226 if (!areFdsValid(Config.PipeFDs.Read, Config.PipeFDs.Write)) {
227 errs() <<
"Warning: failed to create jobserver client due to invalid "
228 "Pipe FDs in MAKEFLAGS environment variable\n";
234 auto Client = std::make_unique<JobserverClientImpl>(Config);
235 if (Client->isValid()) {
237 GJobserver = Client.release();
239 errs() <<
"Warning: jobserver client initialization failed.\n";
250 GJobserver =
nullptr;
252 new (&GJobserverOnceFlag) std::once_flag();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
A JobSlot represents a single job slot that can be acquired from or released to a jobserver pool.
uint8_t getExplicitValue() const
~JobserverClientImpl() override
void release(JobSlot Slot) override
Releases a job slot back to the pool.
unsigned getNumJobs() const override
Returns the number of job slots available, as determined on first use.
JobSlot tryAcquire() override
Tries to acquire a job slot from the pool.
JobserverClientImpl(const JobserverConfig &Config)
The public interface for a jobserver client.
static LLVM_ABI_FOR_TEST JobserverClient * getInstance()
Returns the singleton instance of the JobserverClient.
static LLVM_ABI_FOR_TEST void resetForTesting()
Resets the singleton instance. For testing purposes only.
virtual ~JobserverClient()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
LLVM Value Representation.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
LLVM_ABI void SplitString(StringRef Source, SmallVectorImpl< StringRef > &OutFragments, StringRef Delimiters=" \t\n\v\f\r")
SplitString - Split up the specified string according to the specified delimiters,...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)