Skip to content

Commit 2264544

Browse files
authored
[clang][CodeGen] Remove unnecessary ShouldLinkFiles conditional (#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
1 parent d70963a commit 2264544

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

clang/lib/CodeGen/BackendConsumer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class BackendConsumer : public ASTConsumer {
112112
void HandleVTable(CXXRecordDecl *RD) override;
113113

114114
// Links each entry in LinkModules into our module. Returns true on error.
115-
bool LinkInModules(llvm::Module *M, bool ShouldLinkFiles = true);
115+
bool LinkInModules(llvm::Module *M);
116116

117117
/// Get the best possible source location to represent a diagnostic that
118118
/// may have associated debug info.

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
10351035

10361036
// Link against bitcodes supplied via the -mlink-builtin-bitcode option
10371037
if (CodeGenOpts.LinkBitcodePostopt)
1038-
MPM.addPass(LinkInModulesPass(BC, false));
1038+
MPM.addPass(LinkInModulesPass(BC));
10391039

10401040
// Add a verifier pass if requested. We don't have to do this if the action
10411041
// requires code generation because there will already be a verifier pass in

clang/lib/CodeGen/CodeGenAction.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,11 @@ void BackendConsumer::HandleInterestingDecl(DeclGroupRef D) {
226226
HandleTopLevelDecl(D);
227227
}
228228

229-
// Links each entry in LinkModules into our module. Returns true on error.
230-
bool BackendConsumer::LinkInModules(llvm::Module *M, bool ShouldLinkFiles) {
229+
// Links each entry in LinkModules into our module. Returns true on error.
230+
bool BackendConsumer::LinkInModules(llvm::Module *M) {
231231
for (auto &LM : LinkModules) {
232232
assert(LM.Module && "LinkModule does not actually have a module");
233233

234-
// If ShouldLinkFiles is not set, skip files added via the
235-
// -mlink-bitcode-files, only linking -mlink-builtin-bitcode
236-
if (!LM.Internalize && !ShouldLinkFiles)
237-
continue;
238-
239234
if (LM.PropagateAttrs)
240235
for (Function &F : *LM.Module) {
241236
// Skip intrinsics. Keep consistent with how intrinsics are created

clang/lib/CodeGen/LinkInModulesPass.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020

2121
using namespace llvm;
2222

23-
LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC,
24-
bool ShouldLinkFiles)
25-
: BC(BC), ShouldLinkFiles(ShouldLinkFiles) {}
23+
LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC) : BC(BC),
24+
ShouldLinkFiles(ShouldLinkFiles) {}
2625

2726
PreservedAnalyses LinkInModulesPass::run(Module &M, ModuleAnalysisManager &AM) {
2827
if (!BC)
2928
return PreservedAnalyses::all();
3029

31-
if (BC->LinkInModules(&M, ShouldLinkFiles))
30+
if (BC->LinkInModules(&M))
3231
report_fatal_error("Bitcode module postopt linking failed, aborted!");
3332

3433
return PreservedAnalyses::none();

clang/lib/CodeGen/LinkInModulesPass.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LinkInModulesPass : public PassInfoMixin<LinkInModulesPass> {
3131
bool ShouldLinkFiles;
3232

3333
public:
34-
LinkInModulesPass(clang::BackendConsumer *BC, bool ShouldLinkFiles = true);
34+
LinkInModulesPass(clang::BackendConsumer *BC);
3535

3636
PreservedAnalyses run(Module &M, AnalysisManager<Module> &);
3737
static bool isRequired() { return true; }

0 commit comments

Comments
 (0)