[lld] ELF: Add branch-to-branch optimization. (PR #138366)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 2 17:00:01 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- lld/ELF/Arch/TargetImpl.h lld/ELF/Arch/AArch64.cpp lld/ELF/Arch/X86_64.cpp lld/ELF/Config.h lld/ELF/Driver.cpp lld/ELF/Relocations.cpp lld/ELF/Target.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/lld/ELF/Arch/TargetImpl.h b/lld/ELF/Arch/TargetImpl.h
index bb1074951..1b2eb3108 100644
--- a/lld/ELF/Arch/TargetImpl.h
+++ b/lld/ELF/Arch/TargetImpl.h
@@ -43,8 +43,9 @@ inline void applyBranchToBranchOptImpl(
// reading relocations of other sections.
for (ELFFileBase *f : ctx.objectFiles) {
auto getRelocBranchInfo =
- [&ctx, &getBranchInfo](Relocation &r,
- uint64_t addend) -> std::pair<Relocation *, uint64_t> {
+ [&ctx,
+ &getBranchInfo](Relocation &r,
+ uint64_t addend) -> std::pair<Relocation *, uint64_t> {
auto *target = dyn_cast_or_null<Defined>(r.sym);
// We don't allow preemptible symbols (may go somewhere else),
// absolute symbols (runtime behavior unknown), non-executable memory
@@ -54,21 +55,21 @@ inline void applyBranchToBranchOptImpl(
target->section->kind() != SectionBase::Regular)
return {nullptr, 0};
return getBranchInfo(*cast<InputSection>(target->section),
- target->value + addend);
+ target->value + addend);
};
for (InputSectionBase *s : f->getSections()) {
if (!s)
continue;
for (Relocation &r : s->relocations) {
if (std::optional<uint64_t> addend =
- getControlTransferAddend(*cast<InputSection>(s),
- r)) {
+ getControlTransferAddend(*cast<InputSection>(s), r)) {
std::pair<Relocation *, uint64_t> targetAndAddend =
getRelocBranchInfo(r, *addend);
if (targetAndAddend.first) {
while (1) {
std::pair<Relocation *, uint64_t> nextTargetAndAddend =
- getRelocBranchInfo(*targetAndAddend.first, targetAndAddend.second);
+ getRelocBranchInfo(*targetAndAddend.first,
+ targetAndAddend.second);
if (!nextTargetAndAddend.first)
break;
targetAndAddend = nextTargetAndAddend;
``````````
</details>
https://github.com/llvm/llvm-project/pull/138366
More information about the llvm-commits
mailing list