[clang] [clang][CodeGen] Remove unnecessary ShouldLinkFiles conditional (PR #96951)

Jacob Lambert via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 27 11:55:27 PDT 2024


https://github.com/lamb-j created https://github.com/llvm/llvm-project/pull/96951

We have reworked the bitcode linking option to no longer link twice if post-optimization linking is requested. As such, we no longer need to conditionally link bitcodes supplied via -mlink-bitcode-file, as there is no danger of linking them twice

>From 08e0d825ca27e6a5718c28d1754787905bb872b5 Mon Sep 17 00:00:00 2001
From: Jacob Lambert <jacob.lambert at amd.com>
Date: Thu, 27 Jun 2024 11:50:28 -0700
Subject: [PATCH] [clang][CodeGen] Remove unnecessary ShouldLinkFiles
 conditional

We have reworked the bitcode linking option to no longer
link twice if post-optimization linking is requested. As such,
we no longer need to conditionally link bitcodes supplied via
-mlink-bitcode-file, as there is no danger of linking them twice
---
 clang/lib/CodeGen/BackendConsumer.h     | 2 +-
 clang/lib/CodeGen/BackendUtil.cpp       | 2 +-
 clang/lib/CodeGen/CodeGenAction.cpp     | 9 ++-------
 clang/lib/CodeGen/LinkInModulesPass.cpp | 7 +++----
 clang/lib/CodeGen/LinkInModulesPass.h   | 2 +-
 5 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/BackendConsumer.h b/clang/lib/CodeGen/BackendConsumer.h
index 0fe9929dca2b3..a648bd314e501 100644
--- a/clang/lib/CodeGen/BackendConsumer.h
+++ b/clang/lib/CodeGen/BackendConsumer.h
@@ -112,7 +112,7 @@ class BackendConsumer : public ASTConsumer {
   void HandleVTable(CXXRecordDecl *RD) override;
 
   // Links each entry in LinkModules into our module.  Returns true on error.
-  bool LinkInModules(llvm::Module *M, bool ShouldLinkFiles = true);
+  bool LinkInModules(llvm::Module *M);
 
   /// Get the best possible source location to represent a diagnostic that
   /// may have associated debug info.
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index b09680086248d..22b593e8f2b7a 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1035,7 +1035,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
 
   // Link against bitcodes supplied via the -mlink-builtin-bitcode option
   if (CodeGenOpts.LinkBitcodePostopt)
-    MPM.addPass(LinkInModulesPass(BC, false));
+    MPM.addPass(LinkInModulesPass(BC));
 
   // Add a verifier pass if requested. We don't have to do this if the action
   // requires code generation because there will already be a verifier pass in
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 7766383fdc890..0b92c5318a5c2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -226,16 +226,11 @@ void BackendConsumer::HandleInterestingDecl(DeclGroupRef D) {
     HandleTopLevelDecl(D);
 }
 
-// Links each entry in LinkModules into our module.  Returns true on error.
-bool BackendConsumer::LinkInModules(llvm::Module *M, bool ShouldLinkFiles) {
+// Links each entry in LinkModules into our module. Returns true on error.
+bool BackendConsumer::LinkInModules(llvm::Module *M) {
   for (auto &LM : LinkModules) {
     assert(LM.Module && "LinkModule does not actually have a module");
 
-    // If ShouldLinkFiles is not set, skip files added via the
-    // -mlink-bitcode-files, only linking -mlink-builtin-bitcode
-    if (!LM.Internalize && !ShouldLinkFiles)
-      continue;
-
     if (LM.PropagateAttrs)
       for (Function &F : *LM.Module) {
         // Skip intrinsics. Keep consistent with how intrinsics are created
diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp b/clang/lib/CodeGen/LinkInModulesPass.cpp
index c3831aae13b64..9dfcca53754a4 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.cpp
+++ b/clang/lib/CodeGen/LinkInModulesPass.cpp
@@ -20,15 +20,14 @@
 
 using namespace llvm;
 
-LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC,
-                                     bool ShouldLinkFiles)
-    : BC(BC), ShouldLinkFiles(ShouldLinkFiles) {}
+LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC) : BC(BC),
+  ShouldLinkFiles(ShouldLinkFiles) {}
 
 PreservedAnalyses LinkInModulesPass::run(Module &M, ModuleAnalysisManager &AM) {
   if (!BC)
     return PreservedAnalyses::all();
 
-  if (BC->LinkInModules(&M, ShouldLinkFiles))
+  if (BC->LinkInModules(&M))
     report_fatal_error("Bitcode module postopt linking failed, aborted!");
 
   return PreservedAnalyses::none();
diff --git a/clang/lib/CodeGen/LinkInModulesPass.h b/clang/lib/CodeGen/LinkInModulesPass.h
index 7fe94d6250583..a184cce184c03 100644
--- a/clang/lib/CodeGen/LinkInModulesPass.h
+++ b/clang/lib/CodeGen/LinkInModulesPass.h
@@ -31,7 +31,7 @@ class LinkInModulesPass : public PassInfoMixin<LinkInModulesPass> {
   bool ShouldLinkFiles;
 
 public:
-  LinkInModulesPass(clang::BackendConsumer *BC, bool ShouldLinkFiles = true);
+  LinkInModulesPass(clang::BackendConsumer *BC);
 
   PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
   static bool isRequired() { return true; }



More information about the cfe-commits mailing list