llvm-project/clang/lib/CodeGen/LinkInModulesPass.cpp
Jacob Lambert 11a6799740
[clang][CodeGen] Omit pre-opt link when post-opt is link requested (#85672)
Currently, when the -relink-builtin-bitcodes-postop option is used we
link builtin bitcodes twice: once before optimization, and again after
optimization.

With this change, we omit the pre-opt linking when the option is set,
and we rename the option to the following:

  -Xclang -mlink-builtin-bitcodes-postopt
 (-Xclang -mno-link-builtin-bitcodes-postopt) 

The goal of this change is to reduce compile time. We do lose the
theoretical benefits of pre-opt linking, but in practice these are small
than the overhead of linking twice. However we may be able to address
this in a future patch by adjusting the position of the builtin-bitcode
linking pass.

Compilations not setting the option are unaffected
2024-05-08 08:11:15 -07:00

36 lines
1.1 KiB
C++

//===-- LinkInModulesPass.cpp - Module Linking pass --------------- 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
//
//===----------------------------------------------------------------------===//
/// \file
///
/// LinkInModulesPass implementation.
///
//===----------------------------------------------------------------------===//
#include "LinkInModulesPass.h"
#include "BackendConsumer.h"
#include "clang/Basic/CodeGenOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
using namespace llvm;
LinkInModulesPass::LinkInModulesPass(clang::BackendConsumer *BC,
bool ShouldLinkFiles)
: BC(BC), ShouldLinkFiles(ShouldLinkFiles) {}
PreservedAnalyses LinkInModulesPass::run(Module &M, ModuleAnalysisManager &AM) {
if (!BC)
return PreservedAnalyses::all();
if (BC->LinkInModules(&M, ShouldLinkFiles))
report_fatal_error("Bitcode module postopt linking failed, aborted!");
return PreservedAnalyses::none();
}