LLVM: include/llvm/Support/Threading.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_SUPPORT_THREADING_H

15#define LLVM_SUPPORT_THREADING_H

16

19#include "llvm/Config/llvm-config.h"

21#include

22

23#if defined(_MSC_VER)

24

25

26#define LLVM_THREADING_USE_STD_CALL_ONCE 1

27#elif defined(LLVM_ON_UNIX) && \

28 (defined(_LIBCPP_VERSION) || \

29 !(defined(__NetBSD__) || defined(__OpenBSD__) || defined(__powerpc__)))

30

31

32

33#define LLVM_THREADING_USE_STD_CALL_ONCE 1

34#elif defined(LLVM_ON_UNIX) && \

35 (defined(__powerpc__) && defined(__LITTLE_ENDIAN__))

36#define LLVM_THREADING_USE_STD_CALL_ONCE 1

37#else

38#define LLVM_THREADING_USE_STD_CALL_ONCE 0

39#endif

40

41#if LLVM_THREADING_USE_STD_CALL_ONCE

42#include

43#else

45#endif

46

47namespace llvm {

48class Twine;

49

50

51

53

54#if LLVM_THREADING_USE_STD_CALL_ONCE

55

56using once_flag = std::once_flag;

57

58#else

59

61

62

63

64

65

66

70

71#endif

72

73

74

75

76

77

78

79

80

81

82

83

84

85 template <typename Function, typename... Args>

87#if LLVM_THREADING_USE_STD_CALL_ONCE

88 std::call_once(flag, std::forward(F),

89 std::forward(ArgList)...);

90#else

91

92

95 std::forward(F)(std::forward(ArgList)...);

101 } else {

102

105 while (tmp != Done) {

108 }

109 }

111#endif

112 }

113

114

116 public:

117

118

119

120

122

123

124

126

127

128

130

131

132

134

135

136

137

138

140

141

142

143 LLVM_ABI std::optional

145

146

147

148

150 };

151

152

153

154

155

156

157 LLVM_ABI std::optional

159

160

161

162

163

164

165

166 inline ThreadPoolStrategy

173

174

175

176

177

179 std::optional S =

181 if (S)

182 return *S;

184 }

185

186

187

188

189

195

196

197

198

199

201 std::optional S =

203 if (S)

204 return *S;

206 }

207

208

209

210

217

218

219

220

221

225

226

228 return S;

229 }

230

231

232

233

234

236

237

238

240

241

242

243

244

245

246

248

249

250

251

252

253

254

256

257

258

259

261

262

264

265

266

267

269

271

272

273

275

276

277

278

279

281

282

284 };

287}

288

289#endif

This file implements the BitVector class.

#define TsanHappensBefore(cv)

#define TsanHappensAfter(cv)

#define TsanIgnoreWritesEnd()

#define TsanIgnoreWritesBegin()

static cl::opt< int > ThreadCount("threads", cl::init(0))

StringRef - Represent a constant reference to a string, i.e.

This tells how a thread pool will be used.

Definition Threading.h:115

bool Limit

Definition Threading.h:129

unsigned ThreadsRequested

Definition Threading.h:121

bool UseHyperThreads

Definition Threading.h:125

LLVM_ABI void apply_thread_strategy(unsigned ThreadPoolNum) const

Assign the current thread to an ideal hardware CPU or NUMA node.

LLVM_ABI std::optional< unsigned > compute_cpu_socket(unsigned ThreadPoolNum) const

Finds the CPU socket where a thread should go.

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...

Definition Threading.h:149

LLVM_ABI void MemoryFence()

LLVM_ABI cas_flag CompareAndSwap(volatile cas_flag *ptr, cas_flag new_value, cas_flag old_value)

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,...

Definition Threading.h:190

ThreadPoolStrategy heavyweight_hardware_concurrency(unsigned ThreadCount=0)

Returns a thread strategy for tasks requiring significant memory or other resources.

Definition Threading.h:167

ThreadPoolStrategy jobserver_concurrency()

Returns a thread strategy that attempts to coordinate with a GNU Make jobserver.

Definition Threading.h:222

ThreadPriority

Definition Threading.h:270

@ Low

Lower the current thread's priority such that it does not affect foreground tasks significantly.

Definition Threading.h:280

@ Background

Lower the current thread's priority as much as possible.

Definition Threading.h:274

constexpr bool llvm_is_multithreaded()

Returns true if LLVM is compiled with support for multi-threading, and false otherwise.

Definition Threading.h:52

InitStatus

Definition Threading.h:60

@ Uninitialized

Definition Threading.h:60

@ Wait

Definition Threading.h:60

@ Done

Definition Threading.h:60

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 SetThreadPriorityResult set_thread_priority(ThreadPriority Priority)

LLVM_ABI unsigned get_cpus()

Returns how many physical CPUs or NUMA groups the system has.

ThreadPoolStrategy optimal_concurrency(unsigned TaskCount=0)

Returns an optimal thread strategy to execute specified amount of tasks.

Definition Threading.h:211

LLVM_ABI void set_thread_name(const Twine &Name)

Set the name of the current thread.

SetThreadPriorityResult

Definition Threading.h:285

@ FAILURE

Definition Threading.h:285

@ SUCCESS

Definition Threading.h:285

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.

void call_once(once_flag &flag, Function &&F, Args &&... ArgList)

Execute the function specified as a parameter once.

Definition Threading.h:86

@ Default

The result values are uniform if and only if all operands are uniform.

The llvm::once_flag structure.

Definition Threading.h:67

volatile sys::cas_flag status

Definition Threading.h:68