Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Don't compile usage of std::thread
Browse files Browse the repository at this point in the history
As of the time of this writing it's not actually used anywhere meaningfullly
throughout the LLVM repo that we need, and it unfortunately uses `std::thread`
which isn't available in mingw-w64 toolchains with the win32 threading model
(the one that we use).

The change made to achive this was to just always use the single-threaded
support in `include/llvm/Support/thread.h`, and hopefuly that'll be enough...

For reference, the upstream LLVM bug has been reported [1]

[1]: https://llvm.org/bugs/show_bug.cgi?id=26365
  • Loading branch information
alexcrichton authored and pftbest committed Oct 28, 2016
1 parent fc0dadf commit 58731be
Show file tree
Hide file tree
Showing 37 changed files with 43 additions and 5,048 deletions.
13 changes: 0 additions & 13 deletions include/llvm/ExecutionEngine/Orc/RPCChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,29 @@ class RPCChannel {

/// Flush the stream if possible.
virtual Error send() = 0;

/// Get the lock for stream reading.
std::mutex &getReadLock() { return readLock; }

/// Get the lock for stream writing.
std::mutex &getWriteLock() { return writeLock; }

private:
std::mutex readLock, writeLock;
};

/// Notify the channel that we're starting a message send.
/// Locks the channel for writing.
inline Error startSendMessage(RPCChannel &C) {
C.getWriteLock().lock();
return Error::success();
}

/// Notify the channel that we're ending a message send.
/// Unlocks the channel for writing.
inline Error endSendMessage(RPCChannel &C) {
C.getWriteLock().unlock();
return Error::success();
}

/// Notify the channel that we're starting a message receive.
/// Locks the channel for reading.
inline Error startReceiveMessage(RPCChannel &C) {
C.getReadLock().lock();
return Error::success();
}

/// Notify the channel that we're ending a message receive.
/// Unlocks the channel for reading.
inline Error endReceiveMessage(RPCChannel &C) {
C.getReadLock().unlock();
return Error::success();
}

Expand Down
16 changes: 11 additions & 5 deletions include/llvm/ExecutionEngine/Orc/RPCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class RPCBase {

template <typename ChannelT>
static Error readResult(ChannelT &C, std::promise<OptionalReturn> &P) {
#if 0
RetT Val;
auto Err = deserialize(C, Val);
auto Err2 = endReceiveMessage(C);
Expand All @@ -112,11 +113,14 @@ class RPCBase {
return Err;
}
P.set_value(std::move(Val));
#endif
return Error::success();
}

static void abandon(std::promise<OptionalReturn> &P) {
#if 0
P.set_value(OptionalReturn());
#endif
}

template <typename ChannelT, typename SequenceNumberT>
Expand Down Expand Up @@ -159,11 +163,17 @@ class RPCBase {
template <typename ChannelT>
static Error readResult(ChannelT &C, std::promise<OptionalReturn> &P) {
// Void functions don't have anything to deserialize, so we're good.
#if 0
P.set_value(true);
#endif
return endReceiveMessage(C);
}

static void abandon(std::promise<OptionalReturn> &P) { P.set_value(false); }
static void abandon(std::promise<OptionalReturn> &P) {
#if 0
P.set_value(false);
#endif
}

template <typename ChannelT, typename SequenceNumberT>
static Error respond(ChannelT &C, SequenceNumberT SeqNo,
Expand Down Expand Up @@ -617,13 +627,11 @@ class RPC : public RPCBase {
}

void reset() {
std::lock_guard<std::mutex> Lock(SeqNoLock);
NextSequenceNumber = 0;
FreeSequenceNumbers.clear();
}

SequenceNumberT getSequenceNumber() {
std::lock_guard<std::mutex> Lock(SeqNoLock);
if (FreeSequenceNumbers.empty())
return NextSequenceNumber++;
auto SequenceNumber = FreeSequenceNumbers.back();
Expand All @@ -632,12 +640,10 @@ class RPC : public RPCBase {
}

void releaseSequenceNumber(SequenceNumberT SequenceNumber) {
std::lock_guard<std::mutex> Lock(SeqNoLock);
FreeSequenceNumbers.push_back(SequenceNumber);
}

private:
std::mutex SeqNoLock;
SequenceNumberT NextSequenceNumber = 0;
std::vector<SequenceNumberT> FreeSequenceNumbers;
};
Expand Down
4 changes: 4 additions & 0 deletions include/llvm/Support/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "llvm/Support/thread.h"

# if 0

#ifdef _MSC_VER
// concrt.h depends on eh.h for __uncaught_exception declaration
// even if we disable exceptions.
Expand Down Expand Up @@ -134,4 +136,6 @@ class ThreadPool {
};
}

# endif

#endif // LLVM_SUPPORT_THREAD_POOL_H
2 changes: 1 addition & 1 deletion include/llvm/Support/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

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

#if LLVM_ENABLE_THREADS
#if LLVM_ENABLE_THREADS && 0

#ifdef _MSC_VER
// concrt.h depends on eh.h for __uncaught_exception declaration
Expand Down
2 changes: 2 additions & 0 deletions lib/CodeGen/ParallelCG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ std::unique_ptr<Module> llvm::splitCodeGen(
return M;
}

#if 0
// Create ThreadPool in nested scope so that threads will be joined
// on destruction.
{
Expand Down Expand Up @@ -95,5 +96,6 @@ std::unique_ptr<Module> llvm::splitCodeGen(
PreserveLocals);
}

#endif
return {};
}
4 changes: 3 additions & 1 deletion lib/LTO/ThinLTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extern cl::opt<bool> LTODiscardValueNames;
namespace {

static cl::opt<int> ThreadCount("threads",
cl::init(std::thread::hardware_concurrency()));
cl::init(1));

static void diagnosticHandler(const DiagnosticInfo &DI) {
DiagnosticPrinterRawOStream DP(errs());
Expand Down Expand Up @@ -667,6 +667,7 @@ std::unique_ptr<MemoryBuffer> ThinLTOCodeGenerator::codegen(Module &TheModule) {

// Main entry point for the ThinLTO processing
void ThinLTOCodeGenerator::run() {
#if 0
if (CodeGenOnly) {
// Perform only parallel codegen and return.
ThreadPool Pool;
Expand Down Expand Up @@ -832,4 +833,5 @@ void ThinLTOCodeGenerator::run() {
// If statistics were requested, print them out now.
if (llvm::AreStatisticsEnabled())
llvm::PrintStatistics();
#endif
}
6 changes: 5 additions & 1 deletion lib/Support/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
//
//===----------------------------------------------------------------------===//

#if 0

#include "llvm/Support/ThreadPool.h"

#include "llvm/Config/llvm-config.h"
#include "llvm/Support/raw_ostream.h"

using namespace llvm;

#if LLVM_ENABLE_THREADS
#if LLVM_ENABLE_THREADS && 0

// Default to std::thread::hardware_concurrency
ThreadPool::ThreadPool() : ThreadPool(std::thread::hardware_concurrency()) {}
Expand Down Expand Up @@ -156,3 +158,5 @@ ThreadPool::~ThreadPool() {
}

#endif

#endif
1 change: 0 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(LLVM_TEST_DEPENDS
count
llc
lli
lli-child-target
llvm-ar
llvm-as
llvm-bcanalyzer
Expand Down
5 changes: 0 additions & 5 deletions tools/lli/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
if ( LLVM_INCLUDE_UTILS )
add_subdirectory(ChildTarget)
endif()

set(LLVM_LINK_COMPONENTS
CodeGen
Core
Expand Down Expand Up @@ -39,6 +35,5 @@ endif( LLVM_USE_INTEL_JITEVENTS )

add_llvm_tool(lli
lli.cpp
OrcLazyJIT.cpp
)
export_executable_symbols(lli)
10 changes: 0 additions & 10 deletions tools/lli/ChildTarget/CMakeLists.txt

This file was deleted.

78 changes: 0 additions & 78 deletions tools/lli/ChildTarget/ChildTarget.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions tools/lli/ChildTarget/LLVMBuild.txt

This file was deleted.

3 changes: 0 additions & 3 deletions tools/lli/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
;
;===------------------------------------------------------------------------===;

[common]
subdirectories = ChildTarget

[component_0]
type = Tool
name = lli
Expand Down
Loading

0 comments on commit 58731be

Please sign in to comment.