Skip to content

[NFC][CodeGen] Remove dead ParallelCG.h/.cpp API #95770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

Pierre-vh
Copy link
Contributor

@Pierre-vh Pierre-vh commented Jun 17, 2024

LTOBackend 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.

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.
@Pierre-vh Pierre-vh requested a review from teresajohnson June 17, 2024 11:53
@llvmbot llvmbot added the LTO Link time optimization (regular/full LTO or ThinLTO) label Jun 17, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 17, 2024

@llvm/pr-subscribers-lto

Author: Pierre van Houtryve (Pierre-vh)

Changes

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 --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",

Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but please correct the summary. Looks like it is LTOBackend.cpp that has the static copy, not LTOCodeGenerator.cpp

@Pierre-vh Pierre-vh merged commit cb20d4d into llvm:main Jun 19, 2024
6 of 9 checks passed
@Pierre-vh Pierre-vh deleted the remove-dead-parallelcg branch June 19, 2024 07:07
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
LTOBackend 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants