[llvm] [BOLT][AArch64] Preserve external branches to non-function symbols (PR #227275)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 04:21:38 PDT 2026


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 origin/main HEAD --extensions cpp,h -- bolt/include/bolt/Core/BinaryFunction.h bolt/include/bolt/Core/BinarySection.h bolt/include/bolt/Core/MCPlus.h bolt/include/bolt/Core/MCPlusBuilder.h bolt/include/bolt/Core/Relocation.h bolt/lib/Core/BinaryFunction.cpp bolt/lib/Core/BinaryFunctionProfile.cpp bolt/lib/Core/MCPlusBuilder.cpp bolt/lib/Passes/Inliner.cpp bolt/lib/Passes/LongJmp.cpp bolt/lib/Profile/DataReader.cpp bolt/lib/Profile/StaleProfileMatching.cpp bolt/lib/Profile/YAMLProfileReader.cpp bolt/lib/Profile/YAMLProfileWriter.cpp bolt/lib/Rewrite/RewriteInstance.cpp bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/bolt/include/bolt/Core/Relocation.h b/bolt/include/bolt/Core/Relocation.h
index 9b0aedb15..e2aee21ea 100644
--- a/bolt/include/bolt/Core/Relocation.h
+++ b/bolt/include/bolt/Core/Relocation.h
@@ -46,7 +46,8 @@ public:
              uint32_t JmpRelocationIndex = NoJmpRelocationIndex)
       : Offset(Offset), Symbol(Symbol), Addend(Addend), Value(Value),
         Type(Type), ELFSymType(ELFSymType),
-        JmpRelocationIndex(JmpRelocationIndex), Optional(false), IsRELR(IsRELR) {
+        JmpRelocationIndex(JmpRelocationIndex), Optional(false),
+        IsRELR(IsRELR) {
     assert((isRelative() || !isRELR()) &&
            "Only relative relocations can be relr.");
   }
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index 24306dc40..625bfab71 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -2378,8 +2378,7 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
           !MIB->isIndirectBranch(*PrevInstr) &&
           !MIB->isUnconditionalBranch(*PrevInstr) &&
           !MIB->getConditionalTailCall(*PrevInstr) &&
-          !MIB->isExternalBranch(*PrevInstr) &&
-          !MIB->isReturn(*PrevInstr)) {
+          !MIB->isExternalBranch(*PrevInstr) && !MIB->isReturn(*PrevInstr)) {
         // Temporarily restore inserter basic block.
         InsertBB = PrevBB;
       } else {
@@ -2482,10 +2481,10 @@ Error BinaryFunction::buildCFG(MCPlusBuilder::AllocatorIdTy AllocatorId) {
     if (BB->succ_size() == 0) {
       // Conditional tail calls and external branches have no local taken
       // successor, but can still fall through.
-      IsPrevFT = !MIB->isTerminator(*LastInstr) ||
-                 (MIB->isConditionalBranch(*LastInstr) &&
-                  (MIB->isExternalBranch(*LastInstr) ||
-                   MIB->isTailCall(*LastInstr)));
+      IsPrevFT =
+          !MIB->isTerminator(*LastInstr) ||
+          (MIB->isConditionalBranch(*LastInstr) &&
+           (MIB->isExternalBranch(*LastInstr) || MIB->isTailCall(*LastInstr)));
     } else if (BB->succ_size() == 1) {
       IsPrevFT = MIB->isConditionalBranch(*LastInstr);
     } else {
@@ -2631,10 +2630,10 @@ void BinaryFunction::removeConditionalExits() {
     uint64_t TakenCount = BinaryBasicBlock::COUNT_NO_PROFILE;
     uint64_t MispredCount = BinaryBasicBlock::COUNT_NO_PROFILE;
     if (hasValidProfile()) {
-      TakenCount = BC.MIB->getAnnotationWithDefault<uint64_t>(*CondBranch,
-          IsExternalBranch ? "Count" : "CTCTakenCount");
-      MispredCount = BC.MIB->getAnnotationWithDefault<uint64_t>(*CondBranch,
-          IsExternalBranch ? "MispredCount" : "CTCMispredCount");
+      TakenCount = BC.MIB->getAnnotationWithDefault<uint64_t>(
+          *CondBranch, IsExternalBranch ? "Count" : "CTCTakenCount");
+      MispredCount = BC.MIB->getAnnotationWithDefault<uint64_t>(
+          *CondBranch, IsExternalBranch ? "MispredCount" : "CTCMispredCount");
     }
 
     assert(!BC.MIB->getEHInfo(*CondBranch) &&
@@ -4898,8 +4897,7 @@ bool BinaryFunction::isPossibleVeneer() const {
 
 void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
                                    uint32_t RelType, uint64_t Addend,
-                                   uint64_t Value,
-                                   uint8_t ELFSymType) {
+                                   uint64_t Value, uint8_t ELFSymType) {
   assert(Address >= getAddress() && Address < getAddress() + getMaxSize() &&
          "address is outside of the function");
   uint64_t Offset = Address - getAddress();
@@ -4910,8 +4908,8 @@ void BinaryFunction::addRelocation(uint64_t Address, MCSymbol *Symbol,
   std::map<uint64_t, Relocation> &Rels =
       IsCI ? Islands->Relocations : Relocations;
   if (BC.MIB->shouldRecordCodeRelocation(RelType))
-    Rels[Offset] = Relocation{Offset, Symbol, RelType, Addend, Value,
-                             ELFSymType};
+    Rels[Offset] =
+        Relocation{Offset, Symbol, RelType, Addend, Value, ELFSymType};
 }
 
 } // namespace bolt
diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp
index 95384c6fc..95f42216b 100644
--- a/bolt/lib/Profile/DataReader.cpp
+++ b/bolt/lib/Profile/DataReader.cpp
@@ -649,9 +649,9 @@ void DataReader::convertBranchData(BinaryFunction &BF) const {
       continue;
 
     MCInst *Instr = BF.getInstructionAtOffset(BI.From.Offset);
-    if (!Instr || (!BC.MIB->isCall(*Instr) &&
-                   !BC.MIB->isIndirectBranch(*Instr) &&
-                   !BC.MIB->isExternalBranch(*Instr)))
+    if (!Instr ||
+        (!BC.MIB->isCall(*Instr) && !BC.MIB->isIndirectBranch(*Instr) &&
+         !BC.MIB->isExternalBranch(*Instr)))
       continue;
 
     auto setOrUpdateAnnotation = [&](StringRef Name, uint64_t Count) {
diff --git a/bolt/lib/Profile/YAMLProfileReader.cpp b/bolt/lib/Profile/YAMLProfileReader.cpp
index fddfeb6e7..b88c2c2c1 100644
--- a/bolt/lib/Profile/YAMLProfileReader.cpp
+++ b/bolt/lib/Profile/YAMLProfileReader.cpp
@@ -272,8 +272,7 @@ bool YAMLProfileReader::parseFunctionProfile(
           !BC.MIB->isExternalBranch(*Instr)) {
         if (opts::Verbosity >= 2)
           errs() << "BOLT-WARNING: expected call or external branch at offset "
-                 << YamlCSI.Offset
-                 << " in block " << BB.getName() << '\n';
+                 << YamlCSI.Offset << " in block " << BB.getName() << '\n';
         ++MismatchedCalls;
         continue;
       }

``````````

</details>


https://github.com/llvm/llvm-project/pull/227275


More information about the llvm-commits mailing list