https://github.com/lamb-j created https://github.com/llvm/llvm-project/pull/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: -link-builtin-bitcodes-postopt The goal of this change is to reduce compile time. We do lose the benefits of pre-opt linking, but 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 relink (link) option are unaffected >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert <jacob.lamb...@amd.com> Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH] [clang][CodeGen] Omit pre-opt link when post-opt link requested 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: -link-builtin-bitcodes-postopt --- clang/lib/CodeGen/BackendUtil.cpp | 13 +++++-------- clang/lib/CodeGen/CodeGenAction.cpp | 6 +++--- clang/lib/CodeGen/LinkInModulesPass.cpp | 4 ---- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 82b30b8d815629..c5571eb15ce3a9 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -112,9 +112,9 @@ static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP( extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt<bool> ClRelinkBuiltinBitcodePostop( - "relink-builtin-bitcode-postop", cl::Optional, - cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt<bool> ClLinkBuiltinBitcodePostopt( + "link-builtin-bitcode-postopt", cl::Optional, + cl::desc("Link builtin bitcodes after optimization."), cl::init(false)); } // namespace llvm namespace { @@ -1051,11 +1051,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( } } - // Re-link against any bitcodes supplied via the -mlink-builtin-bitcode option - // Some optimizations may generate new function calls that would not have - // been linked pre-optimization (i.e. fused sincos calls generated by - // AMDGPULibCalls::fold_sincos.) - if (ClRelinkBuiltinBitcodePostop) + // Link against bitcodes supplied via the -mlink-builtin-bitcode option + if (ClLinkBuiltinBitcodePostopt) MPM.addPass(LinkInModulesPass(BC, false)); // Add a verifier pass if requested. We don't have to do this if the action diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index bb9aaba025fa59..51f54d178672d1 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -58,7 +58,7 @@ using namespace llvm; #define DEBUG_TYPE "codegenaction" namespace llvm { -extern cl::opt<bool> ClRelinkBuiltinBitcodePostop; +extern cl::opt<bool> ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext &C) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto &F : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (Result.LinkInModules(&*TheModule)) + if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) return; // PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be diff --git a/clang/lib/CodeGen/LinkInModulesPass.cpp b/clang/lib/CodeGen/LinkInModulesPass.cpp index 929539cc8f3346..ce1c0ebe046a61 100644 --- a/clang/lib/CodeGen/LinkInModulesPass.cpp +++ b/clang/lib/CodeGen/LinkInModulesPass.cpp @@ -28,10 +28,6 @@ PreservedAnalyses LinkInModulesPass::run(Module &M, ModuleAnalysisManager &AM) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules(&M)) - report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(&M, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits