[llvm] [NFC][CodeGen] Remove dead ParallelCG.h/.cpp API (PR #95770)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 04:54:16 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lto

Author: Pierre van Houtryve (Pierre-vh)

<details>
<summary>Changes</summary>

LTOCodeGenerator inlined it a while ago and now uses a static copy. This API was unused.

We can always restore it at some point if it's needed, but right now it's just bloat.

---
Full diff: https://github.com/llvm/llvm-project/pull/95770.diff


5 Files Affected:

- (removed) llvm/include/llvm/CodeGen/ParallelCG.h (-44) 
- (modified) llvm/lib/CodeGen/CMakeLists.txt (-1) 
- (removed) llvm/lib/CodeGen/ParallelCG.cpp (-95) 
- (modified) llvm/lib/LTO/LTOCodeGenerator.cpp (-1) 
- (modified) llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn (-1) 


``````````diff
diff --git a/llvm/include/llvm/CodeGen/ParallelCG.h b/llvm/include/llvm/CodeGen/ParallelCG.h
deleted file mode 100644
index fc50dc1442541..0000000000000
--- a/llvm/include/llvm/CodeGen/ParallelCG.h
+++ /dev/null
@@ -1,44 +0,0 @@
-//===-- llvm/CodeGen/ParallelCG.h - Parallel code generation ----*- C++ -*-===//
-//
-// 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 header declares functions that can be used for parallel code generation.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CODEGEN_PARALLELCG_H
-#define LLVM_CODEGEN_PARALLELCG_H
-
-#include "llvm/Support/CodeGen.h"
-#include <functional>
-#include <memory>
-
-namespace llvm {
-
-template <typename T> class ArrayRef;
-class Module;
-class TargetMachine;
-class raw_pwrite_stream;
-
-/// Split M into OSs.size() partitions, and generate code for each. Takes a
-/// factory function for the TargetMachine TMFactory. Writes OSs.size() output
-/// files to the output streams in OSs. The resulting output files if linked
-/// together are intended to be equivalent to the single output file that would
-/// have been code generated from M.
-///
-/// Writes bitcode for individual partitions into output streams in BCOSs, if
-/// BCOSs is not empty.
-void splitCodeGen(
-    Module &M, ArrayRef<raw_pwrite_stream *> OSs,
-    ArrayRef<llvm::raw_pwrite_stream *> BCOSs,
-    const std::function<std::unique_ptr<TargetMachine>()> &TMFactory,
-    CodeGenFileType FileType = CodeGenFileType::ObjectFile,
-    bool PreserveLocals = false);
-
-} // namespace llvm
-
-#endif
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 1f5556ed2349e..41fc555c93e93 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -163,7 +163,6 @@ add_llvm_component_library(LLVMCodeGen
   MacroFusion.cpp
   NonRelocatableStringpool.cpp
   OptimizePHIs.cpp
-  ParallelCG.cpp
   PeepholeOptimizer.cpp
   PHIElimination.cpp
   PHIEliminationUtils.cpp
diff --git a/llvm/lib/CodeGen/ParallelCG.cpp b/llvm/lib/CodeGen/ParallelCG.cpp
deleted file mode 100644
index 8ab64f8afe6ec..0000000000000
--- a/llvm/lib/CodeGen/ParallelCG.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-//===-- 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/MemoryBufferRef.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);
-}
-
-void llvm::splitCodeGen(
-    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, *OSs[0], TMFactory, FileType);
-    return;
-  }
-
-  // Create ThreadPool in nested scope so that threads will be joined
-  // on destruction.
-  {
-    DefaultThreadPool CodegenThreadPool(hardware_concurrency(OSs.size()));
-    int ThreadCount = 0;
-
-    SplitModule(
-        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(BC.str(), "<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);
-  }
-}
diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp
index 0611099c4690d..34aacb660144f 100644
--- a/llvm/lib/LTO/LTOCodeGenerator.cpp
+++ b/llvm/lib/LTO/LTOCodeGenerator.cpp
@@ -20,7 +20,6 @@
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Bitcode/BitcodeWriter.h"
 #include "llvm/CodeGen/CommandFlags.h"
-#include "llvm/CodeGen/ParallelCG.h"
 #include "llvm/CodeGen/TargetSubtargetInfo.h"
 #include "llvm/Config/config.h"
 #include "llvm/IR/Constants.h"
diff --git a/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
index 9068fa2577a42..b3882fe4d6b76 100644
--- a/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
@@ -170,7 +170,6 @@ static_library("CodeGen") {
     "OptimizePHIs.cpp",
     "PHIElimination.cpp",
     "PHIEliminationUtils.cpp",
-    "ParallelCG.cpp",
     "PatchableFunction.cpp",
     "PeepholeOptimizer.cpp",
     "PostRAHazardRecognizer.cpp",

``````````

</details>


https://github.com/llvm/llvm-project/pull/95770


More information about the llvm-commits mailing list