[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
lamb-j wrote: https://github.com/llvm/llvm-project/pull/91495 Follow up PR to fix warning with now-unused private variable in BackendConsumer class (FileMgr) https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j closed https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/yxsamliu approved this pull request. https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/jhuber6 approved this pull request. Hopefully in the future we can handle this in the linker better. https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
b-sumner wrote: Looks good to me. https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/7] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/7] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j edited https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
lamb-j wrote: Switched the option from a cl::opt to a Clang/CodeGen option. Also added a LIT test which tests both -mlink-builtin-bitcode-postopt and -mno-link-builtin-bitcode-postopt https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/6] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/6] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/5] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/5] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
b-sumner wrote: > > I'm thinking of an option that developers can use. If > > -link-builtin-bitcodes-postopt, becomes the default, how can developers > > disable it? > > Presumably you'd add `--no-link-builtin-bitcodes-postopt` and then use > `Args.hasFlag(PosFlag, NegFlag, Default)`. I assume I'd need an -Xclang or -Wl, in front? And it would need some test coverage. https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
jhuber6 wrote: > > Currently if a user doesn't supply the new "-link-builtin-bitcodes-postopt" > > option, linking builtin bitcodes happens first, then the optimization > > pipeline follows. Does that cover the case you're talking about? > > I'm thinking of an option that developers can use. If > -link-builtin-bitcodes-postopt, becomes the default, how can developers > disable it? Presumably you'd add `--no-link-builtin-bitcodes-postopt`. https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
b-sumner wrote: > Currently if a user doesn't supply the new "-link-builtin-bitcodes-postopt" > option, linking builtin bitcodes happens first, then the optimization > pipeline follows. Does that cover the case you're talking about? I'm thinking of an option that developers can use. If -link-builtin-bitcodes-postopt, becomes the default, how can developers disable it? https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
lamb-j wrote: > @lamb-j I appreciate your carrying out these performance tests! > > Would you be open to providing an option to enable post-link optimization > that could be off by default for now? Currently if a user doesn't supply the new "-link-builtin-bitcodes-postopt" option, linking builtin bitcodes happens first, then the optimization pipeline follows. Does that cover the case you're talking about? https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
b-sumner wrote: @lamb-j I appreciate your carrying out these performance tests! Would you be open to providing an option to enable post-link optimization that could be off by default for now? https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
lamb-j wrote: I've been working on testing this patch with an array of OpenCL benchmarks over the past month. We did some high-level regression testing with the following benchmarks: BlackMagic Linpack_Dgemm babelstream-Double babelstream-Float chimex clfft clmem clpeak-Double-precision compute clpeak-Global memory bandwidth clpeak-Integer compute clpeak-Single-precision compute clpeak-Transfer bandwidth computeApps dgemm_linux fahbench flopscl ge-workspace ge_rdppenality indigo-benchmark lattice luxmark luxmark4 mixbench-ocl-ro ocltst shoc silentarmy viennacl With apps, we didn't see any significant regressions. I also did some in-depth testing with FAHbench and Chimex: **FAHBench** Current: Final score: 216.8422, 218.2792, 218.3647 Scaled score: 216.8422 (23558 atoms) App Runtime: 1m42.181s, 1m42.185s, 1m42.167s Compilation time: 3226 ms With this PR: Final score: 222.3547, 219.8134, 223.3722 Scaled score: 222.3547 (23558 atoms) App Runtime: 1m40.852s, 1m40.850s, 1m40.849s Compilation time: 1822 ms Between the two builds, the total runtime difference is ~1.3 seconds, and the difference in compilation is also ~1.3 seconds. So it does seem to support that we're only removing overhead with this PR, not introducing regressions. I also looked into the intermediate files. If we dump the two final .so files, they're nearly identical, with only a few lines differing. **Chimex** Current: Correlation matrices computation time: 2.3876s on GPU [Theoretical max: @13.9 TFLOPS, 1659.3 kHz; 83% efficiency] [Algorithm max: @13.9 TFLOPS, 1634.6 kHz; 84% efficiency] Compilation Time: 742 ms With this PR: Correlation matrices computation time: 1.9782s on GPU [Theoretical max: @13.9 TFLOPS, 1659.3 kHz; 100% efficiency] [Algorithm max: @13.9 TFLOPS, 1634.6 kHz; 101% efficiency] Compilation Time: 551 ms https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/5] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/5] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
@@ -28,12 +28,8 @@ PreservedAnalyses LinkInModulesPass::run(Module , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) -report_fatal_error("Bitcode module re-linking failed, aborted!"); +report_fatal_error("Bitcode module postopt linking failed, aborted!"); - return PreservedAnalyses::all(); lamb-j wrote: This should fix the issue: LLVM ERROR: Function @_Z6sincosfPU3AS5f changed by LinkInModulesPass without invalidating analyses https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
jhuber6 wrote: This means that there won't be any optimizations on these definitions, correct? Likely not ideal to have no inlining even if it saves compilation time. This "post-op" linking is only required because we emit calls to functions that don't exist in the module. The way we solved this in OpenMP is by always providing the library at the link step and making the optimization passes not emit new calls if we are in "post-link LTO" as determined by module flags. We could theoretically just force all AMDGPU compilation to go through the LTO pass, something like `ld.lld --start-lib ockl.bc ocml.bc --end-lib`. That would have the effect of fixing-up any missing definitions as it will only extract if needed. Problem is that the device libs have protected visibility until the next release cycle so this won't actually internalize. https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/4] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/4] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/3] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/3] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
b-sumner wrote: This seems like it could have a significant hit on performance. Have the runtime performance effects been measured? https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
https://github.com/lamb-j updated https://github.com/llvm/llvm-project/pull/85672 >From aff1a762a73ce30cde38a6fcbbed8a3e4f0b5366 Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:19:38 -0700 Subject: [PATCH 1/2] [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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); >From 9a6757c9497019dbc2c9c0d449c0d1cbc70c98fd Mon Sep 17 00:00:00 2001 From: Jacob Lambert Date: Mon, 18 Mar 2024 10:47:25 -0700 Subject: [PATCH 2/2] fix option name --- clang/lib/CodeGen/CodeGenAction.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index 51f54d178672d1..a3ff5dc7d29e99 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) + if (!ClLinkBuiltinBitcodePostopt && LinkInModules(getModule())) return; for (auto : getModule()->functions()) { @@ -1213,7 +1213,7 @@ void CodeGenAction::ExecuteAction() { std::move(LinkModules), *VMContext, nullptr); // Link in each pending link module. - if (!LinkBuiltinBitcodesPostopt && Result.LinkInModules(&*TheModule)) + if
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Jacob Lambert (lamb-j) Changes 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 --- Full diff: https://github.com/llvm/llvm-project/pull/85672.diff 3 Files Affected: - (modified) clang/lib/CodeGen/BackendUtil.cpp (+5-8) - (modified) clang/lib/CodeGen/CodeGenAction.cpp (+3-3) - (modified) clang/lib/CodeGen/LinkInModulesPass.cpp (-4) ``diff 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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, ShouldLinkFiles)) report_fatal_error("Bitcode module re-linking failed, aborted!"); `` https://github.com/llvm/llvm-project/pull/85672 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][CodeGen] Omit pre-opt link when post-opt is link requested (PR #85672)
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 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 ClSanitizeOnOptimizerEarlyEP( extern cl::opt ProfileCorrelate; // Re-link builtin bitcodes after optimization -cl::opt ClRelinkBuiltinBitcodePostop( -"relink-builtin-bitcode-postop", cl::Optional, -cl::desc("Re-link builtin bitcodes after optimization."), cl::init(false)); +cl::opt 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 ClRelinkBuiltinBitcodePostop; +extern cl::opt ClLinkBuiltinBitcodePostopt; } namespace clang { @@ -359,7 +359,7 @@ void BackendConsumer::HandleTranslationUnit(ASTContext ) { } // Link each LinkModule into our module. - if (LinkInModules(getModule())) + if (!LinkBuiltinBitcodesPostopt && LinkInModules(getModule())) return; for (auto : 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 , ModuleAnalysisManager ) { if (!BC) return PreservedAnalyses::all(); - // Re-load bitcode modules from files - if (BC->ReloadModules()) -report_fatal_error("Bitcode module re-loading failed, aborted!"); - if (BC->LinkInModules(, 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