Skip to content

Commit 9c9710e

Browse files
author
Zachary Turner
committedJun 19, 2014
Remove support for LLVM runtime multi-threading.
After a number of previous small iterations, the functions llvm_start_multithreaded() and llvm_stop_multithreaded() have been reduced essentially to no-ops. This change removes them entirely. Reviewed by: rnk, dblaikie Differential Revision: http://reviews.llvm.org/D4216 llvm-svn: 211287
1 parent 778268d commit 9c9710e

File tree

7 files changed

+19
-99
lines changed

7 files changed

+19
-99
lines changed
 

‎llvm/docs/ProgrammersManual.rst

+4-41
Original file line numberDiff line numberDiff line change
@@ -2170,62 +2170,25 @@ compiler, consider compiling LLVM and LLVM-GCC in single-threaded mode, and
21702170
using the resultant compiler to build a copy of LLVM with multithreading
21712171
support.
21722172

2173-
.. _startmultithreaded:
2174-
2175-
Entering and Exiting Multithreaded Mode
2176-
---------------------------------------
2177-
2178-
In order to properly protect its internal data structures while avoiding
2179-
excessive locking overhead in the single-threaded case, the LLVM must intialize
2180-
certain data structures necessary to provide guards around its internals. To do
2181-
so, the client program must invoke ``llvm_start_multithreaded()`` before making
2182-
any concurrent LLVM API calls. To subsequently tear down these structures, use
2183-
the ``llvm_stop_multithreaded()`` call. You can also use the
2184-
``llvm_is_multithreaded()`` call to check the status of multithreaded mode.
2185-
2186-
Note that both of these calls must be made *in isolation*. That is to say that
2187-
no other LLVM API calls may be executing at any time during the execution of
2188-
``llvm_start_multithreaded()`` or ``llvm_stop_multithreaded``. It is the
2189-
client's responsibility to enforce this isolation.
2190-
2191-
The return value of ``llvm_start_multithreaded()`` indicates the success or
2192-
failure of the initialization. Failure typically indicates that your copy of
2193-
LLVM was built without multithreading support, typically because GCC atomic
2194-
intrinsics were not found in your system compiler. In this case, the LLVM API
2195-
will not be safe for concurrent calls. However, it *will* be safe for hosting
2196-
threaded applications in the JIT, though :ref:`care must be taken
2197-
<jitthreading>` to ensure that side exits and the like do not accidentally
2198-
result in concurrent LLVM API calls.
2199-
22002173
.. _shutdown:
22012174

22022175
Ending Execution with ``llvm_shutdown()``
22032176
-----------------------------------------
22042177

22052178
When you are done using the LLVM APIs, you should call ``llvm_shutdown()`` to
2206-
deallocate memory used for internal structures. This will also invoke
2207-
``llvm_stop_multithreaded()`` if LLVM is operating in multithreaded mode. As
2208-
such, ``llvm_shutdown()`` requires the same isolation guarantees as
2209-
``llvm_stop_multithreaded()``.
2210-
2211-
Note that, if you use scope-based shutdown, you can use the
2212-
``llvm_shutdown_obj`` class, which calls ``llvm_shutdown()`` in its destructor.
2179+
deallocate memory used for internal structures.
22132180

22142181
.. _managedstatic:
22152182

22162183
Lazy Initialization with ``ManagedStatic``
22172184
------------------------------------------
22182185

22192186
``ManagedStatic`` is a utility class in LLVM used to implement static
2220-
initialization of static resources, such as the global type tables. Before the
2221-
invocation of ``llvm_shutdown()``, it implements a simple lazy initialization
2222-
scheme. Once ``llvm_start_multithreaded()`` returns, however, it uses
2187+
initialization of static resources, such as the global type tables. In a
2188+
single-threaded environment, it implements a simple lazy initialization scheme.
2189+
When LLVM is compiled with support for multi-threading, however, it uses
22232190
double-checked locking to implement thread-safe lazy initialization.
22242191

2225-
Note that, because no other threads are allowed to issue LLVM API calls before
2226-
``llvm_start_multithreaded()`` returns, it is possible to have
2227-
``ManagedStatic``\ s of ``llvm::sys::Mutex``\ s.
2228-
22292192
.. _llvmcontext:
22302193

22312194
Achieving Isolation with ``LLVMContext``

‎llvm/include/llvm-c/Core.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -2848,16 +2848,13 @@ void LLVMDisposePassManager(LLVMPassManagerRef PM);
28482848
* @{
28492849
*/
28502850

2851-
/** Allocate and initialize structures needed to make LLVM safe for
2852-
multithreading. The return value indicates whether multithreaded
2853-
initialization succeeded. Must be executed in isolation from all
2854-
other LLVM api calls.
2855-
@see llvm::llvm_start_multithreaded */
2851+
/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2852+
time define LLVM_ENABLE_THREADS. This function always returns
2853+
LLVMIsMultithreaded(). */
28562854
LLVMBool LLVMStartMultithreaded(void);
28572855

2858-
/** Deallocate structures necessary to make LLVM safe for multithreading.
2859-
Must be executed in isolation from all other LLVM api calls.
2860-
@see llvm::llvm_stop_multithreaded */
2856+
/** Deprecated: Multi-threading can only be enabled/disabled with the compile
2857+
time define LLVM_ENABLE_THREADS. */
28612858
void LLVMStopMultithreaded(void);
28622859

28632860
/** Check whether LLVM is executing in thread-safe mode or not.

‎llvm/include/llvm/Support/ManagedStatic.h

-3
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ void llvm_shutdown();
103103
/// llvm_shutdown() when it is destroyed.
104104
struct llvm_shutdown_obj {
105105
llvm_shutdown_obj() { }
106-
explicit llvm_shutdown_obj(bool multithreaded) {
107-
if (multithreaded) llvm_start_multithreaded();
108-
}
109106
~llvm_shutdown_obj() { llvm_shutdown(); }
110107
};
111108

‎llvm/include/llvm/Support/Threading.h

+6-17
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,19 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// TThis file defines llvm_start_multithreaded() and friends.
10+
// This file declares helper functions for running LLVM in a multi-threaded
11+
// environment.
1112
//
1213
//===----------------------------------------------------------------------===//
1314

1415
#ifndef LLVM_SUPPORT_THREADING_H
1516
#define LLVM_SUPPORT_THREADING_H
1617

17-
namespace llvm {
18-
/// llvm_start_multithreaded - Allocate and initialize structures needed to
19-
/// make LLVM safe for multithreading. The return value indicates whether
20-
/// multithreaded initialization succeeded. LLVM will still be operational
21-
/// on "failed" return, and will still be safe for hosting threading
22-
/// applications in the JIT, but will not be safe for concurrent calls to the
23-
/// LLVM APIs.
24-
/// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.
25-
bool llvm_start_multithreaded();
26-
27-
/// llvm_stop_multithreaded - Deallocate structures necessary to make LLVM
28-
/// safe for multithreading.
29-
/// THIS MUST EXECUTE IN ISOLATION FROM ALL OTHER LLVM API CALLS.
30-
void llvm_stop_multithreaded();
18+
#include "llvm/Support/Mutex.h"
3119

32-
/// llvm_is_multithreaded - Check whether LLVM is executing in thread-safe
33-
/// mode or not.
20+
namespace llvm {
21+
/// Returns true if LLVM is compiled with support for multi-threading, and
22+
/// false otherwise.
3423
bool llvm_is_multithreaded();
3524

3625
/// llvm_execute_on_thread - Execute the given \p UserFn on a separate

‎llvm/lib/IR/Core.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2702,11 +2702,10 @@ void LLVMDisposePassManager(LLVMPassManagerRef PM) {
27022702
/*===-- Threading ------------------------------------------------------===*/
27032703

27042704
LLVMBool LLVMStartMultithreaded() {
2705-
return llvm_start_multithreaded();
2705+
return LLVMIsMultithreaded();
27062706
}
27072707

27082708
void LLVMStopMultithreaded() {
2709-
llvm_stop_multithreaded();
27102709
}
27112710

27122711
LLVMBool LLVMIsMultithreaded() {

‎llvm/lib/Support/Threading.cpp

+3-26
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// This file implements llvm_start_multithreaded() and friends.
10+
// This file defines helper functions for running LLVM in a multi-threaded
11+
// environment.
1112
//
1213
//===----------------------------------------------------------------------===//
1314

@@ -19,38 +20,14 @@
1920

2021
using namespace llvm;
2122

22-
static bool multithreaded_mode = false;
23-
24-
bool llvm::llvm_start_multithreaded() {
23+
bool llvm::llvm_is_multithreaded() {
2524
#if LLVM_ENABLE_THREADS != 0
26-
assert(!multithreaded_mode && "Already multithreaded!");
27-
multithreaded_mode = true;
28-
29-
// We fence here to ensure that all initialization is complete BEFORE we
30-
// return from llvm_start_multithreaded().
31-
sys::MemoryFence();
3225
return true;
3326
#else
3427
return false;
3528
#endif
3629
}
3730

38-
void llvm::llvm_stop_multithreaded() {
39-
#if LLVM_ENABLE_THREADS != 0
40-
assert(multithreaded_mode && "Not currently multithreaded!");
41-
42-
// We fence here to insure that all threaded operations are complete BEFORE we
43-
// return from llvm_stop_multithreaded().
44-
sys::MemoryFence();
45-
46-
multithreaded_mode = false;
47-
#endif
48-
}
49-
50-
bool llvm::llvm_is_multithreaded() {
51-
return multithreaded_mode;
52-
}
53-
5431
#if LLVM_ENABLE_THREADS != 0 && defined(HAVE_PTHREAD_H)
5532
#include <pthread.h>
5633

‎llvm/unittests/Support/ManagedStatic.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ TEST(Initialize, MultipleThreads) {
4747
void *p1 = test1::allocate_stack(a1);
4848
void *p2 = test1::allocate_stack(a2);
4949

50-
llvm_start_multithreaded();
5150
pthread_t t1, t2;
5251
pthread_create(&t1, &a1, test1::helper, nullptr);
5352
pthread_create(&t2, &a2, test1::helper, nullptr);
5453
pthread_join(t1, nullptr);
5554
pthread_join(t2, nullptr);
5655
free(p1);
5756
free(p2);
58-
llvm_stop_multithreaded();
5957
}
6058
#endif
6159

0 commit comments

Comments
 (0)
Please sign in to comment.