diff options
author | Jacob Lambert <jacob.lambert@amd.com> | 2024-05-08 08:11:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-08 08:11:15 -0700 |
commit | 11a6799740f824282650aa9ec249b55dcf1a8aae (patch) | |
tree | ba98ea6788f43caba374861f931275e30763be08 /clang/lib/CodeGen/CodeGenAction.cpp | |
parent | 50b45b24220ead33cf5cedc49c13e0336297e4eb (diff) | |
download | llvm-11a6799740f824282650aa9ec249b55dcf1a8aae.zip llvm-11a6799740f824282650aa9ec249b55dcf1a8aae.tar.gz llvm-11a6799740f824282650aa9ec249b55dcf1a8aae.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenAction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 1a6b628..0255f05 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -60,10 +60,6 @@ using namespace llvm; #define DEBUG_TYPE "codegenaction" -namespace llvm { -extern cl::opt<bool> ClRelinkBuiltinBitcodePostop; -} - namespace clang { class BackendConsumer; class ClangDiagnosticHandler final : public DiagnosticHandler { @@ -232,35 +228,6 @@ void BackendConsumer::HandleInterestingDecl(DeclGroupRef D) { HandleTopLevelDecl(D); } -bool BackendConsumer::ReloadModules(llvm::Module *M) { - for (const CodeGenOptions::BitcodeFileToLink &F : - CodeGenOpts.LinkBitcodeFiles) { - auto BCBuf = FileMgr.getBufferForFile(F.Filename); - if (!BCBuf) { - Diags.Report(diag::err_cannot_open_file) - << F.Filename << BCBuf.getError().message(); - LinkModules.clear(); - return true; - } - - LLVMContext &Ctx = getModule()->getContext(); - Expected<std::unique_ptr<llvm::Module>> ModuleOrErr = - getOwningLazyBitcodeModule(std::move(*BCBuf), Ctx); - - if (!ModuleOrErr) { - handleAllErrors(ModuleOrErr.takeError(), [&](ErrorInfoBase &EIB) { - Diags.Report(diag::err_cannot_open_file) << F.Filename << EIB.message(); - }); - LinkModules.clear(); - return true; - } - LinkModules.push_back({std::move(ModuleOrErr.get()), F.PropagateAttrs, - F.Internalize, F.LinkFlags}); - } - - return false; // success -} - // Links each entry in LinkModules into our module. Returns true on error. bool BackendConsumer::LinkInModules(llvm::Module *M, bool ShouldLinkFiles) { for (auto &LM : LinkModules) { @@ -362,7 +329,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext &C) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!CodeGenOpts.LinkBitcodePostopt && LinkInModules(getModule())) return; for (auto &F : getModule()->functions()) { @@ -1232,7 +1199,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (Result.LinkInModules(&*TheModule)) + if (!CodeGenOpts.LinkBitcodePostopt && Result.LinkInModules(&*TheModule)) return; // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be |