|
| 1 | +From 69ef168544e4f15b793dd35d272008fde9a6e835 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alex Crichton < [email protected]> |
| 3 | +Date: Thu, 28 Jan 2016 20:44:50 -0800 |
| 4 | +Subject: [PATCH] Don't compile usage of std::thread |
| 5 | + |
| 6 | +As of the time of this writing it's not actually used anywhere meaningfullly |
| 7 | +throughout the LLVM repo that we need, and it unfortunately uses `std::thread` |
| 8 | +which isn't available in mingw-w64 toolchains with the win32 threading model |
| 9 | +(the one that we use). |
| 10 | + |
| 11 | +Two major changes were made to achieve this: |
| 12 | + |
| 13 | +1. The `ThreadPool.cpp` file was just entirely commented out. This isn't used |
| 14 | + anywhere in the LLVM repo nor in Rust itself. |
| 15 | +2. The `ParallelCG.cpp` file was mostly deleted. Unfortunately it's used a few |
| 16 | + places in LLVM and is needed to link correctly, but we in Rust don't use it |
| 17 | + at all. For now it's just a stub implementation that hopefully compiles |
| 18 | + everywhere, but perhaps we can find a less invasive (aka doesn't have rebase |
| 19 | + conflicts in the future) change to apply soon. |
| 20 | + |
| 21 | +For reference, the upstream LLVM bug has been reported [1] |
| 22 | + |
| 23 | +[1]: https://llvm.org/bugs/show_bug.cgi?id=26365 |
| 24 | +--- |
| 25 | + include/llvm/Support/ThreadPool.h | 4 +++ |
| 26 | + include/llvm/Support/thread.h | 4 +++ |
| 27 | + lib/CodeGen/ParallelCG.cpp | 63 +-------------------------------------- |
| 28 | + lib/Support/ThreadPool.cpp | 4 +++ |
| 29 | + 4 files changed, 13 insertions(+), 62 deletions(-) |
| 30 | + |
| 31 | +diff --git a/include/llvm/Support/ThreadPool.h b/include/llvm/Support/ThreadPool.h |
| 32 | +index 745334d..4564615 100644 |
| 33 | +--- a/include/llvm/Support/ThreadPool.h |
| 34 | ++++ b/include/llvm/Support/ThreadPool.h |
| 35 | +@@ -11,6 +11,8 @@ |
| 36 | + // |
| 37 | + //===----------------------------------------------------------------------===// |
| 38 | + |
| 39 | ++#if 0 |
| 40 | ++ |
| 41 | + #ifndef LLVM_SUPPORT_THREAD_POOL_H |
| 42 | + #define LLVM_SUPPORT_THREAD_POOL_H |
| 43 | + |
| 44 | +@@ -134,3 +136,5 @@ class ThreadPool { |
| 45 | + } |
| 46 | + |
| 47 | + #endif // LLVM_SUPPORT_THREAD_POOL_H |
| 48 | ++ |
| 49 | ++#endif |
| 50 | +diff --git a/include/llvm/Support/thread.h b/include/llvm/Support/thread.h |
| 51 | +index 2d13041..80340e6 100644 |
| 52 | +--- a/include/llvm/Support/thread.h |
| 53 | ++++ b/include/llvm/Support/thread.h |
| 54 | +@@ -14,6 +14,8 @@ |
| 55 | + // |
| 56 | + //===----------------------------------------------------------------------===// |
| 57 | + |
| 58 | ++#if 0 |
| 59 | ++ |
| 60 | + #ifndef LLVM_SUPPORT_THREAD_H |
| 61 | + #define LLVM_SUPPORT_THREAD_H |
| 62 | + |
| 63 | +@@ -64,3 +66,5 @@ struct thread { |
| 64 | + #endif // LLVM_ENABLE_THREADS |
| 65 | + |
| 66 | + #endif |
| 67 | ++ |
| 68 | ++#endif |
| 69 | +diff --git a/lib/CodeGen/ParallelCG.cpp b/lib/CodeGen/ParallelCG.cpp |
| 70 | +index e73ba02..7362cda 100644 |
| 71 | +--- a/lib/CodeGen/ParallelCG.cpp |
| 72 | ++++ b/lib/CodeGen/ParallelCG.cpp |
| 73 | +@@ -25,72 +25,11 @@ |
| 74 | + |
| 75 | + using namespace llvm; |
| 76 | + |
| 77 | +-static void codegen(Module *M, llvm::raw_pwrite_stream &OS, |
| 78 | +- const Target *TheTarget, StringRef CPU, StringRef Features, |
| 79 | +- const TargetOptions &Options, Reloc::Model RM, |
| 80 | +- CodeModel::Model CM, CodeGenOpt::Level OL, |
| 81 | +- TargetMachine::CodeGenFileType FileType) { |
| 82 | +- std::unique_ptr<TargetMachine> TM(TheTarget->createTargetMachine( |
| 83 | +- M->getTargetTriple(), CPU, Features, Options, RM, CM, OL)); |
| 84 | +- |
| 85 | +- legacy::PassManager CodeGenPasses; |
| 86 | +- if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType)) |
| 87 | +- report_fatal_error("Failed to setup codegen"); |
| 88 | +- CodeGenPasses.run(*M); |
| 89 | +-} |
| 90 | +- |
| 91 | + std::unique_ptr<Module> |
| 92 | + llvm::splitCodeGen(std::unique_ptr<Module> M, |
| 93 | + ArrayRef<llvm::raw_pwrite_stream *> OSs, StringRef CPU, |
| 94 | + StringRef Features, const TargetOptions &Options, |
| 95 | + Reloc::Model RM, CodeModel::Model CM, CodeGenOpt::Level OL, |
| 96 | + TargetMachine::CodeGenFileType FileType) { |
| 97 | +- StringRef TripleStr = M->getTargetTriple(); |
| 98 | +- std::string ErrMsg; |
| 99 | +- const Target *TheTarget = TargetRegistry::lookupTarget(TripleStr, ErrMsg); |
| 100 | +- if (!TheTarget) |
| 101 | +- report_fatal_error(Twine("Target not found: ") + ErrMsg); |
| 102 | +- |
| 103 | +- if (OSs.size() == 1) { |
| 104 | +- codegen(M.get(), *OSs[0], TheTarget, CPU, Features, Options, RM, CM, |
| 105 | +- OL, FileType); |
| 106 | +- return M; |
| 107 | +- } |
| 108 | +- |
| 109 | +- std::vector<thread> Threads; |
| 110 | +- SplitModule(std::move(M), OSs.size(), [&](std::unique_ptr<Module> MPart) { |
| 111 | +- // We want to clone the module in a new context to multi-thread the codegen. |
| 112 | +- // We do it by serializing partition modules to bitcode (while still on the |
| 113 | +- // main thread, in order to avoid data races) and spinning up new threads |
| 114 | +- // which deserialize the partitions into separate contexts. |
| 115 | +- // FIXME: Provide a more direct way to do this in LLVM. |
| 116 | +- SmallVector<char, 0> BC; |
| 117 | +- raw_svector_ostream BCOS(BC); |
| 118 | +- WriteBitcodeToFile(MPart.get(), BCOS); |
| 119 | +- |
| 120 | +- llvm::raw_pwrite_stream *ThreadOS = OSs[Threads.size()]; |
| 121 | +- Threads.emplace_back( |
| 122 | +- [TheTarget, CPU, Features, Options, RM, CM, OL, FileType, |
| 123 | +- ThreadOS](const SmallVector<char, 0> &BC) { |
| 124 | +- LLVMContext Ctx; |
| 125 | +- ErrorOr<std::unique_ptr<Module>> MOrErr = |
| 126 | +- parseBitcodeFile(MemoryBufferRef(StringRef(BC.data(), BC.size()), |
| 127 | +- "<split-module>"), |
| 128 | +- Ctx); |
| 129 | +- if (!MOrErr) |
| 130 | +- report_fatal_error("Failed to read bitcode"); |
| 131 | +- std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get()); |
| 132 | +- |
| 133 | +- codegen(MPartInCtx.get(), *ThreadOS, TheTarget, CPU, Features, |
| 134 | +- Options, RM, CM, OL, FileType); |
| 135 | +- }, |
| 136 | +- // Pass BC using std::move to ensure that it get moved rather than |
| 137 | +- // copied into the thread's context. |
| 138 | +- std::move(BC)); |
| 139 | +- }); |
| 140 | +- |
| 141 | +- for (thread &T : Threads) |
| 142 | +- T.join(); |
| 143 | +- |
| 144 | +- return {}; |
| 145 | ++ return M; |
| 146 | + } |
| 147 | +diff --git a/lib/Support/ThreadPool.cpp b/lib/Support/ThreadPool.cpp |
| 148 | +index d4dcb2e..bc25c59 100644 |
| 149 | +--- a/lib/Support/ThreadPool.cpp |
| 150 | ++++ b/lib/Support/ThreadPool.cpp |
| 151 | +@@ -11,6 +11,8 @@ |
| 152 | + // |
| 153 | + //===----------------------------------------------------------------------===// |
| 154 | + |
| 155 | ++#if 0 |
| 156 | ++ |
| 157 | + #include "llvm/Support/ThreadPool.h" |
| 158 | + |
| 159 | + #include "llvm/Config/llvm-config.h" |
| 160 | +@@ -153,3 +155,5 @@ ThreadPool::~ThreadPool() { |
| 161 | + } |
| 162 | + |
| 163 | + #endif |
| 164 | ++ |
| 165 | ++#endif |
| 166 | +diff --git a/unittests/Support/ThreadPool.cpp b/unittests/Support/ThreadPool.cpp |
| 167 | +index 0f36c38..32f4eab 100644 |
| 168 | +--- a/unittests/Support/ThreadPool.cpp |
| 169 | ++++ b/unittests/Support/ThreadPool.cpp |
| 170 | +@@ -7,6 +7,8 @@ |
| 171 | + // |
| 172 | + //===----------------------------------------------------------------------===// |
| 173 | + |
| 174 | ++#if 0 |
| 175 | ++ |
| 176 | + #include "llvm/Support/ThreadPool.h" |
| 177 | + |
| 178 | + #include "llvm/ADT/STLExtras.h" |
| 179 | +@@ -166,3 +168,5 @@ TEST_F(ThreadPoolTest, PoolDestruction) { |
| 180 | + } |
| 181 | + ASSERT_EQ(5, checked_in); |
| 182 | + } |
| 183 | ++ |
| 184 | ++#endif |
0 commit comments