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

Commit deb2692

Browse files
committed
Don't compile usage of std::thread
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). Two major changes were made to achieve this: 1. The `ThreadPool.cpp` file was just entirely commented out. This isn't used anywhere in the LLVM repo nor in Rust itself. 2. The `ParallelCG.cpp` file was mostly deleted. Unfortunately it's used a few places in LLVM and is needed to link correctly, but we in Rust don't use it at all. For now it's just a stub implementation that hopefully compiles everywhere, but perhaps we can find a less invasive (aka doesn't have rebase conflicts in the future) change to apply soon. For reference, the upstream LLVM bug has been reported [1] [1]: https://llvm.org/bugs/show_bug.cgi?id=26365
1 parent d16f119 commit deb2692

File tree

4 files changed

+13
-62
lines changed

4 files changed

+13
-62
lines changed

include/llvm/Support/ThreadPool.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#if 0
15+
1416
#ifndef LLVM_SUPPORT_THREAD_POOL_H
1517
#define LLVM_SUPPORT_THREAD_POOL_H
1618

@@ -134,3 +136,5 @@ class ThreadPool {
134136
}
135137

136138
#endif // LLVM_SUPPORT_THREAD_POOL_H
139+
140+
#endif

include/llvm/Support/thread.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#if 0
18+
1719
#ifndef LLVM_SUPPORT_THREAD_H
1820
#define LLVM_SUPPORT_THREAD_H
1921

@@ -64,3 +66,5 @@ struct thread {
6466
#endif // LLVM_ENABLE_THREADS
6567

6668
#endif
69+
70+
#endif

lib/CodeGen/ParallelCG.cpp

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,72 +25,11 @@
2525

2626
using namespace llvm;
2727

28-
static void codegen(Module *M, llvm::raw_pwrite_stream &OS,
29-
const Target *TheTarget, StringRef CPU, StringRef Features,
30-
const TargetOptions &Options, Reloc::Model RM,
31-
CodeModel::Model CM, CodeGenOpt::Level OL,
32-
TargetMachine::CodeGenFileType FileType) {
33-
std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine(
34-
M->getTargetTriple(), CPU, Features, Options, RM, CM, OL));
35-
36-
legacy::PassManager CodeGenPasses;
37-
if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType))
38-
report_fatal_error("Failed to setup codegen");
39-
CodeGenPasses.run(*M);
40-
}
41-
4228
std::unique_ptr<Module>
4329
llvm::splitCodeGen(std::unique_ptr<Module> M,
4430
ArrayRef<llvm::raw_pwrite_stream *> OSs, StringRef CPU,
4531
StringRef Features, const TargetOptions &Options,
4632
Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL,
4733
TargetMachine::CodeGenFileType FileType) {
48-
StringRef TripleStr = M->getTargetTriple();
49-
std::string ErrMsg;
50-
const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg);
51-
if (!TheTarget)
52-
report_fatal_error(Twine("Target not found: ") + ErrMsg);
53-
54-
if (OSs.size() == 1) {
55-
codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM,
56-
OL, FileType);
57-
return M;
58-
}
59-
60-
std::vector<thread> Threads;
61-
SplitModule(std::move(M), OSs.size(), [&](std::unique_ptr<Module> MPart) {
62-
// We want to clone the module in a new context to multi-thread the codegen.
63-
// We do it by serializing partition modules to bitcode (while still on the
64-
// main thread, in order to avoid data races) and spinning up new threads
65-
// which deserialize the partitions into separate contexts.
66-
// FIXME: Provide a more direct way to do this in LLVM.
67-
SmallVector<char, 0> BC;
68-
raw_svector_ostream BCOS(BC);
69-
WriteBitcodeToFile(MPart.get(), BCOS);
70-
71-
llvm::raw_pwrite_stream *ThreadOS = OSs[Threads.size()];
72-
Threads.emplace_back(
73-
[TheTarget, CPU, Features, Options, RM, CM, OL, FileType,
74-
ThreadOS](const SmallVector<char, 0> &BC) {
75-
LLVMContext Ctx;
76-
ErrorOr<std::unique_ptr<Module>> MOrErr =
77-
parseBitcodeFile(MemoryBufferRef(StringRef(BC.data(), BC.size()),
78-
"<split-module>"),
79-
Ctx);
80-
if (!MOrErr)
81-
report_fatal_error("Failed to read bitcode");
82-
std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
83-
84-
codegen(MPartInCtx.get(), *ThreadOS, TheTarget, CPU, Features,
85-
Options, RM, CM, OL, FileType);
86-
},
87-
// Pass BC using std::move to ensure that it get moved rather than
88-
// copied into the thread's context.
89-
std::move(BC));
90-
});
91-
92-
for (thread &T : Threads)
93-
T.join();
94-
95-
return {};
34+
return M;
9635
}

lib/Support/ThreadPool.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14+
#if 0
15+
1416
#include "llvm/Support/ThreadPool.h"
1517

1618
#include "llvm/Config/llvm-config.h"
@@ -153,3 +155,5 @@ ThreadPool::~ThreadPool() {
153155
}
154156

155157
#endif
158+
159+
#endif

0 commit comments

Comments
 (0)