summaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp
diff options
context:
space:
mode:
authororivej <[email protected]>2022-02-10 16:44:49 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:49 +0300
commit718c552901d703c502ccbefdfc3c9028d608b947 (patch)
tree46534a98bbefcd7b1f3faa5b52c138ab27db75b7 /contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp
parente9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp')
-rw-r--r--contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp196
1 files changed, 98 insertions, 98 deletions
diff --git a/contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp b/contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp
index 849b667254b..072439c860a 100644
--- a/contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp
+++ b/contrib/libs/llvm12/lib/CodeGen/ParallelCG.cpp
@@ -1,100 +1,100 @@
-//===-- ParallelCG.cpp ----------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines functions that can be used for parallel code generation.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/CodeGen/ParallelCG.h"
-#include "llvm/Bitcode/BitcodeReader.h"
-#include "llvm/Bitcode/BitcodeWriter.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Support/ErrorOr.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/ThreadPool.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Utils/SplitModule.h"
-
-using namespace llvm;
-
-static void codegen(Module *M, llvm::raw_pwrite_stream &OS,
- function_ref<std::unique_ptr<TargetMachine>()> TMFactory,
- CodeGenFileType FileType) {
- std::unique_ptr<TargetMachine> TM = TMFactory();
+//===-- ParallelCG.cpp ----------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines functions that can be used for parallel code generation.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/ParallelCG.h"
+#include "llvm/Bitcode/BitcodeReader.h"
+#include "llvm/Bitcode/BitcodeWriter.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/ThreadPool.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Utils/SplitModule.h"
+
+using namespace llvm;
+
+static void codegen(Module *M, llvm::raw_pwrite_stream &OS,
+ function_ref<std::unique_ptr<TargetMachine>()> TMFactory,
+ CodeGenFileType FileType) {
+ std::unique_ptr<TargetMachine> TM = TMFactory();
assert(TM && "Failed to create target machine!");
- legacy::PassManager CodeGenPasses;
- if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, FileType))
- report_fatal_error("Failed to setup codegen");
- CodeGenPasses.run(*M);
-}
-
-std::unique_ptr<Module> llvm::splitCodeGen(
- std::unique_ptr<Module> M, ArrayRef<llvm::raw_pwrite_stream *> OSs,
- ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
- const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
- CodeGenFileType FileType, bool PreserveLocals) {
- assert(BCOSs.empty() || BCOSs.size() == OSs.size());
-
- if (OSs.size() == 1) {
- if (!BCOSs.empty())
- WriteBitcodeToFile(*M, *BCOSs[0]);
- codegen(M.get(), *OSs[0], TMFactory, FileType);
- return M;
- }
-
- // Create ThreadPool in nested scope so that threads will be joined
- // on destruction.
- {
- ThreadPool CodegenThreadPool(hardware_concurrency(OSs.size()));
- int ThreadCount = 0;
-
- SplitModule(
- std::move(M), OSs.size(),
- [&](std::unique_ptr<Module> MPart) {
- // We want to clone the module in a new context to multi-thread the
- // codegen. We do it by serializing partition modules to bitcode
- // (while still on the main thread, in order to avoid data races) and
- // spinning up new threads which deserialize the partitions into
- // separate contexts.
- // FIXME: Provide a more direct way to do this in LLVM.
- SmallString<0> BC;
- raw_svector_ostream BCOS(BC);
- WriteBitcodeToFile(*MPart, BCOS);
-
- if (!BCOSs.empty()) {
- BCOSs[ThreadCount]->write(BC.begin(), BC.size());
- BCOSs[ThreadCount]->flush();
- }
-
- llvm::raw_pwrite_stream *ThreadOS = OSs[ThreadCount++];
- // Enqueue the task
- CodegenThreadPool.async(
- [TMFactory, FileType, ThreadOS](const SmallString<0> &BC) {
- LLVMContext Ctx;
- Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
- MemoryBufferRef(StringRef(BC.data(), BC.size()),
- "<split-module>"),
- Ctx);
- if (!MOrErr)
- report_fatal_error("Failed to read bitcode");
- std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
-
- codegen(MPartInCtx.get(), *ThreadOS, TMFactory, FileType);
- },
- // Pass BC using std::move to ensure that it get moved rather than
- // copied into the thread's context.
- std::move(BC));
- },
- PreserveLocals);
- }
-
- return {};
-}
+ legacy::PassManager CodeGenPasses;
+ if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, FileType))
+ report_fatal_error("Failed to setup codegen");
+ CodeGenPasses.run(*M);
+}
+
+std::unique_ptr<Module> llvm::splitCodeGen(
+ std::unique_ptr<Module> M, ArrayRef<llvm::raw_pwrite_stream *> OSs,
+ ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
+ const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
+ CodeGenFileType FileType, bool PreserveLocals) {
+ assert(BCOSs.empty() || BCOSs.size() == OSs.size());
+
+ if (OSs.size() == 1) {
+ if (!BCOSs.empty())
+ WriteBitcodeToFile(*M, *BCOSs[0]);
+ codegen(M.get(), *OSs[0], TMFactory, FileType);
+ return M;
+ }
+
+ // Create ThreadPool in nested scope so that threads will be joined
+ // on destruction.
+ {
+ ThreadPool CodegenThreadPool(hardware_concurrency(OSs.size()));
+ int ThreadCount = 0;
+
+ SplitModule(
+ std::move(M), OSs.size(),
+ [&](std::unique_ptr<Module> MPart) {
+ // We want to clone the module in a new context to multi-thread the
+ // codegen. We do it by serializing partition modules to bitcode
+ // (while still on the main thread, in order to avoid data races) and
+ // spinning up new threads which deserialize the partitions into
+ // separate contexts.
+ // FIXME: Provide a more direct way to do this in LLVM.
+ SmallString<0> BC;
+ raw_svector_ostream BCOS(BC);
+ WriteBitcodeToFile(*MPart, BCOS);
+
+ if (!BCOSs.empty()) {
+ BCOSs[ThreadCount]->write(BC.begin(), BC.size());
+ BCOSs[ThreadCount]->flush();
+ }
+
+ llvm::raw_pwrite_stream *ThreadOS = OSs[ThreadCount++];
+ // Enqueue the task
+ CodegenThreadPool.async(
+ [TMFactory, FileType, ThreadOS](const SmallString<0> &BC) {
+ LLVMContext Ctx;
+ Expected<std::unique_ptr<Module>> MOrErr = parseBitcodeFile(
+ MemoryBufferRef(StringRef(BC.data(), BC.size()),
+ "<split-module>"),
+ Ctx);
+ if (!MOrErr)
+ report_fatal_error("Failed to read bitcode");
+ std::unique_ptr<Module> MPartInCtx = std::move(MOrErr.get());
+
+ codegen(MPartInCtx.get(), *ThreadOS, TMFactory, FileType);
+ },
+ // Pass BC using std::move to ensure that it get moved rather than
+ // copied into the thread's context.
+ std::move(BC));
+ },
+ PreserveLocals);
+ }
+
+ return {};
+}